Btrfs-progs: fix btrfs-convert rollback to check ROOT_BACKREF
authorLiu Bo <bo.li.liu@oracle.com>
Sun, 18 Oct 2015 05:44:41 +0000 (13:44 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 2 Nov 2015 08:35:06 +0000 (09:35 +0100)
Btrfs has changed to delete subvolume/snapshot asynchronously, which
means that after umount itself, if we've already deleted 'ext2_saved',
rollback can still be completed.

So this adds a check for ROOT_BACKREF before checking ROOT_ITEM since
ROOT_BACKREF is immediately not in the btree after
ioctl(BTRFS_IOC_SNAP_DESTROY) returns.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ updated error messages ]
Signed-off-by: David Sterba <dsterba@suse.com>
btrfs-convert.c

index 39eaa37..5b9171e 100644 (file)
@@ -2597,6 +2597,23 @@ static int do_rollback(const char *devname)
        btrfs_init_path(&path);
 
        key.objectid = CONV_IMAGE_SUBVOL_OBJECTID;
+       key.type = BTRFS_ROOT_BACKREF_KEY;
+       key.offset = BTRFS_FS_TREE_OBJECTID;
+       ret = btrfs_search_slot(NULL, root->fs_info->tree_root, &key, &path, 0,
+                               0);
+       btrfs_release_path(&path);
+       if (ret > 0) {
+               fprintf(stderr,
+               "ERROR: unable to convert ext2 image subvolume, is it deleted?\n");
+               goto fail;
+       } else if (ret < 0) {
+               fprintf(stderr,
+                       "ERROR: unable to open ext2_subvol, id=%llu: %s\n",
+                       (unsigned long long)key.objectid, strerror(-ret));
+               goto fail;
+       }
+
+       key.objectid = CONV_IMAGE_SUBVOL_OBJECTID;
        key.type = BTRFS_ROOT_ITEM_KEY;
        key.offset = (u64)-1;
        image_root = btrfs_read_fs_root(root->fs_info, &key);