aboutsummaryrefslogtreecommitdiff
path: root/utils/lxc/patches/001-build-detect-where-struct-mount_attr-is-declared.patch
blob: 89b52fc227b94ac83ab331a9eabcd5e04232a0a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
From c1115e1503bf955c97f4cf3b925a6a9f619764c3 Mon Sep 17 00:00:00 2001
From: Christian Brauner <brauner@kernel.org>
Date: Tue, 9 Aug 2022 16:14:25 +0200
Subject: build: detect where struct mount_attr is declared

Fixes: #4176
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
---
 meson.build                | 30 ++++++++++++++++++++++++++++--
 src/lxc/conf.c             |  6 +++---
 src/lxc/conf.h             |  2 +-
 src/lxc/mount_utils.c      |  6 +++---
 src/lxc/syscall_wrappers.h | 12 ++++++++++--
 5 files changed, 45 insertions(+), 11 deletions(-)

--- a/meson.build
+++ b/meson.build
@@ -589,7 +589,6 @@ decl_headers = '''
 foreach decl: [
     '__aligned_u64',
     'struct clone_args',
-    'struct mount_attr',
     'struct open_how',
     'struct rtnl_link_stats64',
 ]
@@ -609,7 +608,6 @@ foreach tuple: [
     ['struct seccomp_notif_sizes'],
     ['struct clone_args'],
     ['__aligned_u64'],
-    ['struct mount_attr'],
     ['struct open_how'],
     ['struct rtnl_link_stats64'],
 ]
@@ -629,6 +627,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>
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -2885,7 +2885,7 @@ static int __lxc_idmapped_mounts_child(s
 		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(s
 
 		/* 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 lx
 
 	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;
 
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -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;
 };
 
--- a/src/lxc/mount_utils.c
+++ b/src/lxc/mount_utils.c
@@ -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
 {
 	__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
 		    __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,
--- a/src/lxc/syscall_wrappers.h
+++ b/src/lxc/syscall_wrappers.h
@@ -18,6 +18,12 @@
 #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 i
 /*
  * 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);
 }