xref: /freebsd/sys/contrib/openzfs/config/kernel-rename.m4 (revision 9f27341c336aa12f6c7163c17e646e76c813b689)
1AC_DEFUN([ZFS_AC_KERNEL_SRC_RENAME], [
2	dnl #
3	dnl # 3.9 (to 4.9) API change,
4	dnl #
5	dnl # A new version of iops->rename() was added (rename2) that takes a flag
6	dnl # argument (to support renameat2). However this separate function was
7	dnl # merged back into iops->rename() in Linux 4.9.
8	dnl #
9	ZFS_LINUX_TEST_SRC([inode_operations_rename2], [
10		#include <linux/fs.h>
11		int rename2_fn(struct inode *sip, struct dentry *sdp,
12			struct inode *tip, struct dentry *tdp,
13			unsigned int flags) { return 0; }
14
15		static const struct inode_operations
16		    iops __attribute__ ((unused)) = {
17			.rename2 = rename2_fn,
18		};
19	],[])
20
21	dnl #
22	dnl # 4.9 API change,
23	dnl #
24	dnl # iops->rename2() merged into iops->rename(), and iops->rename() now
25	dnl # wants flags.
26	dnl #
27	ZFS_LINUX_TEST_SRC([inode_operations_rename_flags], [
28		#include <linux/fs.h>
29		int rename_fn(struct inode *sip, struct dentry *sdp,
30			struct inode *tip, struct dentry *tdp,
31			unsigned int flags) { return 0; }
32
33		static const struct inode_operations
34		    iops __attribute__ ((unused)) = {
35			.rename = rename_fn,
36		};
37	],[])
38
39	dnl #
40	dnl # EL7 compatibility
41	dnl #
42	dnl # EL7 has backported renameat2 support, but it's done by defining a
43	dnl # separate iops wrapper structure that takes the .renameat2 function.
44	dnl #
45	ZFS_LINUX_TEST_SRC([dir_inode_operations_wrapper_rename2], [
46		#include <linux/fs.h>
47		int rename2_fn(struct inode *sip, struct dentry *sdp,
48			struct inode *tip, struct dentry *tdp,
49			unsigned int flags) { return 0; }
50
51		static const struct inode_operations_wrapper
52		    iops __attribute__ ((unused)) = {
53			.rename2 = rename2_fn,
54		};
55	],[])
56
57	dnl #
58	dnl # 5.12 API change,
59	dnl #
60	dnl # Linux 5.12 introduced passing struct user_namespace* as the first
61	dnl # argument of the rename() and other inode_operations members.
62	dnl #
63	ZFS_LINUX_TEST_SRC([inode_operations_rename_userns], [
64		#include <linux/fs.h>
65		int rename_fn(struct user_namespace *user_ns, struct inode *sip,
66			struct dentry *sdp, struct inode *tip, struct dentry *tdp,
67			unsigned int flags) { return 0; }
68
69		static const struct inode_operations
70		    iops __attribute__ ((unused)) = {
71			.rename = rename_fn,
72		};
73	],[])
74
75	dnl #
76	dnl # 6.3 API change - the first arg is now struct mnt_idmap*
77	dnl #
78	ZFS_LINUX_TEST_SRC([inode_operations_rename_mnt_idmap], [
79		#include <linux/fs.h>
80		int rename_fn(struct mnt_idmap *idmap, struct inode *sip,
81			struct dentry *sdp, struct inode *tip, struct dentry *tdp,
82			unsigned int flags) { return 0; }
83
84		static const struct inode_operations
85		    iops __attribute__ ((unused)) = {
86			.rename = rename_fn,
87		};
88	],[])
89])
90
91AC_DEFUN([ZFS_AC_KERNEL_RENAME], [
92	AC_MSG_CHECKING([whether iops->rename() takes struct mnt_idmap*])
93	ZFS_LINUX_TEST_RESULT([inode_operations_rename_mnt_idmap], [
94		AC_MSG_RESULT(yes)
95		AC_DEFINE(HAVE_IOPS_RENAME_IDMAP, 1,
96		    [iops->rename() takes struct mnt_idmap*])
97	],[
98		AC_MSG_CHECKING([whether iops->rename() takes struct user_namespace*])
99		ZFS_LINUX_TEST_RESULT([inode_operations_rename_userns], [
100			AC_MSG_RESULT(yes)
101			AC_DEFINE(HAVE_IOPS_RENAME_USERNS, 1,
102			    [iops->rename() takes struct user_namespace*])
103		],[
104			AC_MSG_RESULT(no)
105
106			AC_MSG_CHECKING([whether iops->rename2() exists])
107			ZFS_LINUX_TEST_RESULT([inode_operations_rename2], [
108				AC_MSG_RESULT(yes)
109				AC_DEFINE(HAVE_RENAME2, 1, [iops->rename2() exists])
110			],[
111				AC_MSG_RESULT(no)
112
113				AC_MSG_CHECKING([whether iops->rename() wants flags])
114				ZFS_LINUX_TEST_RESULT([inode_operations_rename_flags], [
115					AC_MSG_RESULT(yes)
116					AC_DEFINE(HAVE_RENAME_WANTS_FLAGS, 1,
117						[iops->rename() wants flags])
118				],[
119					AC_MSG_RESULT(no)
120
121					AC_MSG_CHECKING([whether struct inode_operations_wrapper takes .rename2()])
122					ZFS_LINUX_TEST_RESULT([dir_inode_operations_wrapper_rename2], [
123						AC_MSG_RESULT(yes)
124						AC_DEFINE(HAVE_RENAME2_OPERATIONS_WRAPPER, 1,
125							[struct inode_operations_wrapper takes .rename2()])
126					],[
127						AC_MSG_RESULT(no)
128					])
129				])
130			])
131		])
132	])
133])
134