linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: qgroup: Check for ENOTCONN error on create/assign/limit
@ 2019-11-27  3:48 Marcos Paulo de Souza
  2019-11-27  4:30 ` Qu Wenruo
  0 siblings, 1 reply; 4+ messages in thread
From: Marcos Paulo de Souza @ 2019-11-27  3:48 UTC (permalink / raw)
  Cc: dsterba, linux-btrfs, anand.jain, wqu, Marcos Paulo de Souza

From: Marcos Paulo de Souza <mpdesouza@suse.com>

Current btrfs code returns ENOTCONN when the user tries to create a
qgroup on a subvolume without quota enabled. In order to present a
meaningful message to the user, we now handle ENOTCONN showing
the message "quota not enabled".

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 This patch survived a full btrfs-progs tests run

 cmds/qgroup.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/cmds/qgroup.c b/cmds/qgroup.c
index ba81052a..6bfb4949 100644
--- a/cmds/qgroup.c
+++ b/cmds/qgroup.c
@@ -98,7 +98,9 @@ static int _cmd_qgroup_assign(const struct cmd_struct *cmd, int assign,
 
 	ret = ioctl(fd, BTRFS_IOC_QGROUP_ASSIGN, &args);
 	if (ret < 0) {
-		error("unable to assign quota group: %m");
+		error("unable to assign quota group: %s",
+				errno == ENOTCONN ? "quota not enabled"
+						: strerror(errno));
 		close_file_or_dir(fd, dirstream);
 		return 1;
 	}
@@ -152,8 +154,10 @@ static int _cmd_qgroup_create(int create, int argc, char **argv)
 	ret = ioctl(fd, BTRFS_IOC_QGROUP_CREATE, &args);
 	close_file_or_dir(fd, dirstream);
 	if (ret < 0) {
-		error("unable to %s quota group: %m",
-			create ? "create":"destroy");
+		error("unable to %s quota group: %s",
+			create ? "create":"destroy",
+				errno == ENOTCONN ? "quota not enabled"
+						: strerror(errno));
 		return 1;
 	}
 	return 0;
@@ -447,7 +451,10 @@ static int cmd_qgroup_limit(const struct cmd_struct *cmd, int argc, char **argv)
 	ret = ioctl(fd, BTRFS_IOC_QGROUP_LIMIT, &args);
 	close_file_or_dir(fd, dirstream);
 	if (ret < 0) {
-		error("unable to limit requested quota group: %m");
+		error("unable to limit requested quota group: %s",
+				errno == ENOTCONN ? "quota not enabled"
+						: strerror(errno));
+
 		return 1;
 	}
 	return 0;
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs-progs: qgroup: Check for ENOTCONN error on create/assign/limit
  2019-11-27  3:48 [PATCH] btrfs-progs: qgroup: Check for ENOTCONN error on create/assign/limit Marcos Paulo de Souza
@ 2019-11-27  4:30 ` Qu Wenruo
  2019-11-28 11:08   ` David Sterba
  0 siblings, 1 reply; 4+ messages in thread
From: Qu Wenruo @ 2019-11-27  4:30 UTC (permalink / raw)
  To: Marcos Paulo de Souza
  Cc: dsterba, linux-btrfs, anand.jain, wqu, Marcos Paulo de Souza


[-- Attachment #1.1: Type: text/plain, Size: 2206 bytes --]



On 2019/11/27 上午11:48, Marcos Paulo de Souza wrote:
> From: Marcos Paulo de Souza <mpdesouza@suse.com>
> 
> Current btrfs code returns ENOTCONN when the user tries to create a
> qgroup on a subvolume without quota enabled. In order to present a
> meaningful message to the user, we now handle ENOTCONN showing
> the message "quota not enabled".
> 
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>

Don't forget the original -EINVAL.

So it needs to cover both -EINVAL (for older kernel) and -ENOTCONN (for
newer kernel).

Thanks,
Qu

> ---
>  This patch survived a full btrfs-progs tests run
> 
>  cmds/qgroup.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/cmds/qgroup.c b/cmds/qgroup.c
> index ba81052a..6bfb4949 100644
> --- a/cmds/qgroup.c
> +++ b/cmds/qgroup.c
> @@ -98,7 +98,9 @@ static int _cmd_qgroup_assign(const struct cmd_struct *cmd, int assign,
>  
>  	ret = ioctl(fd, BTRFS_IOC_QGROUP_ASSIGN, &args);
>  	if (ret < 0) {
> -		error("unable to assign quota group: %m");
> +		error("unable to assign quota group: %s",
> +				errno == ENOTCONN ? "quota not enabled"
> +						: strerror(errno));
>  		close_file_or_dir(fd, dirstream);
>  		return 1;
>  	}
> @@ -152,8 +154,10 @@ static int _cmd_qgroup_create(int create, int argc, char **argv)
>  	ret = ioctl(fd, BTRFS_IOC_QGROUP_CREATE, &args);
>  	close_file_or_dir(fd, dirstream);
>  	if (ret < 0) {
> -		error("unable to %s quota group: %m",
> -			create ? "create":"destroy");
> +		error("unable to %s quota group: %s",
> +			create ? "create":"destroy",
> +				errno == ENOTCONN ? "quota not enabled"
> +						: strerror(errno));
>  		return 1;
>  	}
>  	return 0;
> @@ -447,7 +451,10 @@ static int cmd_qgroup_limit(const struct cmd_struct *cmd, int argc, char **argv)
>  	ret = ioctl(fd, BTRFS_IOC_QGROUP_LIMIT, &args);
>  	close_file_or_dir(fd, dirstream);
>  	if (ret < 0) {
> -		error("unable to limit requested quota group: %m");
> +		error("unable to limit requested quota group: %s",
> +				errno == ENOTCONN ? "quota not enabled"
> +						: strerror(errno));
> +
>  		return 1;
>  	}
>  	return 0;
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs-progs: qgroup: Check for ENOTCONN error on create/assign/limit
  2019-11-27  4:30 ` Qu Wenruo
