* [RFC PATCH] btrfs-progs: Quiet mode for btrfs-receive
@ 2019-02-20 9:16 Steven Davies
2019-03-05 12:41 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Steven Davies @ 2019-02-20 9:16 UTC (permalink / raw)
To: linux-btrfs
Provide an option in `btrfs receive` to suppress the informational
messages when writing files.
Signed-off-by: Steven Davies <btrfs@steev.me.uk>
---
cmds-receive.c | 67 ++++++++++++++++++++++++++++++--------------------
1 file changed, 40 insertions(+), 27 deletions(-)
diff --git a/cmds-receive.c b/cmds-receive.c
index 3888149a..96411bac 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -52,7 +52,11 @@
#include "send-dump.h"
#include "help.h"
-static int g_verbose = 0;
+/*
+ * Default is 1 for historical reasons, changing may break scripts that
expect
+ * the 'At subvol' message.
+ */
+static int g_verbose = 1;
struct btrfs_receive
{
@@ -111,7 +115,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 >= 1) {
+ if (g_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);
@@ -194,12 +198,14 @@ static int process_subvol(const char *path, const
u8 *uuid, u64 ctransid,
goto out;
}
- fprintf(stderr, "At subvol %s\n", path);
+ if (g_verbose) {
+ fprintf(stdout, "At subvol %s\n", path);
+ }
memcpy(rctx->cur_subvol.received_uuid, uuid, BTRFS_UUID_SIZE);
rctx->cur_subvol.stransid = ctransid;
- if (g_verbose) {
+ if (g_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,
@@ -263,12 +269,14 @@ static int process_snapshot(const char *path,
const u8 *uuid, u64 ctransid,
goto out;
}
- fprintf(stdout, "At snapshot %s\n", path);
+ if (g_verbose) {
+ fprintf(stderr, "At snapshot %s\n", path);
+ }
memcpy(rctx->cur_subvol.received_uuid, uuid, BTRFS_UUID_SIZE);
rctx->cur_subvol.stransid = ctransid;
- if (g_verbose) {
+ if (g_verbose >= 2) {
uuid_unparse((u8*)rctx->cur_subvol.received_uuid,
uuid_str);
fprintf(stderr, "receiving snapshot %s uuid=%s, "
"ctransid=%llu ", path, uuid_str,
@@ -395,7 +403,7 @@ static int process_mkfile(const char *path, void
*user)
goto out;
}
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "mkfile %s\n", path);
ret = creat(full_path, 0600);
@@ -423,7 +431,7 @@ static int process_mkdir(const char *path, void
*user)
goto out;
}
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "mkdir %s\n", path);
ret = mkdir(full_path, 0700);
@@ -448,7 +456,7 @@ static int process_mknod(const char *path, u64 mode,
u64 dev, void *user)
goto out;
}
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "mknod %s mode=%llu, dev=%llu\n",
path, mode, dev);
@@ -474,7 +482,7 @@ static int process_mkfifo(const char *path, void
*user)
goto out;
}
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "mkfifo %s\n", path);
ret = mkfifo(full_path, 0600);
@@ -499,7 +507,7 @@ static int process_mksock(const char *path, void
*user)
goto out;
}
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "mksock %s\n", path);
ret = mknod(full_path, 0600 | S_IFSOCK, 0);
@@ -524,7 +532,7 @@ static int process_symlink(const char *path, const
char *lnk, void *user)
goto out;
}
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "symlink %s -> %s\n", path, lnk);
ret = symlink(lnk, full_path);
@@ -556,7 +564,7 @@ static int process_rename(const char *from, const
char *to, void *user)
goto out;
}
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "rename %s -> %s\n", from, to);
ret = rename(full_from, full_to);
@@ -588,7 +596,7 @@ static int process_link(const char *path, const char
*lnk, void *user)
goto out;
}
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "link %s -> %s\n", path, lnk);
ret = link(full_link_path, full_path);
@@ -614,7 +622,7 @@ static int process_unlink(const char *path, void
*user)
goto out;
}
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "unlink %s\n", path);
ret = unlink(full_path);
@@ -639,7 +647,7 @@ static int process_rmdir(const char *path, void
*user)
goto out;
}
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "rmdir %s\n", path);
ret = rmdir(full_path);
@@ -845,7 +853,7 @@ static int process_set_xattr(const char *path, const
char *name,
}
if (strcmp("security.capability", name) == 0) {
- if (g_verbose >= 3)
+ if (g_verbose >= 4)
fprintf(stderr, "set_xattr: cache
capabilities\n");
if (rctx->cached_capabilities_len)
warning("capabilities set multiple times per
file: %s",
@@ -860,7 +868,7 @@ static int process_set_xattr(const char *path, const
char *name,
memcpy(rctx->cached_capabilities, data, len);
}
- if (g_verbose >= 2) {
+ if (g_verbose >= 3) {
fprintf(stderr, "set_xattr %s - name=%s data_len=%d "
"data=%.*s\n", path, name, len,
len, (char*)data);
@@ -890,7 +898,7 @@ static int process_remove_xattr(const char *path,
const char *name, void *user)
goto out;
}
- if (g_verbose >= 2) {
+ if (g_verbose >= 3) {
fprintf(stderr, "remove_xattr %s - name=%s\n",
path, name);
}
@@ -918,7 +926,7 @@ static int process_truncate(const char *path, u64
size, void *user)
goto out;
}
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "truncate %s size=%llu\n", path, size);
ret = truncate(full_path, size);
@@ -944,7 +952,7 @@ static int process_chmod(const char *path, u64 mode,
void *user)
goto out;
}
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "chmod %s - mode=0%o\n", path,
(int)mode);
ret = chmod(full_path, mode);
@@ -970,7 +978,7 @@ static int process_chown(const char *path, u64 uid,
u64 gid, void *user)
goto out;
}
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "chown %s - uid=%llu, gid=%llu\n", path,
uid, gid);
@@ -982,7 +990,7 @@ static int process_chown(const char *path, u64 uid,
u64 gid, void *user)
}
if (rctx->cached_capabilities_len) {
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "chown: restore
capabilities\n");
ret = lsetxattr(full_path, "security.capability",
rctx->cached_capabilities,
@@ -1016,7 +1024,7 @@ static int process_utimes(const char *path, struct
timespec *at,
goto out;
}
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "utimes %s\n", path);
tv[0] = *at;
@@ -1035,7 +1043,7 @@ out:
static int process_update_extent(const char *path, u64 offset, u64 len,
void *user)
{
- if (g_verbose >= 2)
+ if (g_verbose >= 3)
fprintf(stderr, "update_extent %s: offset=%llu,
len=%llu\n",
path, (unsigned long long)offset,
(unsigned long long)len);
@@ -1175,7 +1183,7 @@ static int do_receive(struct btrfs_receive *rctx,
const char *tomnt,
while (!end) {
if (rctx->cached_capabilities_len) {
- if (g_verbose >= 3)
+ if (g_verbose >= 4)
fprintf(stderr, "clear cached
capabilities\n");
memset(rctx->cached_capabilities, 0,
sizeof(rctx->cached_capabilities));
@@ -1262,10 +1270,11 @@ int cmd_receive(int argc, char **argv)
{ "max-errors", required_argument, NULL, 'E' },
{ "chroot", no_argument, NULL, 'C' },
{ "dump", no_argument, NULL, GETOPT_VAL_DUMP },
+ { "quiet", no_argument, NULL, 'q' },
{ NULL, 0, NULL, 0 }
};
- c = getopt_long(argc, argv, "Cevf:m:E:", long_opts,
NULL);
+ c = getopt_long(argc, argv, "Cevqf:m:E:", long_opts,
NULL);
if (c < 0)
break;
@@ -1273,6 +1282,9 @@ int cmd_receive(int argc, char **argv)
case 'v':
g_verbose++;
break;
+ case 'q':
+ g_verbose = 0;
+ break;
case 'f':
if (arg_copy_path(fromfile, optarg,
sizeof(fromfile))) {
error("input file path too long (%zu)",
@@ -1361,6 +1373,7 @@ const char * const cmd_receive_usage[] = {
"read-only.",
"",
"-v increase verbosity about performed actions",
+ "-q|--quiet suppress all messages, except errors",
"-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",
--
2.19.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RFC PATCH] btrfs-progs: Quiet mode for btrfs-receive
2019-02-20 9:16 [RFC PATCH] btrfs-progs: Quiet mode for btrfs-receive Steven Davies
@ 2019-03-05 12:41 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2019-03-05 12:41 UTC (permalink / raw)
To: Steven Davies; +Cc: linux-btrfs
On Wed, Feb 20, 2019 at 09:16:04AM +0000, Steven Davies wrote:
> Provide an option in `btrfs receive` to suppress the informational
> messages when writing files.
Thank, looks ok to me, the 'receive' command already has the verbosity
option so it makes sense to have both.
> Signed-off-by: Steven Davies <btrfs@steev.me.uk>
> ---
> cmds-receive.c | 67 ++++++++++++++++++++++++++++++--------------------
> 1 file changed, 40 insertions(+), 27 deletions(-)
>
> diff --git a/cmds-receive.c b/cmds-receive.c
> index 3888149a..96411bac 100644
> --- a/cmds-receive.c
> +++ b/cmds-receive.c
> @@ -52,7 +52,11 @@
> #include "send-dump.h"
> #include "help.h"
>
> -static int g_verbose = 0;
> +/*
> + * Default is 1 for historical reasons, changing may break scripts that
> expect
> + * the 'At subvol' message.
> + */
> +static int g_verbose = 1;
>
> struct btrfs_receive
> {
> @@ -194,12 +198,14 @@ static int process_subvol(const char *path, const
> u8 *uuid, u64 ctransid,
> goto out;
> }
>
> - fprintf(stderr, "At subvol %s\n", path);
> + if (g_verbose) {
> + fprintf(stdout, "At subvol %s\n", path);
> + }
This changes stderr to stdout.
>
> memcpy(rctx->cur_subvol.received_uuid, uuid, BTRFS_UUID_SIZE);
> rctx->cur_subvol.stransid = ctransid;
>
> - if (g_verbose) {
> + if (g_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,
> @@ -263,12 +269,14 @@ static int process_snapshot(const char *path,
> const u8 *uuid, u64 ctransid,
> goto out;
> }
>
> - fprintf(stdout, "At snapshot %s\n", path);
> + if (g_verbose) {
> + fprintf(stderr, "At snapshot %s\n", path);
And this stdout -> stderr.
That's inconsistent in the original code too, that may need some care to
fix. The stderr is used for all the verbosity levels and it's been like
that since the beginning. I doubt that it has a good reason and that
everybody does 'btrfs receive 2>&1' anyway, but we can never be sure
with that.
So for sake of backward compatibility I'll fix it to keep using the same
output streams and add to devel. Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-03-05 12:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-20 9:16 [RFC PATCH] btrfs-progs: Quiet mode for btrfs-receive Steven Davies
2019-03-05 12:41 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).