From: Christian Brauner Date: Wed, 17 Mar 2021 10:07:47 +0000 (+0100) Subject: mount_utils: add helper to determine whether new mount api supports bind mounts X-Git-Tag: lxc-5.0.0~197^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4e07569bb5acafaaffa89ae7b713caa612518a0;p=thirdparty%2Flxc.git mount_utils: add helper to determine whether new mount api supports bind mounts Signed-off-by: Christian Brauner --- diff --git a/src/lxc/mount_utils.c b/src/lxc/mount_utils.c index c0d5a4535..05d129ac1 100644 --- a/src/lxc/mount_utils.c +++ b/src/lxc/mount_utils.c @@ -488,3 +488,28 @@ bool can_use_mount_api(void) return supported == 1; } + +bool can_use_bind_mounts(void) +{ + static int supported = -1; + + if (supported == -1) { + int ret; + + if (!can_use_mount_api()) { + supported = 0; + return false; + } + + ret = mount_setattr(-EBADF, NULL, 0, NULL, 0); + if (!ret || errno == ENOSYS) { + supported = 0; + return false; + } + + supported = 1; + TRACE("Kernel supports bind mounts in the new mount api"); + } + + return supported == 1; +} diff --git a/src/lxc/mount_utils.h b/src/lxc/mount_utils.h index 5053ebfea..7edc15fd2 100644 --- a/src/lxc/mount_utils.h +++ b/src/lxc/mount_utils.h @@ -206,5 +206,6 @@ __hidden extern unsigned long add_required_remount_flags(const char *s, unsigned long flags); __hidden extern bool can_use_mount_api(void); +__hidden extern bool can_use_bind_mounts(void); #endif /* __LXC_MOUNT_UTILS_H */