1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or https://opensource.org/licenses/CDDL-1.0.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (C) 2011 Lawrence Livermore National Security, LLC.
24  */
25 
26 #ifndef _ZFS_XATTR_H
27 #define	_ZFS_XATTR_H
28 
29 #include <linux/posix_acl_xattr.h>
30 
31 /*
32  * 2.6.35 API change,
33  * The const keyword was added to the 'struct xattr_handler' in the
34  * generic Linux super_block structure.  To handle this we define an
35  * appropriate xattr_handler_t typedef which can be used.  This was
36  * the preferred solution because it keeps the code clean and readable.
37  */
38 typedef const struct xattr_handler	xattr_handler_t;
39 
40 /*
41  * 4.5 API change,
42  */
43 #define	ZPL_XATTR_LIST_WRAPPER(fn)					\
44 static bool								\
45 fn(struct dentry *dentry)						\
46 {									\
47 	return (!!__ ## fn(dentry->d_inode, NULL, 0, NULL, 0));		\
48 }
49 
50 #ifdef HAVE_XATTR_GET_DENTRY_INODE_FLAGS
51 /*
52  * Android API change,
53  * The xattr_handler->get() callback also takes a flags arg.
54  */
55 #define	ZPL_XATTR_GET_WRAPPER(fn)					\
56 static int								\
57 fn(const struct xattr_handler *handler, struct dentry *dentry,		\
58     struct inode *inode, const char *name, void *buffer,		\
59     size_t size, int flags)						\
60 {									\
61 	return (__ ## fn(inode, name, buffer, size));			\
62 }
63 #else
64 #define	ZPL_XATTR_GET_WRAPPER(fn)					\
65 static int								\
66 fn(const struct xattr_handler *handler, struct dentry *dentry,		\
67     struct inode *inode, const char *name, void *buffer, size_t size)	\
68 {									\
69 	return (__ ## fn(inode, name, buffer, size));			\
70 }
71 #endif
72 
73 /*
74  * 6.3 API change,
75  * The xattr_handler->set() callback was changed to take the
76  * struct mnt_idmap* as the first arg, to support idmapped
77  * mounts.
78  */
79 #if defined(HAVE_XATTR_SET_IDMAP)
80 #define	ZPL_XATTR_SET_WRAPPER(fn)					\
81 static int								\
82 fn(const struct xattr_handler *handler, struct mnt_idmap *user_ns,	\
83     struct dentry *dentry, struct inode *inode, const char *name,	\
84     const void *buffer, size_t size, int flags)	\
85 {									\
86 	return (__ ## fn(user_ns, inode, name, buffer, size, flags));	\
87 }
88 /*
89  * 5.12 API change,
90  * The xattr_handler->set() callback was changed to take the
91  * struct user_namespace* as the first arg, to support idmapped
92  * mounts.
93  */
94 #elif defined(HAVE_XATTR_SET_USERNS)
95 #define	ZPL_XATTR_SET_WRAPPER(fn)					\
96 static int								\
97 fn(const struct xattr_handler *handler, struct user_namespace *user_ns, \
98     struct dentry *dentry, struct inode *inode, const char *name,	\
99     const void *buffer, size_t size, int flags)	\
100 {									\
101 	return (__ ## fn(user_ns, inode, name, buffer, size, flags));	\
102 }
103 /*
104  * 4.7 API change,
105  * The xattr_handler->set() callback was changed to take a both dentry and
106  * inode, because the dentry might not be attached to an inode yet.
107  */
108 #elif defined(HAVE_XATTR_SET_DENTRY_INODE)
109 #define	ZPL_XATTR_SET_WRAPPER(fn)					\
110 static int								\
111 fn(const struct xattr_handler *handler, struct dentry *dentry,		\
112     struct inode *inode, const char *name, const void *buffer,		\
113     size_t size, int flags)						\
114 {									\
115 	return (__ ## fn(kcred->user_ns, inode, name, buffer, size, flags));\
116 }
117 #else
118 #error "Unsupported kernel"
119 #endif
120 
121 /*
122  * Linux 3.7 API change. posix_acl_{from,to}_xattr gained the user_ns
123  * parameter.  All callers are expected to pass the &init_user_ns which
124  * is available through the init credential (kcred).
125  */
126 static inline struct posix_acl *
zpl_acl_from_xattr(const void * value,int size)127 zpl_acl_from_xattr(const void *value, int size)
128 {
129 	return (posix_acl_from_xattr(kcred->user_ns, value, size));
130 }
131 
132 static inline int
zpl_acl_to_xattr(struct posix_acl * acl,void * value,int size)133 zpl_acl_to_xattr(struct posix_acl *acl, void *value, int size)
134 {
135 	return (posix_acl_to_xattr(kcred->user_ns, acl, value, size));
136 }
137 
138 #endif /* _ZFS_XATTR_H */
139