1789Sahrens /* 2789Sahrens * CDDL HEADER START 3789Sahrens * 4789Sahrens * The contents of this file are subject to the terms of the 51484Sek110237 * Common Development and Distribution License (the "License"). 61484Sek110237 * You may not use this file except in compliance with the License. 7789Sahrens * 8789Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9789Sahrens * or http://www.opensolaris.org/os/licensing. 10789Sahrens * See the License for the specific language governing permissions 11789Sahrens * and limitations under the License. 12789Sahrens * 13789Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14789Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15789Sahrens * If applicable, add the following below this CDDL HEADER, with the 16789Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17789Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18789Sahrens * 19789Sahrens * CDDL HEADER END 20789Sahrens */ 21789Sahrens /* 229030SMark.Shellenbaum@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23789Sahrens * Use is subject to license terms. 24789Sahrens */ 25789Sahrens 26789Sahrens #include <sys/types.h> 27789Sahrens #include <sys/param.h> 28789Sahrens #include <sys/systm.h> 29789Sahrens #include <sys/sysmacros.h> 30789Sahrens #include <sys/kmem.h> 31789Sahrens #include <sys/pathname.h> 32789Sahrens #include <sys/vnode.h> 33789Sahrens #include <sys/vfs.h> 343898Srsb #include <sys/vfs_opreg.h> 35789Sahrens #include <sys/mntent.h> 36789Sahrens #include <sys/mount.h> 37789Sahrens #include <sys/cmn_err.h> 38789Sahrens #include "fs/fs_subr.h" 39789Sahrens #include <sys/zfs_znode.h> 403461Sahrens #include <sys/zfs_dir.h> 41789Sahrens #include <sys/zil.h> 42789Sahrens #include <sys/fs/zfs.h> 43789Sahrens #include <sys/dmu.h> 44789Sahrens #include <sys/dsl_prop.h> 453912Slling #include <sys/dsl_dataset.h> 464543Smarks #include <sys/dsl_deleg.h> 47789Sahrens #include <sys/spa.h> 48789Sahrens #include <sys/zap.h> 49789Sahrens #include <sys/varargs.h> 50789Sahrens #include <sys/policy.h> 51789Sahrens #include <sys/atomic.h> 52789Sahrens #include <sys/mkdev.h> 53789Sahrens #include <sys/modctl.h> 544543Smarks #include <sys/refstr.h> 55789Sahrens #include <sys/zfs_ioctl.h> 56789Sahrens #include <sys/zfs_ctldir.h> 575331Samw #include <sys/zfs_fuid.h> 581544Seschrock #include <sys/bootconf.h> 59849Sbonwick #include <sys/sunddi.h> 601484Sek110237 #include <sys/dnlc.h> 615326Sek110237 #include <sys/dmu_objset.h> 626423Sgw25295 #include <sys/spa_boot.h> 63789Sahrens 64789Sahrens int zfsfstype; 65789Sahrens vfsops_t *zfs_vfsops = NULL; 66849Sbonwick static major_t zfs_major; 67789Sahrens static minor_t zfs_minor; 68789Sahrens static kmutex_t zfs_dev_mtx; 69789Sahrens 709234SGeorge.Wilson@Sun.COM extern int sys_shutdown; 719234SGeorge.Wilson@Sun.COM 72789Sahrens static int zfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr); 73789Sahrens static int zfs_umount(vfs_t *vfsp, int fflag, cred_t *cr); 741544Seschrock static int zfs_mountroot(vfs_t *vfsp, enum whymountroot); 75789Sahrens static int zfs_root(vfs_t *vfsp, vnode_t **vpp); 76789Sahrens static int zfs_statvfs(vfs_t *vfsp, struct statvfs64 *statp); 77789Sahrens static int zfs_vget(vfs_t *vfsp, vnode_t **vpp, fid_t *fidp); 78789Sahrens static void zfs_freevfs(vfs_t *vfsp); 79789Sahrens 80789Sahrens static const fs_operation_def_t zfs_vfsops_template[] = { 813898Srsb VFSNAME_MOUNT, { .vfs_mount = zfs_mount }, 823898Srsb VFSNAME_MOUNTROOT, { .vfs_mountroot = zfs_mountroot }, 833898Srsb VFSNAME_UNMOUNT, { .vfs_unmount = zfs_umount }, 843898Srsb VFSNAME_ROOT, { .vfs_root = zfs_root }, 853898Srsb VFSNAME_STATVFS, { .vfs_statvfs = zfs_statvfs }, 863898Srsb VFSNAME_SYNC, { .vfs_sync = zfs_sync }, 873898Srsb VFSNAME_VGET, { .vfs_vget = zfs_vget }, 883898Srsb VFSNAME_FREEVFS, { .vfs_freevfs = zfs_freevfs }, 893898Srsb NULL, NULL 90789Sahrens }; 91789Sahrens 92789Sahrens static const fs_operation_def_t zfs_vfsops_eio_template[] = { 933898Srsb VFSNAME_FREEVFS, { .vfs_freevfs = zfs_freevfs }, 943898Srsb NULL, NULL 95789Sahrens }; 96789Sahrens 97789Sahrens /* 98789Sahrens * We need to keep a count of active fs's. 99789Sahrens * This is necessary to prevent our module 100789Sahrens * from being unloaded after a umount -f 101789Sahrens */ 102789Sahrens static uint32_t zfs_active_fs_count = 0; 103789Sahrens 104789Sahrens static char *noatime_cancel[] = { MNTOPT_ATIME, NULL }; 105789Sahrens static char *atime_cancel[] = { MNTOPT_NOATIME, NULL }; 1063234Sck153898 static char *noxattr_cancel[] = { MNTOPT_XATTR, NULL }; 1073234Sck153898 static char *xattr_cancel[] = { MNTOPT_NOXATTR, NULL }; 108789Sahrens 1093234Sck153898 /* 1104596Slling * MO_DEFAULT is not used since the default value is determined 1114596Slling * by the equivalent property. 1123234Sck153898 */ 113789Sahrens static mntopt_t mntopts[] = { 1143234Sck153898 { MNTOPT_NOXATTR, noxattr_cancel, NULL, 0, NULL }, 1153234Sck153898 { MNTOPT_XATTR, xattr_cancel, NULL, 0, NULL }, 1164596Slling { MNTOPT_NOATIME, noatime_cancel, NULL, 0, NULL }, 117789Sahrens { MNTOPT_ATIME, atime_cancel, NULL, 0, NULL } 118789Sahrens }; 119789Sahrens 120789Sahrens static mntopts_t zfs_mntopts = { 121789Sahrens sizeof (mntopts) / sizeof (mntopt_t), 122789Sahrens mntopts 123789Sahrens }; 124789Sahrens 125789Sahrens /*ARGSUSED*/ 126789Sahrens int 127789Sahrens zfs_sync(vfs_t *vfsp, short flag, cred_t *cr) 128789Sahrens { 129789Sahrens /* 130789Sahrens * Data integrity is job one. We don't want a compromised kernel 131789Sahrens * writing to the storage pool, so we never sync during panic. 132789Sahrens */ 133789Sahrens if (panicstr) 134789Sahrens return (0); 135789Sahrens 136789Sahrens /* 137789Sahrens * SYNC_ATTR is used by fsflush() to force old filesystems like UFS 138789Sahrens * to sync metadata, which they would otherwise cache indefinitely. 139789Sahrens * Semantically, the only requirement is that the sync be initiated. 140789Sahrens * The DMU syncs out txgs frequently, so there's nothing to do. 141789Sahrens */ 142789Sahrens if (flag & SYNC_ATTR) 143789Sahrens return (0); 144789Sahrens 145789Sahrens if (vfsp != NULL) { 146789Sahrens /* 147789Sahrens * Sync a specific filesystem. 148789Sahrens */ 149789Sahrens zfsvfs_t *zfsvfs = vfsp->vfs_data; 1509234SGeorge.Wilson@Sun.COM dsl_pool_t *dp; 151789Sahrens 152789Sahrens ZFS_ENTER(zfsvfs); 1539234SGeorge.Wilson@Sun.COM dp = dmu_objset_pool(zfsvfs->z_os); 1549234SGeorge.Wilson@Sun.COM 1559234SGeorge.Wilson@Sun.COM /* 1569234SGeorge.Wilson@Sun.COM * If the system is shutting down, then skip any 1579234SGeorge.Wilson@Sun.COM * filesystems which may exist on a suspended pool. 1589234SGeorge.Wilson@Sun.COM */ 1599234SGeorge.Wilson@Sun.COM if (sys_shutdown && spa_suspended(dp->dp_spa)) { 1609234SGeorge.Wilson@Sun.COM ZFS_EXIT(zfsvfs); 1619234SGeorge.Wilson@Sun.COM return (0); 1629234SGeorge.Wilson@Sun.COM } 1639234SGeorge.Wilson@Sun.COM 164789Sahrens if (zfsvfs->z_log != NULL) 1652638Sperrin zil_commit(zfsvfs->z_log, UINT64_MAX, 0); 166789Sahrens else 1679234SGeorge.Wilson@Sun.COM txg_wait_synced(dp, 0); 168789Sahrens ZFS_EXIT(zfsvfs); 169789Sahrens } else { 170789Sahrens /* 171789Sahrens * Sync all ZFS filesystems. This is what happens when you 172789Sahrens * run sync(1M). Unlike other filesystems, ZFS honors the 173789Sahrens * request by waiting for all pools to commit all dirty data. 174789Sahrens */ 175789Sahrens spa_sync_allpools(); 176789Sahrens } 177789Sahrens 178789Sahrens return (0); 179789Sahrens } 180789Sahrens 1811544Seschrock static int 1821544Seschrock zfs_create_unique_device(dev_t *dev) 1831544Seschrock { 1841544Seschrock major_t new_major; 1851544Seschrock 1861544Seschrock do { 1871544Seschrock ASSERT3U(zfs_minor, <=, MAXMIN32); 1881544Seschrock minor_t start = zfs_minor; 1891544Seschrock do { 1901544Seschrock mutex_enter(&zfs_dev_mtx); 1911544Seschrock if (zfs_minor >= MAXMIN32) { 1921544Seschrock /* 1931544Seschrock * If we're still using the real major 1941544Seschrock * keep out of /dev/zfs and /dev/zvol minor 1951544Seschrock * number space. If we're using a getudev()'ed 1961544Seschrock * major number, we can use all of its minors. 1971544Seschrock */ 1981544Seschrock if (zfs_major == ddi_name_to_major(ZFS_DRIVER)) 1991544Seschrock zfs_minor = ZFS_MIN_MINOR; 2001544Seschrock else 2011544Seschrock zfs_minor = 0; 2021544Seschrock } else { 2031544Seschrock zfs_minor++; 2041544Seschrock } 2051544Seschrock *dev = makedevice(zfs_major, zfs_minor); 2061544Seschrock mutex_exit(&zfs_dev_mtx); 2071544Seschrock } while (vfs_devismounted(*dev) && zfs_minor != start); 2081544Seschrock if (zfs_minor == start) { 2091544Seschrock /* 2101544Seschrock * We are using all ~262,000 minor numbers for the 2111544Seschrock * current major number. Create a new major number. 2121544Seschrock */ 2131544Seschrock if ((new_major = getudev()) == (major_t)-1) { 2141544Seschrock cmn_err(CE_WARN, 2151544Seschrock "zfs_mount: Can't get unique major " 2161544Seschrock "device number."); 2171544Seschrock return (-1); 2181544Seschrock } 2191544Seschrock mutex_enter(&zfs_dev_mtx); 2201544Seschrock zfs_major = new_major; 2211544Seschrock zfs_minor = 0; 2221544Seschrock 2231544Seschrock mutex_exit(&zfs_dev_mtx); 2241544Seschrock } else { 2251544Seschrock break; 2261544Seschrock } 2271544Seschrock /* CONSTANTCONDITION */ 2281544Seschrock } while (1); 2291544Seschrock 2301544Seschrock return (0); 2311544Seschrock } 2321544Seschrock 233789Sahrens static void 234789Sahrens atime_changed_cb(void *arg, uint64_t newval) 235789Sahrens { 236789Sahrens zfsvfs_t *zfsvfs = arg; 237789Sahrens 238789Sahrens if (newval == TRUE) { 239789Sahrens zfsvfs->z_atime = TRUE; 240789Sahrens vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME); 241789Sahrens vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_ATIME, NULL, 0); 242789Sahrens } else { 243789Sahrens zfsvfs->z_atime = FALSE; 244789Sahrens vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_ATIME); 245789Sahrens vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME, NULL, 0); 246789Sahrens } 247789Sahrens } 248789Sahrens 249789Sahrens static void 2503234Sck153898 xattr_changed_cb(void *arg, uint64_t newval) 2513234Sck153898 { 2523234Sck153898 zfsvfs_t *zfsvfs = arg; 2533234Sck153898 2543234Sck153898 if (newval == TRUE) { 2553234Sck153898 /* XXX locking on vfs_flag? */ 2563234Sck153898 zfsvfs->z_vfs->vfs_flag |= VFS_XATTR; 2573234Sck153898 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR); 2583234Sck153898 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_XATTR, NULL, 0); 2593234Sck153898 } else { 2603234Sck153898 /* XXX locking on vfs_flag? */ 2613234Sck153898 zfsvfs->z_vfs->vfs_flag &= ~VFS_XATTR; 2623234Sck153898 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_XATTR); 2633234Sck153898 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR, NULL, 0); 2643234Sck153898 } 2653234Sck153898 } 2663234Sck153898 2673234Sck153898 static void 268789Sahrens blksz_changed_cb(void *arg, uint64_t newval) 269789Sahrens { 270789Sahrens zfsvfs_t *zfsvfs = arg; 271789Sahrens 272789Sahrens if (newval < SPA_MINBLOCKSIZE || 273789Sahrens newval > SPA_MAXBLOCKSIZE || !ISP2(newval)) 274789Sahrens newval = SPA_MAXBLOCKSIZE; 275789Sahrens 276789Sahrens zfsvfs->z_max_blksz = newval; 277789Sahrens zfsvfs->z_vfs->vfs_bsize = newval; 278789Sahrens } 279789Sahrens 280789Sahrens static void 281789Sahrens readonly_changed_cb(void *arg, uint64_t newval) 282789Sahrens { 283789Sahrens zfsvfs_t *zfsvfs = arg; 284789Sahrens 285789Sahrens if (newval) { 286789Sahrens /* XXX locking on vfs_flag? */ 287789Sahrens zfsvfs->z_vfs->vfs_flag |= VFS_RDONLY; 288789Sahrens vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RW); 289789Sahrens vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RO, NULL, 0); 290789Sahrens } else { 291789Sahrens /* XXX locking on vfs_flag? */ 292789Sahrens zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY; 293789Sahrens vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RO); 294789Sahrens vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RW, NULL, 0); 295789Sahrens } 296789Sahrens } 297789Sahrens 298789Sahrens static void 299789Sahrens devices_changed_cb(void *arg, uint64_t newval) 300789Sahrens { 301789Sahrens zfsvfs_t *zfsvfs = arg; 302789Sahrens 303789Sahrens if (newval == FALSE) { 304789Sahrens zfsvfs->z_vfs->vfs_flag |= VFS_NODEVICES; 305789Sahrens vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_DEVICES); 306789Sahrens vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NODEVICES, NULL, 0); 307789Sahrens } else { 308789Sahrens zfsvfs->z_vfs->vfs_flag &= ~VFS_NODEVICES; 309789Sahrens vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NODEVICES); 310789Sahrens vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_DEVICES, NULL, 0); 311789Sahrens } 312789Sahrens } 313789Sahrens 314789Sahrens static void 315789Sahrens setuid_changed_cb(void *arg, uint64_t newval) 316789Sahrens { 317789Sahrens zfsvfs_t *zfsvfs = arg; 318789Sahrens 319789Sahrens if (newval == FALSE) { 320789Sahrens zfsvfs->z_vfs->vfs_flag |= VFS_NOSETUID; 321789Sahrens vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_SETUID); 322789Sahrens vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID, NULL, 0); 323789Sahrens } else { 324789Sahrens zfsvfs->z_vfs->vfs_flag &= ~VFS_NOSETUID; 325789Sahrens vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID); 326789Sahrens vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_SETUID, NULL, 0); 327789Sahrens } 328789Sahrens } 329789Sahrens 330789Sahrens static void 331789Sahrens exec_changed_cb(void *arg, uint64_t newval) 332789Sahrens { 333789Sahrens zfsvfs_t *zfsvfs = arg; 334789Sahrens 335789Sahrens if (newval == FALSE) { 336789Sahrens zfsvfs->z_vfs->vfs_flag |= VFS_NOEXEC; 337789Sahrens vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_EXEC); 338789Sahrens vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC, NULL, 0); 339789Sahrens } else { 340789Sahrens zfsvfs->z_vfs->vfs_flag &= ~VFS_NOEXEC; 341789Sahrens vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC); 342789Sahrens vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_EXEC, NULL, 0); 343789Sahrens } 344789Sahrens } 345789Sahrens 3465331Samw /* 3475331Samw * The nbmand mount option can be changed at mount time. 3485331Samw * We can't allow it to be toggled on live file systems or incorrect 3495331Samw * behavior may be seen from cifs clients 3505331Samw * 3515331Samw * This property isn't registered via dsl_prop_register(), but this callback 3525331Samw * will be called when a file system is first mounted 3535331Samw */ 3545331Samw static void 3555331Samw nbmand_changed_cb(void *arg, uint64_t newval) 3565331Samw { 3575331Samw zfsvfs_t *zfsvfs = arg; 3585331Samw if (newval == FALSE) { 3595331Samw vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND); 3605331Samw vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND, NULL, 0); 3615331Samw } else { 3625331Samw vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND); 3635331Samw vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND, NULL, 0); 3645331Samw } 3655331Samw } 3665331Samw 367789Sahrens static void 368789Sahrens snapdir_changed_cb(void *arg, uint64_t newval) 369789Sahrens { 370789Sahrens zfsvfs_t *zfsvfs = arg; 371789Sahrens 372789Sahrens zfsvfs->z_show_ctldir = newval; 373789Sahrens } 374789Sahrens 375789Sahrens static void 3765331Samw vscan_changed_cb(void *arg, uint64_t newval) 3775331Samw { 3785331Samw zfsvfs_t *zfsvfs = arg; 3795331Samw 3805331Samw zfsvfs->z_vscan = newval; 3815331Samw } 3825331Samw 3835331Samw static void 384789Sahrens acl_mode_changed_cb(void *arg, uint64_t newval) 385789Sahrens { 386789Sahrens zfsvfs_t *zfsvfs = arg; 387789Sahrens 388789Sahrens zfsvfs->z_acl_mode = newval; 389789Sahrens } 390789Sahrens 391789Sahrens static void 392789Sahrens acl_inherit_changed_cb(void *arg, uint64_t newval) 393789Sahrens { 394789Sahrens zfsvfs_t *zfsvfs = arg; 395789Sahrens 396789Sahrens zfsvfs->z_acl_inherit = newval; 397789Sahrens } 398789Sahrens 3991544Seschrock static int 4001544Seschrock zfs_register_callbacks(vfs_t *vfsp) 4011544Seschrock { 4021544Seschrock struct dsl_dataset *ds = NULL; 4031544Seschrock objset_t *os = NULL; 4041544Seschrock zfsvfs_t *zfsvfs = NULL; 4055331Samw uint64_t nbmand; 4065331Samw int readonly, do_readonly = B_FALSE; 4075331Samw int setuid, do_setuid = B_FALSE; 4085331Samw int exec, do_exec = B_FALSE; 4095331Samw int devices, do_devices = B_FALSE; 4105331Samw int xattr, do_xattr = B_FALSE; 4115331Samw int atime, do_atime = B_FALSE; 4121544Seschrock int error = 0; 4131544Seschrock 4141544Seschrock ASSERT(vfsp); 4151544Seschrock zfsvfs = vfsp->vfs_data; 4161544Seschrock ASSERT(zfsvfs); 4171544Seschrock os = zfsvfs->z_os; 4181544Seschrock 4191544Seschrock /* 4201544Seschrock * The act of registering our callbacks will destroy any mount 4211544Seschrock * options we may have. In order to enable temporary overrides 4223234Sck153898 * of mount options, we stash away the current values and 4231544Seschrock * restore them after we register the callbacks. 4241544Seschrock */ 4251544Seschrock if (vfs_optionisset(vfsp, MNTOPT_RO, NULL)) { 4261544Seschrock readonly = B_TRUE; 4271544Seschrock do_readonly = B_TRUE; 4281544Seschrock } else if (vfs_optionisset(vfsp, MNTOPT_RW, NULL)) { 4291544Seschrock readonly = B_FALSE; 4301544Seschrock do_readonly = B_TRUE; 4311544Seschrock } 4321544Seschrock if (vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL)) { 4331544Seschrock devices = B_FALSE; 4341544Seschrock setuid = B_FALSE; 4351544Seschrock do_devices = B_TRUE; 4361544Seschrock do_setuid = B_TRUE; 4371544Seschrock } else { 4381544Seschrock if (vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL)) { 4391544Seschrock devices = B_FALSE; 4401544Seschrock do_devices = B_TRUE; 4413912Slling } else if (vfs_optionisset(vfsp, MNTOPT_DEVICES, NULL)) { 4421544Seschrock devices = B_TRUE; 4431544Seschrock do_devices = B_TRUE; 4441544Seschrock } 4451544Seschrock 4461544Seschrock if (vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL)) { 4471544Seschrock setuid = B_FALSE; 4481544Seschrock do_setuid = B_TRUE; 4491544Seschrock } else if (vfs_optionisset(vfsp, MNTOPT_SETUID, NULL)) { 4501544Seschrock setuid = B_TRUE; 4511544Seschrock do_setuid = B_TRUE; 4521544Seschrock } 4531544Seschrock } 4541544Seschrock if (vfs_optionisset(vfsp, MNTOPT_NOEXEC, NULL)) { 4551544Seschrock exec = B_FALSE; 4561544Seschrock do_exec = B_TRUE; 4571544Seschrock } else if (vfs_optionisset(vfsp, MNTOPT_EXEC, NULL)) { 4581544Seschrock exec = B_TRUE; 4591544Seschrock do_exec = B_TRUE; 4601544Seschrock } 4613234Sck153898 if (vfs_optionisset(vfsp, MNTOPT_NOXATTR, NULL)) { 4623234Sck153898 xattr = B_FALSE; 4633234Sck153898 do_xattr = B_TRUE; 4643234Sck153898 } else if (vfs_optionisset(vfsp, MNTOPT_XATTR, NULL)) { 4653234Sck153898 xattr = B_TRUE; 4663234Sck153898 do_xattr = B_TRUE; 4673234Sck153898 } 4684596Slling if (vfs_optionisset(vfsp, MNTOPT_NOATIME, NULL)) { 4694596Slling atime = B_FALSE; 4704596Slling do_atime = B_TRUE; 4714596Slling } else if (vfs_optionisset(vfsp, MNTOPT_ATIME, NULL)) { 4724596Slling atime = B_TRUE; 4734596Slling do_atime = B_TRUE; 4744596Slling } 4751544Seschrock 4761544Seschrock /* 4775331Samw * nbmand is a special property. It can only be changed at 4785331Samw * mount time. 4795331Samw * 4805331Samw * This is weird, but it is documented to only be changeable 4815331Samw * at mount time. 4825331Samw */ 4835331Samw if (vfs_optionisset(vfsp, MNTOPT_NONBMAND, NULL)) { 4845331Samw nbmand = B_FALSE; 4855331Samw } else if (vfs_optionisset(vfsp, MNTOPT_NBMAND, NULL)) { 4865331Samw nbmand = B_TRUE; 4875331Samw } else { 4885331Samw char osname[MAXNAMELEN]; 4895331Samw 4905331Samw dmu_objset_name(os, osname); 4915331Samw if (error = dsl_prop_get_integer(osname, "nbmand", &nbmand, 4927265Sahrens NULL)) { 4937265Sahrens return (error); 4947265Sahrens } 4955331Samw } 4965331Samw 4975331Samw /* 4981544Seschrock * Register property callbacks. 4991544Seschrock * 5001544Seschrock * It would probably be fine to just check for i/o error from 5011544Seschrock * the first prop_register(), but I guess I like to go 5021544Seschrock * overboard... 5031544Seschrock */ 5041544Seschrock ds = dmu_objset_ds(os); 5051544Seschrock error = dsl_prop_register(ds, "atime", atime_changed_cb, zfsvfs); 5061544Seschrock error = error ? error : dsl_prop_register(ds, 5073234Sck153898 "xattr", xattr_changed_cb, zfsvfs); 5083234Sck153898 error = error ? error : dsl_prop_register(ds, 5091544Seschrock "recordsize", blksz_changed_cb, zfsvfs); 5101544Seschrock error = error ? error : dsl_prop_register(ds, 5111544Seschrock "readonly", readonly_changed_cb, zfsvfs); 5121544Seschrock error = error ? error : dsl_prop_register(ds, 5131544Seschrock "devices", devices_changed_cb, zfsvfs); 5141544Seschrock error = error ? error : dsl_prop_register(ds, 5151544Seschrock "setuid", setuid_changed_cb, zfsvfs); 5161544Seschrock error = error ? error : dsl_prop_register(ds, 5171544Seschrock "exec", exec_changed_cb, zfsvfs); 5181544Seschrock error = error ? error : dsl_prop_register(ds, 5191544Seschrock "snapdir", snapdir_changed_cb, zfsvfs); 5201544Seschrock error = error ? error : dsl_prop_register(ds, 5211544Seschrock "aclmode", acl_mode_changed_cb, zfsvfs); 5221544Seschrock error = error ? error : dsl_prop_register(ds, 5231544Seschrock "aclinherit", acl_inherit_changed_cb, zfsvfs); 5245331Samw error = error ? error : dsl_prop_register(ds, 5255331Samw "vscan", vscan_changed_cb, zfsvfs); 5261544Seschrock if (error) 5271544Seschrock goto unregister; 5281544Seschrock 5291544Seschrock /* 5301544Seschrock * Invoke our callbacks to restore temporary mount options. 5311544Seschrock */ 5321544Seschrock if (do_readonly) 5331544Seschrock readonly_changed_cb(zfsvfs, readonly); 5341544Seschrock if (do_setuid) 5351544Seschrock setuid_changed_cb(zfsvfs, setuid); 5361544Seschrock if (do_exec) 5371544Seschrock exec_changed_cb(zfsvfs, exec); 5381544Seschrock if (do_devices) 5391544Seschrock devices_changed_cb(zfsvfs, devices); 5403234Sck153898 if (do_xattr) 5413234Sck153898 xattr_changed_cb(zfsvfs, xattr); 5424596Slling if (do_atime) 5434596Slling atime_changed_cb(zfsvfs, atime); 5441544Seschrock 5455331Samw nbmand_changed_cb(zfsvfs, nbmand); 5465331Samw 5471544Seschrock return (0); 5481544Seschrock 5491544Seschrock unregister: 5501544Seschrock /* 5511544Seschrock * We may attempt to unregister some callbacks that are not 5521544Seschrock * registered, but this is OK; it will simply return ENOMSG, 5531544Seschrock * which we will ignore. 5541544Seschrock */ 5551544Seschrock (void) dsl_prop_unregister(ds, "atime", atime_changed_cb, zfsvfs); 5563234Sck153898 (void) dsl_prop_unregister(ds, "xattr", xattr_changed_cb, zfsvfs); 5571544Seschrock (void) dsl_prop_unregister(ds, "recordsize", blksz_changed_cb, zfsvfs); 5581544Seschrock (void) dsl_prop_unregister(ds, "readonly", readonly_changed_cb, zfsvfs); 5591544Seschrock (void) dsl_prop_unregister(ds, "devices", devices_changed_cb, zfsvfs); 5601544Seschrock (void) dsl_prop_unregister(ds, "setuid", setuid_changed_cb, zfsvfs); 5611544Seschrock (void) dsl_prop_unregister(ds, "exec", exec_changed_cb, zfsvfs); 5621544Seschrock (void) dsl_prop_unregister(ds, "snapdir", snapdir_changed_cb, zfsvfs); 5631544Seschrock (void) dsl_prop_unregister(ds, "aclmode", acl_mode_changed_cb, zfsvfs); 5641544Seschrock (void) dsl_prop_unregister(ds, "aclinherit", acl_inherit_changed_cb, 5651544Seschrock zfsvfs); 5665331Samw (void) dsl_prop_unregister(ds, "vscan", vscan_changed_cb, zfsvfs); 5671544Seschrock return (error); 5681544Seschrock 5691544Seschrock } 5701544Seschrock 571*9396SMatthew.Ahrens@Sun.COM static void 572*9396SMatthew.Ahrens@Sun.COM uidacct(objset_t *os, boolean_t isgroup, uint64_t fuid, 573*9396SMatthew.Ahrens@Sun.COM int64_t delta, dmu_tx_t *tx) 574*9396SMatthew.Ahrens@Sun.COM { 575*9396SMatthew.Ahrens@Sun.COM uint64_t used = 0; 576*9396SMatthew.Ahrens@Sun.COM char buf[32]; 577*9396SMatthew.Ahrens@Sun.COM int err; 578*9396SMatthew.Ahrens@Sun.COM uint64_t obj = isgroup ? DMU_GROUPUSED_OBJECT : DMU_USERUSED_OBJECT; 579*9396SMatthew.Ahrens@Sun.COM 580*9396SMatthew.Ahrens@Sun.COM if (delta == 0) 581*9396SMatthew.Ahrens@Sun.COM return; 582*9396SMatthew.Ahrens@Sun.COM 583*9396SMatthew.Ahrens@Sun.COM (void) snprintf(buf, sizeof (buf), "%llx", (longlong_t)fuid); 584*9396SMatthew.Ahrens@Sun.COM err = zap_lookup(os, obj, buf, 8, 1, &used); 585*9396SMatthew.Ahrens@Sun.COM ASSERT(err == 0 || err == ENOENT); 586*9396SMatthew.Ahrens@Sun.COM /* no underflow/overflow */ 587*9396SMatthew.Ahrens@Sun.COM ASSERT(delta > 0 || used >= -delta); 588*9396SMatthew.Ahrens@Sun.COM ASSERT(delta < 0 || used + delta > used); 589*9396SMatthew.Ahrens@Sun.COM used += delta; 590*9396SMatthew.Ahrens@Sun.COM if (used == 0) 591*9396SMatthew.Ahrens@Sun.COM err = zap_remove(os, obj, buf, tx); 592*9396SMatthew.Ahrens@Sun.COM else 593*9396SMatthew.Ahrens@Sun.COM err = zap_update(os, obj, buf, 8, 1, &used, tx); 594*9396SMatthew.Ahrens@Sun.COM ASSERT(err == 0); 595*9396SMatthew.Ahrens@Sun.COM } 596*9396SMatthew.Ahrens@Sun.COM 597*9396SMatthew.Ahrens@Sun.COM static void 598*9396SMatthew.Ahrens@Sun.COM zfs_space_delta_cb(objset_t *os, dmu_object_type_t bonustype, 599*9396SMatthew.Ahrens@Sun.COM void *oldbonus, void *newbonus, 600*9396SMatthew.Ahrens@Sun.COM uint64_t oldused, uint64_t newused, dmu_tx_t *tx) 601*9396SMatthew.Ahrens@Sun.COM { 602*9396SMatthew.Ahrens@Sun.COM znode_phys_t *oldznp = oldbonus; 603*9396SMatthew.Ahrens@Sun.COM znode_phys_t *newznp = newbonus; 604*9396SMatthew.Ahrens@Sun.COM 605*9396SMatthew.Ahrens@Sun.COM if (bonustype != DMU_OT_ZNODE) 606*9396SMatthew.Ahrens@Sun.COM return; 607*9396SMatthew.Ahrens@Sun.COM 608*9396SMatthew.Ahrens@Sun.COM /* We charge 512 for the dnode (if it's allocated). */ 609*9396SMatthew.Ahrens@Sun.COM if (oldznp->zp_gen != 0) 610*9396SMatthew.Ahrens@Sun.COM oldused += DNODE_SIZE; 611*9396SMatthew.Ahrens@Sun.COM if (newznp->zp_gen != 0) 612*9396SMatthew.Ahrens@Sun.COM newused += DNODE_SIZE; 613*9396SMatthew.Ahrens@Sun.COM 614*9396SMatthew.Ahrens@Sun.COM if (oldznp->zp_uid == newznp->zp_uid) { 615*9396SMatthew.Ahrens@Sun.COM uidacct(os, B_FALSE, oldznp->zp_uid, newused-oldused, tx); 616*9396SMatthew.Ahrens@Sun.COM } else { 617*9396SMatthew.Ahrens@Sun.COM uidacct(os, B_FALSE, oldznp->zp_uid, -oldused, tx); 618*9396SMatthew.Ahrens@Sun.COM uidacct(os, B_FALSE, newznp->zp_uid, newused, tx); 619*9396SMatthew.Ahrens@Sun.COM } 620*9396SMatthew.Ahrens@Sun.COM 621*9396SMatthew.Ahrens@Sun.COM if (oldznp->zp_gid == newznp->zp_gid) { 622*9396SMatthew.Ahrens@Sun.COM uidacct(os, B_TRUE, oldznp->zp_gid, newused-oldused, tx); 623*9396SMatthew.Ahrens@Sun.COM } else { 624*9396SMatthew.Ahrens@Sun.COM uidacct(os, B_TRUE, oldznp->zp_gid, -oldused, tx); 625*9396SMatthew.Ahrens@Sun.COM uidacct(os, B_TRUE, newznp->zp_gid, newused, tx); 626*9396SMatthew.Ahrens@Sun.COM } 627*9396SMatthew.Ahrens@Sun.COM } 628*9396SMatthew.Ahrens@Sun.COM 629*9396SMatthew.Ahrens@Sun.COM static void 630*9396SMatthew.Ahrens@Sun.COM fuidstr_to_sid(zfsvfs_t *zfsvfs, const char *fuidstr, 631*9396SMatthew.Ahrens@Sun.COM char *domainbuf, int buflen, uid_t *ridp) 632*9396SMatthew.Ahrens@Sun.COM { 633*9396SMatthew.Ahrens@Sun.COM extern uint64_t strtonum(const char *str, char **nptr); 634*9396SMatthew.Ahrens@Sun.COM uint64_t fuid; 635*9396SMatthew.Ahrens@Sun.COM const char *domain; 636*9396SMatthew.Ahrens@Sun.COM 637*9396SMatthew.Ahrens@Sun.COM fuid = strtonum(fuidstr, NULL); 638*9396SMatthew.Ahrens@Sun.COM 639*9396SMatthew.Ahrens@Sun.COM domain = zfs_fuid_find_by_idx(zfsvfs, FUID_INDEX(fuid)); 640*9396SMatthew.Ahrens@Sun.COM if (domain) 641*9396SMatthew.Ahrens@Sun.COM (void) strlcpy(domainbuf, domain, buflen); 642*9396SMatthew.Ahrens@Sun.COM else 643*9396SMatthew.Ahrens@Sun.COM domainbuf[0] = '\0'; 644*9396SMatthew.Ahrens@Sun.COM *ridp = FUID_RID(fuid); 645*9396SMatthew.Ahrens@Sun.COM } 646*9396SMatthew.Ahrens@Sun.COM 647*9396SMatthew.Ahrens@Sun.COM static uint64_t 648*9396SMatthew.Ahrens@Sun.COM zfs_userquota_prop_to_obj(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type) 649*9396SMatthew.Ahrens@Sun.COM { 650*9396SMatthew.Ahrens@Sun.COM switch (type) { 651*9396SMatthew.Ahrens@Sun.COM case ZFS_PROP_USERUSED: 652*9396SMatthew.Ahrens@Sun.COM return (DMU_USERUSED_OBJECT); 653*9396SMatthew.Ahrens@Sun.COM case ZFS_PROP_GROUPUSED: 654*9396SMatthew.Ahrens@Sun.COM return (DMU_GROUPUSED_OBJECT); 655*9396SMatthew.Ahrens@Sun.COM case ZFS_PROP_USERQUOTA: 656*9396SMatthew.Ahrens@Sun.COM return (zfsvfs->z_userquota_obj); 657*9396SMatthew.Ahrens@Sun.COM case ZFS_PROP_GROUPQUOTA: 658*9396SMatthew.Ahrens@Sun.COM return (zfsvfs->z_groupquota_obj); 659*9396SMatthew.Ahrens@Sun.COM } 660*9396SMatthew.Ahrens@Sun.COM return (0); 661*9396SMatthew.Ahrens@Sun.COM } 662*9396SMatthew.Ahrens@Sun.COM 663*9396SMatthew.Ahrens@Sun.COM int 664*9396SMatthew.Ahrens@Sun.COM zfs_userspace_many(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type, 665*9396SMatthew.Ahrens@Sun.COM uint64_t *cookiep, void *vbuf, uint64_t *bufsizep) 666*9396SMatthew.Ahrens@Sun.COM { 667*9396SMatthew.Ahrens@Sun.COM int error; 668*9396SMatthew.Ahrens@Sun.COM zap_cursor_t zc; 669*9396SMatthew.Ahrens@Sun.COM zap_attribute_t za; 670*9396SMatthew.Ahrens@Sun.COM zfs_useracct_t *buf = vbuf; 671*9396SMatthew.Ahrens@Sun.COM uint64_t obj; 672*9396SMatthew.Ahrens@Sun.COM 673*9396SMatthew.Ahrens@Sun.COM if (!dmu_objset_userspace_present(zfsvfs->z_os)) 674*9396SMatthew.Ahrens@Sun.COM return (ENOTSUP); 675*9396SMatthew.Ahrens@Sun.COM 676*9396SMatthew.Ahrens@Sun.COM obj = zfs_userquota_prop_to_obj(zfsvfs, type); 677*9396SMatthew.Ahrens@Sun.COM if (obj == 0) { 678*9396SMatthew.Ahrens@Sun.COM *bufsizep = 0; 679*9396SMatthew.Ahrens@Sun.COM return (0); 680*9396SMatthew.Ahrens@Sun.COM } 681*9396SMatthew.Ahrens@Sun.COM 682*9396SMatthew.Ahrens@Sun.COM for (zap_cursor_init_serialized(&zc, zfsvfs->z_os, obj, *cookiep); 683*9396SMatthew.Ahrens@Sun.COM (error = zap_cursor_retrieve(&zc, &za)) == 0; 684*9396SMatthew.Ahrens@Sun.COM zap_cursor_advance(&zc)) { 685*9396SMatthew.Ahrens@Sun.COM if ((uintptr_t)buf - (uintptr_t)vbuf + sizeof (zfs_useracct_t) > 686*9396SMatthew.Ahrens@Sun.COM *bufsizep) 687*9396SMatthew.Ahrens@Sun.COM break; 688*9396SMatthew.Ahrens@Sun.COM 689*9396SMatthew.Ahrens@Sun.COM fuidstr_to_sid(zfsvfs, za.za_name, 690*9396SMatthew.Ahrens@Sun.COM buf->zu_domain, sizeof (buf->zu_domain), &buf->zu_rid); 691*9396SMatthew.Ahrens@Sun.COM 692*9396SMatthew.Ahrens@Sun.COM buf->zu_space = za.za_first_integer; 693*9396SMatthew.Ahrens@Sun.COM buf++; 694*9396SMatthew.Ahrens@Sun.COM } 695*9396SMatthew.Ahrens@Sun.COM if (error == ENOENT) 696*9396SMatthew.Ahrens@Sun.COM error = 0; 697*9396SMatthew.Ahrens@Sun.COM 698*9396SMatthew.Ahrens@Sun.COM ASSERT3U((uintptr_t)buf - (uintptr_t)vbuf, <=, *bufsizep); 699*9396SMatthew.Ahrens@Sun.COM *bufsizep = (uintptr_t)buf - (uintptr_t)vbuf; 700*9396SMatthew.Ahrens@Sun.COM *cookiep = zap_cursor_serialize(&zc); 701*9396SMatthew.Ahrens@Sun.COM zap_cursor_fini(&zc); 702*9396SMatthew.Ahrens@Sun.COM return (error); 703*9396SMatthew.Ahrens@Sun.COM } 704*9396SMatthew.Ahrens@Sun.COM 705*9396SMatthew.Ahrens@Sun.COM /* 706*9396SMatthew.Ahrens@Sun.COM * buf must be big enough (eg, 32 bytes) 707*9396SMatthew.Ahrens@Sun.COM */ 708*9396SMatthew.Ahrens@Sun.COM static int 709*9396SMatthew.Ahrens@Sun.COM id_to_fuidstr(zfsvfs_t *zfsvfs, const char *domain, uid_t rid, 710*9396SMatthew.Ahrens@Sun.COM char *buf, boolean_t addok) 711*9396SMatthew.Ahrens@Sun.COM { 712*9396SMatthew.Ahrens@Sun.COM uint64_t fuid; 713*9396SMatthew.Ahrens@Sun.COM int domainid = 0; 714*9396SMatthew.Ahrens@Sun.COM 715*9396SMatthew.Ahrens@Sun.COM if (domain && domain[0]) { 716*9396SMatthew.Ahrens@Sun.COM domainid = zfs_fuid_find_by_domain(zfsvfs, domain, NULL, addok); 717*9396SMatthew.Ahrens@Sun.COM if (domainid == -1) 718*9396SMatthew.Ahrens@Sun.COM return (ENOENT); 719*9396SMatthew.Ahrens@Sun.COM } 720*9396SMatthew.Ahrens@Sun.COM fuid = FUID_ENCODE(domainid, rid); 721*9396SMatthew.Ahrens@Sun.COM (void) sprintf(buf, "%llx", (longlong_t)fuid); 722*9396SMatthew.Ahrens@Sun.COM return (0); 723*9396SMatthew.Ahrens@Sun.COM } 724*9396SMatthew.Ahrens@Sun.COM 725*9396SMatthew.Ahrens@Sun.COM int 726*9396SMatthew.Ahrens@Sun.COM zfs_userspace_one(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type, 727*9396SMatthew.Ahrens@Sun.COM const char *domain, uint64_t rid, uint64_t *valp) 728*9396SMatthew.Ahrens@Sun.COM { 729*9396SMatthew.Ahrens@Sun.COM char buf[32]; 730*9396SMatthew.Ahrens@Sun.COM int err; 731*9396SMatthew.Ahrens@Sun.COM uint64_t obj; 732*9396SMatthew.Ahrens@Sun.COM 733*9396SMatthew.Ahrens@Sun.COM *valp = 0; 734*9396SMatthew.Ahrens@Sun.COM 735*9396SMatthew.Ahrens@Sun.COM if (!dmu_objset_userspace_present(zfsvfs->z_os)) 736*9396SMatthew.Ahrens@Sun.COM return (ENOTSUP); 737*9396SMatthew.Ahrens@Sun.COM 738*9396SMatthew.Ahrens@Sun.COM obj = zfs_userquota_prop_to_obj(zfsvfs, type); 739*9396SMatthew.Ahrens@Sun.COM if (obj == 0) 740*9396SMatthew.Ahrens@Sun.COM return (0); 741*9396SMatthew.Ahrens@Sun.COM 742*9396SMatthew.Ahrens@Sun.COM err = id_to_fuidstr(zfsvfs, domain, rid, buf, B_FALSE); 743*9396SMatthew.Ahrens@Sun.COM if (err) 744*9396SMatthew.Ahrens@Sun.COM return (err); 745*9396SMatthew.Ahrens@Sun.COM 746*9396SMatthew.Ahrens@Sun.COM err = zap_lookup(zfsvfs->z_os, obj, buf, 8, 1, valp); 747*9396SMatthew.Ahrens@Sun.COM if (err == ENOENT) 748*9396SMatthew.Ahrens@Sun.COM err = 0; 749*9396SMatthew.Ahrens@Sun.COM return (err); 750*9396SMatthew.Ahrens@Sun.COM } 751*9396SMatthew.Ahrens@Sun.COM 752*9396SMatthew.Ahrens@Sun.COM int 753*9396SMatthew.Ahrens@Sun.COM zfs_set_userquota(zfsvfs_t *zfsvfs, zfs_userquota_prop_t type, 754*9396SMatthew.Ahrens@Sun.COM const char *domain, uint64_t rid, uint64_t quota) 755*9396SMatthew.Ahrens@Sun.COM { 756*9396SMatthew.Ahrens@Sun.COM char buf[32]; 757*9396SMatthew.Ahrens@Sun.COM int err; 758*9396SMatthew.Ahrens@Sun.COM dmu_tx_t *tx; 759*9396SMatthew.Ahrens@Sun.COM uint64_t *objp; 760*9396SMatthew.Ahrens@Sun.COM boolean_t fuid_dirtied; 761*9396SMatthew.Ahrens@Sun.COM 762*9396SMatthew.Ahrens@Sun.COM if (type != ZFS_PROP_USERQUOTA && type != ZFS_PROP_GROUPQUOTA) 763*9396SMatthew.Ahrens@Sun.COM return (EINVAL); 764*9396SMatthew.Ahrens@Sun.COM 765*9396SMatthew.Ahrens@Sun.COM if (zfsvfs->z_version < ZPL_VERSION_USERSPACE) 766*9396SMatthew.Ahrens@Sun.COM return (ENOTSUP); 767*9396SMatthew.Ahrens@Sun.COM 768*9396SMatthew.Ahrens@Sun.COM objp = (type == ZFS_PROP_USERQUOTA) ? &zfsvfs->z_userquota_obj : 769*9396SMatthew.Ahrens@Sun.COM &zfsvfs->z_groupquota_obj; 770*9396SMatthew.Ahrens@Sun.COM 771*9396SMatthew.Ahrens@Sun.COM err = id_to_fuidstr(zfsvfs, domain, rid, buf, B_TRUE); 772*9396SMatthew.Ahrens@Sun.COM if (err) 773*9396SMatthew.Ahrens@Sun.COM return (err); 774*9396SMatthew.Ahrens@Sun.COM fuid_dirtied = zfsvfs->z_fuid_dirty; 775*9396SMatthew.Ahrens@Sun.COM 776*9396SMatthew.Ahrens@Sun.COM tx = dmu_tx_create(zfsvfs->z_os); 777*9396SMatthew.Ahrens@Sun.COM dmu_tx_hold_zap(tx, *objp ? *objp : DMU_NEW_OBJECT, B_TRUE, NULL); 778*9396SMatthew.Ahrens@Sun.COM if (*objp == 0) { 779*9396SMatthew.Ahrens@Sun.COM dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_TRUE, 780*9396SMatthew.Ahrens@Sun.COM zfs_userquota_prop_prefixes[type]); 781*9396SMatthew.Ahrens@Sun.COM } 782*9396SMatthew.Ahrens@Sun.COM if (fuid_dirtied) 783*9396SMatthew.Ahrens@Sun.COM zfs_fuid_txhold(zfsvfs, tx); 784*9396SMatthew.Ahrens@Sun.COM err = dmu_tx_assign(tx, TXG_WAIT); 785*9396SMatthew.Ahrens@Sun.COM if (err) { 786*9396SMatthew.Ahrens@Sun.COM dmu_tx_abort(tx); 787*9396SMatthew.Ahrens@Sun.COM return (err); 788*9396SMatthew.Ahrens@Sun.COM } 789*9396SMatthew.Ahrens@Sun.COM 790*9396SMatthew.Ahrens@Sun.COM mutex_enter(&zfsvfs->z_lock); 791*9396SMatthew.Ahrens@Sun.COM if (*objp == 0) { 792*9396SMatthew.Ahrens@Sun.COM *objp = zap_create(zfsvfs->z_os, DMU_OT_USERGROUP_QUOTA, 793*9396SMatthew.Ahrens@Sun.COM DMU_OT_NONE, 0, tx); 794*9396SMatthew.Ahrens@Sun.COM VERIFY(0 == zap_add(zfsvfs->z_os, MASTER_NODE_OBJ, 795*9396SMatthew.Ahrens@Sun.COM zfs_userquota_prop_prefixes[type], 8, 1, objp, tx)); 796*9396SMatthew.Ahrens@Sun.COM } 797*9396SMatthew.Ahrens@Sun.COM mutex_exit(&zfsvfs->z_lock); 798*9396SMatthew.Ahrens@Sun.COM 799*9396SMatthew.Ahrens@Sun.COM if (quota == 0) { 800*9396SMatthew.Ahrens@Sun.COM err = zap_remove(zfsvfs->z_os, *objp, buf, tx); 801*9396SMatthew.Ahrens@Sun.COM if (err == ENOENT) 802*9396SMatthew.Ahrens@Sun.COM err = 0; 803*9396SMatthew.Ahrens@Sun.COM } else { 804*9396SMatthew.Ahrens@Sun.COM err = zap_update(zfsvfs->z_os, *objp, buf, 8, 1, "a, tx); 805*9396SMatthew.Ahrens@Sun.COM } 806*9396SMatthew.Ahrens@Sun.COM ASSERT(err == 0); 807*9396SMatthew.Ahrens@Sun.COM if (fuid_dirtied) 808*9396SMatthew.Ahrens@Sun.COM zfs_fuid_sync(zfsvfs, tx); 809*9396SMatthew.Ahrens@Sun.COM dmu_tx_commit(tx); 810*9396SMatthew.Ahrens@Sun.COM return (err); 811*9396SMatthew.Ahrens@Sun.COM } 812*9396SMatthew.Ahrens@Sun.COM 813*9396SMatthew.Ahrens@Sun.COM boolean_t 814*9396SMatthew.Ahrens@Sun.COM zfs_usergroup_overquota(zfsvfs_t *zfsvfs, boolean_t isgroup, uint64_t fuid) 815*9396SMatthew.Ahrens@Sun.COM { 816*9396SMatthew.Ahrens@Sun.COM char buf[32]; 817*9396SMatthew.Ahrens@Sun.COM uint64_t used, quota, usedobj, quotaobj; 818*9396SMatthew.Ahrens@Sun.COM int err; 819*9396SMatthew.Ahrens@Sun.COM 820*9396SMatthew.Ahrens@Sun.COM usedobj = isgroup ? DMU_GROUPUSED_OBJECT : DMU_USERUSED_OBJECT; 821*9396SMatthew.Ahrens@Sun.COM quotaobj = isgroup ? zfsvfs->z_groupquota_obj : zfsvfs->z_userquota_obj; 822*9396SMatthew.Ahrens@Sun.COM 823*9396SMatthew.Ahrens@Sun.COM if (quotaobj == 0 || zfsvfs->z_replay) 824*9396SMatthew.Ahrens@Sun.COM return (B_FALSE); 825*9396SMatthew.Ahrens@Sun.COM 826*9396SMatthew.Ahrens@Sun.COM (void) sprintf(buf, "%llx", (longlong_t)fuid); 827*9396SMatthew.Ahrens@Sun.COM err = zap_lookup(zfsvfs->z_os, quotaobj, buf, 8, 1, "a); 828*9396SMatthew.Ahrens@Sun.COM if (err != 0) 829*9396SMatthew.Ahrens@Sun.COM return (B_FALSE); 830*9396SMatthew.Ahrens@Sun.COM 831*9396SMatthew.Ahrens@Sun.COM err = zap_lookup(zfsvfs->z_os, usedobj, buf, 8, 1, &used); 832*9396SMatthew.Ahrens@Sun.COM if (err != 0) 833*9396SMatthew.Ahrens@Sun.COM return (B_FALSE); 834*9396SMatthew.Ahrens@Sun.COM return (used >= quota); 835*9396SMatthew.Ahrens@Sun.COM } 836*9396SMatthew.Ahrens@Sun.COM 837*9396SMatthew.Ahrens@Sun.COM int 838*9396SMatthew.Ahrens@Sun.COM zfsvfs_create(const char *osname, int mode, zfsvfs_t **zvp) 839*9396SMatthew.Ahrens@Sun.COM { 840*9396SMatthew.Ahrens@Sun.COM objset_t *os; 841*9396SMatthew.Ahrens@Sun.COM zfsvfs_t *zfsvfs; 842*9396SMatthew.Ahrens@Sun.COM uint64_t zval; 843*9396SMatthew.Ahrens@Sun.COM int i, error; 844*9396SMatthew.Ahrens@Sun.COM 845*9396SMatthew.Ahrens@Sun.COM if (error = dsl_prop_get_integer(osname, "readonly", &zval, NULL)) 846*9396SMatthew.Ahrens@Sun.COM return (error); 847*9396SMatthew.Ahrens@Sun.COM if (zval) 848*9396SMatthew.Ahrens@Sun.COM mode |= DS_MODE_READONLY; 849*9396SMatthew.Ahrens@Sun.COM 850*9396SMatthew.Ahrens@Sun.COM error = dmu_objset_open(osname, DMU_OST_ZFS, mode, &os); 851*9396SMatthew.Ahrens@Sun.COM if (error == EROFS) { 852*9396SMatthew.Ahrens@Sun.COM mode |= DS_MODE_READONLY; 853*9396SMatthew.Ahrens@Sun.COM error = dmu_objset_open(osname, DMU_OST_ZFS, mode, &os); 854*9396SMatthew.Ahrens@Sun.COM } 855*9396SMatthew.Ahrens@Sun.COM if (error) 856*9396SMatthew.Ahrens@Sun.COM return (error); 857*9396SMatthew.Ahrens@Sun.COM 858*9396SMatthew.Ahrens@Sun.COM /* 859*9396SMatthew.Ahrens@Sun.COM * Initialize the zfs-specific filesystem structure. 860*9396SMatthew.Ahrens@Sun.COM * Should probably make this a kmem cache, shuffle fields, 861*9396SMatthew.Ahrens@Sun.COM * and just bzero up to z_hold_mtx[]. 862*9396SMatthew.Ahrens@Sun.COM */ 863*9396SMatthew.Ahrens@Sun.COM zfsvfs = kmem_zalloc(sizeof (zfsvfs_t), KM_SLEEP); 864*9396SMatthew.Ahrens@Sun.COM zfsvfs->z_vfs = NULL; 865*9396SMatthew.Ahrens@Sun.COM zfsvfs->z_parent = zfsvfs; 866*9396SMatthew.Ahrens@Sun.COM zfsvfs->z_max_blksz = SPA_MAXBLOCKSIZE; 867*9396SMatthew.Ahrens@Sun.COM zfsvfs->z_show_ctldir = ZFS_SNAPDIR_VISIBLE; 868*9396SMatthew.Ahrens@Sun.COM zfsvfs->z_os = os; 869*9396SMatthew.Ahrens@Sun.COM 870*9396SMatthew.Ahrens@Sun.COM error = zfs_get_zplprop(os, ZFS_PROP_VERSION, &zfsvfs->z_version); 871*9396SMatthew.Ahrens@Sun.COM if (error) { 872*9396SMatthew.Ahrens@Sun.COM goto out; 873*9396SMatthew.Ahrens@Sun.COM } else if (zfsvfs->z_version > ZPL_VERSION) { 874*9396SMatthew.Ahrens@Sun.COM (void) printf("Mismatched versions: File system " 875*9396SMatthew.Ahrens@Sun.COM "is version %llu on-disk format, which is " 876*9396SMatthew.Ahrens@Sun.COM "incompatible with this software version %lld!", 877*9396SMatthew.Ahrens@Sun.COM (u_longlong_t)zfsvfs->z_version, ZPL_VERSION); 878*9396SMatthew.Ahrens@Sun.COM error = ENOTSUP; 879*9396SMatthew.Ahrens@Sun.COM goto out; 880*9396SMatthew.Ahrens@Sun.COM } 881*9396SMatthew.Ahrens@Sun.COM 882*9396SMatthew.Ahrens@Sun.COM if ((error = zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &zval)) != 0) 883*9396SMatthew.Ahrens@Sun.COM goto out; 884*9396SMatthew.Ahrens@Sun.COM zfsvfs->z_norm = (int)zval; 885*9396SMatthew.Ahrens@Sun.COM 886*9396SMatthew.Ahrens@Sun.COM if ((error = zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &zval)) != 0) 887*9396SMatthew.Ahrens@Sun.COM goto out; 888*9396SMatthew.Ahrens@Sun.COM zfsvfs->z_utf8 = (zval != 0); 889*9396SMatthew.Ahrens@Sun.COM 890*9396SMatthew.Ahrens@Sun.COM if ((error = zfs_get_zplprop(os, ZFS_PROP_CASE, &zval)) != 0) 891*9396SMatthew.Ahrens@Sun.COM goto out; 892*9396SMatthew.Ahrens@Sun.COM zfsvfs->z_case = (uint_t)zval; 893*9396SMatthew.Ahrens@Sun.COM 894*9396SMatthew.Ahrens@Sun.COM /* 895*9396SMatthew.Ahrens@Sun.COM * Fold case on file systems that are always or sometimes case 896*9396SMatthew.Ahrens@Sun.COM * insensitive. 897*9396SMatthew.Ahrens@Sun.COM */ 898*9396SMatthew.Ahrens@Sun.COM if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE || 899*9396SMatthew.Ahrens@Sun.COM zfsvfs->z_case == ZFS_CASE_MIXED) 900*9396SMatthew.Ahrens@Sun.COM zfsvfs->z_norm |= U8_TEXTPREP_TOUPPER; 901*9396SMatthew.Ahrens@Sun.COM 902*9396SMatthew.Ahrens@Sun.COM zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os); 903*9396SMatthew.Ahrens@Sun.COM 904*9396SMatthew.Ahrens@Sun.COM error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1, 905*9396SMatthew.Ahrens@Sun.COM &zfsvfs->z_root); 906*9396SMatthew.Ahrens@Sun.COM if (error) 907*9396SMatthew.Ahrens@Sun.COM goto out; 908*9396SMatthew.Ahrens@Sun.COM ASSERT(zfsvfs->z_root != 0); 909*9396SMatthew.Ahrens@Sun.COM 910*9396SMatthew.Ahrens@Sun.COM error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_UNLINKED_SET, 8, 1, 911*9396SMatthew.Ahrens@Sun.COM &zfsvfs->z_unlinkedobj); 912*9396SMatthew.Ahrens@Sun.COM if (error) 913*9396SMatthew.Ahrens@Sun.COM goto out; 914*9396SMatthew.Ahrens@Sun.COM 915*9396SMatthew.Ahrens@Sun.COM error = zap_lookup(os, MASTER_NODE_OBJ, 916*9396SMatthew.Ahrens@Sun.COM zfs_userquota_prop_prefixes[ZFS_PROP_USERQUOTA], 917*9396SMatthew.Ahrens@Sun.COM 8, 1, &zfsvfs->z_userquota_obj); 918*9396SMatthew.Ahrens@Sun.COM if (error && error != ENOENT) 919*9396SMatthew.Ahrens@Sun.COM goto out; 920*9396SMatthew.Ahrens@Sun.COM 921*9396SMatthew.Ahrens@Sun.COM error = zap_lookup(os, MASTER_NODE_OBJ, 922*9396SMatthew.Ahrens@Sun.COM zfs_userquota_prop_prefixes[ZFS_PROP_GROUPQUOTA], 923*9396SMatthew.Ahrens@Sun.COM 8, 1, &zfsvfs->z_groupquota_obj); 924*9396SMatthew.Ahrens@Sun.COM if (error && error != ENOENT) 925*9396SMatthew.Ahrens@Sun.COM goto out; 926*9396SMatthew.Ahrens@Sun.COM 927*9396SMatthew.Ahrens@Sun.COM error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_FUID_TABLES, 8, 1, 928*9396SMatthew.Ahrens@Sun.COM &zfsvfs->z_fuid_obj); 929*9396SMatthew.Ahrens@Sun.COM if (error && error != ENOENT) 930*9396SMatthew.Ahrens@Sun.COM goto out; 931*9396SMatthew.Ahrens@Sun.COM 932*9396SMatthew.Ahrens@Sun.COM error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_SHARES_DIR, 8, 1, 933*9396SMatthew.Ahrens@Sun.COM &zfsvfs->z_shares_dir); 934*9396SMatthew.Ahrens@Sun.COM if (error && error != ENOENT) 935*9396SMatthew.Ahrens@Sun.COM goto out; 936*9396SMatthew.Ahrens@Sun.COM 937*9396SMatthew.Ahrens@Sun.COM mutex_init(&zfsvfs->z_znodes_lock, NULL, MUTEX_DEFAULT, NULL); 938*9396SMatthew.Ahrens@Sun.COM mutex_init(&zfsvfs->z_online_recv_lock, NULL, MUTEX_DEFAULT, NULL); 939*9396SMatthew.Ahrens@Sun.COM mutex_init(&zfsvfs->z_lock, NULL, MUTEX_DEFAULT, NULL); 940*9396SMatthew.Ahrens@Sun.COM list_create(&zfsvfs->z_all_znodes, sizeof (znode_t), 941*9396SMatthew.Ahrens@Sun.COM offsetof(znode_t, z_link_node)); 942*9396SMatthew.Ahrens@Sun.COM rrw_init(&zfsvfs->z_teardown_lock); 943*9396SMatthew.Ahrens@Sun.COM rw_init(&zfsvfs->z_teardown_inactive_lock, NULL, RW_DEFAULT, NULL); 944*9396SMatthew.Ahrens@Sun.COM rw_init(&zfsvfs->z_fuid_lock, NULL, RW_DEFAULT, NULL); 945*9396SMatthew.Ahrens@Sun.COM for (i = 0; i != ZFS_OBJ_MTX_SZ; i++) 946*9396SMatthew.Ahrens@Sun.COM mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL); 947*9396SMatthew.Ahrens@Sun.COM 948*9396SMatthew.Ahrens@Sun.COM *zvp = zfsvfs; 949*9396SMatthew.Ahrens@Sun.COM return (0); 950*9396SMatthew.Ahrens@Sun.COM 951*9396SMatthew.Ahrens@Sun.COM out: 952*9396SMatthew.Ahrens@Sun.COM dmu_objset_close(os); 953*9396SMatthew.Ahrens@Sun.COM *zvp = NULL; 954*9396SMatthew.Ahrens@Sun.COM kmem_free(zfsvfs, sizeof (zfsvfs_t)); 955*9396SMatthew.Ahrens@Sun.COM return (error); 956*9396SMatthew.Ahrens@Sun.COM } 957*9396SMatthew.Ahrens@Sun.COM 9581544Seschrock static int 9595326Sek110237 zfsvfs_setup(zfsvfs_t *zfsvfs, boolean_t mounting) 9605326Sek110237 { 9615326Sek110237 int error; 9625326Sek110237 9635326Sek110237 error = zfs_register_callbacks(zfsvfs->z_vfs); 9645326Sek110237 if (error) 9655326Sek110237 return (error); 9665326Sek110237 9675326Sek110237 /* 9685326Sek110237 * Set the objset user_ptr to track its zfsvfs. 9695326Sek110237 */ 9705326Sek110237 mutex_enter(&zfsvfs->z_os->os->os_user_ptr_lock); 9715326Sek110237 dmu_objset_set_user(zfsvfs->z_os, zfsvfs); 9725326Sek110237 mutex_exit(&zfsvfs->z_os->os->os_user_ptr_lock); 9735326Sek110237 9749292SNeil.Perrin@Sun.COM zfsvfs->z_log = zil_open(zfsvfs->z_os, zfs_get_data); 9759292SNeil.Perrin@Sun.COM if (zil_disable) { 9769292SNeil.Perrin@Sun.COM zil_destroy(zfsvfs->z_log, 0); 9779292SNeil.Perrin@Sun.COM zfsvfs->z_log = NULL; 9789292SNeil.Perrin@Sun.COM } 9799292SNeil.Perrin@Sun.COM 9805326Sek110237 /* 9815326Sek110237 * If we are not mounting (ie: online recv), then we don't 9825326Sek110237 * have to worry about replaying the log as we blocked all 9835326Sek110237 * operations out since we closed the ZIL. 9845326Sek110237 */ 9855326Sek110237 if (mounting) { 9867638SNeil.Perrin@Sun.COM boolean_t readonly; 9877638SNeil.Perrin@Sun.COM 9885326Sek110237 /* 9895326Sek110237 * During replay we remove the read only flag to 9905326Sek110237 * allow replays to succeed. 9915326Sek110237 */ 9925326Sek110237 readonly = zfsvfs->z_vfs->vfs_flag & VFS_RDONLY; 9938227SNeil.Perrin@Sun.COM if (readonly != 0) 9948227SNeil.Perrin@Sun.COM zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY; 9958227SNeil.Perrin@Sun.COM else 9968227SNeil.Perrin@Sun.COM zfs_unlinked_drain(zfsvfs); 9975326Sek110237 9989292SNeil.Perrin@Sun.COM if (zfsvfs->z_log) { 9998227SNeil.Perrin@Sun.COM /* 10008227SNeil.Perrin@Sun.COM * Parse and replay the intent log. 10018227SNeil.Perrin@Sun.COM * 10028227SNeil.Perrin@Sun.COM * Because of ziltest, this must be done after 10038227SNeil.Perrin@Sun.COM * zfs_unlinked_drain(). (Further note: ziltest 10048227SNeil.Perrin@Sun.COM * doesn't use readonly mounts, where 10058227SNeil.Perrin@Sun.COM * zfs_unlinked_drain() isn't called.) This is because 10068227SNeil.Perrin@Sun.COM * ziltest causes spa_sync() to think it's committed, 10078227SNeil.Perrin@Sun.COM * but actually it is not, so the intent log contains 10088227SNeil.Perrin@Sun.COM * many txg's worth of changes. 10098227SNeil.Perrin@Sun.COM * 10108227SNeil.Perrin@Sun.COM * In particular, if object N is in the unlinked set in 10118227SNeil.Perrin@Sun.COM * the last txg to actually sync, then it could be 10128227SNeil.Perrin@Sun.COM * actually freed in a later txg and then reallocated 10138227SNeil.Perrin@Sun.COM * in a yet later txg. This would write a "create 10148227SNeil.Perrin@Sun.COM * object N" record to the intent log. Normally, this 10158227SNeil.Perrin@Sun.COM * would be fine because the spa_sync() would have 10168227SNeil.Perrin@Sun.COM * written out the fact that object N is free, before 10178227SNeil.Perrin@Sun.COM * we could write the "create object N" intent log 10188227SNeil.Perrin@Sun.COM * record. 10198227SNeil.Perrin@Sun.COM * 10208227SNeil.Perrin@Sun.COM * But when we are in ziltest mode, we advance the "open 10218227SNeil.Perrin@Sun.COM * txg" without actually spa_sync()-ing the changes to 10228227SNeil.Perrin@Sun.COM * disk. So we would see that object N is still 10238227SNeil.Perrin@Sun.COM * allocated and in the unlinked set, and there is an 10248227SNeil.Perrin@Sun.COM * intent log record saying to allocate it. 10258227SNeil.Perrin@Sun.COM */ 10268227SNeil.Perrin@Sun.COM zfsvfs->z_replay = B_TRUE; 10278227SNeil.Perrin@Sun.COM zil_replay(zfsvfs->z_os, zfsvfs, zfs_replay_vector); 10288227SNeil.Perrin@Sun.COM zfsvfs->z_replay = B_FALSE; 10298227SNeil.Perrin@Sun.COM } 10305326Sek110237 zfsvfs->z_vfs->vfs_flag |= readonly; /* restore readonly bit */ 10315326Sek110237 } 10325326Sek110237 10335326Sek110237 return (0); 10345326Sek110237 } 10355326Sek110237 1036*9396SMatthew.Ahrens@Sun.COM void 1037*9396SMatthew.Ahrens@Sun.COM zfsvfs_free(zfsvfs_t *zfsvfs) 10386083Sek110237 { 1039*9396SMatthew.Ahrens@Sun.COM int i; 1040*9396SMatthew.Ahrens@Sun.COM 1041*9396SMatthew.Ahrens@Sun.COM zfs_fuid_destroy(zfsvfs); 1042*9396SMatthew.Ahrens@Sun.COM 10436083Sek110237 mutex_destroy(&zfsvfs->z_znodes_lock); 10446083Sek110237 mutex_destroy(&zfsvfs->z_online_recv_lock); 10459030SMark.Shellenbaum@Sun.COM mutex_destroy(&zfsvfs->z_lock); 10466083Sek110237 list_destroy(&zfsvfs->z_all_znodes); 10476083Sek110237 rrw_destroy(&zfsvfs->z_teardown_lock); 10486083Sek110237 rw_destroy(&zfsvfs->z_teardown_inactive_lock); 10496083Sek110237 rw_destroy(&zfsvfs->z_fuid_lock); 1050*9396SMatthew.Ahrens@Sun.COM for (i = 0; i != ZFS_OBJ_MTX_SZ; i++) 1051*9396SMatthew.Ahrens@Sun.COM mutex_destroy(&zfsvfs->z_hold_mtx[i]); 10526083Sek110237 kmem_free(zfsvfs, sizeof (zfsvfs_t)); 10536083Sek110237 } 10546083Sek110237 1055*9396SMatthew.Ahrens@Sun.COM static void 1056*9396SMatthew.Ahrens@Sun.COM zfs_set_fuid_feature(zfsvfs_t *zfsvfs) 1057*9396SMatthew.Ahrens@Sun.COM { 1058*9396SMatthew.Ahrens@Sun.COM zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os); 1059*9396SMatthew.Ahrens@Sun.COM if (zfsvfs->z_use_fuids && zfsvfs->z_vfs) { 1060*9396SMatthew.Ahrens@Sun.COM vfs_set_feature(zfsvfs->z_vfs, VFSFT_XVATTR); 1061*9396SMatthew.Ahrens@Sun.COM vfs_set_feature(zfsvfs->z_vfs, VFSFT_SYSATTR_VIEWS); 1062*9396SMatthew.Ahrens@Sun.COM vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACEMASKONACCESS); 1063*9396SMatthew.Ahrens@Sun.COM vfs_set_feature(zfsvfs->z_vfs, VFSFT_ACLONCREATE); 1064*9396SMatthew.Ahrens@Sun.COM } 1065*9396SMatthew.Ahrens@Sun.COM } 1066*9396SMatthew.Ahrens@Sun.COM 10675326Sek110237 static int 10687046Sahrens zfs_domount(vfs_t *vfsp, char *osname) 10691544Seschrock { 10701544Seschrock dev_t mount_dev; 1071*9396SMatthew.Ahrens@Sun.COM uint64_t recordsize, fsid_guid; 10721544Seschrock int error = 0; 10731544Seschrock zfsvfs_t *zfsvfs; 10741544Seschrock 10751544Seschrock ASSERT(vfsp); 10761544Seschrock ASSERT(osname); 10771544Seschrock 1078*9396SMatthew.Ahrens@Sun.COM error = zfsvfs_create(osname, DS_MODE_OWNER, &zfsvfs); 1079*9396SMatthew.Ahrens@Sun.COM if (error) 1080*9396SMatthew.Ahrens@Sun.COM return (error); 10811544Seschrock zfsvfs->z_vfs = vfsp; 10821544Seschrock 10831544Seschrock /* Initialize the generic filesystem structure. */ 10841544Seschrock vfsp->vfs_bcount = 0; 10851544Seschrock vfsp->vfs_data = NULL; 10861544Seschrock 10871544Seschrock if (zfs_create_unique_device(&mount_dev) == -1) { 10881544Seschrock error = ENODEV; 10891544Seschrock goto out; 10901544Seschrock } 10911544Seschrock ASSERT(vfs_devismounted(mount_dev) == 0); 10921544Seschrock 10931544Seschrock if (error = dsl_prop_get_integer(osname, "recordsize", &recordsize, 10941544Seschrock NULL)) 10951544Seschrock goto out; 10961544Seschrock 10971544Seschrock vfsp->vfs_dev = mount_dev; 10981544Seschrock vfsp->vfs_fstype = zfsfstype; 10991544Seschrock vfsp->vfs_bsize = recordsize; 11001544Seschrock vfsp->vfs_flag |= VFS_NOTRUNC; 11011544Seschrock vfsp->vfs_data = zfsvfs; 11021544Seschrock 1103*9396SMatthew.Ahrens@Sun.COM /* 1104*9396SMatthew.Ahrens@Sun.COM * The fsid is 64 bits, composed of an 8-bit fs type, which 1105*9396SMatthew.Ahrens@Sun.COM * separates our fsid from any other filesystem types, and a 1106*9396SMatthew.Ahrens@Sun.COM * 56-bit objset unique ID. The objset unique ID is unique to 1107*9396SMatthew.Ahrens@Sun.COM * all objsets open on this system, provided by unique_create(). 1108*9396SMatthew.Ahrens@Sun.COM * The 8-bit fs type must be put in the low bits of fsid[1] 1109*9396SMatthew.Ahrens@Sun.COM * because that's where other Solaris filesystems put it. 1110*9396SMatthew.Ahrens@Sun.COM */ 1111*9396SMatthew.Ahrens@Sun.COM fsid_guid = dmu_objset_fsid_guid(zfsvfs->z_os); 1112*9396SMatthew.Ahrens@Sun.COM ASSERT((fsid_guid & ~((1ULL<<56)-1)) == 0); 1113*9396SMatthew.Ahrens@Sun.COM vfsp->vfs_fsid.val[0] = fsid_guid; 1114*9396SMatthew.Ahrens@Sun.COM vfsp->vfs_fsid.val[1] = ((fsid_guid>>32) << 8) | 1115*9396SMatthew.Ahrens@Sun.COM zfsfstype & 0xFF; 11161544Seschrock 11175331Samw /* 11185331Samw * Set features for file system. 11195331Samw */ 1120*9396SMatthew.Ahrens@Sun.COM zfs_set_fuid_feature(zfsvfs); 11215498Stimh if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE) { 11225498Stimh vfs_set_feature(vfsp, VFSFT_DIRENTFLAGS); 11235498Stimh vfs_set_feature(vfsp, VFSFT_CASEINSENSITIVE); 11245498Stimh vfs_set_feature(vfsp, VFSFT_NOCASESENSITIVE); 11255498Stimh } else if (zfsvfs->z_case == ZFS_CASE_MIXED) { 11265498Stimh vfs_set_feature(vfsp, VFSFT_DIRENTFLAGS); 11275498Stimh vfs_set_feature(vfsp, VFSFT_CASEINSENSITIVE); 11285498Stimh } 11295331Samw 11301544Seschrock if (dmu_objset_is_snapshot(zfsvfs->z_os)) { 11315331Samw uint64_t pval; 11323234Sck153898 11331544Seschrock atime_changed_cb(zfsvfs, B_FALSE); 11341544Seschrock readonly_changed_cb(zfsvfs, B_TRUE); 11355331Samw if (error = dsl_prop_get_integer(osname, "xattr", &pval, NULL)) 11363234Sck153898 goto out; 11375331Samw xattr_changed_cb(zfsvfs, pval); 11381544Seschrock zfsvfs->z_issnap = B_TRUE; 11391544Seschrock } else { 11405326Sek110237 error = zfsvfs_setup(zfsvfs, B_TRUE); 11411544Seschrock } 11421544Seschrock 11431544Seschrock if (!zfsvfs->z_issnap) 11441544Seschrock zfsctl_create(zfsvfs); 11451544Seschrock out: 11461544Seschrock if (error) { 1147*9396SMatthew.Ahrens@Sun.COM dmu_objset_close(zfsvfs->z_os); 1148*9396SMatthew.Ahrens@Sun.COM zfsvfs_free(zfsvfs); 11491544Seschrock } else { 11501544Seschrock atomic_add_32(&zfs_active_fs_count, 1); 11511544Seschrock } 11521544Seschrock 11531544Seschrock return (error); 11541544Seschrock } 11551544Seschrock 11561544Seschrock void 11571544Seschrock zfs_unregister_callbacks(zfsvfs_t *zfsvfs) 11581544Seschrock { 11591544Seschrock objset_t *os = zfsvfs->z_os; 11601544Seschrock struct dsl_dataset *ds; 11611544Seschrock 11621544Seschrock /* 11631544Seschrock * Unregister properties. 11641544Seschrock */ 11651544Seschrock if (!dmu_objset_is_snapshot(os)) { 11661544Seschrock ds = dmu_objset_ds(os); 11671544Seschrock VERIFY(dsl_prop_unregister(ds, "atime", atime_changed_cb, 11681544Seschrock zfsvfs) == 0); 11691544Seschrock 11703234Sck153898 VERIFY(dsl_prop_unregister(ds, "xattr", xattr_changed_cb, 11713234Sck153898 zfsvfs) == 0); 11723234Sck153898 11731544Seschrock VERIFY(dsl_prop_unregister(ds, "recordsize", blksz_changed_cb, 11741544Seschrock zfsvfs) == 0); 11751544Seschrock 11761544Seschrock VERIFY(dsl_prop_unregister(ds, "readonly", readonly_changed_cb, 11771544Seschrock zfsvfs) == 0); 11781544Seschrock 11791544Seschrock VERIFY(dsl_prop_unregister(ds, "devices", devices_changed_cb, 11801544Seschrock zfsvfs) == 0); 11811544Seschrock 11821544Seschrock VERIFY(dsl_prop_unregister(ds, "setuid", setuid_changed_cb, 11831544Seschrock zfsvfs) == 0); 11841544Seschrock 11851544Seschrock VERIFY(dsl_prop_unregister(ds, "exec", exec_changed_cb, 11861544Seschrock zfsvfs) == 0); 11871544Seschrock 11881544Seschrock VERIFY(dsl_prop_unregister(ds, "snapdir", snapdir_changed_cb, 11891544Seschrock zfsvfs) == 0); 11901544Seschrock 11911544Seschrock VERIFY(dsl_prop_unregister(ds, "aclmode", acl_mode_changed_cb, 11921544Seschrock zfsvfs) == 0); 11931544Seschrock 11941544Seschrock VERIFY(dsl_prop_unregister(ds, "aclinherit", 11951544Seschrock acl_inherit_changed_cb, zfsvfs) == 0); 11965331Samw 11975331Samw VERIFY(dsl_prop_unregister(ds, "vscan", 11985331Samw vscan_changed_cb, zfsvfs) == 0); 11991544Seschrock } 12001544Seschrock } 12011544Seschrock 12023912Slling /* 12033912Slling * Convert a decimal digit string to a uint64_t integer. 12043912Slling */ 12053912Slling static int 12063912Slling str_to_uint64(char *str, uint64_t *objnum) 12073912Slling { 12083912Slling uint64_t num = 0; 12093912Slling 12103912Slling while (*str) { 12113912Slling if (*str < '0' || *str > '9') 12123912Slling return (EINVAL); 12133912Slling 12143912Slling num = num*10 + *str++ - '0'; 12153912Slling } 12163912Slling 12173912Slling *objnum = num; 12183912Slling return (0); 12193912Slling } 12203912Slling 12213912Slling /* 12223912Slling * The boot path passed from the boot loader is in the form of 12233912Slling * "rootpool-name/root-filesystem-object-number'. Convert this 12243912Slling * string to a dataset name: "rootpool-name/root-filesystem-name". 12253912Slling */ 12263912Slling static int 12276423Sgw25295 zfs_parse_bootfs(char *bpath, char *outpath) 12283912Slling { 12293912Slling char *slashp; 12303912Slling uint64_t objnum; 12313912Slling int error; 12323912Slling 12333912Slling if (*bpath == 0 || *bpath == '/') 12343912Slling return (EINVAL); 12353912Slling 12367656SSherry.Moore@Sun.COM (void) strcpy(outpath, bpath); 12377656SSherry.Moore@Sun.COM 12383912Slling slashp = strchr(bpath, '/'); 12393912Slling 12403912Slling /* if no '/', just return the pool name */ 12413912Slling if (slashp == NULL) { 12423912Slling return (0); 12433912Slling } 12443912Slling 12457656SSherry.Moore@Sun.COM /* if not a number, just return the root dataset name */ 12467656SSherry.Moore@Sun.COM if (str_to_uint64(slashp+1, &objnum)) { 12477656SSherry.Moore@Sun.COM return (0); 12487656SSherry.Moore@Sun.COM } 12493912Slling 12503912Slling *slashp = '\0'; 12513912Slling error = dsl_dsobj_to_dsname(bpath, objnum, outpath); 12523912Slling *slashp = '/'; 12533912Slling 12543912Slling return (error); 12553912Slling } 12563912Slling 12571544Seschrock static int 12581544Seschrock zfs_mountroot(vfs_t *vfsp, enum whymountroot why) 12591544Seschrock { 12601544Seschrock int error = 0; 12611544Seschrock static int zfsrootdone = 0; 12621544Seschrock zfsvfs_t *zfsvfs = NULL; 12631544Seschrock znode_t *zp = NULL; 12641544Seschrock vnode_t *vp = NULL; 12656423Sgw25295 char *zfs_bootfs; 12667147Staylor char *zfs_devid; 12671544Seschrock 12681544Seschrock ASSERT(vfsp); 12691544Seschrock 12701544Seschrock /* 12713912Slling * The filesystem that we mount as root is defined in the 12726423Sgw25295 * boot property "zfs-bootfs" with a format of 12736423Sgw25295 * "poolname/root-dataset-objnum". 12741544Seschrock */ 12751544Seschrock if (why == ROOT_INIT) { 12761544Seschrock if (zfsrootdone++) 12771544Seschrock return (EBUSY); 12786423Sgw25295 /* 12796423Sgw25295 * the process of doing a spa_load will require the 12806423Sgw25295 * clock to be set before we could (for example) do 12816423Sgw25295 * something better by looking at the timestamp on 12826423Sgw25295 * an uberblock, so just set it to -1. 12836423Sgw25295 */ 12846423Sgw25295 clkset(-1); 12851544Seschrock 12867147Staylor if ((zfs_bootfs = spa_get_bootprop("zfs-bootfs")) == NULL) { 12877147Staylor cmn_err(CE_NOTE, "spa_get_bootfs: can not get " 12887147Staylor "bootfs name"); 12896423Sgw25295 return (EINVAL); 12905648Ssetje } 12917147Staylor zfs_devid = spa_get_bootprop("diskdevid"); 12927147Staylor error = spa_import_rootpool(rootfs.bo_name, zfs_devid); 12937147Staylor if (zfs_devid) 12947147Staylor spa_free_bootprop(zfs_devid); 12957147Staylor if (error) { 12967147Staylor spa_free_bootprop(zfs_bootfs); 12977147Staylor cmn_err(CE_NOTE, "spa_import_rootpool: error %d", 12987147Staylor error); 12997147Staylor return (error); 13007147Staylor } 13017147Staylor if (error = zfs_parse_bootfs(zfs_bootfs, rootfs.bo_name)) { 13027147Staylor spa_free_bootprop(zfs_bootfs); 13037147Staylor cmn_err(CE_NOTE, "zfs_parse_bootfs: error %d", 13046423Sgw25295 error); 13056423Sgw25295 return (error); 13066423Sgw25295 } 13073912Slling 13087147Staylor spa_free_bootprop(zfs_bootfs); 13091544Seschrock 13101544Seschrock if (error = vfs_lock(vfsp)) 13111544Seschrock return (error); 13121544Seschrock 13137046Sahrens if (error = zfs_domount(vfsp, rootfs.bo_name)) { 13147147Staylor cmn_err(CE_NOTE, "zfs_domount: error %d", error); 13151544Seschrock goto out; 13166423Sgw25295 } 13171544Seschrock 13181544Seschrock zfsvfs = (zfsvfs_t *)vfsp->vfs_data; 13191544Seschrock ASSERT(zfsvfs); 13206423Sgw25295 if (error = zfs_zget(zfsvfs, zfsvfs->z_root, &zp)) { 13217147Staylor cmn_err(CE_NOTE, "zfs_zget: error %d", error); 13221544Seschrock goto out; 13236423Sgw25295 } 13241544Seschrock 13251544Seschrock vp = ZTOV(zp); 13261544Seschrock mutex_enter(&vp->v_lock); 13271544Seschrock vp->v_flag |= VROOT; 13281544Seschrock mutex_exit(&vp->v_lock); 13291544Seschrock rootvp = vp; 13301544Seschrock 13311544Seschrock /* 13326570Smarks * Leave rootvp held. The root file system is never unmounted. 13331544Seschrock */ 13341544Seschrock 13351544Seschrock vfs_add((struct vnode *)0, vfsp, 13361544Seschrock (vfsp->vfs_flag & VFS_RDONLY) ? MS_RDONLY : 0); 13371544Seschrock out: 13381544Seschrock vfs_unlock(vfsp); 13396423Sgw25295 return (error); 13401544Seschrock } else if (why == ROOT_REMOUNT) { 13411544Seschrock readonly_changed_cb(vfsp->vfs_data, B_FALSE); 13421544Seschrock vfsp->vfs_flag |= VFS_REMOUNT; 13434596Slling 13444596Slling /* refresh mount options */ 13454596Slling zfs_unregister_callbacks(vfsp->vfs_data); 13464596Slling return (zfs_register_callbacks(vfsp)); 13474596Slling 13481544Seschrock } else if (why == ROOT_UNMOUNT) { 13491544Seschrock zfs_unregister_callbacks((zfsvfs_t *)vfsp->vfs_data); 13501544Seschrock (void) zfs_sync(vfsp, 0, 0); 13511544Seschrock return (0); 13521544Seschrock } 13531544Seschrock 13541544Seschrock /* 13551544Seschrock * if "why" is equal to anything else other than ROOT_INIT, 13561544Seschrock * ROOT_REMOUNT, or ROOT_UNMOUNT, we do not support it. 13571544Seschrock */ 13581544Seschrock return (ENOTSUP); 13591544Seschrock } 13601544Seschrock 1361789Sahrens /*ARGSUSED*/ 1362789Sahrens static int 1363789Sahrens zfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr) 1364789Sahrens { 1365789Sahrens char *osname; 1366789Sahrens pathname_t spn; 1367789Sahrens int error = 0; 1368789Sahrens uio_seg_t fromspace = (uap->flags & MS_SYSSPACE) ? 13693912Slling UIO_SYSSPACE : UIO_USERSPACE; 1370789Sahrens int canwrite; 1371789Sahrens 1372789Sahrens if (mvp->v_type != VDIR) 1373789Sahrens return (ENOTDIR); 1374789Sahrens 1375789Sahrens mutex_enter(&mvp->v_lock); 1376789Sahrens if ((uap->flags & MS_REMOUNT) == 0 && 1377789Sahrens (uap->flags & MS_OVERLAY) == 0 && 1378789Sahrens (mvp->v_count != 1 || (mvp->v_flag & VROOT))) { 1379789Sahrens mutex_exit(&mvp->v_lock); 1380789Sahrens return (EBUSY); 1381789Sahrens } 1382789Sahrens mutex_exit(&mvp->v_lock); 1383789Sahrens 1384789Sahrens /* 1385789Sahrens * ZFS does not support passing unparsed data in via MS_DATA. 1386789Sahrens * Users should use the MS_OPTIONSTR interface; this means 1387789Sahrens * that all option parsing is already done and the options struct 1388789Sahrens * can be interrogated. 1389789Sahrens */ 1390789Sahrens if ((uap->flags & MS_DATA) && uap->datalen > 0) 1391789Sahrens return (EINVAL); 1392789Sahrens 1393789Sahrens /* 1394789Sahrens * Get the objset name (the "special" mount argument). 1395789Sahrens */ 1396789Sahrens if (error = pn_get(uap->spec, fromspace, &spn)) 1397789Sahrens return (error); 1398789Sahrens 1399789Sahrens osname = spn.pn_path; 1400789Sahrens 14014543Smarks /* 14024543Smarks * Check for mount privilege? 14034543Smarks * 14044543Smarks * If we don't have privilege then see if 14054543Smarks * we have local permission to allow it 14064543Smarks */ 14074543Smarks error = secpolicy_fs_mount(cr, mvp, vfsp); 14084543Smarks if (error) { 14094543Smarks error = dsl_deleg_access(osname, ZFS_DELEG_PERM_MOUNT, cr); 14104543Smarks if (error == 0) { 14114543Smarks vattr_t vattr; 14124543Smarks 14134543Smarks /* 14144543Smarks * Make sure user is the owner of the mount point 14154543Smarks * or has sufficient privileges. 14164543Smarks */ 14174543Smarks 14184543Smarks vattr.va_mask = AT_UID; 14194543Smarks 14205331Samw if (error = VOP_GETATTR(mvp, &vattr, 0, cr, NULL)) { 14214543Smarks goto out; 14224543Smarks } 14234543Smarks 14245489Smarks if (secpolicy_vnode_owner(cr, vattr.va_uid) != 0 && 14255489Smarks VOP_ACCESS(mvp, VWRITE, 0, cr, NULL) != 0) { 14265489Smarks error = EPERM; 14274543Smarks goto out; 14284543Smarks } 14294543Smarks 14304543Smarks secpolicy_fs_mount_clearopts(cr, vfsp); 14314543Smarks } else { 14324543Smarks goto out; 14334543Smarks } 14344543Smarks } 1435789Sahrens 1436789Sahrens /* 1437789Sahrens * Refuse to mount a filesystem if we are in a local zone and the 1438789Sahrens * dataset is not visible. 1439789Sahrens */ 1440789Sahrens if (!INGLOBALZONE(curproc) && 1441789Sahrens (!zone_dataset_visible(osname, &canwrite) || !canwrite)) { 1442789Sahrens error = EPERM; 1443789Sahrens goto out; 1444789Sahrens } 1445789Sahrens 14464596Slling /* 14474596Slling * When doing a remount, we simply refresh our temporary properties 14484596Slling * according to those options set in the current VFS options. 14494596Slling */ 14504596Slling if (uap->flags & MS_REMOUNT) { 14514596Slling /* refresh mount options */ 14524596Slling zfs_unregister_callbacks(vfsp->vfs_data); 14534596Slling error = zfs_register_callbacks(vfsp); 14544596Slling goto out; 14554596Slling } 14564596Slling 14577046Sahrens error = zfs_domount(vfsp, osname); 1458789Sahrens 14599214Schris.kirby@sun.com /* 14609214Schris.kirby@sun.com * Add an extra VFS_HOLD on our parent vfs so that it can't 14619214Schris.kirby@sun.com * disappear due to a forced unmount. 14629214Schris.kirby@sun.com */ 14639246Schris.kirby@sun.com if (error == 0 && ((zfsvfs_t *)vfsp->vfs_data)->z_issnap) 14649214Schris.kirby@sun.com VFS_HOLD(mvp->v_vfsp); 14659214Schris.kirby@sun.com 1466789Sahrens out: 1467789Sahrens pn_free(&spn); 1468789Sahrens return (error); 1469789Sahrens } 1470789Sahrens 1471789Sahrens static int 1472789Sahrens zfs_statvfs(vfs_t *vfsp, struct statvfs64 *statp) 1473789Sahrens { 1474789Sahrens zfsvfs_t *zfsvfs = vfsp->vfs_data; 1475789Sahrens dev32_t d32; 14762885Sahrens uint64_t refdbytes, availbytes, usedobjs, availobjs; 1477789Sahrens 1478789Sahrens ZFS_ENTER(zfsvfs); 1479789Sahrens 14802885Sahrens dmu_objset_space(zfsvfs->z_os, 14812885Sahrens &refdbytes, &availbytes, &usedobjs, &availobjs); 1482789Sahrens 1483789Sahrens /* 1484789Sahrens * The underlying storage pool actually uses multiple block sizes. 1485789Sahrens * We report the fragsize as the smallest block size we support, 1486789Sahrens * and we report our blocksize as the filesystem's maximum blocksize. 1487789Sahrens */ 1488789Sahrens statp->f_frsize = 1UL << SPA_MINBLOCKSHIFT; 1489789Sahrens statp->f_bsize = zfsvfs->z_max_blksz; 1490789Sahrens 1491789Sahrens /* 1492789Sahrens * The following report "total" blocks of various kinds in the 1493789Sahrens * file system, but reported in terms of f_frsize - the 1494789Sahrens * "fragment" size. 1495789Sahrens */ 1496789Sahrens 14972885Sahrens statp->f_blocks = (refdbytes + availbytes) >> SPA_MINBLOCKSHIFT; 14982885Sahrens statp->f_bfree = availbytes >> SPA_MINBLOCKSHIFT; 1499789Sahrens statp->f_bavail = statp->f_bfree; /* no root reservation */ 1500789Sahrens 1501789Sahrens /* 1502789Sahrens * statvfs() should really be called statufs(), because it assumes 1503789Sahrens * static metadata. ZFS doesn't preallocate files, so the best 1504789Sahrens * we can do is report the max that could possibly fit in f_files, 1505789Sahrens * and that minus the number actually used in f_ffree. 1506789Sahrens * For f_ffree, report the smaller of the number of object available 1507789Sahrens * and the number of blocks (each object will take at least a block). 1508789Sahrens */ 15092885Sahrens statp->f_ffree = MIN(availobjs, statp->f_bfree); 1510789Sahrens statp->f_favail = statp->f_ffree; /* no "root reservation" */ 15112885Sahrens statp->f_files = statp->f_ffree + usedobjs; 1512789Sahrens 1513789Sahrens (void) cmpldev(&d32, vfsp->vfs_dev); 1514789Sahrens statp->f_fsid = d32; 1515789Sahrens 1516789Sahrens /* 1517789Sahrens * We're a zfs filesystem. 1518789Sahrens */ 1519789Sahrens (void) strcpy(statp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name); 1520789Sahrens 15211123Smarks statp->f_flag = vf_to_stf(vfsp->vfs_flag); 1522789Sahrens 1523789Sahrens statp->f_namemax = ZFS_MAXNAMELEN; 1524789Sahrens 1525789Sahrens /* 1526789Sahrens * We have all of 32 characters to stuff a string here. 1527789Sahrens * Is there anything useful we could/should provide? 1528789Sahrens */ 1529789Sahrens bzero(statp->f_fstr, sizeof (statp->f_fstr)); 1530789Sahrens 1531789Sahrens ZFS_EXIT(zfsvfs); 1532789Sahrens return (0); 1533789Sahrens } 1534789Sahrens 1535789Sahrens static int 1536789Sahrens zfs_root(vfs_t *vfsp, vnode_t **vpp) 1537789Sahrens { 1538789Sahrens zfsvfs_t *zfsvfs = vfsp->vfs_data; 1539789Sahrens znode_t *rootzp; 1540789Sahrens int error; 1541789Sahrens 1542789Sahrens ZFS_ENTER(zfsvfs); 1543789Sahrens 1544789Sahrens error = zfs_zget(zfsvfs, zfsvfs->z_root, &rootzp); 1545789Sahrens if (error == 0) 1546789Sahrens *vpp = ZTOV(rootzp); 1547789Sahrens 1548789Sahrens ZFS_EXIT(zfsvfs); 1549789Sahrens return (error); 1550789Sahrens } 1551789Sahrens 15525326Sek110237 /* 15535326Sek110237 * Teardown the zfsvfs::z_os. 15545326Sek110237 * 15555326Sek110237 * Note, if 'unmounting' if FALSE, we return with the 'z_teardown_lock' 15565326Sek110237 * and 'z_teardown_inactive_lock' held. 15575326Sek110237 */ 15585326Sek110237 static int 15595326Sek110237 zfsvfs_teardown(zfsvfs_t *zfsvfs, boolean_t unmounting) 15605326Sek110237 { 15615642Smaybee znode_t *zp; 15625326Sek110237 15635326Sek110237 rrw_enter(&zfsvfs->z_teardown_lock, RW_WRITER, FTAG); 15645326Sek110237 15655326Sek110237 if (!unmounting) { 15665326Sek110237 /* 15675326Sek110237 * We purge the parent filesystem's vfsp as the parent 15685326Sek110237 * filesystem and all of its snapshots have their vnode's 15695326Sek110237 * v_vfsp set to the parent's filesystem's vfsp. Note, 15705326Sek110237 * 'z_parent' is self referential for non-snapshots. 15715326Sek110237 */ 15725326Sek110237 (void) dnlc_purge_vfsp(zfsvfs->z_parent->z_vfs, 0); 15735326Sek110237 } 15745326Sek110237 15755326Sek110237 /* 15765326Sek110237 * Close the zil. NB: Can't close the zil while zfs_inactive 15775326Sek110237 * threads are blocked as zil_close can call zfs_inactive. 15785326Sek110237 */ 15795326Sek110237 if (zfsvfs->z_log) { 15805326Sek110237 zil_close(zfsvfs->z_log); 15815326Sek110237 zfsvfs->z_log = NULL; 15825326Sek110237 } 15835326Sek110237 15845326Sek110237 rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_WRITER); 15855326Sek110237 15865326Sek110237 /* 15875326Sek110237 * If we are not unmounting (ie: online recv) and someone already 15885326Sek110237 * unmounted this file system while we were doing the switcheroo, 15895326Sek110237 * or a reopen of z_os failed then just bail out now. 15905326Sek110237 */ 15915326Sek110237 if (!unmounting && (zfsvfs->z_unmounted || zfsvfs->z_os == NULL)) { 15925326Sek110237 rw_exit(&zfsvfs->z_teardown_inactive_lock); 15935326Sek110237 rrw_exit(&zfsvfs->z_teardown_lock, FTAG); 15945326Sek110237 return (EIO); 15955326Sek110237 } 15965326Sek110237 15975326Sek110237 /* 15985326Sek110237 * At this point there are no vops active, and any new vops will 15995326Sek110237 * fail with EIO since we have z_teardown_lock for writer (only 16005326Sek110237 * relavent for forced unmount). 16015326Sek110237 * 16025326Sek110237 * Release all holds on dbufs. 16035326Sek110237 */ 16045326Sek110237 mutex_enter(&zfsvfs->z_znodes_lock); 16055642Smaybee for (zp = list_head(&zfsvfs->z_all_znodes); zp != NULL; 16065642Smaybee zp = list_next(&zfsvfs->z_all_znodes, zp)) 16075446Sahrens if (zp->z_dbuf) { 16085642Smaybee ASSERT(ZTOV(zp)->v_count > 0); 16095642Smaybee zfs_znode_dmu_fini(zp); 16105326Sek110237 } 16115326Sek110237 mutex_exit(&zfsvfs->z_znodes_lock); 16125326Sek110237 16135326Sek110237 /* 16145326Sek110237 * If we are unmounting, set the unmounted flag and let new vops 16155326Sek110237 * unblock. zfs_inactive will have the unmounted behavior, and all 16165326Sek110237 * other vops will fail with EIO. 16175326Sek110237 */ 16185326Sek110237 if (unmounting) { 16195326Sek110237 zfsvfs->z_unmounted = B_TRUE; 16205326Sek110237 rrw_exit(&zfsvfs->z_teardown_lock, FTAG); 16215326Sek110237 rw_exit(&zfsvfs->z_teardown_inactive_lock); 16225326Sek110237 } 16235326Sek110237 16245326Sek110237 /* 16255326Sek110237 * z_os will be NULL if there was an error in attempting to reopen 16265326Sek110237 * zfsvfs, so just return as the properties had already been 16275326Sek110237 * unregistered and cached data had been evicted before. 16285326Sek110237 */ 16295326Sek110237 if (zfsvfs->z_os == NULL) 16305326Sek110237 return (0); 16315326Sek110237 16325326Sek110237 /* 16335326Sek110237 * Unregister properties. 16345326Sek110237 */ 16355326Sek110237 zfs_unregister_callbacks(zfsvfs); 16365326Sek110237 16375326Sek110237 /* 16385326Sek110237 * Evict cached data 16395326Sek110237 */ 16406083Sek110237 if (dmu_objset_evict_dbufs(zfsvfs->z_os)) { 16415429Smaybee txg_wait_synced(dmu_objset_pool(zfsvfs->z_os), 0); 16426083Sek110237 (void) dmu_objset_evict_dbufs(zfsvfs->z_os); 16435429Smaybee } 16445326Sek110237 16455326Sek110237 return (0); 16465326Sek110237 } 16475326Sek110237 1648789Sahrens /*ARGSUSED*/ 1649789Sahrens static int 1650789Sahrens zfs_umount(vfs_t *vfsp, int fflag, cred_t *cr) 1651789Sahrens { 1652789Sahrens zfsvfs_t *zfsvfs = vfsp->vfs_data; 16535326Sek110237 objset_t *os; 1654789Sahrens int ret; 1655789Sahrens 16564543Smarks ret = secpolicy_fs_unmount(cr, vfsp); 16574543Smarks if (ret) { 16584543Smarks ret = dsl_deleg_access((char *)refstr_value(vfsp->vfs_resource), 16594543Smarks ZFS_DELEG_PERM_MOUNT, cr); 16604543Smarks if (ret) 16614543Smarks return (ret); 16624543Smarks } 16631484Sek110237 16644736Sek110237 /* 16654736Sek110237 * We purge the parent filesystem's vfsp as the parent filesystem 16664736Sek110237 * and all of its snapshots have their vnode's v_vfsp set to the 16674736Sek110237 * parent's filesystem's vfsp. Note, 'z_parent' is self 16684736Sek110237 * referential for non-snapshots. 16694736Sek110237 */ 16704736Sek110237 (void) dnlc_purge_vfsp(zfsvfs->z_parent->z_vfs, 0); 16711484Sek110237 1672789Sahrens /* 1673789Sahrens * Unmount any snapshots mounted under .zfs before unmounting the 1674789Sahrens * dataset itself. 1675789Sahrens */ 1676789Sahrens if (zfsvfs->z_ctldir != NULL && 16774543Smarks (ret = zfsctl_umount_snapshots(vfsp, fflag, cr)) != 0) { 1678789Sahrens return (ret); 16794543Smarks } 1680789Sahrens 16814787Sahrens if (!(fflag & MS_FORCE)) { 16824480Sgw25295 /* 16834787Sahrens * Check the number of active vnodes in the file system. 16844787Sahrens * Our count is maintained in the vfs structure, but the 16854787Sahrens * number is off by 1 to indicate a hold on the vfs 16864787Sahrens * structure itself. 16874787Sahrens * 16884787Sahrens * The '.zfs' directory maintains a reference of its 16894787Sahrens * own, and any active references underneath are 16904787Sahrens * reflected in the vnode count. 1691789Sahrens */ 16924787Sahrens if (zfsvfs->z_ctldir == NULL) { 16934787Sahrens if (vfsp->vfs_count > 1) 16944787Sahrens return (EBUSY); 16954787Sahrens } else { 16964787Sahrens if (vfsp->vfs_count > 2 || 16975326Sek110237 zfsvfs->z_ctldir->v_count > 1) 16984787Sahrens return (EBUSY); 1699789Sahrens } 1700789Sahrens } 1701789Sahrens 1702789Sahrens vfsp->vfs_flag |= VFS_UNMOUNTED; 17034787Sahrens 17045326Sek110237 VERIFY(zfsvfs_teardown(zfsvfs, B_TRUE) == 0); 17055326Sek110237 os = zfsvfs->z_os; 17064787Sahrens 17074787Sahrens /* 17085326Sek110237 * z_os will be NULL if there was an error in 17095326Sek110237 * attempting to reopen zfsvfs. 17104787Sahrens */ 17115326Sek110237 if (os != NULL) { 17125326Sek110237 /* 17135326Sek110237 * Unset the objset user_ptr. 17145326Sek110237 */ 17155326Sek110237 mutex_enter(&os->os->os_user_ptr_lock); 17165326Sek110237 dmu_objset_set_user(os, NULL); 17175326Sek110237 mutex_exit(&os->os->os_user_ptr_lock); 17184787Sahrens 17195326Sek110237 /* 17206689Smaybee * Finally release the objset 17215326Sek110237 */ 17225326Sek110237 dmu_objset_close(os); 17234787Sahrens } 17244787Sahrens 17254787Sahrens /* 17264787Sahrens * We can now safely destroy the '.zfs' directory node. 17274787Sahrens */ 17284787Sahrens if (zfsvfs->z_ctldir != NULL) 17294787Sahrens zfsctl_destroy(zfsvfs); 1730789Sahrens 1731789Sahrens return (0); 1732789Sahrens } 1733789Sahrens 1734789Sahrens static int 1735789Sahrens zfs_vget(vfs_t *vfsp, vnode_t **vpp, fid_t *fidp) 1736789Sahrens { 1737789Sahrens zfsvfs_t *zfsvfs = vfsp->vfs_data; 1738789Sahrens znode_t *zp; 1739789Sahrens uint64_t object = 0; 1740789Sahrens uint64_t fid_gen = 0; 1741789Sahrens uint64_t gen_mask; 1742789Sahrens uint64_t zp_gen; 1743789Sahrens int i, err; 1744789Sahrens 1745789Sahrens *vpp = NULL; 1746789Sahrens 1747789Sahrens ZFS_ENTER(zfsvfs); 1748789Sahrens 1749789Sahrens if (fidp->fid_len == LONG_FID_LEN) { 1750789Sahrens zfid_long_t *zlfid = (zfid_long_t *)fidp; 1751789Sahrens uint64_t objsetid = 0; 1752789Sahrens uint64_t setgen = 0; 1753789Sahrens 1754789Sahrens for (i = 0; i < sizeof (zlfid->zf_setid); i++) 1755789Sahrens objsetid |= ((uint64_t)zlfid->zf_setid[i]) << (8 * i); 1756789Sahrens 1757789Sahrens for (i = 0; i < sizeof (zlfid->zf_setgen); i++) 1758789Sahrens setgen |= ((uint64_t)zlfid->zf_setgen[i]) << (8 * i); 1759789Sahrens 1760789Sahrens ZFS_EXIT(zfsvfs); 1761789Sahrens 1762789Sahrens err = zfsctl_lookup_objset(vfsp, objsetid, &zfsvfs); 1763789Sahrens if (err) 1764789Sahrens return (EINVAL); 1765789Sahrens ZFS_ENTER(zfsvfs); 1766789Sahrens } 1767789Sahrens 1768789Sahrens if (fidp->fid_len == SHORT_FID_LEN || fidp->fid_len == LONG_FID_LEN) { 1769789Sahrens zfid_short_t *zfid = (zfid_short_t *)fidp; 1770789Sahrens 1771789Sahrens for (i = 0; i < sizeof (zfid->zf_object); i++) 1772789Sahrens object |= ((uint64_t)zfid->zf_object[i]) << (8 * i); 1773789Sahrens 1774789Sahrens for (i = 0; i < sizeof (zfid->zf_gen); i++) 1775789Sahrens fid_gen |= ((uint64_t)zfid->zf_gen[i]) << (8 * i); 1776789Sahrens } else { 1777789Sahrens ZFS_EXIT(zfsvfs); 1778789Sahrens return (EINVAL); 1779789Sahrens } 1780789Sahrens 1781789Sahrens /* A zero fid_gen means we are in the .zfs control directories */ 1782789Sahrens if (fid_gen == 0 && 1783789Sahrens (object == ZFSCTL_INO_ROOT || object == ZFSCTL_INO_SNAPDIR)) { 1784789Sahrens *vpp = zfsvfs->z_ctldir; 1785789Sahrens ASSERT(*vpp != NULL); 1786789Sahrens if (object == ZFSCTL_INO_SNAPDIR) { 1787789Sahrens VERIFY(zfsctl_root_lookup(*vpp, "snapshot", vpp, NULL, 17885331Samw 0, NULL, NULL, NULL, NULL, NULL) == 0); 1789789Sahrens } else { 1790789Sahrens VN_HOLD(*vpp); 1791789Sahrens } 1792789Sahrens ZFS_EXIT(zfsvfs); 1793789Sahrens return (0); 1794789Sahrens } 1795789Sahrens 1796789Sahrens gen_mask = -1ULL >> (64 - 8 * i); 1797789Sahrens 1798789Sahrens dprintf("getting %llu [%u mask %llx]\n", object, fid_gen, gen_mask); 1799789Sahrens if (err = zfs_zget(zfsvfs, object, &zp)) { 1800789Sahrens ZFS_EXIT(zfsvfs); 1801789Sahrens return (err); 1802789Sahrens } 1803789Sahrens zp_gen = zp->z_phys->zp_gen & gen_mask; 1804789Sahrens if (zp_gen == 0) 1805789Sahrens zp_gen = 1; 18063461Sahrens if (zp->z_unlinked || zp_gen != fid_gen) { 1807789Sahrens dprintf("znode gen (%u) != fid gen (%u)\n", zp_gen, fid_gen); 1808789Sahrens VN_RELE(ZTOV(zp)); 1809789Sahrens ZFS_EXIT(zfsvfs); 1810789Sahrens return (EINVAL); 1811789Sahrens } 1812789Sahrens 1813789Sahrens *vpp = ZTOV(zp); 1814789Sahrens ZFS_EXIT(zfsvfs); 1815789Sahrens return (0); 1816789Sahrens } 1817789Sahrens 18185326Sek110237 /* 18195326Sek110237 * Block out VOPs and close zfsvfs_t::z_os 18205326Sek110237 * 18215326Sek110237 * Note, if successful, then we return with the 'z_teardown_lock' and 18225326Sek110237 * 'z_teardown_inactive_lock' write held. 18235326Sek110237 */ 18245326Sek110237 int 1825*9396SMatthew.Ahrens@Sun.COM zfs_suspend_fs(zfsvfs_t *zfsvfs, char *name, int *modep) 18265326Sek110237 { 18275326Sek110237 int error; 18285326Sek110237 18295326Sek110237 if ((error = zfsvfs_teardown(zfsvfs, B_FALSE)) != 0) 18305326Sek110237 return (error); 18315326Sek110237 1832*9396SMatthew.Ahrens@Sun.COM *modep = zfsvfs->z_os->os_mode; 1833*9396SMatthew.Ahrens@Sun.COM if (name) 1834*9396SMatthew.Ahrens@Sun.COM dmu_objset_name(zfsvfs->z_os, name); 18355326Sek110237 dmu_objset_close(zfsvfs->z_os); 18365326Sek110237 18375326Sek110237 return (0); 18385326Sek110237 } 18395326Sek110237 18405326Sek110237 /* 18415326Sek110237 * Reopen zfsvfs_t::z_os and release VOPs. 18425326Sek110237 */ 18435326Sek110237 int 18445326Sek110237 zfs_resume_fs(zfsvfs_t *zfsvfs, const char *osname, int mode) 18455326Sek110237 { 18465326Sek110237 int err; 18475326Sek110237 18485326Sek110237 ASSERT(RRW_WRITE_HELD(&zfsvfs->z_teardown_lock)); 18495326Sek110237 ASSERT(RW_WRITE_HELD(&zfsvfs->z_teardown_inactive_lock)); 18505326Sek110237 18515326Sek110237 err = dmu_objset_open(osname, DMU_OST_ZFS, mode, &zfsvfs->z_os); 18525326Sek110237 if (err) { 18535326Sek110237 zfsvfs->z_os = NULL; 18545326Sek110237 } else { 18555326Sek110237 znode_t *zp; 18565326Sek110237 18575326Sek110237 VERIFY(zfsvfs_setup(zfsvfs, B_FALSE) == 0); 18585326Sek110237 18595326Sek110237 /* 18605326Sek110237 * Attempt to re-establish all the active znodes with 18615326Sek110237 * their dbufs. If a zfs_rezget() fails, then we'll let 18625326Sek110237 * any potential callers discover that via ZFS_ENTER_VERIFY_VP 18635326Sek110237 * when they try to use their znode. 18645326Sek110237 */ 18655326Sek110237 mutex_enter(&zfsvfs->z_znodes_lock); 18665326Sek110237 for (zp = list_head(&zfsvfs->z_all_znodes); zp; 18675326Sek110237 zp = list_next(&zfsvfs->z_all_znodes, zp)) { 18685326Sek110237 (void) zfs_rezget(zp); 18695326Sek110237 } 18705326Sek110237 mutex_exit(&zfsvfs->z_znodes_lock); 18715326Sek110237 18725326Sek110237 } 18735326Sek110237 18745326Sek110237 /* release the VOPs */ 18755326Sek110237 rw_exit(&zfsvfs->z_teardown_inactive_lock); 18765326Sek110237 rrw_exit(&zfsvfs->z_teardown_lock, FTAG); 18775326Sek110237 18785326Sek110237 if (err) { 18795326Sek110237 /* 18805326Sek110237 * Since we couldn't reopen zfsvfs::z_os, force 18815326Sek110237 * unmount this file system. 18825326Sek110237 */ 18835326Sek110237 if (vn_vfswlock(zfsvfs->z_vfs->vfs_vnodecovered) == 0) 18845326Sek110237 (void) dounmount(zfsvfs->z_vfs, MS_FORCE, CRED()); 18855326Sek110237 } 18865326Sek110237 return (err); 18875326Sek110237 } 18885326Sek110237 1889789Sahrens static void 1890789Sahrens zfs_freevfs(vfs_t *vfsp) 1891789Sahrens { 1892789Sahrens zfsvfs_t *zfsvfs = vfsp->vfs_data; 18939214Schris.kirby@sun.com 18949214Schris.kirby@sun.com /* 18959214Schris.kirby@sun.com * If this is a snapshot, we have an extra VFS_HOLD on our parent 18969214Schris.kirby@sun.com * from zfs_mount(). Release it here. 18979214Schris.kirby@sun.com */ 18989214Schris.kirby@sun.com if (zfsvfs->z_issnap) 18999214Schris.kirby@sun.com VFS_RELE(zfsvfs->z_parent->z_vfs); 19009214Schris.kirby@sun.com 1901*9396SMatthew.Ahrens@Sun.COM zfsvfs_free(zfsvfs); 1902789Sahrens 1903789Sahrens atomic_add_32(&zfs_active_fs_count, -1); 1904789Sahrens } 1905789Sahrens 1906789Sahrens /* 1907789Sahrens * VFS_INIT() initialization. Note that there is no VFS_FINI(), 1908789Sahrens * so we can't safely do any non-idempotent initialization here. 1909789Sahrens * Leave that to zfs_init() and zfs_fini(), which are called 1910789Sahrens * from the module's _init() and _fini() entry points. 1911789Sahrens */ 1912789Sahrens /*ARGSUSED*/ 1913789Sahrens static int 1914789Sahrens zfs_vfsinit(int fstype, char *name) 1915789Sahrens { 1916789Sahrens int error; 1917789Sahrens 1918789Sahrens zfsfstype = fstype; 1919789Sahrens 1920789Sahrens /* 1921789Sahrens * Setup vfsops and vnodeops tables. 1922789Sahrens */ 1923789Sahrens error = vfs_setfsops(fstype, zfs_vfsops_template, &zfs_vfsops); 1924789Sahrens if (error != 0) { 1925789Sahrens cmn_err(CE_WARN, "zfs: bad vfs ops template"); 1926789Sahrens } 1927789Sahrens 1928789Sahrens error = zfs_create_op_tables(); 1929789Sahrens if (error) { 1930789Sahrens zfs_remove_op_tables(); 1931789Sahrens cmn_err(CE_WARN, "zfs: bad vnode ops template"); 1932789Sahrens (void) vfs_freevfsops_by_type(zfsfstype); 1933789Sahrens return (error); 1934789Sahrens } 1935789Sahrens 1936789Sahrens mutex_init(&zfs_dev_mtx, NULL, MUTEX_DEFAULT, NULL); 1937789Sahrens 1938789Sahrens /* 1939849Sbonwick * Unique major number for all zfs mounts. 1940849Sbonwick * If we run out of 32-bit minors, we'll getudev() another major. 1941789Sahrens */ 1942849Sbonwick zfs_major = ddi_name_to_major(ZFS_DRIVER); 1943849Sbonwick zfs_minor = ZFS_MIN_MINOR; 1944789Sahrens 1945789Sahrens return (0); 1946789Sahrens } 1947789Sahrens 1948789Sahrens void 1949789Sahrens zfs_init(void) 1950789Sahrens { 1951789Sahrens /* 1952789Sahrens * Initialize .zfs directory structures 1953789Sahrens */ 1954789Sahrens zfsctl_init(); 1955789Sahrens 1956789Sahrens /* 1957789Sahrens * Initialize znode cache, vnode ops, etc... 1958789Sahrens */ 1959789Sahrens zfs_znode_init(); 1960*9396SMatthew.Ahrens@Sun.COM 1961*9396SMatthew.Ahrens@Sun.COM dmu_objset_register_type(DMU_OST_ZFS, zfs_space_delta_cb); 1962789Sahrens } 1963789Sahrens 1964789Sahrens void 1965789Sahrens zfs_fini(void) 1966789Sahrens { 1967789Sahrens zfsctl_fini(); 1968789Sahrens zfs_znode_fini(); 1969789Sahrens } 1970789Sahrens 1971789Sahrens int 1972789Sahrens zfs_busy(void) 1973789Sahrens { 1974789Sahrens return (zfs_active_fs_count != 0); 1975789Sahrens } 1976789Sahrens 19774577Sahrens int 1978*9396SMatthew.Ahrens@Sun.COM zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers) 19794577Sahrens { 19804577Sahrens int error; 1981*9396SMatthew.Ahrens@Sun.COM objset_t *os = zfsvfs->z_os; 19824577Sahrens dmu_tx_t *tx; 19834577Sahrens 19844577Sahrens if (newvers < ZPL_VERSION_INITIAL || newvers > ZPL_VERSION) 19854577Sahrens return (EINVAL); 19864577Sahrens 1987*9396SMatthew.Ahrens@Sun.COM if (newvers < zfsvfs->z_version) 1988*9396SMatthew.Ahrens@Sun.COM return (EINVAL); 19894577Sahrens 19904577Sahrens tx = dmu_tx_create(os); 1991*9396SMatthew.Ahrens@Sun.COM dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, B_FALSE, ZPL_VERSION_STR); 19924577Sahrens error = dmu_tx_assign(tx, TXG_WAIT); 19934577Sahrens if (error) { 19944577Sahrens dmu_tx_abort(tx); 1995*9396SMatthew.Ahrens@Sun.COM return (error); 19964577Sahrens } 1997*9396SMatthew.Ahrens@Sun.COM error = zap_update(os, MASTER_NODE_OBJ, ZPL_VERSION_STR, 1998*9396SMatthew.Ahrens@Sun.COM 8, 1, &newvers, tx); 1999*9396SMatthew.Ahrens@Sun.COM 2000*9396SMatthew.Ahrens@Sun.COM if (error) { 2001*9396SMatthew.Ahrens@Sun.COM dmu_tx_commit(tx); 2002*9396SMatthew.Ahrens@Sun.COM return (error); 2003*9396SMatthew.Ahrens@Sun.COM } 20044577Sahrens 20054577Sahrens spa_history_internal_log(LOG_DS_UPGRADE, 20064577Sahrens dmu_objset_spa(os), tx, CRED(), 2007*9396SMatthew.Ahrens@Sun.COM "oldver=%llu newver=%llu dataset = %llu", 2008*9396SMatthew.Ahrens@Sun.COM zfsvfs->z_version, newvers, dmu_objset_id(os)); 2009*9396SMatthew.Ahrens@Sun.COM 20104577Sahrens dmu_tx_commit(tx); 20114577Sahrens 2012*9396SMatthew.Ahrens@Sun.COM zfsvfs->z_version = newvers; 2013*9396SMatthew.Ahrens@Sun.COM 2014*9396SMatthew.Ahrens@Sun.COM if (zfsvfs->z_version >= ZPL_VERSION_FUID) 2015*9396SMatthew.Ahrens@Sun.COM zfs_set_fuid_feature(zfsvfs); 2016*9396SMatthew.Ahrens@Sun.COM 2017*9396SMatthew.Ahrens@Sun.COM return (0); 20184577Sahrens } 20194577Sahrens 20205498Stimh /* 20215498Stimh * Read a property stored within the master node. 20225498Stimh */ 20235498Stimh int 20245498Stimh zfs_get_zplprop(objset_t *os, zfs_prop_t prop, uint64_t *value) 20255498Stimh { 20265498Stimh const char *pname; 20277184Stimh int error = ENOENT; 20285498Stimh 20295498Stimh /* 20305498Stimh * Look up the file system's value for the property. For the 20315498Stimh * version property, we look up a slightly different string. 20325498Stimh */ 20335498Stimh if (prop == ZFS_PROP_VERSION) 20345498Stimh pname = ZPL_VERSION_STR; 20355498Stimh else 20365498Stimh pname = zfs_prop_to_name(prop); 20375498Stimh 20387184Stimh if (os != NULL) 20397184Stimh error = zap_lookup(os, MASTER_NODE_OBJ, pname, 8, 1, value); 20405498Stimh 20416404Smaybee if (error == ENOENT) { 20425498Stimh /* No value set, use the default value */ 20435498Stimh switch (prop) { 20446404Smaybee case ZFS_PROP_VERSION: 20456404Smaybee *value = ZPL_VERSION; 20466404Smaybee break; 20475498Stimh case ZFS_PROP_NORMALIZE: 20485498Stimh case ZFS_PROP_UTF8ONLY: 20495498Stimh *value = 0; 20505498Stimh break; 20515498Stimh case ZFS_PROP_CASE: 20525498Stimh *value = ZFS_CASE_SENSITIVE; 20535498Stimh break; 20545498Stimh default: 20556404Smaybee return (error); 20565498Stimh } 20576404Smaybee error = 0; 20585498Stimh } 20596404Smaybee return (error); 20605498Stimh } 20615498Stimh 2062789Sahrens static vfsdef_t vfw = { 2063789Sahrens VFSDEF_VERSION, 2064789Sahrens MNTTYPE_ZFS, 2065789Sahrens zfs_vfsinit, 20665331Samw VSW_HASPROTO|VSW_CANRWRO|VSW_CANREMOUNT|VSW_VOLATILEDEV|VSW_STATS| 20675331Samw VSW_XID, 2068789Sahrens &zfs_mntopts 2069789Sahrens }; 2070789Sahrens 2071789Sahrens struct modlfs zfs_modlfs = { 20724577Sahrens &mod_fsops, "ZFS filesystem version " SPA_VERSION_STRING, &vfw 2073789Sahrens }; 2074