]>
Commit | Line | Data |
---|---|---|
777d4af8 BB |
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 http://www.opensolaris.org/os/licensing. | |
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 | |
d1d7e268 | 27 | #define _ZFS_XATTR_H |
777d4af8 | 28 | |
023699cd MM |
29 | #include <linux/posix_acl_xattr.h> |
30 | ||
777d4af8 BB |
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 | #ifdef HAVE_CONST_XATTR_HANDLER | |
39 | typedef const struct xattr_handler xattr_handler_t; | |
40 | #else | |
41 | typedef struct xattr_handler xattr_handler_t; | |
42 | #endif | |
43 | ||
4967a3eb BB |
44 | /* |
45 | * 3.7 API change, | |
46 | * Preferred XATTR_NAME_* definitions introduced, these are mapped to | |
47 | * the previous definitions for older kernels. | |
48 | */ | |
49 | #ifndef XATTR_NAME_POSIX_ACL_DEFAULT | |
50 | #define XATTR_NAME_POSIX_ACL_DEFAULT POSIX_ACL_XATTR_DEFAULT | |
51 | #endif | |
52 | ||
53 | #ifndef XATTR_NAME_POSIX_ACL_ACCESS | |
54 | #define XATTR_NAME_POSIX_ACL_ACCESS POSIX_ACL_XATTR_ACCESS | |
55 | #endif | |
56 | ||
57 | /* | |
58 | * 4.5 API change, | |
59 | */ | |
60 | #if defined(HAVE_XATTR_LIST_SIMPLE) | |
61 | #define ZPL_XATTR_LIST_WRAPPER(fn) \ | |
62 | static bool \ | |
63 | fn(struct dentry *dentry) \ | |
64 | { \ | |
65 | return (!!__ ## fn(dentry->d_inode, NULL, 0, NULL, 0)); \ | |
66 | } | |
67 | /* | |
68 | * 4.4 API change, | |
69 | */ | |
70 | #elif defined(HAVE_XATTR_LIST_DENTRY) | |
71 | #define ZPL_XATTR_LIST_WRAPPER(fn) \ | |
72 | static size_t \ | |
73 | fn(struct dentry *dentry, char *list, size_t list_size, \ | |
74 | const char *name, size_t name_len, int type) \ | |
75 | { \ | |
76 | return (__ ## fn(dentry->d_inode, \ | |
77 | list, list_size, name, name_len)); \ | |
78 | } | |
f9637c6c BB |
79 | /* |
80 | * 2.6.33 API change, | |
f9637c6c | 81 | */ |
4967a3eb BB |
82 | #elif defined(HAVE_XATTR_LIST_HANDLER) |
83 | #define ZPL_XATTR_LIST_WRAPPER(fn) \ | |
84 | static size_t \ | |
85 | fn(const struct xattr_handler *handler, struct dentry *dentry, \ | |
86 | char *list, size_t list_size, const char *name, size_t name_len) \ | |
f9637c6c | 87 | { \ |
4967a3eb BB |
88 | return (__ ## fn(dentry->d_inode, \ |
89 | list, list_size, name, name_len)); \ | |
90 | } | |
91 | /* | |
92 | * 2.6.32 API | |
93 | */ | |
94 | #elif defined(HAVE_XATTR_LIST_INODE) | |
95 | #define ZPL_XATTR_LIST_WRAPPER(fn) \ | |
96 | static size_t \ | |
97 | fn(struct inode *ip, char *list, size_t list_size, \ | |
98 | const char *name, size_t name_len) \ | |
99 | { \ | |
100 | return (__ ## fn(ip, list, list_size, name, name_len)); \ | |
f9637c6c | 101 | } |
4967a3eb BB |
102 | #endif |
103 | ||
61d482f7 CC |
104 | /* |
105 | * 4.4 API change, | |
4967a3eb | 106 | * The xattr_handler->get() callback was changed to take a xattr_handler, |
61d482f7 CC |
107 | * and handler_flags argument was removed and should be accessed by |
108 | * handler->flags. | |
109 | */ | |
4967a3eb | 110 | #if defined(HAVE_XATTR_GET_HANDLER) |
61d482f7 CC |
111 | #define ZPL_XATTR_GET_WRAPPER(fn) \ |
112 | static int \ | |
113 | fn(const struct xattr_handler *handler, struct dentry *dentry, \ | |
114 | const char *name, void *buffer, size_t size) \ | |
115 | { \ | |
116 | return (__ ## fn(dentry->d_inode, name, buffer, size)); \ | |
117 | } | |
4967a3eb BB |
118 | /* |
119 | * 2.6.33 API change, | |
120 | * The xattr_handler->get() callback was changed to take a dentry | |
121 | * instead of an inode, and a handler_flags argument was added. | |
122 | */ | |
123 | #elif defined(HAVE_XATTR_GET_DENTRY) | |
d1d7e268 | 124 | #define ZPL_XATTR_GET_WRAPPER(fn) \ |
f9637c6c | 125 | static int \ |
4967a3eb BB |
126 | fn(struct dentry *dentry, const char *name, void *buffer, size_t size, \ |
127 | int unused_handler_flags) \ | |
f9637c6c | 128 | { \ |
4967a3eb | 129 | return (__ ## fn(dentry->d_inode, name, buffer, size)); \ |
f9637c6c | 130 | } |
f9637c6c | 131 | /* |
4967a3eb | 132 | * 2.6.32 API |
f9637c6c | 133 | */ |
4967a3eb BB |
134 | #elif defined(HAVE_XATTR_GET_INODE) |
135 | #define ZPL_XATTR_GET_WRAPPER(fn) \ | |
f9637c6c | 136 | static int \ |
4967a3eb | 137 | fn(struct inode *ip, const char *name, void *buffer, size_t size) \ |
f9637c6c | 138 | { \ |
4967a3eb | 139 | return (__ ## fn(ip, name, buffer, size)); \ |
f9637c6c | 140 | } |
4967a3eb BB |
141 | #endif |
142 | ||
61d482f7 CC |
143 | /* |
144 | * 4.4 API change, | |
4967a3eb | 145 | * The xattr_handler->set() callback was changed to take a xattr_handler, |
61d482f7 CC |
146 | * and handler_flags argument was removed and should be accessed by |
147 | * handler->flags. | |
148 | */ | |
4967a3eb | 149 | #if defined(HAVE_XATTR_SET_HANDLER) |
61d482f7 CC |
150 | #define ZPL_XATTR_SET_WRAPPER(fn) \ |
151 | static int \ | |
152 | fn(const struct xattr_handler *handler, struct dentry *dentry, \ | |
153 | const char *name, const void *buffer, size_t size, int flags) \ | |
154 | { \ | |
155 | return (__ ## fn(dentry->d_inode, name, buffer, size, flags)); \ | |
156 | } | |
4967a3eb BB |
157 | /* |
158 | * 2.6.33 API change, | |
159 | * The xattr_handler->set() callback was changed to take a dentry | |
160 | * instead of an inode, and a handler_flags argument was added. | |
161 | */ | |
162 | #elif defined(HAVE_XATTR_SET_DENTRY) | |
163 | #define ZPL_XATTR_SET_WRAPPER(fn) \ | |
164 | static int \ | |
165 | fn(struct dentry *dentry, const char *name, const void *buffer, \ | |
166 | size_t size, int flags, int unused_handler_flags) \ | |
167 | { \ | |
168 | return (__ ## fn(dentry->d_inode, name, buffer, size, flags)); \ | |
169 | } | |
170 | /* | |
171 | * 2.6.32 API | |
172 | */ | |
173 | #elif defined(HAVE_XATTR_SET_INODE) | |
d1d7e268 | 174 | #define ZPL_XATTR_SET_WRAPPER(fn) \ |
f9637c6c BB |
175 | static int \ |
176 | fn(struct inode *ip, const char *name, const void *buffer, \ | |
177 | size_t size, int flags) \ | |
178 | { \ | |
d1d7e268 | 179 | return (__ ## fn(ip, name, buffer, size, flags)); \ |
f9637c6c | 180 | } |
4967a3eb | 181 | #endif |
f9637c6c | 182 | |
5c03efc3 | 183 | #ifdef HAVE_6ARGS_SECURITY_INODE_INIT_SECURITY |
d1d7e268 | 184 | #define zpl_security_inode_init_security(ip, dip, qstr, nm, val, len) \ |
5c03efc3 BB |
185 | security_inode_init_security(ip, dip, qstr, nm, val, len) |
186 | #else | |
d1d7e268 | 187 | #define zpl_security_inode_init_security(ip, dip, qstr, nm, val, len) \ |
5c03efc3 BB |
188 | security_inode_init_security(ip, dip, nm, val, len) |
189 | #endif /* HAVE_6ARGS_SECURITY_INODE_INIT_SECURITY */ | |
190 | ||
023699cd MM |
191 | /* |
192 | * Linux 3.7 API change. posix_acl_{from,to}_xattr gained the user_ns | |
193 | * parameter. For the HAVE_POSIX_ACL_FROM_XATTR_USERNS version the | |
194 | * userns _may_ not be correct because it's used outside the RCU. | |
195 | */ | |
196 | #ifdef HAVE_POSIX_ACL_FROM_XATTR_USERNS | |
197 | static inline struct posix_acl * | |
198 | zpl_acl_from_xattr(const void *value, int size) | |
199 | { | |
d1d7e268 | 200 | return (posix_acl_from_xattr(CRED()->user_ns, value, size)); |
023699cd MM |
201 | } |
202 | ||
203 | static inline int | |
204 | zpl_acl_to_xattr(struct posix_acl *acl, void *value, int size) | |
205 | { | |
d1d7e268 | 206 | return (posix_acl_to_xattr(CRED()->user_ns, acl, value, size)); |
023699cd MM |
207 | } |
208 | ||
209 | #else | |
210 | ||
211 | static inline struct posix_acl * | |
d1d7e268 | 212 | zpl_acl_from_xattr(const void *value, int size) |
023699cd | 213 | { |
d1d7e268 | 214 | return (posix_acl_from_xattr(value, size)); |
023699cd MM |
215 | } |
216 | ||
217 | static inline int | |
218 | zpl_acl_to_xattr(struct posix_acl *acl, void *value, int size) | |
219 | { | |
d1d7e268 | 220 | return (posix_acl_to_xattr(acl, value, size)); |
023699cd MM |
221 | } |
222 | #endif /* HAVE_POSIX_ACL_FROM_XATTR_USERNS */ | |
223 | ||
777d4af8 | 224 | #endif /* _ZFS_XATTR_H */ |