All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] btrfs-progs: move check_arg_type() to util.c
@ 2014-12-25  1:16 Gui Hecheng
  2014-12-25  1:16 ` [PATCH 2/2] btrfs-progs: refine btrfs-debug-tree error prompt when a mount point given Gui Hecheng
  2014-12-25  6:43 ` [PATCH 1/2] btrfs-progs: move check_arg_type() to util.c Satoru Takeuchi
  0 siblings, 2 replies; 6+ messages in thread
From: Gui Hecheng @ 2014-12-25  1:16 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Gui Hecheng

The check_arg_type() function does quite generic thing,
move it to utils.c.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
 cmds-filesystem.c | 32 --------------------------------
 utils.c           | 32 ++++++++++++++++++++++++++++++++
 utils.h           |  1 +
 3 files changed, 33 insertions(+), 32 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 253f105..4d7a797 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -537,38 +537,6 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
 	return 0;
 }
 
-/* This function checks if the given input parameter is
- * an uuid or a path
- * return -1: some error in the given input
- * return 0: unknow input
- * return 1: given input is uuid
- * return 2: given input is path
- */
-static int check_arg_type(char *input)
-{
-	uuid_t	out;
-	char path[PATH_MAX];
-
-	if (!input)
-		return -EINVAL;
-
-	if (realpath(input, path)) {
-		if (is_block_device(path) == 1)
-			return BTRFS_ARG_BLKDEV;
-
-		if (is_mount_point(path) == 1)
-			return BTRFS_ARG_MNTPOINT;
-
-		return BTRFS_ARG_UNKNOWN;
-	}
-
-	if (strlen(input) == (BTRFS_UUID_UNPARSED_SIZE - 1) &&
-		!uuid_parse(input, out))
-		return BTRFS_ARG_UUID;
-
-	return BTRFS_ARG_UNKNOWN;
-}
-
 static int btrfs_scan_kernel(void *search)
 {
 	int ret = 0, fd;
diff --git a/utils.c b/utils.c
index 2a92416..80f85e9 100644
--- a/utils.c
+++ b/utils.c
@@ -852,6 +852,38 @@ int is_mount_point(const char *path)
 	return ret;
 }
 
+/* This function checks if the given input parameter is
+ * an uuid or a path
+ * return -1: some error in the given input
+ * return 0: unknow input
+ * return 1: given input is uuid
+ * return 2: given input is path
+ */
+int check_arg_type(const char *input)
+{
+	uuid_t	out;
+	char path[PATH_MAX];
+
+	if (!input)
+		return -EINVAL;
+
+	if (realpath(input, path)) {
+		if (is_block_device(path) == 1)
+			return BTRFS_ARG_BLKDEV;
+
+		if (is_mount_point(path) == 1)
+			return BTRFS_ARG_MNTPOINT;
+
+		return BTRFS_ARG_UNKNOWN;
+	}
+
+	if (strlen(input) == (BTRFS_UUID_UNPARSED_SIZE - 1) &&
+		!uuid_parse(input, out))
+		return BTRFS_ARG_UUID;
+
+	return BTRFS_ARG_UNKNOWN;
+}
+
 /*
  * Find the mount point for a mounted device.
  * On success, returns 0 with mountpoint in *mp.
diff --git a/utils.h b/utils.h
index 289e86b..8d67720 100644
--- a/utils.h
+++ b/utils.h
@@ -115,6 +115,7 @@ int set_label(const char *btrfs_dev, const char *label);
 char *__strncpy__null(char *dest, const char *src, size_t n);
 int is_block_device(const char *file);
 int is_mount_point(const char *file);
+int check_arg_type(const char *input);
 int open_path_or_dev_mnt(const char *path, DIR **dirstream);
 u64 btrfs_device_size(int fd, struct stat *st);
 /* Helper to always get proper size of the destination string */
-- 
1.8.1.4


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

* [PATCH 2/2] btrfs-progs: refine btrfs-debug-tree error prompt when a mount point given
  2014-12-25  1:16 [PATCH 1/2] btrfs-progs: move check_arg_type() to util.c Gui Hecheng
@ 2014-12-25  1:16 ` Gui Hecheng
  2014-12-25  6:49   ` Satoru Takeuchi
  2014-12-29 16:29   ` David Sterba
  2014-12-25  6:43 ` [PATCH 1/2] btrfs-progs: move check_arg_type() to util.c Satoru Takeuchi
  1 sibling, 2 replies; 6+ messages in thread
