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);
39 inode_set_iversion(ip, 1);
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 fstrans_cookie_t cookie;
62 cookie = spl_fstrans_mark();
63 zfs_dirty_inode(ip, flags);
64 spl_fstrans_unmark(cookie);
68 zpl_dirty_inode(struct inode *ip)
70 fstrans_cookie_t cookie;
72 cookie = spl_fstrans_mark();
73 zfs_dirty_inode(ip, 0);
74 spl_fstrans_unmark(cookie);
76 #endif /* HAVE_DIRTY_INODE_WITH_FLAGS */
79 * When ->drop_inode() is called its return value indicates if the
80 * inode should be evicted from the inode cache. If the inode is
81 * unhashed and has no links the default policy is to evict it
84 * Prior to 2.6.36 this eviction was accomplished by the vfs calling
85 * ->delete_inode(). It was ->delete_inode()'s responsibility to
86 * truncate the inode pages and call clear_inode(). The call to
87 * clear_inode() synchronously invalidates all the buffers and
88 * calls ->clear_inode(). It was ->clear_inode()'s responsibility
89 * to cleanup and filesystem specific data before freeing the inode.
91 * This elaborate mechanism was replaced by ->evict_inode() which
92 * does the job of both ->delete_inode() and ->clear_inode(). It
93 * will be called exactly once, and when it returns the inode must
94 * be in a state where it can simply be freed.i
96 * The ->evict_inode() callback must minimally truncate the inode pages,
97 * and call clear_inode(). For 2.6.35 and later kernels this will
98 * simply update the inode state, with the sync occurring before the
99 * truncate in evict(). For earlier kernels clear_inode() maps to
100 * end_writeback() which is responsible for completing all outstanding
101 * write back. In either case, once this is done it is safe to cleanup
102 * any remaining inode specific data via zfs_inactive().
103 * remaining filesystem specific data.
105 #ifdef HAVE_EVICT_INODE
107 zpl_evict_inode(struct inode *ip)
109 fstrans_cookie_t cookie;
111 cookie = spl_fstrans_mark();
112 truncate_setsize(ip, 0);
115 spl_fstrans_unmark(cookie);
121 zpl_drop_inode(struct inode *ip)
123 generic_delete_inode(ip);
127 zpl_clear_inode(struct inode *ip)
129 fstrans_cookie_t cookie;
131 cookie = spl_fstrans_mark();
133 spl_fstrans_unmark(cookie);
137 zpl_inode_delete(struct inode *ip)
139 truncate_setsize(ip, 0);
142 #endif /* HAVE_EVICT_INODE */
145 zpl_put_super(struct super_block *sb)
147 fstrans_cookie_t cookie;
150 cookie = spl_fstrans_mark();
151 error = -zfs_umount(sb);
152 spl_fstrans_unmark(cookie);
153 ASSERT3S(error, <=, 0);
157 zpl_sync_fs(struct super_block *sb, int wait)
159 fstrans_cookie_t cookie;
164 cookie = spl_fstrans_mark();
165 error = -zfs_sync(sb, wait, cr);
166 spl_fstrans_unmark(cookie);
168 ASSERT3S(error, <=, 0);
174 zpl_statfs(struct dentry *dentry, struct kstatfs *statp)
176 fstrans_cookie_t cookie;
179 cookie = spl_fstrans_mark();
180 error = -zfs_statvfs(dentry, statp);
181 spl_fstrans_unmark(cookie);
182 ASSERT3S(error, <=, 0);
185 * If required by a 32-bit system call, dynamically scale the
186 * block size up to 16MiB and decrease the block counts. This
187 * allows for a maximum size of 64EiB to be reported. The file
188 * counts must be artificially capped at 2^32-1.
190 if (unlikely(zpl_is_32bit_api())) {
191 while (statp->f_blocks > UINT32_MAX &&
192 statp->f_bsize < SPA_MAXBLOCKSIZE) {
193 statp->f_frsize <<= 1;
194 statp->f_bsize <<= 1;
196 statp->f_blocks >>= 1;
197 statp->f_bfree >>= 1;
198 statp->f_bavail >>= 1;
201 uint64_t usedobjs = statp->f_files - statp->f_ffree;
202 statp->f_ffree = MIN(statp->f_ffree, UINT32_MAX - usedobjs);
203 statp->f_files = statp->f_ffree + usedobjs;
210 zpl_remount_fs(struct super_block *sb, int *flags, char *data)
212 zfs_mnt_t zm = { .mnt_osname = NULL, .mnt_data = data };
213 fstrans_cookie_t cookie;
216 cookie = spl_fstrans_mark();
217 error = -zfs_remount(sb, flags, &zm);
218 spl_fstrans_unmark(cookie);
219 ASSERT3S(error, <=, 0);
225 __zpl_show_options(struct seq_file *seq, zfsvfs_t *zfsvfs)
227 seq_printf(seq, ",%s",
228 zfsvfs->z_flags & ZSB_XATTR ? "xattr" : "noxattr");
230 #ifdef CONFIG_FS_POSIX_ACL
231 switch (zfsvfs->z_acl_type) {
232 case ZFS_ACLTYPE_POSIXACL:
233 seq_puts(seq, ",posixacl");
236 seq_puts(seq, ",noacl");
239 #endif /* CONFIG_FS_POSIX_ACL */
244 #ifdef HAVE_SHOW_OPTIONS_WITH_DENTRY
246 zpl_show_options(struct seq_file *seq, struct dentry *root)
248 return (__zpl_show_options(seq, root->d_sb->s_fs_info));
252 zpl_show_options(struct seq_file *seq, struct vfsmount *vfsp)
254 return (__zpl_show_options(seq, vfsp->mnt_sb->s_fs_info));
256 #endif /* HAVE_SHOW_OPTIONS_WITH_DENTRY */
259 zpl_fill_super(struct super_block *sb, void *data, int silent)
261 zfs_mnt_t *zm = (zfs_mnt_t *)data;
262 fstrans_cookie_t cookie;
265 cookie = spl_fstrans_mark();
266 error = -zfs_domount(sb, zm, silent);
267 spl_fstrans_unmark(cookie);
268 ASSERT3S(error, <=, 0);
274 zpl_test_super(struct super_block *s, void *data)
276 zfsvfs_t *zfsvfs = s->s_fs_info;
282 return (os == zfsvfs->z_os);
285 static struct super_block *
286 zpl_mount_impl(struct file_system_type *fs_type, int flags, zfs_mnt_t *zm)
288 struct super_block *s;
292 err = dmu_objset_hold(zm->mnt_osname, FTAG, &os);
294 return (ERR_PTR(-err));
297 * The dsl pool lock must be released prior to calling sget().
298 * It is possible sget() may block on the lock in grab_super()
299 * while deactivate_super() holds that same lock and waits for
300 * a txg sync. If the dsl_pool lock is held over over sget()
301 * this can prevent the pool sync and cause a deadlock.
303 dsl_pool_rele(dmu_objset_pool(os), FTAG);
304 s = zpl_sget(fs_type, zpl_test_super, set_anon_super, flags, os);
305 dsl_dataset_rele(dmu_objset_ds(os), FTAG);
308 return (ERR_CAST(s));
310 if (s->s_root == NULL) {
311 err = zpl_fill_super(s, zm, flags & SB_SILENT ? 1 : 0);
313 deactivate_locked_super(s);
314 return (ERR_PTR(err));
316 s->s_flags |= SB_ACTIVE;
317 } else if ((flags ^ s->s_flags) & SB_RDONLY) {
318 deactivate_locked_super(s);
319 return (ERR_PTR(-EBUSY));
325 #ifdef HAVE_FST_MOUNT
326 static struct dentry *
327 zpl_mount(struct file_system_type *fs_type, int flags,
328 const char *osname, void *data)
330 zfs_mnt_t zm = { .mnt_osname = osname, .mnt_data = data };
332 struct super_block *sb = zpl_mount_impl(fs_type, flags, &zm);
334 return (ERR_CAST(sb));
336 return (dget(sb->s_root));
340 zpl_get_sb(struct file_system_type *fs_type, int flags,
341 const char *osname, void *data, struct vfsmount *mnt)
343 zfs_mnt_t zm = { .mnt_osname = osname, .mnt_data = data };
345 struct super_block *sb = zpl_mount_impl(fs_type, flags, &zm);
347 return (PTR_ERR(sb));
349 (void) simple_set_mnt(mnt, sb);
353 #endif /* HAVE_FST_MOUNT */
356 zpl_kill_sb(struct super_block *sb)
361 #ifdef HAVE_S_INSTANCES_LIST_HEAD
362 sb->s_instances.next = &(zpl_fs_type.fs_supers);
363 #endif /* HAVE_S_INSTANCES_LIST_HEAD */
367 zpl_prune_sb(int64_t nr_to_scan, void *arg)
369 struct super_block *sb = (struct super_block *)arg;
372 (void) -zfs_prune(sb, nr_to_scan, &objects);
375 #ifdef HAVE_NR_CACHED_OBJECTS
377 zpl_nr_cached_objects(struct super_block *sb)
381 #endif /* HAVE_NR_CACHED_OBJECTS */
383 #ifdef HAVE_FREE_CACHED_OBJECTS
385 zpl_free_cached_objects(struct super_block *sb, int nr_to_scan)
389 #endif /* HAVE_FREE_CACHED_OBJECTS */
391 const struct super_operations zpl_super_operations = {
392 .alloc_inode = zpl_inode_alloc,
393 .destroy_inode = zpl_inode_destroy,
394 .dirty_inode = zpl_dirty_inode,
396 #ifdef HAVE_EVICT_INODE
397 .evict_inode = zpl_evict_inode,
399 .drop_inode = zpl_drop_inode,
400 .clear_inode = zpl_clear_inode,
401 .delete_inode = zpl_inode_delete,
402 #endif /* HAVE_EVICT_INODE */
403 .put_super = zpl_put_super,
404 .sync_fs = zpl_sync_fs,
405 .statfs = zpl_statfs,
406 .remount_fs = zpl_remount_fs,
407 .show_options = zpl_show_options,
409 #ifdef HAVE_NR_CACHED_OBJECTS
410 .nr_cached_objects = zpl_nr_cached_objects,
411 #endif /* HAVE_NR_CACHED_OBJECTS */
412 #ifdef HAVE_FREE_CACHED_OBJECTS
413 .free_cached_objects = zpl_free_cached_objects,
414 #endif /* HAVE_FREE_CACHED_OBJECTS */
417 struct file_system_type zpl_fs_type = {
418 .owner = THIS_MODULE,
420 #ifdef HAVE_FST_MOUNT
423 .get_sb = zpl_get_sb,
424 #endif /* HAVE_FST_MOUNT */
425 .kill_sb = zpl_kill_sb,