]> git.proxmox.com Git - mirror_lxc.git/commitdiff
build: detect where struct mount_attr is declared
authorChristian Brauner <brauner@kernel.org>
Tue, 9 Aug 2022 14:14:25 +0000 (16:14 +0200)
committerChristian Brauner (Microsoft) <christian.brauner@ubuntu.com>
Tue, 9 Aug 2022 15:20:13 +0000 (17:20 +0200)
Fixes: #4176
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
meson.build
src/lxc/conf.c
src/lxc/conf.h
src/lxc/mount_utils.c
src/lxc/syscall_wrappers.h

index a145faf069fb25a2920c6a1205c99a15e5d0775c..f679aabbc8a6b05dc5f2b10b054362abd5d7359f 100644 (file)
@@ -590,7 +590,6 @@ decl_headers = '''
 foreach decl: [
     '__aligned_u64',
     'struct clone_args',
-    'struct mount_attr',
     'struct open_how',
     'struct rtnl_link_stats64',
 ]
@@ -610,7 +609,6 @@ foreach tuple: [
     ['struct seccomp_notif_sizes'],
     ['struct clone_args'],
     ['__aligned_u64'],
-    ['struct mount_attr'],
     ['struct open_how'],
     ['struct rtnl_link_stats64'],
 ]
@@ -630,6 +628,34 @@ foreach tuple: [
     endif
 endforeach
 
+## Types.
+decl_headers = '''
+#include <sys/mount.h>
+'''
+
+# We get -1 if the size cannot be determined
+if cc.sizeof('struct mount_attr', prefix: decl_headers, args: '-D_GNU_SOURCE') > 0
+    srcconf.set10('HAVE_' + 'struct mount_attr'.underscorify().to_upper(), true)
+    found_types += 'struct mount_attr (sys/mount.h)'
+else
+    srcconf.set10('HAVE_' + 'struct mount_attr'.underscorify().to_upper(), false)
+    missing_types += 'struct mount_attr (sys/mount.h)'
+endif
+
+## Types.
+decl_headers = '''
+#include <linux/mount.h>
+'''
+
+# We get -1 if the size cannot be determined
+if cc.sizeof('struct mount_attr', prefix: decl_headers, args: '-D_GNU_SOURCE') > 0
+    srcconf.set10('HAVE_UAPI_' + 'struct mount_attr'.underscorify().to_upper(), true)
+    found_types += 'struct mount_attr (linux/mount.h)'
+else
+    srcconf.set10('HAVE_UAPI_' + 'struct mount_attr'.underscorify().to_upper(), false)
+    missing_types += 'struct mount_attr (linux/mount.h)'
+endif
+
 ## Headers.
 foreach ident: [
     ['bpf',               '''#include <sys/syscall.h>
index ffbe74c2f6cb5b3a8441a21f1510764a5aefa74f..4193cd07f52e9b69cb4b404ba86b40dc4dc4e11a 100644 (file)
@@ -2885,7 +2885,7 @@ static int __lxc_idmapped_mounts_child(struct lxc_handler *handler, FILE *f)
                struct lxc_mount_options opts = {};
                int dfd_from;
                const char *source_relative, *target_relative;
-               struct lxc_mount_attr attr = {};
+               struct mount_attr attr = {};
 
                ret = parse_lxc_mount_attrs(&opts, mntent.mnt_opts);
                if (ret < 0)
@@ -3005,7 +3005,7 @@ static int __lxc_idmapped_mounts_child(struct lxc_handler *handler, FILE *f)
 
                /* Set propagation mount options. */
                if (opts.attr.propagation) {
-                       attr = (struct lxc_mount_attr) {
+                       attr = (struct mount_attr) {
                                .propagation = opts.attr.propagation,
                        };
 
@@ -4109,7 +4109,7 @@ int lxc_idmapped_mounts_parent(struct lxc_handler *handler)
 
        for (;;) {
                __do_close int fd_from = -EBADF, fd_userns = -EBADF;
-               struct lxc_mount_attr attr = {};
+               struct mount_attr attr = {};
                struct lxc_mount_options opts = {};
                ssize_t ret;
 
index 7dc2f15b603cf98b7514b6aa4203ad8770724114..772479f9e1be5f973c82736b02f053343120bd7d 100644 (file)
@@ -223,7 +223,7 @@ struct lxc_mount_options {
        unsigned long mnt_flags;
        unsigned long prop_flags;
        char *data;
-       struct lxc_mount_attr attr;
+       struct mount_attr attr;
        char *raw_options;
 };
 
index bba75f933cc9dcddc7e9c422b13c5b2e4586eef3..88dd73ee36b2b8e8c6ac95b80fed2fbba7d1961e 100644 (file)
@@ -31,7 +31,7 @@ lxc_log_define(mount_utils, lxc);
  * setting in @attr_set, but must also specify MOUNT_ATTR__ATIME in the
  * @attr_clr field.
  */
-static inline void set_atime(struct lxc_mount_attr *attr)
+static inline void set_atime(struct mount_attr *attr)
 {
        switch (attr->attr_set & MOUNT_ATTR__ATIME) {
        case MOUNT_ATTR_RELATIME:
@@ -272,7 +272,7 @@ int create_detached_idmapped_mount(const char *path, int userns_fd,
 {
        __do_close int fd_tree_from = -EBADF;
        unsigned int open_tree_flags = OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC;
-       struct lxc_mount_attr attr = {
+       struct mount_attr attr = {
                .attr_set       = MOUNT_ATTR_IDMAP | attr_set,
                .attr_clr       = attr_clr,
                .userns_fd      = userns_fd,
@@ -335,7 +335,7 @@ int __fd_bind_mount(int dfd_from, const char *path_from, __u64 o_flags_from,
                    __u64 attr_clr, __u64 propagation, int userns_fd,
                    bool recursive)
 {
-       struct lxc_mount_attr attr = {
+       struct mount_attr attr = {
                .attr_set       = attr_set,
                .attr_clr       = attr_clr,
                .propagation    = propagation,
index a5e98b565cb6666c0e04bc36bc156e3da048eddf..c8a7d0c7b700d1952b23a74077b7dbfd55842f3a 100644 (file)
 #include "macro.h"
 #include "syscall_numbers.h"
 
+#if HAVE_STRUCT_MOUNT_ATTR
+#include <sys/mount.h>
+#elif HAVE_UAPI_STRUCT_MOUNT_ATTR
+#include <linux/mount.h>
+#endif
+
 #ifdef HAVE_LINUX_MEMFD_H
 #include <linux/memfd.h>
 #endif
@@ -210,16 +216,18 @@ extern int fsmount(int fs_fd, unsigned int flags, unsigned int attr_flags);
 /*
  * mount_setattr()
  */
-struct lxc_mount_attr {
+#if !HAVE_STRUCT_MOUNT_ATTR && !HAVE_UAPI_STRUCT_MOUNT_ATTR
+struct mount_attr {
        __u64 attr_set;
        __u64 attr_clr;
        __u64 propagation;
        __u64 userns_fd;
 };
+#endif
 
 #if !HAVE_MOUNT_SETATTR
 static inline int mount_setattr(int dfd, const char *path, unsigned int flags,
-                               struct lxc_mount_attr *attr, size_t size)
+                               struct mount_attr *attr, size_t size)
 {
        return syscall(__NR_mount_setattr, dfd, path, flags, attr, size);
 }