Blame SOURCES/0195-libmount-fix-is-mounted-check-for-btrfs.patch

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