1eda14cbcSMatt Macy /*
2eda14cbcSMatt Macy * CDDL HEADER START
3eda14cbcSMatt Macy *
4eda14cbcSMatt Macy * The contents of this file are subject to the terms of the
5eda14cbcSMatt Macy * Common Development and Distribution License (the "License").
6eda14cbcSMatt Macy * You may not use this file except in compliance with the License.
7eda14cbcSMatt Macy *
8eda14cbcSMatt Macy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9271171e0SMartin Matuska * or https://opensource.org/licenses/CDDL-1.0.
10eda14cbcSMatt Macy * See the License for the specific language governing permissions
11eda14cbcSMatt Macy * and limitations under the License.
12eda14cbcSMatt Macy *
13eda14cbcSMatt Macy * When distributing Covered Code, include this CDDL HEADER in each
14eda14cbcSMatt Macy * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15eda14cbcSMatt Macy * If applicable, add the following below this CDDL HEADER, with the
16eda14cbcSMatt Macy * fields enclosed by brackets "[]" replaced with your own identifying
17eda14cbcSMatt Macy * information: Portions Copyright [yyyy] [name of copyright owner]
18eda14cbcSMatt Macy *
19eda14cbcSMatt Macy * CDDL HEADER END
20eda14cbcSMatt Macy */
21eda14cbcSMatt Macy
22eda14cbcSMatt Macy /*
23eda14cbcSMatt Macy * Copyright (C) 2011 Lawrence Livermore National Security, LLC.
24eda14cbcSMatt Macy */
25eda14cbcSMatt Macy
26eda14cbcSMatt Macy #ifndef _ZFS_XATTR_H
27eda14cbcSMatt Macy #define _ZFS_XATTR_H
28eda14cbcSMatt Macy
29eda14cbcSMatt Macy #include <linux/posix_acl_xattr.h>
30eda14cbcSMatt Macy
31eda14cbcSMatt Macy /*
32eda14cbcSMatt Macy * 2.6.35 API change,
33eda14cbcSMatt Macy * The const keyword was added to the 'struct xattr_handler' in the
34eda14cbcSMatt Macy * generic Linux super_block structure. To handle this we define an
35eda14cbcSMatt Macy * appropriate xattr_handler_t typedef which can be used. This was
36eda14cbcSMatt Macy * the preferred solution because it keeps the code clean and readable.
37eda14cbcSMatt Macy */
38eda14cbcSMatt Macy typedef const struct xattr_handler xattr_handler_t;
39eda14cbcSMatt Macy
40eda14cbcSMatt Macy /*
41eda14cbcSMatt Macy * 4.5 API change,
42eda14cbcSMatt Macy */
43eda14cbcSMatt Macy #if defined(HAVE_XATTR_LIST_SIMPLE)
44eda14cbcSMatt Macy #define ZPL_XATTR_LIST_WRAPPER(fn) \
45eda14cbcSMatt Macy static bool \
46eda14cbcSMatt Macy fn(struct dentry *dentry) \
47eda14cbcSMatt Macy { \
48eda14cbcSMatt Macy return (!!__ ## fn(dentry->d_inode, NULL, 0, NULL, 0)); \
49eda14cbcSMatt Macy }
50eda14cbcSMatt Macy /*
51eda14cbcSMatt Macy * 4.4 API change,
52eda14cbcSMatt Macy */
53eda14cbcSMatt Macy #elif defined(HAVE_XATTR_LIST_DENTRY)
54eda14cbcSMatt Macy #define ZPL_XATTR_LIST_WRAPPER(fn) \
55eda14cbcSMatt Macy static size_t \
56eda14cbcSMatt Macy fn(struct dentry *dentry, char *list, size_t list_size, \
57eda14cbcSMatt Macy const char *name, size_t name_len, int type) \
58eda14cbcSMatt Macy { \
59eda14cbcSMatt Macy return (__ ## fn(dentry->d_inode, \
60eda14cbcSMatt Macy list, list_size, name, name_len)); \
61eda14cbcSMatt Macy }
62eda14cbcSMatt Macy /*
63eda14cbcSMatt Macy * 2.6.33 API change,
64eda14cbcSMatt Macy */
65eda14cbcSMatt Macy #elif defined(HAVE_XATTR_LIST_HANDLER)
66eda14cbcSMatt Macy #define ZPL_XATTR_LIST_WRAPPER(fn) \
67eda14cbcSMatt Macy static size_t \
68eda14cbcSMatt Macy fn(const struct xattr_handler *handler, struct dentry *dentry, \
69eda14cbcSMatt Macy char *list, size_t list_size, const char *name, size_t name_len) \
70eda14cbcSMatt Macy { \
71eda14cbcSMatt Macy return (__ ## fn(dentry->d_inode, \
72eda14cbcSMatt Macy list, list_size, name, name_len)); \
73eda14cbcSMatt Macy }
74eda14cbcSMatt Macy #else
75eda14cbcSMatt Macy #error "Unsupported kernel"
76eda14cbcSMatt Macy #endif
77eda14cbcSMatt Macy
78eda14cbcSMatt Macy /*
79eda14cbcSMatt Macy * 4.7 API change,
80eda14cbcSMatt Macy * The xattr_handler->get() callback was changed to take a both dentry and
81eda14cbcSMatt Macy * inode, because the dentry might not be attached to an inode yet.
82eda14cbcSMatt Macy */
83eda14cbcSMatt Macy #if defined(HAVE_XATTR_GET_DENTRY_INODE)
84eda14cbcSMatt Macy #define ZPL_XATTR_GET_WRAPPER(fn) \
85eda14cbcSMatt Macy static int \
86eda14cbcSMatt Macy fn(const struct xattr_handler *handler, struct dentry *dentry, \
87eda14cbcSMatt Macy struct inode *inode, const char *name, void *buffer, size_t size) \
88eda14cbcSMatt Macy { \
89eda14cbcSMatt Macy return (__ ## fn(inode, name, buffer, size)); \
90eda14cbcSMatt Macy }
91eda14cbcSMatt Macy /*
92eda14cbcSMatt Macy * 4.4 API change,
93eda14cbcSMatt Macy * The xattr_handler->get() callback was changed to take a xattr_handler,
94eda14cbcSMatt Macy * and handler_flags argument was removed and should be accessed by
95eda14cbcSMatt Macy * handler->flags.
96eda14cbcSMatt Macy */
97eda14cbcSMatt Macy #elif defined(HAVE_XATTR_GET_HANDLER)
98eda14cbcSMatt Macy #define ZPL_XATTR_GET_WRAPPER(fn) \
99eda14cbcSMatt Macy static int \
100eda14cbcSMatt Macy fn(const struct xattr_handler *handler, struct dentry *dentry, \
101eda14cbcSMatt Macy const char *name, void *buffer, size_t size) \
102eda14cbcSMatt Macy { \
103eda14cbcSMatt Macy return (__ ## fn(dentry->d_inode, name, buffer, size)); \
104eda14cbcSMatt Macy }
105eda14cbcSMatt Macy /*
106eda14cbcSMatt Macy * 2.6.33 API change,
107eda14cbcSMatt Macy * The xattr_handler->get() callback was changed to take a dentry
108eda14cbcSMatt Macy * instead of an inode, and a handler_flags argument was added.
109eda14cbcSMatt Macy */
110eda14cbcSMatt Macy #elif defined(HAVE_XATTR_GET_DENTRY)
111eda14cbcSMatt Macy #define ZPL_XATTR_GET_WRAPPER(fn) \
112eda14cbcSMatt Macy static int \
113eda14cbcSMatt Macy fn(struct dentry *dentry, const char *name, void *buffer, size_t size, \
114eda14cbcSMatt Macy int unused_handler_flags) \
115eda14cbcSMatt Macy { \
116eda14cbcSMatt Macy return (__ ## fn(dentry->d_inode, name, buffer, size)); \
117eda14cbcSMatt Macy }
118c7046f76SMartin Matuska /*
119c7046f76SMartin Matuska * Android API change,
120c7046f76SMartin Matuska * The xattr_handler->get() callback was changed to take a dentry and inode
121c7046f76SMartin Matuska * and flags, because the dentry might not be attached to an inode yet.
122c7046f76SMartin Matuska */
123c7046f76SMartin Matuska #elif defined(HAVE_XATTR_GET_DENTRY_INODE_FLAGS)
124c7046f76SMartin Matuska #define ZPL_XATTR_GET_WRAPPER(fn) \
125c7046f76SMartin Matuska static int \
126c7046f76SMartin Matuska fn(const struct xattr_handler *handler, struct dentry *dentry, \
127c7046f76SMartin Matuska struct inode *inode, const char *name, void *buffer, \
128c7046f76SMartin Matuska size_t size, int flags) \
129c7046f76SMartin Matuska { \
130c7046f76SMartin Matuska return (__ ## fn(inode, name, buffer, size)); \
131c7046f76SMartin Matuska }
132eda14cbcSMatt Macy #else
133eda14cbcSMatt Macy #error "Unsupported kernel"
134eda14cbcSMatt Macy #endif
135eda14cbcSMatt Macy
136eda14cbcSMatt Macy /*
137*d411c1d6SMartin Matuska * 6.3 API change,
138*d411c1d6SMartin Matuska * The xattr_handler->set() callback was changed to take the
139*d411c1d6SMartin Matuska * struct mnt_idmap* as the first arg, to support idmapped
140*d411c1d6SMartin Matuska * mounts.
141*d411c1d6SMartin Matuska */
142*d411c1d6SMartin Matuska #if defined(HAVE_XATTR_SET_IDMAP)
143*d411c1d6SMartin Matuska #define ZPL_XATTR_SET_WRAPPER(fn) \
144*d411c1d6SMartin Matuska static int \
145*d411c1d6SMartin Matuska fn(const struct xattr_handler *handler, struct mnt_idmap *user_ns, \
146*d411c1d6SMartin Matuska struct dentry *dentry, struct inode *inode, const char *name, \
147*d411c1d6SMartin Matuska const void *buffer, size_t size, int flags) \
148*d411c1d6SMartin Matuska { \
149*d411c1d6SMartin Matuska return (__ ## fn(user_ns, inode, name, buffer, size, flags)); \
150*d411c1d6SMartin Matuska }
151*d411c1d6SMartin Matuska /*
152f9693befSMartin Matuska * 5.12 API change,
153f9693befSMartin Matuska * The xattr_handler->set() callback was changed to take the
154f9693befSMartin Matuska * struct user_namespace* as the first arg, to support idmapped
155f9693befSMartin Matuska * mounts.
156f9693befSMartin Matuska */
157*d411c1d6SMartin Matuska #elif defined(HAVE_XATTR_SET_USERNS)
158f9693befSMartin Matuska #define ZPL_XATTR_SET_WRAPPER(fn) \
159f9693befSMartin Matuska static int \
160f9693befSMartin Matuska fn(const struct xattr_handler *handler, struct user_namespace *user_ns, \
161f9693befSMartin Matuska struct dentry *dentry, struct inode *inode, const char *name, \
162f9693befSMartin Matuska const void *buffer, size_t size, int flags) \
163f9693befSMartin Matuska { \
164dbd5678dSMartin Matuska return (__ ## fn(user_ns, inode, name, buffer, size, flags)); \
165f9693befSMartin Matuska }
166f9693befSMartin Matuska /*
167eda14cbcSMatt Macy * 4.7 API change,
168eda14cbcSMatt Macy * The xattr_handler->set() callback was changed to take a both dentry and
169eda14cbcSMatt Macy * inode, because the dentry might not be attached to an inode yet.
170eda14cbcSMatt Macy */
171f9693befSMartin Matuska #elif defined(HAVE_XATTR_SET_DENTRY_INODE)
172eda14cbcSMatt Macy #define ZPL_XATTR_SET_WRAPPER(fn) \
173eda14cbcSMatt Macy static int \
174eda14cbcSMatt Macy fn(const struct xattr_handler *handler, struct dentry *dentry, \
175eda14cbcSMatt Macy struct inode *inode, const char *name, const void *buffer, \
176eda14cbcSMatt Macy size_t size, int flags) \
177eda14cbcSMatt Macy { \
178dbd5678dSMartin Matuska return (__ ## fn(kcred->user_ns, inode, name, buffer, size, flags));\
179eda14cbcSMatt Macy }
180eda14cbcSMatt Macy /*
181eda14cbcSMatt Macy * 4.4 API change,
182eda14cbcSMatt Macy * The xattr_handler->set() callback was changed to take a xattr_handler,
183eda14cbcSMatt Macy * and handler_flags argument was removed and should be accessed by
184eda14cbcSMatt Macy * handler->flags.
185eda14cbcSMatt Macy */
186eda14cbcSMatt Macy #elif defined(HAVE_XATTR_SET_HANDLER)
187eda14cbcSMatt Macy #define ZPL_XATTR_SET_WRAPPER(fn) \
188eda14cbcSMatt Macy static int \
189eda14cbcSMatt Macy fn(const struct xattr_handler *handler, struct dentry *dentry, \
190eda14cbcSMatt Macy const char *name, const void *buffer, size_t size, int flags) \
191eda14cbcSMatt Macy { \
192dbd5678dSMartin Matuska return (__ ## fn(kcred->user_ns, dentry->d_inode, name, \
193dbd5678dSMartin Matuska buffer, size, flags)); \
194eda14cbcSMatt Macy }
195eda14cbcSMatt Macy /*
196eda14cbcSMatt Macy * 2.6.33 API change,
197eda14cbcSMatt Macy * The xattr_handler->set() callback was changed to take a dentry
198eda14cbcSMatt Macy * instead of an inode, and a handler_flags argument was added.
199eda14cbcSMatt Macy */
200eda14cbcSMatt Macy #elif defined(HAVE_XATTR_SET_DENTRY)
201eda14cbcSMatt Macy #define ZPL_XATTR_SET_WRAPPER(fn) \
202eda14cbcSMatt Macy static int \
203eda14cbcSMatt Macy fn(struct dentry *dentry, const char *name, const void *buffer, \
204eda14cbcSMatt Macy size_t size, int flags, int unused_handler_flags) \
205eda14cbcSMatt Macy { \
206dbd5678dSMartin Matuska return (__ ## fn(kcred->user_ns, dentry->d_inode, name, \
207dbd5678dSMartin Matuska buffer, size, flags)); \
208eda14cbcSMatt Macy }
209eda14cbcSMatt Macy #else
210eda14cbcSMatt Macy #error "Unsupported kernel"
211eda14cbcSMatt Macy #endif
212eda14cbcSMatt Macy
213eda14cbcSMatt Macy /*
214eda14cbcSMatt Macy * Linux 3.7 API change. posix_acl_{from,to}_xattr gained the user_ns
215eda14cbcSMatt Macy * parameter. All callers are expected to pass the &init_user_ns which
216eda14cbcSMatt Macy * is available through the init credential (kcred).
217eda14cbcSMatt Macy */
218eda14cbcSMatt Macy static inline struct posix_acl *
zpl_acl_from_xattr(const void * value,int size)219eda14cbcSMatt Macy zpl_acl_from_xattr(const void *value, int size)
220eda14cbcSMatt Macy {
221eda14cbcSMatt Macy return (posix_acl_from_xattr(kcred->user_ns, value, size));
222eda14cbcSMatt Macy }
223eda14cbcSMatt Macy
224eda14cbcSMatt Macy static inline int
zpl_acl_to_xattr(struct posix_acl * acl,void * value,int size)225eda14cbcSMatt Macy zpl_acl_to_xattr(struct posix_acl *acl, void *value, int size)
226eda14cbcSMatt Macy {
227eda14cbcSMatt Macy return (posix_acl_to_xattr(kcred->user_ns, acl, value, size));
228eda14cbcSMatt Macy }
229eda14cbcSMatt Macy
230eda14cbcSMatt Macy #endif /* _ZFS_XATTR_H */
231