Skip to contentSkip to conversation

btrfs-progs: add quiet option

PATCH Superseded Anand Jain 2 participants 12 messages Jun 8, 2020 – Jun 11, 2020 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

cover btrfs-progs: add quiet option

The part-1 patchset [1] 'btrfs-progs: global verbose and quiet option'
[1]
https://patchwork.kernel.org/project/linux-btrfs/list/?series=207709

provided a global structure to communicate the verbose and quiet options down to the individual sub-commands where the actual printf happens. So each of the sub-command could enable the verbose or quiet option as needed.
But some of the sub-commands already had the verbose and quiet options locally at the sub-command level. So the aim of part-1 of this series was to merge the local verbose and quiet option with the global verbose and quiet, which it did successfully.

In this series, part-2, adds the global quiet option to the found chatty sub-commands. So each of the sub-commands outputs were individually checked and brought those logs under the global quiet option. As this process is nondeterministic (unless like in part-1 where sub-commands with -v or -q were checked) so there might have few logs left behind and those can be fixed as moved along.

The whole series can be fetched from [2], which is based on latest devel branch, last commit: c1d6d654a3f9 (btrfs-progs: docs: update balance).

[2]
https://github.com/asj/btrfs-progs.git verbose

Anand Jain (8):
btrfs-progs: quota rescan: add quiet option
btrfs-progs: subvolume create: add quiet option
btrfs-progs: subvolume delete: add quiet option
btrfs-progs: balance start: add quiet option
btrfs-progs: balance resume: add quiet option
btrfs-progs: subvolume snapshot: add quiet option
btrfs-progs: scrub start|resume: use global quiet option
btrfs-progs: scrub cancel: add quiet option

 cmds/balance.c   | 17 +++++++++++------
 cmds/quota.c     |  4 +++-
 cmds/scrub.c     | 25 +++++++++++++++----------
 cmds/subvolume.c | 24 +++++++++++++++---------
 4 files changed, 44 insertions(+), 26 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/8 btrfs-progs: quota rescan: add quiet option

Enable the quiet option to the btrfs(8) quota rescan command. Does the job quietly. For example:
btrfs --quiet quota rescan

---
 cmds/quota.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
cmds/quota.c +3 -1
index 075fc79816ad..4a68f9db081b 100644
@@ -108,6 +108,8 @@ static const char * const cmd_quota_rescan_usage[] = {
 	"",
 	"-s   show status of a running rescan operation",
 	"-w   wait for rescan operation to finish (can be already in progress)",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
@@ -172,7 +174,7 @@ static int cmd_quota_rescan(const struct cmd_struct *cmd, int argc, char **argv)
 	}
 
 	if (ret == 0) {
-		printf("quota rescan started\n");
+		pr_verbose(-1, "quota rescan started\n");
 		fflush(stdout);
 	} else if (ret < 0 && (!wait_for_completion || e != EINPROGRESS)) {
 		error("quota rescan failed: %m");
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/8] btrfs-progs: quota rescan: add quiet option

Quoted 23 lines · Anand Jain

Enable the quiet option to the btrfs(8) quota rescan command. Does the job quietly. For example:
btrfs --quiet quota rescan

---
 cmds/quota.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
cmds/quota.c +2 -0
index 075fc79816ad..4a68f9db081b 100644
@@ -108,6 +108,8 @@ static const char * const cmd_quota_rescan_usage[] = {
 	"",
 	"-s   show status of a running rescan operation",
 	"-w   wait for rescan operation to finish (can be already in progress)",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 

cmds/quota.c static int cmd_quota_rescan(const struct cmd_struct *cmd, int argc, char **argv) · line 177

Quoted 5 lines
cmds/quota.c +1 -1
@@ -172,7 +174,7 @@ static int cmd_quota_rescan(const struct cmd_struct *cmd, int argc, char **argv)
 	}
 
 	if (ret == 0) {
-		printf("quota rescan started\n");
+		pr_verbose(-1, "quota rescan started\n");

That the raw value -1 is used here is not nice, I assume it means print unless there was another setting of the verbosity (nothing if -q, otherwise yes).

Quoted 5 lines
cmds/quota.c +0 -0
 		fflush(stdout);
 	} else if (ret < 0 && (!wait_for_completion || e != EINPROGRESS)) {
 		error("quota rescan failed: %m");
Signature · 1 line
2.25.1
author
#3 lore raw

Re: [PATCH 1/8] btrfs-progs: quota rescan: add quiet option

Quoted 26 lines · David Sterba
Quoted 25 lines · Anand Jain

Enable the quiet option to the btrfs(8) quota rescan command. Does the job quietly. For example:

   btrfs --quiet quota rescan
---
  cmds/quota.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
cmds/quota.c +2 -0
index 075fc79816ad..4a68f9db081b 100644
@@ -108,6 +108,8 @@ static const char * const cmd_quota_rescan_usage[] = {
  	"",
  	"-s   show status of a running rescan operation",
  	"-w   wait for rescan operation to finish (can be already in progress)",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_QUIET,
  	NULL
  };
 
@@ -172,7 +174,7 @@ static int cmd_quota_rescan(const struct cmd_struct *cmd, int argc, char **argv)
  	}
 
