Skip to content

Commit ac068b1

Browse files
committed
Implement rename() update for 5.12 user_namespace API change
Implement configure code that determines if the struct user_namespace* is required as the first argument to rename() in struct inode_operations, and if so, update zpl_rename implementation to match. Signed-off-by: Coleman Kane <[email protected]>
1 parent 99488eb commit ac068b1

File tree

4 files changed

+56
-18
lines changed

4 files changed

+56
-18
lines changed

config/kernel-rename.m4

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
dnl #
2-
dnl # 4.9 API change,
3-
dnl # iops->rename2() merged into iops->rename(), and iops->rename() now wants
4-
dnl # flags.
5-
dnl #
6-
AC_DEFUN([ZFS_AC_KERNEL_SRC_RENAME_WANTS_FLAGS], [
7-
ZFS_LINUX_TEST_SRC([inode_operations_rename], [
1+
AC_DEFUN([ZFS_AC_KERNEL_SRC_RENAME], [
2+
dnl #
3+
dnl # 4.9 API change,
4+
dnl # iops->rename2() merged into iops->rename(), and iops->rename() now wants
5+
dnl # flags.
6+
dnl #
7+
ZFS_LINUX_TEST_SRC([inode_operations_rename_flags], [
88
#include <linux/fs.h>
99
int rename_fn(struct inode *sip, struct dentry *sdp,
1010
struct inode *tip, struct dentry *tdp,
@@ -15,15 +15,41 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_RENAME_WANTS_FLAGS], [
1515
.rename = rename_fn,
1616
};
1717
],[])
18+
19+
dnl #
20+
dnl # 5.12 API change,
21+
dnl #
22+
dnl # Linux 5.12 introduced passing struct user_namespace* as the first argument
23+
dnl # of the rename() and other inode_operations members.
24+
dnl #
25+
ZFS_LINUX_TEST_SRC([inode_operations_rename_userns], [
26+
#include <linux/fs.h>
27+
int rename_fn(struct user_namespace *user_ns, struct inode *sip,
28+
struct dentry *sdp, struct inode *tip, struct dentry *tdp,
29+
unsigned int flags) { return 0; }
30+
31+
static const struct inode_operations
32+
iops __attribute__ ((unused)) = {
33+
.rename = rename_fn,
34+
};
35+
],[])
1836
])
1937

20-
AC_DEFUN([ZFS_AC_KERNEL_RENAME_WANTS_FLAGS], [
21-
AC_MSG_CHECKING([whether iops->rename() wants flags])
22-
ZFS_LINUX_TEST_RESULT([inode_operations_rename], [
38+
AC_DEFUN([ZFS_AC_KERNEL_RENAME], [
39+
AC_MSG_CHECKING([whether iops->rename() takes struct user_namespace*])
40+
ZFS_LINUX_TEST_RESULT([inode_operations_rename_userns], [
2341
AC_MSG_RESULT(yes)
24-
AC_DEFINE(HAVE_RENAME_WANTS_FLAGS, 1,
25-
[iops->rename() wants flags])
42+
AC_DEFINE(HAVE_IOPS_RENAME_USERNS, 1,
43+
[iops->rename() takes struct user_namespace*])
2644
],[
2745
AC_MSG_RESULT(no)
46+
47+
ZFS_LINUX_TEST_RESULT([inode_operations_rename_flags], [
48+
AC_MSG_RESULT(yes)
49+
AC_DEFINE(HAVE_RENAME_WANTS_FLAGS, 1,
50+
[iops->rename() wants flags])
51+
],[
52+
AC_MSG_RESULT(no)
53+
])
2854
])
2955
])

config/kernel.m4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
115115
ZFS_AC_KERNEL_SRC_KUIDGID_T
116116
ZFS_AC_KERNEL_SRC_KUID_HELPERS
117117
ZFS_AC_KERNEL_SRC_MODULE_PARAM_CALL_CONST
118-
ZFS_AC_KERNEL_SRC_RENAME_WANTS_FLAGS
118+
ZFS_AC_KERNEL_SRC_RENAME
119119
ZFS_AC_KERNEL_SRC_CURRENT_TIME
120120
ZFS_AC_KERNEL_SRC_USERNS_CAPABILITIES
121121
ZFS_AC_KERNEL_SRC_IN_COMPAT_SYSCALL
@@ -216,7 +216,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
216216
ZFS_AC_KERNEL_KUIDGID_T
217217
ZFS_AC_KERNEL_KUID_HELPERS
218218
ZFS_AC_KERNEL_MODULE_PARAM_CALL_CONST
219-
ZFS_AC_KERNEL_RENAME_WANTS_FLAGS
219+
ZFS_AC_KERNEL_RENAME
220220
ZFS_AC_KERNEL_CURRENT_TIME
221221
ZFS_AC_KERNEL_USERNS_CAPABILITIES
222222
ZFS_AC_KERNEL_IN_COMPAT_SYSCALL

module/os/linux/zfs/zpl_ctldir.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,14 @@ zpl_snapdir_readdir(struct file *filp, void *dirent, filldir_t filldir)
300300
#endif /* !HAVE_VFS_ITERATE && !HAVE_VFS_ITERATE_SHARED */
301301

302302
static int
303+
#ifdef HAVE_IOPS_RENAME_USERNS
304+
zpl_snapdir_rename2(struct user_namespace *user_ns, struct inode *sdip,
305+
struct dentry *sdentry, struct inode *tdip, struct dentry *tdentry,
306+
unsigned int flags)
307+
#else
303308
zpl_snapdir_rename2(struct inode *sdip, struct dentry *sdentry,
304309
struct inode *tdip, struct dentry *tdentry, unsigned int flags)
310+
#endif
305311
{
306312
cred_t *cr = CRED();
307313
int error;
@@ -319,7 +325,7 @@ zpl_snapdir_rename2(struct inode *sdip, struct dentry *sdentry,
319325
return (error);
320326
}
321327

322-
#ifndef HAVE_RENAME_WANTS_FLAGS
328+
#if !defined(HAVE_RENAME_WANTS_FLAGS) && !defined(HAVE_IOPS_RENAME_USERNS)
323329
static int
324330
zpl_snapdir_rename(struct inode *sdip, struct dentry *sdentry,
325331
struct inode *tdip, struct dentry *tdentry)
@@ -433,7 +439,7 @@ const struct file_operations zpl_fops_snapdir = {
433439
const struct inode_operations zpl_ops_snapdir = {
434440
.lookup = zpl_snapdir_lookup,
435441
.getattr = zpl_snapdir_getattr,
436-
#ifdef HAVE_RENAME_WANTS_FLAGS
442+
#if defined(HAVE_RENAME_WANTS_FLAGS) || defined(HAVE_IOPS_RENAME_USERNS)
437443
.rename = zpl_snapdir_rename2,
438444
#else
439445
.rename = zpl_snapdir_rename,

module/os/linux/zfs/zpl_inode.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,14 @@ zpl_setattr(struct dentry *dentry, struct iattr *ia)
429429
}
430430

431431
static int
432+
#ifdef HAVE_IOPS_RENAME_USERNS
433+
zpl_rename2(struct user_namespace *user_ns, struct inode *sdip,
434+
struct dentry *sdentry, struct inode *tdip, struct dentry *tdentry,
435+
unsigned int flags)
436+
#else
432437
zpl_rename2(struct inode *sdip, struct dentry *sdentry,
433438
struct inode *tdip, struct dentry *tdentry, unsigned int flags)
439+
#endif
434440
{
435441
cred_t *cr = CRED();
436442
int error;
@@ -451,7 +457,7 @@ zpl_rename2(struct inode *sdip, struct dentry *sdentry,
451457
return (error);
452458
}
453459

454-
#ifndef HAVE_RENAME_WANTS_FLAGS
460+
#if !defined(HAVE_RENAME_WANTS_FLAGS) && !defined(HAVE_IOPS_RENAME_USERNS)
455461
static int
456462
zpl_rename(struct inode *sdip, struct dentry *sdentry,
457463
struct inode *tdip, struct dentry *tdentry)
@@ -712,7 +718,7 @@ const struct inode_operations zpl_dir_inode_operations = {
712718
.mkdir = zpl_mkdir,
713719
.rmdir = zpl_rmdir,
714720
.mknod = zpl_mknod,
715-
#ifdef HAVE_RENAME_WANTS_FLAGS
721+
#if defined(HAVE_RENAME_WANTS_FLAGS) || defined(HAVE_IOPS_RENAME_USERNS)
716722
.rename = zpl_rename2,
717723
#else
718724
.rename = zpl_rename,

0 commit comments

Comments
 (0)