summaryrefslogtreecommitdiffstats
path: root/libmount/src/tab.c
diff options
context:
space:
mode:
authorKarel Zak2015-12-02 13:38:51 +0100
committerKarel Zak2015-12-02 13:38:51 +0100
commit352740e88e2c9cb180fe845ce210b1c7b5ad88c7 (patch)
treed93fd598c125440799c62a57143ef5ad6737e422 /libmount/src/tab.c
parentlscpu: Print physical cpu information (diff)
downloadkernel-qcow2-util-linux-352740e88e2c9cb180fe845ce210b1c7b5ad88c7.tar.gz
kernel-qcow2-util-linux-352740e88e2c9cb180fe845ce210b1c7b5ad88c7.tar.xz
kernel-qcow2-util-linux-352740e88e2c9cb180fe845ce210b1c7b5ad88c7.zip
libmount: fix is-mounted check for btrfs
fstab: /dev/sdc /mnt/test btrfs subvol=/anydir /mnt/test /mnt/test2 auto bind and "mount -a" does not detect that /mnt/test2 is already mounted. Reported-by: Stanislav Brabec <sbrabec@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/tab.c')
-rw-r--r--libmount/src/tab.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/libmount/src/tab.c b/libmount/src/tab.c
index 0df8d496d..951fe8c40 100644
--- a/libmount/src/tab.c
+++ b/libmount/src/tab.c
@@ -1240,21 +1240,33 @@ struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb,
goto dflt;
}
- /* on btrfs the subvolume is used as fs-root in
- * /proc/self/mountinfo, so we have to get the original subvolume
- * name from src_fs and prepend the subvolume name to the
- * fs-root path
+ /* It's possible that fstab_fs source is subdirectory on btrfs
+ * subvolume or anothe bind mount. For example:
+ *
+ * /dev/sdc /mnt/test btrfs subvol=/anydir
+ * /mnt/test/foo /mnt/test2 auto bind
+ *
+ * in this case, the root for /mnt/test2 will be /anydir/foo on
+ * /dev/sdc. It means we have to compose the final root from
+ * root and src_root.
*/
src_root = mnt_fs_get_root(src_fs);
+
+ DBG(FS, ul_debugobj(fs, "source root: %s, source FS root: %s", root, src_root));
+
if (src_root && !startswith(root, src_root)) {
- size_t sz = strlen(root) + strlen(src_root) + 1;
- char *tmp = malloc(sz);
-
- if (!tmp)
- goto err;
- snprintf(tmp, sz, "%s%s", src_root, root);
- free(root);
- root = tmp;
+ if (strcmp(root, "/") == 0) {
+ free(root);
+ root = strdup(src_root);
+ if (!root)
+ goto err;
+ } else {
+ char *tmp;
+ if (asprintf(&tmp, "%s%s", src_root, root) < 0)
+ goto err;
+ free(root);
+ root = tmp;
+ }
}
}
@@ -1372,6 +1384,8 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs)
}
mnt_reset_iter(&itr, MNT_ITER_FORWARD);
+ DBG(FS, ul_debugobj(fstab_fs, "is mounted: src=%s, tgt=%s, root=%s", src, tgt, root));
+
while (mnt_table_next_fs(tb, &itr, &fs) == 0) {
int eq = mnt_fs_streq_srcpath(fs, src);