Quoted 7 lines

cmds/quota.c static int cmd_quota_rescan(const struct cmd_struct *cmd, int argc, char **argv) · line 177

Quoted 3 lines
cmds/quota.c +1 -1
  	if (ret == 0) {
-		printf("quota rescan started\n");
+		pr_verbose(-1, "quota rescan started\n");

That the raw value -1 is used here is not nice, I assume it means print unless there was another setting of the verbosity (nothing if -q, otherwise yes).

Yes that's right. In v3 I have defined -1 as

#define MUST_LOG -1

I ran out of ideas to name it more sensibly, open to suggestions.

Quoted 6 lines
Quoted 6 lines
cmds/quota.c +0 -0
  		fflush(stdout);
  	} else if (ret < 0 && (!wait_for_completion || e != EINPROGRESS)) {
  		error("quota rescan failed: %m");
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH 1/8] btrfs-progs: quota rescan: add quiet option

Quoted 35 lines · Anand Jain
Quoted 26 lines · David Sterba
Quoted 25 lines · Anand Jain

Enable the quiet option to the btrfs(8) quota rescan command. Does the job quietly. For example:

   btrfs --quiet quota rescan
---
  cmds/quota.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
cmds/quota.c +2 -0
index 075fc79816ad..4a68f9db081b 100644
@@ -108,6 +108,8 @@ static const char * const cmd_quota_rescan_usage[] = {
  	"",
  	"-s   show status of a running rescan operation",
  	"-w   wait for rescan operation to finish (can be already in progress)",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_QUIET,
  	NULL
  };
 
@@ -172,7 +174,7 @@ static int cmd_quota_rescan(const struct cmd_struct *cmd, int argc, char **argv)
  	}
 
Quoted 7 lines

cmds/quota.c static int cmd_quota_rescan(const struct cmd_struct *cmd, int argc, char **argv) · line 177