@ 2019-11-28 11:08   ` David Sterba
  2019-11-28 12:39     ` Qu Wenruo
  0 siblings, 1 reply; 4+ messages in thread
From: David Sterba @ 2019-11-28 11:08 UTC (permalink / raw)
  To: Qu Wenruo
  Cc: Marcos Paulo de Souza, dsterba, linux-btrfs, anand.jain, wqu,
	Marcos Paulo de Souza

On Wed, Nov 27, 2019 at 12:30:38PM +0800, Qu Wenruo wrote:
> 
> 
> On 2019/11/27 上午11:48, Marcos Paulo de Souza wrote:
> > From: Marcos Paulo de Souza <mpdesouza@suse.com>
> > 
> > Current btrfs code returns ENOTCONN when the user tries to create a
> > qgroup on a subvolume without quota enabled. In order to present a
> > meaningful message to the user, we now handle ENOTCONN showing
> > the message "quota not enabled".
> > 
> > Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> 
> Don't forget the original -EINVAL.
> 
> So it needs to cover both -EINVAL (for older kernel) and -ENOTCONN (for
> newer kernel).

I think for now only ENOTCONN should be interpreted as 'quotas not
enabled' as we can be sure it's just that. But EINVAL means 'invalid
parameter' and this can be interpreted in that context as if the qgroup
ids are wrong etc.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs-progs: qgroup: Check for ENOTCONN error on create/assign/limit
  2019-11-28 11:08   ` David Sterba
@ 2019-11-28 12:39     ` Qu Wenruo
  0 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2019-11-28 12:39 UTC (permalink / raw)
  To: dsterba, Marcos Paulo de Souza, dsterba, linux-btrfs, anand.jain,
	wqu, Marcos Paulo de Souza


[-- Attachment #1.1: Type: text/plain, Size: 1039 bytes --]



On 2019/11/28 下午7:08, David Sterba wrote:
> On Wed, Nov 27, 2019 at 12:30:38PM +0800, Qu Wenruo wrote:
>>
>>
>> On 2019/11/27 上午11:48, Marcos Paulo de Souza wrote:
>>> From: Marcos Paulo de Souza <mpdesouza@suse.com>
>>>
>>> Current btrfs code returns ENOTCONN when the user tries to create a
>>> qgroup on a subvolume without quota enabled. In order to present a
>>> meaningful message to the user, we now handle ENOTCONN showing
>>> the message "quota not enabled".
>>>
>>> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
>>
>> Don't forget the original -EINVAL.
>>
>> So it needs to cover both -EINVAL (for older kernel) and -ENOTCONN (for
>> newer kernel).
> 
> I think for now only ENOTCONN should be interpreted as 'quotas not
> enabled' as we can be sure it's just that. But EINVAL means 'invalid
> parameter' and this can be interpreted in that context as if the qgroup
> ids are wrong etc.
>

Ah, makes sense.
So no need for a new version.
Reviewed-by: Qu Wenruo <wqu@suse.com>


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-11-28 12:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-27  3:48 [PATCH] btrfs-progs: qgroup: Check for ENOTCONN error on create/assign/limit Marcos Paulo de Souza
2019-11-27  4:30 ` Qu Wenruo
2019-11-28 11:08   ` David Sterba
2019-11-28 12:39     ` Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).