add option to supress "At subvol …" message in btrfs send
Subsystems (2)
Hello,
btrfs send puts a “At subvol …” on stderr, which is very annoying in scripts, esp. cron-jobs. Piping stderr to /dev/null does suppress this message, but also error-messages which one would probably want to see. I added an option to not change the behavior of btrfs send and possibly break existing scripts, but moving this message to verbose would be O.K. for me too.
cmds-send.c +8 -2
@@ -45,6 +45,7 @@#include "send-utils.h" static int g_verbose =0 ; +static int g_quiet =0 ;struct btrfs_send {int send_fd;
@@ -442,7 +443,7 @@static const struct option long_options[] = { {"no-data" , no_argument,NULL ,GETOPT_VAL_SEND_NO_DATA } }; -int c =getopt_long (argc, argv,"vec:f:i:p:" , long_options,NULL ); +int c =getopt_long (argc, argv,"vec:f:i:p:q" , long_options,NULL );if (c <0 )break ;
@@ -534,6 +535,9 @@error ("option -i was removed, use -c instead" ); ret =1 ; goto out; +case 'q' : + g_quiet =1 ; +break ;case GETOPT_VAL_SEND_NO_DATA : send_flags |=BTRFS_SEND_FLAG_NO_FILE_DATA ;break ;
@@ -642,7 +646,8 @@free (subvol); subvol = argv[i]; -fprintf (stderr,"At subvol %s\n" , subvol); +if (!g_quiet) +fprintf (stderr,"At subvol %s\n" , subvol); subvol =realpath (subvol,NULL );if (!subvol) {
@@ -737,5 +742,6 @@" does not contain any file data and thus cannot be used" ," to transfer changes. This mode is faster and useful to" ," show the differences in metadata." , +"-q suppress 'At subvol' message on stderr" , NULL };
Documentation/btrfs-send.asciidoc +2 -0
@@ -45,6 +45,8 @@ Send in NO_FILE_DATA mode. The output stream does not contain any file data and thus cannot be used to transfer changes. This mode is faster and useful to show the differences in metadata. +-q:: +Suppress "At subvol" message on stderr. EXIT STATUS -----------
MfG
bmg
Signature · 3 lines
„Des is völlig wurscht, was heut beschlos- | M G Berberich sen wird: I bin sowieso dagegn!“ | [email protected] (SPD-Stadtrat Kurt Schindler; Regensburg) |
Quoted 6 lines · M G Berberich
btrfs send puts a “At subvol …” on stderr, which is very annoying in scripts, esp. cron-jobs. Piping stderr to
/dev/nulldoes suppress this message, but also error-messages which one would probably want to see. I added an option to not change the behavior of btrfs send and possibly break existing scripts, but moving this message to verbose would be O.K. for me too.
We should use the current verbosity option. For compatibility reasons, I'd keep the 'At subvol' printed as default, matching verbosity level 1. All existing messages verbosity should then become 2, and the proposed quiet option 0.
PATCH 1/1 btrfs-progs: added quiet-option for scripts
From: M G Berberich <[email protected]>
-q,--quiet to prevent status-messages on stderr --verbose as alternative for -v
moved 'Mode NO_FILE_DATA enabled' message to stderr changed default for g_verbose to 1
--- cmds-send.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
cmds-send.c +18 -8
@@ -44,7 +44,9 @@#include "send.h" #include "send-utils.h" -static int g_verbose =0 ; +/* default is 1 for historical reasons +changing may break scripts */ +static int g_verbose =1 ;struct btrfs_send {int send_fd;
@@ -301,10 +303,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 >0 ) +if (g_verbose >1 )fprintf (stderr,"BTRFS_IOC_SEND returned %d\n" , ret); -if (g_verbose >0 ) +if (g_verbose >1 )fprintf (stderr,"joining genl thread\n" );close (pipefd[1 ]);
@@ -429,9 +431,11 @@ int cmd_send(int argc, char **argv)while (1 ) {enum {GETOPT_VAL_SEND_NO_DATA =256 };static const struct option long_options[] = { + {"verbose" , no_argument,NULL ,'v' }, + {"quiet" , no_argument,NULL ,'q' }, {"no-data" , no_argument,NULL ,GETOPT_VAL_SEND_NO_DATA } }; -int c =getopt_long (argc, argv,"vec:f:i:p:" , long_options,NULL ); +int c =getopt_long (argc, argv,"vqec:f:i:p:" , long_options,NULL );if (c <0 )break ;
@@ -440,6 +444,9 @@ int cmd_send(int argc, char **argv)case 'v' : g_verbose++;break ; +case 'q' : + g_verbose--; +break ;case 'e' : new_end_cmd_semantic =1 ;break ;
@@ -622,8 +629,8 @@ int cmd_send(int argc, char **argv) } } -if (send_flags &BTRFS_SEND_FLAG_NO_FILE_DATA ) -printf ("Mode NO_FILE_DATA enabled\n" ); +if ((send_flags &BTRFS_SEND_FLAG_NO_FILE_DATA ) && g_verbose >1 ) +fprintf (stderr,"Mode NO_FILE_DATA enabled\n" );for (i = optind; i < argc; i++) {int is_first_subvol;
@@ -632,7 +639,8 @@ int cmd_send(int argc, char **argv)free (subvol); subvol = argv[i]; -fprintf (stderr,"At subvol %s\n" , subvol); +if (g_verbose >0 ) +fprintf (stderr,"At subvol %s\n" , subvol); subvol =realpath (subvol,NULL );if (!subvol) {
@@ -713,8 +721,9 @@ const char * const cmd_send_usage[] = {"which case 'btrfs send' will determine a suitable parent among the" ,"clone sources itself." ,"\n" , -"-v Enable verbose debug output. Each occurrence of" , +"-v, --verbose Enable verbose debug output. Each occurrence of" ," this option increases the verbose level more." , +"-q, --quiet suppress messages to stderr." ,"-e If sending multiple subvols at once, use the new" ," format and omit the end-cmd between the subvols." , "-p <parent> Send an incremental stream from <parent> to",
@@ -728,5 +737,6 @@ const char * const cmd_send_usage[] = {" does not contain any file data and thus cannot be used" ," to transfer changes. This mode is faster and useful to" ," show the differences in metadata." , +"--help display this help and exit" , NULL };
Signature · 1 line
2.8.1
Re: [PATCH] btrfs-progs: added quiet-option for scripts
Hi,
Quoted 6 lines · On Thu, May 12, 2016 at 09:49:25PM +0200, [email protected] wrote:
From: M G Berberich <[email protected]>
-q,--quiet to prevent status-messages on stderr --verbose as alternative for -v
moved 'ModeNO_FILE_DATAenabled' message to stderr changed default forg_verboseto 1
added the signed-off-by line and did the following tweaks and applied, thanks.
cmds-send.c +10 -8
@@ -44,8 +44,10 @@#include "send.h" #include "send-utils.h" -/* default is 1 for historical reasons -changing may break scripts */ +/* +* Default is 1 for historical reasons, changing may break scripts that expect +* the 'At subvol' message. +*/ static int g_verbose =1 ;struct btrfs_send {
@@ -445,7 +447,7 @@ int cmd_send(int argc, char **argv) g_verbose++;break ;case 'q' : - g_verbose--; + g_verbose =0 ;break ;case 'e' : new_end_cmd_semantic =1 ;
@@ -630,7 +632,8 @@ int cmd_send(int argc, char **argv) }if ((send_flags &BTRFS_SEND_FLAG_NO_FILE_DATA ) && g_verbose >1 ) -fprintf (stderr,"Mode NO_FILE_DATA enabled\n" ); +if (g_verbose >1 ) +fprintf (stderr,"Mode NO_FILE_DATA enabled\n" );for (i = optind; i < argc; i++) {int is_first_subvol;
@@ -721,9 +724,6 @@ const char * const cmd_send_usage[] = {"which case 'btrfs send' will determine a suitable parent among the" ,"clone sources itself." ,"\n" , -"-v, --verbose Enable verbose debug output. Each occurrence of" , -" this option increases the verbose level more." , -"-q, --quiet suppress messages to stderr." ,"-e If sending multiple subvols at once, use the new" ," format and omit the end-cmd between the subvols." , "-p <parent> Send an incremental stream from <parent> to",
@@ -737,6 +737,8 @@ const char * const cmd_send_usage[] = {" does not contain any file data and thus cannot be used" ," to transfer changes. This mode is faster and useful to" ," show the differences in metadata." , -"--help display this help and exit" , +"-v|--verbose enable verbose output to stderr, each occurrence of" , +" this option increases verbosity" , +"-q|--quiet suppress all messages, except errors" , NULL };