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.
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.
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]
23 * Copyright (C) 2011 Lawrence Livermore National Security, LLC.
31 * Added insert_inode_locked() helper function, prior to this most callers
32 * used insert_inode_hash(). The older method doesn't check for collisions
33 * in the inode_hashtable but it still acceptible for use.
35 #ifndef HAVE_INSERT_INODE_LOCKED
37 insert_inode_locked(struct inode
*ip
)
39 insert_inode_hash(ip
);
42 #endif /* HAVE_INSERT_INODE_LOCKED */
46 * Add truncate_setsize() if it is not exported by the Linux kernel.
48 * Truncate the inode and pages associated with the inode. The pages are
49 * unmapped and removed from cache.
51 #ifndef HAVE_TRUNCATE_SETSIZE
53 truncate_setsize(struct inode
*ip
, loff_t
new)
55 struct address_space
*mapping
= ip
->i_mapping
;
57 i_size_write(ip
, new);
59 unmap_mapping_range(mapping
, new + PAGE_SIZE
- 1, 0, 1);
60 truncate_inode_pages(mapping
, new);
61 unmap_mapping_range(mapping
, new + PAGE_SIZE
- 1, 0, 1);
63 #endif /* HAVE_TRUNCATE_SETSIZE */
65 #if defined(HAVE_BDI) && !defined(HAVE_BDI_SETUP_AND_REGISTER)
68 * Add bdi_setup_and_register() function if not yet provided by kernel.
69 * It is used to quickly initialize and register a BDI for the filesystem.
71 extern atomic_long_t zfs_bdi_seq
;
74 bdi_setup_and_register(struct backing_dev_info
*bdi
,char *name
,unsigned int cap
)
80 bdi
->capabilities
= cap
;
81 error
= bdi_init(bdi
);
85 sprintf(tmp
, "%.28s%s", name
, "-%d");
86 error
= bdi_register(bdi
, NULL
, tmp
,
87 atomic_long_inc_return(&zfs_bdi_seq
));
95 #endif /* HAVE_BDI && !HAVE_BDI_SETUP_AND_REGISTER */
99 * LOOKUP_RCU flag introduced to distinguish rcu-walk from ref-walk cases.
102 #define LOOKUP_RCU 0x0
103 #endif /* LOOKUP_RCU */
106 * 3.2-rc1 API change,
107 * Add set_nlink() if it is not exported by the Linux kernel.
109 * i_nlink is read-only in Linux 3.2, but it can be set directly in
112 #ifndef HAVE_SET_NLINK
114 set_nlink(struct inode
*inode
, unsigned int nlink
)
116 inode
->i_nlink
= nlink
;
118 #endif /* HAVE_SET_NLINK */
122 * The VFS .create, .mkdir and .mknod callbacks were updated to take a
123 * umode_t type rather than an int. To cleanly handle both definitions
124 * the zpl_umode_t type is introduced and set accordingly.
126 #ifdef HAVE_MKDIR_UMODE_T
127 typedef umode_t zpl_umode_t
;
129 typedef int zpl_umode_t
;
134 * The clear_inode() function replaces end_writeback() and introduces an
135 * ordering change regarding when the inode_sync_wait() occurs. See the
136 * configure check in config/kernel-clear-inode.m4 for full details.
138 #if defined(HAVE_EVICT_INODE) && !defined(HAVE_CLEAR_INODE)
139 #define clear_inode(ip) end_writeback(ip)
140 #endif /* HAVE_EVICT_INODE && !HAVE_CLEAR_INODE */
144 * The sget() helper function now takes the mount flags as an argument.
146 #ifdef HAVE_5ARG_SGET
147 #define zpl_sget(type, cmp, set, fl, mtd) sget(type, cmp, set, fl, mtd)
149 #define zpl_sget(type, cmp, set, fl, mtd) sget(type, cmp, set, mtd)
150 #endif /* HAVE_5ARG_SGET */
152 #define ZFS_IOC_GETFLAGS FS_IOC_GETFLAGS
153 #define ZFS_IOC_SETFLAGS FS_IOC_SETFLAGS
155 #if defined(SEEK_HOLE) && defined(SEEK_DATA) && !defined(HAVE_LSEEK_EXECUTE)
157 lseek_execute(struct file
*filp
, struct inode
*inode
,
158 loff_t offset
, loff_t maxsize
)
160 if (offset
< 0 && !(filp
->f_mode
& FMODE_UNSIGNED_OFFSET
))
163 if (offset
> maxsize
)
166 if (offset
!= filp
->f_pos
) {
167 spin_lock(&filp
->f_lock
);
168 filp
->f_pos
= offset
;
170 spin_unlock(&filp
->f_lock
);
175 #endif /* SEEK_HOLE && SEEK_DATA && !HAVE_LSEEK_EXECUTE */
177 #if defined(CONFIG_FS_POSIX_ACL)
179 * These functions safely approximates the behavior of posix_acl_release()
180 * which cannot be used because it calls the GPL-only symbol kfree_rcu().
181 * The in-kernel version, which can access the RCU, frees the ACLs after
182 * the grace period expires. Because we're unsure how long that grace
183 * period may be this implementation conservatively delays for 60 seconds.
184 * This is several orders of magnitude larger than expected grace period.
185 * At 60 seconds the kernel will also begin issuing RCU stall warnings.
187 #include <linux/posix_acl.h>
188 #ifndef HAVE_POSIX_ACL_CACHING
189 #define ACL_NOT_CACHED ((void *)(-1))
190 #endif /* HAVE_POSIX_ACL_CACHING */
192 #if defined(HAVE_POSIX_ACL_RELEASE) && !defined(HAVE_POSIX_ACL_RELEASE_GPL_ONLY)
194 #define zpl_posix_acl_release(arg) posix_acl_release(arg)
195 #define zpl_set_cached_acl(ip, ty, n) set_cached_acl(ip, ty, n)
196 #define zpl_forget_cached_acl(ip, ty) forget_cached_acl(ip, ty)
201 zpl_posix_acl_free(void *arg
) {
206 zpl_posix_acl_release(struct posix_acl
*acl
)
208 if ((acl
== NULL
) || (acl
== ACL_NOT_CACHED
))
211 if (atomic_dec_and_test(&acl
->a_refcount
)) {
212 taskq_dispatch_delay(system_taskq
, zpl_posix_acl_free
, acl
,
213 TQ_SLEEP
, ddi_get_lbolt() + 60*HZ
);
218 zpl_set_cached_acl(struct inode
*ip
, int type
, struct posix_acl
*newer
) {
219 #ifdef HAVE_POSIX_ACL_CACHING
220 struct posix_acl
*older
= NULL
;
222 spin_lock(&ip
->i_lock
);
224 if ((newer
!= ACL_NOT_CACHED
) && (newer
!= NULL
))
225 posix_acl_dup(newer
);
228 case ACL_TYPE_ACCESS
:
230 rcu_assign_pointer(ip
->i_acl
,newer
);
232 case ACL_TYPE_DEFAULT
:
233 older
= ip
->i_default_acl
;
234 rcu_assign_pointer(ip
->i_default_acl
,newer
);
238 spin_unlock(&ip
->i_lock
);
240 zpl_posix_acl_release(older
);
241 #endif /* HAVE_POSIX_ACL_CACHING */
245 zpl_forget_cached_acl(struct inode
*ip
, int type
) {
246 zpl_set_cached_acl(ip
, type
, (struct posix_acl
*)ACL_NOT_CACHED
);
248 #endif /* HAVE_POSIX_ACL_RELEASE */
252 * The is_owner_or_cap() function was renamed to inode_owner_or_capable().
254 #ifdef HAVE_INODE_OWNER_OR_CAPABLE
255 #define zpl_inode_owner_or_capable(ip) inode_owner_or_capable(ip)
257 #define zpl_inode_owner_or_capable(ip) is_owner_or_cap(ip)
258 #endif /* HAVE_INODE_OWNER_OR_CAPABLE */
260 #ifndef HAVE_POSIX_ACL_CHMOD
262 posix_acl_chmod(struct posix_acl
**acl
, int flags
, umode_t umode
) {
263 struct posix_acl
*oldacl
= *acl
;
267 *acl
= posix_acl_clone(*acl
, flags
);
268 zpl_posix_acl_release(oldacl
);
273 error
= posix_acl_chmod_masq(*acl
, mode
);
275 zpl_posix_acl_release(*acl
);
283 posix_acl_create(struct posix_acl
** acl
, int flags
, umode_t
* umodep
) {
284 struct posix_acl
*oldacl
= *acl
;
285 mode_t mode
= *umodep
;
288 *acl
= posix_acl_clone(*acl
, flags
);
289 zpl_posix_acl_release(oldacl
);
294 error
= posix_acl_create_masq(*acl
, &mode
);
298 zpl_posix_acl_release(*acl
);
304 #endif /* HAVE_POSIX_ACL_CHMOD */
306 #ifndef HAVE_CURRENT_UMASK
310 return (current
->fs
->umask
);
312 #endif /* HAVE_CURRENT_UMASK */
314 #ifdef HAVE_POSIX_ACL_EQUIV_MODE_UMODE_T
315 typedef umode_t zpl_equivmode_t
;
317 typedef mode_t zpl_equivmode_t
;
318 #endif /* HAVE_POSIX_ACL_EQUIV_MODE_UMODE_T */
319 #endif /* CONFIG_FS_POSIX_ACL */
321 #endif /* _ZFS_VFS_H */