aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2022-01-18 15:13:23 +0100
committerEryu Guan <guaneryu@gmail.com>2022-01-23 22:25:12 +0800
commitbd4746b14ae607b09cf5d99573af91f17895a69f (patch)
tree166dd55df70a3a1ef22a305980412bce4ead5433
parentb454412847f35a8102d8d8080d159cfec77c0384 (diff)
downloadxfstests-dev-bd4746b14ae607b09cf5d99573af91f17895a69f.tar.gz
idmapped-mounts: add fs_allow_idmap() helper
Move the check whether the underlying filesystem supports idmapped mounts into a separate helper. We will use it in the following patch to make it possible to always run all tests that don't require idmapped mounts. Link: https://lore.kernel.org/r/20220113132421.865002-1-brauner@kernel.org Cc: Seth Forshee <sforshee@digitalocean.com> Cc: Eryu Guan <guaneryu@gmail.com> Cc: Christoph Hellwig <hch@lst.de> Cc: fstests@vger.kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org> Reviewed-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: Eryu Guan <guaneryu@gmail.com>
-rw-r--r--src/idmapped-mounts/idmapped-mounts.c57
1 files changed, 30 insertions, 27 deletions
diff --git a/src/idmapped-mounts/idmapped-mounts.c b/src/idmapped-mounts/idmapped-mounts.c
index a5c0a983e6..fc305606e6 100644
--- a/src/idmapped-mounts/idmapped-mounts.c
+++ b/src/idmapped-mounts/idmapped-mounts.c
@@ -13955,6 +13955,35 @@ static bool run_test(struct t_idmapped_mounts suite[], size_t suite_size)
return true;
}
+static bool fs_allow_idmap(void)
+{
+ int ret;
+ int open_tree_fd = -EBADF;
+ struct mount_attr attr = {
+ .attr_set = MOUNT_ATTR_IDMAP,
+ .userns_fd = -EBADF,
+ };
+
+ /* Changing mount properties on a detached mount. */
+ attr.userns_fd = get_userns_fd(0, 1000, 1);
+ if (attr.userns_fd < 0)
+ return false;
+
+ open_tree_fd = sys_open_tree(t_mnt_fd, "",
+ AT_EMPTY_PATH | AT_NO_AUTOMOUNT |
+ AT_SYMLINK_NOFOLLOW | OPEN_TREE_CLOEXEC |
+ OPEN_TREE_CLONE);
+ if (open_tree_fd < 0)
+ ret = -1;
+ else
+ ret = sys_mount_setattr(open_tree_fd, "", AT_EMPTY_PATH, &attr,
+ sizeof(attr));
+ close(open_tree_fd);
+ close(attr.userns_fd);
+
+ return ret == 0;
+}
+
int main(int argc, char *argv[])
{
int fret, ret;
@@ -14035,34 +14064,8 @@ int main(int argc, char *argv[])
* idmapped mounts.
*/
if (supported) {
- int open_tree_fd = -EBADF;
- struct mount_attr attr = {
- .attr_set = MOUNT_ATTR_IDMAP,
- .userns_fd = -EBADF,
- };
-
- /* Changing mount properties on a detached mount. */
- attr.userns_fd = get_userns_fd(0, 1000, 1);
- if (attr.userns_fd < 0)
+ if (!fs_allow_idmap())
exit(EXIT_FAILURE);
-
- open_tree_fd = sys_open_tree(t_mnt_fd, "",
- AT_EMPTY_PATH |
- AT_NO_AUTOMOUNT |
- AT_SYMLINK_NOFOLLOW |
- OPEN_TREE_CLOEXEC |
- OPEN_TREE_CLONE);
- if (open_tree_fd < 0)
- ret = -1;
- else
- ret = sys_mount_setattr(open_tree_fd, "", AT_EMPTY_PATH, &attr, sizeof(attr));
-
- close(open_tree_fd);
- close(attr.userns_fd);
-
- if (ret)
- exit(EXIT_FAILURE);
-
exit(EXIT_SUCCESS);
}