xref: /dflybsd-src/sys/vfs/hammer/hammer_vfsops.c (revision 77062c8a3b75f492d0a239470f367a11ae226799)
1427e5fc6SMatthew Dillon /*
2b84de5afSMatthew Dillon  * Copyright (c) 2007-2008 The DragonFly Project.  All rights reserved.
3427e5fc6SMatthew Dillon  *
4427e5fc6SMatthew Dillon  * This code is derived from software contributed to The DragonFly Project
5427e5fc6SMatthew Dillon  * by Matthew Dillon <dillon@backplane.com>
6427e5fc6SMatthew Dillon  *
7427e5fc6SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
8427e5fc6SMatthew Dillon  * modification, are permitted provided that the following conditions
9427e5fc6SMatthew Dillon  * are met:
10427e5fc6SMatthew Dillon  *
11427e5fc6SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
12427e5fc6SMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
13427e5fc6SMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
14427e5fc6SMatthew Dillon  *    notice, this list of conditions and the following disclaimer in
15427e5fc6SMatthew Dillon  *    the documentation and/or other materials provided with the
16427e5fc6SMatthew Dillon  *    distribution.
17427e5fc6SMatthew Dillon  * 3. Neither the name of The DragonFly Project nor the names of its
18427e5fc6SMatthew Dillon  *    contributors may be used to endorse or promote products derived
19427e5fc6SMatthew Dillon  *    from this software without specific, prior written permission.
20427e5fc6SMatthew Dillon  *
21427e5fc6SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22427e5fc6SMatthew Dillon  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23427e5fc6SMatthew Dillon  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24427e5fc6SMatthew Dillon  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25427e5fc6SMatthew Dillon  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26427e5fc6SMatthew Dillon  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27427e5fc6SMatthew Dillon  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28427e5fc6SMatthew Dillon  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29427e5fc6SMatthew Dillon  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30427e5fc6SMatthew Dillon  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31427e5fc6SMatthew Dillon  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32427e5fc6SMatthew Dillon  * SUCH DAMAGE.
33427e5fc6SMatthew Dillon  *
34*77062c8aSMatthew Dillon  * $DragonFly: src/sys/vfs/hammer/hammer_vfsops.c,v 1.34 2008/05/06 00:21:08 dillon Exp $
35427e5fc6SMatthew Dillon  */
36427e5fc6SMatthew Dillon 
37427e5fc6SMatthew Dillon #include <sys/param.h>
38427e5fc6SMatthew Dillon #include <sys/systm.h>
39427e5fc6SMatthew Dillon #include <sys/kernel.h>
40427e5fc6SMatthew Dillon #include <sys/vnode.h>
41427e5fc6SMatthew Dillon #include <sys/mount.h>
42427e5fc6SMatthew Dillon #include <sys/malloc.h>
43427e5fc6SMatthew Dillon #include <sys/nlookup.h>
44427e5fc6SMatthew Dillon #include <sys/fcntl.h>
45b3deaf57SMatthew Dillon #include <sys/sysctl.h>
46427e5fc6SMatthew Dillon #include <sys/buf.h>
47427e5fc6SMatthew Dillon #include <sys/buf2.h>
48427e5fc6SMatthew Dillon #include "hammer.h"
49427e5fc6SMatthew Dillon 
50d5ef456eSMatthew Dillon int hammer_debug_general;
51*77062c8aSMatthew Dillon int hammer_debug_debug;
52e8599db1SMatthew Dillon int hammer_debug_inode;
537d683b0fSMatthew Dillon int hammer_debug_locks;
54b3deaf57SMatthew Dillon int hammer_debug_btree;
55d113fda1SMatthew Dillon int hammer_debug_tid;
5646fe7ae1SMatthew Dillon int hammer_debug_recover;	/* -1 will disable, +1 will force */
5746fe7ae1SMatthew Dillon int hammer_debug_recover_faults;
58b3deaf57SMatthew Dillon int hammer_count_inodes;
59b3deaf57SMatthew Dillon int hammer_count_records;
60b3deaf57SMatthew Dillon int hammer_count_record_datas;
61b3deaf57SMatthew Dillon int hammer_count_volumes;
62b3deaf57SMatthew Dillon int hammer_count_buffers;
63b3deaf57SMatthew Dillon int hammer_count_nodes;
649480ff55SMatthew Dillon int hammer_count_dirtybufs;		/* global */
659480ff55SMatthew Dillon int hammer_limit_dirtybufs = 100;	/* per-mount */
661f07f686SMatthew Dillon int hammer_bio_count;
677d683b0fSMatthew Dillon int64_t hammer_contention_count;
68f03c9cf4SMatthew Dillon int64_t hammer_zone_limit;
69b3deaf57SMatthew Dillon 
70b3deaf57SMatthew Dillon SYSCTL_NODE(_vfs, OID_AUTO, hammer, CTLFLAG_RW, 0, "HAMMER filesystem");
71d5ef456eSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_general, CTLFLAG_RW,
72d5ef456eSMatthew Dillon 	   &hammer_debug_general, 0, "");
73*77062c8aSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_debug, CTLFLAG_RW,
74*77062c8aSMatthew Dillon 	   &hammer_debug_debug, 0, "");
75e8599db1SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_inode, CTLFLAG_RW,
76e8599db1SMatthew Dillon 	   &hammer_debug_inode, 0, "");
777d683b0fSMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_locks, CTLFLAG_RW,
787d683b0fSMatthew Dillon 	   &hammer_debug_locks, 0, "");
79b3deaf57SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_btree, CTLFLAG_RW,
80b3deaf57SMatthew Dillon 	   &hammer_debug_btree, 0, "");
81d113fda1SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_tid, CTLFLAG_RW,
82d113fda1SMatthew Dillon 	   &hammer_debug_tid, 0, "");
83b33e2cc0SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_recover, CTLFLAG_RW,
84b33e2cc0SMatthew Dillon 	   &hammer_debug_recover, 0, "");
8546fe7ae1SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, debug_recover_faults, CTLFLAG_RW,
8646fe7ae1SMatthew Dillon 	   &hammer_debug_recover_faults, 0, "");
879480ff55SMatthew Dillon 
889480ff55SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, limit_dirtybufs, CTLFLAG_RW,
899480ff55SMatthew Dillon 	   &hammer_limit_dirtybufs, 0, "");
909480ff55SMatthew Dillon 
91b3deaf57SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_inodes, CTLFLAG_RD,
92b3deaf57SMatthew Dillon 	   &hammer_count_inodes, 0, "");
93b3deaf57SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_records, CTLFLAG_RD,
94b3deaf57SMatthew Dillon 	   &hammer_count_records, 0, "");
95b3deaf57SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_record_datas, CTLFLAG_RD,
96b3deaf57SMatthew Dillon 	   &hammer_count_record_datas, 0, "");
97b3deaf57SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_volumes, CTLFLAG_RD,
98b3deaf57SMatthew Dillon 	   &hammer_count_volumes, 0, "");
99b3deaf57SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_buffers, CTLFLAG_RD,
100b3deaf57SMatthew Dillon 	   &hammer_count_buffers, 0, "");
101b3deaf57SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_nodes, CTLFLAG_RD,
102b3deaf57SMatthew Dillon 	   &hammer_count_nodes, 0, "");
1039480ff55SMatthew Dillon SYSCTL_INT(_vfs_hammer, OID_AUTO, count_dirtybufs, CTLFLAG_RD,
1049480ff55SMatthew Dillon 	   &hammer_count_dirtybufs, 0, "");
105f03c9cf4SMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, zone_limit, CTLFLAG_RW,
106f03c9cf4SMatthew Dillon 	   &hammer_zone_limit, 0, "");
1077d683b0fSMatthew Dillon SYSCTL_QUAD(_vfs_hammer, OID_AUTO, contention_count, CTLFLAG_RW,
1087d683b0fSMatthew Dillon 	   &hammer_contention_count, 0, "");
109b3deaf57SMatthew Dillon 
110427e5fc6SMatthew Dillon /*
111427e5fc6SMatthew Dillon  * VFS ABI
112427e5fc6SMatthew Dillon  */
113427e5fc6SMatthew Dillon static void	hammer_free_hmp(struct mount *mp);
114427e5fc6SMatthew Dillon 
115427e5fc6SMatthew Dillon static int	hammer_vfs_mount(struct mount *mp, char *path, caddr_t data,
116427e5fc6SMatthew Dillon 				struct ucred *cred);
117427e5fc6SMatthew Dillon static int	hammer_vfs_unmount(struct mount *mp, int mntflags);
118427e5fc6SMatthew Dillon static int	hammer_vfs_root(struct mount *mp, struct vnode **vpp);
119427e5fc6SMatthew Dillon static int	hammer_vfs_statfs(struct mount *mp, struct statfs *sbp,
120427e5fc6SMatthew Dillon 				struct ucred *cred);
121427e5fc6SMatthew Dillon static int	hammer_vfs_sync(struct mount *mp, int waitfor);
122513ca7d7SMatthew Dillon static int	hammer_vfs_vget(struct mount *mp, ino_t ino,
123513ca7d7SMatthew Dillon 				struct vnode **vpp);
124427e5fc6SMatthew Dillon static int	hammer_vfs_init(struct vfsconf *conf);
125513ca7d7SMatthew Dillon static int	hammer_vfs_fhtovp(struct mount *mp, struct fid *fhp,
126513ca7d7SMatthew Dillon 				struct vnode **vpp);
127513ca7d7SMatthew Dillon static int	hammer_vfs_vptofh(struct vnode *vp, struct fid *fhp);
128513ca7d7SMatthew Dillon static int	hammer_vfs_checkexp(struct mount *mp, struct sockaddr *nam,
129513ca7d7SMatthew Dillon 				int *exflagsp, struct ucred **credanonp);
130513ca7d7SMatthew Dillon 
131427e5fc6SMatthew Dillon 
132427e5fc6SMatthew Dillon static struct vfsops hammer_vfsops = {
133427e5fc6SMatthew Dillon 	.vfs_mount	= hammer_vfs_mount,
134427e5fc6SMatthew Dillon 	.vfs_unmount	= hammer_vfs_unmount,
135427e5fc6SMatthew Dillon 	.vfs_root 	= hammer_vfs_root,
136427e5fc6SMatthew Dillon 	.vfs_statfs	= hammer_vfs_statfs,
137427e5fc6SMatthew Dillon 	.vfs_sync	= hammer_vfs_sync,
138427e5fc6SMatthew Dillon 	.vfs_vget	= hammer_vfs_vget,
139513ca7d7SMatthew Dillon 	.vfs_init	= hammer_vfs_init,
140513ca7d7SMatthew Dillon 	.vfs_vptofh	= hammer_vfs_vptofh,
141513ca7d7SMatthew Dillon 	.vfs_fhtovp	= hammer_vfs_fhtovp,
142513ca7d7SMatthew Dillon 	.vfs_checkexp	= hammer_vfs_checkexp
143427e5fc6SMatthew Dillon };
144427e5fc6SMatthew Dillon 
145427e5fc6SMatthew Dillon MALLOC_DEFINE(M_HAMMER, "hammer-mount", "hammer mount");
146427e5fc6SMatthew Dillon 
147427e5fc6SMatthew Dillon VFS_SET(hammer_vfsops, hammer, 0);
148427e5fc6SMatthew Dillon MODULE_VERSION(hammer, 1);
149427e5fc6SMatthew Dillon 
150427e5fc6SMatthew Dillon static int
151427e5fc6SMatthew Dillon hammer_vfs_init(struct vfsconf *conf)
152427e5fc6SMatthew Dillon {
15347197d71SMatthew Dillon 	/*hammer_init_alist_config();*/
154427e5fc6SMatthew Dillon 	return(0);
155427e5fc6SMatthew Dillon }
156427e5fc6SMatthew Dillon 
157427e5fc6SMatthew Dillon static int
158427e5fc6SMatthew Dillon hammer_vfs_mount(struct mount *mp, char *mntpt, caddr_t data,
159427e5fc6SMatthew Dillon 		 struct ucred *cred)
160427e5fc6SMatthew Dillon {
161427e5fc6SMatthew Dillon 	struct hammer_mount_info info;
162a89aec1bSMatthew Dillon 	hammer_mount_t hmp;
163a89aec1bSMatthew Dillon 	hammer_volume_t rootvol;
16427ea2398SMatthew Dillon 	struct vnode *rootvp;
165427e5fc6SMatthew Dillon 	const char *upath;	/* volume name in userspace */
166427e5fc6SMatthew Dillon 	char *path;		/* volume name in system space */
167427e5fc6SMatthew Dillon 	int error;
168427e5fc6SMatthew Dillon 	int i;
169427e5fc6SMatthew Dillon 
170427e5fc6SMatthew Dillon 	if ((error = copyin(data, &info, sizeof(info))) != 0)
171427e5fc6SMatthew Dillon 		return (error);
172427e5fc6SMatthew Dillon 	if (info.nvolumes <= 0 || info.nvolumes >= 32768)
173427e5fc6SMatthew Dillon 		return (EINVAL);
174427e5fc6SMatthew Dillon 
175427e5fc6SMatthew Dillon 	/*
176427e5fc6SMatthew Dillon 	 * Interal mount data structure
177427e5fc6SMatthew Dillon 	 */
178195c19a1SMatthew Dillon 	if (mp->mnt_flag & MNT_UPDATE) {
179195c19a1SMatthew Dillon 		hmp = (void *)mp->mnt_data;
180195c19a1SMatthew Dillon 		KKASSERT(hmp != NULL);
181195c19a1SMatthew Dillon 	} else {
182427e5fc6SMatthew Dillon 		hmp = kmalloc(sizeof(*hmp), M_HAMMER, M_WAITOK | M_ZERO);
183427e5fc6SMatthew Dillon 		mp->mnt_data = (qaddr_t)hmp;
184427e5fc6SMatthew Dillon 		hmp->mp = mp;
185195c19a1SMatthew Dillon 		hmp->zbuf = kmalloc(HAMMER_BUFSIZE, M_HAMMER, M_WAITOK|M_ZERO);
186195c19a1SMatthew Dillon 		hmp->namekey_iterator = mycpu->gd_time_seconds;
18746fe7ae1SMatthew Dillon 		/*TAILQ_INIT(&hmp->recycle_list);*/
18847197d71SMatthew Dillon 
18947197d71SMatthew Dillon 		hmp->root_btree_beg.obj_id = -0x8000000000000000LL;
19047197d71SMatthew Dillon 		hmp->root_btree_beg.key = -0x8000000000000000LL;
19147197d71SMatthew Dillon 		hmp->root_btree_beg.create_tid = 1;
19247197d71SMatthew Dillon 		hmp->root_btree_beg.delete_tid = 1;
19347197d71SMatthew Dillon 		hmp->root_btree_beg.rec_type = 0;
19447197d71SMatthew Dillon 		hmp->root_btree_beg.obj_type = 0;
19547197d71SMatthew Dillon 
19647197d71SMatthew Dillon 		hmp->root_btree_end.obj_id = 0x7FFFFFFFFFFFFFFFLL;
19747197d71SMatthew Dillon 		hmp->root_btree_end.key = 0x7FFFFFFFFFFFFFFFLL;
19847197d71SMatthew Dillon 		hmp->root_btree_end.create_tid = 0xFFFFFFFFFFFFFFFFULL;
19947197d71SMatthew Dillon 		hmp->root_btree_end.delete_tid = 0;   /* special case */
20047197d71SMatthew Dillon 		hmp->root_btree_end.rec_type = 0xFFFFU;
20147197d71SMatthew Dillon 		hmp->root_btree_end.obj_type = 0;
20240043e7fSMatthew Dillon 		lockinit(&hmp->blockmap_lock, "blkmap", 0, 0);
203f03c9cf4SMatthew Dillon 
2049480ff55SMatthew Dillon 		hmp->sync_lock.refs = 1;
205c9b9e29dSMatthew Dillon 		hmp->free_lock.refs = 1;
2069480ff55SMatthew Dillon 
207059819e3SMatthew Dillon 		TAILQ_INIT(&hmp->flush_list);
2080729c8c8SMatthew Dillon 		TAILQ_INIT(&hmp->objid_cache_list);
209e8599db1SMatthew Dillon 		TAILQ_INIT(&hmp->undo_lru_list);
210059819e3SMatthew Dillon 
2110729c8c8SMatthew Dillon 		/*
2120729c8c8SMatthew Dillon 		 * Set default zone limits.  This value can be reduced
2130729c8c8SMatthew Dillon 		 * further by the zone limit specified in the root volume.
2140729c8c8SMatthew Dillon 		 *
2150729c8c8SMatthew Dillon 		 * The sysctl can force a small zone limit for debugging
2160729c8c8SMatthew Dillon 		 * purposes.
2170729c8c8SMatthew Dillon 		 */
218f03c9cf4SMatthew Dillon 		for (i = 0; i < HAMMER_MAX_ZONES; ++i) {
219f03c9cf4SMatthew Dillon 			hmp->zone_limits[i] =
220f03c9cf4SMatthew Dillon 				HAMMER_ZONE_ENCODE(i, HAMMER_ZONE_LIMIT);
2210729c8c8SMatthew Dillon 
222f03c9cf4SMatthew Dillon 			if (hammer_zone_limit) {
223f03c9cf4SMatthew Dillon 				hmp->zone_limits[i] =
224f03c9cf4SMatthew Dillon 				    HAMMER_ZONE_ENCODE(i, hammer_zone_limit);
225f03c9cf4SMatthew Dillon 			}
226bf686dbeSMatthew Dillon 			hammer_init_holes(hmp, &hmp->holes[i]);
227f03c9cf4SMatthew Dillon 		}
228195c19a1SMatthew Dillon 	}
229195c19a1SMatthew Dillon 	hmp->hflags = info.hflags;
2307f7c1f84SMatthew Dillon 	if (info.asof) {
2317f7c1f84SMatthew Dillon 		mp->mnt_flag |= MNT_RDONLY;
2327f7c1f84SMatthew Dillon 		hmp->asof = info.asof;
2337f7c1f84SMatthew Dillon 	} else {
2347f7c1f84SMatthew Dillon 		hmp->asof = HAMMER_MAX_TID;
2357f7c1f84SMatthew Dillon 	}
236195c19a1SMatthew Dillon 
237195c19a1SMatthew Dillon 	/*
238195c19a1SMatthew Dillon 	 * Re-open read-write if originally read-only, or vise-versa XXX
239195c19a1SMatthew Dillon 	 */
240195c19a1SMatthew Dillon 	if (mp->mnt_flag & MNT_UPDATE) {
241195c19a1SMatthew Dillon 		if (hmp->ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
242195c19a1SMatthew Dillon 			kprintf("HAMMER read-write -> read-only XXX\n");
243195c19a1SMatthew Dillon 			hmp->ronly = 1;
244195c19a1SMatthew Dillon 		} else if (hmp->ronly && (mp->mnt_flag & MNT_RDONLY) == 0) {
245195c19a1SMatthew Dillon 			kprintf("HAMMER read-only -> read-write XXX\n");
246195c19a1SMatthew Dillon 			hmp->ronly = 0;
247195c19a1SMatthew Dillon 		}
248195c19a1SMatthew Dillon 		return(0);
249195c19a1SMatthew Dillon 	}
250195c19a1SMatthew Dillon 
251427e5fc6SMatthew Dillon 	RB_INIT(&hmp->rb_vols_root);
252427e5fc6SMatthew Dillon 	RB_INIT(&hmp->rb_inos_root);
25340043e7fSMatthew Dillon 	RB_INIT(&hmp->rb_nods_root);
254e8599db1SMatthew Dillon 	RB_INIT(&hmp->rb_undo_root);
255195c19a1SMatthew Dillon 	hmp->ronly = ((mp->mnt_flag & MNT_RDONLY) != 0);
256427e5fc6SMatthew Dillon 
25710a5d1baSMatthew Dillon 	TAILQ_INIT(&hmp->volu_list);
25810a5d1baSMatthew Dillon 	TAILQ_INIT(&hmp->undo_list);
25910a5d1baSMatthew Dillon 	TAILQ_INIT(&hmp->data_list);
26010a5d1baSMatthew Dillon 	TAILQ_INIT(&hmp->meta_list);
26110a5d1baSMatthew Dillon 	TAILQ_INIT(&hmp->lose_list);
26210a5d1baSMatthew Dillon 
263427e5fc6SMatthew Dillon 	/*
264427e5fc6SMatthew Dillon 	 * Load volumes
265427e5fc6SMatthew Dillon 	 */
266427e5fc6SMatthew Dillon 	path = objcache_get(namei_oc, M_WAITOK);
267d26d0ae9SMatthew Dillon 	hmp->nvolumes = info.nvolumes;
268427e5fc6SMatthew Dillon 	for (i = 0; i < info.nvolumes; ++i) {
269427e5fc6SMatthew Dillon 		error = copyin(&info.volumes[i], &upath, sizeof(char *));
270427e5fc6SMatthew Dillon 		if (error == 0)
271427e5fc6SMatthew Dillon 			error = copyinstr(upath, path, MAXPATHLEN, NULL);
272427e5fc6SMatthew Dillon 		if (error == 0)
2738cd0a023SMatthew Dillon 			error = hammer_install_volume(hmp, path);
274427e5fc6SMatthew Dillon 		if (error)
275427e5fc6SMatthew Dillon 			break;
276427e5fc6SMatthew Dillon 	}
277427e5fc6SMatthew Dillon 	objcache_put(namei_oc, path);
278427e5fc6SMatthew Dillon 
279427e5fc6SMatthew Dillon 	/*
280427e5fc6SMatthew Dillon 	 * Make sure we found a root volume
281427e5fc6SMatthew Dillon 	 */
282427e5fc6SMatthew Dillon 	if (error == 0 && hmp->rootvol == NULL) {
283427e5fc6SMatthew Dillon 		kprintf("hammer_mount: No root volume found!\n");
284427e5fc6SMatthew Dillon 		error = EINVAL;
285427e5fc6SMatthew Dillon 	}
286427e5fc6SMatthew Dillon 	if (error) {
287427e5fc6SMatthew Dillon 		hammer_free_hmp(mp);
288427e5fc6SMatthew Dillon 		return (error);
289427e5fc6SMatthew Dillon 	}
290427e5fc6SMatthew Dillon 
291427e5fc6SMatthew Dillon 	/*
29227ea2398SMatthew Dillon 	 * No errors, setup enough of the mount point so we can lookup the
29327ea2398SMatthew Dillon 	 * root vnode.
294427e5fc6SMatthew Dillon 	 */
295427e5fc6SMatthew Dillon 	mp->mnt_iosize_max = MAXPHYS;
296427e5fc6SMatthew Dillon 	mp->mnt_kern_flag |= MNTK_FSMID;
297c0ade690SMatthew Dillon 
298c0ade690SMatthew Dillon 	/*
299c0ade690SMatthew Dillon 	 * note: f_iosize is used by vnode_pager_haspage() when constructing
300c0ade690SMatthew Dillon 	 * its VOP_BMAP call.
301c0ade690SMatthew Dillon 	 */
302c0ade690SMatthew Dillon 	mp->mnt_stat.f_iosize = HAMMER_BUFSIZE;
303fbc6e32aSMatthew Dillon 	mp->mnt_stat.f_bsize = HAMMER_BUFSIZE;
304427e5fc6SMatthew Dillon 	mp->mnt_maxsymlinklen = 255;
305427e5fc6SMatthew Dillon 	mp->mnt_flag |= MNT_LOCAL;
306427e5fc6SMatthew Dillon 
307427e5fc6SMatthew Dillon 	vfs_add_vnodeops(mp, &hammer_vnode_vops, &mp->mnt_vn_norm_ops);
3087a04d74fSMatthew Dillon 	vfs_add_vnodeops(mp, &hammer_spec_vops, &mp->mnt_vn_spec_ops);
3097a04d74fSMatthew Dillon 	vfs_add_vnodeops(mp, &hammer_fifo_vops, &mp->mnt_vn_fifo_ops);
31027ea2398SMatthew Dillon 
31127ea2398SMatthew Dillon 	/*
312a89aec1bSMatthew Dillon 	 * The root volume's ondisk pointer is only valid if we hold a
313a89aec1bSMatthew Dillon 	 * reference to it.
314a89aec1bSMatthew Dillon 	 */
315a89aec1bSMatthew Dillon 	rootvol = hammer_get_root_volume(hmp, &error);
316a89aec1bSMatthew Dillon 	if (error)
317f90dde4cSMatthew Dillon 		goto failed;
318f90dde4cSMatthew Dillon 
319f90dde4cSMatthew Dillon 	/*
3200729c8c8SMatthew Dillon 	 * Perform any necessary UNDO operations.  The recover code does
3210729c8c8SMatthew Dillon 	 * call hammer_undo_lookup() so we have to pre-cache the blockmap,
3220729c8c8SMatthew Dillon 	 * and then re-copy it again after recovery is complete.
323c9b9e29dSMatthew Dillon 	 *
324c9b9e29dSMatthew Dillon 	 * The recover code will load hmp->flusher_undo_start.
325f90dde4cSMatthew Dillon 	 */
3260729c8c8SMatthew Dillon 	bcopy(rootvol->ondisk->vol0_blockmap, hmp->blockmap,
3270729c8c8SMatthew Dillon 	      sizeof(hmp->blockmap));
328c9b9e29dSMatthew Dillon 
329f90dde4cSMatthew Dillon 	error = hammer_recover(hmp, rootvol);
330f90dde4cSMatthew Dillon 	if (error) {
331f90dde4cSMatthew Dillon 		kprintf("Failed to recover HAMMER filesystem on mount\n");
332a89aec1bSMatthew Dillon 		goto done;
333f90dde4cSMatthew Dillon 	}
334f90dde4cSMatthew Dillon 
335f90dde4cSMatthew Dillon 	/*
336f90dde4cSMatthew Dillon 	 * Finish setup now that we have a good root volume
337f90dde4cSMatthew Dillon 	 */
338a89aec1bSMatthew Dillon 	ksnprintf(mp->mnt_stat.f_mntfromname,
339a89aec1bSMatthew Dillon 		  sizeof(mp->mnt_stat.f_mntfromname), "%s",
340a89aec1bSMatthew Dillon 		  rootvol->ondisk->vol_name);
341513ca7d7SMatthew Dillon 	mp->mnt_stat.f_fsid.val[0] =
342513ca7d7SMatthew Dillon 		crc32((char *)&rootvol->ondisk->vol_fsid + 0, 8);
343513ca7d7SMatthew Dillon 	mp->mnt_stat.f_fsid.val[1] =
344513ca7d7SMatthew Dillon 		crc32((char *)&rootvol->ondisk->vol_fsid + 8, 8);
345b84de5afSMatthew Dillon 
3460729c8c8SMatthew Dillon 	/*
3470729c8c8SMatthew Dillon 	 * Certain often-modified fields in the root volume are cached in
3480729c8c8SMatthew Dillon 	 * the hammer_mount structure so we do not have to generate lots
3490729c8c8SMatthew Dillon 	 * of little UNDO structures for them.
350c9b9e29dSMatthew Dillon 	 *
351c9b9e29dSMatthew Dillon 	 * Recopy after recovery.
3520729c8c8SMatthew Dillon 	 */
353b84de5afSMatthew Dillon 	hmp->next_tid = rootvol->ondisk->vol0_next_tid;
3540729c8c8SMatthew Dillon 	bcopy(rootvol->ondisk->vol0_blockmap, hmp->blockmap,
3550729c8c8SMatthew Dillon 	      sizeof(hmp->blockmap));
3560729c8c8SMatthew Dillon 
3570729c8c8SMatthew Dillon 	/*
3580729c8c8SMatthew Dillon 	 * Use the zone limit set by newfs_hammer, or the zone limit set by
3590729c8c8SMatthew Dillon 	 * sysctl (for debugging), whichever is smaller.
3600729c8c8SMatthew Dillon 	 */
3610729c8c8SMatthew Dillon 	if (rootvol->ondisk->vol0_zone_limit) {
3620729c8c8SMatthew Dillon 		hammer_off_t vol0_zone_limit;
3630729c8c8SMatthew Dillon 
3640729c8c8SMatthew Dillon 		vol0_zone_limit = rootvol->ondisk->vol0_zone_limit;
3650729c8c8SMatthew Dillon 		for (i = 0; i < HAMMER_MAX_ZONES; ++i) {
3660729c8c8SMatthew Dillon 			if (hmp->zone_limits[i] > vol0_zone_limit)
3670729c8c8SMatthew Dillon 				hmp->zone_limits[i] = vol0_zone_limit;
3680729c8c8SMatthew Dillon 		}
3690729c8c8SMatthew Dillon 	}
370b84de5afSMatthew Dillon 
371059819e3SMatthew Dillon 	hammer_flusher_create(hmp);
372059819e3SMatthew Dillon 
373a89aec1bSMatthew Dillon 	/*
37427ea2398SMatthew Dillon 	 * Locate the root directory using the root cluster's B-Tree as a
37527ea2398SMatthew Dillon 	 * starting point.  The root directory uses an obj_id of 1.
37627ea2398SMatthew Dillon 	 *
37727ea2398SMatthew Dillon 	 * FUTURE: Leave the root directory cached referenced but unlocked
37827ea2398SMatthew Dillon 	 * in hmp->rootvp (need to flush it on unmount).
37927ea2398SMatthew Dillon 	 */
38027ea2398SMatthew Dillon 	error = hammer_vfs_vget(mp, 1, &rootvp);
381a89aec1bSMatthew Dillon 	if (error)
382a89aec1bSMatthew Dillon 		goto done;
38327ea2398SMatthew Dillon 	vput(rootvp);
38427ea2398SMatthew Dillon 	/*vn_unlock(hmp->rootvp);*/
38527ea2398SMatthew Dillon 
386a89aec1bSMatthew Dillon done:
387f90dde4cSMatthew Dillon 	hammer_rel_volume(rootvol, 0);
388f90dde4cSMatthew Dillon failed:
38927ea2398SMatthew Dillon 	/*
39027ea2398SMatthew Dillon 	 * Cleanup and return.
39127ea2398SMatthew Dillon 	 */
39227ea2398SMatthew Dillon 	if (error)
39327ea2398SMatthew Dillon 		hammer_free_hmp(mp);
394427e5fc6SMatthew Dillon 	return (error);
395427e5fc6SMatthew Dillon }
396427e5fc6SMatthew Dillon 
397427e5fc6SMatthew Dillon static int
398427e5fc6SMatthew Dillon hammer_vfs_unmount(struct mount *mp, int mntflags)
399427e5fc6SMatthew Dillon {
400427e5fc6SMatthew Dillon #if 0
401427e5fc6SMatthew Dillon 	struct hammer_mount *hmp = (void *)mp->mnt_data;
402427e5fc6SMatthew Dillon #endif
403427e5fc6SMatthew Dillon 	int flags;
40466325755SMatthew Dillon 	int error;
40527ea2398SMatthew Dillon 
40627ea2398SMatthew Dillon 	/*
407427e5fc6SMatthew Dillon 	 * Clean out the vnodes
408427e5fc6SMatthew Dillon 	 */
40966325755SMatthew Dillon 	flags = 0;
41066325755SMatthew Dillon 	if (mntflags & MNT_FORCE)
41166325755SMatthew Dillon 		flags |= FORCECLOSE;
41266325755SMatthew Dillon 	if ((error = vflush(mp, 0, flags)) != 0)
41366325755SMatthew Dillon 		return (error);
414427e5fc6SMatthew Dillon 
415427e5fc6SMatthew Dillon 	/*
416427e5fc6SMatthew Dillon 	 * Clean up the internal mount structure and related entities.  This
417427e5fc6SMatthew Dillon 	 * may issue I/O.
418427e5fc6SMatthew Dillon 	 */
419427e5fc6SMatthew Dillon 	hammer_free_hmp(mp);
420427e5fc6SMatthew Dillon 	return(0);
421427e5fc6SMatthew Dillon }
422427e5fc6SMatthew Dillon 
423427e5fc6SMatthew Dillon /*
424427e5fc6SMatthew Dillon  * Clean up the internal mount structure and disassociate it from the mount.
425427e5fc6SMatthew Dillon  * This may issue I/O.
426427e5fc6SMatthew Dillon  */
427427e5fc6SMatthew Dillon static void
428427e5fc6SMatthew Dillon hammer_free_hmp(struct mount *mp)
429427e5fc6SMatthew Dillon {
430427e5fc6SMatthew Dillon 	struct hammer_mount *hmp = (void *)mp->mnt_data;
431bf686dbeSMatthew Dillon 	int i;
432427e5fc6SMatthew Dillon 
43327ea2398SMatthew Dillon #if 0
434427e5fc6SMatthew Dillon 	/*
435427e5fc6SMatthew Dillon 	 * Clean up the root vnode
436427e5fc6SMatthew Dillon 	 */
437427e5fc6SMatthew Dillon 	if (hmp->rootvp) {
438427e5fc6SMatthew Dillon 		vrele(hmp->rootvp);
439427e5fc6SMatthew Dillon 		hmp->rootvp = NULL;
440427e5fc6SMatthew Dillon 	}
44127ea2398SMatthew Dillon #endif
442059819e3SMatthew Dillon 	hammer_flusher_sync(hmp);
443b84de5afSMatthew Dillon 	hammer_flusher_sync(hmp);
444059819e3SMatthew Dillon 	hammer_flusher_destroy(hmp);
445427e5fc6SMatthew Dillon 
446b84de5afSMatthew Dillon 	KKASSERT(RB_EMPTY(&hmp->rb_inos_root));
447b84de5afSMatthew Dillon 
448b84de5afSMatthew Dillon #if 0
449427e5fc6SMatthew Dillon 	/*
450427e5fc6SMatthew Dillon 	 * Unload & flush inodes
451b84de5afSMatthew Dillon 	 *
452b84de5afSMatthew Dillon 	 * XXX illegal to call this from here, it can only be done from
453b84de5afSMatthew Dillon 	 * the flusher.
454427e5fc6SMatthew Dillon 	 */
455427e5fc6SMatthew Dillon 	RB_SCAN(hammer_ino_rb_tree, &hmp->rb_inos_root, NULL,
456d113fda1SMatthew Dillon 		hammer_unload_inode, (void *)MNT_WAIT);
457427e5fc6SMatthew Dillon 
458427e5fc6SMatthew Dillon 	/*
459427e5fc6SMatthew Dillon 	 * Unload & flush volumes
460427e5fc6SMatthew Dillon 	 */
461b84de5afSMatthew Dillon #endif
462b84de5afSMatthew Dillon 	/*
463b84de5afSMatthew Dillon 	 * Unload the volumes
464b84de5afSMatthew Dillon 	 */
465427e5fc6SMatthew Dillon 	RB_SCAN(hammer_vol_rb_tree, &hmp->rb_vols_root, NULL,
466427e5fc6SMatthew Dillon 		hammer_unload_volume, NULL);
467427e5fc6SMatthew Dillon 
468427e5fc6SMatthew Dillon 	mp->mnt_data = NULL;
46966325755SMatthew Dillon 	mp->mnt_flag &= ~MNT_LOCAL;
470427e5fc6SMatthew Dillon 	hmp->mp = NULL;
4710729c8c8SMatthew Dillon 	hammer_destroy_objid_cache(hmp);
47266325755SMatthew Dillon 	kfree(hmp->zbuf, M_HAMMER);
47340043e7fSMatthew Dillon 	lockuninit(&hmp->blockmap_lock);
474bf686dbeSMatthew Dillon 
475bf686dbeSMatthew Dillon 	for (i = 0; i < HAMMER_MAX_ZONES; ++i)
476bf686dbeSMatthew Dillon 		hammer_free_holes(hmp, &hmp->holes[i]);
477bf686dbeSMatthew Dillon 
478427e5fc6SMatthew Dillon 	kfree(hmp, M_HAMMER);
479427e5fc6SMatthew Dillon }
480427e5fc6SMatthew Dillon 
481427e5fc6SMatthew Dillon /*
482513ca7d7SMatthew Dillon  * Obtain a vnode for the specified inode number.  An exclusively locked
483513ca7d7SMatthew Dillon  * vnode is returned.
484513ca7d7SMatthew Dillon  */
485513ca7d7SMatthew Dillon int
486513ca7d7SMatthew Dillon hammer_vfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
487513ca7d7SMatthew Dillon {
48836f82b23SMatthew Dillon 	struct hammer_transaction trans;
489513ca7d7SMatthew Dillon 	struct hammer_mount *hmp = (void *)mp->mnt_data;
490513ca7d7SMatthew Dillon 	struct hammer_inode *ip;
491513ca7d7SMatthew Dillon 	int error;
492513ca7d7SMatthew Dillon 
49336f82b23SMatthew Dillon 	hammer_simple_transaction(&trans, hmp);
49436f82b23SMatthew Dillon 
495513ca7d7SMatthew Dillon 	/*
49636f82b23SMatthew Dillon 	 * Lookup the requested HAMMER inode.  The structure must be
49736f82b23SMatthew Dillon 	 * left unlocked while we manipulate the related vnode to avoid
49836f82b23SMatthew Dillon 	 * a deadlock.
499513ca7d7SMatthew Dillon 	 */
50036f82b23SMatthew Dillon 	ip = hammer_get_inode(&trans, NULL, ino, hmp->asof, 0, &error);
501513ca7d7SMatthew Dillon 	if (ip == NULL) {
502513ca7d7SMatthew Dillon 		*vpp = NULL;
503513ca7d7SMatthew Dillon 		return(error);
504513ca7d7SMatthew Dillon 	}
505e8599db1SMatthew Dillon 	error = hammer_get_vnode(ip, vpp);
506513ca7d7SMatthew Dillon 	hammer_rel_inode(ip, 0);
507b84de5afSMatthew Dillon 	hammer_done_transaction(&trans);
508513ca7d7SMatthew Dillon 	return (error);
509513ca7d7SMatthew Dillon }
510513ca7d7SMatthew Dillon 
511513ca7d7SMatthew Dillon /*
512427e5fc6SMatthew Dillon  * Return the root vnode for the filesystem.
513427e5fc6SMatthew Dillon  *
514427e5fc6SMatthew Dillon  * HAMMER stores the root vnode in the hammer_mount structure so
515427e5fc6SMatthew Dillon  * getting it is easy.
516427e5fc6SMatthew Dillon  */
517427e5fc6SMatthew Dillon static int
518427e5fc6SMatthew Dillon hammer_vfs_root(struct mount *mp, struct vnode **vpp)
519427e5fc6SMatthew Dillon {
52047197d71SMatthew Dillon #if 0
521427e5fc6SMatthew Dillon 	struct hammer_mount *hmp = (void *)mp->mnt_data;
52247197d71SMatthew Dillon #endif
52327ea2398SMatthew Dillon 	int error;
524427e5fc6SMatthew Dillon 
52527ea2398SMatthew Dillon 	error = hammer_vfs_vget(mp, 1, vpp);
52627ea2398SMatthew Dillon 	return (error);
527427e5fc6SMatthew Dillon }
528427e5fc6SMatthew Dillon 
529427e5fc6SMatthew Dillon static int
530427e5fc6SMatthew Dillon hammer_vfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
531427e5fc6SMatthew Dillon {
532fbc6e32aSMatthew Dillon 	struct hammer_mount *hmp = (void *)mp->mnt_data;
533fbc6e32aSMatthew Dillon 	hammer_volume_t volume;
534fbc6e32aSMatthew Dillon 	hammer_volume_ondisk_t ondisk;
535fbc6e32aSMatthew Dillon 	int error;
53647197d71SMatthew Dillon 	int64_t bfree;
537fbc6e32aSMatthew Dillon 
538fbc6e32aSMatthew Dillon 	volume = hammer_get_root_volume(hmp, &error);
539fbc6e32aSMatthew Dillon 	if (error)
540fbc6e32aSMatthew Dillon 		return(error);
541fbc6e32aSMatthew Dillon 	ondisk = volume->ondisk;
542fbc6e32aSMatthew Dillon 
54347197d71SMatthew Dillon 	/*
54447197d71SMatthew Dillon 	 * Basic stats
54547197d71SMatthew Dillon 	 */
546fbc6e32aSMatthew Dillon 	mp->mnt_stat.f_files = ondisk->vol0_stat_inodes;
547c3be93f2SMatthew Dillon 	bfree = ondisk->vol0_stat_freebigblocks * HAMMER_LARGEBLOCK_SIZE;
54840043e7fSMatthew Dillon 	hammer_rel_volume(volume, 0);
54947197d71SMatthew Dillon 
55047197d71SMatthew Dillon 	mp->mnt_stat.f_bfree = bfree / HAMMER_BUFSIZE;
55147197d71SMatthew Dillon 	mp->mnt_stat.f_bavail = mp->mnt_stat.f_bfree;
552fbc6e32aSMatthew Dillon 	if (mp->mnt_stat.f_files < 0)
553fbc6e32aSMatthew Dillon 		mp->mnt_stat.f_files = 0;
554fbc6e32aSMatthew Dillon 
55527ea2398SMatthew Dillon 	*sbp = mp->mnt_stat;
55627ea2398SMatthew Dillon 	return(0);
557427e5fc6SMatthew Dillon }
558427e5fc6SMatthew Dillon 
5590729c8c8SMatthew Dillon /*
5600729c8c8SMatthew Dillon  * Sync the filesystem.  Currently we have to run it twice, the second
5610729c8c8SMatthew Dillon  * one will advance the undo start index to the end index, so if a crash
5620729c8c8SMatthew Dillon  * occurs no undos will be run on mount.
563*77062c8aSMatthew Dillon  *
564*77062c8aSMatthew Dillon  * We do not sync the filesystem if we are called from a panic.  If we did
565*77062c8aSMatthew Dillon  * we might end up blowing up a sync that was already in progress.
5660729c8c8SMatthew Dillon  */
567427e5fc6SMatthew Dillon static int
568427e5fc6SMatthew Dillon hammer_vfs_sync(struct mount *mp, int waitfor)
569427e5fc6SMatthew Dillon {
570fbc6e32aSMatthew Dillon 	struct hammer_mount *hmp = (void *)mp->mnt_data;
5710729c8c8SMatthew Dillon 	int error;
5720729c8c8SMatthew Dillon 
573*77062c8aSMatthew Dillon 	if (panicstr == NULL) {
5740729c8c8SMatthew Dillon 		error = hammer_sync_hmp(hmp, waitfor);
5750729c8c8SMatthew Dillon 		if (error == 0)
5760729c8c8SMatthew Dillon 			error = hammer_sync_hmp(hmp, waitfor);
577*77062c8aSMatthew Dillon 	} else {
578*77062c8aSMatthew Dillon 		error = EIO;
579*77062c8aSMatthew Dillon 		hkprintf("S");
580*77062c8aSMatthew Dillon 	}
5810729c8c8SMatthew Dillon 	return (error);
582427e5fc6SMatthew Dillon }
583427e5fc6SMatthew Dillon 
584513ca7d7SMatthew Dillon /*
585513ca7d7SMatthew Dillon  * Convert a vnode to a file handle.
586513ca7d7SMatthew Dillon  */
587513ca7d7SMatthew Dillon static int
588513ca7d7SMatthew Dillon hammer_vfs_vptofh(struct vnode *vp, struct fid *fhp)
589513ca7d7SMatthew Dillon {
590513ca7d7SMatthew Dillon 	hammer_inode_t ip;
591513ca7d7SMatthew Dillon 
592513ca7d7SMatthew Dillon 	KKASSERT(MAXFIDSZ >= 16);
593513ca7d7SMatthew Dillon 	ip = VTOI(vp);
594513ca7d7SMatthew Dillon 	fhp->fid_len = offsetof(struct fid, fid_data[16]);
595513ca7d7SMatthew Dillon 	fhp->fid_reserved = 0;
596513ca7d7SMatthew Dillon 	bcopy(&ip->obj_id, fhp->fid_data + 0, sizeof(ip->obj_id));
597513ca7d7SMatthew Dillon 	bcopy(&ip->obj_asof, fhp->fid_data + 8, sizeof(ip->obj_asof));
598513ca7d7SMatthew Dillon 	return(0);
599513ca7d7SMatthew Dillon }
600513ca7d7SMatthew Dillon 
601513ca7d7SMatthew Dillon 
602513ca7d7SMatthew Dillon /*
603513ca7d7SMatthew Dillon  * Convert a file handle back to a vnode.
604513ca7d7SMatthew Dillon  */
605513ca7d7SMatthew Dillon static int
606513ca7d7SMatthew Dillon hammer_vfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
607513ca7d7SMatthew Dillon {
60836f82b23SMatthew Dillon 	struct hammer_transaction trans;
609513ca7d7SMatthew Dillon 	struct hammer_inode *ip;
610513ca7d7SMatthew Dillon 	struct hammer_inode_info info;
611513ca7d7SMatthew Dillon 	int error;
612513ca7d7SMatthew Dillon 
613513ca7d7SMatthew Dillon 	bcopy(fhp->fid_data + 0, &info.obj_id, sizeof(info.obj_id));
614513ca7d7SMatthew Dillon 	bcopy(fhp->fid_data + 8, &info.obj_asof, sizeof(info.obj_asof));
615513ca7d7SMatthew Dillon 
61636f82b23SMatthew Dillon 	hammer_simple_transaction(&trans, (void *)mp->mnt_data);
61736f82b23SMatthew Dillon 
618513ca7d7SMatthew Dillon 	/*
619513ca7d7SMatthew Dillon 	 * Get/allocate the hammer_inode structure.  The structure must be
620513ca7d7SMatthew Dillon 	 * unlocked while we manipulate the related vnode to avoid a
621513ca7d7SMatthew Dillon 	 * deadlock.
622513ca7d7SMatthew Dillon 	 */
62336f82b23SMatthew Dillon 	ip = hammer_get_inode(&trans, NULL, info.obj_id, info.obj_asof,
62436f82b23SMatthew Dillon 			      0, &error);
625513ca7d7SMatthew Dillon 	if (ip == NULL) {
626513ca7d7SMatthew Dillon 		*vpp = NULL;
627513ca7d7SMatthew Dillon 		return(error);
628513ca7d7SMatthew Dillon 	}
629e8599db1SMatthew Dillon 	error = hammer_get_vnode(ip, vpp);
630513ca7d7SMatthew Dillon 	hammer_rel_inode(ip, 0);
631b84de5afSMatthew Dillon 	hammer_done_transaction(&trans);
632513ca7d7SMatthew Dillon 	return (error);
633513ca7d7SMatthew Dillon }
634513ca7d7SMatthew Dillon 
635513ca7d7SMatthew Dillon static int
636513ca7d7SMatthew Dillon hammer_vfs_checkexp(struct mount *mp, struct sockaddr *nam,
637513ca7d7SMatthew Dillon 		    int *exflagsp, struct ucred **credanonp)
638513ca7d7SMatthew Dillon {
639513ca7d7SMatthew Dillon 	hammer_mount_t hmp = (void *)mp->mnt_data;
640513ca7d7SMatthew Dillon 	struct netcred *np;
641513ca7d7SMatthew Dillon 	int error;
642513ca7d7SMatthew Dillon 
643513ca7d7SMatthew Dillon 	np = vfs_export_lookup(mp, &hmp->export, nam);
644513ca7d7SMatthew Dillon 	if (np) {
645513ca7d7SMatthew Dillon 		*exflagsp = np->netc_exflags;
646513ca7d7SMatthew Dillon 		*credanonp = &np->netc_anon;
647513ca7d7SMatthew Dillon 		error = 0;
648513ca7d7SMatthew Dillon 	} else {
649513ca7d7SMatthew Dillon 		error = EACCES;
650513ca7d7SMatthew Dillon 	}
651513ca7d7SMatthew Dillon 	return (error);
652513ca7d7SMatthew Dillon 
653513ca7d7SMatthew Dillon }
654513ca7d7SMatthew Dillon 
655513ca7d7SMatthew Dillon int
656513ca7d7SMatthew Dillon hammer_vfs_export(struct mount *mp, int op, const struct export_args *export)
657513ca7d7SMatthew Dillon {
658513ca7d7SMatthew Dillon 	hammer_mount_t hmp = (void *)mp->mnt_data;
659513ca7d7SMatthew Dillon 	int error;
660513ca7d7SMatthew Dillon 
661513ca7d7SMatthew Dillon 	switch(op) {
662513ca7d7SMatthew Dillon 	case MOUNTCTL_SET_EXPORT:
663513ca7d7SMatthew Dillon 		error = vfs_export(mp, &hmp->export, export);
664513ca7d7SMatthew Dillon 		break;
665513ca7d7SMatthew Dillon 	default:
666513ca7d7SMatthew Dillon 		error = EOPNOTSUPP;
667513ca7d7SMatthew Dillon 		break;
668513ca7d7SMatthew Dillon 	}
669513ca7d7SMatthew Dillon 	return(error);
670513ca7d7SMatthew Dillon }
671513ca7d7SMatthew Dillon 
672