btrfs-progs: enclose uuid tree compat code with ifdefs
[platform/upstream/btrfs-progs.git] / cmds-receive.c
index 7abce76..cce37a7 100644 (file)
@@ -78,7 +78,7 @@ static int finish_subvol(struct btrfs_receive *r)
        int ret;
        int subvol_fd = -1;
        struct btrfs_ioctl_received_subvol_args rs_args;
-       char uuid_str[128];
+       char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
        u64 flags;
 
        if (r->cur_subvol == NULL)
@@ -149,7 +149,7 @@ static int process_subvol(const char *path, const u8 *uuid, u64 ctransid,
        int ret;
        struct btrfs_receive *r = user;
        struct btrfs_ioctl_vol_args args_v1;
-       char uuid_str[128];
+       char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
 
        ret = finish_subvol(r);
        if (ret < 0)
@@ -196,7 +196,7 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
 {
        int ret;
        struct btrfs_receive *r = user;
-       char uuid_str[128];
+       char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
        struct btrfs_ioctl_vol_args_v2 args_v2;
        struct subvol_info *parent_subvol = NULL;
 
@@ -234,6 +234,10 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
        parent_subvol = subvol_uuid_search(&r->sus, 0, parent_uuid,
                        parent_ctransid, NULL, subvol_search_by_received_uuid);
        if (!parent_subvol) {
+               parent_subvol = subvol_uuid_search(&r->sus, 0, parent_uuid,
+                               parent_ctransid, NULL, subvol_search_by_uuid);
+       }
+       if (!parent_subvol) {
                ret = -ENOENT;
                fprintf(stderr, "ERROR: could not find parent subvolume\n");
                goto out;
@@ -253,8 +257,15 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
                        O_RDONLY | O_NOATIME);
        if (args_v2.fd < 0) {
                ret = -errno;
-               fprintf(stderr, "ERROR: open %s failed. %s\n",
-                               parent_subvol->path, strerror(-ret));
+               if (errno != ENOENT)
+                       fprintf(stderr, "ERROR: open %s failed. %s\n",
+                                       parent_subvol->path, strerror(-ret));
+               else
+                       fprintf(stderr,
+                               "It seems that you have changed your default "
+                               "subvolume or you specify other subvolume to\n"
+                               "mount btrfs, try to remount this btrfs filesystem "
+                               "with fs tree, and run btrfs receive again!\n");
                goto out;
        }
 
@@ -787,7 +798,7 @@ out:
 }
 
 
-struct btrfs_send_ops send_ops = {
+static struct btrfs_send_ops send_ops = {
        .subvol = process_subvol,
        .snapshot = process_snapshot,
        .mkfile = process_mkfile,
@@ -810,7 +821,7 @@ struct btrfs_send_ops send_ops = {
        .utimes = process_utimes,
 };
 
-int do_receive(struct btrfs_receive *r, const char *tomnt, int r_fd)
+static int do_receive(struct btrfs_receive *r, const char *tomnt, int r_fd)
 {
        int ret;
        char *dest_dir_full_path;
@@ -951,13 +962,13 @@ int cmd_receive(int argc, char **argv)
                receive_fd = open(fromfile, O_RDONLY | O_NOATIME);
                if (receive_fd < 0) {
                        fprintf(stderr, "ERROR: failed to open %s\n", fromfile);
-                       return -errno;
+                       return 1;
                }
        }
 
        ret = do_receive(&r, tomnt, receive_fd);
 
-       return ret;
+       return !!ret;
 }
 
 const char * const cmd_receive_usage[] = {