linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/16] btrfs-progs: global verbose and quiet option
@ 2019-11-25 10:39 Anand Jain
  2019-11-25 10:39 ` [PATCH 01/16] btrfs-progs: split global help HELPINFO_INSERT_GLOBALS Anand Jain
                   ` (20 more replies)
  0 siblings, 21 replies; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

v1.1->v2:
Mainly:
 . Splits define HELPINFO_INSERT_GLOBALS from --format option and
 . Rename HELPINFO_GLOBAL_OPTIONS_HEADER to HELPINFO_INSERT_GLOBALS
 . Create and use helper bconf_be_verbose() and bconf_be_quiet().
 . Use gobal bconf.verbose where possible and drop local verbose argument passing.
 . In some patches the bconf.verbose initialization wasn't necessary so drop it.
Some small fixes as mentioned in the individual patch.

v1->v1.1:
 . Fix typo in HELPINFO_INSERT_QUIET.
 . Remove #include <stdbool.h> where its no more required.
   (was needed when %bconf.verbose was declared as bool).
 . Use pr_verbose(-1,..) instead of all conditions printf()
 . Use pr_verbose(1,..) instead of pr_verbose(true,..)

verbosity sample code as in v1.1

global init
-----------
        bconf.verbose = -1; //-1:default, 0:quiet, >1:verbose

at global options
-----------------
	case 'v':
		bconf.verbose < 0 ? bconf.verbose = 1 : bconf.verbose++;
		break;
	case 'q':
		bconf.verbose = 0;
		break;

sub-command init
----------------
For send/receive only (special cases, default verbosity is 1):

	if (bconf.verbose < 0)
		bconf.verbose = 1;
	else if (bconf.verbose > 0)
		bconf.verbose++;

Non-send/receive:
default verbosity is 0 (ref: cmds/rescue.c)
	if (bconf.verbose < 0)
		bconf.verbose = 0;

at sub-command options
----------------------
	case 'v':
		bconf.verbose++;
		break;
	case 'q':
		bconf.verbose = 0;
		break;


pr_verbose()
------------
/*
 * level -1: prints message unless bconf.verbose == 0;
 * level  0: quiet
 * level >0: prints message only if <= bconf.verbose
 */
void pr_verbose(int level, const char *fmt, ...)
{
        va_list args;

        if (level == 0 || bconf.verbose == 0)
                return;

        if (level > bconf.verbose)
                return;

        va_start(args, fmt);
        vfprintf(stdout, fmt, args);
        va_end(args);
}


RFC->v1:
. Adds --quiet option to the global btrfs(8) command.
. Used global struct bconf.
. Refactored pr_verbose(), accepts level (int) as argument, so now the
sub-command can specify the verbose level at which the particular
verbose messages has to be printed.
. Added global help defines.

Kindly note the following:-

1.
 There are certain sub-commands which does not have any verbose output
 or quiet output. However if the global options were used with those
 sub-commands then the command shall not report any usage error. Or
 my question is should it error out.? For example:
  (with the patch) btrfs --verbose device ready /dev/sdb
 actually there isn't any verbose output but we won't error out.
 Similarly,
  (without the patch) btrfs send -vvvvv will not show usage error
  as well.
  So I believe this is fine. IMO.

2.
  There is slight difference in output when global options are used
  as compared to the output using the same sequence of options at the
  sub-command level. For example:

   btrfs send -v -q -v  is-equal-to  btrfs send
   But same sequence in the global option
   btrfs -v -q -v send is-not-equal-to btrfs send
   but is-equal-to btrfs -v send or btrfs send -v.
   (similarly applies to receive as well).

  which IMO is fair expectation as -v is ending last.


RFC:
This patch set brings --verbose option to the top level btrfs command,
such as 'btrfs --verbose'. With this we don't have to add or remember
verbose option at the sub-commands level.

As there are already verbose options to 11 sub-commands as listed
below [1][2]. So the top level --verbose option here takes care to transpire
verbose request from the top level to the sub-command level for 9 (not 11)
sub-commands as in [1] as of now.

This patch is RFC still for the following two reasons (comments appreciated).

1.
The sub-commands as in [2] uses multi-level compile time verbose option,
such as %g_verbose = 0 (quite), %g_verbose = 1 (default), %g_verbose > 1
(real-verbose). And verbose at default is also part the .out files in
fstests. So it needs further discussions on how to handle the multi-
level verbose option using the global verbose option, and so sub-
commands in [2] are untouched.

2.
These patch has been unit-tested individually.
These patches does not alter the verbose output.
But it fixes the indentation in the command's help output, which may be
used in fstests and btrfs-progs/tests and their verification is pending
still, which I am planning to do it before v1.

[1]
btrfs subvolume delete --help
        -v|--verbose           verbose output of operations
btrfs filesystem defragment --help
        -v                  be verbose
btrfs balance start --help
        -v|--verbose        be verbose
btrfs balance status --help
        -v|--verbose        be verbose
btrfs rescue chunk-recover --help
        -v      Verbose mode
btrfs rescue super-recover --help
        -v      Verbose mode
btrfs restore --help
        -v|--verbose         verbose
btrfs inspect-internal inode-resolve --help
        -v   verbose mode
btrfs inspect-internal logical-resolve --help
        -v          verbose mode

[2]
btrfs send --help
        -v|--verbose     enable verbose output to stderr, each occurrence of
btrfs receive --help
        -v               increase verbosity about performed action



Anand Jain (16):
  btrfs-progs: split global help HELPINFO_INSERT_GLOBALS
  btrfs-progs: add global verbose and quiet options and helper functions
  btrfs-progs: send: use global verbose and quiet options
  btrfs-progs: receive: use global verbose and quiet options
  btrfs-progs: subvolume delete: use global verbose option
  btrfs-progs: filesystem defragment: use global verbose option
  btrfs-progs: balance start: use global verbose option
  btrfs-progs: balance status: use global verbose option
  btrfs-progs: rescue chunk-recover: use global verbose option
  btrfs-progs: rescue super-recover: use global verbose option
  btrfs-progs: restore: use global verbose option
  btrfs-progs: inspect-internal inode-resolve: use global verbose
  btrfs-progs: inspect-internal logical-resolve: use global verbose
    option
  btrfs-progs: refactor btrfs_scan_devices() to accept verbose argument
  btrfs-progs: device scan: add verbose option
  btrfs-progs: device scan: add quiet option

 btrfs.c                     | 20 ++++++++++--
 cmds/balance.c              | 14 ++++----
 cmds/device.c               |  7 ++--
 cmds/filesystem.c           | 14 ++++----
 cmds/inspect.c              | 41 +++++++++++------------
 cmds/receive.c              | 80 +++++++++++++++++++++++++--------------------
 cmds/rescue-chunk-recover.c |  9 +++--
 cmds/rescue-super-recover.c |  7 ++--
 cmds/rescue.c               | 18 ++++++----
 cmds/rescue.h               |  4 +--
 cmds/restore.c              | 53 +++++++++++++-----------------
 cmds/send.c                 | 33 ++++++++++++-------
 cmds/subvolume.c            | 28 ++++++++--------
 common/device-scan.c        |  3 +-
 common/device-scan.h        |  2 +-
 common/help.c               |  4 +--
 common/help.h               |  9 ++++-
 common/messages.c           | 25 ++++++++++++++
 common/messages.h           |  3 ++
 common/utils.c              | 16 ++++++++-
 common/utils.h              | 11 +++++++
 disk-io.c                   |  2 +-
 22 files changed, 245 insertions(+), 158 deletions(-)

-- 
1.8.3.1


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

* [PATCH 01/16] btrfs-progs: split global help HELPINFO_INSERT_GLOBALS
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2019-11-25 10:39 ` [PATCH v2 02/16] btrfs-progs: add global verbose and quiet options and helper functions Anand Jain
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

As of now the define HELPINFO_INSERT_GLOBALS if used as in the example
as below (as of now its not been used anywhere) will print the help
texts as shown below

#diff --git a/cmds/filesystem.c b/cmds/filesystem.c
#index 4f22089abeaa..564dc40cc99a 100644
#--- a/cmds/filesystem.c
#+++ b/cmds/filesystem.c
#@@ -631,6 +631,7 @@ static const char * const
#cmd_filesystem_show_usage[] = {
#        "-m|--mounted       show only mounted btrfs",
#        HELPINFO_UNITS_LONG,
#        "If no argument is given, structure of all present filesystems
#is shown.",
#+       HELPINFO_INSERT_GLOBALS,
#        NULL
# };
#
$ ./btrfs fi show --help

 <snip>

    Global options:
    --format TYPE      where TYPE is: text

$

So in preparation to add --verbose and --quiet global options, and
apparently --format is not being used yet, this patch splits the global
options into two defines.

                                       "Global options:"

So that the currently added global options --verbose and --quiet can use
the define HELPINFO_INSERT_GLOBALS header as shown below.

(For example:)
$ ./btrfs fi show --help
<snip>

    Global options:

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 common/help.c | 4 +---
 common/help.h | 4 +++-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/common/help.c b/common/help.c
index 189a1d3545c2..78f6ee99597c 100644
--- a/common/help.c
+++ b/common/help.c
@@ -209,15 +209,13 @@ static int do_usage_one_command(const char * const *usagestr,
 	fputc('\n', outf);
 
 	while (*usagestr) {
-		if (strcmp(*usagestr, HELPINFO_INSERT_GLOBALS) == 0) {
+		if (strcmp(*usagestr, HELPINFO_INSERT_FORMAT) == 0) {
 			int i;
 
-			fputc('\n', outf);
 			/*
 			 * We always support text, that's on by default for all
 			 * commands
 			 */
-			fprintf(outf, "%*sGlobal options:\n", pad, "");
 			fprintf(outf, "%*s--format TYPE      where TYPE is: %s",
 					pad, "", output_formats[0].name);
 			for (i = 1; i < ARRAY_SIZE(output_formats); i++) {
diff --git a/common/help.h b/common/help.h
index 01dfc68a7c8d..91874abfe207 100644
--- a/common/help.h
+++ b/common/help.h
@@ -57,7 +57,9 @@
  * options and then continue with the following text that possibly follows
  * after the regular options
  */
-#define HELPINFO_INSERT_GLOBALS		"INSERT_GLOBALS"
+#define HELPINFO_INSERT_GLOBALS		"",					\
+					"Global options:"
+#define HELPINFO_INSERT_FORMAT		"--foramt TYPE"
 
 struct cmd_struct;
 struct cmd_group;
-- 
1.8.3.1


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

* [PATCH v2 02/16] btrfs-progs: add global verbose and quiet options and helper functions
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
  2019-11-25 10:39 ` [PATCH 01/16] btrfs-progs: split global help HELPINFO_INSERT_GLOBALS Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2020-06-12 10:56   ` [PATCH v3 " Anand Jain
  2019-11-25 10:39 ` [PATCH v2 03/16] btrfs-progs: send: use global verbose and quiet options Anand Jain
                   ` (18 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

Add btrfs(8) global --verbose and --quiet command options to show
verbose or no output from the sub-commands.
By introducing global a %bconf::verbose memeber to transpire the same
down to the sub-command.
Further the added helper function pr_verbose() helps to logs the verbose
messages, based on the state of the %bconf::verbose. And further HELPINFO_
defines are provides for the usage.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2:
  Add missing -q along with --quiet.
  Create and use bconf_be_verbose() and bconf_be_quiet().
  Change help wordings for verbose and quiet.
  Define and use BTRFS_BCONF_UNSET and BTRFS_BCONF_QUIET.
  Use HELPINFO_INSERT_GLOBALS.

 btrfs.c           | 20 ++++++++++++++++++--
 common/help.h     |  5 +++++
 common/messages.c | 25 +++++++++++++++++++++++++
 common/messages.h |  3 +++
 common/utils.c    | 14 ++++++++++++++
 common/utils.h    | 11 +++++++++++
 6 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/btrfs.c b/btrfs.c
index 72dad6fb3983..eb3b6183eb21 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -27,7 +27,7 @@
 #include "common/box.h"
 
 static const char * const btrfs_cmd_group_usage[] = {
-	"btrfs [--help] [--version] [--format <format>] <group> [<group>...] <command> [<args>]",
+	"btrfs [--help] [--version] [--format <format>] [-v|--verbose] [-q|--quiet] <group> [<group>...] <command> [<args>]",
 	NULL
 };
 
@@ -248,6 +248,8 @@ static int handle_global_options(int argc, char **argv)
 		{ "version", no_argument, NULL, OPT_VERSION },
 		{ "format", required_argument, NULL, OPT_FORMAT },
 		{ "full", no_argument, NULL, OPT_FULL },
+		{ "verbose", no_argument, NULL, 'v' },
+		{ "quiet", no_argument, NULL, 'q' },
 		{ NULL, 0, NULL, 0}
 	};
 	int shift;
@@ -259,7 +261,7 @@ static int handle_global_options(int argc, char **argv)
 	while (1) {
 		int c;
 
-		c = getopt_long(argc, argv, "+", long_options, NULL);
+		c = getopt_long(argc, argv, "+vq", long_options, NULL);
 		if (c < 0)
 			break;
 
@@ -270,6 +272,12 @@ static int handle_global_options(int argc, char **argv)
 		case OPT_FORMAT:
 			handle_output_format(optarg);
 			break;
+		case 'v':
+			bconf_be_verbose();
+			break;
+		case 'q':
+			bconf_be_quiet();
+			break;
 		default:
 			fprintf(stderr, "Unknown global option: %s\n",
 					argv[optind - 1]);
@@ -310,6 +318,14 @@ static void handle_special_globals(int shift, int argc, char **argv)
 			cmd_execute(&cmd_struct_version, argc, argv);
 			exit(0);
 		}
+
+	for (i = 0; i < shift; i++)
+		if (strcmp(argv[i], "--verbose") == 0)
+			bconf_be_verbose();
+
+	for (i = 0; i < shift; i++)
+		if (strcmp(argv[i], "--quiet") == 0)
+			bconf_be_quiet();
 }
 
 static const struct cmd_group btrfs_cmd_group = {
diff --git a/common/help.h b/common/help.h
index 91874abfe207..dbc5259d2277 100644
--- a/common/help.h
+++ b/common/help.h
@@ -60,6 +60,11 @@
 #define HELPINFO_INSERT_GLOBALS		"",					\
 					"Global options:"
 #define HELPINFO_INSERT_FORMAT		"--foramt TYPE"
+/*
+ * Global verbose option for the sub-commands
+ */
+#define HELPINFO_INSERT_VERBOSE	"-v|--verbose       increase output verbosity"
+#define HELPINFO_INSERT_QUIET	"-q|--quiet         print only errors"
 
 struct cmd_struct;
 struct cmd_group;
diff --git a/common/messages.c b/common/messages.c
index 0e5694ecd467..95e705dbe754 100644
--- a/common/messages.c
+++ b/common/messages.c
@@ -17,6 +17,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include "common/messages.h"
+#include "common/utils.h"
 
 __attribute__ ((format (printf, 1, 2)))
 void __btrfs_warning(const char *fmt, ...)
@@ -75,3 +76,27 @@ int __btrfs_error_on(int condition, const char *fmt, ...)
 
 	return 1;
 }
+
+/*
+ * Print verbose helper function
+ * level: Minimum verbose level at which the message has to be printed.
+ */
+__attribute__ ((format (printf, 2, 3)))
+void pr_verbose(int level, const char *fmt, ...)
+{
+	va_list args;
+
+	if (bconf.verbose == BTRFS_BCONF_QUIET || level == BTRFS_BCONF_QUIET)
+		return;
+
+	/*
+	 * level is set by the threads requesting to print only if the command
+	 * verbose option is higher than the level.
+	 */
+	if (bconf.verbose < level)
+		return;
+
+	va_start(args, fmt);
+	vfprintf(stdout, fmt, args);
+	va_end(args);
+}
diff --git a/common/messages.h b/common/messages.h
index 596047948fef..f802a9413265 100644
--- a/common/messages.h
+++ b/common/messages.h
@@ -96,3 +96,6 @@ __attribute__ ((format (printf, 2, 3)))
 int __btrfs_error_on(int condition, const char *fmt, ...);
 
 #endif
+
+__attribute__ ((format (printf, 2, 3)))
+void pr_verbose(int level, const char *fmt, ...);
diff --git a/common/utils.c b/common/utils.c
index 4ce3683640d2..4b5d40b2bc56 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -1679,6 +1679,20 @@ u8 rand_u8(void)
 void btrfs_config_init(void)
 {
 	bconf.output_format = CMD_FORMAT_TEXT;
+	bconf.verbose = BTRFS_BCONF_UNSET;
+}
+
+void bconf_be_verbose(void)
+{
+	if (bconf.verbose == BTRFS_BCONF_UNSET)
+		bconf.verbose = 1;
+	else
+		bconf.verbose++;
+}
+
+void bconf_be_quiet(void)
+{
+	bconf.verbose = BTRFS_BCONF_QUIET;
 }
 
 /* Returns total size of main memory in bytes, -1UL if error. */
diff --git a/common/utils.h b/common/utils.h
index c31da330efa7..cecad6cfc7f9 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -117,16 +117,27 @@ unsigned long total_memory(void);
 void print_device_info(struct btrfs_device *device, char *prefix);
 void print_all_devices(struct list_head *devices);
 
+#define BTRFS_BCONF_UNSET	-1
+#define BTRFS_BCONF_QUIET	 0
 /*
  * Global program state, configurable by command line and available to
  * functions without extra context passing.
  */
 struct btrfs_config {
 	unsigned int output_format;
+
+	/* values
+	 *   BTRFS_BCONF_QUIET
+	 *   BTRFS_BCONF_UNSET
+	 *   > 0: Verbose level
+	 */
+	int verbose;
 };
 extern struct btrfs_config bconf;
 
 void btrfs_config_init(void);
+void bconf_be_verbose(void);
+void bconf_be_quiet(void);
 
 /* Pseudo random number generator wrappers */
 int rand_int(void);
-- 
1.8.3.1


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

* [PATCH v2 03/16] btrfs-progs: send: use global verbose and quiet options
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
  2019-11-25 10:39 ` [PATCH 01/16] btrfs-progs: split global help HELPINFO_INSERT_GLOBALS Anand Jain
  2019-11-25 10:39 ` [PATCH v2 02/16] btrfs-progs: add global verbose and quiet options and helper functions Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2020-06-12 10:58   ` [PATCH v3 " Anand Jain
  2019-11-25 10:39 ` [PATCH v2 04/16] btrfs-progs: receive: " Anand Jain
                   ` (17 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

Transpire global --verbose and --quiet options down to the btrfs send
sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Use new helper function and defines
    HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
    bconf_be_verbose(), bconf_be_quiet()

 cmds/send.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/cmds/send.c b/cmds/send.c
index 7ce6c3273857..93e731d56f54 100644
--- a/cmds/send.c
+++ b/cmds/send.c
@@ -48,11 +48,6 @@
 
 #define SEND_BUFFER_SIZE	SZ_64K
 
-/*
- * Default is 1 for historical reasons, changing may break scripts that expect
- * the 'At subvol' message.
- */
-static int g_verbose = 1;
 
 struct btrfs_send {
 	int send_fd;
@@ -292,10 +287,10 @@ static int do_send(struct btrfs_send *send, u64 parent_root_id,
 				"Try upgrading your kernel or don't use -e.\n");
 		goto out;
 	}
-	if (g_verbose > 1)
+	if (bconf.verbose > 1)
 		fprintf(stderr, "BTRFS_IOC_SEND returned %d\n", ret);
 
-	if (g_verbose > 1)
+	if (bconf.verbose > 1)
 		fprintf(stderr, "joining genl thread\n");
 
 	close(pipefd[1]);
@@ -460,6 +455,9 @@ static const char * const cmd_send_usage[] = {
 	"-v|--verbose     enable verbose output to stderr, each occurrence of",
 	"                 this option increases verbosity",
 	"-q|--quiet       suppress all messages, except errors",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
@@ -482,6 +480,17 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv)
 	send.dump_fd = fileno(stdout);
 	outname[0] = 0;
 
+	/*
+	 * For send, verbose default is 1 (insteasd of 0) for historical reasons,
+	 * changing may break scripts that expect the 'At subvol' message. But do
+	 * it only when bconf.verbose is unset (-1) and also adjust the value,
+	 * if global verbose is already set.
+	 */
+	if (bconf.verbose == BTRFS_BCONF_UNSET)
+		bconf.verbose = 1;
+	else if (bconf.verbose > BTRFS_BCONF_QUIET)
+		bconf.verbose++;
+
 	optind = 0;
 	while (1) {
 		enum { GETOPT_VAL_SEND_NO_DATA = 256 };
@@ -497,10 +506,10 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv)
 
 		switch (c) {
 		case 'v':
-			g_verbose++;
+			bconf_be_verbose();
 			break;
 		case 'q':
-			g_verbose = 0;
+			bconf_be_quiet();
 			break;
 		case 'e':
 			new_end_cmd_semantic = 1;
@@ -680,8 +689,8 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv)
 		}
 	}
 
-	if ((send_flags & BTRFS_SEND_FLAG_NO_FILE_DATA) && g_verbose > 1)
-		if (g_verbose > 1)
+	if ((send_flags & BTRFS_SEND_FLAG_NO_FILE_DATA) && bconf.verbose > 1)
+		if (bconf.verbose > 1)
 			fprintf(stderr, "Mode NO_FILE_DATA enabled\n");
 
 	for (i = optind; i < argc; i++) {
@@ -691,7 +700,7 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv)
 		free(subvol);
 		subvol = argv[i];
 
-		if (g_verbose > 0)
+		if (bconf.verbose > BTRFS_BCONF_QUIET)
 			fprintf(stderr, "At subvol %s\n", subvol);
 
 		subvol = realpath(subvol, NULL);
