]> git.proxmox.com Git - mirror_zfs-debian.git/blame - module/zfs/zpl_super.c
New upstream version 0.7.9
[mirror_zfs-debian.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);
42f7b73b 39 inode_set_iversion(ip, 1);
51f0bbe4
BB
40
41 return (ip);
42}
43
44static void
45zpl_inode_destroy(struct inode *ip)
46{
a08ee875 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{
ea04106b
AX
60 fstrans_cookie_t cookie;
61
62 cookie = spl_fstrans_mark();
8780c539 63 zfs_dirty_inode(ip, flags);
ea04106b 64 spl_fstrans_unmark(cookie);
8780c539
BB
65}
66#else
67static void
68zpl_dirty_inode(struct inode *ip)
69{
ea04106b
AX
70 fstrans_cookie_t cookie;
71
72 cookie = spl_fstrans_mark();
8780c539 73 zfs_dirty_inode(ip, 0);
ea04106b 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{
ea04106b
AX
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);
ea04106b 115 spl_fstrans_unmark(cookie);
51f0bbe4
BB
116}
117
2c395def
BB
118#else
119
ea04106b
AX
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{
ea04106b
AX
129 fstrans_cookie_t cookie;
130
131 cookie = spl_fstrans_mark();
51f0bbe4 132 zfs_inactive(ip);
ea04106b 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{
ea04106b 147 fstrans_cookie_t cookie;
51f0bbe4
BB
148 int error;
149
ea04106b 150 cookie = spl_fstrans_mark();
51f0bbe4 151 error = -zfs_umount(sb);
ea04106b 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{
ea04106b 159 fstrans_cookie_t cookie;
0d3ac5e7 160 cred_t *cr = CRED();
03f9ba9d
BB
161 int error;
162
0d3ac5e7 163 crhold(cr);
ea04106b 164 cookie = spl_fstrans_mark();
03f9ba9d 165 error = -zfs_sync(sb, wait, cr);
ea04106b 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{
ea04106b 176 fstrans_cookie_t cookie;
51f0bbe4
BB
177 int error;
178
ea04106b 179 cookie = spl_fstrans_mark();
51f0bbe4 180 error = -zfs_statvfs(dentry, statp);
ea04106b 181 spl_fstrans_unmark(cookie);
51f0bbe4
BB
182 ASSERT3S(error, <=, 0);
183
184 return (error);
185}
186
0de19dad
BB
187static int
188zpl_remount_fs(struct super_block *sb, int *flags, char *data)
189{
cae5b340 190 zfs_mnt_t zm = { .mnt_osname = NULL, .mnt_data = data };
ea04106b 191 fstrans_cookie_t cookie;
0de19dad 192 int error;
ea04106b
AX
193
194 cookie = spl_fstrans_mark();
cae5b340 195 error = -zfs_remount(sb, flags, &zm);
ea04106b 196 spl_fstrans_unmark(cookie);
0de19dad
BB
197 ASSERT3S(error, <=, 0);
198
199 return (error);
200}
201
51f0bbe4 202static int
cae5b340 203__zpl_show_options(struct seq_file *seq, zfsvfs_t *zfsvfs)
51f0bbe4 204{
cae5b340
AX
205 seq_printf(seq, ",%s",
206 zfsvfs->z_flags & ZSB_XATTR ? "xattr" : "noxattr");
47621f3d 207
a08ee875 208#ifdef CONFIG_FS_POSIX_ACL
cae5b340 209 switch (zfsvfs->z_acl_type) {
a08ee875
LG
210 case ZFS_ACLTYPE_POSIXACL:
211 seq_puts(seq, ",posixacl");
212 break;
213 default:
214 seq_puts(seq, ",noacl");
215 break;
216 }
217#endif /* CONFIG_FS_POSIX_ACL */
218
47621f3d
BB
219 return (0);
220}
a08ee875
LG
221
222#ifdef HAVE_SHOW_OPTIONS_WITH_DENTRY
223static int
224zpl_show_options(struct seq_file *seq, struct dentry *root)
225{
226 return (__zpl_show_options(seq, root->d_sb->s_fs_info));
227}
47621f3d
BB
228#else
229static int
230zpl_show_options(struct seq_file *seq, struct vfsmount *vfsp)
231{
a08ee875 232 return (__zpl_show_options(seq, vfsp->mnt_sb->s_fs_info));
51f0bbe4 233}
47621f3d 234#endif /* HAVE_SHOW_OPTIONS_WITH_DENTRY */
51f0bbe4
BB
235
236static int
237zpl_fill_super(struct super_block *sb, void *data, int silent)
238{
cae5b340 239 zfs_mnt_t *zm = (zfs_mnt_t *)data;
ea04106b 240 fstrans_cookie_t cookie;
51f0bbe4
BB
241 int error;
242
ea04106b 243 cookie = spl_fstrans_mark();
cae5b340 244 error = -zfs_domount(sb, zm, silent);
ea04106b 245 spl_fstrans_unmark(cookie);
51f0bbe4
BB
246 ASSERT3S(error, <=, 0);
247
248 return (error);
249}
250
42f7b73b
AX
251static int
252zpl_test_super(struct super_block *s, void *data)
253{
254 zfsvfs_t *zfsvfs = s->s_fs_info;
255 objset_t *os = data;
256
257 if (zfsvfs == NULL)
258 return (0);
259
260 return (os == zfsvfs->z_os);
261}
262
263static struct super_block *
264zpl_mount_impl(struct file_system_type *fs_type, int flags, zfs_mnt_t *zm)
265{
266 struct super_block *s;
267 objset_t *os;
268 int err;
269
270 err = dmu_objset_hold(zm->mnt_osname, FTAG, &os);
271 if (err)
272 return (ERR_PTR(-err));
273
274 s = zpl_sget(fs_type, zpl_test_super, set_anon_super, flags, os);
275 dmu_objset_rele(os, FTAG);
276 if (IS_ERR(s))
277 return (ERR_CAST(s));
278
279 if (s->s_root == NULL) {
280 err = zpl_fill_super(s, zm, flags & SB_SILENT ? 1 : 0);
281 if (err) {
282 deactivate_locked_super(s);
283 return (ERR_PTR(err));
284 }
285 s->s_flags |= SB_ACTIVE;
286 } else if ((flags ^ s->s_flags) & SB_RDONLY) {
287 deactivate_locked_super(s);
288 return (ERR_PTR(-EBUSY));
289 }
290
291 return (s);
292}
293
294#ifdef HAVE_FST_MOUNT
2cf7f52b
BB
295static struct dentry *
296zpl_mount(struct file_system_type *fs_type, int flags,
297 const char *osname, void *data)
298{
cae5b340 299 zfs_mnt_t zm = { .mnt_osname = osname, .mnt_data = data };
2cf7f52b 300
42f7b73b
AX
301 struct super_block *sb = zpl_mount_impl(fs_type, flags, &zm);
302 if (IS_ERR(sb))
303 return (ERR_CAST(sb));
304
305 return (dget(sb->s_root));
2cf7f52b
BB
306}
307#else
51f0bbe4
BB
308static int
309zpl_get_sb(struct file_system_type *fs_type, int flags,
310 const char *osname, void *data, struct vfsmount *mnt)
311{
cae5b340 312 zfs_mnt_t zm = { .mnt_osname = osname, .mnt_data = data };
51f0bbe4 313
42f7b73b
AX
314 struct super_block *sb = zpl_mount_impl(fs_type, flags, &zm);
315 if (IS_ERR(sb))
316 return (PTR_ERR(sb));
317
318 (void) simple_set_mnt(mnt, sb);
319
320 return (0);
51f0bbe4 321}
42f7b73b 322#endif /* HAVE_FST_MOUNT */
51f0bbe4
BB
323
324static void
325zpl_kill_sb(struct super_block *sb)
326{
ebe7e575 327 zfs_preumount(sb);
51f0bbe4 328 kill_anon_super(sb);
c06d4368
AX
329
330#ifdef HAVE_S_INSTANCES_LIST_HEAD
331 sb->s_instances.next = &(zpl_fs_type.fs_supers);
332#endif /* HAVE_S_INSTANCES_LIST_HEAD */
51f0bbe4
BB
333}
334
ab26409d 335void
ea04106b 336zpl_prune_sb(int64_t nr_to_scan, void *arg)
ab26409d 337{
ea04106b
AX
338 struct super_block *sb = (struct super_block *)arg;
339 int objects = 0;
ab26409d 340
cae5b340 341 (void) -zfs_prune(sb, nr_to_scan, &objects);
ab26409d 342}
ab26409d
BB
343
344#ifdef HAVE_NR_CACHED_OBJECTS
345static int
346zpl_nr_cached_objects(struct super_block *sb)
347{
e10b0808 348 return (0);
ab26409d
BB
349}
350#endif /* HAVE_NR_CACHED_OBJECTS */
351
352#ifdef HAVE_FREE_CACHED_OBJECTS
ab26409d
BB
353static void
354zpl_free_cached_objects(struct super_block *sb, int nr_to_scan)
355{
ea04106b 356 /* noop */
ab26409d
BB
357}
358#endif /* HAVE_FREE_CACHED_OBJECTS */
359
51f0bbe4 360const struct super_operations zpl_super_operations = {
ab26409d
BB
361 .alloc_inode = zpl_inode_alloc,
362 .destroy_inode = zpl_inode_destroy,
8780c539 363 .dirty_inode = zpl_dirty_inode,
ab26409d 364 .write_inode = NULL,
2c395def 365#ifdef HAVE_EVICT_INODE
ab26409d 366 .evict_inode = zpl_evict_inode,
2c395def 367#else
ea04106b 368 .drop_inode = zpl_drop_inode,
ab26409d
BB
369 .clear_inode = zpl_clear_inode,
370 .delete_inode = zpl_inode_delete,
2c395def 371#endif /* HAVE_EVICT_INODE */
ab26409d 372 .put_super = zpl_put_super,
ab26409d
BB
373 .sync_fs = zpl_sync_fs,
374 .statfs = zpl_statfs,
375 .remount_fs = zpl_remount_fs,
376 .show_options = zpl_show_options,
377 .show_stats = NULL,
378#ifdef HAVE_NR_CACHED_OBJECTS
379 .nr_cached_objects = zpl_nr_cached_objects,
380#endif /* HAVE_NR_CACHED_OBJECTS */
381#ifdef HAVE_FREE_CACHED_OBJECTS
382 .free_cached_objects = zpl_free_cached_objects,
383#endif /* HAVE_FREE_CACHED_OBJECTS */
51f0bbe4
BB
384};
385
51f0bbe4 386struct file_system_type zpl_fs_type = {
ab26409d
BB
387 .owner = THIS_MODULE,
388 .name = ZFS_DRIVER,
42f7b73b 389#ifdef HAVE_FST_MOUNT
ab26409d 390 .mount = zpl_mount,
2cf7f52b 391#else
ab26409d 392 .get_sb = zpl_get_sb,
42f7b73b 393#endif /* HAVE_FST_MOUNT */
ab26409d 394 .kill_sb = zpl_kill_sb,
51f0bbe4 395};