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(
75 struct backing_dev_info *bdi,
83 bdi->capabilities = cap;
84 error = bdi_init(bdi);
88 sprintf(tmp, "%.28s%s", name, "-%d");
89 error = bdi_register(bdi, NULL, tmp,
90 atomic_long_inc_return(&zfs_bdi_seq));
98 #endif /* HAVE_BDI && !HAVE_BDI_SETUP_AND_REGISTER */
102 * LOOKUP_RCU flag introduced to distinguish rcu-walk from ref-walk cases.
105 #define LOOKUP_RCU 0x0
106 #endif /* LOOKUP_RCU */
109 * 3.2-rc1 API change,
110 * Add set_nlink() if it is not exported by the Linux kernel.
112 * i_nlink is read-only in Linux 3.2, but it can be set directly in
115 #ifndef HAVE_SET_NLINK
117 set_nlink(struct inode *inode, unsigned int nlink)
119 inode->i_nlink = nlink;
121 #endif /* HAVE_SET_NLINK */
125 * The VFS .create, .mkdir and .mknod callbacks were updated to take a
126 * umode_t type rather than an int. To cleanly handle both definitions
127 * the zpl_umode_t type is introduced and set accordingly.
129 #ifdef HAVE_MKDIR_UMODE_T
130 typedef umode_t zpl_umode_t;
132 typedef int zpl_umode_t;
137 * The clear_inode() function replaces end_writeback() and introduces an
138 * ordering change regarding when the inode_sync_wait() occurs. See the
139 * configure check in config/kernel-clear-inode.m4 for full details.
141 #if defined(HAVE_EVICT_INODE) && !defined(HAVE_CLEAR_INODE)
142 #define clear_inode(ip) end_writeback(ip)
143 #endif /* HAVE_EVICT_INODE && !HAVE_CLEAR_INODE */
147 * The sget() helper function now takes the mount flags as an argument.
149 #ifdef HAVE_5ARG_SGET
150 #define zpl_sget(type, cmp, set, fl, mtd) sget(type, cmp, set, fl, mtd)
152 #define zpl_sget(type, cmp, set, fl, mtd) sget(type, cmp, set, mtd)
153 #endif /* HAVE_5ARG_SGET */
155 #define ZFS_IOC_GETFLAGS FS_IOC_GETFLAGS
156 #define ZFS_IOC_SETFLAGS FS_IOC_SETFLAGS
158 #if defined(SEEK_HOLE) && defined(SEEK_DATA) && !defined(HAVE_LSEEK_EXECUTE)
166 if (offset < 0 && !(filp->f_mode & FMODE_UNSIGNED_OFFSET))
169 if (offset > maxsize)
172 if (offset != filp->f_pos) {
173 spin_lock(&filp->f_lock);
174 filp->f_pos = offset;
176 spin_unlock(&filp->f_lock);
181 #endif /* SEEK_HOLE && SEEK_DATA && !HAVE_LSEEK_EXECUTE */
183 #if defined(CONFIG_FS_POSIX_ACL)
185 * These functions safely approximates the behavior of posix_acl_release()
186 * which cannot be used because it calls the GPL-only symbol kfree_rcu().
187 * The in-kernel version, which can access the RCU, frees the ACLs after
188 * the grace period expires. Because we're unsure how long that grace
189 * period may be this implementation conservatively delays for 60 seconds.
190 * This is several orders of magnitude larger than expected grace period.
191 * At 60 seconds the kernel will also begin issuing RCU stall warnings.
193 #include <linux/posix_acl.h>
194 #ifndef HAVE_POSIX_ACL_CACHING
195 #define ACL_NOT_CACHED ((void *)(-1))
196 #endif /* HAVE_POSIX_ACL_CACHING */
198 #if defined(HAVE_POSIX_ACL_RELEASE) && !defined(HAVE_POSIX_ACL_RELEASE_GPL_ONLY)
200 #define zpl_posix_acl_release(arg) posix_acl_release(arg)
201 #define zpl_set_cached_acl(ip, ty, n) set_cached_acl(ip, ty, n)
202 #define zpl_forget_cached_acl(ip, ty) forget_cached_acl(ip, ty)
207 zpl_posix_acl_free(void *arg) {
212 zpl_posix_acl_release(struct posix_acl *acl)
214 if ((acl == NULL) || (acl == ACL_NOT_CACHED))
217 if (atomic_dec_and_test(&acl->a_refcount)) {
218 taskq_dispatch_delay(system_taskq, zpl_posix_acl_free, acl,
219 TQ_SLEEP, ddi_get_lbolt() + 60*HZ);
224 zpl_set_cached_acl(struct inode *ip, int type, struct posix_acl *newer) {
225 #ifdef HAVE_POSIX_ACL_CACHING
226 struct posix_acl *older = NULL;
228 spin_lock(&ip->i_lock);
230 if ((newer != ACL_NOT_CACHED) && (newer != NULL))
231 posix_acl_dup(newer);
234 case ACL_TYPE_ACCESS:
236 rcu_assign_pointer(ip->i_acl, newer);
238 case ACL_TYPE_DEFAULT:
239 older = ip->i_default_acl;
240 rcu_assign_pointer(ip->i_default_acl, newer);
244 spin_unlock(&ip->i_lock);
246 zpl_posix_acl_release(older);
247 #endif /* HAVE_POSIX_ACL_CACHING */
251 zpl_forget_cached_acl(struct inode *ip, int type) {
252 zpl_set_cached_acl(ip, type, (struct posix_acl *)ACL_NOT_CACHED);
254 #endif /* HAVE_POSIX_ACL_RELEASE */
258 * The is_owner_or_cap() function was renamed to inode_owner_or_capable().
260 #ifdef HAVE_INODE_OWNER_OR_CAPABLE
261 #define zpl_inode_owner_or_capable(ip) inode_owner_or_capable(ip)
263 #define zpl_inode_owner_or_capable(ip) is_owner_or_cap(ip)
264 #endif /* HAVE_INODE_OWNER_OR_CAPABLE */
266 #ifndef HAVE_POSIX_ACL_CHMOD
268 posix_acl_chmod(struct posix_acl **acl, int flags, umode_t umode) {
269 struct posix_acl *oldacl = *acl;
273 *acl = posix_acl_clone(*acl, flags);
274 zpl_posix_acl_release(oldacl);
279 error = posix_acl_chmod_masq(*acl, mode);
281 zpl_posix_acl_release(*acl);
289 posix_acl_create(struct posix_acl **acl, int flags, umode_t *umodep) {
290 struct posix_acl *oldacl = *acl;
291 mode_t mode = *umodep;
294 *acl = posix_acl_clone(*acl, flags);
295 zpl_posix_acl_release(oldacl);
300 error = posix_acl_create_masq(*acl, &mode);
304 zpl_posix_acl_release(*acl);
310 #endif /* HAVE_POSIX_ACL_CHMOD */
312 #ifndef HAVE_CURRENT_UMASK
316 return (current->fs->umask);
318 #endif /* HAVE_CURRENT_UMASK */
320 #ifdef HAVE_POSIX_ACL_EQUIV_MODE_UMODE_T
321 typedef umode_t zpl_equivmode_t;
323 typedef mode_t zpl_equivmode_t;
324 #endif /* HAVE_POSIX_ACL_EQUIV_MODE_UMODE_T */
325 #endif /* CONFIG_FS_POSIX_ACL */
327 #endif /* _ZFS_VFS_H */