]> git.proxmox.com Git - mirror_zfs.git/blob - include/linux/xattr_compat.h
a7371f9466dbdd8287402e4d100c391a1beb835c
[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 #else
58 #define ZPL_XATTR_GET_WRAPPER(fn) \
59 static int \
60 fn(struct inode *ip, const char *name, void *buffer, size_t size) \
61 { \
62 return (__ ## fn(ip, name, buffer, size)); \
63 }
64 #endif /* HAVE_DENTRY_XATTR_GET */
65
66 /*
67 * 2.6.33 API change,
68 * The xattr_hander->set() callback was changed to take a dentry
69 * instead of an inode, and a handler_flags argument was added.
70 */
71 #ifdef HAVE_DENTRY_XATTR_SET
72 #define ZPL_XATTR_SET_WRAPPER(fn) \
73 static int \
74 fn(struct dentry *dentry, const char *name, const void *buffer, \
75 size_t size, int flags, int unused_handler_flags) \
76 { \
77 return (__ ## fn(dentry->d_inode, name, buffer, size, flags)); \
78 }
79 #else
80 #define ZPL_XATTR_SET_WRAPPER(fn) \
81 static int \
82 fn(struct inode *ip, const char *name, const void *buffer, \
83 size_t size, int flags) \
84 { \
85 return (__ ## fn(ip, name, buffer, size, flags)); \
86 }
87 #endif /* HAVE_DENTRY_XATTR_SET */
88
89 #ifdef HAVE_6ARGS_SECURITY_INODE_INIT_SECURITY
90 #define zpl_security_inode_init_security(ip, dip, qstr, nm, val, len) \
91 security_inode_init_security(ip, dip, qstr, nm, val, len)
92 #else
93 #define zpl_security_inode_init_security(ip, dip, qstr, nm, val, len) \
94 security_inode_init_security(ip, dip, nm, val, len)
95 #endif /* HAVE_6ARGS_SECURITY_INODE_INIT_SECURITY */
96
97 /*
98 * Linux 3.7 API change. posix_acl_{from,to}_xattr gained the user_ns
99 * parameter. For the HAVE_POSIX_ACL_FROM_XATTR_USERNS version the
100 * userns _may_ not be correct because it's used outside the RCU.
101 */
102 #ifdef HAVE_POSIX_ACL_FROM_XATTR_USERNS
103 static inline struct posix_acl *
104 zpl_acl_from_xattr(const void *value, int size)
105 {
106 return (posix_acl_from_xattr(CRED()->user_ns, value, size));
107 }
108
109 static inline int
110 zpl_acl_to_xattr(struct posix_acl *acl, void *value, int size)
111 {
112 return (posix_acl_to_xattr(CRED()->user_ns, acl, value, size));
113 }
114
115 #else
116
117 static inline struct posix_acl *
118 zpl_acl_from_xattr(const void *value, int size)
119 {
120 return (posix_acl_from_xattr(value, size));
121 }
122
123 static inline int
124 zpl_acl_to_xattr(struct posix_acl *acl, void *value, int size)
125 {
126 return (posix_acl_to_xattr(acl, value, size));
127 }
128 #endif /* HAVE_POSIX_ACL_FROM_XATTR_USERNS */
129
130 #endif /* _ZFS_XATTR_H */