dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

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

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