From: Gui Hecheng @ 2014-12-25  1:16 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Gui Hecheng

Now, if exec:
	# btrfs-debug-tree <mount_point>
it echos:
	: Superblock bytenr is larger than device size

But it is quite misleading, because it is a valid btrfs.
In this case, we should tell the developer to provide a block device.

After apply:
	: '<mount_point>' is not a block device
	: 'usage: btrfs-debug-tree [options] device

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
 btrfs-debug-tree.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/btrfs-debug-tree.c b/btrfs-debug-tree.c
index e46500d..7f079a9 100644
--- a/btrfs-debug-tree.c
+++ b/btrfs-debug-tree.c
@@ -179,6 +179,12 @@ int main(int ac, char **av)
 	if (check_argc_exact(ac, 1))
 		print_usage();
 
+	ret = check_arg_type(av[optind]);
+	if (ret != BTRFS_ARG_BLKDEV) {
+		fprintf(stderr, "'%s' is not a block device\n", av[optind]);
+		print_usage();
+	}
+
 	info = open_ctree_fs_info(av[optind], 0, 0, OPEN_CTREE_PARTIAL);
 	if (!info) {
 		fprintf(stderr, "unable to open %s\n", av[optind]);
-- 
1.8.1.4


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

* Re: [PATCH 1/2] btrfs-progs: move check_arg_type() to util.c
  2014-12-25  1:16 [PATCH 1/2] btrfs-progs: move check_arg_type() to util.c Gui Hecheng
  2014-12-25  1:16 ` [PATCH 2/2] btrfs-progs: refine btrfs-debug-tree error prompt when a mount point given Gui Hecheng
@ 2014-12-25  6:43 ` Satoru Takeuchi
  1 sibling, 0 replies; 6+ messages in thread
From: Satoru Takeuchi @ 2014-12-25  6:43 UTC (permalink / raw)
  To: Gui Hecheng, linux-btrfs

On 2014/12/25 10:16, Gui Hecheng wrote:
> The check_arg_type() function does quite generic thing,
> move it to utils.c.
> 
> Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>

Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>

> ---
>   cmds-filesystem.c | 32 --------------------------------
>   utils.c           | 32 ++++++++++++++++++++++++++++++++
>   utils.h           |  1 +
>   3 files changed, 33 insertions(+), 32 deletions(-)
> 
> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
> index 253f105..4d7a797 100644
> --- a/cmds-filesystem.c
> +++ b/cmds-filesystem.c
> @@ -537,38 +537,6 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
>   	return 0;
>   }
>   
> -/* This function checks if the given input parameter is
> - * an uuid or a path
> - * return -1: some error in the given input
> - * return 0: unknow input
> - * return 1: given input is uuid
> - * return 2: given input is path
> - */
> -static int check_arg_type(char *input)
> -{
> -	uuid_t	out;
> -	char path[PATH_MAX];
> -
> -	if (!input)
> -		return -EINVAL;
> -
> -	if (realpath(input, path)) {
> -		if (is_block_device(path) == 1)
> -			return BTRFS_ARG_BLKDEV;
> -
> -		if (is_mount_point(path) == 1)
> -			return BTRFS_ARG_MNTPOINT;
> -
> -		return BTRFS_ARG_UNKNOWN;
> -	}
> -
> -	if (strlen(input) == (BTRFS_UUID_UNPARSED_SIZE - 1) &&
> -		!uuid_parse(input, out))
> -		return BTRFS_ARG_UUID;
> -
> -	return BTRFS_ARG_UNKNOWN;
> -}
> -
>   static int btrfs_scan_kernel(void *search)
>   {
>   	int ret = 0, fd;
> diff --git a/utils.c b/utils.c
> index 2a92416..80f85e9 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -852,6 +852,38 @@ int is_mount_point(const char *path)
>   	return ret;
>   }
>   
> +/* This function checks if the given input parameter is
> + * an uuid or a path
> + * return -1: some error in the given input
> + * return 0: unknow input
> + * return 1: given input is uuid
> + * return 2: given input is path
> + */
> +int check_arg_type(const char *input)
> +{
> +	uuid_t	out;
> +	char path[PATH_MAX];
> +
> +	if (!input)
> +		return -EINVAL;
> +
> +	if (realpath(input, path)) {
> +		if (is_block_device(path) == 1)
> +			return BTRFS_ARG_BLKDEV;
> +
> +		if (is_mount_point(path) == 1)
> +			return BTRFS_ARG_MNTPOINT;
> +
> +		return BTRFS_ARG_UNKNOWN;
> +	}
> +
> +	if (strlen(input) == (BTRFS_UUID_UNPARSED_SIZE - 1) &&
> +		!uuid_parse(input, out))
> +		return BTRFS_ARG_UUID;
> +
> +	return BTRFS_ARG_UNKNOWN;
> +}
> +
>   /*
>    * Find the mount point for a mounted device.
>    * On success, returns 0 with mountpoint in *mp.
> diff --git a/utils.h b/utils.h
> index 289e86b..8d67720 100644
> --- a/utils.h
> +++ b/utils.h
> @@ -115,6 +115,7 @@ int set_label(const char *btrfs_dev, const char *label);
>   char *__strncpy__null(char *dest, const char *src, size_t n);
>   int is_block_device(const char *file);
>   int is_mount_point(const char *file);
> +int check_arg_type(const char *input);
>   int open_path_or_dev_mnt(const char *path, DIR **dirstream);
>   u64 btrfs_device_size(int fd, struct stat *st);
>   /* Helper to always get proper size of the destination string */
> 


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

