]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
mount_utils: add helper to determine whether new mount api supports bind mounts
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 17 Mar 2021 10:07:47 +0000 (11:07 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 21 Apr 2021 08:05:59 +0000 (10:05 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/mount_utils.c
src/lxc/mount_utils.h

index c0d5a453585e93c00864b16f87b17745d0b62231..05d129ac14e7e30630b5702772974ade085ad771 100644 (file)
@@ -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;
+}
index 5053ebfea39fbef12529e1b41266fe7cbba79a64..7edc15fd2d069f6a0942cfb85ffe9979d053362c 100644 (file)
@@ -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 */