]> git.proxmox.com Git - mirror_zfs-debian.git/blame - include/linux/xattr_compat.h
Imported Upstream version 0.6.5.4
[mirror_zfs-debian.git] / include / linux / xattr_compat.h
CommitLineData
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
a08ee875
LG
27#define _ZFS_XATTR_H
28
29#include <linux/posix_acl_xattr.h>
777d4af8
BB
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
39typedef const struct xattr_handler xattr_handler_t;
40#else
41typedef struct xattr_handler xattr_handler_t;
42#endif
43
f9637c6c
BB
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
a08ee875 50#define ZPL_XATTR_GET_WRAPPER(fn) \
f9637c6c
BB
51static int \
52fn(struct dentry *dentry, const char *name, void *buffer, size_t size, \
53 int unused_handler_flags) \
54{ \
a08ee875 55 return (__ ## fn(dentry->d_inode, name, buffer, size)); \
f9637c6c 56}
94a40997
AX
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) \
65static int \
66fn(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}
f9637c6c 71#else
a08ee875 72#define ZPL_XATTR_GET_WRAPPER(fn) \
f9637c6c
BB
73static int \
74fn(struct inode *ip, const char *name, void *buffer, size_t size) \
75{ \
a08ee875 76 return (__ ## fn(ip, name, buffer, size)); \
f9637c6c
BB
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
a08ee875 86#define ZPL_XATTR_SET_WRAPPER(fn) \
f9637c6c
BB
87static int \
88fn(struct dentry *dentry, const char *name, const void *buffer, \
89 size_t size, int flags, int unused_handler_flags) \
90{ \
a08ee875 91 return (__ ## fn(dentry->d_inode, name, buffer, size, flags)); \
f9637c6c 92}
94a40997
AX
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) \
101static int \
102fn(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}
f9637c6c 107#else
a08ee875 108#define ZPL_XATTR_SET_WRAPPER(fn) \
f9637c6c
BB
109static int \
110fn(struct inode *ip, const char *name, const void *buffer, \
111 size_t size, int flags) \
112{ \
a08ee875 113 return (__ ## fn(ip, name, buffer, size, flags)); \
f9637c6c
BB
114}
115#endif /* HAVE_DENTRY_XATTR_SET */
116
5c03efc3 117#ifdef HAVE_6ARGS_SECURITY_INODE_INIT_SECURITY
a08ee875 118#define zpl_security_inode_init_security(ip, dip, qstr, nm, val, len) \
5c03efc3
BB
119 security_inode_init_security(ip, dip, qstr, nm, val, len)
120#else
a08ee875 121#define zpl_security_inode_init_security(ip, dip, qstr, nm, val, len) \
5c03efc3
BB
122 security_inode_init_security(ip, dip, nm, val, len)
123#endif /* HAVE_6ARGS_SECURITY_INODE_INIT_SECURITY */
124
a08ee875
LG
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
131static inline struct posix_acl *
132zpl_acl_from_xattr(const void *value, int size)
133{
134 return (posix_acl_from_xattr(CRED()->user_ns, value, size));
135}
136
137static inline int
138zpl_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
145static inline struct posix_acl *
146zpl_acl_from_xattr(const void *value, int size)
147{
148 return (posix_acl_from_xattr(value, size));
149}
150
151static inline int
152zpl_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
777d4af8 158#endif /* _ZFS_XATTR_H */