@@ -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,13 @@ 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(stderr, "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,
@@ -268,7 +273,7 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
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 +400,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 +428,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 +453,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 +479,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 +504,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 +529,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 +561,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 +593,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 +619,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 +644,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 +850,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 +865,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 +895,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 +923,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 +949,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 +975,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 +987,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 +1021,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 +1040,7 @@ static int process_utimes(const char *path, struct timespec *at,
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 +1180,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,17 +1267,21 @@ 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;

switch (c) {
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)",
@@ -1359,6 +1368,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",
@@ -2506,7 +2506,12 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans,
profile = BTRFS_BLOCK_GROUP_METADATA | alloc_profile;
}

if (root->ref_cows) {
/*
* Do metadata preallocation if we're not modifying the extent tree.
* Allocating chunk while modifying extent tree could lead to transid
* mismatch, as do_chunk_alloc() could commit transaction.
*/
if (root->root_key.objectid != BTRFS_EXTENT_TREE_OBJECTID) {
if (!(profile & BTRFS_BLOCK_GROUP_METADATA)) {
ret = do_chunk_alloc(trans, info,
num_bytes,
@@ -216,11 +216,9 @@ u32 get_running_kernel_version(void)
return (u32)-1;
version |= atoi(tmp) << 8;
tmp = strtok_r(NULL, ".", &saveptr);
if (tmp) {
if (!string_is_numerical(tmp))
return (u32)-1;
/* Relaxed format accepts eg. 1.2.3+ */
if (tmp && string_is_numerical(tmp))
version |= atoi(tmp);
}

return version;
}