Gentoo Archives: gentoo-commits

From: Georgy Yakovlev <gyakovlev@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-fs/zfs-kmod/, sys-fs/zfs-kmod/files/
Date: Wed, 09 Jun 2021 05:20:42
Message-Id: 1623215994.f432437d19a693b4ad7515335a87e61d87df60b2.gyakovlev@gentoo
1 commit: f432437d19a693b4ad7515335a87e61d87df60b2
2 Author: Georgy Yakovlev <gyakovlev <AT> gentoo <DOT> org>
3 AuthorDate: Wed Jun 9 01:18:10 2021 +0000
4 Commit: Georgy Yakovlev <gyakovlev <AT> gentoo <DOT> org>
5 CommitDate: Wed Jun 9 05:19:54 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f432437d
7
8 sys-fs/zfs-kmod: fix a patch that's too large
9
10 Package-Manager: Portage-3.0.19, Repoman-3.0.3
11 Signed-off-by: Georgy Yakovlev <gyakovlev <AT> gentoo.org>
12
13 sys-fs/zfs-kmod/Manifest | 1 +
14 .../zfs-8.0.4_5.12_compat_idmapped_mounts.patch | 1231 --------------------
15 sys-fs/zfs-kmod/zfs-kmod-2.0.4-r1.ebuild | 5 +-
16 3 files changed, 4 insertions(+), 1233 deletions(-)
17
18 diff --git a/sys-fs/zfs-kmod/Manifest b/sys-fs/zfs-kmod/Manifest
19 index 514e285239e..272fa8bfaa3 100644
20 --- a/sys-fs/zfs-kmod/Manifest
21 +++ b/sys-fs/zfs-kmod/Manifest
22 @@ -2,3 +2,4 @@ DIST zfs-0.8.6.tar.gz 9295260 BLAKE2B 45424d710aaf75a05f766ae523ae157a24b5cbdcef
23 DIST zfs-2.0.4.tar.gz 13123872 BLAKE2B 7e4780092c0a87d5d187cd5734ddc736574db80b500f155287640ef2230e09335cc9b6b26ec1b7d8ab1b7942673ea49a3007a81da372a6d2ac36f3908913045c SHA512 1dda92d424372bce7020f5215545485eae69211b6f0fb6bea3c7c22efac76c6a2662f0dd14a03f723b6a6fe73b1228ecca211a4034b86cf885bcadf38ba0dc6b
24 DIST zfs-2.1.0-rc6.tar.gz 34777294 BLAKE2B 0080b03a9cf9717ae2bc7674e340dffafd923467368d8941df9be5a21f081e88745297e1a8b2ac5059e9f346949bbeb759a5fc8bcdb60c3be49b0645389ec8b1 SHA512 696d525c1c738a508d04366f8ffd0142aebe4498efbf129c9d38fa7c67dbec83554f55a2c4a5d7647a03ca0df173c2720fe85edbc859195f4ca19e04d2adf143
25 DIST zfs-2.1.0-rc6.tar.gz.asc 195 BLAKE2B a1267b8faffc75ac70082e261c6053b2070cbad014c92051ebc82af56b21bbe2e72e01e44c0701ed255a3201330bb56b5e1a72e12c1ae9f15f72883b53c17ec6 SHA512 afc0eb839de6b0b21b3d781dd74dce9f6f668b7b9fc079ea764666e28d4d3228b8a80641b6d0084851bffedfc3406dc0f829242f6b4247d192f554ba45ce3a4c
26 +DIST zfs-8.0.4_5.12_compat_idmapped_mounts.patch 41410 BLAKE2B 49724351c5a8e6ffa66762d5aac84ad89a3d04022d086d9f37ccd616b3e8e95852197b5333bdeeeab54fc51516d8254d0138a4422cc66214bb602e5ed72bbabf SHA512 1554d74a7024c106a3f4814895a64914f2e3d627f7edff3c8f415b419c6a596454862f8c0984a6e2f96e340851f1a9222a4c472ebd6d5db7dc0aa108dc2dca6c
27
28 diff --git a/sys-fs/zfs-kmod/files/zfs-8.0.4_5.12_compat_idmapped_mounts.patch b/sys-fs/zfs-kmod/files/zfs-8.0.4_5.12_compat_idmapped_mounts.patch
29 deleted file mode 100644
30 index fd8b025a8fd..00000000000
31 --- a/sys-fs/zfs-kmod/files/zfs-8.0.4_5.12_compat_idmapped_mounts.patch
32 +++ /dev/null
33 @@ -1,1231 +0,0 @@
34 -From f315d9a3ff3cc0b81c99dd9be5878a55d2e98d8e Mon Sep 17 00:00:00 2001
35 -From: Coleman Kane <ckane@×××××××××××.org>
36 -Date: Sat, 20 Mar 2021 00:00:59 -0400
37 -Subject: [PATCH] Linux 5.12 compat: idmapped mounts
38 -
39 -In Linux 5.12, the filesystem API was modified to support ipmapped
40 -mounts by adding a "struct user_namespace *" parameter to a number
41 -functions and VFS handlers. This change adds the needed autoconf
42 -macros to detect the new interfaces and updates the code appropriately.
43 -This change does not add support for idmapped mounts, instead it
44 -preserves the existing behavior by passing the initial user namespace
45 -where needed. A subsequent commit will be required to add support
46 -for idmapped mounted.
47 -
48 -Reviewed-by: Tony Hutter <hutter2@××××.gov>
49 -Reviewed-by: Brian Behlendorf <behlendorf1@××××.gov>
50 -Co-authored-by: Brian Behlendorf <behlendorf1@××××.gov>
51 -Signed-off-by: Coleman Kane <ckane@×××××××××××.org>
52 -Closes #11712
53 -(cherry picked from commit e2a8296131e94ad785f5564156ed2db1fdb2e080)
54 -Signed-off-by: Jonathon Fernyhough <jonathon@×××.dev>
55 ----
56 - config/kernel-generic_fillattr.m4 | 28 +++++++
57 - config/kernel-inode-create.m4 | 43 +++++++++--
58 - config/kernel-inode-getattr.m4 | 63 +++++++++++++---
59 - config/kernel-is_owner_or_cap.m4 | 23 +++++-
60 - config/kernel-mkdir-umode-t.m4 | 32 --------
61 - config/kernel-mkdir.m4 | 65 ++++++++++++++++
62 - config/kernel-mknod.m4 | 30 ++++++++
63 - config/kernel-rename.m4 | 50 ++++++++++---
64 - config/kernel-setattr-prepare.m4 | 45 ++++++++---
65 - config/kernel-symlink.m4 | 30 ++++++++
66 - config/kernel-xattr-handler.m4 | 78 +++++++++++++-------
67 - config/kernel.m4 | 18 +++--
68 - include/os/linux/kernel/linux/vfs_compat.h | 24 +++++-
69 - include/os/linux/kernel/linux/xattr_compat.h | 17 ++++-
70 - include/os/linux/zfs/sys/zfs_vnops_os.h | 3 +-
71 - include/os/linux/zfs/sys/zpl.h | 18 +++++
72 - module/os/linux/zfs/policy.c | 2 +-
73 - module/os/linux/zfs/zfs_vnops_os.c | 5 +-
74 - module/os/linux/zfs/zpl_ctldir.c | 51 ++++++++++++-
75 - module/os/linux/zfs/zpl_file.c | 2 +-
76 - module/os/linux/zfs/zpl_inode.c | 49 +++++++++++-
77 - module/os/linux/zfs/zpl_xattr.c | 4 +-
78 - 22 files changed, 557 insertions(+), 123 deletions(-)
79 - create mode 100644 config/kernel-generic_fillattr.m4
80 - delete mode 100644 config/kernel-mkdir-umode-t.m4
81 - create mode 100644 config/kernel-mkdir.m4
82 - create mode 100644 config/kernel-mknod.m4
83 - create mode 100644 config/kernel-symlink.m4
84 -
85 -diff --git a/config/kernel-generic_fillattr.m4 b/config/kernel-generic_fillattr.m4
86 -new file mode 100644
87 -index 00000000000..50c8031305b
88 ---- /dev/null
89 -+++ b/config/kernel-generic_fillattr.m4
90 -@@ -0,0 +1,28 @@
91 -+dnl #
92 -+dnl # 5.12 API
93 -+dnl #
94 -+dnl # generic_fillattr in linux/fs.h now requires a struct user_namespace*
95 -+dnl # as the first arg, to support idmapped mounts.
96 -+dnl #
97 -+AC_DEFUN([ZFS_AC_KERNEL_SRC_GENERIC_FILLATTR_USERNS], [
98 -+ ZFS_LINUX_TEST_SRC([generic_fillattr_userns], [
99 -+ #include <linux/fs.h>
100 -+ ],[
101 -+ struct user_namespace *userns = NULL;
102 -+ struct inode *in = NULL;
103 -+ struct kstat *k = NULL;
104 -+ generic_fillattr(userns, in, k);
105 -+ ])
106 -+])
107 -+
108 -+AC_DEFUN([ZFS_AC_KERNEL_GENERIC_FILLATTR_USERNS], [
109 -+ AC_MSG_CHECKING([whether generic_fillattr requres struct user_namespace*])
110 -+ ZFS_LINUX_TEST_RESULT([generic_fillattr_userns], [
111 -+ AC_MSG_RESULT([yes])
112 -+ AC_DEFINE(HAVE_GENERIC_FILLATTR_USERNS, 1,
113 -+ [generic_fillattr requires struct user_namespace*])
114 -+ ],[
115 -+ AC_MSG_RESULT([no])
116 -+ ])
117 -+])
118 -+
119 -diff --git a/config/kernel-inode-create.m4 b/config/kernel-inode-create.m4
120 -index 9f28bcbd4f7..a6ea11fb61b 100644
121 ---- a/config/kernel-inode-create.m4
122 -+++ b/config/kernel-inode-create.m4
123 -@@ -1,7 +1,25 @@
124 --dnl #
125 --dnl # 3.6 API change
126 --dnl #
127 --AC_DEFUN([ZFS_AC_KERNEL_SRC_CREATE_FLAGS], [
128 -+AC_DEFUN([ZFS_AC_KERNEL_SRC_CREATE], [
129 -+ dnl #
130 -+ dnl # 5.12 API change that added the struct user_namespace* arg
131 -+ dnl # to the front of this function type's arg list.
132 -+ dnl #
133 -+ ZFS_LINUX_TEST_SRC([create_userns], [
134 -+ #include <linux/fs.h>
135 -+ #include <linux/sched.h>
136 -+
137 -+ int inode_create(struct user_namespace *userns,
138 -+ struct inode *inode ,struct dentry *dentry,
139 -+ umode_t umode, bool flag) { return 0; }
140 -+
141 -+ static const struct inode_operations
142 -+ iops __attribute__ ((unused)) = {
143 -+ .create = inode_create,
144 -+ };
145 -+ ],[])
146 -+
147 -+ dnl #
148 -+ dnl # 3.6 API change
149 -+ dnl #
150 - ZFS_LINUX_TEST_SRC([create_flags], [
151 - #include <linux/fs.h>
152 - #include <linux/sched.h>
153 -@@ -16,11 +34,20 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_CREATE_FLAGS], [
154 - ],[])
155 - ])
156 -
157 --AC_DEFUN([ZFS_AC_KERNEL_CREATE_FLAGS], [
158 -- AC_MSG_CHECKING([whether iops->create() passes flags])
159 -- ZFS_LINUX_TEST_RESULT([create_flags], [
160 -+AC_DEFUN([ZFS_AC_KERNEL_CREATE], [
161 -+ AC_MSG_CHECKING([whether iops->create() takes struct user_namespace*])
162 -+ ZFS_LINUX_TEST_RESULT([create_userns], [
163 - AC_MSG_RESULT(yes)
164 -+ AC_DEFINE(HAVE_IOPS_CREATE_USERNS, 1,
165 -+ [iops->create() takes struct user_namespace*])
166 - ],[
167 -- ZFS_LINUX_TEST_ERROR([iops->create()])
168 -+ AC_MSG_RESULT(no)
169 -+
170 -+ AC_MSG_CHECKING([whether iops->create() passes flags])
171 -+ ZFS_LINUX_TEST_RESULT([create_flags], [
172 -+ AC_MSG_RESULT(yes)
173 -+ ],[
174 -+ ZFS_LINUX_TEST_ERROR([iops->create()])
175 -+ ])
176 - ])
177 - ])
178 -diff --git a/config/kernel-inode-getattr.m4 b/config/kernel-inode-getattr.m4
179 -index 48391d66f8b..f62e82f5230 100644
180 ---- a/config/kernel-inode-getattr.m4
181 -+++ b/config/kernel-inode-getattr.m4
182 -@@ -1,8 +1,29 @@
183 --dnl #
184 --dnl # Linux 4.11 API
185 --dnl # See torvalds/linux@a528d35
186 --dnl #
187 - AC_DEFUN([ZFS_AC_KERNEL_SRC_INODE_GETATTR], [
188 -+ dnl #
189 -+ dnl # Linux 5.12 API
190 -+ dnl # The getattr I/O operations handler type was extended to require
191 -+ dnl # a struct user_namespace* as its first arg, to support idmapped
192 -+ dnl # mounts.
193 -+ dnl #
194 -+ ZFS_LINUX_TEST_SRC([inode_operations_getattr_userns], [
195 -+ #include <linux/fs.h>
196 -+
197 -+ int test_getattr(
198 -+ struct user_namespace *userns,
199 -+ const struct path *p, struct kstat *k,
200 -+ u32 request_mask, unsigned int query_flags)
201 -+ { return 0; }
202 -+
203 -+ static const struct inode_operations
204 -+ iops __attribute__ ((unused)) = {
205 -+ .getattr = test_getattr,
206 -+ };
207 -+ ],[])
208 -+
209 -+ dnl #
210 -+ dnl # Linux 4.11 API
211 -+ dnl # See torvalds/linux@a528d35
212 -+ dnl #
213 - ZFS_LINUX_TEST_SRC([inode_operations_getattr_path], [
214 - #include <linux/fs.h>
215 -
216 -@@ -33,21 +54,39 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_INODE_GETATTR], [
217 - ])
218 -
219 - AC_DEFUN([ZFS_AC_KERNEL_INODE_GETATTR], [
220 -- AC_MSG_CHECKING([whether iops->getattr() takes a path])
221 -- ZFS_LINUX_TEST_RESULT([inode_operations_getattr_path], [
222 -+ dnl #
223 -+ dnl # Kernel 5.12 test
224 -+ dnl #
225 -+ AC_MSG_CHECKING([whether iops->getattr() takes user_namespace])
226 -+ ZFS_LINUX_TEST_RESULT([inode_operations_getattr_userns], [
227 - AC_MSG_RESULT(yes)
228 -- AC_DEFINE(HAVE_PATH_IOPS_GETATTR, 1,
229 -- [iops->getattr() takes a path])
230 -+ AC_DEFINE(HAVE_USERNS_IOPS_GETATTR, 1,
231 -+ [iops->getattr() takes struct user_namespace*])
232 - ],[
233 - AC_MSG_RESULT(no)
234 -
235 -- AC_MSG_CHECKING([whether iops->getattr() takes a vfsmount])
236 -- ZFS_LINUX_TEST_RESULT([inode_operations_getattr_vfsmount], [
237 -+ dnl #
238 -+ dnl # Kernel 4.11 test
239 -+ dnl #
240 -+ AC_MSG_CHECKING([whether iops->getattr() takes a path])
241 -+ ZFS_LINUX_TEST_RESULT([inode_operations_getattr_path], [
242 - AC_MSG_RESULT(yes)
243 -- AC_DEFINE(HAVE_VFSMOUNT_IOPS_GETATTR, 1,
244 -- [iops->getattr() takes a vfsmount])
245 -+ AC_DEFINE(HAVE_PATH_IOPS_GETATTR, 1,
246 -+ [iops->getattr() takes a path])
247 - ],[
248 - AC_MSG_RESULT(no)
249 -+
250 -+ dnl #
251 -+ dnl # Kernel < 4.11 test
252 -+ dnl #
253 -+ AC_MSG_CHECKING([whether iops->getattr() takes a vfsmount])
254 -+ ZFS_LINUX_TEST_RESULT([inode_operations_getattr_vfsmount], [
255 -+ AC_MSG_RESULT(yes)
256 -+ AC_DEFINE(HAVE_VFSMOUNT_IOPS_GETATTR, 1,
257 -+ [iops->getattr() takes a vfsmount])
258 -+ ],[
259 -+ AC_MSG_RESULT(no)
260 -+ ])
261 - ])
262 - ])
263 - ])
264 -diff --git a/config/kernel-is_owner_or_cap.m4 b/config/kernel-is_owner_or_cap.m4
265 -index 3df6163da27..3c3c6ad2240 100644
266 ---- a/config/kernel-is_owner_or_cap.m4
267 -+++ b/config/kernel-is_owner_or_cap.m4
268 -@@ -11,13 +11,32 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_INODE_OWNER_OR_CAPABLE], [
269 - struct inode *ip = NULL;
270 - (void) inode_owner_or_capable(ip);
271 - ])
272 -+
273 -+ ZFS_LINUX_TEST_SRC([inode_owner_or_capable_idmapped], [
274 -+ #include <linux/fs.h>
275 -+ ],[
276 -+ struct inode *ip = NULL;
277 -+ (void) inode_owner_or_capable(&init_user_ns, ip);
278 -+ ])
279 - ])
280 -
281 - AC_DEFUN([ZFS_AC_KERNEL_INODE_OWNER_OR_CAPABLE], [
282 - AC_MSG_CHECKING([whether inode_owner_or_capable() exists])
283 - ZFS_LINUX_TEST_RESULT([inode_owner_or_capable], [
284 - AC_MSG_RESULT(yes)
285 -- ],[
286 -- ZFS_LINUX_TEST_ERROR([capability])
287 -+ AC_DEFINE(HAVE_INODE_OWNER_OR_CAPABLE, 1,
288 -+ [inode_owner_or_capable() exists])
289 -+ ], [
290 -+ AC_MSG_RESULT(no)
291 -+
292 -+ AC_MSG_CHECKING(
293 -+ [whether inode_owner_or_capable() takes user_ns])
294 -+ ZFS_LINUX_TEST_RESULT([inode_owner_or_capable_idmapped], [
295 -+ AC_MSG_RESULT(yes)
296 -+ AC_DEFINE(HAVE_INODE_OWNER_OR_CAPABLE_IDMAPPED, 1,
297 -+ [inode_owner_or_capable() takes user_ns])
298 -+ ],[
299 -+ ZFS_LINUX_TEST_ERROR([capability])
300 -+ ])
301 - ])
302 - ])
303 -diff --git a/config/kernel-mkdir-umode-t.m4 b/config/kernel-mkdir-umode-t.m4
304 -deleted file mode 100644
305 -index 19599670df3..00000000000
306 ---- a/config/kernel-mkdir-umode-t.m4
307 -+++ /dev/null
308 -@@ -1,32 +0,0 @@
309 --dnl #
310 --dnl # 3.3 API change
311 --dnl # The VFS .create, .mkdir and .mknod callbacks were updated to take a
312 --dnl # umode_t type rather than an int. The expectation is that any backport
313 --dnl # would also change all three prototypes. However, if it turns out that
314 --dnl # some distribution doesn't backport the whole thing this could be
315 --dnl # broken apart into three separate checks.
316 --dnl #
317 --AC_DEFUN([ZFS_AC_KERNEL_SRC_MKDIR_UMODE_T], [
318 -- ZFS_LINUX_TEST_SRC([inode_operations_mkdir], [
319 -- #include <linux/fs.h>
320 --
321 -- int mkdir(struct inode *inode, struct dentry *dentry,
322 -- umode_t umode) { return 0; }
323 --
324 -- static const struct inode_operations
325 -- iops __attribute__ ((unused)) = {
326 -- .mkdir = mkdir,
327 -- };
328 -- ],[])
329 --])
330 --
331 --AC_DEFUN([ZFS_AC_KERNEL_MKDIR_UMODE_T], [
332 -- AC_MSG_CHECKING([whether iops->create()/mkdir()/mknod() take umode_t])
333 -- ZFS_LINUX_TEST_RESULT([inode_operations_mkdir], [
334 -- AC_MSG_RESULT(yes)
335 -- AC_DEFINE(HAVE_MKDIR_UMODE_T, 1,
336 -- [iops->create()/mkdir()/mknod() take umode_t])
337 -- ],[
338 -- ZFS_LINUX_TEST_ERROR([mkdir()])
339 -- ])
340 --])
341 -diff --git a/config/kernel-mkdir.m4 b/config/kernel-mkdir.m4
342 -new file mode 100644
343 -index 00000000000..a162bcd880f
344 ---- /dev/null
345 -+++ b/config/kernel-mkdir.m4
346 -@@ -0,0 +1,65 @@
347 -+dnl #
348 -+dnl # Supported mkdir() interfaces checked newest to oldest.
349 -+dnl #
350 -+AC_DEFUN([ZFS_AC_KERNEL_SRC_MKDIR], [
351 -+ dnl #
352 -+ dnl # 5.12 API change
353 -+ dnl # The struct user_namespace arg was added as the first argument to
354 -+ dnl # mkdir()
355 -+ dnl #
356 -+ ZFS_LINUX_TEST_SRC([mkdir_user_namespace], [
357 -+ #include <linux/fs.h>
358 -+
359 -+ int mkdir(struct user_namespace *userns,
360 -+ struct inode *inode, struct dentry *dentry,
361 -+ umode_t umode) { return 0; }
362 -+
363 -+ static const struct inode_operations
364 -+ iops __attribute__ ((unused)) = {
365 -+ .mkdir = mkdir,
366 -+ };
367 -+ ],[])
368 -+
369 -+ dnl #
370 -+ dnl # 3.3 API change
371 -+ dnl # The VFS .create, .mkdir and .mknod callbacks were updated to take a
372 -+ dnl # umode_t type rather than an int. The expectation is that any backport
373 -+ dnl # would also change all three prototypes. However, if it turns out that
374 -+ dnl # some distribution doesn't backport the whole thing this could be
375 -+ dnl # broken apart into three separate checks.
376 -+ dnl #
377 -+ ZFS_LINUX_TEST_SRC([inode_operations_mkdir], [
378 -+ #include <linux/fs.h>
379 -+
380 -+ int mkdir(struct inode *inode, struct dentry *dentry,
381 -+ umode_t umode) { return 0; }
382 -+
383 -+ static const struct inode_operations
384 -+ iops __attribute__ ((unused)) = {
385 -+ .mkdir = mkdir,
386 -+ };
387 -+ ],[])
388 -+])
389 -+
390 -+AC_DEFUN([ZFS_AC_KERNEL_MKDIR], [
391 -+ dnl #
392 -+ dnl # 5.12 API change
393 -+ dnl # The struct user_namespace arg was added as the first argument to
394 -+ dnl # mkdir() of the iops structure.
395 -+ dnl #
396 -+ AC_MSG_CHECKING([whether iops->mkdir() takes struct user_namespace*])
397 -+ ZFS_LINUX_TEST_RESULT([mkdir_user_namespace], [
398 -+ AC_MSG_RESULT(yes)
399 -+ AC_DEFINE(HAVE_IOPS_MKDIR_USERNS, 1,
400 -+ [iops->mkdir() takes struct user_namespace*])
401 -+ ],[
402 -+ AC_MSG_CHECKING([whether iops->mkdir() takes umode_t])
403 -+ ZFS_LINUX_TEST_RESULT([inode_operations_mkdir], [
404 -+ AC_MSG_RESULT(yes)
405 -+ AC_DEFINE(HAVE_MKDIR_UMODE_T, 1,
406 -+ [iops->mkdir() takes umode_t])
407 -+ ],[
408 -+ ZFS_LINUX_TEST_ERROR([mkdir()])
409 -+ ])
410 -+ ])
411 -+])
412 -diff --git a/config/kernel-mknod.m4 b/config/kernel-mknod.m4
413 -new file mode 100644
414 -index 00000000000..ffe45106003
415 ---- /dev/null
416 -+++ b/config/kernel-mknod.m4
417 -@@ -0,0 +1,30 @@
418 -+AC_DEFUN([ZFS_AC_KERNEL_SRC_MKNOD], [
419 -+ dnl #
420 -+ dnl # 5.12 API change that added the struct user_namespace* arg
421 -+ dnl # to the front of this function type's arg list.
422 -+ dnl #
423 -+ ZFS_LINUX_TEST_SRC([mknod_userns], [
424 -+ #include <linux/fs.h>
425 -+ #include <linux/sched.h>
426 -+
427 -+ int tmp_mknod(struct user_namespace *userns,
428 -+ struct inode *inode ,struct dentry *dentry,
429 -+ umode_t u, dev_t d) { return 0; }
430 -+
431 -+ static const struct inode_operations
432 -+ iops __attribute__ ((unused)) = {
433 -+ .mknod = tmp_mknod,
434 -+ };
435 -+ ],[])
436 -+])
437 -+
438 -+AC_DEFUN([ZFS_AC_KERNEL_MKNOD], [
439 -+ AC_MSG_CHECKING([whether iops->mknod() takes struct user_namespace*])
440 -+ ZFS_LINUX_TEST_RESULT([mknod_userns], [
441 -+ AC_MSG_RESULT(yes)
442 -+ AC_DEFINE(HAVE_IOPS_MKNOD_USERNS, 1,
443 -+ [iops->mknod() takes struct user_namespace*])
444 -+ ],[
445 -+ AC_MSG_RESULT(no)
446 -+ ])
447 -+])
448 -diff --git a/config/kernel-rename.m4 b/config/kernel-rename.m4
449 -index f707391539d..31d199f33bb 100644
450 ---- a/config/kernel-rename.m4
451 -+++ b/config/kernel-rename.m4
452 -@@ -1,10 +1,10 @@
453 --dnl #
454 --dnl # 4.9 API change,
455 --dnl # iops->rename2() merged into iops->rename(), and iops->rename() now wants
456 --dnl # flags.
457 --dnl #
458 --AC_DEFUN([ZFS_AC_KERNEL_SRC_RENAME_WANTS_FLAGS], [
459 -- ZFS_LINUX_TEST_SRC([inode_operations_rename], [
460 -+AC_DEFUN([ZFS_AC_KERNEL_SRC_RENAME], [
461 -+ dnl #
462 -+ dnl # 4.9 API change,
463 -+ dnl # iops->rename2() merged into iops->rename(), and iops->rename() now wants
464 -+ dnl # flags.
465 -+ dnl #
466 -+ ZFS_LINUX_TEST_SRC([inode_operations_rename_flags], [
467 - #include <linux/fs.h>
468 - int rename_fn(struct inode *sip, struct dentry *sdp,
469 - struct inode *tip, struct dentry *tdp,
470 -@@ -15,15 +15,41 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_RENAME_WANTS_FLAGS], [
471 - .rename = rename_fn,
472 - };
473 - ],[])
474 -+
475 -+ dnl #
476 -+ dnl # 5.12 API change,
477 -+ dnl #
478 -+ dnl # Linux 5.12 introduced passing struct user_namespace* as the first argument
479 -+ dnl # of the rename() and other inode_operations members.
480 -+ dnl #
481 -+ ZFS_LINUX_TEST_SRC([inode_operations_rename_userns], [
482 -+ #include <linux/fs.h>
483 -+ int rename_fn(struct user_namespace *user_ns, struct inode *sip,
484 -+ struct dentry *sdp, struct inode *tip, struct dentry *tdp,
485 -+ unsigned int flags) { return 0; }
486 -+
487 -+ static const struct inode_operations
488 -+ iops __attribute__ ((unused)) = {
489 -+ .rename = rename_fn,
490 -+ };
491 -+ ],[])
492 - ])
493 -
494 --AC_DEFUN([ZFS_AC_KERNEL_RENAME_WANTS_FLAGS], [
495 -- AC_MSG_CHECKING([whether iops->rename() wants flags])
496 -- ZFS_LINUX_TEST_RESULT([inode_operations_rename], [
497 -+AC_DEFUN([ZFS_AC_KERNEL_RENAME], [
498 -+ AC_MSG_CHECKING([whether iops->rename() takes struct user_namespace*])
499 -+ ZFS_LINUX_TEST_RESULT([inode_operations_rename_userns], [
500 - AC_MSG_RESULT(yes)
501 -- AC_DEFINE(HAVE_RENAME_WANTS_FLAGS, 1,
502 -- [iops->rename() wants flags])
503 -+ AC_DEFINE(HAVE_IOPS_RENAME_USERNS, 1,
504 -+ [iops->rename() takes struct user_namespace*])
505 - ],[
506 - AC_MSG_RESULT(no)
507 -+
508 -+ ZFS_LINUX_TEST_RESULT([inode_operations_rename_flags], [
509 -+ AC_MSG_RESULT(yes)
510 -+ AC_DEFINE(HAVE_RENAME_WANTS_FLAGS, 1,
511 -+ [iops->rename() wants flags])
512 -+ ],[
513 -+ AC_MSG_RESULT(no)
514 -+ ])
515 - ])
516 - ])
517 -diff --git a/config/kernel-setattr-prepare.m4 b/config/kernel-setattr-prepare.m4
518 -index 45408c45c69..24245aa5344 100644
519 ---- a/config/kernel-setattr-prepare.m4
520 -+++ b/config/kernel-setattr-prepare.m4
521 -@@ -1,27 +1,52 @@
522 --dnl #
523 --dnl # 4.9 API change
524 --dnl # The inode_change_ok() function has been renamed setattr_prepare()
525 --dnl # and updated to take a dentry rather than an inode.
526 --dnl #
527 - AC_DEFUN([ZFS_AC_KERNEL_SRC_SETATTR_PREPARE], [
528 -+ dnl #
529 -+ dnl # 4.9 API change
530 -+ dnl # The inode_change_ok() function has been renamed setattr_prepare()
531 -+ dnl # and updated to take a dentry rather than an inode.
532 -+ dnl #
533 - ZFS_LINUX_TEST_SRC([setattr_prepare], [
534 - #include <linux/fs.h>
535 - ], [
536 - struct dentry *dentry = NULL;
537 - struct iattr *attr = NULL;
538 - int error __attribute__ ((unused)) =
539 -- setattr_prepare(dentry, attr);
540 -+ setattr_prepare(dentry, attr);
541 -+ ])
542 -+
543 -+ dnl #
544 -+ dnl # 5.12 API change
545 -+ dnl # The setattr_prepare() function has been changed to accept a new argument
546 -+ dnl # for struct user_namespace*
547 -+ dnl #
548 -+ ZFS_LINUX_TEST_SRC([setattr_prepare_userns], [
549 -+ #include <linux/fs.h>
550 -+ ], [
551 -+ struct dentry *dentry = NULL;
552 -+ struct iattr *attr = NULL;
553 -+ struct user_namespace *userns = NULL;
554 -+ int error __attribute__ ((unused)) =
555 -+ setattr_prepare(userns, dentry, attr);
556 - ])
557 - ])
558 -
559 - AC_DEFUN([ZFS_AC_KERNEL_SETATTR_PREPARE], [
560 -- AC_MSG_CHECKING([whether setattr_prepare() is available])
561 -- ZFS_LINUX_TEST_RESULT_SYMBOL([setattr_prepare],
562 -+ AC_MSG_CHECKING([whether setattr_prepare() is available and accepts struct user_namespace*])
563 -+ ZFS_LINUX_TEST_RESULT_SYMBOL([setattr_prepare_userns],
564 - [setattr_prepare], [fs/attr.c], [
565 - AC_MSG_RESULT(yes)
566 -- AC_DEFINE(HAVE_SETATTR_PREPARE, 1,
567 -- [setattr_prepare() is available])
568 -+ AC_DEFINE(HAVE_SETATTR_PREPARE_USERNS, 1,
569 -+ [setattr_prepare() accepts user_namespace])
570 - ], [
571 - AC_MSG_RESULT(no)
572 -+
573 -+ AC_MSG_CHECKING([whether setattr_prepare() is available, doesn't accept user_namespace])
574 -+ ZFS_LINUX_TEST_RESULT_SYMBOL([setattr_prepare],
575 -+ [setattr_prepare], [fs/attr.c], [
576 -+ AC_MSG_RESULT(yes)
577 -+ AC_DEFINE(HAVE_SETATTR_PREPARE_NO_USERNS, 1,
578 -+ [setattr_prepare() is available, doesn't accept user_namespace])
579 -+ ], [
580 -+ AC_MSG_RESULT(no)
581 -+ ])
582 - ])
583 - ])
584 -diff --git a/config/kernel-symlink.m4 b/config/kernel-symlink.m4
585 -new file mode 100644
586 -index 00000000000..d90366d04b7
587 ---- /dev/null
588 -+++ b/config/kernel-symlink.m4
589 -@@ -0,0 +1,30 @@
590 -+AC_DEFUN([ZFS_AC_KERNEL_SRC_SYMLINK], [
591 -+ dnl #
592 -+ dnl # 5.12 API change that added the struct user_namespace* arg
593 -+ dnl # to the front of this function type's arg list.
594 -+ dnl #
595 -+ ZFS_LINUX_TEST_SRC([symlink_userns], [
596 -+ #include <linux/fs.h>
597 -+ #include <linux/sched.h>
598 -+
599 -+ int tmp_symlink(struct user_namespace *userns,
600 -+ struct inode *inode ,struct dentry *dentry,
601 -+ const char *path) { return 0; }
602 -+
603 -+ static const struct inode_operations
604 -+ iops __attribute__ ((unused)) = {
605 -+ .symlink = tmp_symlink,
606 -+ };
607 -+ ],[])
608 -+])
609 -+
610 -+AC_DEFUN([ZFS_AC_KERNEL_SYMLINK], [
611 -+ AC_MSG_CHECKING([whether iops->symlink() takes struct user_namespace*])
612 -+ ZFS_LINUX_TEST_RESULT([symlink_userns], [
613 -+ AC_MSG_RESULT(yes)
614 -+ AC_DEFINE(HAVE_IOPS_SYMLINK_USERNS, 1,
615 -+ [iops->symlink() takes struct user_namespace*])
616 -+ ],[
617 -+ AC_MSG_RESULT(no)
618 -+ ])
619 -+])
620 -diff --git a/config/kernel-xattr-handler.m4 b/config/kernel-xattr-handler.m4
621 -index 137bf4a8aff..00b1e74a9cc 100644
622 ---- a/config/kernel-xattr-handler.m4
623 -+++ b/config/kernel-xattr-handler.m4
624 -@@ -152,6 +152,21 @@ dnl #
625 - dnl # Supported xattr handler set() interfaces checked newest to oldest.
626 - dnl #
627 - AC_DEFUN([ZFS_AC_KERNEL_SRC_XATTR_HANDLER_SET], [
628 -+ ZFS_LINUX_TEST_SRC([xattr_handler_set_userns], [
629 -+ #include <linux/xattr.h>
630 -+
631 -+ int set(const struct xattr_handler *handler,
632 -+ struct user_namespace *mnt_userns,
633 -+ struct dentry *dentry, struct inode *inode,
634 -+ const char *name, const void *buffer,
635 -+ size_t size, int flags)
636 -+ { return 0; }
637 -+ static const struct xattr_handler
638 -+ xops __attribute__ ((unused)) = {
639 -+ .set = set,
640 -+ };
641 -+ ],[])
642 -+
643 - ZFS_LINUX_TEST_SRC([xattr_handler_set_dentry_inode], [
644 - #include <linux/xattr.h>
645 -
646 -@@ -194,45 +209,58 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_XATTR_HANDLER_SET], [
647 -
648 - AC_DEFUN([ZFS_AC_KERNEL_XATTR_HANDLER_SET], [
649 - dnl #
650 -- dnl # 4.7 API change,
651 -- dnl # The xattr_handler->set() callback was changed to take both
652 -- dnl # dentry and inode.
653 -+ dnl # 5.12 API change,
654 -+ dnl # The xattr_handler->set() callback was changed to 8 arguments, and
655 -+ dnl # struct user_namespace* was inserted as arg #2
656 - dnl #
657 -- AC_MSG_CHECKING([whether xattr_handler->set() wants dentry and inode])
658 -- ZFS_LINUX_TEST_RESULT([xattr_handler_set_dentry_inode], [
659 -+ AC_MSG_CHECKING([whether xattr_handler->set() wants dentry, inode, and user_namespace])
660 -+ ZFS_LINUX_TEST_RESULT([xattr_handler_set_userns], [
661 - AC_MSG_RESULT(yes)
662 -- AC_DEFINE(HAVE_XATTR_SET_DENTRY_INODE, 1,
663 -- [xattr_handler->set() wants both dentry and inode])
664 -+ AC_DEFINE(HAVE_XATTR_SET_USERNS, 1,
665 -+ [xattr_handler->set() takes user_namespace])
666 - ],[
667 - dnl #
668 -- dnl # 4.4 API change,
669 -- dnl # The xattr_handler->set() callback was changed to take a
670 -- dnl # xattr_handler, and handler_flags argument was removed and
671 -- dnl # should be accessed by handler->flags.
672 -+ dnl # 4.7 API change,
673 -+ dnl # The xattr_handler->set() callback was changed to take both
674 -+ dnl # dentry and inode.
675 - dnl #
676 - AC_MSG_RESULT(no)
677 -- AC_MSG_CHECKING(
678 -- [whether xattr_handler->set() wants xattr_handler])
679 -- ZFS_LINUX_TEST_RESULT([xattr_handler_set_xattr_handler], [
680 -+ AC_MSG_CHECKING([whether xattr_handler->set() wants dentry and inode])
681 -+ ZFS_LINUX_TEST_RESULT([xattr_handler_set_dentry_inode], [
682 - AC_MSG_RESULT(yes)
683 -- AC_DEFINE(HAVE_XATTR_SET_HANDLER, 1,
684 -- [xattr_handler->set() wants xattr_handler])
685 -+ AC_DEFINE(HAVE_XATTR_SET_DENTRY_INODE, 1,
686 -+ [xattr_handler->set() wants both dentry and inode])
687 - ],[
688 - dnl #
689 -- dnl # 2.6.33 API change,
690 -- dnl # The xattr_handler->set() callback was changed
691 -- dnl # to take a dentry instead of an inode, and a
692 -- dnl # handler_flags argument was added.
693 -+ dnl # 4.4 API change,
694 -+ dnl # The xattr_handler->set() callback was changed to take a
695 -+ dnl # xattr_handler, and handler_flags argument was removed and
696 -+ dnl # should be accessed by handler->flags.
697 - dnl #
698 - AC_MSG_RESULT(no)
699 - AC_MSG_CHECKING(
700 -- [whether xattr_handler->set() wants dentry])
701 -- ZFS_LINUX_TEST_RESULT([xattr_handler_set_dentry], [
702 -+ [whether xattr_handler->set() wants xattr_handler])
703 -+ ZFS_LINUX_TEST_RESULT([xattr_handler_set_xattr_handler], [
704 - AC_MSG_RESULT(yes)
705 -- AC_DEFINE(HAVE_XATTR_SET_DENTRY, 1,
706 -- [xattr_handler->set() wants dentry])
707 -+ AC_DEFINE(HAVE_XATTR_SET_HANDLER, 1,
708 -+ [xattr_handler->set() wants xattr_handler])
709 - ],[
710 -- ZFS_LINUX_TEST_ERROR([xattr set()])
711 -+ dnl #
712 -+ dnl # 2.6.33 API change,
713 -+ dnl # The xattr_handler->set() callback was changed
714 -+ dnl # to take a dentry instead of an inode, and a
715 -+ dnl # handler_flags argument was added.
716 -+ dnl #
717 -+ AC_MSG_RESULT(no)
718 -+ AC_MSG_CHECKING(
719 -+ [whether xattr_handler->set() wants dentry])
720 -+ ZFS_LINUX_TEST_RESULT([xattr_handler_set_dentry], [
721 -+ AC_MSG_RESULT(yes)
722 -+ AC_DEFINE(HAVE_XATTR_SET_DENTRY, 1,
723 -+ [xattr_handler->set() wants dentry])
724 -+ ],[
725 -+ ZFS_LINUX_TEST_ERROR([xattr set()])
726 -+ ])
727 - ])
728 - ])
729 - ])
730 -diff --git a/config/kernel.m4 b/config/kernel.m4
731 -index 55620b3daa8..51c7fb926ec 100644
732 ---- a/config/kernel.m4
733 -+++ b/config/kernel.m4
734 -@@ -79,9 +79,9 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
735 - ZFS_AC_KERNEL_SRC_EVICT_INODE
736 - ZFS_AC_KERNEL_SRC_DIRTY_INODE
737 - ZFS_AC_KERNEL_SRC_SHRINKER
738 -- ZFS_AC_KERNEL_SRC_MKDIR_UMODE_T
739 -+ ZFS_AC_KERNEL_SRC_MKDIR
740 - ZFS_AC_KERNEL_SRC_LOOKUP_FLAGS
741 -- ZFS_AC_KERNEL_SRC_CREATE_FLAGS
742 -+ ZFS_AC_KERNEL_SRC_CREATE
743 - ZFS_AC_KERNEL_SRC_GET_LINK
744 - ZFS_AC_KERNEL_SRC_PUT_LINK
745 - ZFS_AC_KERNEL_SRC_TMPFILE
746 -@@ -115,7 +115,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
747 - ZFS_AC_KERNEL_SRC_KUIDGID_T
748 - ZFS_AC_KERNEL_SRC_KUID_HELPERS
749 - ZFS_AC_KERNEL_SRC_MODULE_PARAM_CALL_CONST
750 -- ZFS_AC_KERNEL_SRC_RENAME_WANTS_FLAGS
751 -+ ZFS_AC_KERNEL_SRC_RENAME
752 - ZFS_AC_KERNEL_SRC_CURRENT_TIME
753 - ZFS_AC_KERNEL_SRC_USERNS_CAPABILITIES
754 - ZFS_AC_KERNEL_SRC_IN_COMPAT_SYSCALL
755 -@@ -124,6 +124,9 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
756 - ZFS_AC_KERNEL_SRC_TOTALHIGH_PAGES
757 - ZFS_AC_KERNEL_SRC_KSTRTOUL
758 - ZFS_AC_KERNEL_SRC_PERCPU
759 -+ ZFS_AC_KERNEL_SRC_GENERIC_FILLATTR_USERNS
760 -+ ZFS_AC_KERNEL_SRC_MKNOD
761 -+ ZFS_AC_KERNEL_SRC_SYMLINK
762 -
763 - AC_MSG_CHECKING([for available kernel interfaces])
764 - ZFS_LINUX_TEST_COMPILE_ALL([kabi])
765 -@@ -176,9 +179,9 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
766 - ZFS_AC_KERNEL_EVICT_INODE
767 - ZFS_AC_KERNEL_DIRTY_INODE
768 - ZFS_AC_KERNEL_SHRINKER
769 -- ZFS_AC_KERNEL_MKDIR_UMODE_T
770 -+ ZFS_AC_KERNEL_MKDIR
771 - ZFS_AC_KERNEL_LOOKUP_FLAGS
772 -- ZFS_AC_KERNEL_CREATE_FLAGS
773 -+ ZFS_AC_KERNEL_CREATE
774 - ZFS_AC_KERNEL_GET_LINK
775 - ZFS_AC_KERNEL_PUT_LINK
776 - ZFS_AC_KERNEL_TMPFILE
777 -@@ -212,7 +215,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
778 - ZFS_AC_KERNEL_KUIDGID_T
779 - ZFS_AC_KERNEL_KUID_HELPERS
780 - ZFS_AC_KERNEL_MODULE_PARAM_CALL_CONST
781 -- ZFS_AC_KERNEL_RENAME_WANTS_FLAGS
782 -+ ZFS_AC_KERNEL_RENAME
783 - ZFS_AC_KERNEL_CURRENT_TIME
784 - ZFS_AC_KERNEL_USERNS_CAPABILITIES
785 - ZFS_AC_KERNEL_IN_COMPAT_SYSCALL
786 -@@ -221,6 +224,9 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
787 - ZFS_AC_KERNEL_TOTALHIGH_PAGES
788 - ZFS_AC_KERNEL_KSTRTOUL
789 - ZFS_AC_KERNEL_PERCPU
790 -+ ZFS_AC_KERNEL_GENERIC_FILLATTR_USERNS
791 -+ ZFS_AC_KERNEL_MKNOD
792 -+ ZFS_AC_KERNEL_SYMLINK
793 - ])
794 -
795 - dnl #
796 -diff --git a/include/os/linux/kernel/linux/vfs_compat.h b/include/os/linux/kernel/linux/vfs_compat.h
797 -index c35e80d31cd..91e908598fb 100644
798 ---- a/include/os/linux/kernel/linux/vfs_compat.h
799 -+++ b/include/os/linux/kernel/linux/vfs_compat.h
800 -@@ -343,7 +343,8 @@ static inline void zfs_gid_write(struct inode *ip, gid_t gid)
801 - /*
802 - * 4.9 API change
803 - */
804 --#ifndef HAVE_SETATTR_PREPARE
805 -+#if !(defined(HAVE_SETATTR_PREPARE_NO_USERNS) || \
806 -+ defined(HAVE_SETATTR_PREPARE_USERNS))
807 - static inline int
808 - setattr_prepare(struct dentry *dentry, struct iattr *ia)
809 - {
810 -@@ -389,6 +390,15 @@ func(const struct path *path, struct kstat *stat, u32 request_mask, \
811 - { \
812 - return (func##_impl(path, stat, request_mask, query_flags)); \
813 - }
814 -+#elif defined(HAVE_USERNS_IOPS_GETATTR)
815 -+#define ZPL_GETATTR_WRAPPER(func) \
816 -+static int \
817 -+func(struct user_namespace *user_ns, const struct path *path, \
818 -+ struct kstat *stat, u32 request_mask, unsigned int query_flags) \
819 -+{ \
820 -+ return (func##_impl(user_ns, path, stat, request_mask, \
821 -+ query_flags)); \
822 -+}
823 - #else
824 - #error
825 - #endif
826 -@@ -436,4 +446,16 @@ zpl_is_32bit_api(void)
827 - #endif
828 - }
829 -
830 -+/*
831 -+ * 5.12 API change
832 -+ * To support id-mapped mounts, generic_fillattr() was modified to
833 -+ * accept a new struct user_namespace* as its first arg.
834 -+ */
835 -+#ifdef HAVE_GENERIC_FILLATTR_USERNS
836 -+#define zpl_generic_fillattr(user_ns, ip, sp) \
837 -+ generic_fillattr(user_ns, ip, sp)
838 -+#else
839 -+#define zpl_generic_fillattr(user_ns, ip, sp) generic_fillattr(ip, sp)
840 -+#endif
841 -+
842 - #endif /* _ZFS_VFS_H */
843 -diff --git a/include/os/linux/kernel/linux/xattr_compat.h b/include/os/linux/kernel/linux/xattr_compat.h
844 -index 8348e99198a..54690727eab 100644
845 ---- a/include/os/linux/kernel/linux/xattr_compat.h
846 -+++ b/include/os/linux/kernel/linux/xattr_compat.h
847 -@@ -119,12 +119,27 @@ fn(struct dentry *dentry, const char *name, void *buffer, size_t size, \
848 - #error "Unsupported kernel"
849 - #endif
850 -
851 -+/*
852 -+ * 5.12 API change,
853 -+ * The xattr_handler->set() callback was changed to take the
854 -+ * struct user_namespace* as the first arg, to support idmapped
855 -+ * mounts.
856 -+ */
857 -+#if defined(HAVE_XATTR_SET_USERNS)
858 -+#define ZPL_XATTR_SET_WRAPPER(fn) \
859 -+static int \
860 -+fn(const struct xattr_handler *handler, struct user_namespace *user_ns, \
861 -+ struct dentry *dentry, struct inode *inode, const char *name, \
862 -+ const void *buffer, size_t size, int flags) \
863 -+{ \
864 -+ return (__ ## fn(inode, name, buffer, size, flags)); \
865 -+}
866 - /*
867 - * 4.7 API change,
868 - * The xattr_handler->set() callback was changed to take a both dentry and
869 - * inode, because the dentry might not be attached to an inode yet.
870 - */
871 --#if defined(HAVE_XATTR_SET_DENTRY_INODE)
872 -+#elif defined(HAVE_XATTR_SET_DENTRY_INODE)
873 - #define ZPL_XATTR_SET_WRAPPER(fn) \
874 - static int \
875 - fn(const struct xattr_handler *handler, struct dentry *dentry, \
876 -diff --git a/include/os/linux/zfs/sys/zfs_vnops_os.h b/include/os/linux/zfs/sys/zfs_vnops_os.h
877 -index 1c9cdf7bf8f..ba83f5dd83d 100644
878 ---- a/include/os/linux/zfs/sys/zfs_vnops_os.h
879 -+++ b/include/os/linux/zfs/sys/zfs_vnops_os.h
880 -@@ -56,7 +56,8 @@ extern int zfs_mkdir(znode_t *dzp, char *dirname, vattr_t *vap,
881 - extern int zfs_rmdir(znode_t *dzp, char *name, znode_t *cwd,
882 - cred_t *cr, int flags);
883 - extern int zfs_readdir(struct inode *ip, zpl_dir_context_t *ctx, cred_t *cr);
884 --extern int zfs_getattr_fast(struct inode *ip, struct kstat *sp);
885 -+extern int zfs_getattr_fast(struct user_namespace *, struct inode *ip,
886 -+ struct kstat *sp);
887 - extern int zfs_setattr(znode_t *zp, vattr_t *vap, int flag, cred_t *cr);
888 - extern int zfs_rename(znode_t *sdzp, char *snm, znode_t *tdzp,
889 - char *tnm, cred_t *cr, int flags);
890 -diff --git a/include/os/linux/zfs/sys/zpl.h b/include/os/linux/zfs/sys/zpl.h
891 -index b0bb9c29c0b..21825d1f378 100644
892 ---- a/include/os/linux/zfs/sys/zpl.h
893 -+++ b/include/os/linux/zfs/sys/zpl.h
894 -@@ -171,4 +171,22 @@ zpl_dir_emit_dots(struct file *file, zpl_dir_context_t *ctx)
895 - timespec_trunc(ts, (ip)->i_sb->s_time_gran)
896 - #endif
897 -
898 -+#if defined(HAVE_INODE_OWNER_OR_CAPABLE)
899 -+#define zpl_inode_owner_or_capable(ns, ip) inode_owner_or_capable(ip)
900 -+#elif defined(HAVE_INODE_OWNER_OR_CAPABLE_IDMAPPED)
901 -+#define zpl_inode_owner_or_capable(ns, ip) inode_owner_or_capable(ns, ip)
902 -+#else
903 -+#error "Unsupported kernel"
904 -+#endif
905 -+
906 -+#ifdef HAVE_SETATTR_PREPARE_USERNS
907 -+#define zpl_setattr_prepare(ns, dentry, ia) setattr_prepare(ns, dentry, ia)
908 -+#else
909 -+/*
910 -+ * Use kernel-provided version, or our own from
911 -+ * linux/vfs_compat.h
912 -+ */
913 -+#define zpl_setattr_prepare(ns, dentry, ia) setattr_prepare(dentry, ia)
914 -+#endif
915 -+
916 - #endif /* _SYS_ZPL_H */
917 -diff --git a/module/os/linux/zfs/policy.c b/module/os/linux/zfs/policy.c
918 -index 8780d7f6c70..bbccb2e572d 100644
919 ---- a/module/os/linux/zfs/policy.c
920 -+++ b/module/os/linux/zfs/policy.c
921 -@@ -124,7 +124,7 @@ secpolicy_vnode_any_access(const cred_t *cr, struct inode *ip, uid_t owner)
922 - if (crgetfsuid(cr) == owner)
923 - return (0);
924 -
925 -- if (inode_owner_or_capable(ip))
926 -+ if (zpl_inode_owner_or_capable(kcred->user_ns, ip))
927 - return (0);
928 -
929 - #if defined(CONFIG_USER_NS)
930 -diff --git a/module/os/linux/zfs/zfs_vnops_os.c b/module/os/linux/zfs/zfs_vnops_os.c
931 -index 7484d651c1f..ce0701763fd 100644
932 ---- a/module/os/linux/zfs/zfs_vnops_os.c
933 -+++ b/module/os/linux/zfs/zfs_vnops_os.c
934 -@@ -1907,7 +1907,8 @@ zfs_readdir(struct inode *ip, zpl_dir_context_t *ctx, cred_t *cr)
935 - */
936 - /* ARGSUSED */
937 - int
938 --zfs_getattr_fast(struct inode *ip, struct kstat *sp)
939 -+zfs_getattr_fast(struct user_namespace *user_ns, struct inode *ip,
940 -+ struct kstat *sp)
941 - {
942 - znode_t *zp = ITOZ(ip);
943 - zfsvfs_t *zfsvfs = ITOZSB(ip);
944 -@@ -1919,7 +1920,7 @@ zfs_getattr_fast(struct inode *ip, struct kstat *sp)
945 -
946 - mutex_enter(&zp->z_lock);
947 -
948 -- generic_fillattr(ip, sp);
949 -+ zpl_generic_fillattr(user_ns, ip, sp);
950 - /*
951 - * +1 link count for root inode with visible '.zfs' directory.
952 - */
953 -diff --git a/module/os/linux/zfs/zpl_ctldir.c b/module/os/linux/zfs/zpl_ctldir.c
954 -index e6420f19ed8..9b526afd000 100644
955 ---- a/module/os/linux/zfs/zpl_ctldir.c
956 -+++ b/module/os/linux/zfs/zpl_ctldir.c
957 -@@ -101,12 +101,22 @@ zpl_root_readdir(struct file *filp, void *dirent, filldir_t filldir)
958 - */
959 - /* ARGSUSED */
960 - static int
961 -+#ifdef HAVE_USERNS_IOPS_GETATTR
962 -+zpl_root_getattr_impl(struct user_namespace *user_ns,
963 -+ const struct path *path, struct kstat *stat, u32 request_mask,
964 -+ unsigned int query_flags)
965 -+#else
966 - zpl_root_getattr_impl(const struct path *path, struct kstat *stat,
967 - u32 request_mask, unsigned int query_flags)
968 -+#endif
969 - {
970 - struct inode *ip = path->dentry->d_inode;
971 -
972 -+#if defined(HAVE_GENERIC_FILLATTR_USERNS) && defined(HAVE_USERNS_IOPS_GETATTR)
973 -+ generic_fillattr(user_ns, ip, stat);
974 -+#else
975 - generic_fillattr(ip, stat);
976 -+#endif
977 - stat->atime = current_time(ip);
978 -
979 - return (0);
980 -@@ -290,8 +300,14 @@ zpl_snapdir_readdir(struct file *filp, void *dirent, filldir_t filldir)
981 - #endif /* !HAVE_VFS_ITERATE && !HAVE_VFS_ITERATE_SHARED */
982 -
983 - static int
984 -+#ifdef HAVE_IOPS_RENAME_USERNS
985 -+zpl_snapdir_rename2(struct user_namespace *user_ns, struct inode *sdip,
986 -+ struct dentry *sdentry, struct inode *tdip, struct dentry *tdentry,
987 -+ unsigned int flags)
988 -+#else
989 - zpl_snapdir_rename2(struct inode *sdip, struct dentry *sdentry,
990 - struct inode *tdip, struct dentry *tdentry, unsigned int flags)
991 -+#endif
992 - {
993 - cred_t *cr = CRED();
994 - int error;
995 -@@ -309,7 +325,7 @@ zpl_snapdir_rename2(struct inode *sdip, struct dentry *sdentry,
996 - return (error);
997 - }
998 -
999 --#ifndef HAVE_RENAME_WANTS_FLAGS
1000 -+#if !defined(HAVE_RENAME_WANTS_FLAGS) && !defined(HAVE_IOPS_RENAME_USERNS)
1001 - static int
1002 - zpl_snapdir_rename(struct inode *sdip, struct dentry *sdentry,
1003 - struct inode *tdip, struct dentry *tdentry)
1004 -@@ -333,7 +349,12 @@ zpl_snapdir_rmdir(struct inode *dip, struct dentry *dentry)
1005 - }
1006 -
1007 - static int
1008 -+#ifdef HAVE_IOPS_MKDIR_USERNS
1009 -+zpl_snapdir_mkdir(struct user_namespace *user_ns, struct inode *dip,
1010 -+ struct dentry *dentry, umode_t mode)
1011 -+#else
1012 - zpl_snapdir_mkdir(struct inode *dip, struct dentry *dentry, umode_t mode)
1013 -+#endif
1014 - {
1015 - cred_t *cr = CRED();
1016 - vattr_t *vap;
1017 -@@ -363,14 +384,24 @@ zpl_snapdir_mkdir(struct inode *dip, struct dentry *dentry, umode_t mode)
1018 - */
1019 - /* ARGSUSED */
1020 - static int
1021 -+#ifdef HAVE_USERNS_IOPS_GETATTR
1022 -+zpl_snapdir_getattr_impl(struct user_namespace *user_ns,
1023 -+ const struct path *path, struct kstat *stat, u32 request_mask,
1024 -+ unsigned int query_flags)
1025 -+#else
1026 - zpl_snapdir_getattr_impl(const struct path *path, struct kstat *stat,
1027 - u32 request_mask, unsigned int query_flags)
1028 -+#endif
1029 - {
1030 - struct inode *ip = path->dentry->d_inode;
1031 - zfsvfs_t *zfsvfs = ITOZSB(ip);
1032 -
1033 - ZPL_ENTER(zfsvfs);
1034 -+#if defined(HAVE_GENERIC_FILLATTR_USERNS) && defined(HAVE_USERNS_IOPS_GETATTR)
1035 -+ generic_fillattr(user_ns, ip, stat);
1036 -+#else
1037 - generic_fillattr(ip, stat);
1038 -+#endif
1039 -
1040 - stat->nlink = stat->size = 2;
1041 - stat->ctime = stat->mtime = dmu_objset_snap_cmtime(zfsvfs->z_os);
1042 -@@ -408,7 +439,7 @@ const struct file_operations zpl_fops_snapdir = {
1043 - const struct inode_operations zpl_ops_snapdir = {
1044 - .lookup = zpl_snapdir_lookup,
1045 - .getattr = zpl_snapdir_getattr,
1046 --#ifdef HAVE_RENAME_WANTS_FLAGS
1047 -+#if defined(HAVE_RENAME_WANTS_FLAGS) || defined(HAVE_IOPS_RENAME_USERNS)
1048 - .rename = zpl_snapdir_rename2,
1049 - #else
1050 - .rename = zpl_snapdir_rename,
1051 -@@ -495,8 +526,14 @@ zpl_shares_readdir(struct file *filp, void *dirent, filldir_t filldir)
1052 -
1053 - /* ARGSUSED */
1054 - static int
1055 -+#ifdef HAVE_USERNS_IOPS_GETATTR
1056 -+zpl_shares_getattr_impl(struct user_namespace *user_ns,
1057 -+ const struct path *path, struct kstat *stat, u32 request_mask,
1058 -+ unsigned int query_flags)
1059 -+#else
1060 - zpl_shares_getattr_impl(const struct path *path, struct kstat *stat,
1061 - u32 request_mask, unsigned int query_flags)
1062 -+#endif
1063 - {
1064 - struct inode *ip = path->dentry->d_inode;
1065 - zfsvfs_t *zfsvfs = ITOZSB(ip);
1066 -@@ -506,7 +543,11 @@ zpl_shares_getattr_impl(const struct path *path, struct kstat *stat,
1067 - ZPL_ENTER(zfsvfs);
1068 -
1069 - if (zfsvfs->z_shares_dir == 0) {
1070 -+#if defined(HAVE_GENERIC_FILLATTR_USERNS) && defined(HAVE_USERNS_IOPS_GETATTR)
1071 -+ generic_fillattr(user_ns, path->dentry->d_inode, stat);
1072 -+#else
1073 - generic_fillattr(path->dentry->d_inode, stat);
1074 -+#endif
1075 - stat->nlink = stat->size = 2;
1076 - stat->atime = current_time(ip);
1077 - ZPL_EXIT(zfsvfs);
1078 -@@ -515,7 +556,11 @@ zpl_shares_getattr_impl(const struct path *path, struct kstat *stat,
1079 -
1080 - error = -zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &dzp);
1081 - if (error == 0) {
1082 -- error = -zfs_getattr_fast(ZTOI(dzp), stat);
1083 -+#if defined(HAVE_GENERIC_FILLATTR_USERNS) && defined(HAVE_USERNS_IOPS_GETATTR)
1084 -+ error = -zfs_getattr_fast(user_ns, ZTOI(dzp), stat);
1085 -+#else
1086 -+ error = -zfs_getattr_fast(kcred->user_ns, ZTOI(dzp), stat);
1087 -+#endif
1088 - iput(ZTOI(dzp));
1089 - }
1090 -
1091 -diff --git a/module/os/linux/zfs/zpl_file.c b/module/os/linux/zfs/zpl_file.c
1092 -index 80762f9669b..08bf97ff338 100644
1093 ---- a/module/os/linux/zfs/zpl_file.c
1094 -+++ b/module/os/linux/zfs/zpl_file.c
1095 -@@ -869,7 +869,7 @@ __zpl_ioctl_setflags(struct inode *ip, uint32_t ioctl_flags, xvattr_t *xva)
1096 - !capable(CAP_LINUX_IMMUTABLE))
1097 - return (-EACCES);
1098 -
1099 -- if (!inode_owner_or_capable(ip))
1100 -+ if (!zpl_inode_owner_or_capable(kcred->user_ns, ip))
1101 - return (-EACCES);
1102 -
1103 - xva_init(xva);
1104 -diff --git a/module/os/linux/zfs/zpl_inode.c b/module/os/linux/zfs/zpl_inode.c
1105 -index f336fbb1272..364b9fbef24 100644
1106 ---- a/module/os/linux/zfs/zpl_inode.c
1107 -+++ b/module/os/linux/zfs/zpl_inode.c
1108 -@@ -128,7 +128,12 @@ zpl_vap_init(vattr_t *vap, struct inode *dir, umode_t mode, cred_t *cr)
1109 - }
1110 -
1111 - static int
1112 -+#ifdef HAVE_IOPS_CREATE_USERNS
1113 -+zpl_create(struct user_namespace *user_ns, struct inode *dir,
1114 -+ struct dentry *dentry, umode_t mode, bool flag)
1115 -+#else
1116 - zpl_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool flag)
1117 -+#endif
1118 - {
1119 - cred_t *cr = CRED();
1120 - znode_t *zp;
1121 -@@ -163,7 +168,12 @@ zpl_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool flag)
1122 - }
1123 -
1124 - static int
1125 -+#ifdef HAVE_IOPS_MKNOD_USERNS
1126 -+zpl_mknod(struct user_namespace *user_ns, struct inode *dir,
1127 -+ struct dentry *dentry, umode_t mode,
1128 -+#else
1129 - zpl_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
1130 -+#endif
1131 - dev_t rdev)
1132 - {
1133 - cred_t *cr = CRED();
1134 -@@ -278,7 +288,12 @@ zpl_unlink(struct inode *dir, struct dentry *dentry)
1135 - }
1136 -
1137 - static int
1138 -+#ifdef HAVE_IOPS_MKDIR_USERNS
1139 -+zpl_mkdir(struct user_namespace *user_ns, struct inode *dir,
1140 -+ struct dentry *dentry, umode_t mode)
1141 -+#else
1142 - zpl_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
1143 -+#endif
1144 - {
1145 - cred_t *cr = CRED();
1146 - vattr_t *vap;
1147 -@@ -338,8 +353,14 @@ zpl_rmdir(struct inode *dir, struct dentry *dentry)
1148 - }
1149 -
1150 - static int
1151 -+#ifdef HAVE_USERNS_IOPS_GETATTR
1152 -+zpl_getattr_impl(struct user_namespace *user_ns,
1153 -+ const struct path *path, struct kstat *stat, u32 request_mask,
1154 -+ unsigned int query_flags)
1155 -+#else
1156 - zpl_getattr_impl(const struct path *path, struct kstat *stat, u32 request_mask,
1157 - unsigned int query_flags)
1158 -+#endif
1159 - {
1160 - int error;
1161 - fstrans_cookie_t cookie;
1162 -@@ -350,7 +371,11 @@ zpl_getattr_impl(const struct path *path, struct kstat *stat, u32 request_mask,
1163 - * XXX request_mask and query_flags currently ignored.
1164 - */
1165 -
1166 -- error = -zfs_getattr_fast(path->dentry->d_inode, stat);
1167 -+#ifdef HAVE_USERNS_IOPS_GETATTR
1168 -+ error = -zfs_getattr_fast(user_ns, path->dentry->d_inode, stat);
1169 -+#else
1170 -+ error = -zfs_getattr_fast(kcred->user_ns, path->dentry->d_inode, stat);
1171 -+#endif
1172 - spl_fstrans_unmark(cookie);
1173 - ASSERT3S(error, <=, 0);
1174 -
1175 -@@ -359,7 +384,12 @@ zpl_getattr_impl(const struct path *path, struct kstat *stat, u32 request_mask,
1176 - ZPL_GETATTR_WRAPPER(zpl_getattr);
1177 -
1178 - static int
1179 -+#ifdef HAVE_SETATTR_PREPARE_USERNS
1180 -+zpl_setattr(struct user_namespace *user_ns, struct dentry *dentry,
1181 -+ struct iattr *ia)
1182 -+#else
1183 - zpl_setattr(struct dentry *dentry, struct iattr *ia)
1184 -+#endif
1185 - {
1186 - struct inode *ip = dentry->d_inode;
1187 - cred_t *cr = CRED();
1188 -@@ -367,7 +397,7 @@ zpl_setattr(struct dentry *dentry, struct iattr *ia)
1189 - int error;
1190 - fstrans_cookie_t cookie;
1191 -
1192 -- error = setattr_prepare(dentry, ia);
1193 -+ error = zpl_setattr_prepare(kcred->user_ns, dentry, ia);
1194 - if (error)
1195 - return (error);
1196 -
1197 -@@ -399,8 +429,14 @@ zpl_setattr(struct dentry *dentry, struct iattr *ia)
1198 - }
1199 -
1200 - static int
1201 -+#ifdef HAVE_IOPS_RENAME_USERNS
1202 -+zpl_rename2(struct user_namespace *user_ns, struct inode *sdip,
1203 -+ struct dentry *sdentry, struct inode *tdip, struct dentry *tdentry,
1204 -+ unsigned int flags)
1205 -+#else
1206 - zpl_rename2(struct inode *sdip, struct dentry *sdentry,
1207 - struct inode *tdip, struct dentry *tdentry, unsigned int flags)
1208 -+#endif
1209 - {
1210 - cred_t *cr = CRED();
1211 - int error;
1212 -@@ -421,7 +457,7 @@ zpl_rename2(struct inode *sdip, struct dentry *sdentry,
1213 - return (error);
1214 - }
1215 -
1216 --#ifndef HAVE_RENAME_WANTS_FLAGS
1217 -+#if !defined(HAVE_RENAME_WANTS_FLAGS) && !defined(HAVE_IOPS_RENAME_USERNS)
1218 - static int
1219 - zpl_rename(struct inode *sdip, struct dentry *sdentry,
1220 - struct inode *tdip, struct dentry *tdentry)
1221 -@@ -431,7 +467,12 @@ zpl_rename(struct inode *sdip, struct dentry *sdentry,
1222 - #endif
1223 -
1224 - static int
1225 -+#ifdef HAVE_IOPS_SYMLINK_USERNS
1226 -+zpl_symlink(struct user_namespace *user_ns, struct inode *dir,
1227 -+ struct dentry *dentry, const char *name)
1228 -+#else
1229 - zpl_symlink(struct inode *dir, struct dentry *dentry, const char *name)
1230 -+#endif
1231 - {
1232 - cred_t *cr = CRED();
1233 - vattr_t *vap;
1234 -@@ -677,7 +718,7 @@ const struct inode_operations zpl_dir_inode_operations = {
1235 - .mkdir = zpl_mkdir,
1236 - .rmdir = zpl_rmdir,
1237 - .mknod = zpl_mknod,
1238 --#ifdef HAVE_RENAME_WANTS_FLAGS
1239 -+#if defined(HAVE_RENAME_WANTS_FLAGS) || defined(HAVE_IOPS_RENAME_USERNS)
1240 - .rename = zpl_rename2,
1241 - #else
1242 - .rename = zpl_rename,
1243 -diff --git a/module/os/linux/zfs/zpl_xattr.c b/module/os/linux/zfs/zpl_xattr.c
1244 -index 1ec3dae2bb8..5e35f90df85 100644
1245 ---- a/module/os/linux/zfs/zpl_xattr.c
1246 -+++ b/module/os/linux/zfs/zpl_xattr.c
1247 -@@ -1233,7 +1233,7 @@ __zpl_xattr_acl_set_access(struct inode *ip, const char *name,
1248 - if (ITOZSB(ip)->z_acl_type != ZFS_ACLTYPE_POSIX)
1249 - return (-EOPNOTSUPP);
1250 -
1251 -- if (!inode_owner_or_capable(ip))
1252 -+ if (!zpl_inode_owner_or_capable(kcred->user_ns, ip))
1253 - return (-EPERM);
1254 -
1255 - if (value) {
1256 -@@ -1273,7 +1273,7 @@ __zpl_xattr_acl_set_default(struct inode *ip, const char *name,
1257 - if (ITOZSB(ip)->z_acl_type != ZFS_ACLTYPE_POSIX)
1258 - return (-EOPNOTSUPP);
1259 -
1260 -- if (!inode_owner_or_capable(ip))
1261 -+ if (!zpl_inode_owner_or_capable(kcred->user_ns, ip))
1262 - return (-EPERM);
1263 -
1264 - if (value) {
1265
1266 diff --git a/sys-fs/zfs-kmod/zfs-kmod-2.0.4-r1.ebuild b/sys-fs/zfs-kmod/zfs-kmod-2.0.4-r1.ebuild
1267 index 636c4c76d07..18391c3ffa9 100644
1268 --- a/sys-fs/zfs-kmod/zfs-kmod-2.0.4-r1.ebuild
1269 +++ b/sys-fs/zfs-kmod/zfs-kmod-2.0.4-r1.ebuild
1270 @@ -13,7 +13,8 @@ if [[ ${PV} == "9999" ]]; then
1271 EGIT_REPO_URI="https://github.com/openzfs/zfs.git"
1272 else
1273 MY_PV="${PV/_rc/-rc}"
1274 - SRC_URI="https://github.com/openzfs/zfs/releases/download/zfs-${MY_PV}/zfs-${MY_PV}.tar.gz"
1275 + SRC_URI="https://github.com/openzfs/zfs/releases/download/zfs-${MY_PV}/zfs-${MY_PV}.tar.gz
1276 + https://github.com/openzfs/zfs/commit/f315d9a3ff3cc0b81c99dd9be5878a55d2e98d8e.patch -> zfs-8.0.4_5.12_compat_idmapped_mounts.patch"
1277 KEYWORDS="~amd64 ~arm64 ~ppc64"
1278 S="${WORKDIR}/zfs-${PV%_rc?}"
1279 ZFS_KERNEL_COMPAT="5.12"
1280 @@ -54,7 +55,7 @@ pkg_pretend() {
1281 }
1282
1283 PATCHES=(
1284 - "${FILESDIR}"/zfs-8.0.4_5.12_compat_idmapped_mounts.patch
1285 + "${DISTDIR}"/zfs-8.0.4_5.12_compat_idmapped_mounts.patch
1286 "${FILESDIR}"/zfs-8.0.4_5.12_compat_bio_max_segs.patch
1287 "${FILESDIR}"/zfs-8.0.4_5.12_compat_tmpfile.patch
1288 "${FILESDIR}"/zfs-8.0.4_5.12_compat_userns.patch