* Re: [PATCH 2/2] btrfs-progs: refine btrfs-debug-tree error prompt when a mount point given
  2014-12-25  1:16 ` [PATCH 2/2] btrfs-progs: refine btrfs-debug-tree error prompt when a mount point given Gui Hecheng
@ 2014-12-25  6:49   ` Satoru Takeuchi
  2014-12-25  7:23     ` Gui Hecheng
  2014-12-29 16:29   ` David Sterba
  1 sibling, 1 reply; 6+ messages in thread
From: Satoru Takeuchi @ 2014-12-25  6:49 UTC (permalink / raw)
  To: Gui Hecheng, linux-btrfs

On 2014/12/25 10:16, Gui Hecheng wrote:
> Now, if exec:
> 	# btrfs-debug-tree <mount_point>
> it echos:
> 	: Superblock bytenr is larger than device size
> 
> But it is quite misleading, because it is a valid btrfs.
> In this case, we should tell the developer to provide a block device.
> 
> After apply:
> 	: '<mount_point>' is not a block device
> 	: 'usage: btrfs-debug-tree [options] device
> 
> Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
> ---
>   btrfs-debug-tree.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/btrfs-debug-tree.c b/btrfs-debug-tree.c
> index e46500d..7f079a9 100644
> --- a/btrfs-debug-tree.c
> +++ b/btrfs-debug-tree.c
> @@ -179,6 +179,12 @@ int main(int ac, char **av)
>   	if (check_argc_exact(ac, 1))
>   		print_usage();
>   
> +	ret = check_arg_type(av[optind]);
> +	if (ret != BTRFS_ARG_BLKDEV) {
> +		fprintf(stderr, "'%s' is not a block device\n", av[optind]);

fprintf(stderr, "ERROR: '%s' is ...)" is better since
other error messages in btrfs-progs have this convention.

Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>

Thanks,
Satoru

> +		print_usage();
> +	}
> +
>   	info = open_ctree_fs_info(av[optind], 0, 0, OPEN_CTREE_PARTIAL);
>   	if (!info) {
>   		fprintf(stderr, "unable to open %s\n", av[optind]);
> 


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

* Re: [PATCH 2/2] btrfs-progs: refine btrfs-debug-tree error prompt when a mount point given
  2014-12-25  6:49   ` Satoru Takeuchi
@ 2014-12-25  7:23     ` Gui Hecheng
  0 siblings, 0 replies; 6+ messages in thread
From: Gui Hecheng @ 2014-12-25  7:23 UTC (permalink / raw)
  To: Satoru Takeuchi; +Cc: linux-btrfs

On Thu, 2014-12-25 at 15:49 +0900, Satoru Takeuchi wrote:
> On 2014/12/25 10:16, Gui Hecheng wrote:
> > Now, if exec:
> > 	# btrfs-debug-tree <mount_point>
> > it echos:
> > 	: Superblock bytenr is larger than device size
> > 
> > But it is quite misleading, because it is a valid btrfs.
> > In this case, we should tell the developer to provide a block device.
> > 
> > After apply:
> > 	: '<mount_point>' is not a block device
> > 	: 'usage: btrfs-debug-tree [options] device
> > 
> > Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
> > ---
> >   btrfs-debug-tree.c | 6 ++++++
> >   1 file changed, 6 insertions(+)
> > 
> > diff --git a/btrfs-debug-tree.c b/btrfs-debug-tree.c
> > index e46500d..7f079a9 100644
> > --- a/btrfs-debug-tree.c
> > +++ b/btrfs-debug-tree.c
> > @@ -179,6 +179,12 @@ int main(int ac, char **av)
> >   	if (check_argc_exact(ac, 1))
> >   		print_usage();
> >   
> > +	ret = check_arg_type(av[optind]);
> > +	if (ret != BTRFS_ARG_BLKDEV) {
> > +		fprintf(stderr, "'%s' is not a block device\n", av[optind]);
> 
> fprintf(stderr, "ERROR: '%s' is ...)" is better since
> other error messages in btrfs-progs have this convention.

Yes, it is good to make it clear about the "ERROR", but since there is
no "ERROR" word throughout the source file, I think I would make all
error prompts to start with the "ERROR" word globally in the progs in
another patch.

Thanks,
Gui

> Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
> 
> Thanks,
> Satoru
> 
> > +		print_usage();
> > +	}
> > +
> >   	info = open_ctree_fs_info(av[optind], 0, 0, OPEN_CTREE_PARTIAL);
> >   	if (!info) {
> >   		fprintf(stderr, "unable to open %s\n", av[optind]);
> > 
> 



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

* Re: [PATCH 2/2] btrfs-progs: refine btrfs-debug-tree error prompt when a mount point given
  2014-12-25  1:16 ` [PATCH 2/2] btrfs-progs: refine btrfs-debug-tree error prompt when a mount point given Gui Hecheng
  2014-12-25  6:49   ` Satoru Takeuchi
@ 2014-12-29 16:29   ` David Sterba
  1 sibling, 0 replies; 6+ messages in thread
From: David Sterba @ 2014-12-29 16:29 UTC (permalink / raw)
  To: Gui Hecheng; +Cc: linux-btrfs

On Thu, Dec 25, 2014 at 09:16:35AM +0800, Gui Hecheng wrote:
> Now, if exec:
> 	# btrfs-debug-tree <mount_point>
> it echos:
> 	: Superblock bytenr is larger than device size
> 
> But it is quite misleading, because it is a valid btrfs.
> In this case, we should tell the developer to provide a block device.
> 
> After apply:
> 	: '<mount_point>' is not a block device
> 	: 'usage: btrfs-debug-tree [options] device
> 
> Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
> ---
>  btrfs-debug-tree.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/btrfs-debug-tree.c b/btrfs-debug-tree.c
> index e46500d..7f079a9 100644
> --- a/btrfs-debug-tree.c
> +++ b/btrfs-debug-tree.c
> @@ -179,6 +179,12 @@ int main(int ac, char **av)
>  	if (check_argc_exact(ac, 1))
>  		print_usage();
>  
> +	ret = check_arg_type(av[optind]);
> +	if (ret != BTRFS_ARG_BLKDEV) {
> +		fprintf(stderr, "'%s' is not a block device\n", av[optind]);
> +		print_usage();

The current widespread pattern is to print_usage() after most errors in
commandline arguments but I find it quite annoying. The help is always
available under --help for each command. As the bugfix is good I'm going
to apply it and replace it with exit().

We can start removing misues of print_usage() from the codebase in the
next dev cycle.

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

end of thread, other threads:[~2014-12-29 16:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-25  1:16 [PATCH 1/2] btrfs-progs: move check_arg_type() to util.c Gui Hecheng
2014-12-25  1:16 ` [PATCH 2/2] btrfs-progs: refine btrfs-debug-tree error prompt when a mount point given Gui Hecheng
2014-12-25  6:49   ` Satoru Takeuchi
2014-12-25  7:23     ` Gui Hecheng
2014-12-29 16:29   ` David Sterba
2014-12-25  6:43 ` [PATCH 1/2] btrfs-progs: move check_arg_type() to util.c Satoru Takeuchi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.