dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
6b9308
From d2e24bb1b485949af2fdd07026380053200a0300 Mon Sep 17 00:00:00 2001
6b9308
From: Karel Zak <kzak@redhat.com>
6b9308
Date: Wed, 2 Dec 2015 13:38:51 +0100
6b9308
Subject: [PATCH 195/197] libmount: fix is-mounted check for btrfs
6b9308
6b9308
fstab:
6b9308
  /dev/sdc        /mnt/test       btrfs   subvol=/anydir
6b9308
  /mnt/test       /mnt/test2      auto    bind
6b9308
6b9308
and "mount -a" does not detect that /mnt/test2 is already mounted.
6b9308
6b9308
Reported-by: Stanislav Brabec <sbrabec@suse.cz>
6b9308
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1816183
6b9308
Upstream: http://github.com/karelzak/util-linux/commit/352740e88e2c9cb180fe845ce210b1c7b5ad88c7
6b9308
Signed-off-by: Karel Zak <kzak@redhat.com>
6b9308
---
6b9308
 libmount/src/tab.c | 38 ++++++++++++++++++++++++++------------
6b9308
 1 file changed, 26 insertions(+), 12 deletions(-)
6b9308
6b9308
diff --git a/libmount/src/tab.c b/libmount/src/tab.c
6b9308
index 3ee9c0042..575b33d8c 100644
6b9308
--- a/libmount/src/tab.c
6b9308
+++ b/libmount/src/tab.c
6b9308
@@ -981,21 +981,33 @@ struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb,
6b9308
 			goto dflt;
6b9308
 		}
6b9308
 
6b9308
-		/* on btrfs the subvolume is used as fs-root in
6b9308
-		 * /proc/self/mountinfo, so we have to get the original subvolume
6b9308
-		 * name from src_fs and prepend the subvolume name to the
6b9308
-		 * fs-root path
6b9308
+		/* It's possible that fstab_fs source is subdirectory on btrfs
6b9308
+		 * subvolume or anothe bind mount. For example:
6b9308
+		 *
6b9308
+		 * /dev/sdc        /mnt/test       btrfs   subvol=/anydir
6b9308
+		 * /mnt/test/foo   /mnt/test2      auto    bind
6b9308
+		 *
6b9308
+		 * in this case, the root for /mnt/test2 will be /anydir/foo on
6b9308
+		 * /dev/sdc. It means we have to compose the final root from
6b9308
+		 * root and src_root.
6b9308
 		 */
6b9308
 		src_root = mnt_fs_get_root(src_fs);
6b9308
+
6b9308
+		DBG(FS, mnt_debug("source root: %s, source FS root: %s", root, src_root));
6b9308
+
6b9308
 		if (src_root && !startswith(root, src_root)) {
6b9308
-			size_t sz = strlen(root) + strlen(src_root) + 1;
6b9308
-			char *tmp = malloc(sz);
6b9308
-
6b9308
-			if (!tmp)
6b9308
-				goto err;
6b9308
-			snprintf(tmp, sz, "%s%s", src_root, root);
6b9308
-			free(root);
6b9308
-			root = tmp;
6b9308
+			if (strcmp(root, "/") == 0) {
6b9308
+				free(root);
6b9308
+				root = strdup(src_root);
6b9308
+				if (!root)
6b9308
+					goto err;
6b9308
+			} else {
6b9308
+				char *tmp;
6b9308
+				if (asprintf(&tmp, "%s%s", src_root, root) < 0)
6b9308
+					goto err;
6b9308
+				free(root);
6b9308
+				root = tmp;
6b9308
+			}
6b9308
 		}
6b9308
 	}
6b9308
 
6b9308
@@ -1138,6 +1150,8 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs)
6b9308
 	}
6b9308
 	mnt_reset_iter(&itr, MNT_ITER_FORWARD);
6b9308
 
6b9308
+	DBG(FS, mnt_debug_h(fstab_fs, "is mounted: src=%s, tgt=%s, root=%s", src, tgt, root));
6b9308
+
6b9308
 	while (mnt_table_next_fs(tb, &itr, &fs) == 0) {
6b9308
 
6b9308
 		if (!mnt_fs_streq_srcpath(fs, src)) {
6b9308
-- 
6b9308
2.25.2
6b9308