]> git.proxmox.com Git - mirror_zfs.git/blame - module/zfs/zpl_super.c
Fix typos in module/zfs/
[mirror_zfs.git] / module / zfs / zpl_super.c
CommitLineData
51f0bbe4
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 * Copyright (c) 2011, Lawrence Livermore National Security, LLC.
23 */
24
25
26#include <sys/zfs_vfsops.h>
27#include <sys/zfs_vnops.h>
28#include <sys/zfs_znode.h>
ebe7e575 29#include <sys/zfs_ctldir.h>
51f0bbe4
BB
30#include <sys/zpl.h>
31
32
33static struct inode *
34zpl_inode_alloc(struct super_block *sb)
35{
36 struct inode *ip;
37
38 VERIFY3S(zfs_inode_alloc(sb, &ip), ==, 0);
18f57327 39 inode_set_iversion(ip, 1);
51f0bbe4
BB
40
41 return (ip);
42}
43
44static void
45zpl_inode_destroy(struct inode *ip)
46{
d1d7e268 47 ASSERT(atomic_read(&ip->i_count) == 0);
51f0bbe4
BB
48 zfs_inode_destroy(ip);
49}
50
8780c539
BB
51/*
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.
55 */
56#ifdef HAVE_DIRTY_INODE_WITH_FLAGS
57static void
58zpl_dirty_inode(struct inode *ip, int flags)
59{
a438ff0e
BB
60 fstrans_cookie_t cookie;
61
62 cookie = spl_fstrans_mark();
8780c539 63 zfs_dirty_inode(ip, flags);
a438ff0e 64 spl_fstrans_unmark(cookie);
8780c539
BB
65}
66#else
67static void
68zpl_dirty_inode(struct inode *ip)
69{
a438ff0e
BB
70 fstrans_cookie_t cookie;
71
72 cookie = spl_fstrans_mark();
8780c539 73 zfs_dirty_inode(ip, 0);
a438ff0e 74 spl_fstrans_unmark(cookie);
8780c539
BB
75}
76#endif /* HAVE_DIRTY_INODE_WITH_FLAGS */
77
2c395def
BB
78/*
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
82 * immediately.
83 *
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.
90 *
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
739a1a82
RY
94 * be in a state where it can simply be freed.i
95 *
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().
2c395def
BB
103 * remaining filesystem specific data.
104 */
105#ifdef HAVE_EVICT_INODE
51f0bbe4 106static void
2c395def 107zpl_evict_inode(struct inode *ip)
51f0bbe4 108{
7f3e4662
BB
109 fstrans_cookie_t cookie;
110
111 cookie = spl_fstrans_mark();
b3129792 112 truncate_setsize(ip, 0);
739a1a82 113 clear_inode(ip);
2c395def 114 zfs_inactive(ip);
7f3e4662 115 spl_fstrans_unmark(cookie);
51f0bbe4
BB
116}
117
2c395def
BB
118#else
119
2cbb06b5
BB
120static void
121zpl_drop_inode(struct inode *ip)
122{
123 generic_delete_inode(ip);
124}
125
51f0bbe4 126static void
2c395def 127zpl_clear_inode(struct inode *ip)
51f0bbe4 128{
7f3e4662
BB
129 fstrans_cookie_t cookie;
130
131 cookie = spl_fstrans_mark();
51f0bbe4 132 zfs_inactive(ip);
7f3e4662 133 spl_fstrans_unmark(cookie);
51f0bbe4
BB
134}
135
2c395def
BB
136static void
137zpl_inode_delete(struct inode *ip)
138{
b3129792 139 truncate_setsize(ip, 0);
2c395def
BB
140 clear_inode(ip);
141}
2c395def
BB
142#endif /* HAVE_EVICT_INODE */
143
51f0bbe4
BB
144static void
145zpl_put_super(struct super_block *sb)
146{
7fad6290 147 fstrans_cookie_t cookie;
51f0bbe4
BB
148 int error;
149
7fad6290 150 cookie = spl_fstrans_mark();
51f0bbe4 151 error = -zfs_umount(sb);
7fad6290 152 spl_fstrans_unmark(cookie);
51f0bbe4
BB
153 ASSERT3S(error, <=, 0);
154}
155
03f9ba9d
BB
156static int
157zpl_sync_fs(struct super_block *sb, int wait)
158{
7fad6290 159 fstrans_cookie_t cookie;
0d3ac5e7 160 cred_t *cr = CRED();
03f9ba9d
BB
161 int error;
162
0d3ac5e7 163 crhold(cr);
7fad6290 164 cookie = spl_fstrans_mark();
03f9ba9d 165 error = -zfs_sync(sb, wait, cr);
7fad6290 166 spl_fstrans_unmark(cookie);
0d3ac5e7 167 crfree(cr);
03f9ba9d
BB
168 ASSERT3S(error, <=, 0);
169
170 return (error);
171}
172
51f0bbe4
BB
173static int
174zpl_statfs(struct dentry *dentry, struct kstatfs *statp)
175{
7fad6290 176 fstrans_cookie_t cookie;
51f0bbe4
BB
177 int error;
178
7fad6290 179 cookie = spl_fstrans_mark();
51f0bbe4 180 error = -zfs_statvfs(dentry, statp);
7fad6290 181 spl_fstrans_unmark(cookie);
51f0bbe4
BB
182 ASSERT3S(error, <=, 0);
183
e897a23e
BB
184 /*
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.
189 */
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;
195
196 statp->f_blocks >>= 1;
197 statp->f_bfree >>= 1;
198 statp->f_bavail >>= 1;
199 }
200
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;
204 }
205
51f0bbe4
BB
206 return (error);
207}
208
0de19dad
BB
209static int
210zpl_remount_fs(struct super_block *sb, int *flags, char *data)
211{
1c2555ef 212 zfs_mnt_t zm = { .mnt_osname = NULL, .mnt_data = data };
7fad6290 213 fstrans_cookie_t cookie;
0de19dad 214 int error;
7fad6290
BB
215
216 cookie = spl_fstrans_mark();
1c2555ef 217 error = -zfs_remount(sb, flags, &zm);
7fad6290 218 spl_fstrans_unmark(cookie);
0de19dad
BB
219 ASSERT3S(error, <=, 0);
220
221 return (error);
222}
223
51f0bbe4 224static int
0037b49e 225__zpl_show_options(struct seq_file *seq, zfsvfs_t *zfsvfs)
51f0bbe4 226{
0037b49e
BB
227 seq_printf(seq, ",%s",
228 zfsvfs->z_flags & ZSB_XATTR ? "xattr" : "noxattr");
47621f3d 229
b695c34e 230#ifdef CONFIG_FS_POSIX_ACL
0037b49e 231 switch (zfsvfs->z_acl_type) {
023699cd
MM
232 case ZFS_ACLTYPE_POSIXACL:
233 seq_puts(seq, ",posixacl");
234 break;
235 default:
236 seq_puts(seq, ",noacl");
237 break;
238 }
b695c34e 239#endif /* CONFIG_FS_POSIX_ACL */
023699cd 240
47621f3d
BB
241 return (0);
242}
023699cd
MM
243
244#ifdef HAVE_SHOW_OPTIONS_WITH_DENTRY
245static int
246zpl_show_options(struct seq_file *seq, struct dentry *root)
247{
d1d7e268 248 return (__zpl_show_options(seq, root->d_sb->s_fs_info));
023699cd 249}
47621f3d
BB
250#else
251static int
252zpl_show_options(struct seq_file *seq, struct vfsmount *vfsp)
253{
d1d7e268 254 return (__zpl_show_options(seq, vfsp->mnt_sb->s_fs_info));
51f0bbe4 255}
47621f3d 256#endif /* HAVE_SHOW_OPTIONS_WITH_DENTRY */
51f0bbe4
BB
257
258static int
259zpl_fill_super(struct super_block *sb, void *data, int silent)
260{
1c2555ef 261 zfs_mnt_t *zm = (zfs_mnt_t *)data;
7fad6290 262 fstrans_cookie_t cookie;
51f0bbe4
BB
263 int error;
264
7fad6290 265 cookie = spl_fstrans_mark();
1c2555ef 266 error = -zfs_domount(sb, zm, silent);
7fad6290 267 spl_fstrans_unmark(cookie);
51f0bbe4
BB
268 ASSERT3S(error, <=, 0);
269
270 return (error);
271}
272
93b43af1
SF
273static int
274zpl_test_super(struct super_block *s, void *data)
275{
276 zfsvfs_t *zfsvfs = s->s_fs_info;
277 objset_t *os = data;
278
279 if (zfsvfs == NULL)
280 return (0);
281
282 return (os == zfsvfs->z_os);
283}
284
285static struct super_block *
286zpl_mount_impl(struct file_system_type *fs_type, int flags, zfs_mnt_t *zm)
287{
288 struct super_block *s;
289 objset_t *os;
290 int err;
291
292 err = dmu_objset_hold(zm->mnt_osname, FTAG, &os);
293 if (err)
294 return (ERR_PTR(-err));
295
ac09630d
BB
296 /*
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
e1cfd73f 300 * a txg sync. If the dsl_pool lock is held over sget()
ac09630d
BB
301 * this can prevent the pool sync and cause a deadlock.
302 */
303 dsl_pool_rele(dmu_objset_pool(os), FTAG);
93b43af1 304 s = zpl_sget(fs_type, zpl_test_super, set_anon_super, flags, os);
ac09630d
BB
305 dsl_dataset_rele(dmu_objset_ds(os), FTAG);
306
93b43af1
SF
307 if (IS_ERR(s))
308 return (ERR_CAST(s));
309
310 if (s->s_root == NULL) {
311 err = zpl_fill_super(s, zm, flags & SB_SILENT ? 1 : 0);
312 if (err) {
313 deactivate_locked_super(s);
314 return (ERR_PTR(err));
315 }
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));
320 }
321
322 return (s);
323}
324
325#ifdef HAVE_FST_MOUNT
2cf7f52b
BB
326static struct dentry *
327zpl_mount(struct file_system_type *fs_type, int flags,
328 const char *osname, void *data)
329{
1c2555ef 330 zfs_mnt_t zm = { .mnt_osname = osname, .mnt_data = data };
2cf7f52b 331
93b43af1
SF
332 struct super_block *sb = zpl_mount_impl(fs_type, flags, &zm);
333 if (IS_ERR(sb))
334 return (ERR_CAST(sb));
335
336 return (dget(sb->s_root));
2cf7f52b
BB
337}
338#else
51f0bbe4
BB
339static int
340zpl_get_sb(struct file_system_type *fs_type, int flags,
341 const char *osname, void *data, struct vfsmount *mnt)
342{
1c2555ef 343 zfs_mnt_t zm = { .mnt_osname = osname, .mnt_data = data };
51f0bbe4 344
93b43af1
SF
345 struct super_block *sb = zpl_mount_impl(fs_type, flags, &zm);
346 if (IS_ERR(sb))
347 return (PTR_ERR(sb));
348
349 (void) simple_set_mnt(mnt, sb);
350
351 return (0);
51f0bbe4 352}
93b43af1 353#endif /* HAVE_FST_MOUNT */
51f0bbe4
BB
354
355static void
356zpl_kill_sb(struct super_block *sb)
357{
ebe7e575 358 zfs_preumount(sb);
51f0bbe4 359 kill_anon_super(sb);
dba1d705
BB
360
361#ifdef HAVE_S_INSTANCES_LIST_HEAD
362 sb->s_instances.next = &(zpl_fs_type.fs_supers);
363#endif /* HAVE_S_INSTANCES_LIST_HEAD */
51f0bbe4
BB
364}
365
ab26409d 366void
2cbb06b5 367zpl_prune_sb(int64_t nr_to_scan, void *arg)
ab26409d 368{
2cbb06b5
BB
369 struct super_block *sb = (struct super_block *)arg;
370 int objects = 0;
ab26409d 371
f298b24d 372 (void) -zfs_prune(sb, nr_to_scan, &objects);
050d22b0 373}
ab26409d
BB
374
375#ifdef HAVE_NR_CACHED_OBJECTS
376static int
377zpl_nr_cached_objects(struct super_block *sb)
378{
04870568 379 return (0);
ab26409d
BB
380}
381#endif /* HAVE_NR_CACHED_OBJECTS */
382
383#ifdef HAVE_FREE_CACHED_OBJECTS
ab26409d
BB
384static void
385zpl_free_cached_objects(struct super_block *sb, int nr_to_scan)
386{
94520ca4 387 /* noop */
ab26409d
BB
388}
389#endif /* HAVE_FREE_CACHED_OBJECTS */
390
51f0bbe4 391const struct super_operations zpl_super_operations = {
ab26409d
BB
392 .alloc_inode = zpl_inode_alloc,
393 .destroy_inode = zpl_inode_destroy,
8780c539 394 .dirty_inode = zpl_dirty_inode,
ab26409d 395 .write_inode = NULL,
2c395def 396#ifdef HAVE_EVICT_INODE
ab26409d 397 .evict_inode = zpl_evict_inode,
2c395def 398#else
2cbb06b5 399 .drop_inode = zpl_drop_inode,
ab26409d
BB
400 .clear_inode = zpl_clear_inode,
401 .delete_inode = zpl_inode_delete,
2c395def 402#endif /* HAVE_EVICT_INODE */
ab26409d 403 .put_super = zpl_put_super,
ab26409d
BB
404 .sync_fs = zpl_sync_fs,
405 .statfs = zpl_statfs,
406 .remount_fs = zpl_remount_fs,
407 .show_options = zpl_show_options,
408 .show_stats = NULL,
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 */
51f0bbe4
BB
415};
416
51f0bbe4 417struct file_system_type zpl_fs_type = {
ab26409d
BB
418 .owner = THIS_MODULE,
419 .name = ZFS_DRIVER,
93b43af1 420#ifdef HAVE_FST_MOUNT
ab26409d 421 .mount = zpl_mount,
2cf7f52b 422#else
ab26409d 423 .get_sb = zpl_get_sb,
93b43af1 424#endif /* HAVE_FST_MOUNT */
ab26409d 425 .kill_sb = zpl_kill_sb,
51f0bbe4 426};