Commit fe5f60b9 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

btrfs: Don't miss subvol0 on matching

Subvolume 0 has own device number as well, don't miss it
when looking up for match.
Reported-by: 's avatarAndrew Vagin <avagin@parallels.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Tested-by: 's avatarAndrew Vagin <avagin@parallels.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 07e153fc
...@@ -49,6 +49,7 @@ struct btrfs_subvol_root { ...@@ -49,6 +49,7 @@ struct btrfs_subvol_root {
struct mount_info const *m; struct mount_info const *m;
u64 tree_id; u64 tree_id;
dev_t st_dev;
}; };
struct btrfs_subvol_node { struct btrfs_subvol_node {
...@@ -177,7 +178,7 @@ static struct btrfs_subvol_node *btrfs_create_node(void) ...@@ -177,7 +178,7 @@ static struct btrfs_subvol_node *btrfs_create_node(void)
return n; return n;
} }
static struct btrfs_subvol_root *btrfs_create_root(int fd, struct mount_info *m) static struct btrfs_subvol_root *btrfs_create_root(int fd, struct mount_info *m, struct stat *st)
{ {
struct btrfs_ioctl_ino_lookup_args args = { }; struct btrfs_ioctl_ino_lookup_args args = { };
struct btrfs_subvol_root *r; struct btrfs_subvol_root *r;
...@@ -195,6 +196,7 @@ static struct btrfs_subvol_root *btrfs_create_root(int fd, struct mount_info *m) ...@@ -195,6 +196,7 @@ static struct btrfs_subvol_root *btrfs_create_root(int fd, struct mount_info *m)
return NULL; return NULL;
} }
r->st_dev = st->st_dev;
r->tree_id = args.treeid; r->tree_id = args.treeid;
r->m = m; r->m = m;
return r; return r;
...@@ -405,6 +407,7 @@ static void *btrfs_parse_volume(struct mount_info *m) ...@@ -405,6 +407,7 @@ static void *btrfs_parse_volume(struct mount_info *m)
unsigned long off, i; unsigned long off, i;
int ret = -1, fd = -1; int ret = -1, fd = -1;
struct stat st;
memzero(&tree_args, sizeof(tree_args)); memzero(&tree_args, sizeof(tree_args));
...@@ -423,7 +426,12 @@ static void *btrfs_parse_volume(struct mount_info *m) ...@@ -423,7 +426,12 @@ static void *btrfs_parse_volume(struct mount_info *m)
goto err; goto err;
} }
r = btrfs_create_root(fd, m); if (stat(m->mountpoint, &st)) {
pr_perror("Can't get stat on %s", m->mountpoint);
goto err;
}
r = btrfs_create_root(fd, m, &st);
if (!r) { if (!r) {
pr_err("Can't create btrfs root for %s\n", m->mountpoint); pr_err("Can't create btrfs root for %s\n", m->mountpoint);
goto err; goto err;
...@@ -495,5 +503,12 @@ bool is_btrfs_subvol(dev_t vol_id, dev_t dev_id) ...@@ -495,5 +503,12 @@ bool is_btrfs_subvol(dev_t vol_id, dev_t dev_id)
struct btrfs_subvol_root *r; struct btrfs_subvol_root *r;
r = btrfs_vol_lookup_dev(vol_id); r = btrfs_vol_lookup_dev(vol_id);
return r ? btrfs_node_lookup_dev(r, dev_id) != NULL : false; if (r) {
if (r->st_dev == dev_id)
return true;
else
return btrfs_node_lookup_dev(r, dev_id) != NULL;
}
return false;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment