xref: /freebsd/sys/contrib/openzfs/config/kernel-xattr-handler.m4 (revision 643ac419fafba89f5adda0e0ea75b538727453fb)
1dnl #
2dnl # 2.6.35 API change,
3dnl # The 'struct xattr_handler' was constified in the generic
4dnl # super_block structure.
5dnl #
6AC_DEFUN([ZFS_AC_KERNEL_SRC_CONST_XATTR_HANDLER], [
7	ZFS_LINUX_TEST_SRC([const_xattr_handler], [
8		#include <linux/fs.h>
9		#include <linux/xattr.h>
10
11		const struct xattr_handler xattr_test_handler = {
12			.prefix	= "test",
13			.get	= NULL,
14			.set	= NULL,
15		};
16
17		const struct xattr_handler *xattr_handlers[] = {
18			&xattr_test_handler,
19		};
20
21		const struct super_block sb __attribute__ ((unused)) = {
22			.s_xattr = xattr_handlers,
23		};
24	],[])
25])
26
27AC_DEFUN([ZFS_AC_KERNEL_CONST_XATTR_HANDLER], [
28	AC_MSG_CHECKING([whether super_block uses const struct xattr_handler])
29	ZFS_LINUX_TEST_RESULT([const_xattr_handler], [
30		AC_MSG_RESULT([yes])
31	],[
32		ZFS_LINUX_TEST_ERROR([const xattr_handler])
33	])
34])
35
36dnl #
37dnl # 4.5 API change,
38dnl # struct xattr_handler added new member "name".
39dnl # xattr_handler which matches to whole name rather than prefix should use
40dnl # "name" instead of "prefix", e.g. "system.posix_acl_access"
41dnl #
42AC_DEFUN([ZFS_AC_KERNEL_SRC_XATTR_HANDLER_NAME], [
43	ZFS_LINUX_TEST_SRC([xattr_handler_name], [
44		#include <linux/xattr.h>
45
46		static const struct xattr_handler
47		    xops __attribute__ ((unused)) = {
48			.name = XATTR_NAME_POSIX_ACL_ACCESS,
49		};
50	],[])
51])
52
53AC_DEFUN([ZFS_AC_KERNEL_XATTR_HANDLER_NAME], [
54	AC_MSG_CHECKING([whether xattr_handler has name])
55	ZFS_LINUX_TEST_RESULT([xattr_handler_name], [
56		AC_MSG_RESULT(yes)
57		AC_DEFINE(HAVE_XATTR_HANDLER_NAME, 1,
58		    [xattr_handler has name])
59	],[
60		AC_MSG_RESULT(no)
61	])
62])
63
64dnl #
65dnl # Supported xattr handler get() interfaces checked newest to oldest.
66dnl #
67AC_DEFUN([ZFS_AC_KERNEL_SRC_XATTR_HANDLER_GET], [
68	ZFS_LINUX_TEST_SRC([xattr_handler_get_dentry_inode], [
69		#include <linux/xattr.h>
70
71		int get(const struct xattr_handler *handler,
72		    struct dentry *dentry, struct inode *inode,
73		    const char *name, void *buffer, size_t size) { return 0; }
74		static const struct xattr_handler
75		    xops __attribute__ ((unused)) = {
76			.get = get,
77		};
78	],[])
79
80	ZFS_LINUX_TEST_SRC([xattr_handler_get_xattr_handler], [
81		#include <linux/xattr.h>
82
83		int get(const struct xattr_handler *handler,
84		    struct dentry *dentry, const char *name,
85		    void *buffer, size_t size) { return 0; }
86		static const struct xattr_handler
87		    xops __attribute__ ((unused)) = {
88			.get = get,
89		};
90	],[])
91
92	ZFS_LINUX_TEST_SRC([xattr_handler_get_dentry], [
93		#include <linux/xattr.h>
94
95		int get(struct dentry *dentry, const char *name,
96		    void *buffer, size_t size, int handler_flags)
97		    { return 0; }
98		static const struct xattr_handler
99		    xops __attribute__ ((unused)) = {
100			.get = get,
101		};
102	],[])
103])
104
105AC_DEFUN([ZFS_AC_KERNEL_XATTR_HANDLER_GET], [
106	dnl #
107	dnl # 4.7 API change,
108	dnl # The xattr_handler->get() callback was changed to take both
109	dnl # dentry and inode.
110	dnl #
111	AC_MSG_CHECKING([whether xattr_handler->get() wants dentry and inode])
112	ZFS_LINUX_TEST_RESULT([xattr_handler_get_dentry_inode], [
113		AC_MSG_RESULT(yes)
114		AC_DEFINE(HAVE_XATTR_GET_DENTRY_INODE, 1,
115		    [xattr_handler->get() wants both dentry and inode])
116	],[
117		dnl #
118		dnl # 4.4 API change,
119		dnl # The xattr_handler->get() callback was changed to take a
120		dnl # attr_handler, and handler_flags argument was removed and
121		dnl # should be accessed by handler->flags.
122		dnl #
123		AC_MSG_RESULT(no)
124		AC_MSG_CHECKING(
125		    [whether xattr_handler->get() wants xattr_handler])
126		ZFS_LINUX_TEST_RESULT([xattr_handler_get_xattr_handler], [
127			AC_MSG_RESULT(yes)
128			AC_DEFINE(HAVE_XATTR_GET_HANDLER, 1,
129			    [xattr_handler->get() wants xattr_handler])
130		],[
131			dnl #
132			dnl # 2.6.33 API change,
133			dnl # The xattr_handler->get() callback was changed
134			dnl # to take a dentry instead of an inode, and a
135			dnl # handler_flags argument was added.
136			dnl #
137			AC_MSG_RESULT(no)
138			AC_MSG_CHECKING(
139			    [whether xattr_handler->get() wants dentry])
140			ZFS_LINUX_TEST_RESULT([xattr_handler_get_dentry], [
141				AC_MSG_RESULT(yes)
142				AC_DEFINE(HAVE_XATTR_GET_DENTRY, 1,
143				    [xattr_handler->get() wants dentry])
144			],[
145				ZFS_LINUX_TEST_ERROR([xattr get()])
146			])
147		])
148	])
149])
150
151dnl #
152dnl # Supported xattr handler set() interfaces checked newest to oldest.
153dnl #
154AC_DEFUN([ZFS_AC_KERNEL_SRC_XATTR_HANDLER_SET], [
155	ZFS_LINUX_TEST_SRC([xattr_handler_set_userns], [
156		#include <linux/xattr.h>
157
158		int set(const struct xattr_handler *handler,
159			struct user_namespace *mnt_userns,
160			struct dentry *dentry, struct inode *inode,
161			const char *name, const void *buffer,
162			size_t size, int flags)
163			{ return 0; }
164		static const struct xattr_handler
165			xops __attribute__ ((unused)) = {
166			.set = set,
167		};
168	],[])
169
170	ZFS_LINUX_TEST_SRC([xattr_handler_set_dentry_inode], [
171		#include <linux/xattr.h>
172
173		int set(const struct xattr_handler *handler,
174		    struct dentry *dentry, struct inode *inode,
175		    const char *name, const void *buffer,
176		    size_t size, int flags)
177		    { return 0; }
178		static const struct xattr_handler
179		    xops __attribute__ ((unused)) = {
180			.set = set,
181		};
182	],[])
183
184	ZFS_LINUX_TEST_SRC([xattr_handler_set_xattr_handler], [
185		#include <linux/xattr.h>
186
187		int set(const struct xattr_handler *handler,
188		    struct dentry *dentry, const char *name,
189		    const void *buffer, size_t size, int flags)
190		    { return 0; }
191		static const struct xattr_handler
192		    xops __attribute__ ((unused)) = {
193			.set = set,
194		};
195	],[])
196
197	ZFS_LINUX_TEST_SRC([xattr_handler_set_dentry], [
198		#include <linux/xattr.h>
199
200		int set(struct dentry *dentry, const char *name,
201		    const void *buffer, size_t size, int flags,
202		    int handler_flags) { return 0; }
203		static const struct xattr_handler
204		    xops __attribute__ ((unused)) = {
205			.set = set,
206		};
207	],[])
208])
209
210AC_DEFUN([ZFS_AC_KERNEL_XATTR_HANDLER_SET], [
211	dnl #
212	dnl # 5.12 API change,
213	dnl # The xattr_handler->set() callback was changed to 8 arguments, and
214	dnl # struct user_namespace* was inserted as arg #2
215	dnl #
216	AC_MSG_CHECKING([whether xattr_handler->set() wants dentry, inode, and user_namespace])
217	ZFS_LINUX_TEST_RESULT([xattr_handler_set_userns], [
218		AC_MSG_RESULT(yes)
219		AC_DEFINE(HAVE_XATTR_SET_USERNS, 1,
220		    [xattr_handler->set() takes user_namespace])
221	],[
222		dnl #
223		dnl # 4.7 API change,
224		dnl # The xattr_handler->set() callback was changed to take both
225		dnl # dentry and inode.
226		dnl #
227		AC_MSG_RESULT(no)
228		AC_MSG_CHECKING([whether xattr_handler->set() wants dentry and inode])
229		ZFS_LINUX_TEST_RESULT([xattr_handler_set_dentry_inode], [
230			AC_MSG_RESULT(yes)
231			AC_DEFINE(HAVE_XATTR_SET_DENTRY_INODE, 1,
232			    [xattr_handler->set() wants both dentry and inode])
233		],[
234			dnl #
235			dnl # 4.4 API change,
236			dnl # The xattr_handler->set() callback was changed to take a
237			dnl # xattr_handler, and handler_flags argument was removed and
238			dnl # should be accessed by handler->flags.
239			dnl #
240			AC_MSG_RESULT(no)
241			AC_MSG_CHECKING(
242			    [whether xattr_handler->set() wants xattr_handler])
243			ZFS_LINUX_TEST_RESULT([xattr_handler_set_xattr_handler], [
244				AC_MSG_RESULT(yes)
245				AC_DEFINE(HAVE_XATTR_SET_HANDLER, 1,
246				    [xattr_handler->set() wants xattr_handler])
247			],[
248				dnl #
249				dnl # 2.6.33 API change,
250				dnl # The xattr_handler->set() callback was changed
251				dnl # to take a dentry instead of an inode, and a
252				dnl # handler_flags argument was added.
253				dnl #
254				AC_MSG_RESULT(no)
255				AC_MSG_CHECKING(
256				    [whether xattr_handler->set() wants dentry])
257				ZFS_LINUX_TEST_RESULT([xattr_handler_set_dentry], [
258					AC_MSG_RESULT(yes)
259					AC_DEFINE(HAVE_XATTR_SET_DENTRY, 1,
260					    [xattr_handler->set() wants dentry])
261				],[
262					ZFS_LINUX_TEST_ERROR([xattr set()])
263				])
264			])
265		])
266	])
267])
268
269dnl #
270dnl # Supported xattr handler list() interfaces checked newest to oldest.
271dnl #
272AC_DEFUN([ZFS_AC_KERNEL_SRC_XATTR_HANDLER_LIST], [
273	ZFS_LINUX_TEST_SRC([xattr_handler_list_simple], [
274		#include <linux/xattr.h>
275
276		bool list(struct dentry *dentry) { return 0; }
277		static const struct xattr_handler
278		    xops __attribute__ ((unused)) = {
279			.list = list,
280		};
281	],[])
282
283	ZFS_LINUX_TEST_SRC([xattr_handler_list_xattr_handler], [
284		#include <linux/xattr.h>
285
286		size_t list(const struct xattr_handler *handler,
287		    struct dentry *dentry, char *list, size_t list_size,
288		    const char *name, size_t name_len) { return 0; }
289		static const struct xattr_handler
290		    xops __attribute__ ((unused)) = {
291			.list = list,
292		};
293	],[])
294
295	ZFS_LINUX_TEST_SRC([xattr_handler_list_dentry], [
296		#include <linux/xattr.h>
297
298		size_t list(struct dentry *dentry,
299		    char *list, size_t list_size,
300		    const char *name, size_t name_len,
301		    int handler_flags) { return 0; }
302		static const struct xattr_handler
303		    xops __attribute__ ((unused)) = {
304			.list = list,
305		};
306	],[])
307])
308
309AC_DEFUN([ZFS_AC_KERNEL_XATTR_HANDLER_LIST], [
310	dnl # 4.5 API change,
311	dnl # The xattr_handler->list() callback was changed to take only a
312	dnl # dentry and it only needs to return if it's accessible.
313	AC_MSG_CHECKING([whether xattr_handler->list() wants simple])
314	ZFS_LINUX_TEST_RESULT([xattr_handler_list_simple], [
315		AC_MSG_RESULT(yes)
316		AC_DEFINE(HAVE_XATTR_LIST_SIMPLE, 1,
317		    [xattr_handler->list() wants simple])
318	],[
319		dnl #
320		dnl # 4.4 API change,
321		dnl # The xattr_handler->list() callback was changed to take a
322		dnl # xattr_handler, and handler_flags argument was removed
323		dnl # and should be accessed by handler->flags.
324		dnl #
325		AC_MSG_RESULT(no)
326		AC_MSG_CHECKING(
327		    [whether xattr_handler->list() wants xattr_handler])
328		ZFS_LINUX_TEST_RESULT([xattr_handler_list_xattr_handler], [
329			AC_MSG_RESULT(yes)
330			AC_DEFINE(HAVE_XATTR_LIST_HANDLER, 1,
331			    [xattr_handler->list() wants xattr_handler])
332		],[
333			dnl #
334			dnl # 2.6.33 API change,
335			dnl # The xattr_handler->list() callback was changed
336			dnl # to take a dentry instead of an inode, and a
337			dnl # handler_flags argument was added.
338			dnl #
339			AC_MSG_RESULT(no)
340			AC_MSG_CHECKING(
341			    [whether xattr_handler->list() wants dentry])
342			ZFS_LINUX_TEST_RESULT([xattr_handler_list_dentry], [
343				AC_MSG_RESULT(yes)
344				AC_DEFINE(HAVE_XATTR_LIST_DENTRY, 1,
345				    [xattr_handler->list() wants dentry])
346			],[
347				ZFS_LINUX_TEST_ERROR([xattr list()])
348			])
349		])
350	])
351])
352
353dnl #
354dnl # 3.7 API change,
355dnl # The posix_acl_{from,to}_xattr functions gained a new
356dnl # parameter: user_ns
357dnl #
358AC_DEFUN([ZFS_AC_KERNEL_SRC_POSIX_ACL_FROM_XATTR_USERNS], [
359	ZFS_LINUX_TEST_SRC([posix_acl_from_xattr_userns], [
360		#include <linux/cred.h>
361		#include <linux/fs.h>
362		#include <linux/posix_acl_xattr.h>
363	],[
364		posix_acl_from_xattr(&init_user_ns, NULL, 0);
365	])
366])
367
368AC_DEFUN([ZFS_AC_KERNEL_POSIX_ACL_FROM_XATTR_USERNS], [
369	AC_MSG_CHECKING([whether posix_acl_from_xattr() needs user_ns])
370	ZFS_LINUX_TEST_RESULT([posix_acl_from_xattr_userns], [
371		AC_MSG_RESULT(yes)
372		AC_DEFINE(HAVE_POSIX_ACL_FROM_XATTR_USERNS, 1,
373		    [posix_acl_from_xattr() needs user_ns])
374	],[
375		ZFS_LINUX_TEST_ERROR([posix_acl_from_xattr()])
376	])
377])
378
379dnl #
380dnl # 4.9 API change,
381dnl # iops->{set,get,remove}xattr and generic_{set,get,remove}xattr are
382dnl # removed. xattr operations will directly go through sb->s_xattr.
383dnl #
384AC_DEFUN([ZFS_AC_KERNEL_SRC_GENERIC_SETXATTR], [
385	ZFS_LINUX_TEST_SRC([have_generic_setxattr], [
386		#include <linux/fs.h>
387		#include <linux/xattr.h>
388
389		static const struct inode_operations
390		    iops __attribute__ ((unused)) = {
391			.setxattr = generic_setxattr
392		};
393	],[])
394])
395
396AC_DEFUN([ZFS_AC_KERNEL_GENERIC_SETXATTR], [
397	AC_MSG_CHECKING([whether generic_setxattr() exists])
398	ZFS_LINUX_TEST_RESULT([have_generic_setxattr], [
399		AC_MSG_RESULT(yes)
400		AC_DEFINE(HAVE_GENERIC_SETXATTR, 1,
401		    [generic_setxattr() exists])
402	],[
403		AC_MSG_RESULT(no)
404	])
405])
406
407AC_DEFUN([ZFS_AC_KERNEL_SRC_XATTR], [
408	ZFS_AC_KERNEL_SRC_CONST_XATTR_HANDLER
409	ZFS_AC_KERNEL_SRC_XATTR_HANDLER_NAME
410	ZFS_AC_KERNEL_SRC_XATTR_HANDLER_GET
411	ZFS_AC_KERNEL_SRC_XATTR_HANDLER_SET
412	ZFS_AC_KERNEL_SRC_XATTR_HANDLER_LIST
413	ZFS_AC_KERNEL_SRC_POSIX_ACL_FROM_XATTR_USERNS
414	ZFS_AC_KERNEL_SRC_GENERIC_SETXATTR
415])
416
417AC_DEFUN([ZFS_AC_KERNEL_XATTR], [
418	ZFS_AC_KERNEL_CONST_XATTR_HANDLER
419	ZFS_AC_KERNEL_XATTR_HANDLER_NAME
420	ZFS_AC_KERNEL_XATTR_HANDLER_GET
421	ZFS_AC_KERNEL_XATTR_HANDLER_SET
422	ZFS_AC_KERNEL_XATTR_HANDLER_LIST
423	ZFS_AC_KERNEL_POSIX_ACL_FROM_XATTR_USERNS
424	ZFS_AC_KERNEL_GENERIC_SETXATTR
425])
426