-- 
1.8.3.1


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

* [PATCH v2 04/16] btrfs-progs: receive: use global verbose and quiet options
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (2 preceding siblings ...)
  2019-11-25 10:39 ` [PATCH v2 03/16] btrfs-progs: send: use global verbose and quiet options Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2020-06-12 11:24   ` [PATCH v3 " Anand Jain
  2019-11-25 10:39 ` [PATCH v2 05/16] btrfs-progs: subvolume delete: use global verbose option Anand Jain
                   ` (16 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

Transpire global --verbose and --quiet options down to the btrfs receive
sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Use new helper functions and defines
    HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
    bconf_be_verbose(), bconf_be_quiet()

 cmds/receive.c | 80 ++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 44 insertions(+), 36 deletions(-)

diff --git a/cmds/receive.c b/cmds/receive.c
index c4827c1dd999..0e6f0e25fa51 100644
--- a/cmds/receive.c
+++ b/cmds/receive.c
@@ -53,12 +53,6 @@
 #include "common/help.h"
 #include "common/path-utils.h"
 
-/*
- * Default is 1 for historical reasons, changing may break scripts that expect
- * the 'At subvol' message.
- */
-static int g_verbose = 1;
-
 struct btrfs_receive
 {
 	int mnt_fd;
@@ -116,7 +110,7 @@ static int finish_subvol(struct btrfs_receive *rctx)
 	memcpy(rs_args.uuid, rctx->cur_subvol.received_uuid, BTRFS_UUID_SIZE);
 	rs_args.stransid = rctx->cur_subvol.stransid;
 
-	if (g_verbose >= 2) {
+	if (bconf.verbose >= 2) {
 		uuid_unparse((u8*)rs_args.uuid, uuid_str);
 		fprintf(stderr, "BTRFS_IOC_SET_RECEIVED_SUBVOL uuid=%s, "
 				"stransid=%llu\n", uuid_str, rs_args.stransid);
@@ -199,13 +193,13 @@ static int process_subvol(const char *path, const u8 *uuid, u64 ctransid,
 		goto out;
 	}
 
-	if (g_verbose)
+	if (bconf.verbose > BTRFS_BCONF_QUIET)
 		fprintf(stderr, "At subvol %s\n", path);
 
 	memcpy(rctx->cur_subvol.received_uuid, uuid, BTRFS_UUID_SIZE);
 	rctx->cur_subvol.stransid = ctransid;
 
-	if (g_verbose >= 2) {
+	if (bconf.verbose >= 2) {
 		uuid_unparse((u8*)rctx->cur_subvol.received_uuid, uuid_str);
 		fprintf(stderr, "receiving subvol %s uuid=%s, stransid=%llu\n",
 				path, uuid_str,
@@ -269,13 +263,12 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
 		goto out;
 	}
 
-	if (g_verbose)
-		fprintf(stdout, "At snapshot %s\n", path);
+	pr_verbose(1, "At snapshot %s\n", path);
 
 	memcpy(rctx->cur_subvol.received_uuid, uuid, BTRFS_UUID_SIZE);
 	rctx->cur_subvol.stransid = ctransid;
 
-	if (g_verbose >= 2) {
+	if (bconf.verbose >= 2) {
 		uuid_unparse((u8*)rctx->cur_subvol.received_uuid, uuid_str);
 		fprintf(stderr, "receiving snapshot %s uuid=%s, "
 				"ctransid=%llu ", path, uuid_str,
@@ -402,7 +395,7 @@ static int process_mkfile(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mkfile %s\n", path);
 
 	ret = creat(full_path, 0600);
@@ -430,7 +423,7 @@ static int process_mkdir(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mkdir %s\n", path);
 
 	ret = mkdir(full_path, 0700);
@@ -455,7 +448,7 @@ static int process_mknod(const char *path, u64 mode, u64 dev, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mknod %s mode=%llu, dev=%llu\n",
 				path, mode, dev);
 
@@ -481,7 +474,7 @@ static int process_mkfifo(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mkfifo %s\n", path);
 
 	ret = mkfifo(full_path, 0600);
@@ -506,7 +499,7 @@ static int process_mksock(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mksock %s\n", path);
 
 	ret = mknod(full_path, 0600 | S_IFSOCK, 0);
@@ -531,7 +524,7 @@ static int process_symlink(const char *path, const char *lnk, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "symlink %s -> %s\n", path, lnk);
 
 	ret = symlink(lnk, full_path);
@@ -563,7 +556,7 @@ static int process_rename(const char *from, const char *to, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "rename %s -> %s\n", from, to);
 
 	ret = rename(full_from, full_to);
@@ -595,7 +588,7 @@ static int process_link(const char *path, const char *lnk, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "link %s -> %s\n", path, lnk);
 
 	ret = link(full_link_path, full_path);
@@ -621,7 +614,7 @@ static int process_unlink(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "unlink %s\n", path);
 
 	ret = unlink(full_path);
@@ -646,7 +639,7 @@ static int process_rmdir(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "rmdir %s\n", path);
 
 	ret = rmdir(full_path);
@@ -711,7 +704,7 @@ static int process_write(const char *path, const void *data, u64 offset,
 	if (ret < 0)
 		goto out;
 
-	if (g_verbose >= 2)
+	if (bconf.verbose >= 2)
 		fprintf(stderr, "write %s - offset=%llu length=%llu\n",
 			path, offset, len);
 
@@ -819,7 +812,7 @@ static int process_clone(const char *path, u64 offset, u64 len,
 		goto out;
 	}
 
-	if (g_verbose >= 2)
+	if (bconf.verbose >= 2)
 		fprintf(stderr,
 			"clone %s - source=%s source offset=%llu offset=%llu length=%llu\n",
 			path, clone_path, clone_offset, offset, len);
@@ -860,7 +853,7 @@ static int process_set_xattr(const char *path, const char *name,
 	}
 
 	if (strcmp("security.capability", name) == 0) {
-		if (g_verbose >= 4)
+		if (bconf.verbose >= 4)
 			fprintf(stderr, "set_xattr: cache capabilities\n");
 		if (rctx->cached_capabilities_len)
 			warning("capabilities set multiple times per file: %s",
@@ -875,7 +868,7 @@ static int process_set_xattr(const char *path, const char *name,
 		memcpy(rctx->cached_capabilities, data, len);
 	}
 
-	if (g_verbose >= 3) {
+	if (bconf.verbose >= 3) {
 		fprintf(stderr, "set_xattr %s - name=%s data_len=%d "
 				"data=%.*s\n", path, name, len,
 				len, (char*)data);
@@ -905,7 +898,7 @@ static int process_remove_xattr(const char *path, const char *name, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3) {
+	if (bconf.verbose >= 3) {
 		fprintf(stderr, "remove_xattr %s - name=%s\n",
 				path, name);
 	}
@@ -933,7 +926,7 @@ static int process_truncate(const char *path, u64 size, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "truncate %s size=%llu\n", path, size);
 
 	ret = truncate(full_path, size);
@@ -959,7 +952,7 @@ static int process_chmod(const char *path, u64 mode, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "chmod %s - mode=0%o\n", path, (int)mode);
 
 	ret = chmod(full_path, mode);
@@ -985,7 +978,7 @@ static int process_chown(const char *path, u64 uid, u64 gid, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "chown %s - uid=%llu, gid=%llu\n", path,
 				uid, gid);
 
@@ -997,7 +990,7 @@ static int process_chown(const char *path, u64 uid, u64 gid, void *user)
 	}
 
 	if (rctx->cached_capabilities_len) {
-		if (g_verbose >= 3)
+		if (bconf.verbose >= 3)
 			fprintf(stderr, "chown: restore capabilities\n");
 		ret = lsetxattr(full_path, "security.capability",
 				rctx->cached_capabilities,
@@ -1031,7 +1024,7 @@ static int process_utimes(const char *path, struct timespec *at,
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "utimes %s\n", path);
 
 	tv[0] = *at;
@@ -1050,7 +1043,7 @@ out:
 static int process_update_extent(const char *path, u64 offset, u64 len,
 		void *user)
 {
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "update_extent %s: offset=%llu, len=%llu\n",
 				path, (unsigned long long)offset,
 				(unsigned long long)len);
@@ -1190,7 +1183,7 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
 
 	while (!end) {
 		if (rctx->cached_capabilities_len) {
-			if (g_verbose >= 4)
+			if (bconf.verbose >= 4)
 				fprintf(stderr, "clear cached capabilities\n");
 			memset(rctx->cached_capabilities, 0,
 					sizeof(rctx->cached_capabilities));
@@ -1279,6 +1272,9 @@ static const char * const cmd_receive_usage[] = {
 	"                 this file system is mounted.",
 	"--dump           dump stream metadata, one line per operation,",
 	"                 does not require the MOUNT parameter",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
@@ -1301,6 +1297,18 @@ static int cmd_receive(const struct cmd_struct *cmd, int argc, char **argv)
 	realmnt[0] = 0;
 	fromfile[0] = 0;
 
+	/*
+	 * Init global verbose to default, if it is unset.
+	 * Default is 1 for historical reasons, changing may break scripts that
+	 * expect the 'At subvol' message.
+	 * As default is 1, which means the effective verbose for receive is 2
+	 * which global verbose is unaware. So adjust global verbose value here.
+	 */
+	if (bconf.verbose == BTRFS_BCONF_UNSET)
+		bconf.verbose = 1;
+	else if (bconf.verbose > BTRFS_BCONF_QUIET)
+		bconf.verbose++;
+
 	optind = 0;
 	while (1) {
 		int c;
@@ -1319,10 +1327,10 @@ static int cmd_receive(const struct cmd_struct *cmd, int argc, char **argv)
 
 		switch (c) {
 		case 'v':
-			g_verbose++;
+			bconf_be_verbose();
 			break;
 		case 'q':
-			g_verbose = 0;
+			bconf_be_quiet();
 			break;
 		case 'f':
 			if (arg_copy_path(fromfile, optarg, sizeof(fromfile))) {
-- 
1.8.3.1


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

* [PATCH v2 05/16] btrfs-progs: subvolume delete: use global verbose option
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (3 preceding siblings ...)
  2019-11-25 10:39 ` [PATCH v2 04/16] btrfs-progs: receive: " Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2020-06-12 11:24   ` [PATCH v3 " Anand Jain
  2019-11-25 10:39 ` [PATCH v2 06/16] btrfs-progs: filesystem defragment: " Anand Jain
                   ` (15 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

Transpire global --verbose option down to the btrfs subvolume delete
sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Use new helper functions and defines
    HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
    bconf_be_verbose(), bconf_be_quiet()

    No need to init bconf.verbose in the sub command.

 cmds/subvolume.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/cmds/subvolume.c b/cmds/subvolume.c
index 7a5fd79bb1f3..2174dbf29c7d 100644
--- a/cmds/subvolume.c
+++ b/cmds/subvolume.c
@@ -234,6 +234,8 @@ static const char * const cmd_subvol_delete_usage[] = {
 	"-c|--commit-after      wait for transaction commit at the end of the operation",
 	"-C|--commit-each       wait for transaction commit after deleting each subvolume",
 	"-v|--verbose           verbose output of operations",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -248,7 +250,6 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd,
 	char	*dupvname = NULL;
 	char	*path;
 	DIR	*dirstream = NULL;
-	int verbose = 0;
 	int commit_mode = 0;
 	u8 fsid[BTRFS_FSID_SIZE];
 	char uuidbuf[BTRFS_UUID_UNPARSED_SIZE];
@@ -278,7 +279,7 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd,
 			commit_mode = COMMIT_EACH;
 			break;
 		case 'v':
-			verbose++;
+			bconf_be_verbose();
 			break;
 		default:
 			usage_unknown_option(cmd, argv);
@@ -288,11 +289,9 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd,
 	if (check_argc_min(argc - optind, 1))
 		return 1;
 
-	if (verbose > 0) {
-		printf("Transaction commit: %s\n",
-			!commit_mode ? "none (default)" :
-			commit_mode == COMMIT_AFTER ? "at the end" : "after each");
-	}
+	pr_verbose(1, "Transaction commit: %s\n",
+		   !commit_mode ? "none (default)" :
+		   commit_mode == COMMIT_AFTER ? "at the end" : "after each");
 
 	cnt = optind;
 
@@ -353,11 +352,9 @@ again:
 		}
 
 		if (add_seen_fsid(fsid, seen_fsid_hash, fd, dirstream) == 0) {
-			if (verbose > 0) {
-				uuid_unparse(fsid, uuidbuf);
-				printf("  new fs is found for '%s', fsid: %s\n",
-						path, uuidbuf);
-			}
+			uuid_unparse(fsid, uuidbuf);
+			pr_verbose(1, "  new fs is found for '%s', fsid: %s\n",
+				   path, uuidbuf);
 			/*
 			 * This is the first time a subvolume on this
 			 * filesystem is deleted, keep fd in order to issue
@@ -398,10 +395,11 @@ keep_fd:
 			"unable to do final sync after deletion: %m, fsid: %s",
 						uuidbuf);
 					ret = 1;
-				} else if (verbose > 0) {
+				} else {
 					uuid_unparse(seen->fsid, uuidbuf);
-					printf("final sync is done for fsid: %s\n",
-						uuidbuf);
+					pr_verbose(1,
+					   "final sync is done for fsid: %s\n",
+						   uuidbuf);
 				}
 				seen = seen->next;
 			}
-- 
1.8.3.1


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

* [PATCH v2 06/16] btrfs-progs: filesystem defragment: use global verbose option
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (4 preceding siblings ...)
  2019-11-25 10:39 ` [PATCH v2 05/16] btrfs-progs: subvolume delete: use global verbose option Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2020-06-08  6:31   ` Anand Jain
  2020-06-12 11:25   ` [PATCH v4 " Anand Jain
  2019-11-25 10:39 ` [PATCH v2 07/16] btrfs-progs: balance start: " Anand Jain
                   ` (14 subsequent siblings)
  20 siblings, 2 replies; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

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>
---
v2: Use new helper functions and defines
    HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
    bconf_be_verbose()

    No need to init bconf.verbose in the sub command.

    Move the HELPINFO_INSERT_GLOBALS, and HELPINFO_INSERT_VERBOSE, right
    after the command options.

 cmds/filesystem.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index 4f22089abeaa..fc1736d9fe66 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -840,6 +840,8 @@ static const char * const cmd_filesystem_defrag_usage[] = {
 	"-l len              defragment only up to len bytes",
 	"-t size             target extent size hint (default: 32M)",
 	"",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	"Warning: most Linux kernels will break up the ref-links of COW data",
 	"(e.g., files copied with 'cp --reflink', snapshots) which may cause",
 	"considerable increase of space usage. See btrfs-filesystem(8) for",
@@ -848,7 +850,6 @@ static const char * const cmd_filesystem_defrag_usage[] = {
 };
 
 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;
@@ -913,7 +913,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 +930,7 @@ static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
 			flush = 1;
 			break;
 		case 'v':
-			defrag_global_verbose = 1;
+			bconf_be_verbose();
 			break;
 		case 's':
 			start = parse_size(optarg);
@@ -1031,8 +1030,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;
-- 
1.8.3.1


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

* [PATCH v2 07/16] btrfs-progs: balance start: use global verbose option
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (5 preceding siblings ...)
  2019-11-25 10:39 ` [PATCH v2 06/16] btrfs-progs: filesystem defragment: " Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2020-06-12 11:25   ` [PATCH v3 " Anand Jain
  2019-11-25 10:39 ` [PATCH v2 08/16] btrfs-progs: balance status: " Anand Jain
                   ` (13 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

Transpire global --verbose option down to the btrfs balance start
sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Use new helper functions and defines
    HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
    bconf_be_verbose(), bconf_be_quiet()

    No need to init bconf.verbose in the sub command.

 cmds/balance.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/cmds/balance.c b/cmds/balance.c
index 5392a6040a02..9c2cdacdb288 100644
--- a/cmds/balance.c
+++ b/cmds/balance.c
@@ -499,6 +499,8 @@ static const char * const cmd_balance_start_usage[] = {
 	"--full-balance do not print warning and do not delay start",
 	"--background|--bg",
 	"               run the balance as a background process",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -509,7 +511,6 @@ static int cmd_balance_start(const struct cmd_struct *cmd,
 	struct btrfs_balance_args *ptrs[] = { &args.data, &args.sys,
 						&args.meta, NULL };
 	int force = 0;
-	int verbose = 0;
 	int background = 0;
 	unsigned start_flags = 0;
 	int i;
@@ -564,7 +565,7 @@ static int cmd_balance_start(const struct cmd_struct *cmd,
 			force = 1;
 			break;
 		case 'v':
-			verbose = 1;
+			bconf_be_verbose();
 			break;
 		case GETOPT_VAL_FULL_BALANCE:
 			start_flags |= BALANCE_START_NOWARN;
@@ -640,7 +641,7 @@ static int cmd_balance_start(const struct cmd_struct *cmd,
 
 	if (force)
 		args.flags |= BTRFS_BALANCE_FORCE;
-	if (verbose)
+	if (bconf.verbose > BTRFS_BCONF_QUIET)
 		dump_ioctl_balance_args(&args);
 	if (background) {
 		switch (fork()) {
-- 
1.8.3.1


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

* [PATCH v2 08/16] btrfs-progs: balance status: use global verbose option
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (6 preceding siblings ...)
  2019-11-25 10:39 ` [PATCH v2 07/16] btrfs-progs: balance start: " Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2020-06-12 11:25   ` [PATCH v3 " Anand Jain
  2019-11-25 10:39 ` [PATCH v2 09/16] btrfs-progs: rescue chunk-recover: " Anand Jain
                   ` (12 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

Transpire global --verbose option down to the btrfs balance status
sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Use new helper functions and defines
    HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
    bconf_be_verbose(), bconf_be_quiet()

    No need to init bconf.verbose in the sub command.

 cmds/balance.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/cmds/balance.c b/cmds/balance.c
index 9c2cdacdb288..9f4ab21518de 100644
--- a/cmds/balance.c
+++ b/cmds/balance.c
@@ -828,6 +828,8 @@ static const char * const cmd_balance_status_usage[] = {
 	"Show status of running or paused balance",
 	"",
 	"-v|--verbose     be verbose",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -844,7 +846,6 @@ static int cmd_balance_status(const struct cmd_struct *cmd,
 	const char *path;
 	DIR *dirstream = NULL;
 	int fd;
-	int verbose = 0;
 	int ret;
 
 	optind = 0;
@@ -861,7 +862,7 @@ static int cmd_balance_status(const struct cmd_struct *cmd,
 
 		switch (opt) {
 		case 'v':
-			verbose = 1;
+			bconf_be_verbose();
 			break;
 		default:
 			usage_unknown_option(cmd, argv);
@@ -907,7 +908,7 @@ static int cmd_balance_status(const struct cmd_struct *cmd,
 	       (unsigned long long)args.stat.considered,
 	       100 * (1 - (float)args.stat.completed/args.stat.expected));
 
-	if (verbose)
+	if (bconf.verbose > BTRFS_BCONF_QUIET)
 		dump_ioctl_balance_args(&args);
 
 	ret = 1;
-- 
1.8.3.1


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

* [PATCH v2 09/16] btrfs-progs: rescue chunk-recover: use global verbose option
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (7 preceding siblings ...)
  2019-11-25 10:39 ` [PATCH v2 08/16] btrfs-progs: balance status: " Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2020-06-12 11:25   ` [PATCH v3 " Anand Jain
  2019-11-25 10:39 ` [PATCH v2 10/16] btrfs-progs: rescue super-recover: " Anand Jain
                   ` (11 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

Transpire global --verbose option down to the btrfs rescue chunk-recover
sub-command.

For example: Both global and local verbose options are now supported.
 btrfs -v|--verbose rescue chunk-recover
 btrfs rescue chunk-recover -v

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Use new helper functions and defines
     HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
     bconf_be_verbose(), bconf_be_quiet()
    Drop verbose argument in init_recover_control()

 cmds/rescue-chunk-recover.c |  9 ++++-----
 cmds/rescue.c               | 11 ++++++++---
 cmds/rescue.h               |  2 +-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/cmds/rescue-chunk-recover.c b/cmds/rescue-chunk-recover.c
index 171b4d07ecf9..cc7dc8c72487 100644
--- a/cmds/rescue-chunk-recover.c
+++ b/cmds/rescue-chunk-recover.c
@@ -194,8 +194,7 @@ static struct btrfs_chunk *create_chunk_item(struct chunk_record *record)
 	return ret;
 }
 
-static void init_recover_control(struct recover_control *rc, int verbose,
-		int yes)
+static void init_recover_control(struct recover_control *rc, int yes)
 {
 	memset(rc, 0, sizeof(struct recover_control));
 	cache_tree_init(&rc->chunk);
@@ -208,7 +207,7 @@ static void init_recover_control(struct recover_control *rc, int verbose,
 	INIT_LIST_HEAD(&rc->rebuild_chunks);
 	INIT_LIST_HEAD(&rc->unrepaired_chunks);
 
-	rc->verbose = verbose;
+	rc->verbose = bconf.verbose;
 	rc->yes = yes;
 	pthread_mutex_init(&rc->rc_lock, NULL);
 }
@@ -2319,14 +2318,14 @@ static void validate_rebuild_chunks(struct recover_control *rc)
 /*
  * Return 0 when successful, < 0 on error and > 0 if aborted by user
  */
-int btrfs_recover_chunk_tree(const char *path, int verbose, int yes)
+int btrfs_recover_chunk_tree(const char *path, int yes)
 {
 	int ret = 0;
 	struct btrfs_root *root = NULL;
 	struct btrfs_trans_handle *trans;
 	struct recover_control rc;
 
-	init_recover_control(&rc, verbose, yes);
+	init_recover_control(&rc, yes);
 
 	ret = recover_prepare(&rc, path);
 	if (ret) {
diff --git a/cmds/rescue.c b/cmds/rescue.c
index 087c33befeff..19de5235a22e 100644
--- a/cmds/rescue.c
+++ b/cmds/rescue.c
@@ -40,6 +40,8 @@ static const char * const cmd_rescue_chunk_recover_usage[] = {
 	"-y	Assume an answer of `yes' to all questions",
 	"-v	Verbose mode",
 	"-h	Help",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -49,7 +51,10 @@ static int cmd_rescue_chunk_recover(const struct cmd_struct *cmd,
 	int ret = 0;
 	char *file;
 	int yes = 0;
-	int verbose = 0;
+
+	/* If verbose is unset, set it to 0 */
+	if (bconf.verbose == BTRFS_BCONF_UNSET)
+		bconf.verbose = BTRFS_BCONF_QUIET;
 
 	optind = 0;
 	while (1) {
@@ -61,7 +66,7 @@ static int cmd_rescue_chunk_recover(const struct cmd_struct *cmd,
 			yes = 1;
 			break;
 		case 'v':
-			verbose = 1;
+			bconf.verbose++;
 			break;
 		default:
 			usage_unknown_option(cmd, argv);
@@ -83,7 +88,7 @@ static int cmd_rescue_chunk_recover(const struct cmd_struct *cmd,
 		return 1;
 	}
 
-	ret = btrfs_recover_chunk_tree(file, verbose, yes);
+	ret = btrfs_recover_chunk_tree(file, yes);
 	if (!ret) {
 		fprintf(stdout, "Chunk tree recovered successfully\n");
 	} else if (ret > 0) {
diff --git a/cmds/rescue.h b/cmds/rescue.h
index de486e2e2004..e594954f78e2 100644
--- a/cmds/rescue.h
+++ b/cmds/rescue.h
@@ -16,6 +16,6 @@
 #define __BTRFS_RESCUE_H__
 
 int btrfs_recover_superblocks(const char *path, int verbose, int yes);
-int btrfs_recover_chunk_tree(const char *path, int verbose, int yes);
+int btrfs_recover_chunk_tree(const char *path, int yes);
 
 #endif
-- 
1.8.3.1


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

* [PATCH v2 10/16] btrfs-progs: rescue super-recover: use global verbose option
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (8 preceding siblings ...)
  2019-11-25 10:39 ` [PATCH v2 09/16] btrfs-progs: rescue chunk-recover: " Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2020-06-12 11:25   ` [PATCH v3 " Anand Jain
  2019-11-25 10:39 ` [PATCH v2 11/16] btrfs-progs: restore: " Anand Jain
                   ` (10 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

Transpire global --verbose option down to the btrfs rescue super-recover
sub-command.

For example: Both global and local verbose options are now supported.
btrfs -v|--verbose rescue super-recover
btrfs rescue super-recover -v

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Use new helper functions and defines
     HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
     bconf_be_verbose(), bconf_be_quiet()
    Drop verbose argument in btrfs_recover_superblocks()

 cmds/rescue-super-recover.c | 7 +++----
 cmds/rescue.c               | 7 ++++---
 cmds/rescue.h               | 2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/cmds/rescue-super-recover.c b/cmds/rescue-super-recover.c
index 5d6bea836c8b..3a60eb40c8bb 100644
--- a/cmds/rescue-super-recover.c
+++ b/cmds/rescue-super-recover.c
@@ -226,8 +226,7 @@ static void recover_err_str(int ret)
 	}
 }
 
-int btrfs_recover_superblocks(const char *dname,
-			int verbose, int yes)
+int btrfs_recover_superblocks(const char *dname, int yes)
 {
 	int fd, ret;
 	struct btrfs_recover_superblock recover;
@@ -249,7 +248,7 @@ int btrfs_recover_superblocks(const char *dname,
 		goto no_recover;
 	}
 
-	if (verbose)
+	if (bconf.verbose > BTRFS_BCONF_QUIET)
 		print_all_devices(&recover.fs_devices->devices);
 
 	ret = read_fs_supers(&recover);
@@ -257,7 +256,7 @@ int btrfs_recover_superblocks(const char *dname,
 		ret = 1;
 		goto no_recover;
 	}
-	if (verbose) {
+	if (bconf.verbose > BTRFS_BCONF_QUIET) {
 		printf("Before Recovering:\n");
 		print_all_supers(&recover);
 	}
diff --git a/cmds/rescue.c b/cmds/rescue.c
index 19de5235a22e..2e14c98ba911 100644
--- a/cmds/rescue.c
+++ b/cmds/rescue.c
@@ -107,6 +107,8 @@ static const char * const cmd_rescue_super_recover_usage[] = {
 	"",
 	"-y	Assume an answer of `yes' to all questions",
 	"-v	Verbose mode",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -122,7 +124,6 @@ static int cmd_rescue_super_recover(const struct cmd_struct *cmd,
 				    int argc, char **argv)
 {
 	int ret;
-	int verbose = 0;
 	int yes = 0;
 	char *dname;
 
@@ -133,7 +134,7 @@ static int cmd_rescue_super_recover(const struct cmd_struct *cmd,
 			break;
 		switch (c) {
 		case 'v':
-			verbose = 1;
+			bconf_be_verbose();
 			break;
 		case 'y':
 			yes = 1;
@@ -155,7 +156,7 @@ static int cmd_rescue_super_recover(const struct cmd_struct *cmd,
 		error("the device is busy");
 		return 1;
 	}
-	ret = btrfs_recover_superblocks(dname, verbose, yes);
+	ret = btrfs_recover_superblocks(dname, yes);
 	return ret;
 }
 static DEFINE_SIMPLE_COMMAND(rescue_super_recover, "super-recover");
diff --git a/cmds/rescue.h b/cmds/rescue.h
index e594954f78e2..3b99ec6b0daa 100644
--- a/cmds/rescue.h
+++ b/cmds/rescue.h
@@ -15,7 +15,7 @@
 #ifndef __BTRFS_RESCUE_H__
 #define __BTRFS_RESCUE_H__
 
-int btrfs_recover_superblocks(const char *path, int verbose, int yes);
+int btrfs_recover_superblocks(const char *path, int yes);
 int btrfs_recover_chunk_tree(const char *path, int yes);
 
 #endif
-- 
1.8.3.1


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

* [PATCH v2 11/16] btrfs-progs: restore: use global verbose option
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (9 preceding siblings ...)
  2019-11-25 10:39 ` [PATCH v2 10/16] btrfs-progs: rescue super-recover: " Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2020-06-12 11:26   ` [PATCH v3 " Anand Jain
  2019-11-25 10:39 ` [PATCH v2 12/16] btrfs-progs: inspect-internal inode-resolve: use global verbose Anand Jain
                   ` (9 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

Transpire global --verbose option down to the btrfs restore sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Use new helper functions and defines
     HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
     bconf_be_verbose(), bconf_be_quiet()

 cmds/restore.c | 53 +++++++++++++++++++++++------------------------------
 1 file changed, 23 insertions(+), 30 deletions(-)

diff --git a/cmds/restore.c b/cmds/restore.c
index c104b01aef69..d541046c6579 100644
--- a/cmds/restore.c
+++ b/cmds/restore.c
@@ -51,7 +51,6 @@ static char fs_name[PATH_MAX];
 static char path_name[PATH_MAX];
 static char symlink_target[PATH_MAX];
 static int get_snaps = 0;
-static int verbose = 0;
 static int restore_metadata = 0;
 static int restore_symlinks = 0;
 static int ignore_errors = 0;
@@ -375,8 +374,7 @@ static int copy_one_extent(struct btrfs_root *root, int fd,
 	if (compress == BTRFS_COMPRESS_NONE)
 		bytenr += offset;
 
-	if (verbose && offset)
-		printf("offset is %Lu\n", offset);
+	pr_verbose(offset ? 1 : 0, "offset is %Lu\n", offset);
 	/* we found a hole */
 	if (disk_size == 0)
 		return 0;
@@ -832,11 +830,13 @@ static int overwrite_ok(const char * path)
 		if (overwrite)
 			return 2;
 
-		if (verbose || !warn)
-			printf("Skipping existing file"
-				   " %s\n", path);
-		if (!warn)
-			printf("If you wish to overwrite use -o\n");
+		if (!warn) {
+			pr_verbose(-1, "Skipping existing file %s\n", path);
+			pr_verbose(-1, "If you wish to overwrite use -o\n");
+		} else {
+			pr_verbose(1, "Skipping existing file %s\n", path);
+		}
+
 		warn = 1;
 		return 0;
 	}
@@ -987,9 +987,8 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 
 	leaf = path.nodes[0];
 	while (!leaf) {
-		if (verbose > 1)
-			printf("No leaf after search, looking for the next "
-			       "leaf\n");
+		pr_verbose(2,
+			   "No leaf after search, looking for the next leaf\n");
 		ret = next_leaf(root, &path);
 		if (ret < 0) {
 			fprintf(stderr, "Error getting next leaf %d\n",
@@ -997,9 +996,8 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 			goto out;
 		} else if (ret > 0) {
 			/* No more leaves to search */
-			if (verbose)
-				printf("Reached the end of the tree looking "
-				       "for the directory\n");
+			pr_verbose(1,
+		   "Reached the end of the tree looking for the directory\n");
 			ret = 0;
 			goto out;
 		}
@@ -1023,10 +1021,8 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 					goto out;
 				} else if (ret > 0) {
 					/* No more leaves to search */
-					if (verbose)
-						printf("Reached the end of "
-						       "the tree searching the"
-						       " directory\n");
+					pr_verbose(1,
+		"Reached the end of the tree searching the directory\n");
 					ret = 0;
 					goto out;
 				}
@@ -1036,14 +1032,12 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 		}
 		btrfs_item_key_to_cpu(leaf, &found_key, path.slots[0]);
 		if (found_key.objectid != key->objectid) {
-			if (verbose > 1)
-				printf("Found objectid=%Lu, key=%Lu\n",
-				       found_key.objectid, key->objectid);
+			pr_verbose(2, "Found objectid=%Lu, key=%Lu\n",
+				   found_key.objectid, key->objectid);
 			break;
 		}
 		if (found_key.type != key->type) {
-			if (verbose > 1)
-				printf("Found type=%u, want=%u\n",
+			pr_verbose(2, "Found type=%u, want=%u\n",
 				       found_key.type, key->type);
 			break;
 		}
@@ -1072,8 +1066,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 			if (!overwrite_ok(path_name))
 				goto next;
 
-			if (verbose)
-				printf("Restoring %s\n", path_name);
+			pr_verbose(1, "Restoring %s\n", path_name);
 			if (dry_run)
 				goto next;
 			fd = open(path_name, O_CREAT|O_WRONLY, 0644);
@@ -1145,8 +1138,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 				location.objectid = BTRFS_FIRST_FREE_OBJECTID;
 			}
 
-			if (verbose)
-				printf("Restoring %s\n", path_name);
+			pr_verbose(1, "Restoring %s\n", path_name);
 
 			errno = 0;
 			if (dry_run)
@@ -1209,8 +1201,7 @@ next:
 		}
 	}
 
-	if (verbose)
-		printf("Done searching %s\n", in_dir);
+	pr_verbose(1, "Done searching %s\n", in_dir);
 out:
 	btrfs_release_path(&path);
 	return ret;
@@ -1420,6 +1411,8 @@ static const char * const cmd_restore_usage[] = {
 	"                     you have to use following syntax (possibly quoted):",
 	"                     ^/(|home(|/username(|/Desktop(|/.*))))$",
 	"-c                   ignore case (--path-regex only)",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -1472,7 +1465,7 @@ static int cmd_restore(const struct cmd_struct *cmd, int argc, char **argv)
 				get_snaps = 1;
 				break;
 			case 'v':
-				verbose++;
+				bconf_be_verbose();
 				break;
 			case 'i':
 				ignore_errors = 1;
-- 
1.8.3.1


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

* [PATCH v2 12/16] btrfs-progs: inspect-internal inode-resolve: use global verbose
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (10 preceding siblings ...)
  2019-11-25 10:39 ` [PATCH v2 11/16] btrfs-progs: restore: " Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2020-06-12 11:26   ` [PATCH v3 " Anand Jain
  2019-11-25 10:39 ` [PATCH v2 13/16] btrfs-progs: inspect-internal logical-resolve: use global verbose option Anand Jain
                   ` (8 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

Transpire global --verbose option down to the
btrfs inspect-internal inode-resolve sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Use new helper functions and defines
     HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
     bconf_be_verbose(), bconf_be_quiet()

 cmds/inspect.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/cmds/inspect.c b/cmds/inspect.c
index 758b6e60c591..de4d163991a5 100644
--- a/cmds/inspect.c
+++ b/cmds/inspect.c
@@ -56,12 +56,11 @@ static int __ino_to_path_fd(u64 inum, int fd, int verbose, const char *prepend)
 		goto out;
 	}
 
-	if (verbose)
-		printf("ioctl ret=%d, bytes_left=%lu, bytes_missing=%lu, "
-			"cnt=%d, missed=%d\n", ret,
-			(unsigned long)fspath->bytes_left,
-			(unsigned long)fspath->bytes_missing,
-			fspath->elem_cnt, fspath->elem_missed);
+	pr_verbose(1,
+	"ioctl ret=%d, bytes_left=%lu, bytes_missing=%lu cnt=%d, missed=%d\n",
+		   ret, (unsigned long)fspath->bytes_left,
+		   (unsigned long)fspath->bytes_missing, fspath->elem_cnt,
+		   fspath->elem_missed);
 
 	for (i = 0; i < fspath->elem_cnt; ++i) {
 		u64 ptr;
@@ -84,6 +83,8 @@ static const char * const cmd_inspect_inode_resolve_usage[] = {
 	"Get file system paths for the given inode",
 	"",
 	"-v   verbose mode",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -91,7 +92,6 @@ static int cmd_inspect_inode_resolve(const struct cmd_struct *cmd,
 				     int argc, char **argv)
 {
 	int fd;
-	int verbose = 0;
 	int ret;
 	DIR *dirstream = NULL;
 
@@ -103,7 +103,7 @@ static int cmd_inspect_inode_resolve(const struct cmd_struct *cmd,
 
 		switch (c) {
 		case 'v':
-			verbose = 1;
+			bconf_be_verbose();
 			break;
 		default:
 			usage_unknown_option(cmd, argv);
@@ -117,8 +117,8 @@ static int cmd_inspect_inode_resolve(const struct cmd_struct *cmd,
 	if (fd < 0)
 		return 1;
 
-	ret = __ino_to_path_fd(arg_strtou64(argv[optind]), fd, verbose,
-			       argv[optind+1]);
+	ret = __ino_to_path_fd(arg_strtou64(argv[optind]), fd,
+			       bconf.verbose, argv[optind+1]);
 	close_file_or_dir(fd, dirstream);
 	return !!ret;
 
-- 
1.8.3.1


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

* [PATCH v2 13/16] btrfs-progs: inspect-internal logical-resolve: use global verbose option
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (11 preceding siblings ...)
  2019-11-25 10:39 ` [PATCH v2 12/16] btrfs-progs: inspect-internal inode-resolve: use global verbose Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2020-06-12 11:26   ` [PATCH v3 " Anand Jain
  2019-11-25 10:39 ` [PATCH 14/16] btrfs-progs: refactor btrfs_scan_devices() to accept verbose argument Anand Jain
                   ` (7 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

Transpire global --verbose option down to the
btrfs inspect-internal logical-resolve sub-command.

Command btrfs inspect-internal logical-resolve provides local verbose
option this patch makes it enable-able by using the global --verbose
option.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Use new helper function bconf_be_verbose()

 cmds/inspect.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/cmds/inspect.c b/cmds/inspect.c
index de4d163991a5..8baa7aa4604a 100644
--- a/cmds/inspect.c
+++ b/cmds/inspect.c
@@ -38,7 +38,7 @@ static const char * const inspect_cmd_group_usage[] = {
 	NULL
 };
 
-static int __ino_to_path_fd(u64 inum, int fd, int verbose, const char *prepend)
+static int __ino_to_path_fd(u64 inum, int fd, const char *prepend)
 {
 	int ret;
 	int i;
@@ -117,8 +117,7 @@ static int cmd_inspect_inode_resolve(const struct cmd_struct *cmd,
 	if (fd < 0)
 		return 1;
 
-	ret = __ino_to_path_fd(arg_strtou64(argv[optind]), fd,
-			       bconf.verbose, argv[optind+1]);
+	ret = __ino_to_path_fd(arg_strtou64(argv[optind]), fd, argv[optind+1]);
 	close_file_or_dir(fd, dirstream);
 	return !!ret;
 
@@ -134,6 +133,8 @@ static const char * const cmd_inspect_logical_resolve_usage[] = {
 	"-s bufsize  set inode container's size. This is used to increase inode",
 	"            container's size in case it is not enough to read all the ",
 	"            resolved results. The max value one can set is 64k",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -143,7 +144,6 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd,
 	int ret;
 	int fd;
 	int i;
-	int verbose = 0;
 	int getpath = 1;
 	int bytes_left;
 	struct btrfs_ioctl_logical_ino_args loi;
@@ -164,7 +164,7 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd,
 			getpath = 0;
 			break;
 		case 'v':
-			verbose = 1;
+			bconf_be_verbose();
 			break;
 		case 's':
 			size = arg_strtou64(optarg);
@@ -199,13 +199,11 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd,
 		goto out;
 	}
 
-	if (verbose)
-		printf("ioctl ret=%d, total_size=%llu, bytes_left=%lu, "
-			"bytes_missing=%lu, cnt=%d, missed=%d\n",
-			ret, size,
-			(unsigned long)inodes->bytes_left,
-			(unsigned long)inodes->bytes_missing,
-			inodes->elem_cnt, inodes->elem_missed);
+	pr_verbose(1,
+"ioctl ret=%d, total_size=%llu, bytes_left=%lu, bytes_missing=%lu, cnt=%d, missed=%d\n",
+		   ret, size, (unsigned long)inodes->bytes_left,
+		   (unsigned long)inodes->bytes_missing, inodes->elem_cnt,
+		   inodes->elem_missed);
 
 	bytes_left = sizeof(full_path);
 	ret = snprintf(full_path, bytes_left, "%s/", argv[optind+1]);
@@ -250,8 +248,7 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd,
 					goto out;
 				}
 			}
-			ret = __ino_to_path_fd(inum, path_fd, verbose,
-						full_path);
+			ret = __ino_to_path_fd(inum, path_fd, full_path);
 			if (path_fd != fd)
 				close_file_or_dir(path_fd, dirs);
 		} else {
-- 
1.8.3.1


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

* [PATCH 14/16] btrfs-progs: refactor btrfs_scan_devices() to accept verbose argument
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (12 preceding siblings ...)
  2019-11-25 10:39 ` [PATCH v2 13/16] btrfs-progs: inspect-internal logical-resolve: use global verbose option Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2019-11-25 10:39 ` [PATCH v2 15/16] btrfs-progs: device scan: add verbose option Anand Jain
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

Function btrfs_scan_devices() is being used by commands such as
'btrfs filesystem' and 'btrfs device', by having the verbose argument in
the btrfs_scan_devices() we can control which threads to show the
verbose when verbose is enabled by the global verbose option.

So add an option %verbose to btrfs_scan_devices().

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds/device.c        | 2 +-
 cmds/filesystem.c    | 2 +-
 common/device-scan.c | 3 ++-
 common/device-scan.h | 2 +-
 common/utils.c       | 2 +-
 disk-io.c            | 2 +-
 6 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/cmds/device.c b/cmds/device.c
index 24158308a41b..f96d71e0477a 100644
--- a/cmds/device.c
+++ b/cmds/device.c
@@ -354,7 +354,7 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv)
 			}
 		} else {
 			printf("Scanning for Btrfs filesystems\n");
-			ret = btrfs_scan_devices();
+			ret = btrfs_scan_devices(0);
 			error_on(ret, "error %d while scanning", ret);
 			ret = btrfs_register_all_devices();
 			error_on(ret,
diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index fc1736d9fe66..621fecd21dde 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -746,7 +746,7 @@ devs_only:
 		else
 			ret = 1;
 	} else {
-		ret = btrfs_scan_devices();
+		ret = btrfs_scan_devices(0);
 	}
 
 	if (ret) {
diff --git a/common/device-scan.c b/common/device-scan.c
index 48dbd9e19715..b6b6b30cfb23 100644
--- a/common/device-scan.c
+++ b/common/device-scan.c
@@ -360,7 +360,7 @@ void free_seen_fsid(struct seen_fsid *seen_fsid_hash[])
 	}
 }
 
-int btrfs_scan_devices(void)
+int btrfs_scan_devices(int verbose)
 {
 	int fd = -1;
 	int ret;
@@ -404,6 +404,7 @@ int btrfs_scan_devices(void)
 			close (fd);
 			continue;
 		}
+		pr_verbose(verbose, "registered: %s\n", path);
 
 		close(fd);
 	}
diff --git a/common/device-scan.h b/common/device-scan.h
index eda2bae5c6c4..8017a27511b9 100644
--- a/common/device-scan.h
+++ b/common/device-scan.h
@@ -29,7 +29,7 @@ struct seen_fsid {
 	int fd;
 };
 
-int btrfs_scan_devices(void);
+int btrfs_scan_devices(int verbose);
 int btrfs_register_one_device(const char *fname);
 int btrfs_register_all_devices(void);
 int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
diff --git a/common/utils.c b/common/utils.c
index 4b5d40b2bc56..fe258eacf655 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -277,7 +277,7 @@ int check_mounted_where(int fd, const char *file, char *where, int size,
 
 	/* scan other devices */
 	if (is_btrfs && total_devs > 1) {
-		ret = btrfs_scan_devices();
+		ret = btrfs_scan_devices(0);
 		if (ret)
 			return ret;
 	}
diff --git a/disk-io.c b/disk-io.c
index 659f8b93a7ca..98431e0d2295 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1105,7 +1105,7 @@ int btrfs_scan_fs_devices(int fd, const char *path,
 	}
 
 	if (!skip_devices && total_devs != 1) {
-		ret = btrfs_scan_devices();
+		ret = btrfs_scan_devices(0);
 		if (ret)
 			return ret;
 	}
-- 
1.8.3.1


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

* [PATCH v2 15/16] btrfs-progs: device scan: add verbose option
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (13 preceding siblings ...)
  2019-11-25 10:39 ` [PATCH 14/16] btrfs-progs: refactor btrfs_scan_devices() to accept verbose argument Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2019-11-25 10:39 ` [PATCH 16/16] btrfs-progs: device scan: add quiet option Anand Jain
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

Enable verbose output for the device scanned, this uses the global
verbose option.

For example:
./btrfs --verbose device scan
Scanning for Btrfs filesystems
registered: /dev/sda1
registered: /dev/sda2
registered: /dev/sda3
registered: /dev/sda5
registered: /dev/sda6

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Use new define HELPINFO_INSERT_GLOBALS

 cmds/device.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/cmds/device.c b/cmds/device.c
index f96d71e0477a..2feb1acd031d 100644
--- a/cmds/device.c
+++ b/cmds/device.c
@@ -303,6 +303,8 @@ static const char * const cmd_device_scan_usage[] = {
 	" -d|--all-devices            enumerate and register all devices, use as a fallback",
 	"                             if blkid is not available",
 	" -u|--forget [<device>...]   unregister a given device or all stale devices if no path ",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -354,7 +356,7 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv)
 			}
 		} else {
 			printf("Scanning for Btrfs filesystems\n");
-			ret = btrfs_scan_devices(0);
+			ret = btrfs_scan_devices(1);
 			error_on(ret, "error %d while scanning", ret);
 			ret = btrfs_register_all_devices();
 			error_on(ret,
-- 
1.8.3.1


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

* [PATCH 16/16] btrfs-progs: device scan: add quiet option
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (14 preceding siblings ...)
  2019-11-25 10:39 ` [PATCH v2 15/16] btrfs-progs: device scan: add verbose option Anand Jain
@ 2019-11-25 10:39 ` Anand Jain
  2019-12-20  5:36 ` [PATCH v2 00/16] btrfs-progs: global verbose and " Anand Jain
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2019-11-25 10:39 UTC (permalink / raw)
  To: linux-btrfs

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

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds/device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/cmds/device.c b/cmds/device.c
index 2feb1acd031d..2c34defd8249 100644
--- a/cmds/device.c
+++ b/cmds/device.c
@@ -305,6 +305,7 @@ static const char * const cmd_device_scan_usage[] = {
 	" -u|--forget [<device>...]   unregister a given device or all stale devices if no path ",
 	HELPINFO_INSERT_GLOBALS,
 	HELPINFO_INSERT_VERBOSE,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
@@ -355,7 +356,7 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv)
 				error("cannot unregister devices: %m");
 			}
 		} else {
-			printf("Scanning for Btrfs filesystems\n");
+			pr_verbose(-1, "Scanning for Btrfs filesystems\n");
 			ret = btrfs_scan_devices(1);
 			error_on(ret, "error %d while scanning", ret);
 			ret = btrfs_register_all_devices();
-- 
1.8.3.1


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

* Re: [PATCH v2 00/16] btrfs-progs: global verbose and quiet option
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (15 preceding siblings ...)
  2019-11-25 10:39 ` [PATCH 16/16] btrfs-progs: device scan: add quiet option Anand Jain
@ 2019-12-20  5:36 ` Anand Jain
  2020-01-14  6:14 ` Anand Jain
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2019-12-20  5:36 UTC (permalink / raw)
  To: linux-btrfs

Gentle ping.

Regds, Anand

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

* Re: [PATCH v2 00/16] btrfs-progs: global verbose and quiet option
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (16 preceding siblings ...)
  2019-12-20  5:36 ` [PATCH v2 00/16] btrfs-progs: global verbose and " Anand Jain
@ 2020-01-14  6:14 ` Anand Jain
  2020-01-14 11:40   ` David Sterba
  2020-06-11 16:36 ` [PATCH v3 02/16] btrfs-progs: add global verbose and quiet options and helper functions Anand Jain
                   ` (2 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2020-01-14  6:14 UTC (permalink / raw)
  To: David Sterba; +Cc: linux-btrfs


David,

  I wonder if could this be integrated?

Thanks, Anand


On 25/11/19 6:39 PM, Anand Jain wrote:
> v1.1->v2:
> Mainly:
>   . Splits define HELPINFO_INSERT_GLOBALS from --format option and
>   . Rename HELPINFO_GLOBAL_OPTIONS_HEADER to HELPINFO_INSERT_GLOBALS
>   . Create and use helper bconf_be_verbose() and bconf_be_quiet().
>   . Use gobal bconf.verbose where possible and drop local verbose argument passing.
>   . In some patches the bconf.verbose initialization wasn't necessary so drop it.
> Some small fixes as mentioned in the individual patch.
> 
> v1->v1.1:
>   . Fix typo in HELPINFO_INSERT_QUIET.
>   . Remove #include <stdbool.h> where its no more required.
>     (was needed when %bconf.verbose was declared as bool).
>   . Use pr_verbose(-1,..) instead of all conditions printf()
>   . Use pr_verbose(1,..) instead of pr_verbose(true,..)
> 
> verbosity sample code as in v1.1
> 
> global init
> -----------
>          bconf.verbose = -1; //-1:default, 0:quiet, >1:verbose
> 
> at global options
> -----------------
> 	case 'v':
> 		bconf.verbose < 0 ? bconf.verbose = 1 : bconf.verbose++;
> 		break;
> 	case 'q':
> 		bconf.verbose = 0;
> 		break;
> 
> sub-command init
> ----------------
> For send/receive only (special cases, default verbosity is 1):
> 
> 	if (bconf.verbose < 0)
> 		bconf.verbose = 1;
> 	else if (bconf.verbose > 0)
> 		bconf.verbose++;
> 
> Non-send/receive:
> default verbosity is 0 (ref: cmds/rescue.c)
> 	if (bconf.verbose < 0)
> 		bconf.verbose = 0;
> 
> at sub-command options
> ----------------------
> 	case 'v':
> 		bconf.verbose++;
> 		break;
> 	case 'q':
> 		bconf.verbose = 0;
> 		break;
> 
> 
> pr_verbose()
> ------------
> /*
>   * level -1: prints message unless bconf.verbose == 0;
>   * level  0: quiet
>   * level >0: prints message only if <= bconf.verbose
>   */
> void pr_verbose(int level, const char *fmt, ...)
> {
>          va_list args;
> 
>          if (level == 0 || bconf.verbose == 0)
>                  return;
> 
>          if (level > bconf.verbose)
>                  return;
> 
>          va_start(args, fmt);
>          vfprintf(stdout, fmt, args);
>          va_end(args);
> }
> 
> 
> RFC->v1:
> .. Adds --quiet option to the global btrfs(8) command.
> .. Used global struct bconf.
> .. Refactored pr_verbose(), accepts level (int) as argument, so now the
> sub-command can specify the verbose level at which the particular
> verbose messages has to be printed.
> .. Added global help defines.
> 
> Kindly note the following:-
> 
> 1.
>   There are certain sub-commands which does not have any verbose output
>   or quiet output. However if the global options were used with those
>   sub-commands then the command shall not report any usage error. Or
>   my question is should it error out.? For example:
>    (with the patch) btrfs --verbose device ready /dev/sdb
>   actually there isn't any verbose output but we won't error out.
>   Similarly,
>    (without the patch) btrfs send -vvvvv will not show usage error
>    as well.
>    So I believe this is fine. IMO.
> 
> 2.
>    There is slight difference in output when global options are used
>    as compared to the output using the same sequence of options at the
>    sub-command level. For example:
> 
>     btrfs send -v -q -v  is-equal-to  btrfs send
>     But same sequence in the global option
>     btrfs -v -q -v send is-not-equal-to btrfs send
>     but is-equal-to btrfs -v send or btrfs send -v.
>     (similarly applies to receive as well).
> 
>    which IMO is fair expectation as -v is ending last.
> 
> 
> RFC:
> This patch set brings --verbose option to the top level btrfs command,
> such as 'btrfs --verbose'. With this we don't have to add or remember
> verbose option at the sub-commands level.
> 
> As there are already verbose options to 11 sub-commands as listed
> below [1][2]. So the top level --verbose option here takes care to transpire
> verbose request from the top level to the sub-command level for 9 (not 11)
> sub-commands as in [1] as of now.
> 
> This patch is RFC still for the following two reasons (comments appreciated).
> 
> 1.
> The sub-commands as in [2] uses multi-level compile time verbose option,
> such as %g_verbose = 0 (quite), %g_verbose = 1 (default), %g_verbose > 1
> (real-verbose). And verbose at default is also part the .out files in
> fstests. So it needs further discussions on how to handle the multi-
> level verbose option using the global verbose option, and so sub-
> commands in [2] are untouched.
> 
> 2.
> These patch has been unit-tested individually.
> These patches does not alter the verbose output.
> But it fixes the indentation in the command's help output, which may be
> used in fstests and btrfs-progs/tests and their verification is pending
> still, which I am planning to do it before v1.
> 
> [1]
> btrfs subvolume delete --help
>          -v|--verbose           verbose output of operations
> btrfs filesystem defragment --help
>          -v                  be verbose
> btrfs balance start --help
>          -v|--verbose        be verbose
> btrfs balance status --help
>          -v|--verbose        be verbose
> btrfs rescue chunk-recover --help
>          -v      Verbose mode
> btrfs rescue super-recover --help
>          -v      Verbose mode
> btrfs restore --help
>          -v|--verbose         verbose
> btrfs inspect-internal inode-resolve --help
>          -v   verbose mode
> btrfs inspect-internal logical-resolve --help
>          -v          verbose mode
> 
> [2]
> btrfs send --help
>          -v|--verbose     enable verbose output to stderr, each occurrence of
> btrfs receive --help
>          -v               increase verbosity about performed action
> 
> 
> 
> Anand Jain (16):
>    btrfs-progs: split global help HELPINFO_INSERT_GLOBALS
>    btrfs-progs: add global verbose and quiet options and helper functions
>    btrfs-progs: send: use global verbose and quiet options
>    btrfs-progs: receive: use global verbose and quiet options
>    btrfs-progs: subvolume delete: use global verbose option
>    btrfs-progs: filesystem defragment: use global verbose option
>    btrfs-progs: balance start: use global verbose option
>    btrfs-progs: balance status: use global verbose option
>    btrfs-progs: rescue chunk-recover: use global verbose option
>    btrfs-progs: rescue super-recover: use global verbose option
>    btrfs-progs: restore: use global verbose option
>    btrfs-progs: inspect-internal inode-resolve: use global verbose
>    btrfs-progs: inspect-internal logical-resolve: use global verbose
>      option
>    btrfs-progs: refactor btrfs_scan_devices() to accept verbose argument
>    btrfs-progs: device scan: add verbose option
>    btrfs-progs: device scan: add quiet option
> 
>   btrfs.c                     | 20 ++++++++++--
>   cmds/balance.c              | 14 ++++----
>   cmds/device.c               |  7 ++--
>   cmds/filesystem.c           | 14 ++++----
>   cmds/inspect.c              | 41 +++++++++++------------
>   cmds/receive.c              | 80 +++++++++++++++++++++++++--------------------
>   cmds/rescue-chunk-recover.c |  9 +++--
>   cmds/rescue-super-recover.c |  7 ++--
>   cmds/rescue.c               | 18 ++++++----
>   cmds/rescue.h               |  4 +--
>   cmds/restore.c              | 53 +++++++++++++-----------------
>   cmds/send.c                 | 33 ++++++++++++-------
>   cmds/subvolume.c            | 28 ++++++++--------
>   common/device-scan.c        |  3 +-
>   common/device-scan.h        |  2 +-
>   common/help.c               |  4 +--
>   common/help.h               |  9 ++++-
>   common/messages.c           | 25 ++++++++++++++
>   common/messages.h           |  3 ++
>   common/utils.c              | 16 ++++++++-
>   common/utils.h              | 11 +++++++
>   disk-io.c                   |  2 +-
>   22 files changed, 245 insertions(+), 158 deletions(-)
> 


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

* Re: [PATCH v2 00/16] btrfs-progs: global verbose and quiet option
  2020-01-14  6:14 ` Anand Jain
@ 2020-01-14 11:40   ` David Sterba
  2020-03-28  5:45     ` Anand Jain
  0 siblings, 1 reply; 47+ messages in thread
From: David Sterba @ 2020-01-14 11:40 UTC (permalink / raw)
  To: Anand Jain; +Cc: David Sterba, linux-btrfs

On Tue, Jan 14, 2020 at 02:14:24PM +0800, Anand Jain wrote:
>   I wonder if could this be integrated?

Yes, when I get to it through the pile of other patches.

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

* Re: [PATCH v2 00/16] btrfs-progs: global verbose and quiet option
  2020-01-14 11:40   ` David Sterba
@ 2020-03-28  5:45     ` Anand Jain
  2020-05-20 10:01       ` Anand Jain
  0 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2020-03-28  5:45 UTC (permalink / raw)
  To: dsterba, David Sterba, linux-btrfs

On 14/1/20 7:40 PM, David Sterba wrote:
> On Tue, Jan 14, 2020 at 02:14:24PM +0800, Anand Jain wrote:
>>    I wonder if could this be integrated?
> 
> Yes, when I get to it through the pile of other patches.
> 

  Can this get into the upcoming release.

Thanks, Anand

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

* Re: [PATCH v2 00/16] btrfs-progs: global verbose and quiet option
  2020-03-28  5:45     ` Anand Jain
@ 2020-05-20 10:01       ` Anand Jain
  2020-06-05  9:24         ` David Sterba
  0 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2020-05-20 10:01 UTC (permalink / raw)
  To: dsterba, David Sterba, linux-btrfs


David,

   A ping on this series.

Thanks, Anand


On 28/3/20 1:45 pm, Anand Jain wrote:
> On 14/1/20 7:40 PM, David Sterba wrote:
>> On Tue, Jan 14, 2020 at 02:14:24PM +0800, Anand Jain wrote:
>>>    I wonder if could this be integrated?
>>
>> Yes, when I get to it through the pile of other patches.
>>
> 
>   Can this get into the upcoming release.
> 
> Thanks, Anand

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

* Re: [PATCH v2 00/16] btrfs-progs: global verbose and quiet option
  2020-05-20 10:01       ` Anand Jain
@ 2020-06-05  9:24         ` David Sterba
  2020-06-05 10:12           ` Anand Jain
  2020-06-11 18:13           ` Anand Jain
  0 siblings, 2 replies; 47+ messages in thread
From: David Sterba @ 2020-06-05  9:24 UTC (permalink / raw)
  To: Anand Jain; +Cc: dsterba, David Sterba, linux-btrfs

On Wed, May 20, 2020 at 06:01:28PM +0800, Anand Jain wrote:
>    A ping on this series.

So I want to merge the series but I think it's unfinished. There are
mostly --verbose options added, while --quiet is only for send and
receive. My first test was 'btrfs -q subvolume create' and 'delete' and
that -q did not work is surprising. The -v/-q options need to come in
the same release.

Also, many options that have their own --verbose option should update
the help text to note that it's an alias of the global.

I'm going to take another look today, the scope of the change might be
too big to do in one go so some incremental steps might be needed.

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

* Re: [PATCH v2 00/16] btrfs-progs: global verbose and quiet option
  2020-06-05  9:24         ` David Sterba
@ 2020-06-05 10:12           ` Anand Jain
  2020-06-10 10:17             ` David Sterba
  2020-06-11 18:13           ` Anand Jain
  1 sibling, 1 reply; 47+ messages in thread
From: Anand Jain @ 2020-06-05 10:12 UTC (permalink / raw)
  To: dsterba, David Sterba, linux-btrfs


> My first test was 'btrfs -q subvolume create' and 'delete' and
> that -q did not work is surprising. The -v/-q options need to come in
> the same release.

  Ah. I thought rest of the commands shall adopt -q option progressively.
  So its not unfinished. Anyway I can fix them now.

> Also, many options that have their own --verbose option should update
> the help text to note that it's an alias of the global.

  Hmm. Yep. Fixing them.

> I'm going to take another look today, the scope of the change might be
> too big to do in one go so some incremental steps might be needed.

  Sure. Thanks.

Anand


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

* Re: [PATCH v2 06/16] btrfs-progs: filesystem defragment: use global verbose option
  2019-11-25 10:39 ` [PATCH v2 06/16] btrfs-progs: filesystem defragment: " Anand Jain
@ 2020-06-08  6:31   ` Anand Jain
  2020-06-11 16:56     ` [PATCH v3 " Anand Jain
  2020-06-12 11:25   ` [PATCH v4 " Anand Jain
  1 sibling, 1 reply; 47+ messages in thread
From: Anand Jain @ 2020-06-08  6:31 UTC (permalink / raw)
  To: linux-btrfs, David Sterba


There is small nit change as below, which I have done locally.
I haven't sent an updated patch yet as I think its better to
send this and other changes if any.

> diff --git a/cmds/filesystem.c b/cmds/filesystem.c
> index 4f22089abeaa..fc1736d9fe66 100644
> --- a/cmds/filesystem.c
> +++ b/cmds/filesystem.c
> @@ -840,6 +840,8 @@ static const char * const cmd_filesystem_defrag_usage[] = {
>   	"-l len              defragment only up to len bytes",
>   	"-t size             target extent size hint (default: 32M)",
>   	"",
> +	HELPINFO_INSERT_GLOBALS,
> +	HELPINFO_INSERT_VERBOSE,
>   	"Warning: most Linux kernels will break up the ref-links of COW data",
>   	"(e.g., files copied with 'cp --reflink', snapshots) which may cause",
>   	"considerable increase of space usage. See btrfs-filesystem(8) for",

Move the new line "" from before HELPINFO_INSERT_GLOBALS to before Warning.

Thanks, Anand

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

* Re: [PATCH v2 00/16] btrfs-progs: global verbose and quiet option
  2020-06-05 10:12           ` Anand Jain
@ 2020-06-10 10:17             ` David Sterba
  0 siblings, 0 replies; 47+ messages in thread
From: David Sterba @ 2020-06-10 10:17 UTC (permalink / raw)
  To: Anand Jain; +Cc: dsterba, David Sterba, linux-btrfs

On Fri, Jun 05, 2020 at 06:12:30PM +0800, Anand Jain wrote:
> 
> > My first test was 'btrfs -q subvolume create' and 'delete' and
> > that -q did not work is surprising. The -v/-q options need to come in
> > the same release.
> 
>   Ah. I thought rest of the commands shall adopt -q option progressively.
>   So its not unfinished. Anyway I can fix them now.

From use case point of view it is unfinished, adding options for
verbosity without the corresponding quieting option just does not make
sense. The global options were my suggestion but so far I don't think
we've reached common understanding what's needed to implement that.

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

* [PATCH v3 02/16] btrfs-progs: add global verbose and quiet options and helper functions
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (17 preceding siblings ...)
  2020-01-14  6:14 ` Anand Jain
@ 2020-06-11 16:36 ` Anand Jain
  2020-06-11 16:39 ` [PATCH v3 11/16] btrfs-progs: restore: use global verbose option Anand Jain
  2020-06-11 16:41 ` [PATCH v2 16/16] btrfs-progs: device scan: add quiet option Anand Jain
  20 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-11 16:36 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Add btrfs(8) global --verbose and --quiet command options to show
verbose or no output from the sub-commands.
By introducing global a %bconf::verbose memeber to transpire the same
down to the sub-command.
Further the added helper function pr_verbose() helps to logs the verbose
messages, based on the state of the %bconf::verbose. And further HELPINFO_
defines are provides for the usage.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3:
  Add define MUST_LOG
  Add comment about the argument %level in the function pr_verbose()
v2:
  Add missing -q along with --quiet.
  Create and use bconf_be_verbose() and bconf_be_quiet().
  Change help wordings for verbose and quiet.
  Define and use BTRFS_BCONF_UNSET and BTRFS_BCONF_QUIET.
  Use HELPINFO_INSERT_GLOBALS.

 btrfs.c           | 20 ++++++++++++++++++--
 common/help.h     |  5 +++++
 common/messages.c | 30 ++++++++++++++++++++++++++++++
 common/messages.h |  4 ++++
 common/utils.c    | 14 ++++++++++++++
 common/utils.h    | 11 +++++++++++
 6 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/btrfs.c b/btrfs.c
index 72dad6fb3983..eb3b6183eb21 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -27,7 +27,7 @@
 #include "common/box.h"
 
 static const char * const btrfs_cmd_group_usage[] = {
-	"btrfs [--help] [--version] [--format <format>] <group> [<group>...] <command> [<args>]",
+	"btrfs [--help] [--version] [--format <format>] [-v|--verbose] [-q|--quiet] <group> [<group>...] <command> [<args>]",
 	NULL
 };
 
@@ -248,6 +248,8 @@ static int handle_global_options(int argc, char **argv)
 		{ "version", no_argument, NULL, OPT_VERSION },
 		{ "format", required_argument, NULL, OPT_FORMAT },
 		{ "full", no_argument, NULL, OPT_FULL },
+		{ "verbose", no_argument, NULL, 'v' },
+		{ "quiet", no_argument, NULL, 'q' },
 		{ NULL, 0, NULL, 0}
 	};
 	int shift;
@@ -259,7 +261,7 @@ static int handle_global_options(int argc, char **argv)
 	while (1) {
 		int c;
 
-		c = getopt_long(argc, argv, "+", long_options, NULL);
+		c = getopt_long(argc, argv, "+vq", long_options, NULL);
 		if (c < 0)
 			break;
 
@@ -270,6 +272,12 @@ static int handle_global_options(int argc, char **argv)
 		case OPT_FORMAT:
 			handle_output_format(optarg);
 			break;
+		case 'v':
+			bconf_be_verbose();
+			break;
+		case 'q':
+			bconf_be_quiet();
+			break;
 		default:
 			fprintf(stderr, "Unknown global option: %s\n",
 					argv[optind - 1]);
@@ -310,6 +318,14 @@ static void handle_special_globals(int shift, int argc, char **argv)
 			cmd_execute(&cmd_struct_version, argc, argv);
 			exit(0);
 		}
+
+	for (i = 0; i < shift; i++)
+		if (strcmp(argv[i], "--verbose") == 0)
+			bconf_be_verbose();
+
+	for (i = 0; i < shift; i++)
+		if (strcmp(argv[i], "--quiet") == 0)
+			bconf_be_quiet();
 }
 
 static const struct cmd_group btrfs_cmd_group = {
diff --git a/common/help.h b/common/help.h
index 91874abfe207..dbc5259d2277 100644
--- a/common/help.h
+++ b/common/help.h
@@ -60,6 +60,11 @@
 #define HELPINFO_INSERT_GLOBALS		"",					\
 					"Global options:"
 #define HELPINFO_INSERT_FORMAT		"--foramt TYPE"
+/*
+ * Global verbose option for the sub-commands
+ */
+#define HELPINFO_INSERT_VERBOSE	"-v|--verbose       increase output verbosity"
+#define HELPINFO_INSERT_QUIET	"-q|--quiet         print only errors"
 
 struct cmd_struct;
 struct cmd_group;
diff --git a/common/messages.c b/common/messages.c
index 0e5694ecd467..43ababe77519 100644
--- a/common/messages.c
+++ b/common/messages.c
@@ -17,6 +17,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include "common/messages.h"
+#include "common/utils.h"
 
 __attribute__ ((format (printf, 1, 2)))
 void __btrfs_warning(const char *fmt, ...)
@@ -75,3 +76,32 @@ int __btrfs_error_on(int condition, const char *fmt, ...)
 
 	return 1;
 }
+
+/*
+ * Print verbose helper function
+ * level: Minimum verbose level at which the message has to be printed.
+ *
+ * Values for argument level:
+ * MUST_LOG - Will log the message unless a quiet option is set.
+ *            Used where messages have to be printed for backward compatibility.
+ * > 0        Prints the message at the corresponding level.
+ */
+__attribute__ ((format (printf, 2, 3)))
+void pr_verbose(int level, const char *fmt, ...)
+{
+	va_list args;
+
+	if (bconf.verbose == BTRFS_BCONF_QUIET || level == BTRFS_BCONF_QUIET)
+		return;
+
+	/*
+	 * level is set by the threads requesting to print only if the command
+	 * verbose option is higher than the level.
+	 */
+	if (bconf.verbose < level)
+		return;
+
+	va_start(args, fmt);
+	vfprintf(stdout, fmt, args);
+	va_end(args);
+}
diff --git a/common/messages.h b/common/messages.h
index 596047948fef..288b32a77c10 100644
--- a/common/messages.h
+++ b/common/messages.h
@@ -96,3 +96,7 @@ __attribute__ ((format (printf, 2, 3)))
 int __btrfs_error_on(int condition, const char *fmt, ...);
 
 #endif
+
+#define	MUST_LOG	-1
+__attribute__ ((format (printf, 2, 3)))
+void pr_verbose(int level, const char *fmt, ...);
diff --git a/common/utils.c b/common/utils.c
index ebc50de2c143..0301efb0a348 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -1679,6 +1679,20 @@ u8 rand_u8(void)
 void btrfs_config_init(void)
 {
 	bconf.output_format = CMD_FORMAT_TEXT;
+	bconf.verbose = BTRFS_BCONF_UNSET;
+}
+
+void bconf_be_verbose(void)
+{
+	if (bconf.verbose == BTRFS_BCONF_UNSET)
+		bconf.verbose = 1;
+	else
+		bconf.verbose++;
+}
+
+void bconf_be_quiet(void)
+{
+	bconf.verbose = BTRFS_BCONF_QUIET;
 }
 
 /* Returns total size of main memory in bytes, -1UL if error. */
diff --git a/common/utils.h b/common/utils.h
index 1172618b8bb1..c650819644e5 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -117,16 +117,27 @@ unsigned long total_memory(void);
 void print_device_info(struct btrfs_device *device, char *prefix);
 void print_all_devices(struct list_head *devices);
 
+#define BTRFS_BCONF_UNSET	-1
+#define BTRFS_BCONF_QUIET	 0
 /*
  * Global program state, configurable by command line and available to
  * functions without extra context passing.
  */
 struct btrfs_config {
 	unsigned int output_format;
+
+	/* values
+	 *   BTRFS_BCONF_QUIET
+	 *   BTRFS_BCONF_UNSET
+	 *   > 0: Verbose level
+	 */
+	int verbose;
 };
 extern struct btrfs_config bconf;
 
 void btrfs_config_init(void);
+void bconf_be_verbose(void);
+void bconf_be_quiet(void);
 
 /* Pseudo random number generator wrappers */
 int rand_int(void);
-- 
2.25.1


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

* [PATCH v3 11/16] btrfs-progs: restore: use global verbose option
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (18 preceding siblings ...)
  2020-06-11 16:36 ` [PATCH v3 02/16] btrfs-progs: add global verbose and quiet options and helper functions Anand Jain
@ 2020-06-11 16:39 ` Anand Jain
  2020-06-11 16:41 ` [PATCH v2 16/16] btrfs-progs: device scan: add quiet option Anand Jain
  20 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-11 16:39 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Transpire global --verbose option down to the btrfs restore sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3: Use MUST_LOG
v2: Use new helper functions and defines
     HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
     bconf_be_verbose(), bconf_be_quiet() 

 cmds/restore.c | 58 ++++++++++++++++++++++----------------------------
 1 file changed, 26 insertions(+), 32 deletions(-)

diff --git a/cmds/restore.c b/cmds/restore.c
index 08f5b7e73183..bcd542507971 100644
--- a/cmds/restore.c
+++ b/cmds/restore.c
@@ -51,7 +51,6 @@ static char fs_name[PATH_MAX];
 static char path_name[PATH_MAX];
 static char symlink_target[PATH_MAX];
 static int get_snaps = 0;
-static int verbose = 0;
 static int restore_metadata = 0;
 static int restore_symlinks = 0;
 static int ignore_errors = 0;
@@ -386,8 +385,7 @@ static int copy_one_extent(struct btrfs_root *root, int fd,
 		size_left -= offset;
 	}
 
-	if (verbose && offset)
-		printf("offset is %Lu\n", offset);
+	pr_verbose(offset ? 1 : 0, "offset is %Lu\n", offset);
 
 	inbuf = malloc(size_left);
 	if (!inbuf) {
@@ -820,11 +818,15 @@ static int overwrite_ok(const char * path)
 		if (overwrite)
 			return 2;
 
-		if (verbose || !warn)
-			printf("Skipping existing file"
-				   " %s\n", path);
-		if (!warn)
-			printf("If you wish to overwrite use -o\n");
+		if (!warn) {
+			pr_verbose(MUST_LOG,
+				   "Skipping existing file %s\n", path);
+			pr_verbose(MUST_LOG,
+				   "If you wish to overwrite use -o\n");
+		} else {
+			pr_verbose(1, "Skipping existing file %s\n", path);
+		}
+
 		warn = 1;
 		return 0;
 	}
@@ -899,8 +901,7 @@ static int copy_symlink(struct btrfs_root *root, struct btrfs_key *key,
 		}
 	}
 
-	if (verbose >= 2)
-		printf("SYMLINK: '%s' => '%s'\n", path_name, symlink_target);
+	pr_verbose(2, "SYMLINK: '%s' => '%s'\n", path_name, symlink_target);
 
 	ret = 0;
 	if (!restore_metadata)
@@ -977,9 +978,8 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 
 	leaf = path.nodes[0];
 	while (!leaf) {
-		if (verbose > 1)
-			printf("No leaf after search, looking for the next "
-			       "leaf\n");
+		pr_verbose(2,
+			   "No leaf after search, looking for the next leaf\n");
 		ret = next_leaf(root, &path);
 		if (ret < 0) {
 			fprintf(stderr, "Error getting next leaf %d\n",
@@ -987,9 +987,8 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 			goto out;
 		} else if (ret > 0) {
 			/* No more leaves to search */
-			if (verbose)
-				printf("Reached the end of the tree looking "
-				       "for the directory\n");
+			pr_verbose(1,
+		   "Reached the end of the tree looking for the directory\n");
 			ret = 0;
 			goto out;
 		}
@@ -1013,10 +1012,8 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 					goto out;
 				} else if (ret > 0) {
 					/* No more leaves to search */
-					if (verbose)
-						printf("Reached the end of "
-						       "the tree searching the"
-						       " directory\n");
+					pr_verbose(1,
+		"Reached the end of the tree searching the directory\n");
 					ret = 0;
 					goto out;
 				}
@@ -1026,14 +1023,12 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 		}
 		btrfs_item_key_to_cpu(leaf, &found_key, path.slots[0]);
 		if (found_key.objectid != key->objectid) {
-			if (verbose > 1)
-				printf("Found objectid=%Lu, key=%Lu\n",
-				       found_key.objectid, key->objectid);
+			pr_verbose(2, "Found objectid=%Lu, key=%Lu\n",
+				   found_key.objectid, key->objectid);
 			break;
 		}
 		if (found_key.type != key->type) {
-			if (verbose > 1)
-				printf("Found type=%u, want=%u\n",
+			pr_verbose(2, "Found type=%u, want=%u\n",
 				       found_key.type, key->type);
 			break;
 		}
@@ -1062,8 +1057,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 			if (!overwrite_ok(path_name))
 				goto next;
 
-			if (verbose)
-				printf("Restoring %s\n", path_name);
+			pr_verbose(1, "Restoring %s\n", path_name);
 			if (dry_run)
 				goto next;
 			fd = open(path_name, O_CREAT|O_WRONLY, 0644);
@@ -1135,8 +1129,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 				location.objectid = BTRFS_FIRST_FREE_OBJECTID;
 			}
 
-			if (verbose)
-				printf("Restoring %s\n", path_name);
+			pr_verbose(1, "Restoring %s\n", path_name);
 
 			errno = 0;
 			if (dry_run)
@@ -1199,8 +1192,7 @@ next:
 		}
 	}
 
-	if (verbose)
-		printf("Done searching %s\n", in_dir);
+	pr_verbose(1, "Done searching %s\n", in_dir);
 out:
 	btrfs_release_path(&path);
 	return ret;
@@ -1410,6 +1402,8 @@ static const char * const cmd_restore_usage[] = {
 	"                     you have to use following syntax (possibly quoted):",
 	"                     ^/(|home(|/username(|/Desktop(|/.*))))$",
 	"-c                   ignore case (--path-regex only)",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -1462,7 +1456,7 @@ static int cmd_restore(const struct cmd_struct *cmd, int argc, char **argv)
 				get_snaps = 1;
 				break;
 			case 'v':
-				verbose++;
+				bconf_be_verbose();
 				break;
 			case 'i':
 				ignore_errors = 1;
-- 
2.25.1


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

* [PATCH v2 16/16] btrfs-progs: device scan: add quiet option
  2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
                   ` (19 preceding siblings ...)
  2020-06-11 16:39 ` [PATCH v3 11/16] btrfs-progs: restore: use global verbose option Anand Jain
@ 2020-06-11 16:41 ` Anand Jain
  20 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-11 16:41 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

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

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: use MUST_LOG

 cmds/device.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/cmds/device.c b/cmds/device.c
index a2c16ecb3034..26ac6d70b427 100644
--- a/cmds/device.c
+++ b/cmds/device.c
@@ -307,6 +307,7 @@ static const char * const cmd_device_scan_usage[] = {
 	" -u|--forget [<device>...]   unregister a given device or all stale devices if no path ",
 	HELPINFO_INSERT_GLOBALS,
 	HELPINFO_INSERT_VERBOSE,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
@@ -357,7 +358,8 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv)
 				error("cannot unregister devices: %m");
 			}
 		} else {
-			printf("Scanning for Btrfs filesystems\n");
+			pr_verbose(MUST_LOG,
+				   "Scanning for Btrfs filesystems\n");
 			ret = btrfs_scan_devices(1);
 			error_on(ret, "error %d while scanning", ret);
 			ret = btrfs_register_all_devices();
-- 
2.25.1


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

* [PATCH v3 06/16] btrfs-progs: filesystem defragment: use global verbose option
  2020-06-08  6:31   ` Anand Jain
@ 2020-06-11 16:56     ` Anand Jain
  0 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-11 16:56 UTC (permalink / raw)
  To: linux-btrfs

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>
---
v3: Space after HELPINFO_INSERT_VERBOSE, in the usage.
v2: Use new helper functions and defines
    HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
    bconf_be_verbose()

    No need to init bconf.verbose in the sub command.

    Move the HELPINFO_INSERT_GLOBALS, and HELPINFO_INSERT_VERBOSE, right
    after the command options.

 cmds/filesystem.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index 936db672e329..a582fa0a5aac 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -840,6 +840,8 @@ static const char * const cmd_filesystem_defrag_usage[] = {
 	"-s start            defragment only from byte onward",
 	"-l len              defragment only up to len bytes",
 	"-t size             target extent size hint (default: 32M)",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	"",
 	"Warning: most Linux kernels will break up the ref-links of COW data",
 	"(e.g., files copied with 'cp --reflink', snapshots) which may cause",
@@ -849,7 +851,6 @@ static const char * const cmd_filesystem_defrag_usage[] = {
 };
 
 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)
@@ -858,8 +859,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;
@@ -914,7 +914,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) {
@@ -932,7 +931,7 @@ static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
 			flush = 1;
 			break;
 		case 'v':
-			defrag_global_verbose = 1;
+			bconf_be_verbose();
 			break;
 		case 's':
 			start = parse_size(optarg);
@@ -1032,8 +1031,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;
-- 
2.25.1


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

* Re: [PATCH v2 00/16] btrfs-progs: global verbose and quiet option
  2020-06-05  9:24         ` David Sterba
  2020-06-05 10:12           ` Anand Jain
@ 2020-06-11 18:13           ` Anand Jain
  1 sibling, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-11 18:13 UTC (permalink / raw)
  To: dsterba, David Sterba, linux-btrfs



> Also, many options that have their own --verbose option should update
> the help text to note that it's an alias of the global.
> 
> I'm going to take another look today, the scope of the change might be
> too big to do in one go so some incremental steps might be needed.

  As global verbose depends on the local verbose to log messages, if
  local verbose used stderr then the global verbose uses the stderr.
  For example
  patch:
     btrfs-progs: send: use global verbose and quiet options

  ------------------
   ./btrfs send --help
  <snip>
     -v|--verbose     enable verbose output to stderr, each occurrence of
                      this option increases verbosity
     -q|--quiet       suppress all messages, except errors

     Global options:
     -v|--verbose       increase output verbosity
     -q|--quiet         print only errors
  ------------------

  IMO verbose should be stdout. Should it be ok to change to stdout as it
  is under verbose?

Thanks.

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

* [PATCH v3 02/16] btrfs-progs: add global verbose and quiet options and helper functions
  2019-11-25 10:39 ` [PATCH v2 02/16] btrfs-progs: add global verbose and quiet options and helper functions Anand Jain
@ 2020-06-12 10:56   ` Anand Jain
  2020-06-12 15:39     ` David Sterba
  2020-06-29 15:36     ` David Sterba
  0 siblings, 2 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-12 10:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Add btrfs(8) global --verbose and --quiet command options to show
verbose or no output from the sub-commands.
By introducing global a %bconf::verbose memeber to transpire the same
down to the sub-command.
Further the added helper function pr_verbose() helps to logs the verbose
messages, based on the state of the %bconf::verbose. And further HELPINFO_
defines are provides for the usage.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3:
  Add define MUST_LOG
  Add comment about the argument %level in the function pr_verbose()
v2:
  Add missing -q along with --quiet.
  Create and use bconf_be_verbose() and bconf_be_quiet().
  Change help wordings for verbose and quiet.
  Define and use BTRFS_BCONF_UNSET and BTRFS_BCONF_QUIET.
  Use HELPINFO_INSERT_GLOBALS.

 btrfs.c           | 20 ++++++++++++++++++--
 common/help.h     |  5 +++++
 common/messages.c | 30 ++++++++++++++++++++++++++++++
 common/messages.h |  4 ++++
 common/utils.c    | 14 ++++++++++++++
 common/utils.h    | 11 +++++++++++
 6 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/btrfs.c b/btrfs.c
index 72dad6fb3983..eb3b6183eb21 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -27,7 +27,7 @@
 #include "common/box.h"
 
 static const char * const btrfs_cmd_group_usage[] = {
-	"btrfs [--help] [--version] [--format <format>] <group> [<group>...] <command> [<args>]",
+	"btrfs [--help] [--version] [--format <format>] [-v|--verbose] [-q|--quiet] <group> [<group>...] <command> [<args>]",
 	NULL
 };
 
@@ -248,6 +248,8 @@ static int handle_global_options(int argc, char **argv)
 		{ "version", no_argument, NULL, OPT_VERSION },
 		{ "format", required_argument, NULL, OPT_FORMAT },
 		{ "full", no_argument, NULL, OPT_FULL },
+		{ "verbose", no_argument, NULL, 'v' },
+		{ "quiet", no_argument, NULL, 'q' },
 		{ NULL, 0, NULL, 0}
 	};
 	int shift;
@@ -259,7 +261,7 @@ static int handle_global_options(int argc, char **argv)
 	while (1) {
 		int c;
 
-		c = getopt_long(argc, argv, "+", long_options, NULL);
+		c = getopt_long(argc, argv, "+vq", long_options, NULL);
 		if (c < 0)
 			break;
 
@@ -270,6 +272,12 @@ static int handle_global_options(int argc, char **argv)
 		case OPT_FORMAT:
 			handle_output_format(optarg);
 			break;
+		case 'v':
+			bconf_be_verbose();
+			break;
+		case 'q':
+			bconf_be_quiet();
+			break;
 		default:
 			fprintf(stderr, "Unknown global option: %s\n",
 					argv[optind - 1]);
@@ -310,6 +318,14 @@ static void handle_special_globals(int shift, int argc, char **argv)
 			cmd_execute(&cmd_struct_version, argc, argv);
 			exit(0);
 		}
+
+	for (i = 0; i < shift; i++)
+		if (strcmp(argv[i], "--verbose") == 0)
+			bconf_be_verbose();
+
+	for (i = 0; i < shift; i++)
+		if (strcmp(argv[i], "--quiet") == 0)
+			bconf_be_quiet();
 }
 
 static const struct cmd_group btrfs_cmd_group = {
diff --git a/common/help.h b/common/help.h
index 91874abfe207..dbc5259d2277 100644
--- a/common/help.h
+++ b/common/help.h
@@ -60,6 +60,11 @@
 #define HELPINFO_INSERT_GLOBALS		"",					\
 					"Global options:"
 #define HELPINFO_INSERT_FORMAT		"--foramt TYPE"
+/*
+ * Global verbose option for the sub-commands
+ */
+#define HELPINFO_INSERT_VERBOSE	"-v|--verbose       increase output verbosity"
+#define HELPINFO_INSERT_QUIET	"-q|--quiet         print only errors"
 
 struct cmd_struct;
 struct cmd_group;
diff --git a/common/messages.c b/common/messages.c
index 0e5694ecd467..43ababe77519 100644
--- a/common/messages.c
+++ b/common/messages.c
@@ -17,6 +17,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include "common/messages.h"
+#include "common/utils.h"
 
 __attribute__ ((format (printf, 1, 2)))
 void __btrfs_warning(const char *fmt, ...)
@@ -75,3 +76,32 @@ int __btrfs_error_on(int condition, const char *fmt, ...)
 
 	return 1;
 }
+
+/*
+ * Print verbose helper function
+ * level: Minimum verbose level at which the message has to be printed.
+ *
+ * Values for argument level:
+ * MUST_LOG - Will log the message unless a quiet option is set.
+ *            Used where messages have to be printed for backward compatibility.
+ * > 0        Prints the message at the corresponding level.
+ */
+__attribute__ ((format (printf, 2, 3)))
+void pr_verbose(int level, const char *fmt, ...)
+{
+	va_list args;
+
+	if (bconf.verbose == BTRFS_BCONF_QUIET || level == BTRFS_BCONF_QUIET)
+		return;
+
+	/*
+	 * level is set by the threads requesting to print only if the command
+	 * verbose option is higher than the level.
+	 */
+	if (bconf.verbose < level)
+		return;
+
+	va_start(args, fmt);
+	vfprintf(stdout, fmt, args);
+	va_end(args);
+}
diff --git a/common/messages.h b/common/messages.h
index 596047948fef..288b32a77c10 100644
--- a/common/messages.h
+++ b/common/messages.h
@@ -96,3 +96,7 @@ __attribute__ ((format (printf, 2, 3)))
 int __btrfs_error_on(int condition, const char *fmt, ...);
 
 #endif
+
+#define	MUST_LOG	-1
+__attribute__ ((format (printf, 2, 3)))
+void pr_verbose(int level, const char *fmt, ...);
diff --git a/common/utils.c b/common/utils.c
index ebc50de2c143..0301efb0a348 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -1679,6 +1679,20 @@ u8 rand_u8(void)
 void btrfs_config_init(void)
 {
 	bconf.output_format = CMD_FORMAT_TEXT;
+	bconf.verbose = BTRFS_BCONF_UNSET;
+}
+
+void bconf_be_verbose(void)
+{
+	if (bconf.verbose == BTRFS_BCONF_UNSET)
+		bconf.verbose = 1;
+	else
+		bconf.verbose++;
+}
+
+void bconf_be_quiet(void)
+{
+	bconf.verbose = BTRFS_BCONF_QUIET;
 }
 
 /* Returns total size of main memory in bytes, -1UL if error. */
diff --git a/common/utils.h b/common/utils.h
index 1172618b8bb1..c650819644e5 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -117,16 +117,27 @@ unsigned long total_memory(void);
 void print_device_info(struct btrfs_device *device, char *prefix);
 void print_all_devices(struct list_head *devices);
 
+#define BTRFS_BCONF_UNSET	-1
+#define BTRFS_BCONF_QUIET	 0
 /*
  * Global program state, configurable by command line and available to
  * functions without extra context passing.
  */
 struct btrfs_config {
 	unsigned int output_format;
+
+	/* values
+	 *   BTRFS_BCONF_QUIET
+	 *   BTRFS_BCONF_UNSET
+	 *   > 0: Verbose level
+	 */
+	int verbose;
 };
 extern struct btrfs_config bconf;
 
 void btrfs_config_init(void);
+void bconf_be_verbose(void);
+void bconf_be_quiet(void);
 
 /* Pseudo random number generator wrappers */
 int rand_int(void);
-- 
2.25.1


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

* [PATCH v3 03/16] btrfs-progs: send: use global verbose and quiet options
  2019-11-25 10:39 ` [PATCH v2 03/16] btrfs-progs: send: use global verbose and quiet options Anand Jain
@ 2020-06-12 10:58   ` Anand Jain
  0 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-12 10:58 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Transpire global --verbose and --quiet options down to the btrfs send
sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3: update help and documentation
v2: Use new helper function and defines
    HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
    bconf_be_verbose(), bconf_be_quiet()

 Documentation/btrfs-send.asciidoc |  6 +++--
 cmds/send.c                       | 39 ++++++++++++++++++++-----------
 2 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/Documentation/btrfs-send.asciidoc b/Documentation/btrfs-send.asciidoc
index cd7ada76d14a..f76e808eed9e 100644
--- a/Documentation/btrfs-send.asciidoc
+++ b/Documentation/btrfs-send.asciidoc
@@ -58,9 +58,11 @@ is useful to show the differences in metadata.
 
 -v|--verbose::
 enable verbose output, print generated commands in a readable form, (each
-occurrence of this option increases the verbosity level)
+occurrence of this option increases the verbosity level). This option is
+merged to the global verbose option.
 -q|--quiet::
-suppress all messages except errors
+suppress all messages except errors. This option is merged to the global quiet
+option.
 
 EXIT STATUS
 -----------
diff --git a/cmds/send.c b/cmds/send.c
index 7ce6c3273857..b2afc6668f95 100644
--- a/cmds/send.c
+++ b/cmds/send.c
@@ -48,11 +48,6 @@
 
 #define SEND_BUFFER_SIZE	SZ_64K
 
-/*
- * Default is 1 for historical reasons, changing may break scripts that expect
- * the 'At subvol' message.
- */
-static int g_verbose = 1;
 
 struct btrfs_send {
 	int send_fd;
@@ -292,10 +287,10 @@ static int do_send(struct btrfs_send *send, u64 parent_root_id,
 				"Try upgrading your kernel or don't use -e.\n");
 		goto out;
 	}
-	if (g_verbose > 1)
+	if (bconf.verbose > 1)
 		fprintf(stderr, "BTRFS_IOC_SEND returned %d\n", ret);
 
-	if (g_verbose > 1)
+	if (bconf.verbose > 1)
 		fprintf(stderr, "joining genl thread\n");
 
 	close(pipefd[1]);
@@ -458,8 +453,13 @@ static const char * const cmd_send_usage[] = {
 	"                 to transfer changes. This mode is faster and useful to",
 	"                 show the differences in metadata.",
 	"-v|--verbose     enable verbose output to stderr, each occurrence of",
-	"                 this option increases verbosity",
-	"-q|--quiet       suppress all messages, except errors",
+	"                 this option increases verbosity. This option is",
+	"                 merged to the global verbose option.",
+	"-q|--quiet       suppress all messages, except errors. This option is",
+	"                 merged to the global quiet option.",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
@@ -482,6 +482,17 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv)
 	send.dump_fd = fileno(stdout);
 	outname[0] = 0;
 
+	/*
+	 * For send, verbose default is 1 (insteasd of 0) for historical reasons,
+	 * changing may break scripts that expect the 'At subvol' message. But do
+	 * it only when bconf.verbose is unset (-1) and also adjust the value,
+	 * if global verbose is already set.
+	 */
+	if (bconf.verbose == BTRFS_BCONF_UNSET)
+		bconf.verbose = 1;
+	else if (bconf.verbose > BTRFS_BCONF_QUIET)
+		bconf.verbose++;
+
 	optind = 0;
 	while (1) {
 		enum { GETOPT_VAL_SEND_NO_DATA = 256 };
@@ -497,10 +508,10 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv)
 
 		switch (c) {
 		case 'v':
-			g_verbose++;
+			bconf_be_verbose();
 			break;
 		case 'q':
-			g_verbose = 0;
+			bconf_be_quiet();
 			break;
 		case 'e':
 			new_end_cmd_semantic = 1;
@@ -680,8 +691,8 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv)
 		}
 	}
 
-	if ((send_flags & BTRFS_SEND_FLAG_NO_FILE_DATA) && g_verbose > 1)
-		if (g_verbose > 1)
+	if ((send_flags & BTRFS_SEND_FLAG_NO_FILE_DATA) && bconf.verbose > 1)
+		if (bconf.verbose > 1)
 			fprintf(stderr, "Mode NO_FILE_DATA enabled\n");
 
 	for (i = optind; i < argc; i++) {
@@ -691,7 +702,7 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv)
 		free(subvol);
 		subvol = argv[i];
 
-		if (g_verbose > 0)
+		if (bconf.verbose > BTRFS_BCONF_QUIET)
 			fprintf(stderr, "At subvol %s\n", subvol);
 
 		subvol = realpath(subvol, NULL);
-- 
2.25.1


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

* [PATCH v3 04/16] btrfs-progs: receive: use global verbose and quiet options
  2019-11-25 10:39 ` [PATCH v2 04/16] btrfs-progs: receive: " Anand Jain
@ 2020-06-12 11:24   ` Anand Jain
  0 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-12 11:24 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Transpire global --verbose and --quiet options down to the btrfs receive
sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3: Updae the help and documentation
v2: Use new helper functions and defines
    HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
    bconf_be_verbose(), bconf_be_quiet()

 Documentation/btrfs-receive.asciidoc |  6 +-
 cmds/receive.c                       | 86 ++++++++++++++++------------
 2 files changed, 52 insertions(+), 40 deletions(-)

diff --git a/Documentation/btrfs-receive.asciidoc b/Documentation/btrfs-receive.asciidoc
index a271d89b9d7d..aed08ba5e705 100644
--- a/Documentation/btrfs-receive.asciidoc
+++ b/Documentation/btrfs-receive.asciidoc
@@ -36,10 +36,12 @@ A subvolume is made read-only after the receiving process finishes successfully
 `Options`
 
 -v::
-increase verbosity about performed actions, print details about each operation
+increase verbosity about performed actions, print details about each operation.
+This option is merged to the global verbose option.
 
 -q|--quiet::
-suppress all messages except errors
+suppress all messages except errors. This option is merged to the global quiet option.
+
 
 -f <FILE>::
 read the stream from <FILE> instead of stdin,
diff --git a/cmds/receive.c b/cmds/receive.c
index 74b73f488a0d..95fc09b8ce9f 100644
--- a/cmds/receive.c
+++ b/cmds/receive.c
@@ -53,12 +53,6 @@
 #include "common/help.h"
 #include "common/path-utils.h"
 
-/*
- * Default is 1 for historical reasons, changing may break scripts that expect
- * the 'At subvol' message.
- */
-static int g_verbose = 1;
-
 struct btrfs_receive
 {
 	int mnt_fd;
@@ -116,7 +110,7 @@ static int finish_subvol(struct btrfs_receive *rctx)
 	memcpy(rs_args.uuid, rctx->cur_subvol.received_uuid, BTRFS_UUID_SIZE);
 	rs_args.stransid = rctx->cur_subvol.stransid;
 
-	if (g_verbose >= 2) {
+	if (bconf.verbose >= 2) {
 		uuid_unparse((u8*)rs_args.uuid, uuid_str);
 		fprintf(stderr, "BTRFS_IOC_SET_RECEIVED_SUBVOL uuid=%s, "
 				"stransid=%llu\n", uuid_str, rs_args.stransid);
@@ -199,13 +193,13 @@ static int process_subvol(const char *path, const u8 *uuid, u64 ctransid,
 		goto out;
 	}
 
-	if (g_verbose)
+	if (bconf.verbose > BTRFS_BCONF_QUIET)
 		fprintf(stderr, "At subvol %s\n", path);
 
 	memcpy(rctx->cur_subvol.received_uuid, uuid, BTRFS_UUID_SIZE);
 	rctx->cur_subvol.stransid = ctransid;
 
-	if (g_verbose >= 2) {
+	if (bconf.verbose >= 2) {
 		uuid_unparse((u8*)rctx->cur_subvol.received_uuid, uuid_str);
 		fprintf(stderr, "receiving subvol %s uuid=%s, stransid=%llu\n",
 				path, uuid_str,
@@ -269,13 +263,12 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
 		goto out;
 	}
 
-	if (g_verbose)
-		fprintf(stdout, "At snapshot %s\n", path);
+	pr_verbose(1, "At snapshot %s\n", path);
 
 	memcpy(rctx->cur_subvol.received_uuid, uuid, BTRFS_UUID_SIZE);
 	rctx->cur_subvol.stransid = ctransid;
 
-	if (g_verbose >= 2) {
+	if (bconf.verbose >= 2) {
 		uuid_unparse((u8*)rctx->cur_subvol.received_uuid, uuid_str);
 		fprintf(stderr, "receiving snapshot %s uuid=%s, "
 				"ctransid=%llu ", path, uuid_str,
@@ -393,7 +386,7 @@ static int process_mkfile(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mkfile %s\n", path);
 
 	ret = creat(full_path, 0600);
@@ -421,7 +414,7 @@ static int process_mkdir(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mkdir %s\n", path);
 
 	ret = mkdir(full_path, 0700);
@@ -446,7 +439,7 @@ static int process_mknod(const char *path, u64 mode, u64 dev, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mknod %s mode=%llu, dev=%llu\n",
 				path, mode, dev);
 
@@ -472,7 +465,7 @@ static int process_mkfifo(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mkfifo %s\n", path);
 
 	ret = mkfifo(full_path, 0600);
@@ -497,7 +490,7 @@ static int process_mksock(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mksock %s\n", path);
 
 	ret = mknod(full_path, 0600 | S_IFSOCK, 0);
@@ -522,7 +515,7 @@ static int process_symlink(const char *path, const char *lnk, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "symlink %s -> %s\n", path, lnk);
 
 	ret = symlink(lnk, full_path);
@@ -554,7 +547,7 @@ static int process_rename(const char *from, const char *to, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "rename %s -> %s\n", from, to);
 
 	ret = rename(full_from, full_to);
@@ -586,7 +579,7 @@ static int process_link(const char *path, const char *lnk, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "link %s -> %s\n", path, lnk);
 
 	ret = link(full_link_path, full_path);
@@ -612,7 +605,7 @@ static int process_unlink(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "unlink %s\n", path);
 
 	ret = unlink(full_path);
@@ -637,7 +630,7 @@ static int process_rmdir(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "rmdir %s\n", path);
 
 	ret = rmdir(full_path);
@@ -702,7 +695,7 @@ static int process_write(const char *path, const void *data, u64 offset,
 	if (ret < 0)
 		goto out;
 
-	if (g_verbose >= 2)
+	if (bconf.verbose >= 2)
 		fprintf(stderr, "write %s - offset=%llu length=%llu\n",
 			path, offset, len);
 
@@ -792,7 +785,7 @@ static int process_clone(const char *path, u64 offset, u64 len,
 		goto out;
 	}
 
-	if (g_verbose >= 2)
+	if (bconf.verbose >= 2)
 		fprintf(stderr,
 			"clone %s - source=%s source offset=%llu offset=%llu length=%llu\n",
 			path, clone_path, clone_offset, offset, len);
@@ -833,7 +826,7 @@ static int process_set_xattr(const char *path, const char *name,
 	}
 
 	if (strcmp("security.capability", name) == 0) {
-		if (g_verbose >= 4)
+		if (bconf.verbose >= 4)
 			fprintf(stderr, "set_xattr: cache capabilities\n");
 		if (rctx->cached_capabilities_len)
 			warning("capabilities set multiple times per file: %s",
@@ -848,7 +841,7 @@ static int process_set_xattr(const char *path, const char *name,
 		memcpy(rctx->cached_capabilities, data, len);
 	}
 
-	if (g_verbose >= 3) {
+	if (bconf.verbose >= 3) {
 		fprintf(stderr, "set_xattr %s - name=%s data_len=%d "
 				"data=%.*s\n", path, name, len,
 				len, (char*)data);
@@ -878,7 +871,7 @@ static int process_remove_xattr(const char *path, const char *name, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3) {
+	if (bconf.verbose >= 3) {
 		fprintf(stderr, "remove_xattr %s - name=%s\n",
 				path, name);
 	}
@@ -906,7 +899,7 @@ static int process_truncate(const char *path, u64 size, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "truncate %s size=%llu\n", path, size);
 
 	ret = truncate(full_path, size);
@@ -932,7 +925,7 @@ static int process_chmod(const char *path, u64 mode, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "chmod %s - mode=0%o\n", path, (int)mode);
 
 	ret = chmod(full_path, mode);
@@ -958,7 +951,7 @@ static int process_chown(const char *path, u64 uid, u64 gid, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "chown %s - uid=%llu, gid=%llu\n", path,
 				uid, gid);
 
@@ -970,7 +963,7 @@ static int process_chown(const char *path, u64 uid, u64 gid, void *user)
 	}
 
 	if (rctx->cached_capabilities_len) {
-		if (g_verbose >= 3)
+		if (bconf.verbose >= 3)
 			fprintf(stderr, "chown: restore capabilities\n");
 		ret = lsetxattr(full_path, "security.capability",
 				rctx->cached_capabilities,
@@ -1004,7 +997,7 @@ static int process_utimes(const char *path, struct timespec *at,
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "utimes %s\n", path);
 
 	tv[0] = *at;
@@ -1023,7 +1016,7 @@ out:
 static int process_update_extent(const char *path, u64 offset, u64 len,
 		void *user)
 {
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "update_extent %s: offset=%llu, len=%llu\n",
 				path, (unsigned long long)offset,
 				(unsigned long long)len);
@@ -1163,7 +1156,7 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
 
 	while (!end) {
 		if (rctx->cached_capabilities_len) {
-			if (g_verbose >= 4)
+			if (bconf.verbose >= 4)
 				fprintf(stderr, "clear cached capabilities\n");
 			memset(rctx->cached_capabilities, 0,
 					sizeof(rctx->cached_capabilities));
@@ -1236,8 +1229,10 @@ static const char * const cmd_receive_usage[] = {
 	"After receiving a subvolume, it is immediately set to",
 	"read-only.",
 	"",
-	"-v               increase verbosity about performed actions",
-	"-q|--quiet       suppress all messages, except errors",
+	"-v               increase verbosity about performed actions. This",
+	"                 option is merged to the global verbose option.",
+	"-q|--quiet       suppress all messages, except errors. This option",
+	"                 is merged with the global quiet option.",
 	"-f FILE          read the stream from FILE instead of stdin",
 	"-e               terminate after receiving an <end cmd> marker in the stream.",
 	"                 Without this option the receiver side terminates only in case",
@@ -1252,6 +1247,9 @@ static const char * const cmd_receive_usage[] = {
 	"                 this file system is mounted.",
 	"--dump           dump stream metadata, one line per operation,",
 	"                 does not require the MOUNT parameter",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
@@ -1274,6 +1272,18 @@ static int cmd_receive(const struct cmd_struct *cmd, int argc, char **argv)
 	realmnt[0] = 0;
 	fromfile[0] = 0;
 
+	/*
+	 * Init global verbose to default, if it is unset.
+	 * Default is 1 for historical reasons, changing may break scripts that
+	 * expect the 'At subvol' message.
+	 * As default is 1, which means the effective verbose for receive is 2
+	 * which global verbose is unaware. So adjust global verbose value here.
+	 */
+	if (bconf.verbose == BTRFS_BCONF_UNSET)
+		bconf.verbose = 1;
+	else if (bconf.verbose > BTRFS_BCONF_QUIET)
+		bconf.verbose++;
+
 	optind = 0;
 	while (1) {
 		int c;
@@ -1292,10 +1302,10 @@ static int cmd_receive(const struct cmd_struct *cmd, int argc, char **argv)
 
 		switch (c) {
 		case 'v':
-			g_verbose++;
+			bconf_be_verbose();
 			break;
 		case 'q':
-			g_verbose = 0;
+			bconf_be_quiet();
 			break;
 		case 'f':
 			if (arg_copy_path(fromfile, optarg, sizeof(fromfile))) {
-- 
2.25.1


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

* [PATCH v3 05/16] btrfs-progs: subvolume delete: use global verbose option
  2019-11-25 10:39 ` [PATCH v2 05/16] btrfs-progs: subvolume delete: use global verbose option Anand Jain
@ 2020-06-12 11:24   ` Anand Jain
  0 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-12 11:24 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Transpire global --verbose option down to the btrfs subvolume delete
sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
V3: Update the help and documentation
v2: Use new helper functions and defines
    HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
    bconf_be_verbose(), bconf_be_quiet()

 Documentation/btrfs-subvolume.asciidoc |  3 ++-
 cmds/subvolume.c                       | 31 +++++++++++++-------------
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/Documentation/btrfs-subvolume.asciidoc b/Documentation/btrfs-subvolume.asciidoc
index d8c414fd5c60..47f0cc471297 100644
--- a/Documentation/btrfs-subvolume.asciidoc
+++ b/Documentation/btrfs-subvolume.asciidoc
@@ -87,7 +87,8 @@ wait for transaction commit at the end of the operation.
 wait for transaction commit after deleting each subvolume.
 +
 -v|--verbose::::
-verbose output of operations.
+verbose output of operations. This option is merged to the global verbose
+option.
 +
 -i|--subvolid <subvolid>::::
 subvolume id to be removed instead of the <path> that should point to the
diff --git a/cmds/subvolume.c b/cmds/subvolume.c
index 6f1d90358785..b1606fbd398c 100644
--- a/cmds/subvolume.c
+++ b/cmds/subvolume.c
@@ -236,7 +236,10 @@ static const char * const cmd_subvol_delete_usage[] = {
 	"-c|--commit-after      wait for transaction commit at the end of the operation",
 	"-C|--commit-each       wait for transaction commit after deleting each subvolume",
 	"-i|--subvolid          subvolume id of the to be removed subvolume",
-	"-v|--verbose           verbose output of operations",
+	"-v|--verbose           verbose output of operations. This option is",
+	"                       merged to the global verbose option.",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -251,7 +254,6 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd,
 	char	*dupvname = NULL;
 	char	*path = NULL;
 	DIR	*dirstream = NULL;
-	int verbose = 0;
 	int commit_mode = 0;
 	u8 fsid[BTRFS_FSID_SIZE];
 	u64 subvolid = 0;
@@ -287,7 +289,7 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd,
 			subvolid = arg_strtou64(optarg);
 			break;
 		case 'v':
-			verbose++;
+			bconf_be_verbose();
 			break;
 		default:
 			usage_unknown_option(cmd, argv);
@@ -301,11 +303,9 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd,
 	if (subvolid > 0 && check_argc_exact(argc - optind, 1))
 		return 1;
 
-	if (verbose > 0) {
-		printf("Transaction commit: %s\n",
-			!commit_mode ? "none (default)" :
-			commit_mode == COMMIT_AFTER ? "at the end" : "after each");
-	}
+	pr_verbose(1, "Transaction commit: %s\n",
+		   !commit_mode ? "none (default)" :
+		   commit_mode == COMMIT_AFTER ? "at the end" : "after each");
 
 	cnt = optind;
 
@@ -395,11 +395,9 @@ again:
 		}
 
 		if (add_seen_fsid(fsid, seen_fsid_hash, fd, dirstream) == 0) {
-			if (verbose > 0) {
-				uuid_unparse(fsid, uuidbuf);
-				printf("  new fs is found for '%s', fsid: %s\n",
-						path, uuidbuf);
-			}
+			uuid_unparse(fsid, uuidbuf);
+			pr_verbose(1, "  new fs is found for '%s', fsid: %s\n",
+				   path, uuidbuf);
 			/*
 			 * This is the first time a subvolume on this
 			 * filesystem is deleted, keep fd in order to issue
@@ -440,10 +438,11 @@ keep_fd:
 			"unable to do final sync after deletion: %m, fsid: %s",
 						uuidbuf);
 					ret = 1;
-				} else if (verbose > 0) {
+				} else {
 					uuid_unparse(seen->fsid, uuidbuf);
-					printf("final sync is done for fsid: %s\n",
-						uuidbuf);
+					pr_verbose(1,
+					   "final sync is done for fsid: %s\n",
+						   uuidbuf);
 				}
 				seen = seen->next;
 			}
-- 
2.25.1


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

* [PATCH v4 06/16] btrfs-progs: filesystem defragment: use global verbose option
  2019-11-25 10:39 ` [PATCH v2 06/16] btrfs-progs: filesystem defragment: " Anand Jain
  2020-06-08  6:31   ` Anand Jain
@ 2020-06-12 11:25   ` Anand Jain
  1 sibling, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-12 11:25 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

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>
---
v4: Update help and documentation
v3: Space after HELPINFO_INSERT_VERBOSE, in the usage.
v2: Use new helper functions and defines
    HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
    bconf_be_verbose()

    No need to init bconf.verbose in the sub command.

    Move the HELPINFO_INSERT_GLOBALS, and HELPINFO_INSERT_VERBOSE, right
    after the command options.

 Documentation/btrfs-filesystem.asciidoc |  3 ++-
 cmds/filesystem.c                       | 15 +++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/Documentation/btrfs-filesystem.asciidoc b/Documentation/btrfs-filesystem.asciidoc
index 151b7889d8a5..ad8717a70949 100644
--- a/Documentation/btrfs-filesystem.asciidoc
+++ b/Documentation/btrfs-filesystem.asciidoc
@@ -111,7 +111,8 @@ KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).
 `Options`
 +
 -v::::
-be verbose, print file names as they're submitted for defragmentation
+be verbose, print file names as they're submitted for defragmentation. This
+option is merged to the global verbose option.
 -c[<algo>]::::
 compress file contents while defragmenting. Optional argument selects the compression
 algorithm, 'zlib' (default), 'lzo' or 'zstd'. Currently it's not possible to select no
diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index 936db672e329..d4ffc000e59b 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -833,13 +833,16 @@ static const char * const cmd_filesystem_defrag_usage[] = {
 	"btrfs filesystem defragment [options] <file>|<dir> [<file>|<dir>...]",
 	"Defragment a file or a directory",
 	"",
-	"-v                  be verbose",
+	"-v                  be verbose. This option is merged to the global",
+	"                    verbose option.",
 	"-r                  defragment files recursively",
 	"-c[zlib,lzo,zstd]   compress the file while defragmenting",
 	"-f                  flush data to disk immediately after defragmenting",
 	"-s start            defragment only from byte onward",
 	"-l len              defragment only up to len bytes",
 	"-t size             target extent size hint (default: 32M)",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	"",
 	"Warning: most Linux kernels will break up the ref-links of COW data",
 	"(e.g., files copied with 'cp --reflink', snapshots) which may cause",
@@ -849,7 +852,6 @@ static const char * const cmd_filesystem_defrag_usage[] = {
 };
 
 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)
@@ -858,8 +860,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;
@@ -914,7 +915,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) {
@@ -932,7 +932,7 @@ static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
 			flush = 1;
 			break;
 		case 'v':
-			defrag_global_verbose = 1;
+			bconf_be_verbose();
 			break;
 		case 's':
 			start = parse_size(optarg);
@@ -1032,8 +1032,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;
-- 
2.25.1


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

* [PATCH v3 07/16] btrfs-progs: balance start: use global verbose option
  2019-11-25 10:39 ` [PATCH v2 07/16] btrfs-progs: balance start: " Anand Jain
@ 2020-06-12 11:25   ` Anand Jain
  0 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-12 11:25 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Transpire global --verbose option down to the btrfs balance start
sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3: update help and documentation
v2: Use new helper functions and defines
    HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
    bconf_be_verbose(), bconf_be_quiet()

    No need to init bconf.verbose in the sub command.

 Documentation/btrfs-balance.asciidoc |  3 ++-
 cmds/balance.c                       | 10 ++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/Documentation/btrfs-balance.asciidoc b/Documentation/btrfs-balance.asciidoc
index 8afd76da2177..4d81692a60d8 100644
--- a/Documentation/btrfs-balance.asciidoc
+++ b/Documentation/btrfs-balance.asciidoc
@@ -99,7 +99,8 @@ act on metadata chunks, see `FILTERS` section for details about 'filters'
 -s[<filters>]::::
 act on system chunks (requires '-f'), see `FILTERS` section for details about 'filters'.
 -v::::
-be verbose and print balance filter arguments
+be verbose and print balance filter arguments. This option is merged to the
+global verbose option.
 -f::::
 force a reduction of metadata integrity, eg. when going from 'raid1' to 'single'
 --background|--bg::::
diff --git a/cmds/balance.c b/cmds/balance.c
index 8b611185bd7d..73bfedba1405 100644
--- a/cmds/balance.c
+++ b/cmds/balance.c
@@ -494,11 +494,14 @@ static const char * const cmd_balance_start_usage[] = {
 	"-d[filters]    act on data chunks",
 	"-m[filters]    act on metadata chunks",
 	"-s[filters]    act on system chunks (only under -f)",
-	"-v|--verbose   be verbose",
+	"-v|--verbose   be verbose. This option is merged to the global",
+	"               verbose option.",
 	"-f             force a reduction of metadata integrity",
 	"--full-balance do not print warning and do not delay start",
 	"--background|--bg",
 	"               run the balance as a background process",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -509,7 +512,6 @@ static int cmd_balance_start(const struct cmd_struct *cmd,
 	struct btrfs_balance_args *ptrs[] = { &args.data, &args.sys,
 						&args.meta, NULL };
 	int force = 0;
-	int verbose = 0;
 	int background = 0;
 	unsigned start_flags = 0;
 	int i;
@@ -564,7 +566,7 @@ static int cmd_balance_start(const struct cmd_struct *cmd,
 			force = 1;
 			break;
 		case 'v':
-			verbose = 1;
+			bconf_be_verbose();
 			break;
 		case GETOPT_VAL_FULL_BALANCE:
 			start_flags |= BALANCE_START_NOWARN;
@@ -640,7 +642,7 @@ static int cmd_balance_start(const struct cmd_struct *cmd,
 
 	if (force)
 		args.flags |= BTRFS_BALANCE_FORCE;
-	if (verbose)
+	if (bconf.verbose > BTRFS_BCONF_QUIET)
 		dump_ioctl_balance_args(&args);
 	if (background) {
 		switch (fork()) {
-- 
2.25.1


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

* [PATCH v3 08/16] btrfs-progs: balance status: use global verbose option
  2019-11-25 10:39 ` [PATCH v2 08/16] btrfs-progs: balance status: " Anand Jain
@ 2020-06-12 11:25   ` Anand Jain
  0 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-12 11:25 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Transpire global --verbose option down to the btrfs balance status
sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3: update help and documentation
v2: Use new helper functions and defines
    HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
    bconf_be_verbose(), bconf_be_quiet()

    No need to init bconf.verbose in the sub command.

 Documentation/btrfs-balance.asciidoc |  3 ++-
 cmds/balance.c                       | 10 ++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/Documentation/btrfs-balance.asciidoc b/Documentation/btrfs-balance.asciidoc
index 4d81692a60d8..2dccb1cc523e 100644
--- a/Documentation/btrfs-balance.asciidoc
+++ b/Documentation/btrfs-balance.asciidoc
@@ -110,7 +110,8 @@ start the process that calls the kernel ioctl
 *status* [-v] <path>::
 Show status of running or paused balance.
 +
-If '-v' option is given, output will be verbose.
+If '-v' option is given, output will be verbose. This option is merged to the
+global verbose option.
 
 FILTERS
 -------
diff --git a/cmds/balance.c b/cmds/balance.c
index 73bfedba1405..4b4adc2ceae6 100644
--- a/cmds/balance.c
+++ b/cmds/balance.c
@@ -830,7 +830,10 @@ static const char * const cmd_balance_status_usage[] = {
 	"btrfs balance status [-v] <path>",
 	"Show status of running or paused balance",
 	"",
-	"-v|--verbose     be verbose",
+	"-v|--verbose     be verbose. This option is merged to the global",
+	"                 verbose option.",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -847,7 +850,6 @@ static int cmd_balance_status(const struct cmd_struct *cmd,
 	const char *path;
 	DIR *dirstream = NULL;
 	int fd;
-	int verbose = 0;
 	int ret;
 
 	optind = 0;
@@ -864,7 +866,7 @@ static int cmd_balance_status(const struct cmd_struct *cmd,
 
 		switch (opt) {
 		case 'v':
-			verbose = 1;
+			bconf_be_verbose();
 			break;
 		default:
 			usage_unknown_option(cmd, argv);
@@ -910,7 +912,7 @@ static int cmd_balance_status(const struct cmd_struct *cmd,
 	       (unsigned long long)args.stat.considered,
 	       100 * (1 - (float)args.stat.completed/args.stat.expected));
 
-	if (verbose)
+	if (bconf.verbose > BTRFS_BCONF_QUIET)
 		dump_ioctl_balance_args(&args);
 
 	ret = 1;
-- 
2.25.1


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

* [PATCH v3 09/16] btrfs-progs: rescue chunk-recover: use global verbose option
  2019-11-25 10:39 ` [PATCH v2 09/16] btrfs-progs: rescue chunk-recover: " Anand Jain
@ 2020-06-12 11:25   ` Anand Jain
  0 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-12 11:25 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Transpire global --verbose option down to the btrfs rescue chunk-recover
sub-command.

For example: Both global and local verbose options are now supported.
 btrfs -v|--verbose rescue chunk-recover
 btrfs rescue chunk-recover -v

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3: update help and documentation
v2: Use new helper functions and defines
     HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
     bconf_be_verbose(), bconf_be_quiet()
    Drop verbose argument in init_recover_control()

 Documentation/btrfs-rescue.asciidoc |  2 +-
 cmds/rescue-chunk-recover.c         |  9 ++++-----
 cmds/rescue.c                       | 14 ++++++++++----
 cmds/rescue.h                       |  2 +-
 4 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/Documentation/btrfs-rescue.asciidoc b/Documentation/btrfs-rescue.asciidoc
index f94a0ff2b45e..995515890e9e 100644
--- a/Documentation/btrfs-rescue.asciidoc
+++ b/Documentation/btrfs-rescue.asciidoc
@@ -24,7 +24,7 @@ Recover the chunk tree by scanning the devices
 -y::::
 assume an answer of 'yes' to all questions.
 -v::::
-verbose mode.
+verbose mode. This option is merged to the global verbose option.
 -h::::
 help.
 
diff --git a/cmds/rescue-chunk-recover.c b/cmds/rescue-chunk-recover.c
index a13acc015d11..1854e7984127 100644
--- a/cmds/rescue-chunk-recover.c
+++ b/cmds/rescue-chunk-recover.c
@@ -194,8 +194,7 @@ static struct btrfs_chunk *create_chunk_item(struct chunk_record *record)
 	return ret;
 }
 
-static void init_recover_control(struct recover_control *rc, int verbose,
-		int yes)
+static void init_recover_control(struct recover_control *rc, int yes)
 {
 	memset(rc, 0, sizeof(struct recover_control));
 	cache_tree_init(&rc->chunk);
@@ -208,7 +207,7 @@ static void init_recover_control(struct recover_control *rc, int verbose,
 	INIT_LIST_HEAD(&rc->rebuild_chunks);
 	INIT_LIST_HEAD(&rc->unrepaired_chunks);
 
-	rc->verbose = verbose;
+	rc->verbose = bconf.verbose;
 	rc->yes = yes;
 	pthread_mutex_init(&rc->rc_lock, NULL);
 }
@@ -2319,14 +2318,14 @@ static void validate_rebuild_chunks(struct recover_control *rc)
 /*
  * Return 0 when successful, < 0 on error and > 0 if aborted by user
  */
-int btrfs_recover_chunk_tree(const char *path, int verbose, int yes)
+int btrfs_recover_chunk_tree(const char *path, int yes)
 {
 	int ret = 0;
 	struct btrfs_root *root = NULL;
 	struct btrfs_trans_handle *trans;
 	struct recover_control rc;
 
-	init_recover_control(&rc, verbose, yes);
+	init_recover_control(&rc, yes);
 
 	ret = recover_prepare(&rc, path);
 	if (ret) {
diff --git a/cmds/rescue.c b/cmds/rescue.c
index 087c33befeff..bb65a672bbf3 100644
--- a/cmds/rescue.c
+++ b/cmds/rescue.c
@@ -38,8 +38,11 @@ static const char * const cmd_rescue_chunk_recover_usage[] = {
 	"Recover the chunk tree by scanning the devices one by one.",
 	"",
 	"-y	Assume an answer of `yes' to all questions",
-	"-v	Verbose mode",
+	"-v	Verbose mode. This option is merged to the global verbose",
+        "       option",
 	"-h	Help",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -49,7 +52,10 @@ static int cmd_rescue_chunk_recover(const struct cmd_struct *cmd,
 	int ret = 0;
 	char *file;
 	int yes = 0;
-	int verbose = 0;
+
+	/* If verbose is unset, set it to 0 */
+	if (bconf.verbose == BTRFS_BCONF_UNSET)
+		bconf.verbose = BTRFS_BCONF_QUIET;
 
 	optind = 0;
 	while (1) {
@@ -61,7 +67,7 @@ static int cmd_rescue_chunk_recover(const struct cmd_struct *cmd,
 			yes = 1;
 			break;
 		case 'v':
-			verbose = 1;
+			bconf.verbose++;
 			break;
 		default:
 			usage_unknown_option(cmd, argv);
@@ -83,7 +89,7 @@ static int cmd_rescue_chunk_recover(const struct cmd_struct *cmd,
 		return 1;
 	}
 
-	ret = btrfs_recover_chunk_tree(file, verbose, yes);
+	ret = btrfs_recover_chunk_tree(file, yes);
 	if (!ret) {
 		fprintf(stdout, "Chunk tree recovered successfully\n");
 	} else if (ret > 0) {
diff --git a/cmds/rescue.h b/cmds/rescue.h
index de486e2e2004..e594954f78e2 100644
--- a/cmds/rescue.h
+++ b/cmds/rescue.h
@@ -16,6 +16,6 @@
 #define __BTRFS_RESCUE_H__
 
 int btrfs_recover_superblocks(const char *path, int verbose, int yes);
-int btrfs_recover_chunk_tree(const char *path, int verbose, int yes);
+int btrfs_recover_chunk_tree(const char *path, int yes);
 
 #endif
-- 
2.25.1


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

* [PATCH v3 10/16] btrfs-progs: rescue super-recover: use global verbose option
  2019-11-25 10:39 ` [PATCH v2 10/16] btrfs-progs: rescue super-recover: " Anand Jain
@ 2020-06-12 11:25   ` Anand Jain
  0 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-12 11:25 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Transpire global --verbose option down to the btrfs rescue super-recover
sub-command.

For example: Both global and local verbose options are now supported.
btrfs -v|--verbose rescue super-recover
btrfs rescue super-recover -v

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3: update help and documentation
v2: Use new helper functions and defines
     HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
     bconf_be_verbose(), bconf_be_quiet()
    Drop verbose argument in btrfs_recover_superblocks()

 Documentation/btrfs-rescue.asciidoc |  2 +-
 cmds/rescue-super-recover.c         |  7 +++----
 cmds/rescue.c                       | 10 ++++++----
 cmds/rescue.h                       |  2 +-
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/Documentation/btrfs-rescue.asciidoc b/Documentation/btrfs-rescue.asciidoc
index 995515890e9e..b48c55189844 100644
--- a/Documentation/btrfs-rescue.asciidoc
+++ b/Documentation/btrfs-rescue.asciidoc
@@ -58,7 +58,7 @@ Recover bad superblocks from good copies.
 -y::::
 assume an answer of 'yes' to all questions.
 -v::::
-verbose mode.
+verbose mode. This option is merged to the global verbose option.
 
 *zero-log* <device>::
 clear the filesystem log tree
diff --git a/cmds/rescue-super-recover.c b/cmds/rescue-super-recover.c
index 5d6bea836c8b..3a60eb40c8bb 100644
--- a/cmds/rescue-super-recover.c
+++ b/cmds/rescue-super-recover.c
@@ -226,8 +226,7 @@ static void recover_err_str(int ret)
 	}
 }
 
-int btrfs_recover_superblocks(const char *dname,
-			int verbose, int yes)
+int btrfs_recover_superblocks(const char *dname, int yes)
 {
 	int fd, ret;
 	struct btrfs_recover_superblock recover;
@@ -249,7 +248,7 @@ int btrfs_recover_superblocks(const char *dname,
 		goto no_recover;
 	}
 
-	if (verbose)
+	if (bconf.verbose > BTRFS_BCONF_QUIET)
 		print_all_devices(&recover.fs_devices->devices);
 
 	ret = read_fs_supers(&recover);
@@ -257,7 +256,7 @@ int btrfs_recover_superblocks(const char *dname,
 		ret = 1;
 		goto no_recover;
 	}
-	if (verbose) {
+	if (bconf.verbose > BTRFS_BCONF_QUIET) {
 		printf("Before Recovering:\n");
 		print_all_supers(&recover);
 	}
diff --git a/cmds/rescue.c b/cmds/rescue.c
index bb65a672bbf3..1d53cf446a96 100644
--- a/cmds/rescue.c
+++ b/cmds/rescue.c
@@ -107,7 +107,10 @@ static const char * const cmd_rescue_super_recover_usage[] = {
 	"Recover bad superblocks from good copies",
 	"",
 	"-y	Assume an answer of `yes' to all questions",
-	"-v	Verbose mode",
+	"-v	Verbose mode. This option is merged to the global verbose",
+	"	option",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -123,7 +126,6 @@ static int cmd_rescue_super_recover(const struct cmd_struct *cmd,
 				    int argc, char **argv)
 {
 	int ret;
-	int verbose = 0;
 	int yes = 0;
 	char *dname;
 
@@ -134,7 +136,7 @@ static int cmd_rescue_super_recover(const struct cmd_struct *cmd,
 			break;
 		switch (c) {
 		case 'v':
-			verbose = 1;
+			bconf_be_verbose();
 			break;
 		case 'y':
 			yes = 1;
@@ -156,7 +158,7 @@ static int cmd_rescue_super_recover(const struct cmd_struct *cmd,
 		error("the device is busy");
 		return 1;
 	}
-	ret = btrfs_recover_superblocks(dname, verbose, yes);
+	ret = btrfs_recover_superblocks(dname, yes);
 	return ret;
 }
 static DEFINE_SIMPLE_COMMAND(rescue_super_recover, "super-recover");
diff --git a/cmds/rescue.h b/cmds/rescue.h
index e594954f78e2..3b99ec6b0daa 100644
--- a/cmds/rescue.h
+++ b/cmds/rescue.h
@@ -15,7 +15,7 @@
 #ifndef __BTRFS_RESCUE_H__
 #define __BTRFS_RESCUE_H__
 
-int btrfs_recover_superblocks(const char *path, int verbose, int yes);
+int btrfs_recover_superblocks(const char *path, int yes);
 int btrfs_recover_chunk_tree(const char *path, int yes);
 
 #endif
-- 
2.25.1


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

* [PATCH v3 11/16] btrfs-progs: restore: use global verbose option
  2019-11-25 10:39 ` [PATCH v2 11/16] btrfs-progs: restore: " Anand Jain
@ 2020-06-12 11:26   ` Anand Jain
  0 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-12 11:26 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Transpire global --verbose option down to the btrfs restore sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3: update help and documentation
v2: Use new helper functions and defines
     HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
     bconf_be_verbose(), bconf_be_quiet()

 Documentation/btrfs-restore.asciidoc |  3 +-
 cmds/restore.c                       | 60 +++++++++++++---------------
 2 files changed, 29 insertions(+), 34 deletions(-)

diff --git a/Documentation/btrfs-restore.asciidoc b/Documentation/btrfs-restore.asciidoc
index 090dcc555bc2..9174c2951db3 100644
--- a/Documentation/btrfs-restore.asciidoc
+++ b/Documentation/btrfs-restore.asciidoc
@@ -48,7 +48,8 @@ restore owner, mode and times for files and directories
 restore symbolic links as well as normal files
 
 -v|--verbose::
-be verbose and print what is being restored
+be verbose and print what is being restored. This option is merged to the
+global verbose option
 
 -i|--ignore-errors::
 ignore errors during restoration and continue
diff --git a/cmds/restore.c b/cmds/restore.c
index 08f5b7e73183..e587ee33beab 100644
--- a/cmds/restore.c
+++ b/cmds/restore.c
@@ -51,7 +51,6 @@ static char fs_name[PATH_MAX];
 static char path_name[PATH_MAX];
 static char symlink_target[PATH_MAX];
 static int get_snaps = 0;
-static int verbose = 0;
 static int restore_metadata = 0;
 static int restore_symlinks = 0;
 static int ignore_errors = 0;
@@ -386,8 +385,7 @@ static int copy_one_extent(struct btrfs_root *root, int fd,
 		size_left -= offset;
 	}
 
-	if (verbose && offset)
-		printf("offset is %Lu\n", offset);
+	pr_verbose(offset ? 1 : 0, "offset is %Lu\n", offset);
 
 	inbuf = malloc(size_left);
 	if (!inbuf) {
@@ -820,11 +818,15 @@ static int overwrite_ok(const char * path)
 		if (overwrite)
 			return 2;
 
-		if (verbose || !warn)
-			printf("Skipping existing file"
-				   " %s\n", path);
-		if (!warn)
-			printf("If you wish to overwrite use -o\n");
+		if (!warn) {
+			pr_verbose(MUST_LOG,
+				   "Skipping existing file %s\n", path);
+			pr_verbose(MUST_LOG,
+				   "If you wish to overwrite use -o\n");
+		} else {
+			pr_verbose(1, "Skipping existing file %s\n", path);
+		}
+
 		warn = 1;
 		return 0;
 	}
@@ -899,8 +901,7 @@ static int copy_symlink(struct btrfs_root *root, struct btrfs_key *key,
 		}
 	}
 
-	if (verbose >= 2)
-		printf("SYMLINK: '%s' => '%s'\n", path_name, symlink_target);
+	pr_verbose(2, "SYMLINK: '%s' => '%s'\n", path_name, symlink_target);
 
 	ret = 0;
 	if (!restore_metadata)
@@ -977,9 +978,8 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 
 	leaf = path.nodes[0];
 	while (!leaf) {
-		if (verbose > 1)
-			printf("No leaf after search, looking for the next "
-			       "leaf\n");
+		pr_verbose(2,
+			   "No leaf after search, looking for the next leaf\n");
 		ret = next_leaf(root, &path);
 		if (ret < 0) {
 			fprintf(stderr, "Error getting next leaf %d\n",
@@ -987,9 +987,8 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 			goto out;
 		} else if (ret > 0) {
 			/* No more leaves to search */
-			if (verbose)
-				printf("Reached the end of the tree looking "
-				       "for the directory\n");
+			pr_verbose(1,
+		   "Reached the end of the tree looking for the directory\n");
 			ret = 0;
 			goto out;
 		}
@@ -1013,10 +1012,8 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 					goto out;
 				} else if (ret > 0) {
 					/* No more leaves to search */
-					if (verbose)
-						printf("Reached the end of "
-						       "the tree searching the"
-						       " directory\n");
+					pr_verbose(1,
+		"Reached the end of the tree searching the directory\n");
 					ret = 0;
 					goto out;
 				}
@@ -1026,14 +1023,12 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 		}
 		btrfs_item_key_to_cpu(leaf, &found_key, path.slots[0]);
 		if (found_key.objectid != key->objectid) {
-			if (verbose > 1)
-				printf("Found objectid=%Lu, key=%Lu\n",
-				       found_key.objectid, key->objectid);
+			pr_verbose(2, "Found objectid=%Lu, key=%Lu\n",
+				   found_key.objectid, key->objectid);
 			break;
 		}
 		if (found_key.type != key->type) {
-			if (verbose > 1)
-				printf("Found type=%u, want=%u\n",
+			pr_verbose(2, "Found type=%u, want=%u\n",
 				       found_key.type, key->type);
 			break;
 		}
@@ -1062,8 +1057,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 			if (!overwrite_ok(path_name))
 				goto next;
 
-			if (verbose)
-				printf("Restoring %s\n", path_name);
+			pr_verbose(1, "Restoring %s\n", path_name);
 			if (dry_run)
 				goto next;
 			fd = open(path_name, O_CREAT|O_WRONLY, 0644);
@@ -1135,8 +1129,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
 				location.objectid = BTRFS_FIRST_FREE_OBJECTID;
 			}
 
-			if (verbose)
-				printf("Restoring %s\n", path_name);
+			pr_verbose(1, "Restoring %s\n", path_name);
 
 			errno = 0;
 			if (dry_run)
@@ -1199,8 +1192,7 @@ next:
 		}
 	}
 
-	if (verbose)
-		printf("Done searching %s\n", in_dir);
+	pr_verbose(1, "Done searching %s\n", in_dir);
 out:
 	btrfs_release_path(&path);
 	return ret;
@@ -1395,7 +1387,7 @@ static const char * const cmd_restore_usage[] = {
 	"-x|--xattr           restore extended attributes",
 	"-m|--metadata        restore owner, mode and times",
 	"-S|--symlink         restore symbolic links",
-	"-v|--verbose         verbose",
+	"-v|--verbose         verbose. This option is merged to the global verbose option",
 	"-i|--ignore-errors   ignore errors",
 	"-o|--overwrite       overwrite",
 	"-t <bytenr>          tree location",
@@ -1410,6 +1402,8 @@ static const char * const cmd_restore_usage[] = {
 	"                     you have to use following syntax (possibly quoted):",
 	"                     ^/(|home(|/username(|/Desktop(|/.*))))$",
 	"-c                   ignore case (--path-regex only)",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -1462,7 +1456,7 @@ static int cmd_restore(const struct cmd_struct *cmd, int argc, char **argv)
 				get_snaps = 1;
 				break;
 			case 'v':
-				verbose++;
+				bconf_be_verbose();
 				break;
 			case 'i':
 				ignore_errors = 1;
-- 
2.25.1


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

* [PATCH v3 12/16] btrfs-progs: inspect-internal inode-resolve: use global verbose
  2019-11-25 10:39 ` [PATCH v2 12/16] btrfs-progs: inspect-internal inode-resolve: use global verbose Anand Jain
@ 2020-06-12 11:26   ` Anand Jain
  0 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-12 11:26 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Transpire global --verbose option down to the
btrfs inspect-internal inode-resolve sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3: update help and documentation
v2: Use new helper functions and defines
     HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
     bconf_be_verbose(), bconf_be_quiet()

 Documentation/btrfs-inspect-internal.asciidoc |  1 +
 cmds/inspect.c                                | 22 +++++++++----------
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/Documentation/btrfs-inspect-internal.asciidoc b/Documentation/btrfs-inspect-internal.asciidoc
index 0718070d8905..e8d4c861603d 100644
--- a/Documentation/btrfs-inspect-internal.asciidoc
+++ b/Documentation/btrfs-inspect-internal.asciidoc
@@ -139,6 +139,7 @@ at 'path', ie. all hardlinks
 +
 -v::::
 verbose mode, print count of returned paths and ioctl() return value
+This option is merged to the global verbose option
 
 *logical-resolve* [-Pvo] [-s <bufsize>] <logical> <path>::
 (needs root privileges)
diff --git a/cmds/inspect.c b/cmds/inspect.c
index 5b946da08b72..b0d3c8102400 100644
--- a/cmds/inspect.c
+++ b/cmds/inspect.c
@@ -56,12 +56,11 @@ static int __ino_to_path_fd(u64 inum, int fd, int verbose, const char *prepend)
 		goto out;
 	}
 
-	if (verbose)
-		printf("ioctl ret=%d, bytes_left=%lu, bytes_missing=%lu, "
-			"cnt=%d, missed=%d\n", ret,
-			(unsigned long)fspath->bytes_left,
-			(unsigned long)fspath->bytes_missing,
-			fspath->elem_cnt, fspath->elem_missed);
+	pr_verbose(1,
+	"ioctl ret=%d, bytes_left=%lu, bytes_missing=%lu cnt=%d, missed=%d\n",
+		   ret, (unsigned long)fspath->bytes_left,
+		   (unsigned long)fspath->bytes_missing, fspath->elem_cnt,
+		   fspath->elem_missed);
 
 	for (i = 0; i < fspath->elem_cnt; ++i) {
 		u64 ptr;
@@ -83,7 +82,9 @@ static const char * const cmd_inspect_inode_resolve_usage[] = {
 	"btrfs inspect-internal inode-resolve [-v] <inode> <path>",
 	"Get file system paths for the given inode",
 	"",
-	"-v   verbose mode",
+	"-v   verbose mode. This option is merged to the global verbose option",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -91,7 +92,6 @@ static int cmd_inspect_inode_resolve(const struct cmd_struct *cmd,
 				     int argc, char **argv)
 {
 	int fd;
-	int verbose = 0;
 	int ret;
 	DIR *dirstream = NULL;
 
@@ -103,7 +103,7 @@ static int cmd_inspect_inode_resolve(const struct cmd_struct *cmd,
 
 		switch (c) {
 		case 'v':
-			verbose = 1;
+			bconf_be_verbose();
 			break;
 		default:
 			usage_unknown_option(cmd, argv);
@@ -117,8 +117,8 @@ static int cmd_inspect_inode_resolve(const struct cmd_struct *cmd,
 	if (fd < 0)
 		return 1;
 
-	ret = __ino_to_path_fd(arg_strtou64(argv[optind]), fd, verbose,
-			       argv[optind+1]);
+	ret = __ino_to_path_fd(arg_strtou64(argv[optind]), fd,
+			       bconf.verbose, argv[optind+1]);
 	close_file_or_dir(fd, dirstream);
 	return !!ret;
 
-- 
2.25.1


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

* [PATCH v3 13/16] btrfs-progs: inspect-internal logical-resolve: use global verbose option
  2019-11-25 10:39 ` [PATCH v2 13/16] btrfs-progs: inspect-internal logical-resolve: use global verbose option Anand Jain
@ 2020-06-12 11:26   ` Anand Jain
  0 siblings, 0 replies; 47+ messages in thread
From: Anand Jain @ 2020-06-12 11:26 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

Transpire global --verbose option down to the
btrfs inspect-internal logical-resolve sub-command.

Command btrfs inspect-internal logical-resolve provides local verbose
option this patch makes it enable-able by using the global --verbose
option.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3: update help and documentation
v2: Use new helper function bconf_be_verbose()

 Documentation/btrfs-inspect-internal.asciidoc |  1 +
 cmds/inspect.c                                | 25 ++++++++-----------
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/Documentation/btrfs-inspect-internal.asciidoc b/Documentation/btrfs-inspect-internal.asciidoc
index e8d4c861603d..c0009e2e5382 100644
--- a/Documentation/btrfs-inspect-internal.asciidoc
+++ b/Documentation/btrfs-inspect-internal.asciidoc
@@ -152,6 +152,7 @@ resolve paths to all files at given 'logical' address in the linear filesystem s
 skip the path resolving and print the inodes instead
 -v::::
 verbose mode, print count of returned paths and all ioctl() return values
+This option is merged to the global verbose option
 -o::::
 ignore offsets, find all references to an extent instead of a single block.
 Requires kernel support for the V2 ioctl (added in 4.15). The results might need
diff --git a/cmds/inspect.c b/cmds/inspect.c
index b0d3c8102400..bbbac4431ac7 100644
--- a/cmds/inspect.c
+++ b/cmds/inspect.c
@@ -38,7 +38,7 @@ static const char * const inspect_cmd_group_usage[] = {
 	NULL
 };
 
-static int __ino_to_path_fd(u64 inum, int fd, int verbose, const char *prepend)
+static int __ino_to_path_fd(u64 inum, int fd, const char *prepend)
 {
 	int ret;
 	int i;
@@ -117,8 +117,7 @@ static int cmd_inspect_inode_resolve(const struct cmd_struct *cmd,
 	if (fd < 0)
 		return 1;
 
-	ret = __ino_to_path_fd(arg_strtou64(argv[optind]), fd,
-			       bconf.verbose, argv[optind+1]);
+	ret = __ino_to_path_fd(arg_strtou64(argv[optind]), fd, argv[optind+1]);
 	close_file_or_dir(fd, dirstream);
 	return !!ret;
 
@@ -137,6 +136,8 @@ static const char * const cmd_inspect_logical_resolve_usage[] = {
 	"            container's size in case it is not enough to read all the ",
 	"            resolved results. The max value one can set is 64k with the",
 	"            v1 ioctl. Sizes over 64k will use the v2 ioctl (kernel 4.15+)",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
 	NULL
 };
 
@@ -146,7 +147,6 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd,
 	int ret;
 	int fd;
 	int i;
-	int verbose = 0;
 	int getpath = 1;
 	int bytes_left;
 	struct btrfs_ioctl_logical_ino_args loi = { 0 };
@@ -169,7 +169,7 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd,
 			getpath = 0;
 			break;
 		case 'v':
-			verbose = 1;
+			bconf_be_verbose();
 			break;
 		case 'o':
 			flags |= BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET;
@@ -211,13 +211,11 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd,
 		goto out;
 	}
 
-	if (verbose)
-		printf("ioctl ret=%d, total_size=%llu, bytes_left=%lu, "
-			"bytes_missing=%lu, cnt=%d, missed=%d\n",
-			ret, size,
-			(unsigned long)inodes->bytes_left,
-			(unsigned long)inodes->bytes_missing,
-			inodes->elem_cnt, inodes->elem_missed);
+	pr_verbose(1,
+"ioctl ret=%d, total_size=%llu, bytes_left=%lu, bytes_missing=%lu, cnt=%d, missed=%d\n",
+		   ret, size, (unsigned long)inodes->bytes_left,
+		   (unsigned long)inodes->bytes_missing, inodes->elem_cnt,
+		   inodes->elem_missed);
 
 	bytes_left = sizeof(full_path);
 	ret = snprintf(full_path, bytes_left, "%s/", argv[optind+1]);
@@ -262,8 +260,7 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd,
 					goto out;
 				}
 			}
-			ret = __ino_to_path_fd(inum, path_fd, verbose,
-						full_path);
+			ret = __ino_to_path_fd(inum, path_fd, full_path);
 			if (path_fd != fd)
 				close_file_or_dir(path_fd, dirs);
 		} else {
-- 
2.25.1


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

* Re: [PATCH v3 02/16] btrfs-progs: add global verbose and quiet options and helper functions
  2020-06-12 10:56   ` [PATCH v3 " Anand Jain
@ 2020-06-12 15:39     ` David Sterba
  2020-06-12 22:48       ` Anand Jain
  2020-06-29 15:36     ` David Sterba
  1 sibling, 1 reply; 47+ messages in thread
From: David Sterba @ 2020-06-12 15:39 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, dsterba

On Fri, Jun 12, 2020 at 06:56:06PM +0800, Anand Jain wrote:
> Add btrfs(8) global --verbose and --quiet command options to show
> verbose or no output from the sub-commands.
> By introducing global a %bconf::verbose memeber to transpire the same
> down to the sub-command.
> Further the added helper function pr_verbose() helps to logs the verbose
> messages, based on the state of the %bconf::verbose. And further HELPINFO_
> defines are provides for the usage.
> 
> Suggested-by: David Sterba <dsterba@suse.com>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> v3:
>   Add define MUST_LOG
>   Add comment about the argument %level in the function pr_verbose()

Now you've created quite some chaos here, why didn't you just send v3 as
a standalone patchset? Replies to individual patches works for small
fixups but not as a whole new iteration.

The second part now depends on this v3 that has the MUST_LOG define
burried in patch 2/16, while it should have been one extra patch to the
second part and we'd be done with that. I'll sort it out somehow but ...

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

* Re: [PATCH v3 02/16] btrfs-progs: add global verbose and quiet options and helper functions
  2020-06-12 15:39     ` David Sterba
@ 2020-06-12 22:48       ` Anand Jain
  2020-06-23 16:44         ` David Sterba
  0 siblings, 1 reply; 47+ messages in thread
From: Anand Jain @ 2020-06-12 22:48 UTC (permalink / raw)
  To: dsterba, linux-btrfs, dsterba



On 12/6/20 11:39 pm, David Sterba wrote:
> On Fri, Jun 12, 2020 at 06:56:06PM +0800, Anand Jain wrote:
>> Add btrfs(8) global --verbose and --quiet command options to show
>> verbose or no output from the sub-commands.
>> By introducing global a %bconf::verbose memeber to transpire the same
>> down to the sub-command.
>> Further the added helper function pr_verbose() helps to logs the verbose
>> messages, based on the state of the %bconf::verbose. And further HELPINFO_
>> defines are provides for the usage.
>>
>> Suggested-by: David Sterba <dsterba@suse.com>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>> v3:
>>    Add define MUST_LOG
>>    Add comment about the argument %level in the function pr_verbose()
> 
> Now you've created quite some chaos here, why didn't you just send v3 as
> a standalone patchset? Replies to individual patches works for small
> fixups but not as a whole new iteration.
> 
> The second part now depends on this v3 that has the MUST_LOG define
> burried in patch 2/16, while it should have been one extra patch to the
> second part and we'd be done with that. I'll sort it out somehow but ...
> 

  Yeah, standalone patch would have been simpler. It was painful at my
  end too. Sorry about that.

  On a different topic. I checked with you before - by legacy send.c and
  receive.c use stderr for verbosity. Is it a regression to change these
  to stdout now?


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

* Re: [PATCH v3 02/16] btrfs-progs: add global verbose and quiet options and helper functions
  2020-06-12 22:48       ` Anand Jain
@ 2020-06-23 16:44         ` David Sterba
  0 siblings, 0 replies; 47+ messages in thread
From: David Sterba @ 2020-06-23 16:44 UTC (permalink / raw)
  To: Anand Jain; +Cc: dsterba, linux-btrfs, dsterba

On Sat, Jun 13, 2020 at 06:48:00AM +0800, Anand Jain wrote:
>   On a different topic. I checked with you before - by legacy send.c and
>   receive.c use stderr for verbosity. Is it a regression to change these
>   to stdout now?

If stdout is used to dump the stream data we cannot obviously print the
messages there. When the -f option is used, the stdout is available but
I'm not sure we want to switch the output descriptor based on an option.
For now I think it needs to stay.

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

* Re: [PATCH v3 02/16] btrfs-progs: add global verbose and quiet options and helper functions
  2020-06-12 10:56   ` [PATCH v3 " Anand Jain
  2020-06-12 15:39     ` David Sterba
@ 2020-06-29 15:36     ` David Sterba
  1 sibling, 0 replies; 47+ messages in thread
From: David Sterba @ 2020-06-29 15:36 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, dsterba

On Fri, Jun 12, 2020 at 06:56:06PM +0800, Anand Jain wrote:
> Add btrfs(8) global --verbose and --quiet command options to show
> verbose or no output from the sub-commands.
> By introducing global a %bconf::verbose memeber to transpire the same
> down to the sub-command.
> Further the added helper function pr_verbose() helps to logs the verbose
> messages, based on the state of the %bconf::verbose. And further HELPINFO_
> defines are provides for the usage.
> 
> Suggested-by: David Sterba <dsterba@suse.com>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> v3:
>   Add define MUST_LOG
>   Add comment about the argument %level in the function pr_verbose()

So the v2 got merged and v3 is not usable as replacement because I did a
lot of fixups to v2 that would be lost. The updated help text and
documentation need to reflect that the subcommand specific options are
deprecated but still kept as an alias.

+	"-q|--quiet       suppress all messages, except errors. This option is",
+	"                 merged to the global quiet option.

In particular, I find the use of word 'merged' to be confusing here.
The final wording is:

-v       deprecated, alias for global -v option

or

-q       deprecated, alias for global -q option

and the options are last in the list. Similar for the documentation,
plus several fixup of spacing. All these things are just help text
updates but user-facing and it has its own importance. I had not
anticipated that merging that would be such time sink despite the
relative simplicity.

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

end of thread, other threads:[~2020-06-29 21:23 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
2019-11-25 10:39 ` [PATCH 01/16] btrfs-progs: split global help HELPINFO_INSERT_GLOBALS Anand Jain
2019-11-25 10:39 ` [PATCH v2 02/16] btrfs-progs: add global verbose and quiet options and helper functions Anand Jain
2020-06-12 10:56   ` [PATCH v3 " Anand Jain
2020-06-12 15:39     ` David Sterba
2020-06-12 22:48       ` Anand Jain
2020-06-23 16:44         ` David Sterba
2020-06-29 15:36     ` David Sterba
2019-11-25 10:39 ` [PATCH v2 03/16] btrfs-progs: send: use global verbose and quiet options Anand Jain
2020-06-12 10:58   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 04/16] btrfs-progs: receive: " Anand Jain
2020-06-12 11:24   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 05/16] btrfs-progs: subvolume delete: use global verbose option Anand Jain
2020-06-12 11:24   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 06/16] btrfs-progs: filesystem defragment: " Anand Jain
2020-06-08  6:31   ` Anand Jain
2020-06-11 16:56     ` [PATCH v3 " Anand Jain
2020-06-12 11:25   ` [PATCH v4 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 07/16] btrfs-progs: balance start: " Anand Jain
2020-06-12 11:25   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 08/16] btrfs-progs: balance status: " Anand Jain
2020-06-12 11:25   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 09/16] btrfs-progs: rescue chunk-recover: " Anand Jain
2020-06-12 11:25   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 10/16] btrfs-progs: rescue super-recover: " Anand Jain
2020-06-12 11:25   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 11/16] btrfs-progs: restore: " Anand Jain
2020-06-12 11:26   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 12/16] btrfs-progs: inspect-internal inode-resolve: use global verbose Anand Jain
2020-06-12 11:26   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 13/16] btrfs-progs: inspect-internal logical-resolve: use global verbose option Anand Jain
2020-06-12 11:26   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH 14/16] btrfs-progs: refactor btrfs_scan_devices() to accept verbose argument Anand Jain
2019-11-25 10:39 ` [PATCH v2 15/16] btrfs-progs: device scan: add verbose option Anand Jain
2019-11-25 10:39 ` [PATCH 16/16] btrfs-progs: device scan: add quiet option Anand Jain
2019-12-20  5:36 ` [PATCH v2 00/16] btrfs-progs: global verbose and " Anand Jain
2020-01-14  6:14 ` Anand Jain
2020-01-14 11:40   ` David Sterba
2020-03-28  5:45     ` Anand Jain
2020-05-20 10:01       ` Anand Jain
2020-06-05  9:24         ` David Sterba
2020-06-05 10:12           ` Anand Jain
2020-06-10 10:17             ` David Sterba
2020-06-11 18:13           ` Anand Jain
2020-06-11 16:36 ` [PATCH v3 02/16] btrfs-progs: add global verbose and quiet options and helper functions Anand Jain
2020-06-11 16:39 ` [PATCH v3 11/16] btrfs-progs: restore: use global verbose option Anand Jain
2020-06-11 16:41 ` [PATCH v2 16/16] btrfs-progs: device scan: add quiet option Anand Jain

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).