Transpire global --verbose option down to the btrfs receive sub-command.
Suggested-by: David Sterba <dsterba@xxxxxxxx>
Signed-off-by: Anand Jain <anand.jain@xxxxxxxxxx>
---
v4: Update help and documentation
v3: Space after HELPINFO_INSERT_VERBOSE, in the usage.
v2: Use new helper functions and defines
HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
bconf_be_verbose()
No need to init bconf.verbose in the sub command.
Move the HELPINFO_INSERT_GLOBALS, and HELPINFO_INSERT_VERBOSE, right
after the command options.
Documentation/btrfs-filesystem.asciidoc | 3 ++-
cmds/filesystem.c | 15 +++++++--------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/Documentation/btrfs-filesystem.asciidoc b/Documentation/btrfs-filesystem.asciidoc
index 151b7889d8a5..ad8717a70949 100644
--- a/Documentation/btrfs-filesystem.asciidoc
+++ b/Documentation/btrfs-filesystem.asciidoc
@@ -111,7 +111,8 @@ KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).
`Options`
+
-v::::
-be verbose, print file names as they're submitted for defragmentation
+be verbose, print file names as they're submitted for defragmentation. This
+option is merged to the global verbose option.
-c[<algo>]::::
compress file contents while defragmenting. Optional argument selects the compression
algorithm, 'zlib' (default), 'lzo' or 'zstd'. Currently it's not possible to select no
diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index 936db672e329..d4ffc000e59b 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -833,13 +833,16 @@ static const char * const cmd_filesystem_defrag_usage[] = {
"btrfs filesystem defragment [options] <file>|<dir> [<file>|<dir>...]",
"Defragment a file or a directory",
"",
- "-v be verbose",
+ "-v be verbose. This option is merged to the global",
+ " verbose option.",
"-r defragment files recursively",
"-c[zlib,lzo,zstd] compress the file while defragmenting",
"-f flush data to disk immediately after defragmenting",
"-s start defragment only from byte onward",
"-l len defragment only up to len bytes",
"-t size target extent size hint (default: 32M)",
+ HELPINFO_INSERT_GLOBALS,
+ HELPINFO_INSERT_VERBOSE,
"",
"Warning: most Linux kernels will break up the ref-links of COW data",
"(e.g., files copied with 'cp --reflink', snapshots) which may cause",
@@ -849,7 +852,6 @@ static const char * const cmd_filesystem_defrag_usage[] = {
};
static struct btrfs_ioctl_defrag_range_args defrag_global_range;
-static int defrag_global_verbose;
static int defrag_global_errors;
static int defrag_callback(const char *fpath, const struct stat *sb,
int typeflag, struct FTW *ftwbuf)
@@ -858,8 +860,7 @@ static int defrag_callback(const char *fpath, const struct stat *sb,
int fd = 0;
if ((typeflag == FTW_F) && S_ISREG(sb->st_mode)) {
- if (defrag_global_verbose)
- printf("%s\n", fpath);
+ pr_verbose(1, "%s\n", fpath);
fd = open(fpath, defrag_open_mode);
if (fd < 0) {
goto error;
@@ -914,7 +915,6 @@ static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
thresh = SZ_32M;
defrag_global_errors = 0;
- defrag_global_verbose = 0;
defrag_global_errors = 0;
optind = 0;
while(1) {
@@ -932,7 +932,7 @@ static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
flush = 1;
break;
case 'v':
- defrag_global_verbose = 1;
+ bconf_be_verbose();
break;
case 's':
start = parse_size(optarg);
@@ -1032,8 +1032,7 @@ static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
/* errors are handled in the callback */
ret = 0;
} else {
- if (defrag_global_verbose)
- printf("%s\n", argv[i]);
+ pr_verbose(1, "%s\n", argv[i]);
ret = ioctl(fd, BTRFS_IOC_DEFRAG_RANGE,
&defrag_global_range);
defrag_err = errno;
--
2.25.1