[RFC,10/14] btrfs-progs: migrate restore to global verbose
diff mbox series

Message ID 1571652082-25982-11-git-send-email-anand.jain@oracle.com
State New
Headers show
Series
  • btrfs-progs: global-verbose option
Related show

Commit Message

Anand Jain Oct. 21, 2019, 10:01 a.m. UTC
Command btrfs restore provides local verbose option, this patch makes it
enable-able by using the global --verbose option as well.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds/restore.c | 69 ++++++++++++++++++++++++++--------------------------------
 1 file changed, 31 insertions(+), 38 deletions(-)

Patch
diff mbox series

diff --git a/cmds/restore.c b/cmds/restore.c
index 79caf6734e76..3592faeb6bca 100644
--- a/cmds/restore.c
+++ b/cmds/restore.c
@@ -51,7 +51,7 @@  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;
+extern bool global_verbose;
 static int restore_metadata = 0;
 static int restore_symlinks = 0;
 static int ignore_errors = 0;
@@ -375,8 +375,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(global_verbose && offset, "offset is %Lu\n", offset);
 	/* we found a hole */
 	if (disk_size == 0)
 		return 0;
@@ -832,9 +831,8 @@  static int overwrite_ok(const char * path)
 		if (overwrite)
 			return 2;
 
-		if (verbose || !warn)
-			printf("Skipping existing file"
-				   " %s\n", path);
+		pr_verbose(global_verbose || !warn,
+			   "Skipping existing file %s\n", path);
 		if (!warn)
 			printf("If you wish to overwrite use -o\n");
 		warn = 1;
@@ -994,9 +992,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(global_verbose,
+		   "Reached the end of the tree looking for the directory\n");
 			ret = 0;
 			goto out;
 		}
@@ -1020,10 +1017,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(global_verbose,
+		"Reached the end of the tree searching the directory\n");
 					ret = 0;
 					goto out;
 				}
@@ -1063,8 +1058,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(global_verbose, "Restoring %s\n", path_name);
 			if (dry_run)
 				goto next;
 			fd = open(path_name, O_CREAT|O_WRONLY, 0644);
@@ -1136,8 +1130,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(global_verbose, "Restoring %s\n", path_name);
 
 			errno = 0;
 			if (dry_run)
@@ -1200,8 +1193,7 @@  next:
 		}
 	}
 
-	if (verbose)
-		printf("Done searching %s\n", in_dir);
+	pr_verbose(global_verbose, "Done searching %s\n", in_dir);
 out:
 	btrfs_release_path(&path);
 	return ret;
@@ -1392,25 +1384,26 @@  static const char * const cmd_restore_usage[] = {
 	"btrfs restore [options] <device> <path> | -l <device>",
 	"Try to restore files from a damaged filesystem (unmounted)",
 	"",
-	"-s|--snapshots       get snapshots",
-	"-x|--xattr           restore extended attributes",
-	"-m|--metadata        restore owner, mode and times",
-	"-S|--symlink         restore symbolic links",
-	"-v|--verbose         verbose",
-	"-i|--ignore-errors   ignore errors",
-	"-o|--overwrite       overwrite",
-	"-t <bytenr>          tree location",
-	"-f <bytenr>          filesystem location",
-	"-u|--super <mirror>  super mirror",
-	"-r|--root <rootid>   root objectid",
-	"-d                   find dir",
-	"-l|--list-roots      list tree roots",
-	"-D|--dry-run         dry run (only list files that would be recovered)",
+	"-s|--snapshots     get snapshots",
+	"-x|--xattr         restore extended attributes",
+	"-m|--metadata      restore owner, mode and times",
+	"-S|--symlink       restore symbolic links",
+	HELPINFO_INSERT_VERBOSE,
+	"-i|--ignore-errors ignore errors",
+	"-o|--overwrite     overwrite",
+	"-t <bytenr>        tree location",
+	"-f <bytenr>        filesystem location",
+	"-u|--super <mirror>",
+	"                   super mirror",
+	"-r|--root <rootid> root objectid",
+	"-d                 find dir",
+	"-l|--list-roots    list tree roots",
+	"-D|--dry-run       dry run (only list files that would be recovered)",
 	"--path-regex <regex>",
-	"                     restore only filenames matching regex,",
-	"                     you have to use following syntax (possibly quoted):",
-	"                     ^/(|home(|/username(|/Desktop(|/.*))))$",
-	"-c                   ignore case (--path-regex only)",
+	"                   restore only filenames matching regex,",
+	"                   you have to use following syntax (possibly quoted):",
+	"                   ^/(|home(|/username(|/Desktop(|/.*))))$",
+	"-c                 ignore case (--path-regex only)",
 	NULL
 };
 
@@ -1463,7 +1456,7 @@  static int cmd_restore(const struct cmd_struct *cmd, int argc, char **argv)
 				get_snaps = 1;
 				break;
 			case 'v':
-				verbose++;
+				global_verbose = true;
 				break;
 			case 'i':
 				ignore_errors = 1;