Quoted 3 lines
cmds/quota.c +1 -1
  	if (ret == 0) {
-		printf("quota rescan started\n");
+		pr_verbose(-1, "quota rescan started\n");

That the raw value -1 is used here is not nice, I assume it means print unless there was another setting of the verbosity (nothing if -q, otherwise yes).

Quoted 5 lines

Yes that's right. In v3 I have defined -1 as

  #define MUST_LOG  -1

I ran out of ideas to name it more sensibly, open to suggestions.

Ok, sounds reasonable to me. It can be documented and used only for the messages that must be printed due to backward compatibility.

I have merged the first part to devel, so please send this patchset once you have it ready.

author
#5 lore raw

PATCH 2/8 btrfs-progs: subvolume create: add quiet option

In reply to Anand Jain

Enable the quiet option to the btrfs(8) subvolume create command. Does the job quietly. For example:
btrfs --quiet subvolume create <path>

---
 cmds/subvolume.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
cmds/subvolume.c +3 -1
index 279c75d0669a..ed3a3ab48ec7 100644
@@ -88,6 +88,8 @@ static const char * const cmd_subvol_create_usage[] = {
 	"",
 	"-i <qgroupid>  add the newly created subvolume to a qgroup. This",
 	"               option can be given multiple times.",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
@@ -169,7 +171,7 @@ static int cmd_subvol_create(const struct cmd_struct *cmd,
 	if (fddst < 0)
 		goto out;
 
-	printf("Create subvolume '%s/%s'\n", dstdir, newname);
+	pr_verbose(-1, "Create subvolume '%s/%s'\n", dstdir, newname);
 	if (inherit) {
 		struct btrfs_ioctl_vol_args_v2	args;
 
Signature · 1 line
2.25.1
author
#6 lore raw

PATCH 3/8 btrfs-progs: subvolume delete: add quiet option

In reply to Anand Jain

Enable the quiet option to the btrfs(8) subvolume delete command. Does the job quietly. For example:

	btrfs --quiet subvolume delete <path>

Also, fix a line with over 80 char with proper indentation.

---
 cmds/subvolume.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
cmds/subvolume.c +4 -4
index ed3a3ab48ec7..9c8fe35a2aae 100644
@@ -359,14 +359,14 @@ again:
 		goto out;
 	}
 
-	printf("Delete subvolume (%s): ",
-		commit_mode == COMMIT_EACH || (commit_mode == COMMIT_AFTER && cnt + 1 == argc)
+	pr_verbose(-1, "Delete subvolume (%s): ",
+commit_mode == COMMIT_EACH || (commit_mode == COMMIT_AFTER && cnt + 1 == argc)
 		? "commit" : "no-commit");
 
 	if (subvolid == 0)
-		printf("'%s/%s'\n", dname, vname);
+		pr_verbose(-1, "'%s/%s'\n", dname, vname);
 	else
-		printf("'%s'\n", full_subvolpath);
+		pr_verbose(-1, "'%s'\n", full_subvolpath);
 
 	if (subvolid == 0)
 		err = btrfs_util_delete_subvolume_fd(fd, vname, 0);
Signature · 1 line
2.25.1
author
#7 lore raw

PATCH 4/8 btrfs-progs: balance start: add quiet option

In reply to Anand Jain

Enable the quiet option to the btrfs(8) balance start command. Does the job quietly. For example:

	btrfs -q balance start --full-balance <path>
---
 cmds/balance.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
cmds/balance.c +5 -3
index b35d90dc362a..154f54c3e3a6 100644
@@ -470,9 +470,10 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
 	} else if (ret > 0) {
 		error("balance: %s", btrfs_err_str(ret));
 	} else {
-		printf("Done, had to relocate %llu out of %llu chunks\n",
-		       (unsigned long long)args->stat.completed,
-		       (unsigned long long)args->stat.considered);
+		pr_verbose(-1,
+			   "Done, had to relocate %llu out of %llu chunks\n",
+			   (unsigned long long)args->stat.completed,
+			   (unsigned long long)args->stat.considered);
 	}
 
 out:
@@ -501,6 +502,7 @@ static const char * const cmd_balance_start_usage[] = {
 	"               run the balance as a background process",
 	HELPINFO_INSERT_GLOBALS,
 	HELPINFO_INSERT_VERBOSE,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
Signature · 1 line
2.25.1
author
#8 lore raw

PATCH 5/8 btrfs-progs: balance resume: add quiet option

In reply to Anand Jain

Enable the quiet option to the btrfs(8) balance resume command. Does the job quietly. For example:
btrfs -q balance resume <path>

---
 cmds/balance.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
cmds/balance.c +6 -3
index 154f54c3e3a6..cf22aa13533b 100644
@@ -769,6 +769,8 @@ static DEFINE_SIMPLE_COMMAND(balance_cancel, "cancel");
 static const char * const cmd_balance_resume_usage[] = {
 	"btrfs balance resume <path>",
 	"Resume interrupted balance",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
@@ -817,9 +819,10 @@ static int cmd_balance_resume(const struct cmd_struct *cmd,
 			ret = 1;
 		}
 	} else {
-		printf("Done, had to relocate %llu out of %llu chunks\n",
-		       (unsigned long long)args.stat.completed,
-		       (unsigned long long)args.stat.considered);
+		pr_verbose(-1,
+			   "Done, had to relocate %llu out of %llu chunks\n",
+			   (unsigned long long)args.stat.completed,
+			   (unsigned long long)args.stat.considered);
 	}
 
 	close_file_or_dir(fd, dirstream);
Signature · 1 line
2.25.1
author
#9 lore raw

PATCH 6/8 btrfs-progs: subvolume snapshot: add quiet option

In reply to Anand Jain

Enable the quiet option to the btrfs(8) subvolume snapshot command. Does the job quietly. For example:
btrfs -q subvolume snapshot <src> <dest>

---
 cmds/subvolume.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
cmds/subvolume.c +8 -4
index 9c8fe35a2aae..dbfa40d1549a 100644
@@ -669,6 +669,8 @@ static const char * const cmd_subvol_snapshot_usage[] = {
 	"-r             create a readonly snapshot",
 	"-i <qgroupid>  add the newly created snapshot to a qgroup. This",
 	"               option can be given multiple times.",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
@@ -783,11 +785,13 @@ static int cmd_subvol_snapshot(const struct cmd_struct *cmd,
 
 	if (readonly) {
 		args.flags |= BTRFS_SUBVOL_RDONLY;
-		printf("Create a readonly snapshot of '%s' in '%s/%s'\n",
-		       subvol, dstdir, newname);
+		pr_verbose(-1,
+			   "Create a readonly snapshot of '%s' in '%s/%s'\n",
+			   subvol, dstdir, newname);
 	} else {
-		printf("Create a snapshot of '%s' in '%s/%s'\n",
-		       subvol, dstdir, newname);
+		pr_verbose(-1,
+			   "Create a snapshot of '%s' in '%s/%s'\n",
+			   subvol, dstdir, newname);
 	}
 
 	args.fd = fd;
Signature · 1 line
2.25.1
author
#10 lore raw

PATCH 7/8 btrfs-progs: scrub start|resume: use global quiet option

In reply to Anand Jain

Transpire global --quiet option down to the btrfs scrub start|resume sub-command.

Now either/both of the following quiet options work.
btrfs -q scrub start <path>
and
btrfs scrub start -q <path>

btrfs -q scrub resume <path>
and
btrfs scrub resume -q <path>

---
 cmds/scrub.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
cmds/scrub.c +12 -9
index 9fe598222f0f..e3b6427b47ae 100644
@@ -1141,7 +1141,7 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
 	int do_background = 1;
 	int do_wait = 0;
 	int do_print = 0;
-	int do_quiet = 0;
+	int do_quiet = !bconf.verbose; /*Read the global quiet option if set*/
 	int do_record = 1;
 	int readonly = 0;
 	int do_stats_per_dev = 0;
@@ -1184,7 +1184,8 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
 			do_stats_per_dev = 1;
 			break;
 		case 'q':
-			do_quiet = 1;
+			bconf_be_quiet();
+			do_quiet = !bconf.verbose;
 			break;
 		case 'r':
 			readonly = 1;
@@ -1330,9 +1331,8 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
 	}
 
 	if (!n_start && !n_resume) {
-		if (!do_quiet)
-			printf("scrub: nothing to resume for %s, fsid %s\n",
-			       path, fsid);
+		pr_verbose(-1, "scrub: nothing to resume for %s, fsid %s\n",
+			   path, fsid);
 		nothing_to_resume = 1;
 		goto out;
 	}
@@ -1403,10 +1403,9 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
 		if (pid) {
 			int stat;
 			scrub_handle_sigint_parent();
-			if (!do_quiet)
-				printf("scrub %s on %s, fsid %s (pid=%d)\n",
-				       n_start ? "started" : "resumed",
-				       path, fsid, pid);
+			pr_verbose(-1, "scrub %s on %s, fsid %s (pid=%d)\n",
+				   n_start ? "started" : "resumed",
+				   path, fsid, pid);
 			if (!do_wait) {
 				err = 0;
 				goto out;
@@ -1611,6 +1610,8 @@ static const char * const cmd_scrub_start_usage[] = {
 	"-n     set ioprio classdata (see ionice(1) manpage)",
 	"-f     force starting new scrub even if a scrub is already running",
 	"       this is useful when scrub stats record file is damaged",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
@@ -1678,6 +1679,8 @@ static const char * const cmd_scrub_resume_usage[] = {
 	"-R     raw print mode, print full data instead of summary",
 	"-c     set ioprio class (see ionice(1) manpage)",
 	"-n     set ioprio classdata (see ionice(1) manpage)",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
Signature · 1 line
2.25.1
author
#11 lore raw

PATCH 8/8 btrfs-progs: scrub cancel: add quiet option

In reply to Anand Jain

Enable the quiet option to the btrfs(8) scrub cancel command. Does the job quietly. For example:
btrfs -q scrub cancel <mnt>

---
 cmds/scrub.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
cmds/scrub.c +3 -1
index e3b6427b47ae..3256f20121ae 100644
@@ -1624,6 +1624,8 @@ static DEFINE_SIMPLE_COMMAND(scrub_start, "start");
 static const char * const cmd_scrub_cancel_usage[] = {
 	"btrfs scrub cancel <path>|<device>",
 	"Cancel a running scrub",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
@@ -1660,7 +1662,7 @@ static int cmd_scrub_cancel(const struct cmd_struct *cmd, int argc, char **argv)
 	}
 
 	ret = 0;
-	printf("scrub cancelled\n");
+	pr_verbose(-1, "scrub cancelled\n");
 
 out:
 	close_file_or_dir(fdmnt, dirstream);
Signature · 1 line
2.25.1