Commit 5372e391 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

mount: btrfs -- Introduce phys_stat_resolve_dev helper (v2)

This routine is aimed to find a mount point on which
the path passed as argument is laying on. We walk over
all mount points and see which one is matching.

Once found (in worst case it will be a root mount point
so function is never failing) we're checking if this is
btrfs and then return subvolume0 device id.

See commit 921cf873
for details what the hell we're doing here.

v2: rewrite mount_resolve_path w/o recursion
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarAndrew Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent cf1ce5f8
......@@ -22,6 +22,7 @@ extern struct mount_info *lookup_mnt_sdev(unsigned int s_dev);
extern struct ns_desc mnt_ns_desc;
extern dev_t phys_stat_resolve_dev(dev_t st_dev, const char *path);
extern bool phys_stat_dev_match(dev_t st_dev, dev_t phys_dev);
#endif /* __CR_MOUNT_H__ */
......@@ -121,6 +121,44 @@ struct mount_info *lookup_mnt_sdev(unsigned int s_dev)
return NULL;
}
static struct mount_info *mount_resolve_path(const char *path)
{
size_t pathlen = strlen(path);
struct mount_info *m = mntinfo_tree, *c;
while (1) {
list_for_each_entry(c, &m->children, siblings) {
size_t n;
n = strlen(c->mountpoint);
if (n > pathlen)
continue;
if (strncmp(c->mountpoint, path, min(n, pathlen)))
continue;
m = c;
break;
}
if (&c->siblings == &m->children)
break;
}
pr_debug("Path `%s' resolved to `%s' mountpoint\n", path, m->mountpoint);
return m;
}
dev_t phys_stat_resolve_dev(dev_t st_dev, const char *path)
{
struct mount_info *m = mount_resolve_path(path);
/*
* BTRFS returns subvolume dev-id instead of
* superblock dev-id, in such case return device
* obtained from mountinfo (ie subvolume0).
*/
return strcmp(m->fstype->name, "btrfs") ? st_dev : m->s_dev;
}
bool phys_stat_dev_match(dev_t st_dev, dev_t phys_dev)
{
if (st_dev == phys_dev)
......
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