All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.com
Subject: [PATCH v3 04/16] btrfs-progs: receive: use global verbose and quiet options
Date: Fri, 12 Jun 2020 19:24:44 +0800	[thread overview]
Message-ID: <20200612112444.3511-1-anand.jain@oracle.com> (raw)
In-Reply-To: <1574678357-22222-5-git-send-email-anand.jain@oracle.com>

Transpire global --verbose and --quiet options down to the btrfs receive
sub-command.

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3: Updae the help and documentation
v2: Use new helper functions and defines
    HELPINFO_INSERT_GLOBALS, BTRFS_BCONF_UNSET, BTRFS_BCONF_QUIET
    bconf_be_verbose(), bconf_be_quiet()

 Documentation/btrfs-receive.asciidoc |  6 +-
 cmds/receive.c                       | 86 ++++++++++++++++------------
 2 files changed, 52 insertions(+), 40 deletions(-)

diff --git a/Documentation/btrfs-receive.asciidoc b/Documentation/btrfs-receive.asciidoc
index a271d89b9d7d..aed08ba5e705 100644
--- a/Documentation/btrfs-receive.asciidoc
+++ b/Documentation/btrfs-receive.asciidoc
@@ -36,10 +36,12 @@ A subvolume is made read-only after the receiving process finishes successfully
 `Options`
 
 -v::
-increase verbosity about performed actions, print details about each operation
+increase verbosity about performed actions, print details about each operation.
+This option is merged to the global verbose option.
 
 -q|--quiet::
-suppress all messages except errors
+suppress all messages except errors. This option is merged to the global quiet option.
+
 
 -f <FILE>::
 read the stream from <FILE> instead of stdin,
diff --git a/cmds/receive.c b/cmds/receive.c
index 74b73f488a0d..95fc09b8ce9f 100644
--- a/cmds/receive.c
+++ b/cmds/receive.c
@@ -53,12 +53,6 @@
 #include "common/help.h"
 #include "common/path-utils.h"
 
-/*
- * Default is 1 for historical reasons, changing may break scripts that expect
- * the 'At subvol' message.
- */
-static int g_verbose = 1;
-
 struct btrfs_receive
 {
 	int mnt_fd;
@@ -116,7 +110,7 @@ static int finish_subvol(struct btrfs_receive *rctx)
 	memcpy(rs_args.uuid, rctx->cur_subvol.received_uuid, BTRFS_UUID_SIZE);
 	rs_args.stransid = rctx->cur_subvol.stransid;
 
-	if (g_verbose >= 2) {
+	if (bconf.verbose >= 2) {
 		uuid_unparse((u8*)rs_args.uuid, uuid_str);
 		fprintf(stderr, "BTRFS_IOC_SET_RECEIVED_SUBVOL uuid=%s, "
 				"stransid=%llu\n", uuid_str, rs_args.stransid);
@@ -199,13 +193,13 @@ static int process_subvol(const char *path, const u8 *uuid, u64 ctransid,
 		goto out;
 	}
 
-	if (g_verbose)
+	if (bconf.verbose > BTRFS_BCONF_QUIET)
 		fprintf(stderr, "At subvol %s\n", path);
 
 	memcpy(rctx->cur_subvol.received_uuid, uuid, BTRFS_UUID_SIZE);
 	rctx->cur_subvol.stransid = ctransid;
 
-	if (g_verbose >= 2) {
+	if (bconf.verbose >= 2) {
 		uuid_unparse((u8*)rctx->cur_subvol.received_uuid, uuid_str);
 		fprintf(stderr, "receiving subvol %s uuid=%s, stransid=%llu\n",
 				path, uuid_str,
@@ -269,13 +263,12 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
 		goto out;
 	}
 
-	if (g_verbose)
-		fprintf(stdout, "At snapshot %s\n", path);
+	pr_verbose(1, "At snapshot %s\n", path);
 
 	memcpy(rctx->cur_subvol.received_uuid, uuid, BTRFS_UUID_SIZE);
 	rctx->cur_subvol.stransid = ctransid;
 
-	if (g_verbose >= 2) {
+	if (bconf.verbose >= 2) {
 		uuid_unparse((u8*)rctx->cur_subvol.received_uuid, uuid_str);
 		fprintf(stderr, "receiving snapshot %s uuid=%s, "
 				"ctransid=%llu ", path, uuid_str,
@@ -393,7 +386,7 @@ static int process_mkfile(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mkfile %s\n", path);
 
 	ret = creat(full_path, 0600);
@@ -421,7 +414,7 @@ static int process_mkdir(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mkdir %s\n", path);
 
 	ret = mkdir(full_path, 0700);
@@ -446,7 +439,7 @@ static int process_mknod(const char *path, u64 mode, u64 dev, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mknod %s mode=%llu, dev=%llu\n",
 				path, mode, dev);
 
@@ -472,7 +465,7 @@ static int process_mkfifo(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mkfifo %s\n", path);
 
 	ret = mkfifo(full_path, 0600);
@@ -497,7 +490,7 @@ static int process_mksock(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "mksock %s\n", path);
 
 	ret = mknod(full_path, 0600 | S_IFSOCK, 0);
@@ -522,7 +515,7 @@ static int process_symlink(const char *path, const char *lnk, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "symlink %s -> %s\n", path, lnk);
 
 	ret = symlink(lnk, full_path);
@@ -554,7 +547,7 @@ static int process_rename(const char *from, const char *to, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "rename %s -> %s\n", from, to);
 
 	ret = rename(full_from, full_to);
@@ -586,7 +579,7 @@ static int process_link(const char *path, const char *lnk, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "link %s -> %s\n", path, lnk);
 
 	ret = link(full_link_path, full_path);
@@ -612,7 +605,7 @@ static int process_unlink(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "unlink %s\n", path);
 
 	ret = unlink(full_path);
@@ -637,7 +630,7 @@ static int process_rmdir(const char *path, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "rmdir %s\n", path);
 
 	ret = rmdir(full_path);
@@ -702,7 +695,7 @@ static int process_write(const char *path, const void *data, u64 offset,
 	if (ret < 0)
 		goto out;
 
-	if (g_verbose >= 2)
+	if (bconf.verbose >= 2)
 		fprintf(stderr, "write %s - offset=%llu length=%llu\n",
 			path, offset, len);
 
@@ -792,7 +785,7 @@ static int process_clone(const char *path, u64 offset, u64 len,
 		goto out;
 	}
 
-	if (g_verbose >= 2)
+	if (bconf.verbose >= 2)
 		fprintf(stderr,
 			"clone %s - source=%s source offset=%llu offset=%llu length=%llu\n",
 			path, clone_path, clone_offset, offset, len);
@@ -833,7 +826,7 @@ static int process_set_xattr(const char *path, const char *name,
 	}
 
 	if (strcmp("security.capability", name) == 0) {
-		if (g_verbose >= 4)
+		if (bconf.verbose >= 4)
 			fprintf(stderr, "set_xattr: cache capabilities\n");
 		if (rctx->cached_capabilities_len)
 			warning("capabilities set multiple times per file: %s",
@@ -848,7 +841,7 @@ static int process_set_xattr(const char *path, const char *name,
 		memcpy(rctx->cached_capabilities, data, len);
 	}
 
-	if (g_verbose >= 3) {
+	if (bconf.verbose >= 3) {
 		fprintf(stderr, "set_xattr %s - name=%s data_len=%d "
 				"data=%.*s\n", path, name, len,
 				len, (char*)data);
@@ -878,7 +871,7 @@ static int process_remove_xattr(const char *path, const char *name, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3) {
+	if (bconf.verbose >= 3) {
 		fprintf(stderr, "remove_xattr %s - name=%s\n",
 				path, name);
 	}
@@ -906,7 +899,7 @@ static int process_truncate(const char *path, u64 size, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "truncate %s size=%llu\n", path, size);
 
 	ret = truncate(full_path, size);
@@ -932,7 +925,7 @@ static int process_chmod(const char *path, u64 mode, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "chmod %s - mode=0%o\n", path, (int)mode);
 
 	ret = chmod(full_path, mode);
@@ -958,7 +951,7 @@ static int process_chown(const char *path, u64 uid, u64 gid, void *user)
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "chown %s - uid=%llu, gid=%llu\n", path,
 				uid, gid);
 
@@ -970,7 +963,7 @@ static int process_chown(const char *path, u64 uid, u64 gid, void *user)
 	}
 
 	if (rctx->cached_capabilities_len) {
-		if (g_verbose >= 3)
+		if (bconf.verbose >= 3)
 			fprintf(stderr, "chown: restore capabilities\n");
 		ret = lsetxattr(full_path, "security.capability",
 				rctx->cached_capabilities,
@@ -1004,7 +997,7 @@ static int process_utimes(const char *path, struct timespec *at,
 		goto out;
 	}
 
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "utimes %s\n", path);
 
 	tv[0] = *at;
@@ -1023,7 +1016,7 @@ out:
 static int process_update_extent(const char *path, u64 offset, u64 len,
 		void *user)
 {
-	if (g_verbose >= 3)
+	if (bconf.verbose >= 3)
 		fprintf(stderr, "update_extent %s: offset=%llu, len=%llu\n",
 				path, (unsigned long long)offset,
 				(unsigned long long)len);
@@ -1163,7 +1156,7 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
 
 	while (!end) {
 		if (rctx->cached_capabilities_len) {
-			if (g_verbose >= 4)
+			if (bconf.verbose >= 4)
 				fprintf(stderr, "clear cached capabilities\n");
 			memset(rctx->cached_capabilities, 0,
 					sizeof(rctx->cached_capabilities));
@@ -1236,8 +1229,10 @@ static const char * const cmd_receive_usage[] = {
 	"After receiving a subvolume, it is immediately set to",
 	"read-only.",
 	"",
-	"-v               increase verbosity about performed actions",
-	"-q|--quiet       suppress all messages, except errors",
+	"-v               increase verbosity about performed actions. This",
+	"                 option is merged to the global verbose option.",
+	"-q|--quiet       suppress all messages, except errors. This option",
+	"                 is merged with the global quiet option.",
 	"-f FILE          read the stream from FILE instead of stdin",
 	"-e               terminate after receiving an <end cmd> marker in the stream.",
 	"                 Without this option the receiver side terminates only in case",
@@ -1252,6 +1247,9 @@ static const char * const cmd_receive_usage[] = {
 	"                 this file system is mounted.",
 	"--dump           dump stream metadata, one line per operation,",
 	"                 does not require the MOUNT parameter",
+	HELPINFO_INSERT_GLOBALS,
+	HELPINFO_INSERT_VERBOSE,
+	HELPINFO_INSERT_QUIET,
 	NULL
 };
 
@@ -1274,6 +1272,18 @@ static int cmd_receive(const struct cmd_struct *cmd, int argc, char **argv)
 	realmnt[0] = 0;
 	fromfile[0] = 0;
 
+	/*
+	 * Init global verbose to default, if it is unset.
+	 * Default is 1 for historical reasons, changing may break scripts that
+	 * expect the 'At subvol' message.
+	 * As default is 1, which means the effective verbose for receive is 2
+	 * which global verbose is unaware. So adjust global verbose value here.
+	 */
+	if (bconf.verbose == BTRFS_BCONF_UNSET)
+		bconf.verbose = 1;
+	else if (bconf.verbose > BTRFS_BCONF_QUIET)
+		bconf.verbose++;
+
 	optind = 0;
 	while (1) {
 		int c;
@@ -1292,10 +1302,10 @@ static int cmd_receive(const struct cmd_struct *cmd, int argc, char **argv)
 
 		switch (c) {
 		case 'v':
-			g_verbose++;
+			bconf_be_verbose();
 			break;
 		case 'q':
-			g_verbose = 0;
+			bconf_be_quiet();
 			break;
 		case 'f':
 			if (arg_copy_path(fromfile, optarg, sizeof(fromfile))) {
-- 
2.25.1


  reply	other threads:[~2020-06-12 11:35 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-25 10:39 [PATCH v2 00/16] btrfs-progs: global verbose and quiet option Anand Jain
2019-11-25 10:39 ` [PATCH 01/16] btrfs-progs: split global help HELPINFO_INSERT_GLOBALS Anand Jain
2019-11-25 10:39 ` [PATCH v2 02/16] btrfs-progs: add global verbose and quiet options and helper functions Anand Jain
2020-06-12 10:56   ` [PATCH v3 " Anand Jain
2020-06-12 15:39     ` David Sterba
2020-06-12 22:48       ` Anand Jain
2020-06-23 16:44         ` David Sterba
2020-06-29 15:36     ` David Sterba
2019-11-25 10:39 ` [PATCH v2 03/16] btrfs-progs: send: use global verbose and quiet options Anand Jain
2020-06-12 10:58   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 04/16] btrfs-progs: receive: " Anand Jain
2020-06-12 11:24   ` Anand Jain [this message]
2019-11-25 10:39 ` [PATCH v2 05/16] btrfs-progs: subvolume delete: use global verbose option Anand Jain
2020-06-12 11:24   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 06/16] btrfs-progs: filesystem defragment: " Anand Jain
2020-06-08  6:31   ` Anand Jain
2020-06-11 16:56     ` [PATCH v3 " Anand Jain
2020-06-12 11:25   ` [PATCH v4 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 07/16] btrfs-progs: balance start: " Anand Jain
2020-06-12 11:25   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 08/16] btrfs-progs: balance status: " Anand Jain
2020-06-12 11:25   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 09/16] btrfs-progs: rescue chunk-recover: " Anand Jain
2020-06-12 11:25   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 10/16] btrfs-progs: rescue super-recover: " Anand Jain
2020-06-12 11:25   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 11/16] btrfs-progs: restore: " Anand Jain
2020-06-12 11:26   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 12/16] btrfs-progs: inspect-internal inode-resolve: use global verbose Anand Jain
2020-06-12 11:26   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH v2 13/16] btrfs-progs: inspect-internal logical-resolve: use global verbose option Anand Jain
2020-06-12 11:26   ` [PATCH v3 " Anand Jain
2019-11-25 10:39 ` [PATCH 14/16] btrfs-progs: refactor btrfs_scan_devices() to accept verbose argument Anand Jain
2019-11-25 10:39 ` [PATCH v2 15/16] btrfs-progs: device scan: add verbose option Anand Jain
2019-11-25 10:39 ` [PATCH 16/16] btrfs-progs: device scan: add quiet option Anand Jain
2019-12-20  5:36 ` [PATCH v2 00/16] btrfs-progs: global verbose and " Anand Jain
2020-01-14  6:14 ` Anand Jain
2020-01-14 11:40   ` David Sterba
2020-03-28  5:45     ` Anand Jain
2020-05-20 10:01       ` Anand Jain
2020-06-05  9:24         ` David Sterba
2020-06-05 10:12           ` Anand Jain
2020-06-10 10:17             ` David Sterba
2020-06-11 18:13           ` Anand Jain
2020-06-11 16:36 ` [PATCH v3 02/16] btrfs-progs: add global verbose and quiet options and helper functions Anand Jain
2020-06-11 16:39 ` [PATCH v3 11/16] btrfs-progs: restore: use global verbose option Anand Jain
2020-06-11 16:41 ` [PATCH v2 16/16] btrfs-progs: device scan: add quiet option Anand Jain

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=20200612112444.3511-1-anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=dsterba@suse.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.