]> git.proxmox.com Git - mirror_zfs-debian.git/blame - include/linux/vfs_compat.h
Imported Upstream version 0.6.5.9
[mirror_zfs-debian.git] / include / linux / vfs_compat.h
CommitLineData
7268e1be
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.
ea04106b 24 * Copyright (C) 2015 Jörg Thalheim.
7268e1be
BB
25 */
26
27#ifndef _ZFS_VFS_H
a08ee875 28#define _ZFS_VFS_H
7268e1be 29
ea04106b 30#include <sys/taskq.h>
e10b0808 31#include <linux/backing-dev.h>
ea04106b 32
bdf4328b
BB
33/*
34 * 2.6.28 API change,
35 * Added insert_inode_locked() helper function, prior to this most callers
36 * used insert_inode_hash(). The older method doesn't check for collisions
37 * in the inode_hashtable but it still acceptible for use.
38 */
39#ifndef HAVE_INSERT_INODE_LOCKED
40static inline int
41insert_inode_locked(struct inode *ip)
42{
43 insert_inode_hash(ip);
44 return (0);
45}
46#endif /* HAVE_INSERT_INODE_LOCKED */
7268e1be 47
b3129792
PJ
48/*
49 * 2.6.35 API change,
50 * Add truncate_setsize() if it is not exported by the Linux kernel.
51 *
52 * Truncate the inode and pages associated with the inode. The pages are
53 * unmapped and removed from cache.
54 */
55#ifndef HAVE_TRUNCATE_SETSIZE
56static inline void
57truncate_setsize(struct inode *ip, loff_t new)
58{
59 struct address_space *mapping = ip->i_mapping;
60
61 i_size_write(ip, new);
62
63 unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
64 truncate_inode_pages(mapping, new);
65 unmap_mapping_range(mapping, new + PAGE_SIZE - 1, 0, 1);
66}
67#endif /* HAVE_TRUNCATE_SETSIZE */
68
76659dc1 69/*
ea04106b
AX
70 * 2.6.32 - 2.6.33, bdi_setup_and_register() is not available.
71 * 2.6.34 - 3.19, bdi_setup_and_register() takes 3 arguments.
72 * 4.0 - x.y, bdi_setup_and_register() takes 2 arguments.
76659dc1 73 */
ea04106b
AX
74#if defined(HAVE_2ARGS_BDI_SETUP_AND_REGISTER)
75static inline int
76zpl_bdi_setup_and_register(struct backing_dev_info *bdi, char *name)
77{
78 return (bdi_setup_and_register(bdi, name));
79}
80#elif defined(HAVE_3ARGS_BDI_SETUP_AND_REGISTER)
81static inline int
82zpl_bdi_setup_and_register(struct backing_dev_info *bdi, char *name)
83{
84 return (bdi_setup_and_register(bdi, name, BDI_CAP_MAP_COPY));
85}
86#else
5547c2f1
BB
87extern atomic_long_t zfs_bdi_seq;
88
89static inline int
ea04106b 90zpl_bdi_setup_and_register(struct backing_dev_info *bdi, char *name)
5547c2f1
BB
91{
92 char tmp[32];
93 int error;
94
95 bdi->name = name;
ea04106b
AX
96 bdi->capabilities = BDI_CAP_MAP_COPY;
97
5547c2f1
BB
98 error = bdi_init(bdi);
99 if (error)
100 return (error);
101
102 sprintf(tmp, "%.28s%s", name, "-%d");
103 error = bdi_register(bdi, NULL, tmp,
104 atomic_long_inc_return(&zfs_bdi_seq));
105 if (error) {
106 bdi_destroy(bdi);
107 return (error);
108 }
109
110 return (error);
111}
ea04106b 112#endif
76659dc1 113
7b3e34ba
BB
114/*
115 * 2.6.38 API change,
116 * LOOKUP_RCU flag introduced to distinguish rcu-walk from ref-walk cases.
117 */
118#ifndef LOOKUP_RCU
a08ee875 119#define LOOKUP_RCU 0x0
7b3e34ba
BB
120#endif /* LOOKUP_RCU */
121
28eb9213
DH
122/*
123 * 3.2-rc1 API change,
124 * Add set_nlink() if it is not exported by the Linux kernel.
125 *
126 * i_nlink is read-only in Linux 3.2, but it can be set directly in
127 * earlier kernels.
128 */
129#ifndef HAVE_SET_NLINK
130static inline void
131set_nlink(struct inode *inode, unsigned int nlink)
132{
133 inode->i_nlink = nlink;
134}
135#endif /* HAVE_SET_NLINK */
136
b39d3b9f
BB
137/*
138 * 3.3 API change,
139 * The VFS .create, .mkdir and .mknod callbacks were updated to take a
140 * umode_t type rather than an int. To cleanly handle both definitions
141 * the zpl_umode_t type is introduced and set accordingly.
142 */
95f5c63b 143#ifdef HAVE_MKDIR_UMODE_T
b39d3b9f
BB
144typedef umode_t zpl_umode_t;
145#else
146typedef int zpl_umode_t;
147#endif
148
739a1a82
RY
149/*
150 * 3.5 API change,
151 * The clear_inode() function replaces end_writeback() and introduces an
152 * ordering change regarding when the inode_sync_wait() occurs. See the
153 * configure check in config/kernel-clear-inode.m4 for full details.
154 */
155#if defined(HAVE_EVICT_INODE) && !defined(HAVE_CLEAR_INODE)
a08ee875 156#define clear_inode(ip) end_writeback(ip)
739a1a82
RY
157#endif /* HAVE_EVICT_INODE && !HAVE_CLEAR_INODE */
158
3c203610
YS
159/*
160 * 3.6 API change,
161 * The sget() helper function now takes the mount flags as an argument.
162 */
163#ifdef HAVE_5ARG_SGET
a08ee875 164#define zpl_sget(type, cmp, set, fl, mtd) sget(type, cmp, set, fl, mtd)
3c203610 165#else
a08ee875 166#define zpl_sget(type, cmp, set, fl, mtd) sget(type, cmp, set, mtd)
3c203610
YS
167#endif /* HAVE_5ARG_SGET */
168
c06d4368
AX
169#if defined(SEEK_HOLE) && defined(SEEK_DATA) && !defined(HAVE_LSEEK_EXECUTE)
170static inline loff_t
a08ee875
LG
171lseek_execute(
172 struct file *filp,
173 struct inode *inode,
174 loff_t offset,
175 loff_t maxsize)
c06d4368
AX
176{
177 if (offset < 0 && !(filp->f_mode & FMODE_UNSIGNED_OFFSET))
178 return (-EINVAL);
179
180 if (offset > maxsize)
181 return (-EINVAL);
182
183 if (offset != filp->f_pos) {
184 spin_lock(&filp->f_lock);
185 filp->f_pos = offset;
186 filp->f_version = 0;
187 spin_unlock(&filp->f_lock);
188 }
189
190 return (offset);
191}
192#endif /* SEEK_HOLE && SEEK_DATA && !HAVE_LSEEK_EXECUTE */
193
a08ee875
LG
194#if defined(CONFIG_FS_POSIX_ACL)
195/*
196 * These functions safely approximates the behavior of posix_acl_release()
197 * which cannot be used because it calls the GPL-only symbol kfree_rcu().
198 * The in-kernel version, which can access the RCU, frees the ACLs after
199 * the grace period expires. Because we're unsure how long that grace
200 * period may be this implementation conservatively delays for 60 seconds.
201 * This is several orders of magnitude larger than expected grace period.
202 * At 60 seconds the kernel will also begin issuing RCU stall warnings.
203 */
204#include <linux/posix_acl.h>
a08ee875
LG
205
206#if defined(HAVE_POSIX_ACL_RELEASE) && !defined(HAVE_POSIX_ACL_RELEASE_GPL_ONLY)
a08ee875 207#define zpl_posix_acl_release(arg) posix_acl_release(arg)
a08ee875 208#else
68d83c55 209void zpl_posix_acl_release_impl(struct posix_acl *);
a08ee875
LG
210
211static inline void
212zpl_posix_acl_release(struct posix_acl *acl)
213{
214 if ((acl == NULL) || (acl == ACL_NOT_CACHED))
215 return;
216
68d83c55
AX
217 if (atomic_dec_and_test(&acl->a_refcount))
218 zpl_posix_acl_release_impl(acl);
a08ee875 219}
68d83c55 220#endif /* HAVE_POSIX_ACL_RELEASE */
a08ee875 221
68d83c55
AX
222#ifdef HAVE_SET_CACHED_ACL_USABLE
223#define zpl_set_cached_acl(ip, ty, n) set_cached_acl(ip, ty, n)
224#define zpl_forget_cached_acl(ip, ty) forget_cached_acl(ip, ty)
225#else
a08ee875
LG
226static inline void
227zpl_set_cached_acl(struct inode *ip, int type, struct posix_acl *newer) {
a08ee875
LG
228 struct posix_acl *older = NULL;
229
230 spin_lock(&ip->i_lock);
231
232 if ((newer != ACL_NOT_CACHED) && (newer != NULL))
233 posix_acl_dup(newer);
234
235 switch (type) {
236 case ACL_TYPE_ACCESS:
237 older = ip->i_acl;
238 rcu_assign_pointer(ip->i_acl, newer);
239 break;
240 case ACL_TYPE_DEFAULT:
241 older = ip->i_default_acl;
242 rcu_assign_pointer(ip->i_default_acl, newer);
243 break;
244 }
245
246 spin_unlock(&ip->i_lock);
247
248 zpl_posix_acl_release(older);
a08ee875
LG
249}
250
251static inline void
252zpl_forget_cached_acl(struct inode *ip, int type) {
253 zpl_set_cached_acl(ip, type, (struct posix_acl *)ACL_NOT_CACHED);
254}
68d83c55 255#endif /* HAVE_SET_CACHED_ACL_USABLE */
a08ee875 256
ea04106b
AX
257#ifndef HAVE___POSIX_ACL_CHMOD
258#ifdef HAVE_POSIX_ACL_CHMOD
259#define __posix_acl_chmod(acl, gfp, mode) posix_acl_chmod(acl, gfp, mode)
260#define __posix_acl_create(acl, gfp, mode) posix_acl_create(acl, gfp, mode)
a08ee875 261#else
a08ee875 262static inline int
ea04106b 263__posix_acl_chmod(struct posix_acl **acl, int flags, umode_t umode) {
a08ee875
LG
264 struct posix_acl *oldacl = *acl;
265 mode_t mode = umode;
266 int error;
267
268 *acl = posix_acl_clone(*acl, flags);
269 zpl_posix_acl_release(oldacl);
270
271 if (!(*acl))
272 return (-ENOMEM);
273
274 error = posix_acl_chmod_masq(*acl, mode);
275 if (error) {
276 zpl_posix_acl_release(*acl);
277 *acl = NULL;
278 }
279
280 return (error);
281}
282
283static inline int
ea04106b 284__posix_acl_create(struct posix_acl **acl, int flags, umode_t *umodep) {
a08ee875
LG
285 struct posix_acl *oldacl = *acl;
286 mode_t mode = *umodep;
287 int error;
288
289 *acl = posix_acl_clone(*acl, flags);
290 zpl_posix_acl_release(oldacl);
291
292 if (!(*acl))
293 return (-ENOMEM);
294
295 error = posix_acl_create_masq(*acl, &mode);
296 *umodep = mode;
297
298 if (error < 0) {
299 zpl_posix_acl_release(*acl);
300 *acl = NULL;
301 }
302
303 return (error);
304}
305#endif /* HAVE_POSIX_ACL_CHMOD */
ea04106b
AX
306#endif /* HAVE___POSIX_ACL_CHMOD */
307
308#ifdef HAVE_POSIX_ACL_EQUIV_MODE_UMODE_T
309typedef umode_t zpl_equivmode_t;
310#else
311typedef mode_t zpl_equivmode_t;
312#endif /* HAVE_POSIX_ACL_EQUIV_MODE_UMODE_T */
a08ee875 313
87dac73d
AX
314/*
315 * 4.8 API change,
316 * posix_acl_valid() now must be passed a namespace, the namespace from
317 * from super block associated with the given inode is used for this purpose.
318 */
319#ifdef HAVE_POSIX_ACL_VALID_WITH_NS
320#define zpl_posix_acl_valid(ip, acl) posix_acl_valid(ip->i_sb->s_user_ns, acl)
321#else
322#define zpl_posix_acl_valid(ip, acl) posix_acl_valid(acl)
323#endif
324
325#endif /* CONFIG_FS_POSIX_ACL */
a08ee875 326
ea04106b
AX
327/*
328 * 2.6.38 API change,
329 * The is_owner_or_cap() function was renamed to inode_owner_or_capable().
330 */
331#ifdef HAVE_INODE_OWNER_OR_CAPABLE
332#define zpl_inode_owner_or_capable(ip) inode_owner_or_capable(ip)
a08ee875 333#else
ea04106b
AX
334#define zpl_inode_owner_or_capable(ip) is_owner_or_cap(ip)
335#endif /* HAVE_INODE_OWNER_OR_CAPABLE */
336
337/*
338 * 3.19 API change
339 * struct access f->f_dentry->d_inode was replaced by accessor function
340 * file_inode(f)
341 */
342#ifndef HAVE_FILE_INODE
343static inline struct inode *file_inode(const struct file *f)
344{
345 return (f->f_dentry->d_inode);
346}
347#endif /* HAVE_FILE_INODE */
a08ee875 348
e10b0808
AX
349/*
350 * 2.6.38 API change
351 */
352#ifdef HAVE_FOLLOW_DOWN_ONE
353#define zpl_follow_down_one(path) follow_down_one(path)
354#define zpl_follow_up(path) follow_up(path)
355#else
356#define zpl_follow_down_one(path) follow_down(path)
357#define zpl_follow_up(path) follow_up(path)
358#endif
359
68d83c55
AX
360/*
361 * 4.9 API change
362 */
363#ifndef HAVE_SETATTR_PREPARE
364static inline int
365setattr_prepare(struct dentry *dentry, struct iattr *ia)
366{
367 return (inode_change_ok(dentry->d_inode, ia));
368}
369#endif
370
7268e1be 371#endif /* _ZFS_VFS_H */