]> git.proxmox.com Git - mirror_zfs.git/blob - include/linux/xattr_compat.h
Linux 4.4 compat: xattr operations takes xattr_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 * 2.6.33 API change,
46 * The xattr_hander->get() callback was changed to take a dentry
47 * instead of an inode, and a handler_flags argument was added.
48 */
49 #ifdef HAVE_DENTRY_XATTR_GET
50 #define ZPL_XATTR_GET_WRAPPER(fn) \
51 static int \
52 fn(struct dentry *dentry, const char *name, void *buffer, size_t size, \
53 int unused_handler_flags) \
54 { \
55 return (__ ## fn(dentry->d_inode, name, buffer, size)); \
56 }
57 /*
58 * 4.4 API change,
59 * The xattr_hander->get() callback was changed to take a xattr_handler,
60 * and handler_flags argument was removed and should be accessed by
61 * handler->flags.
62 */
63 #elif defined(HAVE_HANDLER_XATTR_GET)
64 #define ZPL_XATTR_GET_WRAPPER(fn) \
65 static int \
66 fn(const struct xattr_handler *handler, struct dentry *dentry, \
67 const char *name, void *buffer, size_t size) \
68 { \
69 return (__ ## fn(dentry->d_inode, name, buffer, size)); \
70 }
71 #else
72 #define ZPL_XATTR_GET_WRAPPER(fn) \
73 static int \
74 fn(struct inode *ip, const char *name, void *buffer, size_t size) \
75 { \
76 return (__ ## fn(ip, name, buffer, size)); \
77 }
78 #endif /* HAVE_DENTRY_XATTR_GET */
79
80 /*
81 * 2.6.33 API change,
82 * The xattr_hander->set() callback was changed to take a dentry
83 * instead of an inode, and a handler_flags argument was added.
84 */
85 #ifdef HAVE_DENTRY_XATTR_SET
86 #define ZPL_XATTR_SET_WRAPPER(fn) \
87 static int \
88 fn(struct dentry *dentry, const char *name, const void *buffer, \
89 size_t size, int flags, int unused_handler_flags) \
90 { \
91 return (__ ## fn(dentry->d_inode, name, buffer, size, flags)); \
92 }
93 /*
94 * 4.4 API change,
95 * The xattr_hander->set() callback was changed to take a xattr_handler,
96 * and handler_flags argument was removed and should be accessed by
97 * handler->flags.
98 */
99 #elif defined(HAVE_HANDLER_XATTR_SET)
100 #define ZPL_XATTR_SET_WRAPPER(fn) \
101 static int \
102 fn(const struct xattr_handler *handler, struct dentry *dentry, \
103 const char *name, const void *buffer, size_t size, int flags) \
104 { \
105 return (__ ## fn(dentry->d_inode, name, buffer, size, flags)); \
106 }
107 #else
108 #define ZPL_XATTR_SET_WRAPPER(fn) \
109 static int \
110 fn(struct inode *ip, const char *name, const void *buffer, \
111 size_t size, int flags) \
112 { \
113 return (__ ## fn(ip, name, buffer, size, flags)); \
114 }
115 #endif /* HAVE_DENTRY_XATTR_SET */
116
117 #ifdef HAVE_6ARGS_SECURITY_INODE_INIT_SECURITY
118 #define zpl_security_inode_init_security(ip, dip, qstr, nm, val, len) \
119 security_inode_init_security(ip, dip, qstr, nm, val, len)
120 #else
121 #define zpl_security_inode_init_security(ip, dip, qstr, nm, val, len) \
122 security_inode_init_security(ip, dip, nm, val, len)
123 #endif /* HAVE_6ARGS_SECURITY_INODE_INIT_SECURITY */
124
125 /*
126 * Linux 3.7 API change. posix_acl_{from,to}_xattr gained the user_ns
127 * parameter. For the HAVE_POSIX_ACL_FROM_XATTR_USERNS version the
128 * userns _may_ not be correct because it's used outside the RCU.
129 */
130 #ifdef HAVE_POSIX_ACL_FROM_XATTR_USERNS
131 static inline struct posix_acl *
132 zpl_acl_from_xattr(const void *value, int size)
133 {
134 return (posix_acl_from_xattr(CRED()->user_ns, value, size));
135 }
136
137 static inline int
138 zpl_acl_to_xattr(struct posix_acl *acl, void *value, int size)
139 {
140 return (posix_acl_to_xattr(CRED()->user_ns, acl, value, size));
141 }
142
143 #else
144
145 static inline struct posix_acl *
146 zpl_acl_from_xattr(const void *value, int size)
147 {
148 return (posix_acl_from_xattr(value, size));
149 }
150
151 static inline int
152 zpl_acl_to_xattr(struct posix_acl *acl, void *value, int size)
153 {
154 return (posix_acl_to_xattr(acl, value, size));
155 }
156 #endif /* HAVE_POSIX_ACL_FROM_XATTR_USERNS */
157
158 #endif /* _ZFS_XATTR_H */