]>
Commit | Line | Data |
---|---|---|
a82ba04e | 1 | From c1115e1503bf955c97f4cf3b925a6a9f619764c3 Mon Sep 17 00:00:00 2001 |
2 | From: Christian Brauner <brauner@kernel.org> | |
3 | Date: Tue, 9 Aug 2022 16:14:25 +0200 | |
4 | Subject: [PATCH] build: detect where struct mount_attr is declared | |
5 | ||
6 | Fixes: #4176 | |
7 | Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com> | |
8 | [Retrieved from: | |
9 | https://github.com/lxc/lxc/commit/c1115e1503bf955c97f4cf3b925a6a9f619764c3] | |
10 | Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> | |
11 | --- | |
12 | src/lxc/conf.c | 6 +++--- | |
13 | src/lxc/conf.h | 2 +- | |
14 | src/lxc/mount_utils.c | 6 +++--- | |
15 | src/lxc/syscall_wrappers.h | 12 ++++++++++-- | |
16 | 5 files changed, 45 insertions(+), 11 deletions(-) | |
17 | ||
18 | diff --git a/src/lxc/conf.c b/src/lxc/conf.c | |
19 | index ffbe74c2f6..4193cd07f5 100644 | |
20 | --- a/src/lxc/conf.c | |
21 | +++ b/src/lxc/conf.c | |
22 | @@ -2885,7 +2885,7 @@ static int __lxc_idmapped_mounts_child(struct lxc_handler *handler, FILE *f) | |
23 | struct lxc_mount_options opts = {}; | |
24 | int dfd_from; | |
25 | const char *source_relative, *target_relative; | |
26 | - struct lxc_mount_attr attr = {}; | |
27 | + struct mount_attr attr = {}; | |
28 | ||
29 | ret = parse_lxc_mount_attrs(&opts, mntent.mnt_opts); | |
30 | if (ret < 0) | |
31 | @@ -3005,7 +3005,7 @@ static int __lxc_idmapped_mounts_child(struct lxc_handler *handler, FILE *f) | |
32 | ||
33 | /* Set propagation mount options. */ | |
34 | if (opts.attr.propagation) { | |
35 | - attr = (struct lxc_mount_attr) { | |
36 | + attr = (struct mount_attr) { | |
37 | .propagation = opts.attr.propagation, | |
38 | }; | |
39 | ||
40 | @@ -4109,7 +4109,7 @@ int lxc_idmapped_mounts_parent(struct lxc_handler *handler) | |
41 | ||
42 | for (;;) { | |
43 | __do_close int fd_from = -EBADF, fd_userns = -EBADF; | |
44 | - struct lxc_mount_attr attr = {}; | |
45 | + struct mount_attr attr = {}; | |
46 | struct lxc_mount_options opts = {}; | |
47 | ssize_t ret; | |
48 | ||
49 | diff --git a/src/lxc/conf.h b/src/lxc/conf.h | |
50 | index 7dc2f15b60..772479f9e1 100644 | |
51 | --- a/src/lxc/conf.h | |
52 | +++ b/src/lxc/conf.h | |
53 | @@ -223,7 +223,7 @@ struct lxc_mount_options { | |
54 | unsigned long mnt_flags; | |
55 | unsigned long prop_flags; | |
56 | char *data; | |
57 | - struct lxc_mount_attr attr; | |
58 | + struct mount_attr attr; | |
59 | char *raw_options; | |
60 | }; | |
61 | ||
62 | diff --git a/src/lxc/mount_utils.c b/src/lxc/mount_utils.c | |
63 | index bba75f933c..88dd73ee36 100644 | |
64 | --- a/src/lxc/mount_utils.c | |
65 | +++ b/src/lxc/mount_utils.c | |
66 | @@ -31,7 +31,7 @@ lxc_log_define(mount_utils, lxc); | |
67 | * setting in @attr_set, but must also specify MOUNT_ATTR__ATIME in the | |
68 | * @attr_clr field. | |
69 | */ | |
70 | -static inline void set_atime(struct lxc_mount_attr *attr) | |
71 | +static inline void set_atime(struct mount_attr *attr) | |
72 | { | |
73 | switch (attr->attr_set & MOUNT_ATTR__ATIME) { | |
74 | case MOUNT_ATTR_RELATIME: | |
75 | @@ -272,7 +272,7 @@ int create_detached_idmapped_mount(const char *path, int userns_fd, | |
76 | { | |
77 | __do_close int fd_tree_from = -EBADF; | |
78 | unsigned int open_tree_flags = OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC; | |
79 | - struct lxc_mount_attr attr = { | |
80 | + struct mount_attr attr = { | |
81 | .attr_set = MOUNT_ATTR_IDMAP | attr_set, | |
82 | .attr_clr = attr_clr, | |
83 | .userns_fd = userns_fd, | |
84 | @@ -335,7 +335,7 @@ int __fd_bind_mount(int dfd_from, const char *path_from, __u64 o_flags_from, | |
85 | __u64 attr_clr, __u64 propagation, int userns_fd, | |
86 | bool recursive) | |
87 | { | |
88 | - struct lxc_mount_attr attr = { | |
89 | + struct mount_attr attr = { | |
90 | .attr_set = attr_set, | |
91 | .attr_clr = attr_clr, | |
92 | .propagation = propagation, | |
93 | diff --git a/src/lxc/syscall_wrappers.h b/src/lxc/syscall_wrappers.h | |
94 | index a5e98b565c..c8a7d0c7b7 100644 | |
95 | --- a/src/lxc/syscall_wrappers.h | |
96 | +++ b/src/lxc/syscall_wrappers.h | |
97 | @@ -18,6 +18,12 @@ | |
98 | #include "macro.h" | |
99 | #include "syscall_numbers.h" | |
100 | ||
101 | +#if HAVE_STRUCT_MOUNT_ATTR | |
102 | +#include <sys/mount.h> | |
103 | +#elif HAVE_UAPI_STRUCT_MOUNT_ATTR | |
104 | +#include <linux/mount.h> | |
105 | +#endif | |
106 | + | |
107 | #ifdef HAVE_LINUX_MEMFD_H | |
108 | #include <linux/memfd.h> | |
109 | #endif | |
110 | @@ -210,16 +216,18 @@ extern int fsmount(int fs_fd, unsigned int flags, unsigned int attr_flags); | |
111 | /* | |
112 | * mount_setattr() | |
113 | */ | |
114 | -struct lxc_mount_attr { | |
115 | +#if !HAVE_STRUCT_MOUNT_ATTR && !HAVE_UAPI_STRUCT_MOUNT_ATTR | |
116 | +struct mount_attr { | |
117 | __u64 attr_set; | |
118 | __u64 attr_clr; | |
119 | __u64 propagation; | |
120 | __u64 userns_fd; | |
121 | }; | |
122 | +#endif | |
123 | ||
124 | #if !HAVE_MOUNT_SETATTR | |
125 | static inline int mount_setattr(int dfd, const char *path, unsigned int flags, | |
126 | - struct lxc_mount_attr *attr, size_t size) | |
127 | + struct mount_attr *attr, size_t size) | |
128 | { | |
129 | return syscall(__NR_mount_setattr, dfd, path, flags, attr, size); | |
130 | } | |
131 | --- a/configure.ac 2022-11-21 22:26:58.649999866 +0100 | |
132 | +++ b/configure.ac 2022-11-21 23:13:32.826666552 +0100 | |
133 | @@ -701,7 +701,8 @@ | |
134 | # Check for some syscalls functions | |
135 | AC_CHECK_FUNCS([setns pivot_root sethostname unshare rand_r confstr faccessat gettid memfd_create move_mount open_tree execveat clone3 fsopen fspick fsconfig fsmount openat2 close_range statvfs mount_setattr sigdescr_np]) | |
136 | AC_CHECK_TYPES([__aligned_u64], [], [], [[#include <linux/types.h>]]) | |
137 | -AC_CHECK_TYPES([struct mount_attr], [], [], [[#include <linux/mount.h>]]) | |
138 | +AC_CHECK_TYPES([struct mount_attr], [], [], [[#include <sys/mount.h>]]) | |
139 | +AC_CHECK_TYPES([struct mount_attr], AC_DEFINE(HAVE_UAPI_STRUCT_MOUNT_ATTR,1,[mount_attr from <linux/mount.h>]), [], [[#include <linux/mount.h>]]) | |
140 | AC_CHECK_TYPES([struct open_how], [], [], [[#include <linux/openat2.h>]]) | |
141 | AC_CHECK_TYPES([struct clone_args], [], [], [[#include <linux/sched.h>]]) | |
142 | AC_CHECK_MEMBERS([struct clone_args.set_tid],[],[],[[#include <linux/sched.h>]]) |