btrfs-progs: global verbose and quiet option
Subsystems (2)
v2 cover btrfs-progs: global verbose and quiet option
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(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/16 btrfs-progs: split global help HELPINFO_INSERT_GLOBALS
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:
--- common/help.c | 4 +--- common/help.h | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-)
common/help.c +1 -3
@@ -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++) {
common/help.h +3 -1
@@ -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 ;
Signature · 1 line
1.8.3.1
PATCH v2 2/16 btrfs-progs: add global verbose and quiet options and helper functions
In reply to Anand JainAdd 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.
---
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(-)
btrfs.c +18 -2
@@ -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 = {
common/help.h +5 -0
@@ -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 ;
common/messages.c +25 -0
@@ -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); +}
common/messages.h +3 -0
@@ -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, ...);
common/utils.c +14 -0
@@ -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. */
common/utils.h +11 -0
@@ -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 );
Signature · 1 line
1.8.3.1
PATCH v3 2/16 btrfs-progs: add global verbose and quiet options and helper functions
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.
---
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(-)
btrfs.c +18 -2
@@ -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 = {
common/help.h +5 -0
@@ -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 ;
common/messages.c +30 -0
@@ -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); +}
common/messages.h +4 -0
@@ -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, ...);
common/utils.c +14 -0
@@ -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. */
common/utils.h +11 -0
@@ -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 );
Signature · 1 line
2.25.1
Re: [PATCH v3 02/16] btrfs-progs: add global verbose and quiet options and helper functions
Quoted 8 lines · Anand Jain
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 functionpr_verbose()helps to logs the verbose messages, based on the state of the %bconf::verbose. And furtherHELPINFO_defines are provides for the usage.
Quoted 6 lines
Suggested-by David Sterba <[email protected]>Signed-off-by Anand Jain <[email protected]>---
v3:
Add defineMUST_LOG
Add comment about the argument %level in the functionpr_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 ...
Re: [PATCH v3 02/16] btrfs-progs: add global verbose and quiet options and helper functions
Quoted 16 lines · David Sterba
Quoted 8 lines · Anand Jain
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 functionpr_verbose()helps to logs the verbose messages, based on the state of the %bconf::verbose. And furtherHELPINFO_defines are provides for the usage.Quoted 6 lines
Suggested-by David Sterba <[email protected]>Signed-off-by Anand Jain <[email protected]>---
v3:
Add defineMUST_LOG
Add comment about the argument %level in the functionpr_verbose()
Quoted 8 lines
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_LOGdefine 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?
Re: [PATCH v3 02/16] btrfs-progs: add global verbose and quiet options and helper functions
Quoted 3 lines · Anand Jain
On a different topic. I checked with you before - by legacy
send.candreceive.cuse 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.
Re: [PATCH v3 02/16] btrfs-progs: add global verbose and quiet options and helper functions
In reply to Anand JainQuoted 8 lines · Anand Jain
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 functionpr_verbose()helps to logs the verbose messages, based on the state of the %bconf::verbose. And furtherHELPINFO_defines are provides for the usage.
Quoted 6 lines
Suggested-by David Sterba <[email protected]>Signed-off-by Anand Jain <[email protected]>---
v3:
Add defineMUST_LOG
Add comment about the argument %level in the functionpr_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.
PATCH v2 3/16 btrfs-progs: send: use global verbose and quiet options
In reply to Anand JainTranspire global --verbose and --quiet options down to the btrfs send sub-command.
---
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(-)
cmds/send.c +21 -12
@@ -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 );
Signature · 1 line
1.8.3.1
PATCH v3 3/16 btrfs-progs: send: use global verbose and quiet options
Transpire global --verbose and --quiet options down to the btrfs send sub-command.
---
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(-)
Documentation/btrfs-send.asciidoc +4 -2
@@ -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 -----------
cmds/send.c +25 -14
@@ -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 );
Signature · 1 line
2.25.1
PATCH v2 4/16 btrfs-progs: receive: use global verbose and quiet options
In reply to Anand JainTranspire global --verbose and --quiet options down to the btrfs receive sub-command.
---
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(-)
cmds/receive.c +44 -36
@@ -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))) {
Signature · 1 line
1.8.3.1
PATCH v3 4/16 btrfs-progs: receive: use global verbose and quiet options
Transpire global --verbose and --quiet options down to the btrfs receive sub-command.
---
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(-)
Documentation/btrfs-receive.asciidoc +4 -2
@@ -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,
cmds/receive.c +48 -38
277 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 5/16 btrfs-progs: subvolume delete: use global verbose option
In reply to Anand JainTranspire global --verbose option down to the btrfs subvolume delete sub-command.
---
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(-)
cmds/subvolume.c +13 -15
@@ -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; }
Signature · 1 line
1.8.3.1
PATCH v3 5/16 btrfs-progs: subvolume delete: use global verbose option
Transpire global --verbose option down to the btrfs subvolume delete sub-command.
---
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(-)
Documentation/btrfs-subvolume.asciidoc +2 -1
@@ -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
cmds/subvolume.c +15 -16
@@ -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; }
Signature · 1 line
2.25.1
PATCH v2 6/16 btrfs-progs: filesystem defragment: use global verbose option
In reply to Anand JainTranspire global --verbose option down to the btrfs receive sub-command.
---
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(-)
cmds/filesystem.c +5 -7
@@ -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;
Signature · 1 line
1.8.3.1
Re: [PATCH v2 06/16] btrfs-progs: filesystem defragment: use global verbose option
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.
cmds/filesystem.c static const char * const cmd_filesystem_defrag_usage[] = { · line 847
Quoted 13 lines
cmds/filesystem.c +2
-0@@ -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
PATCH v3 6/16 btrfs-progs: filesystem defragment: use global verbose option
Transpire global --verbose option down to the btrfs receive sub-command.
---
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(-)
cmds/filesystem.c +5 -7
@@ -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;
Signature · 1 line
2.25.1
PATCH v4 6/16 btrfs-progs: filesystem defragment: use global verbose option
In reply to Anand JainTranspire global --verbose option down to the btrfs receive sub-command.
---
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(-)
Documentation/btrfs-filesystem.asciidoc +2 -1
@@ -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
cmds/filesystem.c +7 -8
@@ -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;
Signature · 1 line
2.25.1
PATCH v2 7/16 btrfs-progs: balance start: use global verbose option
In reply to Anand JainTranspire global --verbose option down to the btrfs balance start sub-command.
---
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(-)
cmds/balance.c +4 -3
@@ -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 ()) {
Signature · 1 line
1.8.3.1
PATCH v3 7/16 btrfs-progs: balance start: use global verbose option
Transpire global --verbose option down to the btrfs balance start sub-command.
---
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(-)
Documentation/btrfs-balance.asciidoc +2 -1
@@ -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::::
cmds/balance.c +6 -4
@@ -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 ()) {
Signature · 1 line
2.25.1
PATCH v2 8/16 btrfs-progs: balance status: use global verbose option
In reply to Anand JainTranspire global --verbose option down to the btrfs balance status sub-command.
---
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(-)
cmds/balance.c +4 -3
@@ -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 ;
Signature · 1 line
1.8.3.1
PATCH v3 8/16 btrfs-progs: balance status: use global verbose option
Transpire global --verbose option down to the btrfs balance status sub-command.
---
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(-)
Documentation/btrfs-balance.asciidoc +2 -1
@@ -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 -------
cmds/balance.c +6 -4
@@ -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 ;
Signature · 1 line
2.25.1
PATCH v2 9/16 btrfs-progs: rescue chunk-recover: use global verbose option
In reply to Anand JainTranspire 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
---
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(-)
cmds/rescue-chunk-recover.c +4 -5
@@ -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) {
cmds/rescue.c +8 -3
@@ -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 ) {
cmds/rescue.h +1 -1
@@ -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
Signature · 1 line
1.8.3.1
PATCH v3 9/16 btrfs-progs: rescue chunk-recover: use global verbose option
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
---
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(-)
Documentation/btrfs-rescue.asciidoc +1 -1
@@ -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.
cmds/rescue-chunk-recover.c +4 -5
@@ -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) {
cmds/rescue.c +10 -4
@@ -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 ) {
cmds/rescue.h +1 -1
@@ -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
Signature · 1 line
2.25.1
PATCH v2 10/16 btrfs-progs: rescue super-recover: use global verbose option
In reply to Anand JainTranspire 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
---
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(-)
cmds/rescue-super-recover.c +3 -4
@@ -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); }
cmds/rescue.c +4 -3
@@ -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");
cmds/rescue.h +1 -1
@@ -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
Signature · 1 line
1.8.3.1
PATCH v3 10/16 btrfs-progs: rescue super-recover: use global verbose option
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
---
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(-)
Documentation/btrfs-rescue.asciidoc +1 -1
@@ -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
cmds/rescue-super-recover.c +3 -4
@@ -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); }
cmds/rescue.c +6 -4
@@ -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");
cmds/rescue.h +1 -1
@@ -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
Signature · 1 line
2.25.1
PATCH v2 11/16 btrfs-progs: restore: use global verbose option
In reply to Anand JainTranspire global --verbose option down to the btrfs restore sub-command.
---
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(-)
cmds/restore.c +23 -30
@@ -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 ;
Signature · 1 line
1.8.3.1
PATCH v3 11/16 btrfs-progs: restore: use global verbose option
Transpire global --verbose option down to the btrfs restore sub-command.
---
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(-)
Documentation/btrfs-restore.asciidoc +2 -1
@@ -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
cmds/restore.c +27 -33
147 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 12/16 btrfs-progs: inspect-internal inode-resolve: use global verbose
In reply to Anand JainTranspire global --verbose option down to the
btrfs inspect-internal inode-resolve sub-command.
---
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(-)
cmds/inspect.c +10 -10
@@ -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;
Signature · 1 line
1.8.3.1
PATCH v3 12/16 btrfs-progs: inspect-internal inode-resolve: use global verbose
Transpire global --verbose option down to the btrfs inspect-internal inode-resolve sub-command.
---
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(-)
Documentation/btrfs-inspect-internal.asciidoc +1 -0
@@ -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)
cmds/inspect.c +11 -11
@@ -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;
Signature · 1 line
2.25.1
PATCH v2 13/16 btrfs-progs: inspect-internal logical-resolve: use global verbose option
In reply to Anand JainTranspire 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.
---
v2: Use new helper function bconf_be_verbose()
cmds/inspect.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)
cmds/inspect.c +11 -14
@@ -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 {
Signature · 1 line
1.8.3.1
PATCH v3 13/16 btrfs-progs: inspect-internal logical-resolve: use global verbose option
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.
---
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(-)
Documentation/btrfs-inspect-internal.asciidoc +1 -0
@@ -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
cmds/inspect.c +11 -14
@@ -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 {
Signature · 1 line
2.25.1
PATCH v2 14/16 btrfs-progs: refactor btrfs_scan_devices() to accept verbose argument
In reply to Anand JainFunction 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().
--- 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(-)
cmds/device.c +1 -1
@@ -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,
cmds/filesystem.c +1 -1
@@ -746,7 +746,7 @@ devs_only:else ret =1 ; }else { - ret =btrfs_scan_devices (); + ret =btrfs_scan_devices (0 ); }if (ret) {
common/device-scan.c +2 -1
@@ -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); }
common/device-scan.h +1 -1
@@ -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,
common/utils.c +1 -1
@@ -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; }
disk-io.c +1 -1
@@ -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; }
Signature · 1 line
1.8.3.1
PATCH v2 15/16 btrfs-progs: device scan: add verbose option
In reply to Anand JainEnable 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
---
v2: Use new define HELPINFO_INSERT_GLOBALS
cmds/device.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
cmds/device.c +3 -1
@@ -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,
Signature · 1 line
1.8.3.1
PATCH v2 16/16 btrfs-progs: device scan: add quiet option
In reply to Anand JainEnable the quiet option to the btrfs(8) device scan command. Does the job quietly. For example:
btrfs --quiet device scan
--- cmds/device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
cmds/device.c +2 -1
@@ -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 ();
Signature · 1 line
1.8.3.1
Gentle ping.
Regds, Anand
David,
I wonder if could this be integrated?
Thanks, Anand
Quoted 212 lines · Anand Jain
v1.1->v2:
Mainly:
. Splits defineHELPINFO_INSERT_GLOBALSfrom --format option and
. RenameHELPINFO_GLOBAL_OPTIONS_HEADERtoHELPINFO_INSERT_GLOBALS
. Create and use helperbconf_be_verbose()andbconf_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 inHELPINFO_INSERT_QUIET.
. Remove #include <stdbool.h> where its no more required.
(was needed when %bconf.verbose was declared as bool).
. Usepr_verbose(-1,..)instead of all conditionsprintf(). Usepr_verbose(1,..)instead ofpr_verbose(true,..)verbosity sample code as in v1.1
global init
-----------bconf.verbose = -1; //-1:default, 0:quiet, >1:verboseat 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 */
voidpr_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.
.. Refactoredpr_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 actionAnand Jain (16):
btrfs-progs: split global helpHELPINFO_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: refactorbtrfs_scan_devices()to accept verbose argument
btrfs-progs: device scan: add verbose option
btrfs-progs: device scan: add quiet optionbtrfs.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(-)
Quoted 1 line · Anand Jain
I wonder if could this be integrated?
Yes, when I get to it through the pile of other patches.
Quoted 5 lines · David Sterba
Quoted 1 line · Anand Jain
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
David,
A ping on this series.
Thanks, Anand
Quoted 10 lines · Anand Jain
Quoted 5 lines · David Sterba
Quoted 1 line · Anand Jain
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
Quoted 1 line · Anand Jain
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.
Quoted 4 lines
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.
Quoted 2 lines
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.
Quoted 2 lines
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
Quoted 7 lines · Anand Jain
Quoted 4 lines
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.
Quoted 7 lines
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.
PATCH v3 2/16 btrfs-progs: add global verbose and quiet options and helper functions
In reply to Anand JainAdd 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.
---
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(-)
btrfs.c +18 -2
@@ -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 = {
common/help.h +5 -0
@@ -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 ;
common/messages.c +30 -0
@@ -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); +}
common/messages.h +4 -0
@@ -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, ...);
common/utils.c +14 -0
@@ -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. */
common/utils.h +11 -0
@@ -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 );
Signature · 1 line
2.25.1
PATCH v2 16/16 btrfs-progs: device scan: add quiet option
In reply to Anand JainEnable the quiet option to the btrfs(8) device scan command. Does the job quietly. For example:
btrfs --quiet device scan
---
v2: use MUST_LOG
cmds/device.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
cmds/device.c +3 -1
@@ -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 ();
Signature · 1 line
2.25.1
PATCH v3 11/16 btrfs-progs: restore: use global verbose option
In reply to Anand JainTranspire global --verbose option down to the btrfs restore sub-command.
---
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(-)
cmds/restore.c +26 -32
@@ -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 ;
Signature · 1 line
2.25.1