Blame SOURCES/0072-libmount-cleanup-fs-root-detection-code.patch

b394b9
From bb3483bf21b9cbe462caaa74fbc03d2eb7845d74 Mon Sep 17 00:00:00 2001
b394b9
From: Karel Zak <kzak@redhat.com>
b394b9
Date: Tue, 10 Mar 2015 13:35:56 +0100
b394b9
Subject: [PATCH 72/84] libmount: cleanup fs root detection code
b394b9
b394b9
Upstream: http://github.com/karelzak/util-linux/commit/cc06a01ec551ed2bcd397a5097165b4434179b34
b394b9
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=587393
b394b9
Signed-off-by: Karel Zak <kzak@redhat.com>
b394b9
---
b394b9
 libmount/src/tab.c                            | 32 ++++++++++++++++++++-----
b394b9
 libmount/src/utils.c                          | 34 ---------------------------
b394b9
 tests/expected/libmount/utils-fs-root         |  1 -
b394b9
 tests/expected/libmount/utils-fs-root-subdir  |  1 -
b394b9
 tests/expected/libmount/utils-fs-root-subdir2 |  1 -
b394b9
 tests/ts/libmount/utils                       | 12 ----------
b394b9
 6 files changed, 26 insertions(+), 55 deletions(-)
b394b9
 delete mode 100644 tests/expected/libmount/utils-fs-root
b394b9
 delete mode 100644 tests/expected/libmount/utils-fs-root-subdir
b394b9
 delete mode 100644 tests/expected/libmount/utils-fs-root-subdir2
b394b9
b394b9
diff --git a/libmount/src/tab.c b/libmount/src/tab.c
b394b9
index 1ba1eec..10ee7ce 100644
b394b9
--- a/libmount/src/tab.c
b394b9
+++ b/libmount/src/tab.c
b394b9
@@ -46,6 +46,8 @@
b394b9
 #include "mountP.h"
b394b9
 #include "strutils.h"
b394b9
 #include "loopdev.h"
b394b9
+#include "fileutils.h"
b394b9
+#include "canonicalize.h"
b394b9
 
b394b9
 static int is_mountinfo(struct libmnt_table *tb);
b394b9
 
b394b9
@@ -900,6 +902,20 @@ struct libmnt_fs *mnt_table_find_devno(struct libmnt_table *tb,
b394b9
 	return NULL;
b394b9
 }
b394b9
 
