xref: /netbsd/sys/ufs/chfs/chfs_vfsops.c (revision 97116d3b)
1*97116d3bShannken /*	$NetBSD: chfs_vfsops.c,v 1.10 2014/03/23 15:21:16 hannken Exp $	*/
2060d2ed9Sahoka 
3060d2ed9Sahoka /*-
4060d2ed9Sahoka  * Copyright (c) 2010 Department of Software Engineering,
5060d2ed9Sahoka  *		      University of Szeged, Hungary
6060d2ed9Sahoka  * Copyright (C) 2010 Tamas Toth <ttoth@inf.u-szeged.hu>
7060d2ed9Sahoka  * Copyright (C) 2010 Adam Hoka <ahoka@NetBSD.org>
8060d2ed9Sahoka  * All rights reserved.
9060d2ed9Sahoka  *
10060d2ed9Sahoka  * This code is derived from software contributed to The NetBSD Foundation
11060d2ed9Sahoka  * by the Department of Software Engineering, University of Szeged, Hungary
12060d2ed9Sahoka  *
13060d2ed9Sahoka  * Redistribution and use in source and binary forms, with or without
14060d2ed9Sahoka  * modification, are permitted provided that the following conditions
15060d2ed9Sahoka  * are met:
16060d2ed9Sahoka  * 1. Redistributions of source code must retain the above copyright
17060d2ed9Sahoka  *    notice, this list of conditions and the following disclaimer.
18060d2ed9Sahoka  * 2. Redistributions in binary form must reproduce the above copyright
19060d2ed9Sahoka  *    notice, this list of conditions and the following disclaimer in the
20060d2ed9Sahoka  *    documentation and/or other materials provided with the distribution.
21060d2ed9Sahoka  *
22060d2ed9Sahoka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23060d2ed9Sahoka  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24060d2ed9Sahoka  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25060d2ed9Sahoka  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26060d2ed9Sahoka  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27060d2ed9Sahoka  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28060d2ed9Sahoka  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29060d2ed9Sahoka  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30060d2ed9Sahoka  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31060d2ed9Sahoka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32060d2ed9Sahoka  * SUCH DAMAGE.
33060d2ed9Sahoka  */
34060d2ed9Sahoka 
35060d2ed9Sahoka #include <sys/cdefs.h>
36060d2ed9Sahoka 
37060d2ed9Sahoka #include <sys/param.h>
38060d2ed9Sahoka #include <sys/types.h>
39060d2ed9Sahoka #include <sys/kmem.h>
40060d2ed9Sahoka #include <sys/mount.h>
41060d2ed9Sahoka #include <sys/stat.h>
42060d2ed9Sahoka #include <sys/systm.h>
43060d2ed9Sahoka #include <sys/proc.h>
44060d2ed9Sahoka #include <sys/module.h>
45060d2ed9Sahoka #include <sys/namei.h>
46060d2ed9Sahoka #include <sys/malloc.h>
47060d2ed9Sahoka #include <sys/fcntl.h>
48060d2ed9Sahoka #include <sys/conf.h>
49060d2ed9Sahoka #include <sys/buf.h>
50060d2ed9Sahoka //XXX needed just for debugging
51060d2ed9Sahoka #include <sys/fstrans.h>
52060d2ed9Sahoka #include <sys/sleepq.h>
53060d2ed9Sahoka #include <sys/lockdebug.h>
54060d2ed9Sahoka #include <sys/ktrace.h>
55060d2ed9Sahoka 
56060d2ed9Sahoka #include <uvm/uvm.h>
57060d2ed9Sahoka #include <uvm/uvm_pager.h>
58060d2ed9Sahoka #include <ufs/ufs/dir.h>
59060d2ed9Sahoka #include <ufs/ufs/ufs_extern.h>
60060d2ed9Sahoka #include <miscfs/genfs/genfs.h>
61060d2ed9Sahoka #include <miscfs/genfs/genfs_node.h>
62060d2ed9Sahoka #include <miscfs/specfs/specdev.h>
63060d2ed9Sahoka #include "chfs.h"
64060d2ed9Sahoka #include "chfs_args.h"
65060d2ed9Sahoka 
66060d2ed9Sahoka MODULE(MODULE_CLASS_VFS, chfs, "flash");
67060d2ed9Sahoka 
68060d2ed9Sahoka /* --------------------------------------------------------------------- */
69060d2ed9Sahoka /* functions */
70060d2ed9Sahoka 
71060d2ed9Sahoka static int chfs_mount(struct mount *, const char *, void *, size_t *);
72060d2ed9Sahoka static int chfs_unmount(struct mount *, int);
73060d2ed9Sahoka static int chfs_root(struct mount *, struct vnode **);
74060d2ed9Sahoka static int chfs_vget(struct mount *, ino_t, struct vnode **);
75060d2ed9Sahoka static int chfs_fhtovp(struct mount *, struct fid *, struct vnode **);
76060d2ed9Sahoka static int chfs_vptofh(struct vnode *, struct fid *, size_t *);
77060d2ed9Sahoka static int chfs_start(struct mount *, int);
78060d2ed9Sahoka static int chfs_statvfs(struct mount *, struct statvfs *);
79060d2ed9Sahoka static int chfs_sync(struct mount *, int, kauth_cred_t);
80060d2ed9Sahoka static void chfs_init(void);
81060d2ed9Sahoka static void chfs_reinit(void);
82060d2ed9Sahoka static void chfs_done(void);
83060d2ed9Sahoka static int chfs_snapshot(struct mount *, struct vnode *,
84060d2ed9Sahoka     struct timespec *);
85060d2ed9Sahoka 
86060d2ed9Sahoka /* --------------------------------------------------------------------- */
87060d2ed9Sahoka /* structures */
88060d2ed9Sahoka 
89060d2ed9Sahoka int
90060d2ed9Sahoka chfs_gop_alloc(struct vnode *vp, off_t off, off_t len,  int flags,
91060d2ed9Sahoka     kauth_cred_t cred)
92060d2ed9Sahoka {
93060d2ed9Sahoka 	return (0);
94060d2ed9Sahoka }
95060d2ed9Sahoka 
96060d2ed9Sahoka const struct genfs_ops chfs_genfsops = {
97060d2ed9Sahoka 	.gop_size = genfs_size,
98060d2ed9Sahoka 	.gop_alloc = chfs_gop_alloc,
99060d2ed9Sahoka 	.gop_write = genfs_gop_write,
100060d2ed9Sahoka 	.gop_markupdate = ufs_gop_markupdate,
101060d2ed9Sahoka };
102060d2ed9Sahoka 
103060d2ed9Sahoka struct pool chfs_inode_pool;
104060d2ed9Sahoka 
105060d2ed9Sahoka /* for looking up the major for flash */
106060d2ed9Sahoka extern const struct cdevsw flash_cdevsw;
107060d2ed9Sahoka 
108060d2ed9Sahoka /* --------------------------------------------------------------------- */
109060d2ed9Sahoka 
110060d2ed9Sahoka static int
111060d2ed9Sahoka chfs_mount(struct mount *mp,
112060d2ed9Sahoka     const char *path, void *data, size_t *data_len)
113060d2ed9Sahoka {
114060d2ed9Sahoka 	struct lwp *l = curlwp;
115060d2ed9Sahoka 	struct nameidata nd;
116060d2ed9Sahoka 	struct pathbuf *pb;
117060d2ed9Sahoka 	struct vnode *devvp = NULL;
118060d2ed9Sahoka 	struct ufs_args *args = data;
119060d2ed9Sahoka 	struct ufsmount *ump = NULL;
120060d2ed9Sahoka 	struct chfs_mount *chmp;
121060d2ed9Sahoka 	int err = 0;
122060d2ed9Sahoka 	int xflags;
123060d2ed9Sahoka 
124060d2ed9Sahoka 	dbg("mount()\n");
125060d2ed9Sahoka 
126060d2ed9Sahoka 	if (*data_len < sizeof *args)
127060d2ed9Sahoka 		return EINVAL;
128060d2ed9Sahoka 
129060d2ed9Sahoka 	if (mp->mnt_flag & MNT_GETARGS) {
130060d2ed9Sahoka 		ump = VFSTOUFS(mp);
131060d2ed9Sahoka 		if (ump == NULL)
132060d2ed9Sahoka 			return EIO;
133060d2ed9Sahoka 		memset(args, 0, sizeof *args);
134060d2ed9Sahoka 		args->fspec = NULL;
135060d2ed9Sahoka 		*data_len = sizeof *args;
136060d2ed9Sahoka 		return 0;
137060d2ed9Sahoka 	}
138060d2ed9Sahoka 
139060d2ed9Sahoka 	if (mp->mnt_flag & MNT_UPDATE) {
140060d2ed9Sahoka 		/* XXX: There is no support yet to update file system
141060d2ed9Sahoka 		 * settings.  Should be added. */
142060d2ed9Sahoka 
143060d2ed9Sahoka 		return ENODEV;
144060d2ed9Sahoka 	}
145060d2ed9Sahoka 
146060d2ed9Sahoka 	if (args->fspec != NULL) {
147060d2ed9Sahoka 		err = pathbuf_copyin(args->fspec, &pb);
148060d2ed9Sahoka 		if (err) {
149060d2ed9Sahoka 			return err;
150060d2ed9Sahoka 		}
151aa98cbbaSttoth 		/* Look up the name and verify that it's sane. */
152060d2ed9Sahoka 		NDINIT(&nd, LOOKUP, FOLLOW, pb);
153060d2ed9Sahoka 		if ((err = namei(&nd)) != 0 )
154060d2ed9Sahoka 			return (err);
155060d2ed9Sahoka 		devvp = nd.ni_vp;
156060d2ed9Sahoka 
157aa98cbbaSttoth 		/* Be sure this is a valid block device */
158060d2ed9Sahoka 		if (devvp->v_type != VBLK)
159060d2ed9Sahoka 			err = ENOTBLK;
160060d2ed9Sahoka 		else if (bdevsw_lookup(devvp->v_rdev) == NULL)
161060d2ed9Sahoka 			err = ENXIO;
162060d2ed9Sahoka 	}
163060d2ed9Sahoka 
164060d2ed9Sahoka 	if (err) {
165060d2ed9Sahoka 		vrele(devvp);
166060d2ed9Sahoka 		return (err);
167060d2ed9Sahoka 	}
168060d2ed9Sahoka 
169060d2ed9Sahoka 	if (mp->mnt_flag & MNT_RDONLY)
170060d2ed9Sahoka 		xflags = FREAD;
171060d2ed9Sahoka 	else
172060d2ed9Sahoka 		xflags = FREAD|FWRITE;
173060d2ed9Sahoka 
174060d2ed9Sahoka 	err = VOP_OPEN(devvp, xflags, FSCRED);
175060d2ed9Sahoka 	if (err)
176060d2ed9Sahoka 		goto fail;
177060d2ed9Sahoka 
178aa98cbbaSttoth 	/* call CHFS mount function */
179060d2ed9Sahoka 	err = chfs_mountfs(devvp, mp);
180060d2ed9Sahoka 	if (err) {
181060d2ed9Sahoka 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
182060d2ed9Sahoka 		(void)VOP_CLOSE(devvp, xflags, NOCRED);
183060d2ed9Sahoka 		VOP_UNLOCK(devvp);
184060d2ed9Sahoka 		goto fail;
185060d2ed9Sahoka 	}
186aa98cbbaSttoth 
187060d2ed9Sahoka 	ump = VFSTOUFS(mp);
188060d2ed9Sahoka 	chmp = ump->um_chfs;
189060d2ed9Sahoka 
190060d2ed9Sahoka 	vfs_getnewfsid(mp);
191060d2ed9Sahoka 	chmp->chm_fsmp = mp;
192060d2ed9Sahoka 
193060d2ed9Sahoka 	return set_statvfs_info(path,
194060d2ed9Sahoka 	    UIO_USERSPACE, args->fspec,
195060d2ed9Sahoka 	    UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l);
196060d2ed9Sahoka 
197060d2ed9Sahoka fail:
198060d2ed9Sahoka 	vrele(devvp);
199060d2ed9Sahoka 	return (err);
200060d2ed9Sahoka }
201060d2ed9Sahoka 
202aa98cbbaSttoth /* chfs_mountfs - init CHFS */
203060d2ed9Sahoka int
204060d2ed9Sahoka chfs_mountfs(struct vnode *devvp, struct mount *mp)
205060d2ed9Sahoka {
206060d2ed9Sahoka 	struct lwp *l = curlwp;
207060d2ed9Sahoka 	kauth_cred_t cred;
208060d2ed9Sahoka 	devmajor_t flash_major;
209060d2ed9Sahoka 	dev_t dev;
210060d2ed9Sahoka 	struct ufsmount* ump = NULL;
211060d2ed9Sahoka 	struct chfs_mount* chmp;
212060d2ed9Sahoka 	struct vnode *vp;
213060d2ed9Sahoka 	int err = 0;
214060d2ed9Sahoka 
215060d2ed9Sahoka 	dbg("mountfs()\n");
216060d2ed9Sahoka 
217060d2ed9Sahoka 	dev = devvp->v_rdev;
218060d2ed9Sahoka 	cred = l ? l->l_cred : NOCRED;
219060d2ed9Sahoka 
220060d2ed9Sahoka 	/* Flush out any old buffers remaining from a previous use. */
221060d2ed9Sahoka 	vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
222060d2ed9Sahoka 	err = vinvalbuf(devvp, V_SAVE, cred, l, 0, 0);
223060d2ed9Sahoka 	VOP_UNLOCK(devvp);
224060d2ed9Sahoka 	if (err)
225060d2ed9Sahoka 		return (err);
226060d2ed9Sahoka 
227aa98cbbaSttoth 	/* Setup device. */
228060d2ed9Sahoka 	flash_major = cdevsw_lookup_major(&flash_cdevsw);
229060d2ed9Sahoka 
230060d2ed9Sahoka 	if (devvp->v_type != VBLK)
231060d2ed9Sahoka 		err = ENOTBLK;
232060d2ed9Sahoka 	else if (bdevsw_lookup(dev) == NULL)
233060d2ed9Sahoka 		err = ENXIO;
234060d2ed9Sahoka 	else if (major(dev) != flash_major) {
235060d2ed9Sahoka 		dbg("major(dev): %d, flash_major: %d\n",
236060d2ed9Sahoka 		    major(dev), flash_major);
237060d2ed9Sahoka 		err = ENODEV;
238060d2ed9Sahoka 	}
239060d2ed9Sahoka 	if (err) {
240060d2ed9Sahoka 		vrele(devvp);
241060d2ed9Sahoka 		return (err);
242060d2ed9Sahoka 	}
243060d2ed9Sahoka 
244aa98cbbaSttoth 	/* Connect CHFS to UFS. */
245a6388638Srmind 	ump = kmem_zalloc(sizeof(struct ufsmount), KM_SLEEP);
246a6388638Srmind 
247060d2ed9Sahoka 	ump->um_fstype = UFS1;
248a6388638Srmind 	ump->um_chfs = kmem_zalloc(sizeof(struct chfs_mount), KM_SLEEP);
249060d2ed9Sahoka 	mutex_init(&ump->um_lock, MUTEX_DEFAULT, IPL_NONE);
250060d2ed9Sahoka 
251060d2ed9Sahoka 	chmp = ump->um_chfs;
252060d2ed9Sahoka 
253aa98cbbaSttoth 	/* Initialize erase block handler. */
254060d2ed9Sahoka 	chmp->chm_ebh = kmem_alloc(sizeof(struct chfs_ebh), KM_SLEEP);
255060d2ed9Sahoka 
256060d2ed9Sahoka 	dbg("[]opening flash: %u\n", (unsigned int)devvp->v_rdev);
257060d2ed9Sahoka 	err = ebh_open(chmp->chm_ebh, devvp->v_rdev);
258060d2ed9Sahoka 	if (err) {
259060d2ed9Sahoka 		dbg("error while opening flash\n");
260a6388638Srmind 		goto fail;
261060d2ed9Sahoka 	}
262060d2ed9Sahoka 
263060d2ed9Sahoka 	//TODO check flash sizes
264060d2ed9Sahoka 
265aa98cbbaSttoth 	/* Initialize vnode cache's hashtable and eraseblock array. */
266060d2ed9Sahoka 	chmp->chm_gbl_version = 0;
267060d2ed9Sahoka 	chmp->chm_vnocache_hash = chfs_vnocache_hash_init();
268060d2ed9Sahoka 
269060d2ed9Sahoka 	chmp->chm_blocks = kmem_zalloc(chmp->chm_ebh->peb_nr *
270060d2ed9Sahoka 	    sizeof(struct chfs_eraseblock), KM_SLEEP);
271060d2ed9Sahoka 
272aa98cbbaSttoth 	/* Initialize mutexes. */
273060d2ed9Sahoka 	mutex_init(&chmp->chm_lock_mountfields, MUTEX_DEFAULT, IPL_NONE);
274060d2ed9Sahoka 	mutex_init(&chmp->chm_lock_sizes, MUTEX_DEFAULT, IPL_NONE);
275060d2ed9Sahoka 	mutex_init(&chmp->chm_lock_vnocache, MUTEX_DEFAULT, IPL_NONE);
276060d2ed9Sahoka 
277aa98cbbaSttoth 	/* Initialize read/write contants. (from UFS) */
278060d2ed9Sahoka 	chmp->chm_fs_bmask = -4096;
279060d2ed9Sahoka 	chmp->chm_fs_bsize = 4096;
280060d2ed9Sahoka 	chmp->chm_fs_qbmask = 4095;
281060d2ed9Sahoka 	chmp->chm_fs_bshift = 12;
282060d2ed9Sahoka 	chmp->chm_fs_fmask = -2048;
283060d2ed9Sahoka 	chmp->chm_fs_qfmask = 2047;
284060d2ed9Sahoka 
285aa98cbbaSttoth 	/* Initialize writebuffer. */
286060d2ed9Sahoka 	chmp->chm_wbuf_pagesize = chmp->chm_ebh->flash_if->page_size;
287060d2ed9Sahoka 	dbg("wbuf size: %zu\n", chmp->chm_wbuf_pagesize);
288060d2ed9Sahoka 	chmp->chm_wbuf = kmem_alloc(chmp->chm_wbuf_pagesize, KM_SLEEP);
289060d2ed9Sahoka 	rw_init(&chmp->chm_lock_wbuf);
290060d2ed9Sahoka 
291aa98cbbaSttoth 	/* Initialize queues. */
292060d2ed9Sahoka 	TAILQ_INIT(&chmp->chm_free_queue);
293060d2ed9Sahoka 	TAILQ_INIT(&chmp->chm_clean_queue);
294060d2ed9Sahoka 	TAILQ_INIT(&chmp->chm_dirty_queue);
295060d2ed9Sahoka 	TAILQ_INIT(&chmp->chm_very_dirty_queue);
296060d2ed9Sahoka 	TAILQ_INIT(&chmp->chm_erasable_pending_wbuf_queue);
297060d2ed9Sahoka 	TAILQ_INIT(&chmp->chm_erase_pending_queue);
298060d2ed9Sahoka 
299aa98cbbaSttoth 	/* Initialize flash-specific constants. */
300060d2ed9Sahoka 	chfs_calc_trigger_levels(chmp);
301060d2ed9Sahoka 
302aa98cbbaSttoth 	/* Initialize sizes. */
303060d2ed9Sahoka 	chmp->chm_nr_free_blocks = 0;
304060d2ed9Sahoka 	chmp->chm_nr_erasable_blocks = 0;
305060d2ed9Sahoka 	chmp->chm_max_vno = 2;
306060d2ed9Sahoka 	chmp->chm_checked_vno = 2;
307060d2ed9Sahoka 	chmp->chm_unchecked_size = 0;
308060d2ed9Sahoka 	chmp->chm_used_size = 0;
309060d2ed9Sahoka 	chmp->chm_dirty_size = 0;
310060d2ed9Sahoka 	chmp->chm_wasted_size = 0;
311060d2ed9Sahoka 	chmp->chm_free_size = chmp->chm_ebh->eb_size * chmp->chm_ebh->peb_nr;
312aa98cbbaSttoth 
313aa98cbbaSttoth 	/* Build filesystem. */
314060d2ed9Sahoka 	err = chfs_build_filesystem(chmp);
315060d2ed9Sahoka 
316060d2ed9Sahoka 	if (err) {
317aa98cbbaSttoth 		/* Armageddon and return. */
318060d2ed9Sahoka 		chfs_vnocache_hash_destroy(chmp->chm_vnocache_hash);
319060d2ed9Sahoka 		ebh_close(chmp->chm_ebh);
320a6388638Srmind 		err = EIO;
321a6388638Srmind 		goto fail;
322060d2ed9Sahoka 	}
323060d2ed9Sahoka 
324aa98cbbaSttoth 	/* Initialize UFS. */
325060d2ed9Sahoka 	mp->mnt_data = ump;
326060d2ed9Sahoka 	mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev;
327060d2ed9Sahoka 	mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_CHFS);
328060d2ed9Sahoka 	mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
329060d2ed9Sahoka 	mp->mnt_stat.f_namemax = MAXNAMLEN;
330060d2ed9Sahoka 	mp->mnt_flag |= MNT_LOCAL;
331060d2ed9Sahoka 	mp->mnt_fs_bshift = PAGE_SHIFT;
332060d2ed9Sahoka 	mp->mnt_dev_bshift = DEV_BSHIFT;
333060d2ed9Sahoka 	mp->mnt_iflag |= IMNT_MPSAFE;
334060d2ed9Sahoka 	ump->um_flags = 0;
335060d2ed9Sahoka 	ump->um_mountp = mp;
336060d2ed9Sahoka 	ump->um_dev = dev;
337060d2ed9Sahoka 	ump->um_devvp = devvp;
338060d2ed9Sahoka 	ump->um_maxfilesize = 1048512 * 1024;
339060d2ed9Sahoka 
340aa98cbbaSttoth 	/* Allocate the root vnode. */
341060d2ed9Sahoka 	err = VFS_VGET(mp, CHFS_ROOTINO, &vp);
342060d2ed9Sahoka 	if (err) {
343060d2ed9Sahoka 		dbg("error: %d while allocating root node\n", err);
344060d2ed9Sahoka 		return err;
345060d2ed9Sahoka 	}
346060d2ed9Sahoka 	vput(vp);
347060d2ed9Sahoka 
348aa98cbbaSttoth 	/* Start GC. */
349060d2ed9Sahoka 	chfs_gc_thread_start(chmp);
350060d2ed9Sahoka 	mutex_enter(&chmp->chm_lock_mountfields);
351060d2ed9Sahoka 	chfs_gc_trigger(chmp);
352060d2ed9Sahoka 	mutex_exit(&chmp->chm_lock_mountfields);
353060d2ed9Sahoka 
354ce2a78d3Shannken 	spec_node_setmountedfs(devvp, mp);
355060d2ed9Sahoka 	return 0;
356aa98cbbaSttoth 
357a6388638Srmind fail:
358a6388638Srmind 	kmem_free(chmp->chm_ebh, sizeof(struct chfs_ebh));
359a6388638Srmind 	kmem_free(chmp, sizeof(struct chfs_mount));
360a6388638Srmind 	kmem_free(ump, sizeof(struct ufsmount));
361a6388638Srmind 	return err;
362060d2ed9Sahoka }
363060d2ed9Sahoka 
364060d2ed9Sahoka /* --------------------------------------------------------------------- */
365060d2ed9Sahoka 
366060d2ed9Sahoka static int
367060d2ed9Sahoka chfs_unmount(struct mount *mp, int mntflags)
368060d2ed9Sahoka {
369060d2ed9Sahoka 	int flags = 0, i = 0;
370060d2ed9Sahoka 	struct ufsmount *ump;
371060d2ed9Sahoka 	struct chfs_mount *chmp;
372060d2ed9Sahoka 
373060d2ed9Sahoka 	if (mntflags & MNT_FORCE)
374060d2ed9Sahoka 		flags |= FORCECLOSE;
375060d2ed9Sahoka 
376060d2ed9Sahoka 	dbg("[START]\n");
377060d2ed9Sahoka 
378060d2ed9Sahoka 	ump = VFSTOUFS(mp);
379060d2ed9Sahoka 	chmp = ump->um_chfs;
380060d2ed9Sahoka 
381aa98cbbaSttoth 	/* Stop GC. */
382060d2ed9Sahoka 	chfs_gc_thread_stop(chmp);
383060d2ed9Sahoka 
384aa98cbbaSttoth 	/* Flush everyt buffer. */
385060d2ed9Sahoka 	(void)vflush(mp, NULLVP, flags);
386060d2ed9Sahoka 
387060d2ed9Sahoka 	if (chmp->chm_wbuf_len) {
388060d2ed9Sahoka 		mutex_enter(&chmp->chm_lock_mountfields);
389060d2ed9Sahoka 		chfs_flush_pending_wbuf(chmp);
390060d2ed9Sahoka 		mutex_exit(&chmp->chm_lock_mountfields);
391060d2ed9Sahoka 	}
392060d2ed9Sahoka 
393aa98cbbaSttoth 	/* Free node references. */
394060d2ed9Sahoka 	for (i = 0; i < chmp->chm_ebh->peb_nr; i++) {
395060d2ed9Sahoka 		chfs_free_node_refs(&chmp->chm_blocks[i]);
396060d2ed9Sahoka 	}
397060d2ed9Sahoka 
398aa98cbbaSttoth 	/* Destroy vnode cache hashtable. */
399060d2ed9Sahoka 	chfs_vnocache_hash_destroy(chmp->chm_vnocache_hash);
400060d2ed9Sahoka 
401aa98cbbaSttoth 	/* Close eraseblock handler. */
402060d2ed9Sahoka 	ebh_close(chmp->chm_ebh);
403060d2ed9Sahoka 
404aa98cbbaSttoth 	/* Destroy mutexes. */
405060d2ed9Sahoka 	rw_destroy(&chmp->chm_lock_wbuf);
406060d2ed9Sahoka 	mutex_destroy(&chmp->chm_lock_vnocache);
407060d2ed9Sahoka 	mutex_destroy(&chmp->chm_lock_sizes);
408060d2ed9Sahoka 	mutex_destroy(&chmp->chm_lock_mountfields);
409060d2ed9Sahoka 
410aa98cbbaSttoth 	/* Unmount UFS. */
411060d2ed9Sahoka 	if (ump->um_devvp->v_type != VBAD) {
412ce2a78d3Shannken 		spec_node_setmountedfs(ump->um_devvp, NULL);
413060d2ed9Sahoka 	}
414060d2ed9Sahoka 	vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY);
415060d2ed9Sahoka 	(void)VOP_CLOSE(ump->um_devvp, FREAD|FWRITE, NOCRED);
416060d2ed9Sahoka 	vput(ump->um_devvp);
417060d2ed9Sahoka 
418060d2ed9Sahoka 	mutex_destroy(&ump->um_lock);
419060d2ed9Sahoka 
420aa98cbbaSttoth 	/* Everything done. */
421a6388638Srmind 	kmem_free(ump, sizeof(struct ufsmount));
422060d2ed9Sahoka 	mp->mnt_data = NULL;
423060d2ed9Sahoka 	mp->mnt_flag &= ~MNT_LOCAL;
424060d2ed9Sahoka 	dbg("[END]\n");
425060d2ed9Sahoka 	return (0);
426060d2ed9Sahoka }
427060d2ed9Sahoka 
428060d2ed9Sahoka /* --------------------------------------------------------------------- */
429060d2ed9Sahoka 
430060d2ed9Sahoka static int
431060d2ed9Sahoka chfs_root(struct mount *mp, struct vnode **vpp)
432060d2ed9Sahoka {
433060d2ed9Sahoka 	struct vnode *vp;
434060d2ed9Sahoka 	int error;
435060d2ed9Sahoka 
436d8eae7d2Sdholland 	if ((error = VFS_VGET(mp, (ino_t)UFS_ROOTINO, &vp)) != 0)
437060d2ed9Sahoka 		return error;
438060d2ed9Sahoka 	*vpp = vp;
439060d2ed9Sahoka 	return 0;
440060d2ed9Sahoka }
441060d2ed9Sahoka 
442060d2ed9Sahoka /* --------------------------------------------------------------------- */
443060d2ed9Sahoka 
444060d2ed9Sahoka extern rb_tree_ops_t frag_rbtree_ops;
445060d2ed9Sahoka 
446060d2ed9Sahoka static int
447060d2ed9Sahoka chfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
448060d2ed9Sahoka {
449060d2ed9Sahoka 	struct chfs_mount *chmp;
450060d2ed9Sahoka 	struct chfs_inode *ip;
451060d2ed9Sahoka 	struct ufsmount *ump;
452060d2ed9Sahoka 	struct vnode *vp;
453060d2ed9Sahoka 	dev_t dev;
454060d2ed9Sahoka 	int error;
455060d2ed9Sahoka 	struct chfs_vnode_cache* chvc = NULL;
456060d2ed9Sahoka 	struct chfs_node_ref* nref = NULL;
457060d2ed9Sahoka 	struct buf *bp;
458060d2ed9Sahoka 
45991acea70Sagc 	dbg("vget() | ino: %llu\n", (unsigned long long)ino);
460060d2ed9Sahoka 
461060d2ed9Sahoka 	ump = VFSTOUFS(mp);
462060d2ed9Sahoka 	dev = ump->um_dev;
463060d2ed9Sahoka retry:
464060d2ed9Sahoka 	if (!vpp) {
465060d2ed9Sahoka 		vpp = kmem_alloc(sizeof(struct vnode*), KM_SLEEP);
466060d2ed9Sahoka 	}
467060d2ed9Sahoka 
468aa98cbbaSttoth 	/* Get node from inode hash. */
469060d2ed9Sahoka 	if ((*vpp = chfs_ihashget(dev, ino, LK_EXCLUSIVE)) != NULL) {
470060d2ed9Sahoka 		return 0;
471060d2ed9Sahoka 	}
472060d2ed9Sahoka 
473060d2ed9Sahoka 	/* Allocate a new vnode/inode. */
474060d2ed9Sahoka 	if ((error = getnewvnode(VT_CHFS,
475060d2ed9Sahoka 		    mp, chfs_vnodeop_p, NULL, &vp)) != 0) {
476060d2ed9Sahoka 		*vpp = NULL;
477060d2ed9Sahoka 		return (error);
478060d2ed9Sahoka 	}
479060d2ed9Sahoka 	ip = pool_get(&chfs_inode_pool, PR_WAITOK);
480060d2ed9Sahoka 
481060d2ed9Sahoka 	mutex_enter(&chfs_hashlock);
482060d2ed9Sahoka 	if ((*vpp = chfs_ihashget(dev, ino, LK_EXCLUSIVE)) != NULL) {
483060d2ed9Sahoka 		mutex_exit(&chfs_hashlock);
484060d2ed9Sahoka 		ungetnewvnode(vp);
485060d2ed9Sahoka 		pool_put(&chfs_inode_pool, ip);
486060d2ed9Sahoka 		goto retry;
487060d2ed9Sahoka 	}
488060d2ed9Sahoka 
489060d2ed9Sahoka 	vp->v_vflag |= VV_LOCKSWORK;
490060d2ed9Sahoka 
491aa98cbbaSttoth 	/* Initialize vnode/inode. */
492060d2ed9Sahoka 	memset(ip, 0, sizeof(*ip));
493060d2ed9Sahoka 	vp->v_data = ip;
494060d2ed9Sahoka 	ip->vp = vp;
495e6a23d44Sttoth 	ip->ch_type = VTTOCHT(vp->v_type);
496060d2ed9Sahoka 	ip->ump = ump;
497060d2ed9Sahoka 	ip->chmp = chmp = ump->um_chfs;
498060d2ed9Sahoka 	ip->dev = dev;
499060d2ed9Sahoka 	ip->ino = ino;
500060d2ed9Sahoka 	vp->v_mount = mp;
501060d2ed9Sahoka 	genfs_node_init(vp, &chfs_genfsops);
502060d2ed9Sahoka 
503060d2ed9Sahoka 	rb_tree_init(&ip->fragtree, &frag_rbtree_ops);
504060d2ed9Sahoka 
505060d2ed9Sahoka 	chfs_ihashins(ip);
506060d2ed9Sahoka 	mutex_exit(&chfs_hashlock);
507060d2ed9Sahoka 
508aa98cbbaSttoth 	/* Set root inode. */
509060d2ed9Sahoka 	if (ino == CHFS_ROOTINO) {
510060d2ed9Sahoka 		dbg("SETROOT\n");
511060d2ed9Sahoka 		vp->v_vflag |= VV_ROOT;
512060d2ed9Sahoka 		vp->v_type = VDIR;
513e6a23d44Sttoth 		ip->ch_type = CHT_DIR;
514060d2ed9Sahoka 		ip->mode = IFMT | IEXEC | IWRITE | IREAD;
515060d2ed9Sahoka 		ip->iflag |= (IN_ACCESS | IN_CHANGE | IN_UPDATE);
516060d2ed9Sahoka 		chfs_update(vp, NULL, NULL, UPDATE_WAIT);
517060d2ed9Sahoka 		TAILQ_INIT(&ip->dents);
518060d2ed9Sahoka 		chfs_set_vnode_size(vp, 512);
519060d2ed9Sahoka 	}
520060d2ed9Sahoka 
521060d2ed9Sahoka 	mutex_enter(&chmp->chm_lock_vnocache);
522060d2ed9Sahoka 	chvc = chfs_vnode_cache_get(chmp, ino);
523060d2ed9Sahoka 	mutex_exit(&chmp->chm_lock_vnocache);
524060d2ed9Sahoka 	if (!chvc) {
525060d2ed9Sahoka 		dbg("!chvc\n");
526aa98cbbaSttoth 		/* Initialize the corresponding vnode cache. */
527060d2ed9Sahoka 		/* XXX, we cant alloc under a lock, refactor this! */
528060d2ed9Sahoka 		chvc = chfs_vnode_cache_alloc(ino);
529060d2ed9Sahoka 		mutex_enter(&chmp->chm_lock_vnocache);
530060d2ed9Sahoka 		if (ino == CHFS_ROOTINO) {
531060d2ed9Sahoka 			chvc->nlink = 2;
532060d2ed9Sahoka 			chvc->pvno = CHFS_ROOTINO;
5337982b4ffSttoth 			chvc->state = VNO_STATE_CHECKEDABSENT;
534060d2ed9Sahoka 		}
535060d2ed9Sahoka 		chfs_vnode_cache_add(chmp, chvc);
536060d2ed9Sahoka 		mutex_exit(&chmp->chm_lock_vnocache);
537060d2ed9Sahoka 
538060d2ed9Sahoka 		ip->chvc = chvc;
539060d2ed9Sahoka 		TAILQ_INIT(&ip->dents);
540060d2ed9Sahoka 	} else {
541060d2ed9Sahoka 		dbg("chvc\n");
542060d2ed9Sahoka 		ip->chvc = chvc;
543aa98cbbaSttoth 		/* We had a vnode cache, the node is already on flash, so read it */
544060d2ed9Sahoka 		if (ino == CHFS_ROOTINO) {
545060d2ed9Sahoka 			chvc->pvno = CHFS_ROOTINO;
546060d2ed9Sahoka 			TAILQ_INIT(&chvc->scan_dirents);
547060d2ed9Sahoka 		} else {
548060d2ed9Sahoka 			chfs_readvnode(mp, ino, &vp);
549060d2ed9Sahoka 		}
550060d2ed9Sahoka 
551060d2ed9Sahoka 		mutex_enter(&chmp->chm_lock_mountfields);
552aa98cbbaSttoth 		/* Initialize type specific things. */
553e6a23d44Sttoth 		switch (ip->ch_type) {
554e6a23d44Sttoth 		case CHT_DIR:
555aa98cbbaSttoth 			/* Read every dirent. */
556060d2ed9Sahoka 			nref = chvc->dirents;
557060d2ed9Sahoka 			while (nref &&
558060d2ed9Sahoka 			    (struct chfs_vnode_cache *)nref != chvc) {
559060d2ed9Sahoka 				chfs_readdirent(mp, nref, ip);
560060d2ed9Sahoka 				nref = nref->nref_next;
561060d2ed9Sahoka 			}
562060d2ed9Sahoka 			chfs_set_vnode_size(vp, 512);
563060d2ed9Sahoka 			break;
564e6a23d44Sttoth 		case CHT_REG:
565aa98cbbaSttoth 			/* FALLTHROUGH */
566e6a23d44Sttoth 		case CHT_SOCK:
567aa98cbbaSttoth 			/* Collect data. */
56891acea70Sagc 			dbg("read_inode_internal | ino: %llu\n",
56991acea70Sagc 				(unsigned long long)ip->ino);
570060d2ed9Sahoka 			error = chfs_read_inode(chmp, ip);
571060d2ed9Sahoka 			if (error) {
572060d2ed9Sahoka 				vput(vp);
573060d2ed9Sahoka 				*vpp = NULL;
574060d2ed9Sahoka 				mutex_exit(&chmp->chm_lock_mountfields);
575060d2ed9Sahoka 				return (error);
576060d2ed9Sahoka 			}
577060d2ed9Sahoka 			break;
578e6a23d44Sttoth 		case CHT_LNK:
579aa98cbbaSttoth 			/* Collect data. */
58091acea70Sagc 			dbg("read_inode_internal | ino: %llu\n",
58191acea70Sagc 				(unsigned long long)ip->ino);
582060d2ed9Sahoka 			error = chfs_read_inode_internal(chmp, ip);
583060d2ed9Sahoka 			if (error) {
584060d2ed9Sahoka 				vput(vp);
585060d2ed9Sahoka 				*vpp = NULL;
586060d2ed9Sahoka 				mutex_exit(&chmp->chm_lock_mountfields);
587060d2ed9Sahoka 				return (error);
588060d2ed9Sahoka 			}
589060d2ed9Sahoka 
590aa98cbbaSttoth 			/* Set link. */
59191acea70Sagc 			dbg("size: %llu\n", (unsigned long long)ip->size);
592060d2ed9Sahoka 			bp = getiobuf(vp, true);
593060d2ed9Sahoka 			bp->b_blkno = 0;
594060d2ed9Sahoka 			bp->b_bufsize = bp->b_resid =
595060d2ed9Sahoka 			    bp->b_bcount = ip->size;
596060d2ed9Sahoka 			bp->b_data = kmem_alloc(ip->size, KM_SLEEP);
597060d2ed9Sahoka 			chfs_read_data(chmp, vp, bp);
598060d2ed9Sahoka 			if (!ip->target)
599060d2ed9Sahoka 				ip->target = kmem_alloc(ip->size,
600060d2ed9Sahoka 				    KM_SLEEP);
601060d2ed9Sahoka 			memcpy(ip->target, bp->b_data, ip->size);
602060d2ed9Sahoka 			kmem_free(bp->b_data, ip->size);
603060d2ed9Sahoka 			putiobuf(bp);
604060d2ed9Sahoka 
605060d2ed9Sahoka 			break;
606e6a23d44Sttoth 		case CHT_CHR:
607aa98cbbaSttoth 			/* FALLTHROUGH */
608e6a23d44Sttoth 		case CHT_BLK:
609aa98cbbaSttoth 			/* FALLTHROUGH */
610e6a23d44Sttoth 		case CHT_FIFO:
611aa98cbbaSttoth 			/* Collect data. */
61291acea70Sagc 			dbg("read_inode_internal | ino: %llu\n",
61391acea70Sagc 				(unsigned long long)ip->ino);
614060d2ed9Sahoka 			error = chfs_read_inode_internal(chmp, ip);
615060d2ed9Sahoka 			if (error) {
616060d2ed9Sahoka 				vput(vp);
617060d2ed9Sahoka 				*vpp = NULL;
618060d2ed9Sahoka 				mutex_exit(&chmp->chm_lock_mountfields);
619060d2ed9Sahoka 				return (error);
620060d2ed9Sahoka 			}
621060d2ed9Sahoka 
622aa98cbbaSttoth 			/* Set device. */
623060d2ed9Sahoka 			bp = getiobuf(vp, true);
624060d2ed9Sahoka 			bp->b_blkno = 0;
625060d2ed9Sahoka 			bp->b_bufsize = bp->b_resid =
626060d2ed9Sahoka 			    bp->b_bcount = sizeof(dev_t);
627060d2ed9Sahoka 			bp->b_data = kmem_alloc(sizeof(dev_t), KM_SLEEP);
628060d2ed9Sahoka 			chfs_read_data(chmp, vp, bp);
629060d2ed9Sahoka 			memcpy(&ip->rdev,
630060d2ed9Sahoka 			    bp->b_data, sizeof(dev_t));
631060d2ed9Sahoka 			kmem_free(bp->b_data, sizeof(dev_t));
632060d2ed9Sahoka 			putiobuf(bp);
633aa98cbbaSttoth 			/* Set specific operations. */
634e6a23d44Sttoth 			if (ip->ch_type == CHT_FIFO) {
635060d2ed9Sahoka 				vp->v_op = chfs_fifoop_p;
636e6a23d44Sttoth 			} else {
637060d2ed9Sahoka 				vp->v_op = chfs_specop_p;
638060d2ed9Sahoka 				spec_node_init(vp, ip->rdev);
639060d2ed9Sahoka 			}
640060d2ed9Sahoka 
641060d2ed9Sahoka 		    break;
642e6a23d44Sttoth 		case CHT_BLANK:
643aa98cbbaSttoth 			/* FALLTHROUGH */
644e6a23d44Sttoth 		case CHT_BAD:
645060d2ed9Sahoka 			break;
646060d2ed9Sahoka 		}
647060d2ed9Sahoka 		mutex_exit(&chmp->chm_lock_mountfields);
648060d2ed9Sahoka 
649060d2ed9Sahoka 	}
650060d2ed9Sahoka 
651aa98cbbaSttoth 	/* Finish inode initalization. */
652060d2ed9Sahoka 	ip->devvp = ump->um_devvp;
653060d2ed9Sahoka 	vref(ip->devvp);
654060d2ed9Sahoka 
655060d2ed9Sahoka 	uvm_vnp_setsize(vp, ip->size);
656060d2ed9Sahoka 	*vpp = vp;
657060d2ed9Sahoka 
658060d2ed9Sahoka 	return 0;
659060d2ed9Sahoka }
660060d2ed9Sahoka 
661060d2ed9Sahoka /* --------------------------------------------------------------------- */
662060d2ed9Sahoka 
663060d2ed9Sahoka static int
664060d2ed9Sahoka chfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
665060d2ed9Sahoka {
666060d2ed9Sahoka 	return ENODEV;
667060d2ed9Sahoka }
668060d2ed9Sahoka 
669060d2ed9Sahoka /* --------------------------------------------------------------------- */
670060d2ed9Sahoka 
671060d2ed9Sahoka static int
672060d2ed9Sahoka chfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
673060d2ed9Sahoka {
674060d2ed9Sahoka 	return ENODEV;
675060d2ed9Sahoka }
676060d2ed9Sahoka 
677060d2ed9Sahoka /* --------------------------------------------------------------------- */
678060d2ed9Sahoka 
679060d2ed9Sahoka static int
680060d2ed9Sahoka chfs_start(struct mount *mp, int flags)
681060d2ed9Sahoka {
682060d2ed9Sahoka 	return 0;
683060d2ed9Sahoka }
684060d2ed9Sahoka 
685060d2ed9Sahoka /* --------------------------------------------------------------------- */
686060d2ed9Sahoka 
687060d2ed9Sahoka static int
688060d2ed9Sahoka chfs_statvfs(struct mount *mp, struct statvfs *sbp)
689060d2ed9Sahoka {
690060d2ed9Sahoka  	struct chfs_mount *chmp;
691060d2ed9Sahoka 	struct ufsmount *ump;
692060d2ed9Sahoka 	dbg("statvfs\n");
693060d2ed9Sahoka 
694060d2ed9Sahoka 	ump = VFSTOUFS(mp);
695060d2ed9Sahoka 	chmp = ump->um_chfs;
696060d2ed9Sahoka 
697060d2ed9Sahoka 	sbp->f_flag   = mp->mnt_flag;
698060d2ed9Sahoka 	sbp->f_bsize  = chmp->chm_ebh->eb_size;
699060d2ed9Sahoka 	sbp->f_frsize = chmp->chm_ebh->eb_size;
700060d2ed9Sahoka 	sbp->f_iosize = chmp->chm_ebh->eb_size;
701060d2ed9Sahoka 
702060d2ed9Sahoka 	sbp->f_blocks = chmp->chm_ebh->peb_nr;
703060d2ed9Sahoka 	sbp->f_files  = 0;
704060d2ed9Sahoka 	sbp->f_bavail = chmp->chm_nr_free_blocks - chmp->chm_resv_blocks_write;
705060d2ed9Sahoka 
706060d2ed9Sahoka 	sbp->f_bfree = chmp->chm_nr_free_blocks;
707060d2ed9Sahoka 	sbp->f_bresvd = chmp->chm_resv_blocks_write;
708060d2ed9Sahoka 
709060d2ed9Sahoka 	/* FFS specific */
710060d2ed9Sahoka 	sbp->f_ffree  = 0;
711060d2ed9Sahoka 	sbp->f_favail = 0;
712060d2ed9Sahoka 	sbp->f_fresvd = 0;
713060d2ed9Sahoka 
714060d2ed9Sahoka 	copy_statvfs_info(sbp, mp);
715060d2ed9Sahoka 
716060d2ed9Sahoka 	return 0;
717060d2ed9Sahoka }
718060d2ed9Sahoka 
719060d2ed9Sahoka /* --------------------------------------------------------------------- */
720060d2ed9Sahoka 
721060d2ed9Sahoka static int
722060d2ed9Sahoka chfs_sync(struct mount *mp, int waitfor,
723060d2ed9Sahoka     kauth_cred_t uc)
724060d2ed9Sahoka {
725060d2ed9Sahoka 	return 0;
726060d2ed9Sahoka }
727060d2ed9Sahoka 
728060d2ed9Sahoka /* --------------------------------------------------------------------- */
729060d2ed9Sahoka 
730060d2ed9Sahoka static void
731060d2ed9Sahoka chfs_init(void)
732060d2ed9Sahoka {
733aa98cbbaSttoth 	/* Initialize pools and inode hash. */
734060d2ed9Sahoka 	chfs_alloc_pool_caches();
735060d2ed9Sahoka 	chfs_ihashinit();
736060d2ed9Sahoka 	pool_init(&chfs_inode_pool, sizeof(struct chfs_inode), 0, 0, 0,
737060d2ed9Sahoka 	    "chfsinopl", &pool_allocator_nointr, IPL_NONE);
738060d2ed9Sahoka 	ufs_init();
739060d2ed9Sahoka }
740060d2ed9Sahoka 
741060d2ed9Sahoka /* --------------------------------------------------------------------- */
742060d2ed9Sahoka 
743060d2ed9Sahoka static void
744060d2ed9Sahoka chfs_reinit(void)
745060d2ed9Sahoka {
746060d2ed9Sahoka 	chfs_ihashreinit();
747060d2ed9Sahoka 	ufs_reinit();
748060d2ed9Sahoka }
749060d2ed9Sahoka 
750060d2ed9Sahoka /* --------------------------------------------------------------------- */
751060d2ed9Sahoka 
752060d2ed9Sahoka static void
753060d2ed9Sahoka chfs_done(void)
754060d2ed9Sahoka {
755060d2ed9Sahoka 	ufs_done();
756060d2ed9Sahoka 	chfs_ihashdone();
757060d2ed9Sahoka 	pool_destroy(&chfs_inode_pool);
758060d2ed9Sahoka 	chfs_destroy_pool_caches();
759060d2ed9Sahoka }
760060d2ed9Sahoka 
761060d2ed9Sahoka /* --------------------------------------------------------------------- */
762060d2ed9Sahoka 
763060d2ed9Sahoka static int
764060d2ed9Sahoka chfs_snapshot(struct mount *mp, struct vnode *vp,
765060d2ed9Sahoka     struct timespec *ctime)
766060d2ed9Sahoka {
767060d2ed9Sahoka 	return ENODEV;
768060d2ed9Sahoka }
769060d2ed9Sahoka 
770060d2ed9Sahoka /* --------------------------------------------------------------------- */
771060d2ed9Sahoka 
772060d2ed9Sahoka /*
773060d2ed9Sahoka  * chfs vfs operations.
774060d2ed9Sahoka  */
775060d2ed9Sahoka 
776060d2ed9Sahoka extern const struct vnodeopv_desc chfs_fifoop_opv_desc;
777060d2ed9Sahoka extern const struct vnodeopv_desc chfs_specop_opv_desc;
778060d2ed9Sahoka extern const struct vnodeopv_desc chfs_vnodeop_opv_desc;
779060d2ed9Sahoka 
780060d2ed9Sahoka const struct vnodeopv_desc * const chfs_vnodeopv_descs[] = {
781060d2ed9Sahoka 	&chfs_fifoop_opv_desc,
782060d2ed9Sahoka 	&chfs_specop_opv_desc,
783060d2ed9Sahoka 	&chfs_vnodeop_opv_desc,
784060d2ed9Sahoka 	NULL,
785060d2ed9Sahoka };
786060d2ed9Sahoka 
787060d2ed9Sahoka struct vfsops chfs_vfsops = {
788*97116d3bShannken 	.vfs_name = MOUNT_CHFS,
789*97116d3bShannken 	.vfs_min_mount_data = sizeof (struct chfs_args),
790*97116d3bShannken 	.vfs_mount = chfs_mount,
791*97116d3bShannken 	.vfs_start = chfs_start,
792*97116d3bShannken 	.vfs_unmount = chfs_unmount,
793*97116d3bShannken 	.vfs_root = chfs_root,
794*97116d3bShannken 	.vfs_quotactl = ufs_quotactl,
795*97116d3bShannken 	.vfs_statvfs = chfs_statvfs,
796*97116d3bShannken 	.vfs_sync = chfs_sync,
797*97116d3bShannken 	.vfs_vget = chfs_vget,
798*97116d3bShannken 	.vfs_fhtovp = chfs_fhtovp,
799*97116d3bShannken 	.vfs_vptofh = chfs_vptofh,
800*97116d3bShannken 	.vfs_init = chfs_init,
801*97116d3bShannken 	.vfs_reinit = chfs_reinit,
802*97116d3bShannken 	.vfs_done = chfs_done,
803*97116d3bShannken 	.vfs_snapshot = chfs_snapshot,
804*97116d3bShannken 	.vfs_extattrctl = vfs_stdextattrctl,
805*97116d3bShannken 	.vfs_suspendctl = (void *)eopnotsupp,
806*97116d3bShannken 	.vfs_renamelock_enter = genfs_renamelock_enter,
807*97116d3bShannken 	.vfs_renamelock_exit = genfs_renamelock_exit,
808*97116d3bShannken 	.vfs_fsync = (void *)eopnotsupp,
809*97116d3bShannken 	.vfs_opv_descs = chfs_vnodeopv_descs
810060d2ed9Sahoka };
811060d2ed9Sahoka 
812aa98cbbaSttoth /* For using CHFS as a module. */
813060d2ed9Sahoka static int
814060d2ed9Sahoka chfs_modcmd(modcmd_t cmd, void *arg)
815060d2ed9Sahoka {
816060d2ed9Sahoka 	switch (cmd) {
817060d2ed9Sahoka 	case MODULE_CMD_INIT:
818060d2ed9Sahoka 		return vfs_attach(&chfs_vfsops);
819060d2ed9Sahoka 	case MODULE_CMD_FINI:
820060d2ed9Sahoka 		return vfs_detach(&chfs_vfsops);
821060d2ed9Sahoka 	default:
822060d2ed9Sahoka 		return ENOTTY;
823060d2ed9Sahoka 	}
824060d2ed9Sahoka }
825