summarylogtreecommitdiffstats
path: root/0011-Linux-5.12-Add-user_namespace-param-to-inode-ops.patch
blob: 001f1782df22d10f9daa6845647dcc9ce51b33d1 (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
From 1a5b57363724d221a9065bbb10f817485d0a8bc3 Mon Sep 17 00:00:00 2001
From: Cheyenne Wills <cwills@sinenomine.net>
Date: Fri, 5 Mar 2021 16:31:03 -0700
Subject: [PATCH 11/11] Linux 5.12: Add user_namespace param to inode ops

The Linux commits:
"fs: make helpers idmap mount aware" (549c72977) and
"attr: handle idmapped mounts" (2f221d6f7) that were merged into
Linux-5.12-rc1 cause a build failure when creating the kernel module.

Several functions within the inode_operations structure had their
signature updated to include a user_namespace parameter.  This allows
a filesystem to support idmapped mounts.

OpenAFS only implements some of the changed functions.

   LINUX/vnodeops function inode_operation
   =====================   ===============
   afs_notify_change       setattr
   afs_linux_getattr       getattr
   afs_linux_create        create
   afs_linux_symlink       symlink
   afs_linux_mkdir         mkdir
   afs_linux_rename        rename
   afs_linux_permission    permission

Update the autoconf tests to determine if the Linux kernel requires
the user_namespace structure for inode_operations functions. If so,
define a generic "IOP_TAKES_USER_NAMESPACE" macro.

Update the above vnodeops functions to accept a 'struct user_namespace'
parameter.

When using the 'setattr_prepare' function a user namespace must be
now provided. In order to provide compatibility as a non-idmapped mount
filesystem the initial user namespace can be used. With OpenAFS, the
initial user namespace obtained at kernel module load time is stored in
a global variable 'afs_ns'.

Update the call to setattr_prepare to pass the user namespace pointed
to by the 'afs_ns' global variable.

Update calls to setattr to pass the user namespace pointed to by
the 'afs_ns' global variable.

Notes:

The changes introduced with Linux 5.12 allow a filesystem to support
idmapped mounts if desired. This commit does not implement support for
idmapped mounts, but will continue to use the same initial user
namespace as prior to Linux 5.12.

With Linux 5.12 the following autoconf checks fail:

 HAVE_LINUX_INODE_OPERATIONS_RENAME_TAKES_FLAGS
 HAVE_LINUX_SETATTR_PREPARE
 IOP_CREATE_TAKES_BOOL
 IOP_GETATTR_TAKES_PATH_STRUCT
 IOP_MKDIR_TAKES_UMODE_T

The new macro 'IOP_TAKES_USER_NAMESPACE' covers the cases where these
macros where used.

Reviewed-on: https://gerrit.openafs.org/14549
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
(cherry picked from commit 1bd68506be3243c5670aaf53798b2e4e715d4c8b)

Change-Id: I8cd54042da4e0295f3cf8417c84138bb0458f881
Reviewed-on: https://gerrit.openafs.org/14565
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
---
 src/afs/LINUX/osi_compat.h   |  8 +++--
 src/afs/LINUX/osi_vnodeops.c | 69 +++++++++++++++++++++++++++++++-----
 src/cf/linux-kernel-sig.m4   | 16 ++++++++-
 3 files changed, 81 insertions(+), 12 deletions(-)

diff --git a/src/afs/LINUX/osi_compat.h b/src/afs/LINUX/osi_compat.h
index 3ac4d798d..726b6559c 100644
--- a/src/afs/LINUX/osi_compat.h
+++ b/src/afs/LINUX/osi_compat.h
@@ -524,7 +524,9 @@ afs_inode_setattr(struct osi_file *afile, struct iattr *newattrs) {
 
     int code = 0;
     struct inode *inode = OSIFILE_INODE(afile);
-#if !defined(HAVE_LINUX_INODE_SETATTR)
+#if defined(IOP_TAKES_USER_NAMESPACE)
+    code = inode->i_op->setattr(afs_ns, afile->filp->f_dentry, newattrs);
+#elif !defined(HAVE_LINUX_INODE_SETATTR)
     code = inode->i_op->setattr(afile->filp->f_dentry, newattrs);
 #elif defined(INODE_SETATTR_NOT_VOID)
     if (inode->i_op && inode->i_op->setattr)
@@ -751,7 +753,9 @@ afs_d_path(struct dentry *dp, struct vfsmount *mnt, char *buf, int buflen)
 static inline int
 afs_setattr_prepare(struct dentry *dp, struct iattr *newattrs)
 {
-#if defined(HAVE_LINUX_SETATTR_PREPARE)
+#if defined(IOP_TAKES_USER_NAMESPACE)
+    return setattr_prepare(afs_ns, dp, newattrs);
+#elif defined(HAVE_LINUX_SETATTR_PREPARE)
     return setattr_prepare(dp, newattrs);
 #else
     return inode_change_ok(dp->d_inode, newattrs);
diff --git a/src/afs/LINUX/osi_vnodeops.c b/src/afs/LINUX/osi_vnodeops.c
index 4d0f55c95..9d4a6e334 100644
--- a/src/afs/LINUX/osi_vnodeops.c
+++ b/src/afs/LINUX/osi_vnodeops.c
@@ -1118,8 +1118,13 @@ vattr2inode(struct inode *ip, struct vattr *vp)
  * Linux version of setattr call. What to change is in the iattr struct.
  * We need to set bits in both the Linux inode as well as the vcache.
  */
+#if defined(IOP_TAKES_USER_NAMESPACE)
+static int
+afs_notify_change(struct user_namespace *mnt_userns, struct dentry *dp, struct iattr *iattrp)
+#else
 static int
 afs_notify_change(struct dentry *dp, struct iattr *iattrp)
+#endif
 {
     struct vattr *vattr = NULL;
     cred_t *credp = crref();
@@ -1147,7 +1152,18 @@ out:
     return afs_convert_code(code);
 }
 
-#if defined(IOP_GETATTR_TAKES_PATH_STRUCT)
+#if defined(IOP_TAKES_USER_NAMESPACE)
+static int
+afs_linux_getattr(struct user_namespace *mnt_userns, const struct path *path, struct kstat *stat,
+		  u32 request_mask, unsigned int sync_mode)
+{
+	int err = afs_linux_revalidate(path->dentry);
+	if (!err) {
+		generic_fillattr(afs_ns, path->dentry->d_inode, stat);
+	}
+	return err;
+}
+#elif defined(IOP_GETATTR_TAKES_PATH_STRUCT)
 static int
 afs_linux_getattr(const struct path *path, struct kstat *stat, u32 request_mask, unsigned int sync_mode)
 {
@@ -1605,17 +1621,25 @@ struct dentry_operations afs_dentry_operations = {
  *
  * name is in kernel space at this point.
  */
+
+#if defined(IOP_TAKES_USER_NAMESPACE)
+static int
+afs_linux_create(struct user_namespace *mnt_userns, struct inode *dip,
+		 struct dentry *dp, umode_t mode, bool excl)
+#elif defined(IOP_CREATE_TAKES_BOOL)
 static int
-#if defined(IOP_CREATE_TAKES_BOOL)
 afs_linux_create(struct inode *dip, struct dentry *dp, umode_t mode,
 		 bool excl)
 #elif defined(IOP_CREATE_TAKES_UMODE_T)
+static int
 afs_linux_create(struct inode *dip, struct dentry *dp, umode_t mode,
 		 struct nameidata *nd)
 #elif defined(IOP_CREATE_TAKES_NAMEIDATA)
+static int
 afs_linux_create(struct inode *dip, struct dentry *dp, int mode,
 		 struct nameidata *nd)
 #else
+static int
 afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
 #endif
 {
@@ -1890,8 +1914,14 @@ afs_linux_unlink(struct inode *dip, struct dentry *dp)
 }
 
 
+#if defined(IOP_TAKES_USER_NAMESPACE)
+static int
+afs_linux_symlink(struct user_namespace *mnt_userns, struct inode *dip,
+		  struct dentry *dp, const char *target)
+#else
 static int
 afs_linux_symlink(struct inode *dip, struct dentry *dp, const char *target)
+#endif
 {
     int code;
     cred_t *credp = crref();
@@ -1919,10 +1949,15 @@ out:
     return afs_convert_code(code);
 }
 
+#if defined(IOP_TAKES_USER_NAMESPACE)
+static int
+afs_linux_mkdir(struct user_namespace *mnt_userns, struct inode *dip,
+		struct dentry *dp, umode_t mode)
+#elif defined(IOP_MKDIR_TAKES_UMODE_T)
 static int
-#if defined(IOP_MKDIR_TAKES_UMODE_T)
 afs_linux_mkdir(struct inode *dip, struct dentry *dp, umode_t mode)
 #else
+static int
 afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
 #endif
 {
@@ -1994,13 +2029,22 @@ afs_linux_rmdir(struct inode *dip, struct dentry *dp)
 }
 
 
+#if defined(IOP_TAKES_USER_NAMESPACE)
+static int
+afs_linux_rename(struct user_namespace *mnt_userns,
+		 struct inode *oldip, struct dentry *olddp,
+		 struct inode *newip, struct dentry *newdp,
+		 unsigned int flags)
+#elif defined(HAVE_LINUX_INODE_OPERATIONS_RENAME_TAKES_FLAGS)
+static int
+afs_linux_rename(struct inode *oldip, struct dentry *olddp,
+		 struct inode *newip, struct dentry *newdp,
+		 unsigned int flags)
+#else
 static int
 afs_linux_rename(struct inode *oldip, struct dentry *olddp,
-		 struct inode *newip, struct dentry *newdp
-#ifdef HAVE_LINUX_INODE_OPERATIONS_RENAME_TAKES_FLAGS
-		 , unsigned int flags
+		 struct inode *newip, struct dentry *newdp)
 #endif
-		)
 {
     int code;
     cred_t *credp = crref();
@@ -2008,7 +2052,8 @@ afs_linux_rename(struct inode *oldip, struct dentry *olddp,
     const char *newname = newdp->d_name.name;
     struct dentry *rehash = NULL;
 
-#ifdef HAVE_LINUX_INODE_OPERATIONS_RENAME_TAKES_FLAGS
+#if defined(HAVE_LINUX_INODE_OPERATIONS_RENAME_TAKES_FLAGS) || \
+    defined(IOP_TAKES_USER_NAMESPACE)
     if (flags)
 	return -EINVAL;		/* no support for new flags yet */
 #endif
@@ -3030,12 +3075,18 @@ done:
 /* afs_linux_permission
  * Check access rights - returns error if can't check or permission denied.
  */
+
+#if defined(IOP_TAKES_USER_NAMESPACE)
+static int
+afs_linux_permission(struct user_namespace *mnt_userns, struct inode *ip, int mode)
+#elif defined(IOP_PERMISSION_TAKES_FLAGS)
 static int
-#if defined(IOP_PERMISSION_TAKES_FLAGS)
 afs_linux_permission(struct inode *ip, int mode, unsigned int flags)
 #elif defined(IOP_PERMISSION_TAKES_NAMEIDATA)
+static int
 afs_linux_permission(struct inode *ip, int mode, struct nameidata *nd)
 #else
+static int
 afs_linux_permission(struct inode *ip, int mode)
 #endif
 {
diff --git a/src/cf/linux-kernel-sig.m4 b/src/cf/linux-kernel-sig.m4
index 3d3aff909..e0cc9a2f3 100644
--- a/src/cf/linux-kernel-sig.m4
+++ b/src/cf/linux-kernel-sig.m4
@@ -14,4 +14,18 @@ AC_CHECK_LINUX_OPERATION([inode_operations], [rename], [takes_flags],
                          [struct inode *oinode, struct dentry *odentry,
                          struct inode *ninode, struct dentry *ndentry,
                          unsigned int flags])
-])
+dnl Linux 5.12 added the user_namespace parameter to the several
+dnl inode operations functions.
+dnl Perform a generic test using the inode_op create to test for this change.
+AC_CHECK_LINUX_OPERATION([inode_operations], [create], [user_namespace],
+                         [#include <linux/fs.h>],
+                         [int],
+                         [struct user_namespace *mnt_userns,
+                         struct inode *inode, struct dentry *dentry,
+                         umode_t umode, bool flag])
+dnl if HAVE_LINUX_INODE_OPERATIONS_CREATE_USER_NAMESPACE, create a more generic
+dnl define.
+AS_IF([test AS_VAR_GET([ac_cv_linux_operation_inode_operations_create_user_namespace]) = yes],
+      [AC_DEFINE([IOP_TAKES_USER_NAMESPACE], 1,
+                 [define if inodeops require struct user_namespace])])
+])
\ No newline at end of file
-- 
2.31.1