btrfs-progs: fix type mismatch in backtrace dumping functions
[platform/upstream/btrfs-progs.git] / cmds-send.c
index bbe16d8..74d0128 100644 (file)
 #include "send.h"
 #include "send-utils.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_send {
        int send_fd;
@@ -301,10 +305,10 @@ static int do_send(struct btrfs_send *send, u64 parent_root_id,
                                "Try upgrading your kernel or don't use -e.\n");
                goto out;
        }
-       if (g_verbose > 0)
+       if (g_verbose > 1)
                fprintf(stderr, "BTRFS_IOC_SEND returned %d\n", ret);
 
-       if (g_verbose > 0)
+       if (g_verbose > 1)
                fprintf(stderr, "joining genl thread\n");
 
        close(pipefd[1]);
@@ -429,9 +433,11 @@ int cmd_send(int argc, char **argv)
        while (1) {
                enum { GETOPT_VAL_SEND_NO_DATA = 256 };
                static const struct option long_options[] = {
+                       { "verbose", no_argument, NULL, 'v' },
+                       { "quiet", no_argument, NULL, 'q' },
                        { "no-data", no_argument, NULL, GETOPT_VAL_SEND_NO_DATA }
                };
-               int c = getopt_long(argc, argv, "vec:f:i:p:", long_options, NULL);
+               int c = getopt_long(argc, argv, "vqec:f:i:p:", long_options, NULL);
 
                if (c < 0)
                        break;
@@ -440,6 +446,9 @@ int cmd_send(int argc, char **argv)
                case 'v':
                        g_verbose++;
                        break;
+               case 'q':
+                       g_verbose = 0;
+                       break;
                case 'e':
                        new_end_cmd_semantic = 1;
                        break;
@@ -474,7 +483,7 @@ int cmd_send(int argc, char **argv)
 
                        ret = add_clone_source(&send, root_id);
                        if (ret < 0) {
-                               error("not enough memory");
+                               error("cannot add clone source: %s", strerror(-ret));
                                goto out;
                        }
                        subvol_uuid_search_finit(&send.sus);
@@ -579,7 +588,7 @@ int cmd_send(int argc, char **argv)
 
                ret = add_clone_source(&send, parent_root_id);
                if (ret < 0) {
-                       error("not enough memory");
+                       error("cannot add clone source: %s", strerror(-ret));
                        goto out;
                }
        }
@@ -617,13 +626,14 @@ int cmd_send(int argc, char **argv)
                        goto out;
                if (!ret) {
                        ret = -EINVAL;
-                       error("subvolum %s is not read-only", subvol);
+                       error("subvolume %s is not read-only", subvol);
                        goto out;
                }
        }
 
-       if (send_flags & BTRFS_SEND_FLAG_NO_FILE_DATA)
-               printf("Mode NO_FILE_DATA enabled\n");
+       if ((send_flags & BTRFS_SEND_FLAG_NO_FILE_DATA) && g_verbose > 1)
+               if (g_verbose > 1)
+                       fprintf(stderr, "Mode NO_FILE_DATA enabled\n");
 
        for (i = optind; i < argc; i++) {
                int is_first_subvol;
@@ -632,7 +642,8 @@ int cmd_send(int argc, char **argv)
                free(subvol);
                subvol = argv[i];
 
-               fprintf(stderr, "At subvol %s\n", subvol);
+               if (g_verbose > 0)
+                       fprintf(stderr, "At subvol %s\n", subvol);
 
                subvol = realpath(subvol, NULL);
                if (!subvol) {
@@ -673,15 +684,16 @@ int cmd_send(int argc, char **argv)
                if (ret < 0)
                        goto out;
 
-               /* done with this subvol, so add it to the clone sources */
-               ret = add_clone_source(&send, root_id);
-               if (ret < 0) {
-                       error("not enough memory");
-                       goto out;
+               if (!full_send) {
+                       /* done with this subvol, so add it to the clone sources */
+                       ret = add_clone_source(&send, root_id);
+                       if (ret < 0) {
+                               error("cannot add clone source: %s", strerror(-ret));
+                               goto out;
+                       }
                }
 
                parent_root_id = 0;
-               full_send = 0;
        }
 
        ret = 0;
@@ -712,8 +724,6 @@ const char * const cmd_send_usage[] = {
        "which case 'btrfs send' will determine a suitable parent among the",
        "clone sources itself.",
        "\n",
-       "-v               Enable verbose debug output. Each occurrence of",
-       "                 this option increases the verbose level more.",
        "-e               If sending multiple subvols at once, use the new",
        "                 format and omit the end-cmd between the subvols.",
        "-p <parent>      Send an incremental stream from <parent> to",
@@ -727,5 +737,8 @@ const char * const cmd_send_usage[] = {
        "                 does not contain any file data and thus cannot be used",
        "                 to transfer changes. This mode is faster and useful to",
        "                 show the differences in metadata.",
+       "-v|--verbose     enable verbose output to stderr, each occurrence of",
+       "                 this option increases verbosity",
+       "-q|--quiet       suppress all messages, except errors",
        NULL
 };