diff options
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/svc/milestone/fs-minimal | 39 | ||||
-rw-r--r-- | usr/src/cmd/svc/milestone/fs-root | 31 | ||||
-rw-r--r-- | usr/src/cmd/svc/milestone/fs-usr | 58 | ||||
-rw-r--r-- | usr/src/cmd/svc/shell/fs_include.sh | 27 | ||||
-rw-r--r-- | usr/src/cmd/zfs/zfs_main.c | 45 | ||||
-rw-r--r-- | usr/src/common/zfs/zfs_prop.c | 16 | ||||
-rw-r--r-- | usr/src/lib/libzfs/common/libzfs_changelist.c | 12 | ||||
-rw-r--r-- | usr/src/lib/libzfs/common/libzfs_dataset.c | 17 | ||||
-rw-r--r-- | usr/src/lib/libzfs/common/libzfs_mount.c | 7 | ||||
-rw-r--r-- | usr/src/uts/common/sys/fs/zfs.h | 8 |
10 files changed, 202 insertions, 58 deletions
diff --git a/usr/src/cmd/svc/milestone/fs-minimal b/usr/src/cmd/svc/milestone/fs-minimal index d3b09824b1..6a7141fa1a 100644 --- a/usr/src/cmd/svc/milestone/fs-minimal +++ b/usr/src/cmd/svc/milestone/fs-minimal @@ -3,9 +3,8 @@ # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -21,7 +20,7 @@ # CDDL HEADER END # # -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T. @@ -39,6 +38,13 @@ # documentation): /sbin/mountall, /sbin/umountall, and # /lib/svc/bin/svc.startd. +rootiszfs=0 +readmnttab / < /etc/mnttab +if [ "$fstype" = zfs ] ; then + rootiszfs=1 + be=$special +fi + for fs in /var /var/adm /tmp; do readvfstab $fs < $vfstab if [ -n "$mountp" ]; then @@ -46,10 +52,31 @@ for fs in /var /var/adm /tmp; do checkfs $fsckdev $fstype $mountp || exit $SMF_EXIT_ERR_FATAL mountfs -O $mountp $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL + continue + fi + if [ "$rootiszfs" = 1 ]; then + mountpt=`zfs get -H -o value mountpoint $be$fs 2>/dev/null` + if [ $? = 0 ] ; then + if [ "x$mountpt" = "x$fs" ] ; then + /sbin/zfs mount $be$fs + fi + fi fi done -mounted /var/run - tmpfs < /etc/mnttab && exit $SMF_EXIT_OK -mountfs -O /var/run tmpfs - swap || exit $SMF_EXIT_ERR_FATAL +mounted /var/run - tmpfs < /etc/mnttab +if [ $? != 0 ] ; then + mountfs -O /var/run tmpfs - swap || exit $SMF_EXIT_ERR_FATAL +fi + +if [ "$rootiszfs" = 1 ] ; then + /sbin/zfs list -rH -o mountpoint -s mountpoint $be | \ + while read mountp ; do + if [ "x$mountp" != "x" -a "$mountp" != "legacy" ] ; then + mounted $mountp - zfs < /etc/mnttab && continue + /sbin/zfs mount $be$mountp + fi + done +fi exit $SMF_EXIT_OK diff --git a/usr/src/cmd/svc/milestone/fs-root b/usr/src/cmd/svc/milestone/fs-root index cfbe472eb3..baf8c63d06 100644 --- a/usr/src/cmd/svc/milestone/fs-root +++ b/usr/src/cmd/svc/milestone/fs-root @@ -20,7 +20,7 @@ # CDDL HEADER END # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -165,8 +165,9 @@ fi # # Root is already mounted (by the kernel), but still needs to be -# checked, possibly remounted and entered into mnttab. First -# mount /usr read only if it is a separate file system. This must +# checked, possibly remounted and entered into mnttab. First +# mount /usr if it is a separate file system. If the file system +# type is something other than zfs, mount it read-only. This must # be done first to allow utilities such as fsck and setmnt to # reside on /usr minimizing the space required by the root file # system. @@ -198,6 +199,8 @@ if [ -n "$mountp" ]; then esac mountfs - /usr $cfsbacktype ro $special || exit $SMF_EXIT_ERR_FATAL + elif [ "$fstype" = zfs ]; then + mountfs - /usr $fstype $mntopts - || exit $SMF_EXIT_ERR_FATAL else # # Must use -o largefiles here to ensure the @@ -238,6 +241,28 @@ if [ -n "$mountp" ]; then fi # +# if we are booted from zfs, the /usr mount probably won't be a +# legacy mount. Use the standard zfs mount command instead. + +readmnttab "/" < /etc/mnttab +if [ "$fstype" = zfs ]; then + mountp=`/sbin/zfs get -H -o value mountpoint $special/usr 2>/dev/null` + # + # if mountp = /usr, there is a non-legacy mount of /usr + # in the boot environment being booted. + # + if [ "x$mountp" = "x/usr" ] ; then + /sbin/zfs mount $special/usr + if [ $? != 0 ] ; then + msg='zfs-mount failed' + echo $msg + echo "$SMF_FMRI:" $msg >/dev/msglog + exit $SMF_EXIT_ERR_FATAL + fi + fi +fi + +# # Also mount /boot now so that things like keymap.sh can access # boot properties through eeprom. Readonly isn't required because # /boot (and other pcfs filesystems) aren't fsck'ed at boot yet. diff --git a/usr/src/cmd/svc/milestone/fs-usr b/usr/src/cmd/svc/milestone/fs-usr index 6b15820ee4..f4a75e08f9 100644 --- a/usr/src/cmd/svc/milestone/fs-usr +++ b/usr/src/cmd/svc/milestone/fs-usr @@ -37,11 +37,18 @@ # /sbin/swapadd -1 +rootiszfs=0 +# get the fstype of root +readmnttab / </etc/mnttab +if [ "$fstype" = zfs ] ; then + rootiszfs=1 +fi + # # Check and remount the / (root) file system. # For NFS mounts, force the llock option on. # -if smf_is_globalzone; then +if smf_is_globalzone && [ $rootiszfs = 0 ]; then readvfstab / < $vfstab checkfs $fsckdev $fstype $mountp || exit $SMF_EXIT_ERR_FATAL checkopt "llock" $mntopts @@ -63,33 +70,36 @@ fi # # Check and remount the /usr file system (formerly mounted read-only). +# Unless root is zfs, in which case we've already mounted /usr read-write # -readvfstab /usr < $vfstab -if [ "$mountp" ]; then - if [ "$fstype" = cachefs ]; then - mountfs -O $mountp cachefs $mntopts $special || - exit $SMF_EXIT_ERR_FATAL - else - checkopt ro $mntopts - if [ "x$option" != xro ]; then - checkfs $fsckdev $fstype $mountp || +if [ "$rootiszfs" = 0 ] ; then + readvfstab /usr < $vfstab + if [ "$mountp" ]; then + if [ "$fstype" = cachefs ]; then + mountfs -O $mountp cachefs $mntopts $special || exit $SMF_EXIT_ERR_FATAL - if [ "x$mntopts" != x- ]; then - mntopts="remount,$mntopts" - else - mntopts="remount" - fi + else + checkopt ro $mntopts + if [ "x$option" != xro ]; then + checkfs $fsckdev $fstype $mountp || + exit $SMF_EXIT_ERR_FATAL + if [ "x$mntopts" != x- ]; then + mntopts="remount,$mntopts" + else + mntopts="remount" + fi - # if usr dev is a read-only metadevice then fail - case $special in - /dev/md/dsk/*) - dd if=/dev/null of=$special count=0 \ - >/dev/null 2>&1 || exit $SMF_EXIT_ERR_FATAL - ;; - esac + # if usr dev is a read-only metadevice then fail + case $special in + /dev/md/dsk/*) + dd if=/dev/null of=$special count=0 \ + >/dev/null 2>&1 || exit $SMF_EXIT_ERR_FATAL + ;; + esac - mountfs - /usr $fstype $mntopts - || - exit $SMF_EXIT_ERR_FATAL + mountfs - /usr $fstype $mntopts - || + exit $SMF_EXIT_ERR_FATAL + fi fi fi fi diff --git a/usr/src/cmd/svc/shell/fs_include.sh b/usr/src/cmd/svc/shell/fs_include.sh index 55f817efd4..7ab7dfdd3e 100644 --- a/usr/src/cmd/svc/shell/fs_include.sh +++ b/usr/src/cmd/svc/shell/fs_include.sh @@ -20,7 +20,7 @@ # CDDL HEADER END # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T. @@ -72,6 +72,31 @@ readvfstab() { done } +# +# readmnttab mount_point +# -> (special, mountp, fstype, mntopts, mnttime) +# +# A mnttab-like input stream is scanned for the mount point specified +# as $1. Returns the fields of mnttab in the following shell +# variables: +# +# special block device +# mountp mount point (must match $1, if found) +# fstype file system type +# mntopts file system-specific mount options. +# mnttime time at which file system was mounted +# +# If the mount point can not be found in the standard input stream, +# then all fields are set to empty values. This function assumes that +# stdin is already set to /etc/mnttab (or other appropriate input +# stream). +# +readmnttab() { + while read special mountp fstype mntopts mnttime; do + [ "x$mountp" = "x$1" ] && break + done +} + cecho() { echo $* echo $* >/dev/msglog diff --git a/usr/src/cmd/zfs/zfs_main.c b/usr/src/cmd/zfs/zfs_main.c index 97c79faab3..e0e6a42f1b 100644 --- a/usr/src/cmd/zfs/zfs_main.c +++ b/usr/src/cmd/zfs/zfs_main.c @@ -516,6 +516,7 @@ zfs_do_create(int argc, char **argv) char *propname; char *propval = NULL; char *strval; + int canmount; if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) { (void) fprintf(stderr, gettext("internal error: " @@ -673,22 +674,29 @@ zfs_do_create(int argc, char **argv) if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_DATASET)) == NULL) goto error; + /* + * if the user doesn't want the dataset automatically mounted, + * then skip the mount/share step + */ + + canmount = zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT); /* * Mount and/or share the new filesystem as appropriate. We provide a * verbose error message to let the user know that their filesystem was * in fact created, even if we failed to mount or share it. */ - if (zfs_mount(zhp, NULL, 0) != 0) { - (void) fprintf(stderr, gettext("filesystem successfully " - "created, but not mounted\n")); - ret = 1; - } else if (zfs_share(zhp) != 0) { - (void) fprintf(stderr, gettext("filesystem successfully " - "created, but not shared\n")); - ret = 1; - } else { - ret = 0; + ret = 0; + if (canmount == ZFS_CANMOUNT_ON) { + if (zfs_mount(zhp, NULL, 0) != 0) { + (void) fprintf(stderr, gettext("filesystem " + "successfully created, but not mounted\n")); + ret = 1; + } else if (zfs_share(zhp) != 0) { + (void) fprintf(stderr, gettext("filesystem " + "successfully created, but not shared\n")); + ret = 1; + } } error: @@ -3023,7 +3031,16 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol, return (1); } - if (!canmount) { + /* + * canmount explicit outcome + * on no pass through + * on yes pass through + * off no return 0 + * off yes display error, return 1 + * noauto no return 0 + * noauto yes pass through + */ + if (canmount == ZFS_CANMOUNT_OFF) { if (!explicit) return (0); @@ -3031,6 +3048,8 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol, "'canmount' property is set to 'off'\n"), cmdname, zfs_get_name(zhp)); return (1); + } else if (canmount == ZFS_CANMOUNT_NOAUTO && !explicit) { + return (0); } /* @@ -3583,6 +3602,10 @@ unshare_unmount(int op, int argc, char **argv) NULL, NULL, 0, B_FALSE) == 0); if (strcmp(nfsiscsi_mnt_prop, "legacy") == 0) continue; + /* Ignore canmount=noauto mounts */ + if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) == + ZFS_CANMOUNT_NOAUTO) + continue; default: break; } diff --git a/usr/src/common/zfs/zfs_prop.c b/usr/src/common/zfs/zfs_prop.c index 31559b3558..c65f441d89 100644 --- a/usr/src/common/zfs/zfs_prop.c +++ b/usr/src/common/zfs/zfs_prop.c @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -143,6 +143,13 @@ zfs_prop_init(void) { NULL } }; + static zprop_index_t canmount_table[] = { + { "off", ZFS_CANMOUNT_OFF }, + { "on", ZFS_CANMOUNT_ON }, + { "noauto", ZFS_CANMOUNT_NOAUTO }, + { NULL } + }; + /* inherit index properties */ register_index(ZFS_PROP_CHECKSUM, "checksum", ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, @@ -197,10 +204,9 @@ zfs_prop_init(void) register_index(ZFS_PROP_VERSION, "version", 0, PROP_DEFAULT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT, "1 | 2 | 3 | current", "VERSION", version_table); - - /* default index (boolean) properties */ - register_index(ZFS_PROP_CANMOUNT, "canmount", 1, PROP_DEFAULT, - ZFS_TYPE_FILESYSTEM, "on | off", "CANMOUNT", boolean_table); + register_index(ZFS_PROP_CANMOUNT, "canmount", ZFS_CANMOUNT_ON, + PROP_DEFAULT, ZFS_TYPE_FILESYSTEM, "on | off | noauto", + "CANMOUNT", canmount_table); /* readonly index (boolean) properties */ register_index(ZFS_PROP_MOUNTED, "mounted", 0, PROP_READONLY, diff --git a/usr/src/lib/libzfs/common/libzfs_changelist.c b/usr/src/lib/libzfs/common/libzfs_changelist.c index 3d99982bcb..80e8409af3 100644 --- a/usr/src/lib/libzfs/common/libzfs_changelist.c +++ b/usr/src/lib/libzfs/common/libzfs_changelist.c @@ -695,8 +695,16 @@ changelist_gather(zfs_handle_t *zhp, zfs_prop_t prop, int flags) if ((clp->cl_prop == ZFS_PROP_MOUNTPOINT) && (zfs_prop_get(zhp, prop, property, sizeof (property), NULL, NULL, 0, B_FALSE) == 0 && - (strcmp(property, "legacy") == 0 || strcmp(property, "none") == 0))) - clp->cl_waslegacy = B_TRUE; + (strcmp(property, "legacy") == 0 || + strcmp(property, "none") == 0))) { + /* + * do not automatically mount ex-legacy datasets if + * we specifically set canmount to noauto + */ + if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) != + ZFS_CANMOUNT_NOAUTO) + clp->cl_waslegacy = B_TRUE; + } return (clp); } diff --git a/usr/src/lib/libzfs/common/libzfs_dataset.c b/usr/src/lib/libzfs/common/libzfs_dataset.c index d1d058d3e4..a83226182d 100644 --- a/usr/src/lib/libzfs/common/libzfs_dataset.c +++ b/usr/src/lib/libzfs/common/libzfs_dataset.c @@ -1720,6 +1720,7 @@ zfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval) libzfs_handle_t *hdl = zhp->zfs_hdl; nvlist_t *nvl = NULL, *realprops; zfs_prop_t prop; + int do_prefix = 1; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "cannot set property for '%s'"), @@ -1751,8 +1752,13 @@ zfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval) goto error; } - if ((ret = changelist_prefix(cl)) != 0) - goto error; + + /* do not unmount dataset if canmount is being set to noauto */ + if (prop == ZFS_PROP_CANMOUNT && *propval == ZFS_CANMOUNT_NOAUTO) + do_prefix = 0; + + if (do_prefix && (ret = changelist_prefix(cl)) != 0) + goto error; /* * Execute the corresponding ioctl() to set this property. @@ -1827,11 +1833,14 @@ zfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval) (void) zfs_standard_error(hdl, errno, errbuf); } } else { + if (do_prefix) + ret = changelist_postfix(cl); + /* * Refresh the statistics so the new property value * is reflected. */ - if ((ret = changelist_postfix(cl)) == 0) + if (ret == 0) (void) get_stats(zhp); } @@ -2096,7 +2105,7 @@ get_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src, case ZFS_PROP_CANMOUNT: *val = getprop_uint64(zhp, prop, source); - if (*val == 0) + if (*val != ZFS_CANMOUNT_ON) *source = zhp->zfs_name; else *source = ""; /* default */ diff --git a/usr/src/lib/libzfs/common/libzfs_mount.c b/usr/src/lib/libzfs/common/libzfs_mount.c index a53cc003fb..c182a841bd 100644 --- a/usr/src/lib/libzfs/common/libzfs_mount.c +++ b/usr/src/lib/libzfs/common/libzfs_mount.c @@ -285,7 +285,7 @@ zfs_is_mountable(zfs_handle_t *zhp, char *buf, size_t buflen, strcmp(buf, ZFS_MOUNTPOINT_LEGACY) == 0) return (B_FALSE); - if (!zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT)) + if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) == ZFS_CANMOUNT_OFF) return (B_FALSE); if (zfs_prop_get_int(zhp, ZFS_PROP_ZONED) && @@ -1103,6 +1103,11 @@ mount_cb(zfs_handle_t *zhp, void *data) return (0); } + if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) == ZFS_CANMOUNT_NOAUTO) { + zfs_close(zhp); + return (0); + } + if (cbp->cb_alloc == cbp->cb_used) { void *ptr; diff --git a/usr/src/uts/common/sys/fs/zfs.h b/usr/src/uts/common/sys/fs/zfs.h index cd7184632e..98a2b5c546 100644 --- a/usr/src/uts/common/sys/fs/zfs.h +++ b/usr/src/uts/common/sys/fs/zfs.h @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -200,6 +200,12 @@ typedef enum { #define ZFS_DELEG_PERM_GID "gid" #define ZFS_DELEG_PERM_GROUPS "groups" +typedef enum { + ZFS_CANMOUNT_OFF = 0, + ZFS_CANMOUNT_ON = 1, + ZFS_CANMOUNT_NOAUTO = 2 +} zfs_canmount_type_t; + typedef enum zfs_share_op { ZFS_SHARE_NFS = 0, ZFS_UNSHARE_NFS = 1, |