All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [RFC PATCH 10/14] btrfs-progs: migrate restore to global verbose
Date: Mon, 21 Oct 2019 18:01:18 +0800	[thread overview]
Message-ID: <1571652082-25982-11-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1571652082-25982-1-git-send-email-anand.jain@oracle.com>

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(-)

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;
-- 
1.8.3.1


  parent reply	other threads:[~2019-10-21 10:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-21 10:01 [RFC PATCH 00/14] btrfs-progs: global-verbose option Anand Jain
2019-10-21 10:01 ` [RFC PATCH 01/14] btrfs-progs: add global verbose helper functions Anand Jain
2019-10-21 10:01 ` [RFC PATCH 02/14] btrfs-progs: migrate subvolume delete to global verbose Anand Jain
2019-10-21 10:01 ` [RFC PATCH 03/14] btrfs-progs: migrate filesystem defragment " Anand Jain
2019-10-21 10:01 ` [RFC PATCH 04/14] btrfs-progs: migrate btrfs balance start " Anand Jain
2019-10-21 10:01 ` [RFC PATCH 05/14] btrfs-progs: migrate balance status " Anand Jain
2019-10-21 10:01 ` [RFC PATCH 06/14] btrfs-progs: fix help, show long option in balance start and status Anand Jain
2019-10-21 10:01 ` [RFC PATCH 07/14] btrfs-progs: migrate rescue chunk-recover to global verbose Anand Jain
2019-10-21 10:01 ` [RFC PATCH 08/14] btrfs-progs: migrate rescue super-recover " Anand Jain
2019-10-21 10:01 ` [RFC PATCH 09/14] btrfs-progs: restore: delete unreachable code Anand Jain
2019-10-21 10:01 ` Anand Jain [this message]
2019-10-21 10:01 ` [RFC PATCH 11/14] btrfs-progs: migrate inspect-internal inode-resolve to global verbose Anand Jain
2019-10-21 10:01 ` [RFC PATCH 12/14] btrfs-progs: migrate inspect-internal logical-resolve " Anand Jain
2019-10-21 10:01 ` [RFC PATCH 13/14] btrfs-progs: refactor btrfs_scan_devices() to accept verbose argument Anand Jain
2019-10-21 10:01 ` [RFC PATCH 14/14] btrfs-progs: enable verbose for btrfs device scan Anand Jain
2019-10-21 16:12 ` [RFC PATCH 00/14] btrfs-progs: global-verbose option David Sterba
2019-10-22  1:54   ` Anand Jain
2019-10-22 11:45     ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1571652082-25982-11-git-send-email-anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.