1*6a9242deSriastradh /* $NetBSD: chfs_vfsops.c,v 1.17 2017/11/14 22:06:40 riastradh 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/fcntl.h> 47060d2ed9Sahoka #include <sys/conf.h> 48060d2ed9Sahoka #include <sys/buf.h> 49060d2ed9Sahoka //XXX needed just for debugging 50060d2ed9Sahoka #include <sys/fstrans.h> 51060d2ed9Sahoka #include <sys/sleepq.h> 52060d2ed9Sahoka #include <sys/lockdebug.h> 53060d2ed9Sahoka #include <sys/ktrace.h> 54060d2ed9Sahoka 55060d2ed9Sahoka #include <uvm/uvm.h> 56060d2ed9Sahoka #include <uvm/uvm_pager.h> 57060d2ed9Sahoka #include <ufs/ufs/dir.h> 58060d2ed9Sahoka #include <ufs/ufs/ufs_extern.h> 59060d2ed9Sahoka #include <miscfs/genfs/genfs.h> 60060d2ed9Sahoka #include <miscfs/genfs/genfs_node.h> 61060d2ed9Sahoka #include <miscfs/specfs/specdev.h> 62060d2ed9Sahoka #include "chfs.h" 63060d2ed9Sahoka #include "chfs_args.h" 64060d2ed9Sahoka 65060d2ed9Sahoka MODULE(MODULE_CLASS_VFS, chfs, "flash"); 66060d2ed9Sahoka 67060d2ed9Sahoka /* --------------------------------------------------------------------- */ 68060d2ed9Sahoka /* functions */ 69060d2ed9Sahoka 70060d2ed9Sahoka static int chfs_mount(struct mount *, const char *, void *, size_t *); 71060d2ed9Sahoka static int chfs_unmount(struct mount *, int); 72060d2ed9Sahoka static int chfs_root(struct mount *, struct vnode **); 7366996266Shannken static int chfs_loadvnode(struct mount *, struct vnode *, 7466996266Shannken const void *, size_t, const void **); 75060d2ed9Sahoka static int chfs_vget(struct mount *, ino_t, struct vnode **); 76060d2ed9Sahoka static int chfs_fhtovp(struct mount *, struct fid *, struct vnode **); 77060d2ed9Sahoka static int chfs_vptofh(struct vnode *, struct fid *, size_t *); 78060d2ed9Sahoka static int chfs_start(struct mount *, int); 79060d2ed9Sahoka static int chfs_statvfs(struct mount *, struct statvfs *); 80060d2ed9Sahoka static int chfs_sync(struct mount *, int, kauth_cred_t); 81060d2ed9Sahoka static void chfs_init(void); 82060d2ed9Sahoka static void chfs_reinit(void); 83060d2ed9Sahoka static void chfs_done(void); 84060d2ed9Sahoka static int chfs_snapshot(struct mount *, struct vnode *, 85060d2ed9Sahoka struct timespec *); 86060d2ed9Sahoka 87060d2ed9Sahoka /* --------------------------------------------------------------------- */ 88060d2ed9Sahoka /* structures */ 89060d2ed9Sahoka 90060d2ed9Sahoka int 91060d2ed9Sahoka chfs_gop_alloc(struct vnode *vp, off_t off, off_t len, int flags, 92060d2ed9Sahoka kauth_cred_t cred) 93060d2ed9Sahoka { 94060d2ed9Sahoka return (0); 95060d2ed9Sahoka } 96060d2ed9Sahoka 97060d2ed9Sahoka const struct genfs_ops chfs_genfsops = { 98060d2ed9Sahoka .gop_size = genfs_size, 99060d2ed9Sahoka .gop_alloc = chfs_gop_alloc, 100060d2ed9Sahoka .gop_write = genfs_gop_write, 101060d2ed9Sahoka .gop_markupdate = ufs_gop_markupdate, 102060d2ed9Sahoka }; 103060d2ed9Sahoka 104060d2ed9Sahoka struct pool chfs_inode_pool; 105060d2ed9Sahoka 106060d2ed9Sahoka /* for looking up the major for flash */ 107060d2ed9Sahoka extern const struct cdevsw flash_cdevsw; 108060d2ed9Sahoka 109060d2ed9Sahoka /* --------------------------------------------------------------------- */ 110060d2ed9Sahoka 111060d2ed9Sahoka static int 112060d2ed9Sahoka chfs_mount(struct mount *mp, 113060d2ed9Sahoka const char *path, void *data, size_t *data_len) 114060d2ed9Sahoka { 115060d2ed9Sahoka struct lwp *l = curlwp; 116060d2ed9Sahoka struct nameidata nd; 117060d2ed9Sahoka struct pathbuf *pb; 118060d2ed9Sahoka struct vnode *devvp = NULL; 119060d2ed9Sahoka struct ufs_args *args = data; 120060d2ed9Sahoka struct ufsmount *ump = NULL; 121060d2ed9Sahoka struct chfs_mount *chmp; 122060d2ed9Sahoka int err = 0; 123060d2ed9Sahoka int xflags; 124060d2ed9Sahoka 125060d2ed9Sahoka dbg("mount()\n"); 126060d2ed9Sahoka 127f4f7f4f3Smaxv if (args == NULL) 128f4f7f4f3Smaxv return EINVAL; 129060d2ed9Sahoka if (*data_len < sizeof *args) 130060d2ed9Sahoka return EINVAL; 131060d2ed9Sahoka 132060d2ed9Sahoka if (mp->mnt_flag & MNT_GETARGS) { 133060d2ed9Sahoka ump = VFSTOUFS(mp); 134060d2ed9Sahoka if (ump == NULL) 135060d2ed9Sahoka return EIO; 136060d2ed9Sahoka memset(args, 0, sizeof *args); 137060d2ed9Sahoka args->fspec = NULL; 138060d2ed9Sahoka *data_len = sizeof *args; 139060d2ed9Sahoka return 0; 140060d2ed9Sahoka } 141060d2ed9Sahoka 142060d2ed9Sahoka if (mp->mnt_flag & MNT_UPDATE) { 143060d2ed9Sahoka /* XXX: There is no support yet to update file system 144060d2ed9Sahoka * settings. Should be added. */ 145060d2ed9Sahoka 146060d2ed9Sahoka return ENODEV; 147060d2ed9Sahoka } 148060d2ed9Sahoka 149060d2ed9Sahoka if (args->fspec != NULL) { 150060d2ed9Sahoka err = pathbuf_copyin(args->fspec, &pb); 151060d2ed9Sahoka if (err) { 152060d2ed9Sahoka return err; 153060d2ed9Sahoka } 154aa98cbbaSttoth /* Look up the name and verify that it's sane. */ 155060d2ed9Sahoka NDINIT(&nd, LOOKUP, FOLLOW, pb); 15654778a05Schristos err = namei(&nd); 157858a9750Smaxv pathbuf_destroy(pb); 15854778a05Schristos if (err) 15954778a05Schristos return err; 160060d2ed9Sahoka devvp = nd.ni_vp; 161060d2ed9Sahoka 162aa98cbbaSttoth /* Be sure this is a valid block device */ 163060d2ed9Sahoka if (devvp->v_type != VBLK) 164060d2ed9Sahoka err = ENOTBLK; 165060d2ed9Sahoka else if (bdevsw_lookup(devvp->v_rdev) == NULL) 166060d2ed9Sahoka err = ENXIO; 167060d2ed9Sahoka } 168060d2ed9Sahoka 169060d2ed9Sahoka if (err) { 170060d2ed9Sahoka vrele(devvp); 171060d2ed9Sahoka return (err); 172060d2ed9Sahoka } 173060d2ed9Sahoka 174060d2ed9Sahoka if (mp->mnt_flag & MNT_RDONLY) 175060d2ed9Sahoka xflags = FREAD; 176060d2ed9Sahoka else 177060d2ed9Sahoka xflags = FREAD|FWRITE; 178060d2ed9Sahoka 179060d2ed9Sahoka err = VOP_OPEN(devvp, xflags, FSCRED); 180060d2ed9Sahoka if (err) 181060d2ed9Sahoka goto fail; 182060d2ed9Sahoka 183aa98cbbaSttoth /* call CHFS mount function */ 184060d2ed9Sahoka err = chfs_mountfs(devvp, mp); 185060d2ed9Sahoka if (err) { 186060d2ed9Sahoka vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); 187060d2ed9Sahoka (void)VOP_CLOSE(devvp, xflags, NOCRED); 188060d2ed9Sahoka VOP_UNLOCK(devvp); 189060d2ed9Sahoka goto fail; 190060d2ed9Sahoka } 191aa98cbbaSttoth 192060d2ed9Sahoka ump = VFSTOUFS(mp); 193060d2ed9Sahoka chmp = ump->um_chfs; 194060d2ed9Sahoka 195060d2ed9Sahoka vfs_getnewfsid(mp); 196060d2ed9Sahoka chmp->chm_fsmp = mp; 197060d2ed9Sahoka 198060d2ed9Sahoka return set_statvfs_info(path, 199060d2ed9Sahoka UIO_USERSPACE, args->fspec, 200060d2ed9Sahoka UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l); 201060d2ed9Sahoka 202060d2ed9Sahoka fail: 203060d2ed9Sahoka vrele(devvp); 204060d2ed9Sahoka return (err); 205060d2ed9Sahoka } 206060d2ed9Sahoka 207aa98cbbaSttoth /* chfs_mountfs - init CHFS */ 208060d2ed9Sahoka int 209060d2ed9Sahoka chfs_mountfs(struct vnode *devvp, struct mount *mp) 210060d2ed9Sahoka { 211060d2ed9Sahoka struct lwp *l = curlwp; 212060d2ed9Sahoka kauth_cred_t cred; 213060d2ed9Sahoka devmajor_t flash_major; 214060d2ed9Sahoka dev_t dev; 215060d2ed9Sahoka struct ufsmount* ump = NULL; 216060d2ed9Sahoka struct chfs_mount* chmp; 217060d2ed9Sahoka struct vnode *vp; 218060d2ed9Sahoka int err = 0; 219060d2ed9Sahoka 220060d2ed9Sahoka dbg("mountfs()\n"); 221060d2ed9Sahoka 222060d2ed9Sahoka dev = devvp->v_rdev; 223060d2ed9Sahoka cred = l ? l->l_cred : NOCRED; 224060d2ed9Sahoka 225060d2ed9Sahoka /* Flush out any old buffers remaining from a previous use. */ 226060d2ed9Sahoka vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); 227060d2ed9Sahoka err = vinvalbuf(devvp, V_SAVE, cred, l, 0, 0); 228060d2ed9Sahoka VOP_UNLOCK(devvp); 229060d2ed9Sahoka if (err) 230*6a9242deSriastradh goto fail0; 231060d2ed9Sahoka 232aa98cbbaSttoth /* Setup device. */ 233060d2ed9Sahoka flash_major = cdevsw_lookup_major(&flash_cdevsw); 234060d2ed9Sahoka 235060d2ed9Sahoka if (devvp->v_type != VBLK) 236060d2ed9Sahoka err = ENOTBLK; 237060d2ed9Sahoka else if (bdevsw_lookup(dev) == NULL) 238060d2ed9Sahoka err = ENXIO; 239060d2ed9Sahoka else if (major(dev) != flash_major) { 240060d2ed9Sahoka dbg("major(dev): %d, flash_major: %d\n", 241060d2ed9Sahoka major(dev), flash_major); 242060d2ed9Sahoka err = ENODEV; 243060d2ed9Sahoka } 244*6a9242deSriastradh if (err) 245*6a9242deSriastradh goto fail0; 246060d2ed9Sahoka 247aa98cbbaSttoth /* Connect CHFS to UFS. */ 248a6388638Srmind ump = kmem_zalloc(sizeof(struct ufsmount), KM_SLEEP); 249a6388638Srmind 250060d2ed9Sahoka ump->um_fstype = UFS1; 251a6388638Srmind ump->um_chfs = kmem_zalloc(sizeof(struct chfs_mount), KM_SLEEP); 252060d2ed9Sahoka mutex_init(&ump->um_lock, MUTEX_DEFAULT, IPL_NONE); 253060d2ed9Sahoka 254060d2ed9Sahoka chmp = ump->um_chfs; 255060d2ed9Sahoka 256aa98cbbaSttoth /* Initialize erase block handler. */ 257060d2ed9Sahoka chmp->chm_ebh = kmem_alloc(sizeof(struct chfs_ebh), KM_SLEEP); 258060d2ed9Sahoka 259060d2ed9Sahoka dbg("[]opening flash: %u\n", (unsigned int)devvp->v_rdev); 260060d2ed9Sahoka err = ebh_open(chmp->chm_ebh, devvp->v_rdev); 261060d2ed9Sahoka if (err) { 262060d2ed9Sahoka dbg("error while opening flash\n"); 263*6a9242deSriastradh goto fail1; 264060d2ed9Sahoka } 265060d2ed9Sahoka 266060d2ed9Sahoka //TODO check flash sizes 267060d2ed9Sahoka 268aa98cbbaSttoth /* Initialize vnode cache's hashtable and eraseblock array. */ 269060d2ed9Sahoka chmp->chm_gbl_version = 0; 270060d2ed9Sahoka chmp->chm_vnocache_hash = chfs_vnocache_hash_init(); 271060d2ed9Sahoka 272060d2ed9Sahoka chmp->chm_blocks = kmem_zalloc(chmp->chm_ebh->peb_nr * 273060d2ed9Sahoka sizeof(struct chfs_eraseblock), KM_SLEEP); 274060d2ed9Sahoka 275aa98cbbaSttoth /* Initialize mutexes. */ 276060d2ed9Sahoka mutex_init(&chmp->chm_lock_mountfields, MUTEX_DEFAULT, IPL_NONE); 277060d2ed9Sahoka mutex_init(&chmp->chm_lock_sizes, MUTEX_DEFAULT, IPL_NONE); 278060d2ed9Sahoka mutex_init(&chmp->chm_lock_vnocache, MUTEX_DEFAULT, IPL_NONE); 279060d2ed9Sahoka 280aa98cbbaSttoth /* Initialize read/write contants. (from UFS) */ 281060d2ed9Sahoka chmp->chm_fs_bmask = -4096; 282060d2ed9Sahoka chmp->chm_fs_bsize = 4096; 283060d2ed9Sahoka chmp->chm_fs_qbmask = 4095; 284060d2ed9Sahoka chmp->chm_fs_bshift = 12; 285060d2ed9Sahoka chmp->chm_fs_fmask = -2048; 286060d2ed9Sahoka chmp->chm_fs_qfmask = 2047; 287060d2ed9Sahoka 288aa98cbbaSttoth /* Initialize writebuffer. */ 289060d2ed9Sahoka chmp->chm_wbuf_pagesize = chmp->chm_ebh->flash_if->page_size; 290060d2ed9Sahoka dbg("wbuf size: %zu\n", chmp->chm_wbuf_pagesize); 291060d2ed9Sahoka chmp->chm_wbuf = kmem_alloc(chmp->chm_wbuf_pagesize, KM_SLEEP); 292060d2ed9Sahoka rw_init(&chmp->chm_lock_wbuf); 293060d2ed9Sahoka 294aa98cbbaSttoth /* Initialize queues. */ 295060d2ed9Sahoka TAILQ_INIT(&chmp->chm_free_queue); 296060d2ed9Sahoka TAILQ_INIT(&chmp->chm_clean_queue); 297060d2ed9Sahoka TAILQ_INIT(&chmp->chm_dirty_queue); 298060d2ed9Sahoka TAILQ_INIT(&chmp->chm_very_dirty_queue); 299060d2ed9Sahoka TAILQ_INIT(&chmp->chm_erasable_pending_wbuf_queue); 300060d2ed9Sahoka TAILQ_INIT(&chmp->chm_erase_pending_queue); 301060d2ed9Sahoka 302aa98cbbaSttoth /* Initialize flash-specific constants. */ 303060d2ed9Sahoka chfs_calc_trigger_levels(chmp); 304060d2ed9Sahoka 305aa98cbbaSttoth /* Initialize sizes. */ 306060d2ed9Sahoka chmp->chm_nr_free_blocks = 0; 307060d2ed9Sahoka chmp->chm_nr_erasable_blocks = 0; 308060d2ed9Sahoka chmp->chm_max_vno = 2; 309060d2ed9Sahoka chmp->chm_checked_vno = 2; 310060d2ed9Sahoka chmp->chm_unchecked_size = 0; 311060d2ed9Sahoka chmp->chm_used_size = 0; 312060d2ed9Sahoka chmp->chm_dirty_size = 0; 313060d2ed9Sahoka chmp->chm_wasted_size = 0; 314060d2ed9Sahoka chmp->chm_free_size = chmp->chm_ebh->eb_size * chmp->chm_ebh->peb_nr; 315aa98cbbaSttoth 316aa98cbbaSttoth /* Build filesystem. */ 317060d2ed9Sahoka err = chfs_build_filesystem(chmp); 318060d2ed9Sahoka 319060d2ed9Sahoka if (err) { 320aa98cbbaSttoth /* Armageddon and return. */ 321a6388638Srmind err = EIO; 322*6a9242deSriastradh goto fail2; 323060d2ed9Sahoka } 324060d2ed9Sahoka 325aa98cbbaSttoth /* Initialize UFS. */ 326060d2ed9Sahoka mp->mnt_data = ump; 327060d2ed9Sahoka mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev; 328060d2ed9Sahoka mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_CHFS); 329060d2ed9Sahoka mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0]; 330060d2ed9Sahoka mp->mnt_stat.f_namemax = MAXNAMLEN; 331060d2ed9Sahoka mp->mnt_flag |= MNT_LOCAL; 332060d2ed9Sahoka mp->mnt_fs_bshift = PAGE_SHIFT; 333060d2ed9Sahoka mp->mnt_dev_bshift = DEV_BSHIFT; 334060d2ed9Sahoka mp->mnt_iflag |= IMNT_MPSAFE; 335060d2ed9Sahoka ump->um_flags = 0; 336060d2ed9Sahoka ump->um_mountp = mp; 337060d2ed9Sahoka ump->um_dev = dev; 338060d2ed9Sahoka ump->um_devvp = devvp; 339060d2ed9Sahoka ump->um_maxfilesize = 1048512 * 1024; 340060d2ed9Sahoka 341aa98cbbaSttoth /* Allocate the root vnode. */ 342060d2ed9Sahoka err = VFS_VGET(mp, CHFS_ROOTINO, &vp); 343060d2ed9Sahoka if (err) { 344060d2ed9Sahoka dbg("error: %d while allocating root node\n", err); 345060d2ed9Sahoka return err; 346060d2ed9Sahoka } 347060d2ed9Sahoka vput(vp); 348060d2ed9Sahoka 349aa98cbbaSttoth /* Start GC. */ 350060d2ed9Sahoka chfs_gc_thread_start(chmp); 351060d2ed9Sahoka mutex_enter(&chmp->chm_lock_mountfields); 352060d2ed9Sahoka chfs_gc_trigger(chmp); 353060d2ed9Sahoka mutex_exit(&chmp->chm_lock_mountfields); 354060d2ed9Sahoka 355ce2a78d3Shannken spec_node_setmountedfs(devvp, mp); 356060d2ed9Sahoka return 0; 357aa98cbbaSttoth 358*6a9242deSriastradh fail2: 359*6a9242deSriastradh KASSERT(TAILQ_EMPTY(&chmp->chm_erase_pending_queue)); 360*6a9242deSriastradh KASSERT(TAILQ_EMPTY(&chmp->chm_erasable_pending_wbuf_queue)); 361*6a9242deSriastradh KASSERT(TAILQ_EMPTY(&chmp->chm_very_dirty_queue)); 362*6a9242deSriastradh KASSERT(TAILQ_EMPTY(&chmp->chm_dirty_queue)); 363*6a9242deSriastradh KASSERT(TAILQ_EMPTY(&chmp->chm_clean_queue)); 364*6a9242deSriastradh KASSERT(TAILQ_EMPTY(&chmp->chm_free_queue)); 365*6a9242deSriastradh rw_destroy(&chmp->chm_lock_wbuf); 366*6a9242deSriastradh kmem_free(chmp->chm_wbuf, chmp->chm_wbuf_pagesize); 367*6a9242deSriastradh mutex_destroy(&chmp->chm_lock_vnocache); 368*6a9242deSriastradh mutex_destroy(&chmp->chm_lock_sizes); 369*6a9242deSriastradh mutex_destroy(&chmp->chm_lock_mountfields); 370*6a9242deSriastradh kmem_free(chmp->chm_blocks, chmp->chm_ebh->peb_nr * 371*6a9242deSriastradh sizeof(struct chfs_eraseblock)); 372*6a9242deSriastradh chfs_vnocache_hash_destroy(chmp->chm_vnocache_hash); 373*6a9242deSriastradh ebh_close(chmp->chm_ebh); 374*6a9242deSriastradh 375*6a9242deSriastradh fail1: 376a6388638Srmind kmem_free(chmp->chm_ebh, sizeof(struct chfs_ebh)); 377*6a9242deSriastradh mutex_destroy(&ump->um_lock); 378a6388638Srmind kmem_free(chmp, sizeof(struct chfs_mount)); 379a6388638Srmind kmem_free(ump, sizeof(struct ufsmount)); 380*6a9242deSriastradh 381*6a9242deSriastradh fail0: 382*6a9242deSriastradh KASSERT(err); 383a6388638Srmind return err; 384060d2ed9Sahoka } 385060d2ed9Sahoka 386060d2ed9Sahoka /* --------------------------------------------------------------------- */ 387060d2ed9Sahoka 388060d2ed9Sahoka static int 389060d2ed9Sahoka chfs_unmount(struct mount *mp, int mntflags) 390060d2ed9Sahoka { 391060d2ed9Sahoka int flags = 0, i = 0; 392060d2ed9Sahoka struct ufsmount *ump; 393060d2ed9Sahoka struct chfs_mount *chmp; 394060d2ed9Sahoka 395060d2ed9Sahoka if (mntflags & MNT_FORCE) 396060d2ed9Sahoka flags |= FORCECLOSE; 397060d2ed9Sahoka 398060d2ed9Sahoka dbg("[START]\n"); 399060d2ed9Sahoka 400060d2ed9Sahoka ump = VFSTOUFS(mp); 401060d2ed9Sahoka chmp = ump->um_chfs; 402060d2ed9Sahoka 403aa98cbbaSttoth /* Stop GC. */ 404060d2ed9Sahoka chfs_gc_thread_stop(chmp); 405060d2ed9Sahoka 406aa98cbbaSttoth /* Flush everyt buffer. */ 407060d2ed9Sahoka (void)vflush(mp, NULLVP, flags); 408060d2ed9Sahoka 409060d2ed9Sahoka if (chmp->chm_wbuf_len) { 410060d2ed9Sahoka mutex_enter(&chmp->chm_lock_mountfields); 411060d2ed9Sahoka chfs_flush_pending_wbuf(chmp); 412060d2ed9Sahoka mutex_exit(&chmp->chm_lock_mountfields); 413060d2ed9Sahoka } 414060d2ed9Sahoka 415aa98cbbaSttoth /* Free node references. */ 416060d2ed9Sahoka for (i = 0; i < chmp->chm_ebh->peb_nr; i++) { 417060d2ed9Sahoka chfs_free_node_refs(&chmp->chm_blocks[i]); 418060d2ed9Sahoka } 419060d2ed9Sahoka 420aa98cbbaSttoth /* Destroy vnode cache hashtable. */ 421060d2ed9Sahoka chfs_vnocache_hash_destroy(chmp->chm_vnocache_hash); 422060d2ed9Sahoka 423aa98cbbaSttoth /* Close eraseblock handler. */ 424060d2ed9Sahoka ebh_close(chmp->chm_ebh); 425060d2ed9Sahoka 426aa98cbbaSttoth /* Destroy mutexes. */ 427060d2ed9Sahoka rw_destroy(&chmp->chm_lock_wbuf); 428060d2ed9Sahoka mutex_destroy(&chmp->chm_lock_vnocache); 429060d2ed9Sahoka mutex_destroy(&chmp->chm_lock_sizes); 430060d2ed9Sahoka mutex_destroy(&chmp->chm_lock_mountfields); 431060d2ed9Sahoka 432aa98cbbaSttoth /* Unmount UFS. */ 433060d2ed9Sahoka if (ump->um_devvp->v_type != VBAD) { 434ce2a78d3Shannken spec_node_setmountedfs(ump->um_devvp, NULL); 435060d2ed9Sahoka } 436060d2ed9Sahoka vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY); 437060d2ed9Sahoka (void)VOP_CLOSE(ump->um_devvp, FREAD|FWRITE, NOCRED); 438060d2ed9Sahoka vput(ump->um_devvp); 439060d2ed9Sahoka 440060d2ed9Sahoka mutex_destroy(&ump->um_lock); 441060d2ed9Sahoka 442aa98cbbaSttoth /* Everything done. */ 443a6388638Srmind kmem_free(ump, sizeof(struct ufsmount)); 444060d2ed9Sahoka mp->mnt_data = NULL; 445060d2ed9Sahoka mp->mnt_flag &= ~MNT_LOCAL; 446060d2ed9Sahoka dbg("[END]\n"); 447060d2ed9Sahoka return (0); 448060d2ed9Sahoka } 449060d2ed9Sahoka 450060d2ed9Sahoka /* --------------------------------------------------------------------- */ 451060d2ed9Sahoka 452060d2ed9Sahoka static int 453060d2ed9Sahoka chfs_root(struct mount *mp, struct vnode **vpp) 454060d2ed9Sahoka { 455060d2ed9Sahoka struct vnode *vp; 456060d2ed9Sahoka int error; 457060d2ed9Sahoka 458d8eae7d2Sdholland if ((error = VFS_VGET(mp, (ino_t)UFS_ROOTINO, &vp)) != 0) 459060d2ed9Sahoka return error; 460060d2ed9Sahoka *vpp = vp; 461060d2ed9Sahoka return 0; 462060d2ed9Sahoka } 463060d2ed9Sahoka 464060d2ed9Sahoka /* --------------------------------------------------------------------- */ 465060d2ed9Sahoka 466060d2ed9Sahoka extern rb_tree_ops_t frag_rbtree_ops; 467060d2ed9Sahoka 468060d2ed9Sahoka static int 46966996266Shannken chfs_loadvnode(struct mount *mp, struct vnode *vp, 47066996266Shannken const void *key, size_t key_len, const void **new_key) 471060d2ed9Sahoka { 472060d2ed9Sahoka struct chfs_mount *chmp; 473060d2ed9Sahoka struct chfs_inode *ip; 474060d2ed9Sahoka struct ufsmount *ump; 475060d2ed9Sahoka dev_t dev; 476060d2ed9Sahoka int error; 477060d2ed9Sahoka struct chfs_vnode_cache* chvc = NULL; 478060d2ed9Sahoka struct chfs_node_ref* nref = NULL; 479060d2ed9Sahoka struct buf *bp; 48066996266Shannken ino_t ino; 48166996266Shannken 48266996266Shannken KASSERT(key_len == sizeof(ino)); 48366996266Shannken memcpy(&ino, key, key_len); 484060d2ed9Sahoka 48591acea70Sagc dbg("vget() | ino: %llu\n", (unsigned long long)ino); 486060d2ed9Sahoka 487060d2ed9Sahoka ump = VFSTOUFS(mp); 488060d2ed9Sahoka dev = ump->um_dev; 489060d2ed9Sahoka 490060d2ed9Sahoka ip = pool_get(&chfs_inode_pool, PR_WAITOK); 491060d2ed9Sahoka 492aa98cbbaSttoth /* Initialize vnode/inode. */ 493060d2ed9Sahoka memset(ip, 0, sizeof(*ip)); 494060d2ed9Sahoka ip->vp = vp; 495060d2ed9Sahoka ip->ump = ump; 496060d2ed9Sahoka ip->chmp = chmp = ump->um_chfs; 497060d2ed9Sahoka ip->dev = dev; 498060d2ed9Sahoka ip->ino = ino; 499060d2ed9Sahoka 500060d2ed9Sahoka rb_tree_init(&ip->fragtree, &frag_rbtree_ops); 501060d2ed9Sahoka 50266996266Shannken vp->v_tag = VT_CHFS; 50366996266Shannken vp->v_op = chfs_vnodeop_p; 50466996266Shannken vp->v_vflag |= VV_LOCKSWORK; 50566996266Shannken if (ino == CHFS_ROOTINO) 50666996266Shannken vp->v_vflag |= VV_ROOT; 50766996266Shannken vp->v_data = ip; 508060d2ed9Sahoka 509aa98cbbaSttoth /* Set root inode. */ 510060d2ed9Sahoka if (ino == CHFS_ROOTINO) { 511060d2ed9Sahoka dbg("SETROOT\n"); 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. */ 55366996266Shannken error = 0; 554e6a23d44Sttoth switch (ip->ch_type) { 555e6a23d44Sttoth case CHT_DIR: 556aa98cbbaSttoth /* Read every dirent. */ 557060d2ed9Sahoka nref = chvc->dirents; 558060d2ed9Sahoka while (nref && 559060d2ed9Sahoka (struct chfs_vnode_cache *)nref != chvc) { 560060d2ed9Sahoka chfs_readdirent(mp, nref, ip); 561060d2ed9Sahoka nref = nref->nref_next; 562060d2ed9Sahoka } 563060d2ed9Sahoka chfs_set_vnode_size(vp, 512); 564060d2ed9Sahoka break; 565e6a23d44Sttoth case CHT_REG: 566aa98cbbaSttoth /* FALLTHROUGH */ 567e6a23d44Sttoth case CHT_SOCK: 568aa98cbbaSttoth /* Collect data. */ 56991acea70Sagc dbg("read_inode_internal | ino: %llu\n", 57091acea70Sagc (unsigned long long)ip->ino); 571060d2ed9Sahoka error = chfs_read_inode(chmp, ip); 572060d2ed9Sahoka break; 573e6a23d44Sttoth case CHT_LNK: 574aa98cbbaSttoth /* Collect data. */ 57591acea70Sagc dbg("read_inode_internal | ino: %llu\n", 57691acea70Sagc (unsigned long long)ip->ino); 577060d2ed9Sahoka error = chfs_read_inode_internal(chmp, ip); 57866996266Shannken if (error) 57966996266Shannken break; 580060d2ed9Sahoka 581aa98cbbaSttoth /* Set link. */ 58291acea70Sagc dbg("size: %llu\n", (unsigned long long)ip->size); 583060d2ed9Sahoka bp = getiobuf(vp, true); 584060d2ed9Sahoka bp->b_blkno = 0; 585060d2ed9Sahoka bp->b_bufsize = bp->b_resid = 586060d2ed9Sahoka bp->b_bcount = ip->size; 587060d2ed9Sahoka bp->b_data = kmem_alloc(ip->size, KM_SLEEP); 588060d2ed9Sahoka chfs_read_data(chmp, vp, bp); 589060d2ed9Sahoka if (!ip->target) 590060d2ed9Sahoka ip->target = kmem_alloc(ip->size, 591060d2ed9Sahoka KM_SLEEP); 592060d2ed9Sahoka memcpy(ip->target, bp->b_data, ip->size); 593060d2ed9Sahoka kmem_free(bp->b_data, ip->size); 594060d2ed9Sahoka putiobuf(bp); 595060d2ed9Sahoka 596060d2ed9Sahoka break; 597e6a23d44Sttoth case CHT_CHR: 598aa98cbbaSttoth /* FALLTHROUGH */ 599e6a23d44Sttoth case CHT_BLK: 600aa98cbbaSttoth /* FALLTHROUGH */ 601e6a23d44Sttoth case CHT_FIFO: 602aa98cbbaSttoth /* Collect data. */ 60391acea70Sagc dbg("read_inode_internal | ino: %llu\n", 60491acea70Sagc (unsigned long long)ip->ino); 605060d2ed9Sahoka error = chfs_read_inode_internal(chmp, ip); 60666996266Shannken if (error) 60766996266Shannken break; 608060d2ed9Sahoka 609aa98cbbaSttoth /* Set device. */ 610060d2ed9Sahoka bp = getiobuf(vp, true); 611060d2ed9Sahoka bp->b_blkno = 0; 612060d2ed9Sahoka bp->b_bufsize = bp->b_resid = 613060d2ed9Sahoka bp->b_bcount = sizeof(dev_t); 614060d2ed9Sahoka bp->b_data = kmem_alloc(sizeof(dev_t), KM_SLEEP); 615060d2ed9Sahoka chfs_read_data(chmp, vp, bp); 616060d2ed9Sahoka memcpy(&ip->rdev, 617060d2ed9Sahoka bp->b_data, sizeof(dev_t)); 618060d2ed9Sahoka kmem_free(bp->b_data, sizeof(dev_t)); 619060d2ed9Sahoka putiobuf(bp); 620aa98cbbaSttoth /* Set specific operations. */ 621e6a23d44Sttoth if (ip->ch_type == CHT_FIFO) { 622060d2ed9Sahoka vp->v_op = chfs_fifoop_p; 623e6a23d44Sttoth } else { 624060d2ed9Sahoka vp->v_op = chfs_specop_p; 625060d2ed9Sahoka spec_node_init(vp, ip->rdev); 626060d2ed9Sahoka } 627060d2ed9Sahoka 628060d2ed9Sahoka break; 629e6a23d44Sttoth case CHT_BLANK: 630aa98cbbaSttoth /* FALLTHROUGH */ 631e6a23d44Sttoth case CHT_BAD: 632060d2ed9Sahoka break; 633060d2ed9Sahoka } 634060d2ed9Sahoka mutex_exit(&chmp->chm_lock_mountfields); 63566996266Shannken if (error) { 63666996266Shannken vp->v_data = NULL; 63766996266Shannken KASSERT(TAILQ_FIRST(&ip->dents) == NULL); 63866996266Shannken pool_put(&chfs_inode_pool, ip); 63966996266Shannken return error; 64066996266Shannken } 641060d2ed9Sahoka 642060d2ed9Sahoka } 643060d2ed9Sahoka 644aa98cbbaSttoth /* Finish inode initalization. */ 64566996266Shannken ip->ch_type = VTTOCHT(vp->v_type); 646060d2ed9Sahoka ip->devvp = ump->um_devvp; 647060d2ed9Sahoka vref(ip->devvp); 648060d2ed9Sahoka 64966996266Shannken genfs_node_init(vp, &chfs_genfsops); 650060d2ed9Sahoka uvm_vnp_setsize(vp, ip->size); 65166996266Shannken 65266996266Shannken *new_key = &ip->ino; 653060d2ed9Sahoka 654060d2ed9Sahoka return 0; 655060d2ed9Sahoka } 656060d2ed9Sahoka 657060d2ed9Sahoka /* --------------------------------------------------------------------- */ 658060d2ed9Sahoka 659060d2ed9Sahoka static int 66066996266Shannken chfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp) 66166996266Shannken { 66266996266Shannken int error; 66366996266Shannken 66466996266Shannken error = vcache_get(mp, &ino, sizeof(ino), vpp); 66566996266Shannken if (error) 66666996266Shannken return error; 66766996266Shannken 66866996266Shannken error = vn_lock(*vpp, LK_EXCLUSIVE); 66966996266Shannken if (error) { 67066996266Shannken vrele(*vpp); 67166996266Shannken *vpp = NULL; 67266996266Shannken return error; 67366996266Shannken } 67466996266Shannken 67566996266Shannken return 0; 67666996266Shannken } 67766996266Shannken 67866996266Shannken /* --------------------------------------------------------------------- */ 67966996266Shannken 68066996266Shannken 68166996266Shannken static int 682060d2ed9Sahoka chfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp) 683060d2ed9Sahoka { 684060d2ed9Sahoka return ENODEV; 685060d2ed9Sahoka } 686060d2ed9Sahoka 687060d2ed9Sahoka /* --------------------------------------------------------------------- */ 688060d2ed9Sahoka 689060d2ed9Sahoka static int 690060d2ed9Sahoka chfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size) 691060d2ed9Sahoka { 692060d2ed9Sahoka return ENODEV; 693060d2ed9Sahoka } 694060d2ed9Sahoka 695060d2ed9Sahoka /* --------------------------------------------------------------------- */ 696060d2ed9Sahoka 697060d2ed9Sahoka static int 698060d2ed9Sahoka chfs_start(struct mount *mp, int flags) 699060d2ed9Sahoka { 700060d2ed9Sahoka return 0; 701060d2ed9Sahoka } 702060d2ed9Sahoka 703060d2ed9Sahoka /* --------------------------------------------------------------------- */ 704060d2ed9Sahoka 705060d2ed9Sahoka static int 706060d2ed9Sahoka chfs_statvfs(struct mount *mp, struct statvfs *sbp) 707060d2ed9Sahoka { 708060d2ed9Sahoka struct chfs_mount *chmp; 709060d2ed9Sahoka struct ufsmount *ump; 710060d2ed9Sahoka dbg("statvfs\n"); 711060d2ed9Sahoka 712060d2ed9Sahoka ump = VFSTOUFS(mp); 713060d2ed9Sahoka chmp = ump->um_chfs; 714060d2ed9Sahoka 715060d2ed9Sahoka sbp->f_flag = mp->mnt_flag; 716060d2ed9Sahoka sbp->f_bsize = chmp->chm_ebh->eb_size; 717060d2ed9Sahoka sbp->f_frsize = chmp->chm_ebh->eb_size; 718060d2ed9Sahoka sbp->f_iosize = chmp->chm_ebh->eb_size; 719060d2ed9Sahoka 720060d2ed9Sahoka sbp->f_blocks = chmp->chm_ebh->peb_nr; 721060d2ed9Sahoka sbp->f_files = 0; 722060d2ed9Sahoka sbp->f_bavail = chmp->chm_nr_free_blocks - chmp->chm_resv_blocks_write; 723060d2ed9Sahoka 724060d2ed9Sahoka sbp->f_bfree = chmp->chm_nr_free_blocks; 725060d2ed9Sahoka sbp->f_bresvd = chmp->chm_resv_blocks_write; 726060d2ed9Sahoka 727060d2ed9Sahoka /* FFS specific */ 728060d2ed9Sahoka sbp->f_ffree = 0; 729060d2ed9Sahoka sbp->f_favail = 0; 730060d2ed9Sahoka sbp->f_fresvd = 0; 731060d2ed9Sahoka 732060d2ed9Sahoka copy_statvfs_info(sbp, mp); 733060d2ed9Sahoka 734060d2ed9Sahoka return 0; 735060d2ed9Sahoka } 736060d2ed9Sahoka 737060d2ed9Sahoka /* --------------------------------------------------------------------- */ 738060d2ed9Sahoka 739060d2ed9Sahoka static int 740060d2ed9Sahoka chfs_sync(struct mount *mp, int waitfor, 741060d2ed9Sahoka kauth_cred_t uc) 742060d2ed9Sahoka { 743060d2ed9Sahoka return 0; 744060d2ed9Sahoka } 745060d2ed9Sahoka 746060d2ed9Sahoka /* --------------------------------------------------------------------- */ 747060d2ed9Sahoka 748060d2ed9Sahoka static void 749060d2ed9Sahoka chfs_init(void) 750060d2ed9Sahoka { 751aa98cbbaSttoth /* Initialize pools and inode hash. */ 752060d2ed9Sahoka chfs_alloc_pool_caches(); 753060d2ed9Sahoka pool_init(&chfs_inode_pool, sizeof(struct chfs_inode), 0, 0, 0, 754060d2ed9Sahoka "chfsinopl", &pool_allocator_nointr, IPL_NONE); 755060d2ed9Sahoka ufs_init(); 756060d2ed9Sahoka } 757060d2ed9Sahoka 758060d2ed9Sahoka /* --------------------------------------------------------------------- */ 759060d2ed9Sahoka 760060d2ed9Sahoka static void 761060d2ed9Sahoka chfs_reinit(void) 762060d2ed9Sahoka { 763060d2ed9Sahoka ufs_reinit(); 764060d2ed9Sahoka } 765060d2ed9Sahoka 766060d2ed9Sahoka /* --------------------------------------------------------------------- */ 767060d2ed9Sahoka 768060d2ed9Sahoka static void 769060d2ed9Sahoka chfs_done(void) 770060d2ed9Sahoka { 771060d2ed9Sahoka ufs_done(); 772060d2ed9Sahoka pool_destroy(&chfs_inode_pool); 773060d2ed9Sahoka chfs_destroy_pool_caches(); 774060d2ed9Sahoka } 775060d2ed9Sahoka 776060d2ed9Sahoka /* --------------------------------------------------------------------- */ 777060d2ed9Sahoka 778060d2ed9Sahoka static int 779060d2ed9Sahoka chfs_snapshot(struct mount *mp, struct vnode *vp, 780060d2ed9Sahoka struct timespec *ctime) 781060d2ed9Sahoka { 782060d2ed9Sahoka return ENODEV; 783060d2ed9Sahoka } 784060d2ed9Sahoka 785060d2ed9Sahoka /* --------------------------------------------------------------------- */ 786060d2ed9Sahoka 787060d2ed9Sahoka /* 788060d2ed9Sahoka * chfs vfs operations. 789060d2ed9Sahoka */ 790060d2ed9Sahoka 791060d2ed9Sahoka extern const struct vnodeopv_desc chfs_fifoop_opv_desc; 792060d2ed9Sahoka extern const struct vnodeopv_desc chfs_specop_opv_desc; 793060d2ed9Sahoka extern const struct vnodeopv_desc chfs_vnodeop_opv_desc; 794060d2ed9Sahoka 795060d2ed9Sahoka const struct vnodeopv_desc * const chfs_vnodeopv_descs[] = { 796060d2ed9Sahoka &chfs_fifoop_opv_desc, 797060d2ed9Sahoka &chfs_specop_opv_desc, 798060d2ed9Sahoka &chfs_vnodeop_opv_desc, 799060d2ed9Sahoka NULL, 800060d2ed9Sahoka }; 801060d2ed9Sahoka 802060d2ed9Sahoka struct vfsops chfs_vfsops = { 80397116d3bShannken .vfs_name = MOUNT_CHFS, 80497116d3bShannken .vfs_min_mount_data = sizeof (struct chfs_args), 80597116d3bShannken .vfs_mount = chfs_mount, 80697116d3bShannken .vfs_start = chfs_start, 80797116d3bShannken .vfs_unmount = chfs_unmount, 80897116d3bShannken .vfs_root = chfs_root, 80997116d3bShannken .vfs_quotactl = ufs_quotactl, 81097116d3bShannken .vfs_statvfs = chfs_statvfs, 81197116d3bShannken .vfs_sync = chfs_sync, 81297116d3bShannken .vfs_vget = chfs_vget, 81366996266Shannken .vfs_loadvnode = chfs_loadvnode, 81497116d3bShannken .vfs_fhtovp = chfs_fhtovp, 81597116d3bShannken .vfs_vptofh = chfs_vptofh, 81697116d3bShannken .vfs_init = chfs_init, 81797116d3bShannken .vfs_reinit = chfs_reinit, 81897116d3bShannken .vfs_done = chfs_done, 81997116d3bShannken .vfs_snapshot = chfs_snapshot, 82097116d3bShannken .vfs_extattrctl = vfs_stdextattrctl, 821c0f141edShannken .vfs_suspendctl = genfs_suspendctl, 82297116d3bShannken .vfs_renamelock_enter = genfs_renamelock_enter, 82397116d3bShannken .vfs_renamelock_exit = genfs_renamelock_exit, 82497116d3bShannken .vfs_fsync = (void *)eopnotsupp, 82597116d3bShannken .vfs_opv_descs = chfs_vnodeopv_descs 826060d2ed9Sahoka }; 827060d2ed9Sahoka 828aa98cbbaSttoth /* For using CHFS as a module. */ 829060d2ed9Sahoka static int 830060d2ed9Sahoka chfs_modcmd(modcmd_t cmd, void *arg) 831060d2ed9Sahoka { 832060d2ed9Sahoka switch (cmd) { 833060d2ed9Sahoka case MODULE_CMD_INIT: 834060d2ed9Sahoka return vfs_attach(&chfs_vfsops); 835060d2ed9Sahoka case MODULE_CMD_FINI: 836060d2ed9Sahoka return vfs_detach(&chfs_vfsops); 837060d2ed9Sahoka default: 838060d2ed9Sahoka return ENOTTY; 839060d2ed9Sahoka } 840060d2ed9Sahoka } 841