diff mbox series

[v1,08/18] btrfs-progs: filesystem defragment: use global verbose option

Message ID 1572849196-21775-9-git-send-email-anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: global verbose and quiet option | expand

Commit Message

Anand Jain Nov. 4, 2019, 6:33 a.m. UTC
Transpire global --verbose option down to the btrfs receive sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds/filesystem.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

Comments

David Sterba Nov. 14, 2019, 4:16 p.m. UTC | #1
On Mon, Nov 04, 2019 at 02:33:06PM +0800, Anand Jain wrote:
> Transpire global --verbose option down to the btrfs receive sub-command.
> 
> Suggested-by: David Sterba <dsterba@suse.com>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  cmds/filesystem.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/cmds/filesystem.c b/cmds/filesystem.c
> index 4f22089abeaa..819b9fd1fcc5 100644
> --- a/cmds/filesystem.c
> +++ b/cmds/filesystem.c
> @@ -844,11 +844,12 @@ static const char * const cmd_filesystem_defrag_usage[] = {
>  	"(e.g., files copied with 'cp --reflink', snapshots) which may cause",
>  	"considerable increase of space usage. See btrfs-filesystem(8) for",
>  	"more information.",
> +	HELPINFO_GLOBAL_OPTIONS_HEADER,
> +	HELPINFO_INSERT_VERBOSE,

Please not that this needs to be put right after the command options,
ie. before the paragraph.
Anand Jain Nov. 25, 2019, 10:35 a.m. UTC | #2
On 11/15/19 12:16 AM, David Sterba wrote:
> On Mon, Nov 04, 2019 at 02:33:06PM +0800, Anand Jain wrote:
>> Transpire global --verbose option down to the btrfs receive sub-command.
>>
>> Suggested-by: David Sterba <dsterba@suse.com>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>>   cmds/filesystem.c | 16 +++++++++-------
>>   1 file changed, 9 insertions(+), 7 deletions(-)
>>
>> diff --git a/cmds/filesystem.c b/cmds/filesystem.c
>> index 4f22089abeaa..819b9fd1fcc5 100644
>> --- a/cmds/filesystem.c
>> +++ b/cmds/filesystem.c
>> @@ -844,11 +844,12 @@ static const char * const cmd_filesystem_defrag_usage[] = {
>>   	"(e.g., files copied with 'cp --reflink', snapshots) which may cause",
>>   	"considerable increase of space usage. See btrfs-filesystem(8) for",
>>   	"more information.",
>> +	HELPINFO_GLOBAL_OPTIONS_HEADER,
>> +	HELPINFO_INSERT_VERBOSE,
> 
> Please not that this needs to be put right after the command options,
> ie. before the paragraph.
> 

This is fixed in v2.
diff mbox series

Patch

diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index 4f22089abeaa..819b9fd1fcc5 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -844,11 +844,12 @@  static const char * const cmd_filesystem_defrag_usage[] = {
 	"(e.g., files copied with 'cp --reflink', snapshots) which may cause",
 	"considerable increase of space usage. See btrfs-filesystem(8) for",
 	"more information.",
+	HELPINFO_GLOBAL_OPTIONS_HEADER,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
 static struct btrfs_ioctl_defrag_range_args defrag_global_range;
-static int defrag_global_verbose;
 static int defrag_global_errors;
 static int defrag_callback(const char *fpath, const struct stat *sb,
 		int typeflag, struct FTW *ftwbuf)
@@ -857,8 +858,7 @@  static int defrag_callback(const char *fpath, const struct stat *sb,
 	int fd = 0;
 
 	if ((typeflag == FTW_F) && S_ISREG(sb->st_mode)) {
-		if (defrag_global_verbose)
-			printf("%s\n", fpath);
+		pr_verbose(1, "%s\n", fpath);
 		fd = open(fpath, defrag_open_mode);
 		if (fd < 0) {
 			goto error;
@@ -897,6 +897,10 @@  static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
 	int compress_type = BTRFS_COMPRESS_NONE;
 	DIR *dirstream;
 
+	/* init global verbose if unset */
+	if (bconf.verbose < 0)
+		bconf.verbose = 0;
+
 	/*
 	 * Kernel 4.19+ supports defragmention of files open read-only,
 	 * otherwise it's an ETXTBSY error
@@ -913,7 +917,6 @@  static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
 	thresh = SZ_32M;
 
 	defrag_global_errors = 0;
-	defrag_global_verbose = 0;
 	defrag_global_errors = 0;
 	optind = 0;
 	while(1) {
@@ -931,7 +934,7 @@  static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
 			flush = 1;
 			break;
 		case 'v':
-			defrag_global_verbose = 1;
+			bconf.verbose++;
 			break;
 		case 's':
 			start = parse_size(optarg);
@@ -1031,8 +1034,7 @@  static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
 			/* errors are handled in the callback */
 			ret = 0;
 		} else {
-			if (defrag_global_verbose)
-				printf("%s\n", argv[i]);
+			pr_verbose(1, "%s\n", argv[i]);
 			ret = ioctl(fd, BTRFS_IOC_DEFRAG_RANGE,
 					&defrag_global_range);
 			defrag_err = errno;