]> git.proxmox.com Git - mirror_zfs.git/blob - include/linux/xattr_compat.h
Linux 4.5 compat: xattr list handler
[mirror_zfs.git] / include / linux / xattr_compat.h
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
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 #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
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 }
79 /*
80 * 2.6.33 API change,
81 */
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) \
87 { \
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)); \
101 }
102 #endif
103
104 /*
105 * 4.4 API change,
106 * The xattr_handler->get() callback was changed to take a xattr_handler,
107 * and handler_flags argument was removed and should be accessed by
108 * handler->flags.
109 */
110 #if defined(HAVE_XATTR_GET_HANDLER)
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 }
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)
124 #define ZPL_XATTR_GET_WRAPPER(fn) \
125 static int \
126 fn(struct dentry *dentry, const char *name, void *buffer, size_t size, \
127 int unused_handler_flags) \
128 { \
129 return (__ ## fn(dentry->d_inode, name, buffer, size)); \
130 }
131 /*
132 * 2.6.32 API
133 */
134 #elif defined(HAVE_XATTR_GET_INODE)
135 #define ZPL_XATTR_GET_WRAPPER(fn) \
136 static int \
137 fn(struct inode *ip, const char *name, void *buffer, size_t size) \
138 { \
139 return (__ ## fn(ip, name, buffer, size)); \
140 }
141 #endif
142
143 /*
144 * 4.4 API change,
145 * The xattr_handler->set() callback was changed to take a xattr_handler,
146 * and handler_flags argument was removed and should be accessed by
147 * handler->flags.
148 */
149 #if defined(HAVE_XATTR_SET_HANDLER)
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 }
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)
174 #define ZPL_XATTR_SET_WRAPPER(fn) \
175 static int \
176 fn(struct inode *ip, const char *name, const void *buffer, \
177 size_t size, int flags) \
178 { \
179 return (__ ## fn(ip, name, buffer, size, flags)); \
180 }
181 #endif
182
183 #ifdef HAVE_6ARGS_SECURITY_INODE_INIT_SECURITY
184 #define zpl_security_inode_init_security(ip, dip, qstr, nm, val, len) \
185 security_inode_init_security(ip, dip, qstr, nm, val, len)
186 #else
187 #define zpl_security_inode_init_security(ip, dip, qstr, nm, val, len) \
188 security_inode_init_security(ip, dip, nm, val, len)
189 #endif /* HAVE_6ARGS_SECURITY_INODE_INIT_SECURITY */
190
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 {
200 return (posix_acl_from_xattr(CRED()->user_ns, value, size));
201 }
202
203 static inline int
204 zpl_acl_to_xattr(struct posix_acl *acl, void *value, int size)
205 {
206 return (posix_acl_to_xattr(CRED()->user_ns, acl, value, size));
207 }
208
209 #else
210
211 static inline struct posix_acl *
212 zpl_acl_from_xattr(const void *value, int size)
213 {
214 return (posix_acl_from_xattr(value, size));
215 }
216
217 static inline int
218 zpl_acl_to_xattr(struct posix_acl *acl, void *value, int size)
219 {
220 return (posix_acl_to_xattr(acl, value, size));
221 }
222 #endif /* HAVE_POSIX_ACL_FROM_XATTR_USERNS */
223
224 #endif /* _ZFS_XATTR_H */