|
Yu Watanabe |
38161d |
From b13268dc09eed68426c2e68a402c96b93f8b0fff Mon Sep 17 00:00:00 2001
|
|
Yu Watanabe |
38161d |
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
Yu Watanabe |
38161d |
Date: Mon, 12 Sep 2022 04:57:17 +0900
|
|
Yu Watanabe |
38161d |
Subject: [PATCH] test-mountpoint-util: support running on a mount namespace
|
|
Yu Watanabe |
38161d |
with another mount on /proc
|
|
Yu Watanabe |
38161d |
|
|
Yu Watanabe |
38161d |
Fixes #11505.
|
|
Yu Watanabe |
38161d |
---
|
|
Yu Watanabe |
38161d |
src/test/test-mountpoint-util.c | 30 +++++++++++++++++++++---------
|
|
Yu Watanabe |
38161d |
1 file changed, 21 insertions(+), 9 deletions(-)
|
|
Yu Watanabe |
38161d |
|
|
Yu Watanabe |
38161d |
diff --git a/src/test/test-mountpoint-util.c b/src/test/test-mountpoint-util.c
|
|
Yu Watanabe |
38161d |
index 92eed0be62..391e1c97ba 100644
|
|
Yu Watanabe |
38161d |
--- a/src/test/test-mountpoint-util.c
|
|
Yu Watanabe |
38161d |
+++ b/src/test/test-mountpoint-util.c
|
|
Yu Watanabe |
38161d |
@@ -83,24 +83,36 @@ TEST(mnt_id) {
|
|
Yu Watanabe |
38161d |
|
|
Yu Watanabe |
38161d |
HASHMAP_FOREACH_KEY(p, k, h) {
|
|
Yu Watanabe |
38161d |
int mnt_id = PTR_TO_INT(k), mnt_id2;
|
|
Yu Watanabe |
38161d |
+ const char *q;
|
|
Yu Watanabe |
38161d |
|
|
Yu Watanabe |
38161d |
r = path_get_mnt_id(p, &mnt_id2);
|
|
Yu Watanabe |
38161d |
if (r < 0) {
|
|
Yu Watanabe |
38161d |
- log_debug_errno(r, "Failed to get the mnt id of %s: %m\n", p);
|
|
Yu Watanabe |
38161d |
+ log_debug_errno(r, "Failed to get the mnt id of %s: %m", p);
|
|
Yu Watanabe |
38161d |
continue;
|
|
Yu Watanabe |
38161d |
}
|
|
Yu Watanabe |
38161d |
|
|
Yu Watanabe |
38161d |
if (mnt_id == mnt_id2) {
|
|
Yu Watanabe |
38161d |
- log_debug("mnt ids of %s is %i\n", p, mnt_id);
|
|
Yu Watanabe |
38161d |
+ log_debug("mnt ids of %s is %i.", p, mnt_id);
|
|
Yu Watanabe |
38161d |
continue;
|
|
Yu Watanabe |
38161d |
} else
|
|
Yu Watanabe |
38161d |
- log_debug("mnt ids of %s are %i, %i\n", p, mnt_id, mnt_id2);
|
|
Yu Watanabe |
38161d |
-
|
|
Yu Watanabe |
38161d |
- /* The ids don't match? If so, then there are two mounts on the same path, let's check if
|
|
Yu Watanabe |
38161d |
- * that's really the case */
|
|
Yu Watanabe |
38161d |
- char *t = hashmap_get(h, INT_TO_PTR(mnt_id2));
|
|
Yu Watanabe |
38161d |
- log_debug("the other path for mnt id %i is %s\n", mnt_id2, t);
|
|
Yu Watanabe |
38161d |
- assert_se(path_equal(p, t));
|
|
Yu Watanabe |
38161d |
+ log_debug("mnt ids of %s are %i (from /proc/self/mountinfo), %i (from path_get_mnt_id()).", p, mnt_id, mnt_id2);
|
|
Yu Watanabe |
38161d |
+
|
|
Yu Watanabe |
38161d |
+ /* The ids don't match? This can easily happen e.g. running with "unshare --mount-proc".
|
|
Yu Watanabe |
38161d |
+ * See #11505. */
|
|
Yu Watanabe |
38161d |
+ assert_se(q = hashmap_get(h, INT_TO_PTR(mnt_id2)));
|
|
Yu Watanabe |
38161d |
+
|
|
Yu Watanabe |
38161d |
+ assert_se((r = path_is_mount_point(p, NULL, 0)) >= 0);
|
|
Yu Watanabe |
38161d |
+ if (r == 0) {
|
|
Yu Watanabe |
38161d |
+ /* If the path is not a mount point anymore, then it must be a sub directory of
|
|
Yu Watanabe |
38161d |
+ * the path corresponds to mnt_id2. */
|
|
Yu Watanabe |
38161d |
+ log_debug("The path %s for mnt id %i is not a mount point.", p, mnt_id2);
|
|
Yu Watanabe |
38161d |
+ assert_se(!isempty(path_startswith(p, q)));
|
|
Yu Watanabe |
38161d |
+ } else {
|
|
Yu Watanabe |
38161d |
+ /* If the path is still a mount point, then it must be equivalent to the path
|
|
Yu Watanabe |
38161d |
+ * corresponds to mnt_id2 */
|
|
Yu Watanabe |
38161d |
+ log_debug("There are multiple mounts on the same path %s.", p);
|
|
Yu Watanabe |
38161d |
+ assert_se(path_equal(p, q));
|
|
Yu Watanabe |
38161d |
+ }
|
|
Yu Watanabe |
38161d |
}
|
|
Yu Watanabe |
38161d |
}
|
|
Yu Watanabe |
38161d |
|
|
Yu Watanabe |
38161d |
--
|
|
Yu Watanabe |
38161d |
2.37.2
|
|
Yu Watanabe |
38161d |
|