b394b9
+static char *remove_mountpoint_from_path(const char *path, const char *mnt)
b394b9
+{
b394b9
+        char *res;
b394b9
+	const char *p;
b394b9
+	size_t sz;
b394b9
+
b394b9
+	sz = strlen(mnt);
b394b9
+	p = sz > 1 ? path + sz : path;
b394b9
+
b394b9
+	res = *p ? strdup(p) : strdup("/");
b394b9
+	DBG(UTILS, mnt_debug("%s fs-root is %s", path, res));
b394b9
+	return res;
b394b9
+}
b394b9
+
b394b9
 /*
b394b9
  * tb: /proc/self/mountinfo
b394b9
  * fs: filesystem
b394b9
@@ -919,7 +935,8 @@ struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb,
b394b9
 					unsigned long mountflags,
b394b9
 					char **fsroot)
b394b9
 {
b394b9
-	char *root = NULL, *mnt = NULL;
b394b9
+	char *root = NULL;
b394b9
+	const char *mnt = NULL;
b394b9
 	const char *fstype;
b394b9
 	struct libmnt_fs *src_fs = NULL;
b394b9
 
b394b9
@@ -937,10 +954,15 @@ struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb,
b394b9
 		DBG(TAB, mnt_debug("fs-root for bind"));
b394b9
 
b394b9
 		src = xsrc = mnt_resolve_spec(mnt_fs_get_source(fs), tb->cache);
b394b9
-		if (src)
b394b9
-			mnt = mnt_get_mountpoint(src);
b394b9
+		if (src) {
b394b9
+			struct libmnt_fs *fs = mnt_table_find_mountpoint(tb,
b394b9
+							src, MNT_ITER_BACKWARD);
b394b9
+			if (fs)
b394b9
+				mnt = mnt_fs_get_target(fs);
b394b9
+		}
b394b9
+
b394b9
 		if (mnt)
b394b9
-			root = mnt_get_fs_root(src, mnt);
b394b9
+			root = remove_mountpoint_from_path(src, mnt);
b394b9
 
b394b9
 		if (xsrc && !tb->cache) {
b394b9
 			free(xsrc);
b394b9
@@ -1007,11 +1029,9 @@ dflt:
b394b9
 
b394b9
 	DBG(TAB, mnt_debug("FS root result: %s", root));
b394b9
 
b394b9
-	free(mnt);
b394b9
 	return src_fs;
b394b9
 err:
b394b9
 	free(root);
b394b9
-	free(mnt);
b394b9
 	return NULL;
b394b9
 }
b394b9
 
b394b9
diff --git a/libmount/src/utils.c b/libmount/src/utils.c
b394b9
index 5783d88..2151ff9 100644
b394b9
--- a/libmount/src/utils.c
b394b9
+++ b/libmount/src/utils.c
b394b9
@@ -908,28 +908,6 @@ err:
b394b9
 	return NULL;
b394b9
 }
b394b9
 
b394b9
-char *mnt_get_fs_root(const char *path, const char *mnt)
b394b9
-{
b394b9
-	char *m = (char *) mnt, *res;
b394b9
-	const char *p;
b394b9
-	size_t sz;
b394b9
-
b394b9
-	if (!m)
b394b9
-		m = mnt_get_mountpoint(path);
b394b9
-	if (!m)
b394b9
-		return NULL;
b394b9
-
b394b9
-	sz = strlen(m);
b394b9
-	p = sz > 1 ? path + sz : path;
b394b9
-
b394b9
-	if (m != mnt)
b394b9
-		free(m);
b394b9
-
b394b9
-	res = *p ? strdup(p) : strdup("/");
b394b9
-	DBG(UTILS, mnt_debug("%s fs-root is %s", path, res));
b394b9
-	return res;
b394b9
-}
b394b9
-
b394b9
 /*
b394b9
  * Search for @name kernel command parametr.
b394b9
  *
b394b9
@@ -1085,17 +1063,6 @@ int test_mountpoint(struct libmnt_test *ts, int argc, char *argv[])
b394b9
 	return 0;
b394b9
 }
b394b9
 
b394b9
-int test_fsroot(struct libmnt_test *ts, int argc, char *argv[])
b394b9
-{
b394b9
-	char *path = canonicalize_path(argv[1]),
b394b9
-	     *mnt = path ? mnt_get_fs_root(path, NULL) : NULL;
b394b9
-
b394b9
-	printf("%s: %s\n", argv[1], mnt ? : "unknown");
b394b9
-	free(mnt);
b394b9
-	free(path);
b394b9
-	return 0;
b394b9
-}
b394b9
-
b394b9
 int test_filesystems(struct libmnt_test *ts, int argc, char *argv[])
b394b9
 {
b394b9
 	char **filesystems = NULL;
b394b9
@@ -1170,7 +1137,6 @@ int main(int argc, char *argv[])
b394b9
 	{ "--starts-with",   test_startswith,      "<string> <prefix>" },
b394b9
 	{ "--ends-with",     test_endswith,        "<string> <prefix>" },
b394b9
 	{ "--mountpoint",    test_mountpoint,      "<path>" },
b394b9
-	{ "--fs-root",       test_fsroot,          "<path>" },
b394b9
 	{ "--cd-parent",     test_chdir,           "<path>" },
b394b9
 	{ "--kernel-cmdline",test_kernel_cmdline,  "<option> | <option>=" },
b394b9
 	{ "--mkdir",         test_mkdir,           "<path>" },
b394b9
diff --git a/tests/expected/libmount/utils-fs-root b/tests/expected/libmount/utils-fs-root
b394b9
deleted file mode 100644
b394b9
index 7746b28..0000000
b394b9
--- a/tests/expected/libmount/utils-fs-root
b394b9
+++ /dev/null
b394b9
@@ -1 +0,0 @@
b394b9
-/proc: /
b394b9
diff --git a/tests/expected/libmount/utils-fs-root-subdir b/tests/expected/libmount/utils-fs-root-subdir
b394b9
deleted file mode 100644
b394b9
index 09cdb8d..0000000
b394b9
--- a/tests/expected/libmount/utils-fs-root-subdir
b394b9
+++ /dev/null
b394b9
@@ -1 +0,0 @@
b394b9
-/proc/sys/kernel: /sys/kernel
b394b9
diff --git a/tests/expected/libmount/utils-fs-root-subdir2 b/tests/expected/libmount/utils-fs-root-subdir2
b394b9
deleted file mode 100644
b394b9
index 2e8b89a..0000000
b394b9
--- a/tests/expected/libmount/utils-fs-root-subdir2
b394b9
+++ /dev/null
b394b9
@@ -1 +0,0 @@
b394b9
-/etc: /etc
b394b9
diff --git a/tests/ts/libmount/utils b/tests/ts/libmount/utils
b394b9
index 6facaad..89ecf10 100755
b394b9
--- a/tests/ts/libmount/utils
b394b9
+++ b/tests/ts/libmount/utils
b394b9
@@ -64,18 +64,6 @@ ts_init_subtest "mountpoint-root"
b394b9
 ts_valgrind $TESTPROG --mountpoint / &> $TS_OUTPUT
b394b9
 ts_finalize_subtest
b394b9
 
b394b9
-ts_init_subtest "fs-root"
b394b9
-ts_valgrind $TESTPROG --fs-root /proc &> $TS_OUTPUT
b394b9
-ts_finalize_subtest
b394b9
-
b394b9
-ts_init_subtest "fs-root-subdir"
b394b9
-ts_valgrind $TESTPROG --fs-root /proc/sys/kernel &> $TS_OUTPUT
b394b9
-ts_finalize_subtest
b394b9
-
b394b9
-ts_init_subtest "fs-root-subdir2"
b394b9
-ts_valgrind $TESTPROG --fs-root /etc &> $TS_OUTPUT
b394b9
-ts_finalize_subtest
b394b9
-
b394b9
 ts_init_subtest "kernel-cmdline"
b394b9
 export LIBMOUNT_KERNEL_CMDLINE="$TS_SELF/files/kernel_cmdline"
b394b9
 ts_valgrind $TESTPROG --kernel-cmdline selinux= &>> $TS_OUTPUT
b394b9
-- 
b394b9
2.7.4
b394b9