diff mbox series

[RFC,03/14] btrfs-progs: migrate filesystem defragment to global verbose

Message ID 1571652082-25982-4-git-send-email-anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: global-verbose option | expand

Commit Message

Anand Jain Oct. 21, 2019, 10:01 a.m. UTC
btrfs filesystem deframent already supports local sub-command
verbose option, enable the same when the global verbose option is set.
And as well make sure the same remains enabled at the local level.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds/filesystem.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index 4f22089abeaa..ee4d366fbf64 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -832,13 +832,13 @@  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",
-	"-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_VERBOSE_SHORT,
+	"-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)",
 	"",
 	"Warning: most Linux kernels will break up the ref-links of COW data",
 	"(e.g., files copied with 'cp --reflink', snapshots) which may cause",
@@ -848,7 +848,7 @@  static const char * const cmd_filesystem_defrag_usage[] = {
 };
 
 static struct btrfs_ioctl_defrag_range_args defrag_global_range;
-static int defrag_global_verbose;
+extern bool 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 +857,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(global_verbose, "%s\n", fpath);
 		fd = open(fpath, defrag_open_mode);
 		if (fd < 0) {
 			goto error;
@@ -913,7 +912,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 +929,7 @@  static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
 			flush = 1;
 			break;
 		case 'v':
-			defrag_global_verbose = 1;
+			global_verbose = true;
 			break;
 		case 's':
 			start = parse_size(optarg);
@@ -1031,8 +1029,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(global_verbose, "%s\n", argv[i]);
 			ret = ioctl(fd, BTRFS_IOC_DEFRAG_RANGE,
 					&defrag_global_range);
 			defrag_err = errno;