xref: /freebsd-src/sys/contrib/openzfs/module/os/linux/zfs/zpl_super.c (revision 718519f4efc71096422fc71dab90b2a3369871ff)
1eda14cbcSMatt Macy /*
2eda14cbcSMatt Macy  * CDDL HEADER START
3eda14cbcSMatt Macy  *
4eda14cbcSMatt Macy  * The contents of this file are subject to the terms of the
5eda14cbcSMatt Macy  * Common Development and Distribution License (the "License").
6eda14cbcSMatt Macy  * You may not use this file except in compliance with the License.
7eda14cbcSMatt Macy  *
8eda14cbcSMatt Macy  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9271171e0SMartin Matuska  * or https://opensource.org/licenses/CDDL-1.0.
10eda14cbcSMatt Macy  * See the License for the specific language governing permissions
11eda14cbcSMatt Macy  * and limitations under the License.
12eda14cbcSMatt Macy  *
13eda14cbcSMatt Macy  * When distributing Covered Code, include this CDDL HEADER in each
14eda14cbcSMatt Macy  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15eda14cbcSMatt Macy  * If applicable, add the following below this CDDL HEADER, with the
16eda14cbcSMatt Macy  * fields enclosed by brackets "[]" replaced with your own identifying
17eda14cbcSMatt Macy  * information: Portions Copyright [yyyy] [name of copyright owner]
18eda14cbcSMatt Macy  *
19eda14cbcSMatt Macy  * CDDL HEADER END
20eda14cbcSMatt Macy  */
21eda14cbcSMatt Macy /*
22eda14cbcSMatt Macy  * Copyright (c) 2011, Lawrence Livermore National Security, LLC.
232a58b312SMartin Matuska  * Copyright (c) 2023, Datto Inc. All rights reserved.
24eda14cbcSMatt Macy  */
25eda14cbcSMatt Macy 
26eda14cbcSMatt Macy 
27eda14cbcSMatt Macy #include <sys/zfs_znode.h>
28eda14cbcSMatt Macy #include <sys/zfs_vfsops.h>
29eda14cbcSMatt Macy #include <sys/zfs_vnops.h>
30eda14cbcSMatt Macy #include <sys/zfs_ctldir.h>
31eda14cbcSMatt Macy #include <sys/zpl.h>
327a7741afSMartin Matuska #include <linux/iversion.h>
33eda14cbcSMatt Macy 
34eda14cbcSMatt Macy 
35eda14cbcSMatt Macy static struct inode *
36eda14cbcSMatt Macy zpl_inode_alloc(struct super_block *sb)
37eda14cbcSMatt Macy {
38eda14cbcSMatt Macy 	struct inode *ip;
39eda14cbcSMatt Macy 
40eda14cbcSMatt Macy 	VERIFY3S(zfs_inode_alloc(sb, &ip), ==, 0);
41eda14cbcSMatt Macy 	inode_set_iversion(ip, 1);
42eda14cbcSMatt Macy 
43eda14cbcSMatt Macy 	return (ip);
44eda14cbcSMatt Macy }
45eda14cbcSMatt Macy 
46eda14cbcSMatt Macy static void
47eda14cbcSMatt Macy zpl_inode_destroy(struct inode *ip)
48eda14cbcSMatt Macy {
49eda14cbcSMatt Macy 	ASSERT(atomic_read(&ip->i_count) == 0);
50eda14cbcSMatt Macy 	zfs_inode_destroy(ip);
51eda14cbcSMatt Macy }
52eda14cbcSMatt Macy 
53eda14cbcSMatt Macy /*
54eda14cbcSMatt Macy  * Called from __mark_inode_dirty() to reflect that something in the
55eda14cbcSMatt Macy  * inode has changed.  We use it to ensure the znode system attributes
56eda14cbcSMatt Macy  * are always strictly update to date with respect to the inode.
57eda14cbcSMatt Macy  */
58eda14cbcSMatt Macy static void
59eda14cbcSMatt Macy zpl_dirty_inode(struct inode *ip, int flags)
60eda14cbcSMatt Macy {
61eda14cbcSMatt Macy 	fstrans_cookie_t cookie;
62eda14cbcSMatt Macy 
63eda14cbcSMatt Macy 	cookie = spl_fstrans_mark();
64eda14cbcSMatt Macy 	zfs_dirty_inode(ip, flags);
65eda14cbcSMatt Macy 	spl_fstrans_unmark(cookie);
66eda14cbcSMatt Macy }
67eda14cbcSMatt Macy 
68eda14cbcSMatt Macy /*
69eda14cbcSMatt Macy  * When ->drop_inode() is called its return value indicates if the
70eda14cbcSMatt Macy  * inode should be evicted from the inode cache.  If the inode is
71eda14cbcSMatt Macy  * unhashed and has no links the default policy is to evict it
72eda14cbcSMatt Macy  * immediately.
73eda14cbcSMatt Macy  *
74eda14cbcSMatt Macy  * The ->evict_inode() callback must minimally truncate the inode pages,
75eda14cbcSMatt Macy  * and call clear_inode().  For 2.6.35 and later kernels this will
76eda14cbcSMatt Macy  * simply update the inode state, with the sync occurring before the
77eda14cbcSMatt Macy  * truncate in evict().  For earlier kernels clear_inode() maps to
78eda14cbcSMatt Macy  * end_writeback() which is responsible for completing all outstanding
79eda14cbcSMatt Macy  * write back.  In either case, once this is done it is safe to cleanup
80eda14cbcSMatt Macy  * any remaining inode specific data via zfs_inactive().
81eda14cbcSMatt Macy  * remaining filesystem specific data.
82eda14cbcSMatt Macy  */
83eda14cbcSMatt Macy static void
84eda14cbcSMatt Macy zpl_evict_inode(struct inode *ip)
85eda14cbcSMatt Macy {
86eda14cbcSMatt Macy 	fstrans_cookie_t cookie;
87eda14cbcSMatt Macy 
88eda14cbcSMatt Macy 	cookie = spl_fstrans_mark();
89eda14cbcSMatt Macy 	truncate_setsize(ip, 0);
90eda14cbcSMatt Macy 	clear_inode(ip);
91eda14cbcSMatt Macy 	zfs_inactive(ip);
92eda14cbcSMatt Macy 	spl_fstrans_unmark(cookie);
93eda14cbcSMatt Macy }
94eda14cbcSMatt Macy 
95eda14cbcSMatt Macy static void
96eda14cbcSMatt Macy zpl_put_super(struct super_block *sb)
97eda14cbcSMatt Macy {
98eda14cbcSMatt Macy 	fstrans_cookie_t cookie;
99eda14cbcSMatt Macy 	int error;
100eda14cbcSMatt Macy 
101eda14cbcSMatt Macy 	cookie = spl_fstrans_mark();
102eda14cbcSMatt Macy 	error = -zfs_umount(sb);
103eda14cbcSMatt Macy 	spl_fstrans_unmark(cookie);
104eda14cbcSMatt Macy 	ASSERT3S(error, <=, 0);
105eda14cbcSMatt Macy }
106eda14cbcSMatt Macy 
107eda14cbcSMatt Macy static int
108eda14cbcSMatt Macy zpl_sync_fs(struct super_block *sb, int wait)
109eda14cbcSMatt Macy {
110eda14cbcSMatt Macy 	fstrans_cookie_t cookie;
111eda14cbcSMatt Macy 	cred_t *cr = CRED();
112eda14cbcSMatt Macy 	int error;
113eda14cbcSMatt Macy 
114eda14cbcSMatt Macy 	crhold(cr);
115eda14cbcSMatt Macy 	cookie = spl_fstrans_mark();
116eda14cbcSMatt Macy 	error = -zfs_sync(sb, wait, cr);
117eda14cbcSMatt Macy 	spl_fstrans_unmark(cookie);
118eda14cbcSMatt Macy 	crfree(cr);
119eda14cbcSMatt Macy 	ASSERT3S(error, <=, 0);
120eda14cbcSMatt Macy 
121eda14cbcSMatt Macy 	return (error);
122eda14cbcSMatt Macy }
123eda14cbcSMatt Macy 
124eda14cbcSMatt Macy static int
125eda14cbcSMatt Macy zpl_statfs(struct dentry *dentry, struct kstatfs *statp)
126eda14cbcSMatt Macy {
127eda14cbcSMatt Macy 	fstrans_cookie_t cookie;
128eda14cbcSMatt Macy 	int error;
129eda14cbcSMatt Macy 
130eda14cbcSMatt Macy 	cookie = spl_fstrans_mark();
131eda14cbcSMatt Macy 	error = -zfs_statvfs(dentry->d_inode, statp);
132eda14cbcSMatt Macy 	spl_fstrans_unmark(cookie);
133eda14cbcSMatt Macy 	ASSERT3S(error, <=, 0);
134eda14cbcSMatt Macy 
135eda14cbcSMatt Macy 	/*
136eda14cbcSMatt Macy 	 * If required by a 32-bit system call, dynamically scale the
137eda14cbcSMatt Macy 	 * block size up to 16MiB and decrease the block counts.  This
138eda14cbcSMatt Macy 	 * allows for a maximum size of 64EiB to be reported.  The file
139eda14cbcSMatt Macy 	 * counts must be artificially capped at 2^32-1.
140eda14cbcSMatt Macy 	 */
141eda14cbcSMatt Macy 	if (unlikely(zpl_is_32bit_api())) {
142eda14cbcSMatt Macy 		while (statp->f_blocks > UINT32_MAX &&
143eda14cbcSMatt Macy 		    statp->f_bsize < SPA_MAXBLOCKSIZE) {
144eda14cbcSMatt Macy 			statp->f_frsize <<= 1;
145eda14cbcSMatt Macy 			statp->f_bsize <<= 1;
146eda14cbcSMatt Macy 
147eda14cbcSMatt Macy 			statp->f_blocks >>= 1;
148eda14cbcSMatt Macy 			statp->f_bfree >>= 1;
149eda14cbcSMatt Macy 			statp->f_bavail >>= 1;
150eda14cbcSMatt Macy 		}
151eda14cbcSMatt Macy 
152eda14cbcSMatt Macy 		uint64_t usedobjs = statp->f_files - statp->f_ffree;
153eda14cbcSMatt Macy 		statp->f_ffree = MIN(statp->f_ffree, UINT32_MAX - usedobjs);
154eda14cbcSMatt Macy 		statp->f_files = statp->f_ffree + usedobjs;
155eda14cbcSMatt Macy 	}
156eda14cbcSMatt Macy 
157eda14cbcSMatt Macy 	return (error);
158eda14cbcSMatt Macy }
159eda14cbcSMatt Macy 
160eda14cbcSMatt Macy static int
161eda14cbcSMatt Macy zpl_remount_fs(struct super_block *sb, int *flags, char *data)
162eda14cbcSMatt Macy {
163eda14cbcSMatt Macy 	zfs_mnt_t zm = { .mnt_osname = NULL, .mnt_data = data };
164eda14cbcSMatt Macy 	fstrans_cookie_t cookie;
165eda14cbcSMatt Macy 	int error;
166eda14cbcSMatt Macy 
167eda14cbcSMatt Macy 	cookie = spl_fstrans_mark();
168eda14cbcSMatt Macy 	error = -zfs_remount(sb, flags, &zm);
169eda14cbcSMatt Macy 	spl_fstrans_unmark(cookie);
170eda14cbcSMatt Macy 	ASSERT3S(error, <=, 0);
171eda14cbcSMatt Macy 
172eda14cbcSMatt Macy 	return (error);
173eda14cbcSMatt Macy }
174eda14cbcSMatt Macy 
175eda14cbcSMatt Macy static int
176eac7052fSMatt Macy __zpl_show_devname(struct seq_file *seq, zfsvfs_t *zfsvfs)
177eac7052fSMatt Macy {
178c7046f76SMartin Matuska 	int error;
179c7046f76SMartin Matuska 	if ((error = zpl_enter(zfsvfs, FTAG)) != 0)
180c7046f76SMartin Matuska 		return (error);
181eac7052fSMatt Macy 
1827877fdebSMatt Macy 	char *fsname = kmem_alloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP);
183eac7052fSMatt Macy 	dmu_objset_name(zfsvfs->z_os, fsname);
1847877fdebSMatt Macy 
1857877fdebSMatt Macy 	for (int i = 0; fsname[i] != 0; i++) {
1867877fdebSMatt Macy 		/*
1877877fdebSMatt Macy 		 * Spaces in the dataset name must be converted to their
1887877fdebSMatt Macy 		 * octal escape sequence for getmntent(3) to correctly
1897877fdebSMatt Macy 		 * parse then fsname portion of /proc/self/mounts.
1907877fdebSMatt Macy 		 */
1917877fdebSMatt Macy 		if (fsname[i] == ' ') {
1927877fdebSMatt Macy 			seq_puts(seq, "\\040");
1937877fdebSMatt Macy 		} else {
1947877fdebSMatt Macy 			seq_putc(seq, fsname[i]);
1957877fdebSMatt Macy 		}
1967877fdebSMatt Macy 	}
1977877fdebSMatt Macy 
198eac7052fSMatt Macy 	kmem_free(fsname, ZFS_MAX_DATASET_NAME_LEN);
1997877fdebSMatt Macy 
200c7046f76SMartin Matuska 	zpl_exit(zfsvfs, FTAG);
201eac7052fSMatt Macy 
202eac7052fSMatt Macy 	return (0);
203eac7052fSMatt Macy }
204eac7052fSMatt Macy 
205eac7052fSMatt Macy static int
206eac7052fSMatt Macy zpl_show_devname(struct seq_file *seq, struct dentry *root)
207eac7052fSMatt Macy {
208eac7052fSMatt Macy 	return (__zpl_show_devname(seq, root->d_sb->s_fs_info));
209eac7052fSMatt Macy }
210eac7052fSMatt Macy 
211eac7052fSMatt Macy static int
212eda14cbcSMatt Macy __zpl_show_options(struct seq_file *seq, zfsvfs_t *zfsvfs)
213eda14cbcSMatt Macy {
214eda14cbcSMatt Macy 	seq_printf(seq, ",%s",
215eda14cbcSMatt Macy 	    zfsvfs->z_flags & ZSB_XATTR ? "xattr" : "noxattr");
216eda14cbcSMatt Macy 
217eda14cbcSMatt Macy #ifdef CONFIG_FS_POSIX_ACL
218eda14cbcSMatt Macy 	switch (zfsvfs->z_acl_type) {
2192c48331dSMatt Macy 	case ZFS_ACLTYPE_POSIX:
220eda14cbcSMatt Macy 		seq_puts(seq, ",posixacl");
221eda14cbcSMatt Macy 		break;
222eda14cbcSMatt Macy 	default:
223eda14cbcSMatt Macy 		seq_puts(seq, ",noacl");
224eda14cbcSMatt Macy 		break;
225eda14cbcSMatt Macy 	}
226eda14cbcSMatt Macy #endif /* CONFIG_FS_POSIX_ACL */
227eda14cbcSMatt Macy 
228271171e0SMartin Matuska 	switch (zfsvfs->z_case) {
229271171e0SMartin Matuska 	case ZFS_CASE_SENSITIVE:
230271171e0SMartin Matuska 		seq_puts(seq, ",casesensitive");
231271171e0SMartin Matuska 		break;
232271171e0SMartin Matuska 	case ZFS_CASE_INSENSITIVE:
233271171e0SMartin Matuska 		seq_puts(seq, ",caseinsensitive");
234271171e0SMartin Matuska 		break;
235271171e0SMartin Matuska 	default:
236271171e0SMartin Matuska 		seq_puts(seq, ",casemixed");
237271171e0SMartin Matuska 		break;
238271171e0SMartin Matuska 	}
239271171e0SMartin Matuska 
240eda14cbcSMatt Macy 	return (0);
241eda14cbcSMatt Macy }
242eda14cbcSMatt Macy 
243eda14cbcSMatt Macy static int
244eda14cbcSMatt Macy zpl_show_options(struct seq_file *seq, struct dentry *root)
245eda14cbcSMatt Macy {
246eda14cbcSMatt Macy 	return (__zpl_show_options(seq, root->d_sb->s_fs_info));
247eda14cbcSMatt Macy }
248eda14cbcSMatt Macy 
249eda14cbcSMatt Macy static int
250eda14cbcSMatt Macy zpl_fill_super(struct super_block *sb, void *data, int silent)
251eda14cbcSMatt Macy {
252eda14cbcSMatt Macy 	zfs_mnt_t *zm = (zfs_mnt_t *)data;
253eda14cbcSMatt Macy 	fstrans_cookie_t cookie;
254eda14cbcSMatt Macy 	int error;
255eda14cbcSMatt Macy 
256eda14cbcSMatt Macy 	cookie = spl_fstrans_mark();
257eda14cbcSMatt Macy 	error = -zfs_domount(sb, zm, silent);
258eda14cbcSMatt Macy 	spl_fstrans_unmark(cookie);
259eda14cbcSMatt Macy 	ASSERT3S(error, <=, 0);
260eda14cbcSMatt Macy 
261eda14cbcSMatt Macy 	return (error);
262eda14cbcSMatt Macy }
263eda14cbcSMatt Macy 
264eda14cbcSMatt Macy static int
265eda14cbcSMatt Macy zpl_test_super(struct super_block *s, void *data)
266eda14cbcSMatt Macy {
267eda14cbcSMatt Macy 	zfsvfs_t *zfsvfs = s->s_fs_info;
268eda14cbcSMatt Macy 	objset_t *os = data;
2692a58b312SMartin Matuska 	/*
2702a58b312SMartin Matuska 	 * If the os doesn't match the z_os in the super_block, assume it is
2712a58b312SMartin Matuska 	 * not a match. Matching would imply a multimount of a dataset. It is
2722a58b312SMartin Matuska 	 * possible that during a multimount, there is a simultaneous operation
2732a58b312SMartin Matuska 	 * that changes the z_os, e.g., rollback, where the match will be
2742a58b312SMartin Matuska 	 * missed, but in that case the user will get an EBUSY.
2752a58b312SMartin Matuska 	 */
276315ee00fSMartin Matuska 	return (zfsvfs != NULL && os == zfsvfs->z_os);
277eda14cbcSMatt Macy }
278eda14cbcSMatt Macy 
279eda14cbcSMatt Macy static struct super_block *
280eda14cbcSMatt Macy zpl_mount_impl(struct file_system_type *fs_type, int flags, zfs_mnt_t *zm)
281eda14cbcSMatt Macy {
282eda14cbcSMatt Macy 	struct super_block *s;
283eda14cbcSMatt Macy 	objset_t *os;
284e2df9bb4SMartin Matuska 	boolean_t issnap = B_FALSE;
285eda14cbcSMatt Macy 	int err;
286eda14cbcSMatt Macy 
287eda14cbcSMatt Macy 	err = dmu_objset_hold(zm->mnt_osname, FTAG, &os);
288eda14cbcSMatt Macy 	if (err)
289eda14cbcSMatt Macy 		return (ERR_PTR(-err));
290eda14cbcSMatt Macy 
291eda14cbcSMatt Macy 	/*
292eda14cbcSMatt Macy 	 * The dsl pool lock must be released prior to calling sget().
293eda14cbcSMatt Macy 	 * It is possible sget() may block on the lock in grab_super()
294eda14cbcSMatt Macy 	 * while deactivate_super() holds that same lock and waits for
295eda14cbcSMatt Macy 	 * a txg sync.  If the dsl_pool lock is held over sget()
296eda14cbcSMatt Macy 	 * this can prevent the pool sync and cause a deadlock.
297eda14cbcSMatt Macy 	 */
2982c48331dSMatt Macy 	dsl_dataset_long_hold(dmu_objset_ds(os), FTAG);
299eda14cbcSMatt Macy 	dsl_pool_rele(dmu_objset_pool(os), FTAG);
3002c48331dSMatt Macy 
301eda14cbcSMatt Macy 	s = sget(fs_type, zpl_test_super, set_anon_super, flags, os);
3022c48331dSMatt Macy 
303315ee00fSMartin Matuska 	/*
304315ee00fSMartin Matuska 	 * Recheck with the lock held to prevent mounting the wrong dataset
305315ee00fSMartin Matuska 	 * since z_os can be stale when the teardown lock is held.
306315ee00fSMartin Matuska 	 *
307315ee00fSMartin Matuska 	 * We can't do this in zpl_test_super in since it's under spinlock and
308315ee00fSMartin Matuska 	 * also s_umount lock is not held there so it would race with
309315ee00fSMartin Matuska 	 * zfs_umount and zfsvfs can be freed.
310315ee00fSMartin Matuska 	 */
311315ee00fSMartin Matuska 	if (!IS_ERR(s) && s->s_fs_info != NULL) {
312315ee00fSMartin Matuska 		zfsvfs_t *zfsvfs = s->s_fs_info;
313315ee00fSMartin Matuska 		if (zpl_enter(zfsvfs, FTAG) == 0) {
314315ee00fSMartin Matuska 			if (os != zfsvfs->z_os)
315315ee00fSMartin Matuska 				err = -SET_ERROR(EBUSY);
316e2df9bb4SMartin Matuska 			issnap = zfsvfs->z_issnap;
317315ee00fSMartin Matuska 			zpl_exit(zfsvfs, FTAG);
318315ee00fSMartin Matuska 		} else {
319315ee00fSMartin Matuska 			err = -SET_ERROR(EBUSY);
320315ee00fSMartin Matuska 		}
321315ee00fSMartin Matuska 	}
3222c48331dSMatt Macy 	dsl_dataset_long_rele(dmu_objset_ds(os), FTAG);
323eda14cbcSMatt Macy 	dsl_dataset_rele(dmu_objset_ds(os), FTAG);
324eda14cbcSMatt Macy 
325eda14cbcSMatt Macy 	if (IS_ERR(s))
326eda14cbcSMatt Macy 		return (ERR_CAST(s));
327eda14cbcSMatt Macy 
328315ee00fSMartin Matuska 	if (err) {
329315ee00fSMartin Matuska 		deactivate_locked_super(s);
330315ee00fSMartin Matuska 		return (ERR_PTR(err));
331315ee00fSMartin Matuska 	}
332315ee00fSMartin Matuska 
333eda14cbcSMatt Macy 	if (s->s_root == NULL) {
334eda14cbcSMatt Macy 		err = zpl_fill_super(s, zm, flags & SB_SILENT ? 1 : 0);
335eda14cbcSMatt Macy 		if (err) {
336eda14cbcSMatt Macy 			deactivate_locked_super(s);
337eda14cbcSMatt Macy 			return (ERR_PTR(err));
338eda14cbcSMatt Macy 		}
339eda14cbcSMatt Macy 		s->s_flags |= SB_ACTIVE;
340e2df9bb4SMartin Matuska 	} else if (!issnap && ((flags ^ s->s_flags) & SB_RDONLY)) {
341e2df9bb4SMartin Matuska 		/*
342e2df9bb4SMartin Matuska 		 * Skip ro check for snap since snap is always ro regardless
343e2df9bb4SMartin Matuska 		 * ro flag is passed by mount or not.
344e2df9bb4SMartin Matuska 		 */
345eda14cbcSMatt Macy 		deactivate_locked_super(s);
346eda14cbcSMatt Macy 		return (ERR_PTR(-EBUSY));
347eda14cbcSMatt Macy 	}
348eda14cbcSMatt Macy 
349eda14cbcSMatt Macy 	return (s);
350eda14cbcSMatt Macy }
351eda14cbcSMatt Macy 
352eda14cbcSMatt Macy static struct dentry *
353eda14cbcSMatt Macy zpl_mount(struct file_system_type *fs_type, int flags,
354eda14cbcSMatt Macy     const char *osname, void *data)
355eda14cbcSMatt Macy {
356eda14cbcSMatt Macy 	zfs_mnt_t zm = { .mnt_osname = osname, .mnt_data = data };
357eda14cbcSMatt Macy 
358eda14cbcSMatt Macy 	struct super_block *sb = zpl_mount_impl(fs_type, flags, &zm);
359eda14cbcSMatt Macy 	if (IS_ERR(sb))
360eda14cbcSMatt Macy 		return (ERR_CAST(sb));
361eda14cbcSMatt Macy 
362eda14cbcSMatt Macy 	return (dget(sb->s_root));
363eda14cbcSMatt Macy }
364eda14cbcSMatt Macy 
365eda14cbcSMatt Macy static void
366eda14cbcSMatt Macy zpl_kill_sb(struct super_block *sb)
367eda14cbcSMatt Macy {
368eda14cbcSMatt Macy 	zfs_preumount(sb);
369eda14cbcSMatt Macy 	kill_anon_super(sb);
370eda14cbcSMatt Macy }
371eda14cbcSMatt Macy 
372eda14cbcSMatt Macy void
373f8b1db88SMartin Matuska zpl_prune_sb(uint64_t nr_to_scan, void *arg)
374eda14cbcSMatt Macy {
375eda14cbcSMatt Macy 	struct super_block *sb = (struct super_block *)arg;
376eda14cbcSMatt Macy 	int objects = 0;
377eda14cbcSMatt Macy 
378*718519f4SMartin Matuska 	/*
379*718519f4SMartin Matuska 	 * deactivate_locked_super calls shrinker_free and only then
380*718519f4SMartin Matuska 	 * sops->kill_sb cb, resulting in UAF on umount when trying to reach
381*718519f4SMartin Matuska 	 * for the shrinker functions in zpl_prune_sb of in-umount dataset.
382*718519f4SMartin Matuska 	 * Increment if s_active is not zero, but don't prune if it is -
383*718519f4SMartin Matuska 	 * umount could be underway.
384*718519f4SMartin Matuska 	 */
385*718519f4SMartin Matuska 	if (atomic_inc_not_zero(&sb->s_active)) {
386eda14cbcSMatt Macy 		(void) -zfs_prune(sb, nr_to_scan, &objects);
387*718519f4SMartin Matuska 		atomic_dec(&sb->s_active);
388*718519f4SMartin Matuska 	}
389*718519f4SMartin Matuska 
390eda14cbcSMatt Macy }
391eda14cbcSMatt Macy 
392eda14cbcSMatt Macy const struct super_operations zpl_super_operations = {
393eda14cbcSMatt Macy 	.alloc_inode		= zpl_inode_alloc,
394eda14cbcSMatt Macy 	.destroy_inode		= zpl_inode_destroy,
395eda14cbcSMatt Macy 	.dirty_inode		= zpl_dirty_inode,
396eda14cbcSMatt Macy 	.write_inode		= NULL,
397eda14cbcSMatt Macy 	.evict_inode		= zpl_evict_inode,
398eda14cbcSMatt Macy 	.put_super		= zpl_put_super,
399eda14cbcSMatt Macy 	.sync_fs		= zpl_sync_fs,
400eda14cbcSMatt Macy 	.statfs			= zpl_statfs,
401eda14cbcSMatt Macy 	.remount_fs		= zpl_remount_fs,
402eac7052fSMatt Macy 	.show_devname		= zpl_show_devname,
403eda14cbcSMatt Macy 	.show_options		= zpl_show_options,
404eda14cbcSMatt Macy 	.show_stats		= NULL,
405eda14cbcSMatt Macy };
406eda14cbcSMatt Macy 
407eda14cbcSMatt Macy struct file_system_type zpl_fs_type = {
408eda14cbcSMatt Macy 	.owner			= THIS_MODULE,
409eda14cbcSMatt Macy 	.name			= ZFS_DRIVER,
410dbd5678dSMartin Matuska #if defined(HAVE_IDMAP_MNT_API)
411dbd5678dSMartin Matuska 	.fs_flags		= FS_USERNS_MOUNT | FS_ALLOW_IDMAP,
412dbd5678dSMartin Matuska #else
4131f1e2261SMartin Matuska 	.fs_flags		= FS_USERNS_MOUNT,
414dbd5678dSMartin Matuska #endif
415eda14cbcSMatt Macy 	.mount			= zpl_mount,
416eda14cbcSMatt Macy 	.kill_sb		= zpl_kill_sb,
417eda14cbcSMatt Macy };
418