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]
22 * Copyright (c) 2011, Lawrence Livermore National Security, LLC.
26 #include <sys/zfs_vfsops.h>
27 #include <sys/zfs_vnops.h>
28 #include <sys/zfs_znode.h>
29 #include <sys/zfs_ctldir.h>
34 zpl_inode_alloc(struct super_block *sb)
38 VERIFY3S(zfs_inode_alloc(sb, &ip), ==, 0);
45 zpl_inode_destroy(struct inode *ip)
47 ASSERT(atomic_read(&ip->i_count) == 0);
48 zfs_inode_destroy(ip);
52 * Called from __mark_inode_dirty() to reflect that something in the
53 * inode has changed. We use it to ensure the znode system attributes
54 * are always strictly update to date with respect to the inode.
56 #ifdef HAVE_DIRTY_INODE_WITH_FLAGS
58 zpl_dirty_inode(struct inode *ip, int flags)
60 zfs_dirty_inode(ip, flags);
64 zpl_dirty_inode(struct inode *ip)
66 zfs_dirty_inode(ip, 0);
68 #endif /* HAVE_DIRTY_INODE_WITH_FLAGS */
71 * When ->drop_inode() is called its return value indicates if the
72 * inode should be evicted from the inode cache. If the inode is
73 * unhashed and has no links the default policy is to evict it
76 * Prior to 2.6.36 this eviction was accomplished by the vfs calling
77 * ->delete_inode(). It was ->delete_inode()'s responsibility to
78 * truncate the inode pages and call clear_inode(). The call to
79 * clear_inode() synchronously invalidates all the buffers and
80 * calls ->clear_inode(). It was ->clear_inode()'s responsibility
81 * to cleanup and filesystem specific data before freeing the inode.
83 * This elaborate mechanism was replaced by ->evict_inode() which
84 * does the job of both ->delete_inode() and ->clear_inode(). It
85 * will be called exactly once, and when it returns the inode must
86 * be in a state where it can simply be freed.i
88 * The ->evict_inode() callback must minimally truncate the inode pages,
89 * and call clear_inode(). For 2.6.35 and later kernels this will
90 * simply update the inode state, with the sync occurring before the
91 * truncate in evict(). For earlier kernels clear_inode() maps to
92 * end_writeback() which is responsible for completing all outstanding
93 * write back. In either case, once this is done it is safe to cleanup
94 * any remaining inode specific data via zfs_inactive().
95 * remaining filesystem specific data.
97 #ifdef HAVE_EVICT_INODE
99 zpl_evict_inode(struct inode *ip)
101 truncate_setsize(ip, 0);
109 zpl_clear_inode(struct inode *ip)
115 zpl_inode_delete(struct inode *ip)
117 truncate_setsize(ip, 0);
121 #endif /* HAVE_EVICT_INODE */
124 zpl_put_super(struct super_block *sb)
128 error = -zfs_umount(sb);
129 ASSERT3S(error, <=, 0);
133 zpl_sync_fs(struct super_block *sb, int wait)
139 error = -zfs_sync(sb, wait, cr);
141 ASSERT3S(error, <=, 0);
147 zpl_statfs(struct dentry *dentry, struct kstatfs *statp)
151 error = -zfs_statvfs(dentry, statp);
152 ASSERT3S(error, <=, 0);
158 zpl_remount_fs(struct super_block *sb, int *flags, char *data)
161 error = -zfs_remount(sb, flags, data);
162 ASSERT3S(error, <=, 0);
168 zpl_umount_begin(struct super_block *sb)
170 zfs_sb_t *zsb = sb->s_fs_info;
174 * Best effort to unmount snapshots in .zfs/snapshot/. Normally this
175 * isn't required because snapshots have the MNT_SHRINKABLE flag set.
178 (void) zfsctl_unmount_snapshots(zsb, MNT_FORCE, &count);
182 * The Linux VFS automatically handles the following flags:
183 * MNT_NOSUID, MNT_NODEV, MNT_NOEXEC, MNT_NOATIME, MNT_READONLY
185 #ifdef HAVE_SHOW_OPTIONS_WITH_DENTRY
187 zpl_show_options(struct seq_file *seq, struct dentry *root)
189 zfs_sb_t *zsb = root->d_sb->s_fs_info;
191 seq_printf(seq, ",%s", zsb->z_flags & ZSB_XATTR ? "xattr" : "noxattr");
197 zpl_show_options(struct seq_file *seq, struct vfsmount *vfsp)
199 zfs_sb_t *zsb = vfsp->mnt_sb->s_fs_info;
201 seq_printf(seq, ",%s", zsb->z_flags & ZSB_XATTR ? "xattr" : "noxattr");
205 #endif /* HAVE_SHOW_OPTIONS_WITH_DENTRY */
208 zpl_fill_super(struct super_block *sb, void *data, int silent)
212 error = -zfs_domount(sb, data, silent);
213 ASSERT3S(error, <=, 0);
218 #ifdef HAVE_MOUNT_NODEV
219 static struct dentry *
220 zpl_mount(struct file_system_type *fs_type, int flags,
221 const char *osname, void *data)
223 zpl_mount_data_t zmd = { osname, data };
225 return mount_nodev(fs_type, flags, &zmd, zpl_fill_super);
229 zpl_get_sb(struct file_system_type *fs_type, int flags,
230 const char *osname, void *data, struct vfsmount *mnt)
232 zpl_mount_data_t zmd = { osname, data };
234 return get_sb_nodev(fs_type, flags, &zmd, zpl_fill_super, mnt);
236 #endif /* HAVE_MOUNT_NODEV */
239 zpl_kill_sb(struct super_block *sb)
247 * Linux 3.1 - 3.x API
249 * The Linux 3.1 API introduced per-sb cache shrinkers to replace the
250 * global ones. This allows us a mechanism to cleanly target a specific
251 * zfs file system when the dnode and inode caches grow too large.
253 * In addition, the 3.0 kernel added the iterate_supers_type() helper
254 * function which is used to safely walk all of the zfs file systems.
257 zpl_prune_sb(struct super_block *sb, void *arg)
262 error = -zfs_sb_prune(sb, *(unsigned long *)arg, &objects);
263 ASSERT3S(error, <=, 0);
269 zpl_prune_sbs(int64_t bytes_to_scan, void *private)
271 unsigned long nr_to_scan = (bytes_to_scan / sizeof(znode_t));
273 iterate_supers_type(&zpl_fs_type, zpl_prune_sb, &nr_to_scan);
278 * Linux 2.6.x - 3.0 API
280 * These are best effort interfaces are provided by the SPL to induce
281 * the Linux VM subsystem to reclaim a fraction of the both dnode and
282 * inode caches. Ideally, we want to just target the zfs file systems
283 * however our only option is to reclaim from them all.
286 zpl_prune_sbs(int64_t bytes_to_scan, void *private)
288 unsigned long nr_to_scan = (bytes_to_scan / sizeof(znode_t));
290 shrink_dcache_memory(nr_to_scan, GFP_KERNEL);
291 shrink_icache_memory(nr_to_scan, GFP_KERNEL);
294 #endif /* HAVE_SHRINK */
296 #ifdef HAVE_NR_CACHED_OBJECTS
298 zpl_nr_cached_objects(struct super_block *sb)
300 zfs_sb_t *zsb = sb->s_fs_info;
303 mutex_enter(&zsb->z_znodes_lock);
304 nr = zsb->z_nr_znodes;
305 mutex_exit(&zsb->z_znodes_lock);
309 #endif /* HAVE_NR_CACHED_OBJECTS */
311 #ifdef HAVE_FREE_CACHED_OBJECTS
313 * Attempt to evict some meta data from the cache. The ARC operates in
314 * terms of bytes while the Linux VFS uses objects. Now because this is
315 * just a best effort eviction and the exact values aren't critical so we
316 * extrapolate from an object count to a byte size using the znode_t size.
319 zpl_free_cached_objects(struct super_block *sb, int nr_to_scan)
321 arc_adjust_meta(nr_to_scan * sizeof(znode_t), B_FALSE);
323 #endif /* HAVE_FREE_CACHED_OBJECTS */
325 const struct super_operations zpl_super_operations = {
326 .alloc_inode = zpl_inode_alloc,
327 .destroy_inode = zpl_inode_destroy,
328 .dirty_inode = zpl_dirty_inode,
331 #ifdef HAVE_EVICT_INODE
332 .evict_inode = zpl_evict_inode,
334 .clear_inode = zpl_clear_inode,
335 .delete_inode = zpl_inode_delete,
336 #endif /* HAVE_EVICT_INODE */
337 .put_super = zpl_put_super,
338 .sync_fs = zpl_sync_fs,
339 .statfs = zpl_statfs,
340 .remount_fs = zpl_remount_fs,
341 .umount_begin = zpl_umount_begin,
342 .show_options = zpl_show_options,
344 #ifdef HAVE_NR_CACHED_OBJECTS
345 .nr_cached_objects = zpl_nr_cached_objects,
346 #endif /* HAVE_NR_CACHED_OBJECTS */
347 #ifdef HAVE_FREE_CACHED_OBJECTS
348 .free_cached_objects = zpl_free_cached_objects,
349 #endif /* HAVE_FREE_CACHED_OBJECTS */
352 struct file_system_type zpl_fs_type = {
353 .owner = THIS_MODULE,
355 #ifdef HAVE_MOUNT_NODEV
358 .get_sb = zpl_get_sb,
359 #endif /* HAVE_MOUNT_NODEV */
360 .kill_sb = zpl_kill_sb,