diff options
Diffstat (limited to 'cddl/contrib/opensolaris/cmd/zfs')
-rw-r--r-- | cddl/contrib/opensolaris/cmd/zfs/zfs.8 | 1309 | ||||
-rw-r--r-- | cddl/contrib/opensolaris/cmd/zfs/zfs_iter.c | 71 | ||||
-rw-r--r-- | cddl/contrib/opensolaris/cmd/zfs/zfs_iter.h | 12 | ||||
-rw-r--r-- | cddl/contrib/opensolaris/cmd/zfs/zfs_main.c | 1775 |
4 files changed, 2514 insertions, 653 deletions
diff --git a/cddl/contrib/opensolaris/cmd/zfs/zfs.8 b/cddl/contrib/opensolaris/cmd/zfs/zfs.8 index d49cb87..7217fe8 100644 --- a/cddl/contrib/opensolaris/cmd/zfs/zfs.8 +++ b/cddl/contrib/opensolaris/cmd/zfs/zfs.8 @@ -18,7 +18,7 @@ .\" .\" CDDL HEADER END .\" Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. -.TH zfs 1M "16 Mar 2007" "SunOS 5.11" "System Administration Commands" +.TH zfs 1M "8 Apr 2008" "SunOS 5.11" "System Administration Commands" .SH NAME zfs \- configures ZFS file systems .SH SYNOPSIS @@ -29,12 +29,12 @@ zfs \- configures ZFS file systems .LP .nf -\fBzfs\fR \fBcreate\fR [[\fB-o\fR property=\fIvalue\fR]]... \fIfilesystem\fR +\fBzfs\fR \fBcreate\fR [\fB-p\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR] ... \fIfilesystem\fR .fi .LP .nf -\fBzfs\fR \fBcreate\fR [\fB-s\fR] [\fB-b\fR \fIblocksize\fR] [[\fB-o\fR property=\fIvalue\fR]]... \fB-V\fR \fIsize\fR \fIvolume\fR +\fBzfs\fR \fBcreate\fR [\fB-ps\fR] [\fB-b\fR \fIblocksize\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR] ... \fB-V\fR \fIsize\fR \fIvolume\fR .fi .LP @@ -44,35 +44,44 @@ zfs \- configures ZFS file systems .LP .nf -\fBzfs\fR \fBclone\fR \fIsnapshot\fR \fIfilesystem\fR|\fIvolume\fR +\fBzfs\fR \fBsnapshot\fR [\fB-r\fR] \fIfilesystem@snapname\fR|\fIvolume@snapname\fR .fi .LP .nf -\fBzfs\fR \fBpromote\fR \fIfilesystem\fR +\fBzfs\fR \fBrollback\fR [\fB-rRf\fR] \fIsnapshot\fR +.fi + +.LP +.nf +\fBzfs\fR \fBclone\fR [\fB-p\fR] \fIsnapshot\fR \fIfilesystem\fR|\fIvolume\fR +.fi + +.LP +.nf +\fBzfs\fR \fBpromote\fR \fIclone-filesystem\fR .fi .LP .nf \fBzfs\fR \fBrename\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR - [\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR] + \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR .fi .LP .nf -\fBzfs\fR \fBsnapshot\fR [\fB-r\fR] \fIfilesystem@name\fR|\fIvolume@name\fR +\fBzfs\fR \fBrename\fR [\fB-p\fR] \fIfilesystem\fR|\fIvolume\fR \fIfilesystem\fR|\fIvolume\fR .fi .LP .nf -\fBzfs\fR \fBrollback\fR [\fB-rRf\fR] \fIsnapshot\fR +\fBzfs\fR \fBrename\fR \fB-r\fR \fIsnapshot\fR \fIsnapshot\fR .fi .LP .nf -\fBzfs\fR \fBlist\fR [\fB-rH\fR] [\fB-o\fR \fIprop\fR[,\fIprop\fR] ]... [ \fB-t\fR \fItype\fR[,\fItype\fR]...] - [ \fB-s\fR \fIprop\fR [\fB-s\fR \fIprop\fR]... [ \fB-S\fR \fIprop\fR [\fB-S\fR \fIprop\fR]... - [\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR|\fI/pathname\fR|.\fI/pathname\fR ... +\fBzfs\fR \fBlist\fR [\fB-rH\fR] [\fB-o\fR \fIproperty\fR[,...]] [\fB-t\fR \fItype\fR[,...]] + [\fB-s\fR \fIproperty\fR] ... [\fB-S\fR \fIproperty\fR ... [\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR] ... .fi .LP @@ -82,14 +91,23 @@ zfs \- configures ZFS file systems .LP .nf -\fBzfs\fR \fBget\fR [\fB-rHp\fR] [\fB-o\fR \fIfield\fR[,\fIfield\fR]...] - [\fB-s\fR \fIsource\fR[,\fIsource\fR]...] \fIall\fR | \fIproperty\fR[,\fIproperty\fR]... +\fBzfs\fR \fBget\fR [\fB-rHp\fR] [\fB-o\fR \fIfield\fR[,...]] [\fB-s\fR \fIsource\fR[,...]] "\fIall\fR" | \fIproperty\fR[,...] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ... .fi .LP .nf -\fBzfs\fR \fBinherit\fR [\fB-r\fR] \fIproperty\fR \fIfilesystem\fR|\fIvolume\fR... ... +\fBzfs\fR \fBinherit\fR [\fB-r\fR] \fIproperty\fR \fIfilesystem\fR|\fIvolume\fR ... +.fi + +.LP +.nf +\fBzfs\fR \fBupgrade\fR [\fB-v\fR] +.fi + +.LP +.nf +\fBzfs\fR \fBupgrade\fR [\fB-r\fR] [\fB-V\fR \fIversion\fR] \fB-a\fR | \fIfilesystem\fR .fi .LP @@ -99,58 +117,81 @@ zfs \- configures ZFS file systems .LP .nf -\fBzfs\fR \fBmount\fR [\fB-o \fIoptions\fR\fR] [\fB-O\fR] \fB-a\fR +\fBzfs\fR \fBmount\fR [\fB-vO\fR] [\fB-o \fIoptions\fR\fR] \fB-a\fR | \fIfilesystem\fR .fi .LP .nf -\fBzfs\fR \fBmount\fR [\fB-o \fIoptions\fR\fR] [\fB-O\fR] \fIfilesystem\fR +\fBzfs\fR \fBunmount\fR [\fB-f\fR] \fB-a\fR | \fIfilesystem\fR|\fImountpoint\fR .fi .LP .nf -\fBzfs\fR \fBunmount\fR [\fB-f\fR] \fB-a\fR +\fBzfs\fR \fBshare\fR \fB-a\fR | \fIfilesystem\fR .fi .LP .nf -\fBzfs\fR \fBunmount\fR [\fB-f\fR] \fB\fIfilesystem\fR|\fImountpoint\fR\fR +\fBzfs\fR \fBunshare\fR \fB-a\fR \fIfilesystem\fR|\fImountpoint\fR .fi .LP .nf -\fBzfs\fR \fBshare\fR \fB-a\fR +\fBzfs\fR \fBsend\fR [\fB-vR\fR] [\fB-\fR[\fB-iI\fR] \fIsnapshot\fR] \fIsnapshot\fR .fi .LP .nf -\fBzfs\fR \fBshare\fR \fIfilesystem\fR +\fBzfs\fR \fBreceive\fR [\fB-vnF\fR] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR .fi .LP .nf -\fBzfs\fR \fBunshare\fR [\fB-f\fR] \fB-a\fR +\fBzfs\fR \fBreceive\fR [\fB-vnF\fR] \fB-d\fR \fIfilesystem\fR .fi .LP .nf -\fBzfs\fR \fBunshare\fR [\fB-f\fR] \fB\fIfilesystem\fR|\fImountpoint\fR\fR +\fBzfs\fR \fBallow\fR [\fB-ldug\fR] "\fIeveryone\fR"|\fIuser\fR|\fIgroup\fR[,...] \fIperm\fR|\fI@setname\fR[,...] + \fIfilesystem\fR|\fIvolume\fR .fi .LP .nf -\fBzfs\fR \fBsend\fR [\fB-i\fR \fIsnapshot1\fR] \fB\fIsnapshot2\fR\fR +\fBzfs\fR \fBallow\fR [\fB-ld\fR] \fB-e\fR \fIperm\fR|@\fIsetname\fR[,...] \fIfilesystem\fR|\fIvolume\fR .fi .LP .nf -\fBzfs\fR \fBreceive\fR [\fB-vnF\fR ] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR +\fBzfs\fR \fBallow\fR \fB-c\fR \fIperm\fR|@\fIsetname\fR[,...] \fIfilesystem\fR|\fIvolume\fR .fi .LP .nf -\fBzfs\fR \fBreceive\fR [\fB-vnF\fR ] \fB-d\fR \fB\fIfilesystem\fR\fR +\fBzfs\fR \fBallow\fR \fB-s\fR @setname \fIperm\fR|@\fIsetname\fR[,...] \fIfilesystem\fR|\fIvolume\fR .fi + +.LP +.nf +\fBzfs\fR \fBunallow\fR [\fB-rldug\fR] "\fIeveryone\fR"|\fIuser\fR|\fIgroup\fR[,...] [\fIperm\fR|@\fIsetname\fR[,... ]] + \fIfilesystem\fR|\fIvolume\fR +.fi + +.LP +.nf +\fBzfs\fR \fBunallow\fR [\fB-rld\fR] \fB-e\fR [\fIperm\fR|@\fIsetname\fR[,... ]] \fIfilesystem\fR|\fIvolume\fR +.fi + +.LP +.nf +\fBzfs\fR \fBunallow\fR [\fB-r\fR] \fB-c\fR [\fIperm\fR|@\fIsetname\fR[ ... ]] \fIfilesystem\fR|\fIvolume\fR +.fi + +.LP +.nf +\fBzfs\fR \fBunallow\fR [\fB-r\fR] \fB-s\fR @setname [\fIperm\fR|@\fIsetname\fR[,... ]] \fIfilesystem\fR|\fIvolume\fR +.fi + .LP .nf \fBzfs\fR \fBjail\fR \fBjailid\fR \fB\fIfilesystem\fR\fR @@ -161,6 +202,7 @@ zfs \- configures ZFS file systems .fi .SH DESCRIPTION +.sp .LP The \fBzfs\fR command configures \fBZFS\fR datasets within a \fBZFS\fR storage pool, as described in \fBzpool\fR(1M). A dataset is identified by a unique path within the \fBZFS\fR namespace. For example: @@ -172,8 +214,10 @@ pool/{filesystem,volume,snapshot} .in -2 .sp +.sp .LP where the maximum length of a dataset name is \fBMAXNAMELEN\fR (256 bytes). +.sp .LP A dataset can be one of the following: .sp @@ -210,65 +254,88 @@ A read-only version of a file system or volume at a given point in time. It is s .RE .SS "ZFS File System Hierarchy" +.sp .LP A \fBZFS\fR storage pool is a logical collection of devices that provide space for datasets. A storage pool is also the root of the \fBZFS\fR file system hierarchy. +.sp .LP The root of the pool can be accessed as a file system, such as mounting and unmounting, taking snapshots, and setting properties. The physical storage characteristics, however, are managed by the \fBzpool\fR(1M) command. +.sp .LP See \fBzpool\fR(1M) for more information on creating and administering pools. .SS "Snapshots" +.sp .LP A snapshot is a read-only copy of a file system or volume. Snapshots can be created extremely quickly, and initially consume no additional space within the pool. As data within the active dataset changes, the snapshot consumes more data than would otherwise be shared with the active dataset. +.sp .LP Snapshots can have arbitrary names. Snapshots of volumes can be cloned or rolled back, but cannot be accessed independently. +.sp .LP File system snapshots can be accessed under the ".zfs/snapshot" directory in the root of the file system. Snapshots are automatically mounted on demand and may be unmounted at regular intervals. The visibility of the ".zfs" directory can be controlled by the "snapdir" property. .SS "Clones" +.sp .LP A clone is a writable volume or file system whose initial contents are the same as another dataset. As with snapshots, creating a clone is nearly instantaneous, and initially consumes no additional space. +.sp .LP Clones can only be created from a snapshot. When a snapshot is cloned, it creates an implicit dependency between the parent and child. Even though the clone is created somewhere else in the dataset hierarchy, the original snapshot cannot be destroyed as long as a clone exists. The "origin" property exposes this dependency, and the \fBdestroy\fR command lists any such dependencies, if they exist. +.sp .LP The clone parent-child dependency relationship can be reversed by using the "\fBpromote\fR" subcommand. This causes the "origin" file system to become a clone of the specified file system, which makes it possible to destroy the file system that the clone was created from. .SS "Mount Points" +.sp .LP -Creating a \fBZFS\fR file system is a simple operation, so the number of file systems per system will likely be numerous. To cope with this, \fBZFS\fR automatically manages mounting and unmounting file systems without the need to edit the \fB/etc/vfstab\fR file. -All automatically managed file systems are mounted by \fBZFS\fR at boot time. +Creating a \fBZFS\fR file system is a simple operation, so the number of file systems per system is likely to be numerous. To cope with this, \fBZFS\fR automatically manages mounting and unmounting file systems without the need to edit the \fB/etc/vfstab\fR file. All automatically managed file systems are mounted by \fBZFS\fR at boot time. +.sp .LP By default, file systems are mounted under \fB/\fIpath\fR\fR, where \fIpath\fR is the name of the file system in the \fBZFS\fR namespace. Directories are created and destroyed as needed. +.sp .LP A file system can also have a mount point set in the "mountpoint" property. This directory is created as needed, and \fBZFS\fR automatically mounts the file system when the "\fBzfs mount -a\fR" command is invoked (without editing \fB/etc/vfstab\fR). The mountpoint property can be inherited, so if \fBpool/home\fR has a mount point of \fB/export/stuff\fR, then \fBpool/home/user\fR automatically inherits a mount point of \fB/export/stuff/user\fR. +.sp .LP A file system mountpoint property of "none" prevents the file system from being mounted. +.sp .LP If needed, \fBZFS\fR file systems can also be managed with traditional tools (\fBmount\fR, \fBumount\fR, \fB/etc/vfstab\fR). If a file system's mount point is set to "legacy", \fBZFS\fR makes no attempt to manage the file system, and the administrator is responsible for mounting and unmounting the file system. .SS "Zones" +.sp .LP A \fBZFS\fR file system can be added to a non-global zone by using zonecfg's "\fBadd fs\fR" subcommand. A \fBZFS\fR file system that is added to a non-global zone must have its mountpoint property set to legacy. +.sp .LP The physical properties of an added file system are controlled by the global administrator. However, the zone administrator can create, modify, or destroy files within the added file system, depending on how the file system is mounted. +.sp .LP A dataset can also be delegated to a non-global zone by using zonecfg's "\fBadd dataset\fR" subcommand. You cannot delegate a dataset to one zone and the children of the same dataset to another zone. The zone administrator can change properties of the dataset or any of its children. However, the "quota" property is controlled by the global administrator. +.sp .LP A \fBZFS\fR volume can be added as a device to a non-global zone by using zonecfg's "\fBadd device\fR" subcommand. However, its physical properties can only be modified by the global administrator. +.sp .LP For more information about \fBzonecfg\fR syntax, see \fBzonecfg\fR(1M). +.sp .LP After a dataset is delegated to a non-global zone, the "zoned" property is automatically set. A zoned file system cannot be mounted in the global zone, since the zone administrator might have to set the mount point to an unacceptable value. +.sp .LP The global administrator can forcibly clear the "zoned" property, though this should be done with extreme care. The global administrator should verify that all the mount points are acceptable before clearing the property. .SS "Native Properties" +.sp .LP Properties are divided into two types, native properties and user defined properties. Native properties either export internal statistics or control \fBZFS\fR behavior. In addition, native properties are either editable or read-only. User properties have no effect on \fBZFS\fR behavior, but you can use them to annotate datasets in a way that is meaningful in your environment. For more information about user properties, see the "User Properties" section. +.sp .LP Every dataset has a set of properties that export statistics about the dataset as well as control various behavior. Properties are inherited from the parent unless overridden by the child. Snapshot properties can not be edited; they always inherit their inheritable properties. Properties that are not applicable to snapshots are not displayed. +.sp .LP The values of numeric properties can be specified using the following human-readable suffixes (for example, "k", "KB", "M", "Gb", etc, up to Z for zettabyte). The following are all valid (and equal) specifications: .sp @@ -279,19 +346,35 @@ The values of numeric properties can be specified using the following human-read .in -2 .sp +.sp .LP -The values of non-numeric properties are case sensitive and must be lowercase, except for "mountpoint" and "sharenfs". +The values of non-numeric properties are case sensitive and must be lowercase, except for "mountpoint", "sharenfs" and "sharesmb". +.sp .LP -The first set of properties consist of read-only statistics about the dataset. These properties cannot be set, nor are they inherited. Native properties apply to all dataset types unless otherwise noted. +The following native properties consist of read-only statistics about the dataset. These properties cannot be set, nor are they inherited. Native properties apply to all dataset types unless otherwise noted. .sp .ne 2 .mk .na -\fBtype\fR +\fBavailable\fR .ad -.RS 17n -.rt -The type of dataset: "filesystem", "volume", "snapshot", or "clone". +.sp .6 +.RS 4n +The amount of space available to the dataset and all its children, assuming that there is no other activity in the pool. Because space is shared within a pool, availability can be limited by any number of factors, including physical pool size, quotas, reservations, or other datasets +within the pool. +.sp +This property can also be referred to by its shortened column name, "avail". +.RE + +.sp +.ne 2 +.mk +.na +\fBcompressratio\fR +.ad +.sp .6 +.RS 4n +The compression ratio achieved for this dataset, expressed as a multiplier. Compression can be turned on by running "zfs set compression=on \fIdataset\fR". The default value is "off". .RE .sp @@ -300,8 +383,8 @@ The type of dataset: "filesystem", "volume", "snapshot", or "clone". .na \fBcreation\fR .ad -.RS 17n -.rt +.sp .6 +.RS 4n The time this dataset was created. .RE @@ -309,31 +392,22 @@ The time this dataset was created. .ne 2 .mk .na -\fBused\fR +\fBmounted\fR .ad -.RS 17n -.rt -The amount of space consumed by this dataset and all its descendants. This is the value that is checked against this dataset's quota and reservation. The space used does not include this dataset's reservation, but does take into account the reservations of any descendant datasets. -The amount of space that a dataset consumes from its parent, as well as the amount of space that will be freed if this dataset is recursively destroyed, is the greater of its space used and its reservation. -.sp -When snapshots (see the "Snapshots" section) are created, their space is initially shared between the snapshot and the file system, and possibly with previous snapshots. As the file system changes, space that was previously shared becomes unique to the snapshot, and counted in -the snapshot's space used. Additionally, deleting snapshots can increase the amount of space unique to (and used by) other snapshots. -.sp -The amount of space used, available, or referenced does not take into account pending changes. Pending changes are generally accounted for within a few seconds. Committing a change to a disk using \fBfsync\fR(3c) or \fBO_SYNC\fR does not necessarily guarantee that the space usage information is updated immediately. +.sp .6 +.RS 4n +For file systems, indicates whether the file system is currently mounted. This property can be either "yes" or "no". .RE .sp .ne 2 .mk .na -\fBavailable\fR +\fBorigin\fR .ad -.RS 17n -.rt -The amount of space available to the dataset and all its children, assuming that there is no other activity in the pool. Because space is shared within a pool, availability can be limited by any number of factors, including physical pool size, quotas, reservations, or other datasets -within the pool. -.sp -This property can also be referred to by its shortened column name, "avail". +.sp .6 +.RS 4n +For cloned file systems or volumes, the snapshot from which the clone was created. The origin cannot be destroyed (even with the \fB-r\fR or \fB-f\fR options) so long as a clone exists. .RE .sp @@ -342,8 +416,8 @@ This property can also be referred to by its shortened column name, "avail". .na \fBreferenced\fR .ad -.RS 17n -.rt +.sp .6 +.RS 4n The amount of data that is accessible by this dataset, which may or may not be shared with other datasets in the pool. When a snapshot or clone is created, it initially references the same amount of space as the file system or snapshot it was created from, since its contents are identical. .sp @@ -354,116 +428,166 @@ This property can also be referred to by its shortened column name, "refer". .ne 2 .mk .na -\fBcompressratio\fR +\fBtype\fR .ad -.RS 17n -.rt -The compression ratio achieved for this dataset, expressed as a multiplier. Compression can be turned on by running "zfs set compression=on \fIdataset\fR". The default value is "off". +.sp .6 +.RS 4n +The type of dataset: "filesystem", "volume", "snapshot", or "clone". .RE .sp .ne 2 .mk .na -\fBmounted\fR +\fBused\fR .ad -.RS 17n -.rt -For file systems, indicates whether the file system is currently mounted. This property can be either "yes" or "no". +.sp .6 +.RS 4n +The amount of space consumed by this dataset and all its descendents. This is the value that is checked against this dataset's quota and reservation. The space used does not include this dataset's reservation, but does take into account the reservations of any descendent datasets. +The amount of space that a dataset consumes from its parent, as well as the amount of space that are freed if this dataset is recursively destroyed, is the greater of its space used and its reservation. +.sp +When snapshots (see the "Snapshots" section) are created, their space is initially shared between the snapshot and the file system, and possibly with previous snapshots. As the file system changes, space that was previously shared becomes unique to the snapshot, and counted in +the snapshot's space used. Additionally, deleting snapshots can increase the amount of space unique to (and used by) other snapshots. +.sp +The amount of space used, available, or referenced does not take into account pending changes. Pending changes are generally accounted for within a few seconds. Committing a change to a disk using \fBfsync\fR(3c) or \fBO_SYNC\fR does not necessarily guarantee that the space usage information is updated immediately. .RE .sp .ne 2 .mk .na -\fBorigin\fR +\fBvolblocksize=\fIblocksize\fR\fR .ad -.RS 17n -.rt -For cloned file systems or volumes, the snapshot from which the clone was created. The origin cannot be destroyed (even with the \fB-r\fR or \fB-f\fR options) so long as a clone exists. +.sp .6 +.RS 4n +For volumes, specifies the block size of the volume. The \fBblocksize\fR cannot be changed once the volume has been written, so it should be set at volume creation time. The default \fBblocksize\fR for volumes is 8 Kbytes. Any power of 2 from 512 bytes +to 128 Kbytes is valid. +.sp +This property can also be referred to by its shortened column name, "volblock". .RE +.sp .LP -The following two properties can be set to control the way space is allocated between datasets. These properties are not inherited, but do affect their descendants. +The following native properties can be used to change the behavior of a \fBZFS\fR dataset. .sp .ne 2 .mk .na -\fBquota=\fIsize\fR | \fInone\fR\fR +\fBaclinherit=\fBdiscard\fR | \fBnoallow\fR | \fBrestricted\fR | \fBpassthrough\fR\fR .ad .sp .6 .RS 4n -Limits the amount of space a dataset and its descendants can consume. This property enforces a hard limit on the amount of space used. This includes all space consumed by descendants, including file systems and snapshots. Setting a quota on a descendant of a dataset that already -has a quota does not override the ancestor's quota, but rather imposes an additional limit. +Controls how \fBACL\fR entries are inherited when files and directories are created. A file system with an "aclinherit" property of "\fBdiscard\fR" does not inherit any \fBACL\fR entries. A file system with an "aclinherit" +property value of "\fBnoallow\fR" only inherits inheritable \fBACL\fR entries that specify "deny" permissions. The property value "\fBrestricted\fR" (the default) removes the "\fBwrite_acl\fR" and "\fBwrite_owner\fR" permissions when the \fBACL\fR entry is inherited. A file system with an "aclinherit" property value of "\fBpassthrough\fR" inherits all inheritable \fBACL\fR entries without any modifications made to the \fBACL\fR entries when they are inherited. .sp -Quotas cannot be set on volumes, as the "volsize" property acts as an implicit quota. +When the property value is set to "\fBpassthrough\fR," files are created with a mode determined by the inheritable \fBACE\fRs. If no inheritable \fBACE\fRs exist that affect the mode, then the mode is set in accordance to the requested mode +from the application. .RE .sp .ne 2 .mk .na -\fBreservation=\fIsize\fR | \fInone\fR\fR +\fBaclmode=\fBdiscard\fR | \fBgroupmask\fR | \fBpassthrough\fR\fR .ad .sp .6 .RS 4n -The minimum amount of space guaranteed to a dataset and its descendants. When the amount of space used is below this value, the dataset is treated as if it were taking up the amount of space specified by its reservation. Reservations are accounted for in the parent datasets' space -used, and count against the parent datasets' quotas and reservations. +Controls how an \fBACL\fR is modified during \fBchmod\fR(2). A file system with an "aclmode" property of "\fBdiscard\fR" +deletes all \fBACL\fR entries that do not represent the mode of the file. An "aclmode" property of "\fBgroupmask\fR" (the default) reduces user or group permissions. The permissions are reduced, such that they are no greater than the group permission +bits, unless it is a user entry that has the same \fBUID\fR as the owner of the file or directory. In this case, the \fBACL\fR permissions are reduced so that they are no greater than owner permission bits. A file system with an "aclmode" property of "\fBpassthrough\fR" indicates that no changes are made to the \fBACL\fR other than generating the necessary \fBACL\fR entries to represent the new mode of the file or directory. +.RE + .sp -This property can also be referred to by its shortened column name, "reserv". +.ne 2 +.mk +.na +\fBatime=\fIon\fR | \fIoff\fR\fR +.ad +.sp .6 +.RS 4n +Controls whether the access time for files is updated when they are read. Turning this property off avoids producing write traffic when reading files and can result in significant performance gains, though it might confuse mailers and other similar utilities. The default value +is "on". .RE .sp .ne 2 .mk .na -\fBvolsize=\fIsize\fR\fR +\fBcanmount=\fBon\fR | \fBoff\fR | \fBnoauto\fR\fR .ad .sp .6 .RS 4n -For volumes, specifies the logical size of the volume. By default, creating a volume establishes a reservation of equal size. Any changes to \fBvolsize\fR are reflected in an equivalent change to the reservation. The \fBvolsize\fR can only be set to a -multiple of \fBvolblocksize\fR, and cannot be zero. +If this property is set to "\fBoff\fR", the file system cannot be mounted, and is ignored by "\fBzfs mount -a\fR". Setting this property to "\fBoff\fR" is similar to setting the "mountpoint" +property to "\fBnone\fR", except that the dataset still has a normal "mountpoint" property, which can be inherited. Setting this property to "\fBoff\fR" allows datasets to be used solely as a mechanism to inherit properties. One example +of setting canmount=\fBoff\fR is to have two datasets with the same mountpoint, so that the children of both datasets appear in the same directory, but might have different inherited characteristics. .sp -The reservation is kept equal to the volume's logical size to prevent unexpected behavior for consumers. Without the reservation, the volume could run out of space, resulting in undefined behavior or data corruption, depending on how the volume is used. These effects can also occur when -the volume size is changed while it is in use (particularly when shrinking the size). Extreme care should be used when adjusting the volume size. +When the "\fBnoauto\fR" option is set, a dataset can only be mounted and unmounted explicitly. The dataset is not mounted automatically when the dataset is created or imported, nor is it mounted by the "\fBzfs mount -a\fR" command or unmounted +by the "\fBzfs unmount -a\fR" command. .sp -Though not recommended, a "sparse volume" (also known as "thin provisioning") can be created by specifying the \fB-s\fR option to the "\fBzfs create -V\fR" command, or by changing the reservation after the volume has been created. -A "sparse volume" is a volume where the reservation is less then the volume size. Consequently, writes to a sparse volume can fail with \fBENOSPC\fR when the pool is low on space. For a sparse volume, changes to \fBvolsize\fR are not reflected in the reservation. +This property is not inherited. .RE .sp .ne 2 .mk .na -\fBvolblocksize=\fIblocksize\fR\fR +\fBchecksum=\fIon\fR | \fIoff\fR | \fIfletcher2\fR, | \fIfletcher4\fR | \fIsha256\fR\fR .ad .sp .6 .RS 4n -For volumes, specifies the block size of the volume. The \fBblocksize\fR cannot be changed once the volume has been written, so it should be set at volume creation time. The default \fBblocksize\fR for volumes is 8 Kbytes. Any power of 2 from 512 bytes -to 128 Kbytes is valid. -.sp -This property can also be referred to by its shortened column name, "volblock". +Controls the checksum used to verify data integrity. The default value is "on", which automatically selects an appropriate algorithm (currently, \fIfletcher2\fR, but this may change in future releases). The value "off" disables integrity +checking on user data. Disabling checksums is NOT a recommended practice. .RE .sp .ne 2 .mk .na -\fBrecordsize=\fIsize\fR\fR +\fBcompression=\fIon\fR | \fIoff\fR | \fIlzjb\fR | \fIgzip\fR | \fIgzip-N\fR\fR .ad .sp .6 .RS 4n -Specifies a suggested block size for files in the file system. This property is designed solely for use with database workloads that access files in fixed-size records. \fBZFS\fR automatically tunes block sizes according to internal algorithms optimized for typical -access patterns. +Controls the compression algorithm used for this dataset. The "lzjb" compression algorithm is optimized for performance while providing decent data compression. Setting compression to "on" uses the "lzjb" compression algorithm. The "gzip" +compression algorithm uses the same compression as the \fBgzip\fR(1) command. You can specify the "gzip" level by using the value "gzip-\fIN\fR" where \fIN\fR is +an integer from 1 (fastest) to 9 (best compression ratio). Currently, "gzip" is equivalent to "gzip-6" (which is also the default for \fBgzip\fR(1)). .sp -For databases that create very large files but access them in small random chunks, these algorithms may be suboptimal. Specifying a "recordsize" greater than or equal to the record size of the database can result in significant performance gains. Use of this property for general -purpose file systems is strongly discouraged, and may adversely affect performance. +This property can also be referred to by its shortened column name "compress". +.RE + .sp -The size specified must be a power of two greater than or equal to 512 and less than or equal to 128 Kbytes. +.ne 2 +.mk +.na +\fBcopies=\fB1\fR | \fB2\fR | \fB3\fR\fR +.ad +.sp .6 +.RS 4n +Controls the number of copies of data stored for this dataset. These copies are in addition to any redundancy provided by the pool, for example, mirroring or raid-z. The copies are stored on different disks, if possible. The space used by multiple copies is charged to the associated +file and dataset, changing the "used" property and counting against quotas and reservations. .sp -Changing the file system's \fBrecordsize\fR only affects files created afterward; existing files are unaffected. +Changing this property only affects newly-written data. Therefore, set this property at file system creation time by using the "\fB-o\fR copies=" option. +.RE + .sp -This property can also be referred to by its shortened column name, "recsize". +.ne 2 +.mk +.na +\fBdevices=\fIon\fR | \fIoff\fR\fR +.ad +.sp .6 +.RS 4n +Controls whether device nodes can be opened on this file system. The default value is "on". +.RE + +.sp +.ne 2 +.mk +.na +\fBexec=\fIon\fR | \fIoff\fR\fR +.ad +.sp .6 +.RS 4n +Controls whether processes can be executed from within this file system. The default value is "on". .RE .sp @@ -484,89 +608,100 @@ previously "legacy" or "none", or if they were mounted before the property was c .ne 2 .mk .na -\fBsharenfs=\fIon\fR | \fIoff\fR | \fIopts\fR\fR +\fBnbmand=\fIon\fR | \fIoff\fR\fR .ad .sp .6 .RS 4n -Controls whether the file system is shared via \fBNFS\fR, and what options are used. A file system with a sharenfs property of "off" is managed through traditional tools such as \fBshare\fR(1M), \fBunshare\fR(1M), and \fBdfstab\fR(4). Otherwise, the file system is automatically shared and unshared with the "\fBzfs share\fR" and "\fBzfs unshare\fR" commands. If the property is set to "on", the \fBshare\fR(1M) command is invoked with no options. Otherwise, the \fBshare\fR(1M) command is invoked with options equivalent to the contents of this property. -.sp -When the "sharenfs" property is changed for a dataset, the dataset and any children inheriting the property are re-shared with the new options, only if the property was previously "off", or if they were shared before the property was changed. If the new property is "off", -the file systems are unshared. +Controls whether the file system should be mounted with "\fBnbmand\fR" (Non Blocking mandatory locks). This is used for \fBCIFS\fR clients. Changes to this property only take effect when the file system is umounted and remounted. See \fBmount\fR(1M) for more information on "\fBnbmand\fR" mounts. .RE .sp .ne 2 .mk .na -\fBshareiscsi=\fIon\fR | \fIoff\fR\fR +\fBquota=\fIsize\fR | \fInone\fR\fR .ad .sp .6 .RS 4n -Like the "sharenfs" property, "shareiscsi" indicates whether a \fBZFS\fR volume is exported as an \fBiSCSI\fR target. The acceptable values for this property are "on", "off", and "type=disk". -The default value is "off". In the future, other target types might be supported. For example, "tape". +Limits the amount of space a dataset and its descendents can consume. This property enforces a hard limit on the amount of space used. This includes all space consumed by descendents, including file systems and snapshots. Setting a quota on a descendent of a dataset that already +has a quota does not override the ancestor's quota, but rather imposes an additional limit. .sp -You might want to set "shareiscsi=on" for a file system so that all \fBZFS\fR volumes within the file system are shared by default. Setting this property on a file system has no direct effect, however. +Quotas cannot be set on volumes, as the "volsize" property acts as an implicit quota. .RE .sp .ne 2 .mk .na -\fBchecksum=\fIon\fR | \fIoff\fR | \fIfletcher2\fR, | \fIfletcher4\fR | \fIsha256\fR\fR +\fBreadonly=\fIon\fR | \fIoff\fR\fR .ad .sp .6 .RS 4n -Controls the checksum used to verify data integrity. The default value is "on", which automatically selects an appropriate algorithm (currently, \fIfletcher2\fR, but this may change in future releases). The value "off" disables integrity -checking on user data. Disabling checksums is NOT a recommended practice. +Controls whether this dataset can be modified. The default value is "off". +.sp +This property can also be referred to by its shortened column name, "rdonly". .RE .sp .ne 2 .mk .na -\fBcompression=\fIon\fR | \fIoff\fR | \fIlzjb\fR | \fIgzip\fR | \fIgzip-N\fR\fR +\fBrecordsize=\fIsize\fR\fR .ad .sp .6 .RS 4n -Controls the compression algorithm used for this dataset. The "lzjb" compression algorithm is optimized for performance while providing decent data compression. Setting compression to "on" uses the "lzjb" compression algorithm. The "gzip" -compression algorithm uses the same compression as the \fBgzip\fR(1) command. You can specify the "gzip" level by using the value "gzip-\fIN\fR", -where \fIN\fR is an integer from 1 (fastest) to 9 (best compression ratio). Currently, "gzip" is equivalent to "gzip-6" (which is also the default for \fBgzip\fR(1)). +Specifies a suggested block size for files in the file system. This property is designed solely for use with database workloads that access files in fixed-size records. \fBZFS\fR automatically tunes block sizes according to internal algorithms optimized for typical +access patterns. .sp -This property can also be referred to by its shortened column name "compress". +For databases that create very large files but access them in small random chunks, these algorithms may be suboptimal. Specifying a "recordsize" greater than or equal to the record size of the database can result in significant performance gains. Use of this property for general +purpose file systems is strongly discouraged, and may adversely affect performance. +.sp +The size specified must be a power of two greater than or equal to 512 and less than or equal to 128 Kbytes. +.sp +Changing the file system's \fBrecordsize\fR only affects files created afterward; existing files are unaffected. +.sp +This property can also be referred to by its shortened column name, "recsize". .RE .sp .ne 2 .mk .na -\fBatime=\fIon\fR | \fIoff\fR\fR +\fBrefquota=\fIsize\fR | \fInone\fR\fR .ad .sp .6 .RS 4n -Controls whether the access time for files is updated when they are read. Turning this property off avoids producing write traffic when reading files and can result in significant performance gains, though it might confuse mailers and other similar utilities. The default value -is "on". +Limits the amount of space a dataset can consume. This property enforces a hard limit on the amount of space used. This hard limit does not include space used by descendents, including file systems and snapshots. .RE .sp .ne 2 .mk .na -\fBdevices=\fIon\fR | \fIoff\fR\fR +\fBrefreservation=\fIsize\fR | \fInone\fR\fR .ad .sp .6 .RS 4n -Controls whether device nodes can be opened on this file system. The default value is "on". +The minimum amount of space guaranteed to a dataset, not including its descendents. When the amount of space used is below this value, the dataset is treated as if it were taking up the amount of space specified by \fBrefreservation\fR. The \fBrefreservation\fR reservation +is accounted for in the parent datasets' space used, and counts against the parent datasets' quotas and reservations. +.sp +If \fBrefreservation\fR is set, a snapshot is only allowed if there is enough free pool space outside of this reservation to accommodate the current number of "referenced" bytes in the dataset. +.sp +This property can also be referred to by its shortened column name, "refreserv". .RE .sp .ne 2 .mk .na -\fBexec=\fIon\fR | \fIoff\fR\fR +\fBreservation=\fIsize\fR | \fInone\fR\fR .ad .sp .6 .RS 4n -Controls whether processes can be executed from within this file system. The default value is "on". +The minimum amount of space guaranteed to a dataset and its descendents. When the amount of space used is below this value, the dataset is treated as if it were taking up the amount of space specified by its reservation. Reservations are accounted for in the parent datasets' space +used, and count against the parent datasets' quotas and reservations. +.sp +This property can also be referred to by its shortened column name, "reserv". .RE .sp @@ -584,24 +719,48 @@ Controls whether the set-\fBUID\fR bit is respected for the file system. The def .ne 2 .mk .na -\fBreadonly=\fIon\fR | \fIoff\fR\fR +\fBshareiscsi=\fIon\fR | \fIoff\fR\fR .ad .sp .6 .RS 4n -Controls whether this dataset can be modified. The default value is "off". +Like the "sharenfs" property, "shareiscsi" indicates whether a \fBZFS\fR volume is exported as an \fBiSCSI\fR target. The acceptable values for this property are "on", "off", and "type=disk". +The default value is "off". In the future, other target types might be supported. For example, "tape". .sp -This property can also be referred to by its shortened column name, "rdonly". +You might want to set "shareiscsi=on" for a file system so that all \fBZFS\fR volumes within the file system are shared by default. Setting this property on a file system has no direct effect, however. .RE .sp .ne 2 .mk .na -\fBzoned=\fIon\fR | \fIoff\fR\fR +\fBsharesmb=\fIon\fR | \fIoff\fR | \fIopts\fR\fR .ad .sp .6 .RS 4n -Controls whether the dataset is managed from a non-global zone. See the "Zones" section for more information. The default value is "off". +Controls whether the file system is shared by using the Solaris \fBCIFS\fR service, and what options are to be used. A file system with the "\fBsharesmb\fR" property set to "off" is managed through traditional tools such as \fBsharemgr\fR(1M). Otherwise, the file system is automatically shared and unshared with the "zfs share" and "zfs unshare" commands. If the property is set to "on", +the \fBsharemgr\fR(1M) command is invoked with no options. Otherwise, the \fBsharemgr\fR(1M) command is invoked with options equivalent to the contents of this property. +.sp +Because \fBSMB\fR shares requires a resource name, a unique resource name is constructed from the dataset name. The constructed name is a copy of the dataset name except that the characters in the dataset name, which would be illegal in the resource name, are replaced with underscore +(_) characters. A pseudo property "name" is also supported that allows you to replace the data set name with a specified name. The specified name is then used to replace the prefix dataset in the case of inheritance. For example, if the dataset "\fBdata/home/john\fR" +is set to "name=john", then "\fBdata/home/john\fR" has a resource name of "john". If a child dataset of "\fBdata/home/john/backups\fR", it has a resource name of "john_backups". +.sp +When the "sharesmb" property is changed for a dataset, the dataset and any children inheriting the property are re-shared with the new options, only if the property was previously set to "off", or if they were shared before the property was changed. If the new property +is set to "off", the file systems are unshared. +.RE + +.sp +.ne 2 +.mk +.na +\fBsharenfs=\fIon\fR | \fIoff\fR | \fIopts\fR\fR +.ad +.sp .6 +.RS 4n +Controls whether the file system is shared via \fBNFS\fR, and what options are used. A file system with a"\fBsharenfs\fR" property of "off" is managed through traditional tools such as \fBshare\fR(1M), \fBunshare\fR(1M), and \fBdfstab\fR(4). Otherwise, the file system is automatically shared and unshared with the "\fBzfs share\fR" and "\fBzfs unshare\fR" commands. If the property is set to "on", +the \fBshare\fR(1M) command is invoked with no options. Otherwise, the \fBshare\fR(1M) command is invoked with options equivalent to the contents of this property. +.sp +When the "sharenfs" property is changed for a dataset, the dataset and any children inheriting the property are re-shared with the new options, only if the property was previously "off", or if they were shared before the property was changed. If the new property is "off", +the file systems are unshared. .RE .sp @@ -619,40 +778,40 @@ Controls whether the ".zfs" directory is hidden or visible in the root of the fi .ne 2 .mk .na -\fBaclmode=\fBdiscard\fR | \fBgroupmask\fR | \fBpassthrough\fR\fR +\fBversion=\fB1\fR|\fB2\fR|\fBcurrent\fR\fR .ad .sp .6 .RS 4n -Controls how an \fBACL\fR is modified during \fBchmod\fR(2). A file system with an "aclmode" property of "\fBdiscard\fR" -deletes all \fBACL\fR entries that do not represent the mode of the file. An "aclmode" property of "\fBgroupmask\fR" (the default) reduces user or group permissions. The permissions are reduced, such that they are no greater than the group permission -bits, unless it is a user entry that has the same \fBUID\fR as the owner of the file or directory. In this case, the \fBACL\fR permissions are reduced so that they are no greater than owner permission bits. A file system with an "aclmode" property of "\fBpassthrough\fR" indicates that no changes will be made to the \fBACL\fR other than generating the necessary \fBACL\fR entries to represent the new mode of the file or directory. +The on-disk version of this file system, which is independent of the pool version. This property can only be set to later supported versions. See "\fBzfs upgrade\fR". .RE .sp .ne 2 .mk .na -\fBaclinherit=\fBdiscard\fR | \fBnoallow\fR | \fBsecure\fR | \fBpassthrough\fR\fR +\fBvolsize=\fIsize\fR\fR .ad .sp .6 .RS 4n -Controls how \fBACL\fR entries are inherited when files and directories are created. A file system with an "aclinherit" property of "\fBdiscard\fR" does not inherit any \fBACL\fR entries. A file system with an "aclinherit" -property value of "\fBnoallow\fR" only inherits inheritable \fBACL\fR entries that specify "deny" permissions. The property value "\fBsecure\fR" (the default) removes the "\fBwrite_acl\fR" and "\fBwrite_owner\fR" permissions when the \fBACL\fR entry is inherited. A file system with an "aclinherit" property value of "\fBpassthrough\fR" inherits all inheritable \fBACL\fR entries without any modifications made to the \fBACL\fR entries when they are inherited. +For volumes, specifies the logical size of the volume. By default, creating a volume establishes a reservation of equal size. For storage pools with a version number of 9 or higher, a \fBrefreservation\fR is set instead. Any changes to \fBvolsize\fR are +reflected in an equivalent change to the reservation (or \fBrefreservation\fR). The \fBvolsize\fR can only be set to a multiple of \fBvolblocksize\fR, and cannot be zero. +.sp +The reservation is kept equal to the volume's logical size to prevent unexpected behavior for consumers. Without the reservation, the volume could run out of space, resulting in undefined behavior or data corruption, depending on how the volume is used. These effects can also occur when +the volume size is changed while it is in use (particularly when shrinking the size). Extreme care should be used when adjusting the volume size. +.sp +Though not recommended, a "sparse volume" (also known as "thin provisioning") can be created by specifying the \fB-s\fR option to the "\fBzfs create -V\fR" command, or by changing the reservation after the volume has been created. +A "sparse volume" is a volume where the reservation is less then the volume size. Consequently, writes to a sparse volume can fail with \fBENOSPC\fR when the pool is low on space. For a sparse volume, changes to \fBvolsize\fR are not reflected in the reservation. .RE .sp .ne 2 .mk .na -\fBcanmount=\fBon\fR | \fBoff\fR\fR +\fBvscan=\fBon\fR|\fBoff\fR\fR .ad .sp .6 .RS 4n -If this property is set to "\fBoff\fR", the file system cannot be mounted, and is ignored by "\fBzfs mount -a\fR". This is similar to setting the "mountpoint" property to "\fBnone\fR", except -that the dataset still has a normal "mountpoint" property which can be inherited. This allows datasets to be used solely as a mechanism to inherit properties. One use case is to have two logically separate datasets have the same mountpoint, so that the children of both datasets appear -in the same directory, but may have different inherited characteristics. The default value is "\fBon\fR". -.sp -This property is not inherited. +Controls whether regular files should be scanned for viruses when a file is opened and closed. In addition to enabling this property, the virus scan service must also be enabled for virus scanning to occur. The default value is "off". .RE .sp @@ -670,31 +829,74 @@ Controls whether extended attributes are enabled for this file system. The defau .ne 2 .mk .na -\fBcopies=\fB1\fR | \fB2\fR | \fB3\fR\fR +\fBzoned=\fIon\fR | \fIoff\fR\fR .ad .sp .6 .RS 4n -Controls the number of copies of data stored for this dataset. These copies are in addition to any redundancy provided by the pool, for example, mirroring or raid-z. The copies are stored on different disks, if possible. The space used by multiple copies is charged to the associated -file and dataset, changing the "used" property and counting against quotas and reservations. +Controls whether the dataset is managed from a non-global zone. See the "Zones" section for more information. The default value is "off". +.RE + .sp -Changing this property only affects newly-written data. Therefore, set this property at file system creation time by using the "\fB-o\fR copies=" option. +.LP +The following three properties cannot be changed after the file system is created, and therefore, should be set when the file system is created. If the properties are not set with the "\fBzfs create\fR" command, these properties are inherited from the parent dataset. +If the parent dataset lacks these properties due to having been created prior to these features being supported, the new file system will have the default values for these properties. +.sp +.ne 2 +.mk +.na +\fBcasesensitivity = \fBsensitive\fR | \fBinsensitive\fR | \fBmixed\fR\fR +.ad +.sp .6 +.RS 4n +Indicates whether the file name matching algorithm used by the file system should be case-sensitive, case-insensitive, or allow a combination of both styles of matching. The default value for the "\fBcasesensitivity\fR" property is "\fBsensitive\fR." +Traditionally, UNIX and POSIX file systems have case-sensitive file names. +.sp +The "\fBmixed\fR" value for the "\fBcasesensitivity\fR" property indicates that the file system can support requests for both case-sensitive and case-insensitive matching behavior. Currently, case-insensitive matching behavior on a file system +that supports mixed behavior is limited to the Solaris CIFS server product. For more information about the "mixed" value behavior, see the \fIZFS Administration Guide\fR. +.RE + +.sp +.ne 2 +.mk +.na +\fBnormalization =\fBnone\fR | \fBformD\fR | \fBformKCf\fR\fR +.ad +.sp .6 +.RS 4n +Indicates whether the file system should perform a \fBunicode\fR normalization of file names whenever two file names are compared, and which normalization algorithm should be used. File names are always stored unmodified, names are normalized as part of any comparison +process. If this property is set to a legal value other than "\fBnone\fR," and the "\fButf8only\fR" property was left unspecified, the "\fButf8only\fR" property is automatically set to "\fBon\fR." +The default value of the "\fBnormalization\fR" property is "\fBnone\fR." This property cannot be changed after the file system is created. .RE .sp .ne 2 .mk .na -\fBjailed=\fIon\fR | \fIoff\fR\fR +\fBjailed =\fIon\fR | \fIoff\fR\fR .ad .sp .6 .RS 4n Controls whether the dataset is managed from within a jail. The default value is "off". .RE -.SS "iscsioptions" +.sp +.ne 2 +.mk +.na +\fButf8only =\fBon\fR | \fBoff\fR\fR +.ad +.sp .6 +.RS 4n +Indicates whether the file system should reject file names that include characters that are not present in the \fBUTF-8\fR character code set. If this property is explicitly set to "\fBoff\fR," the normalization property must either not be +explicitly set or be set to "\fBnone\fR." The default value for the "\fButf8only\fR" property is "off." This property cannot be changed after the file system is created. +.RE + +.sp .LP -This read-only property, which is hidden, is used by the \fBiSCSI\fR target daemon to store persistent information, such as the \fBIQN\fR. It cannot be viewed or modified using the \fBzfs\fR command. The contents are not intended for external consumers. +The "\fBcasesensitivity\fR," "\fBnormalization\fR," and "\fButf8only\fR" properties are also new permissions that can be assigned to non-privileged users by using the \fBZFS\fR delegated administration +feature. .SS "Temporary Mount Point Properties" +.sp .LP When a file system is mounted, either through \fBmount\fR(1M) for legacy mounts or the "\fBzfs mount\fR" command for normal file systems, its mount options are set according to its properties. The correlation between properties and mount options is as follows: @@ -711,30 +913,39 @@ its mount options are set according to its properties. The correlation between p .in -2 .sp +.sp .LP In addition, these options can be set on a per-mount basis using the \fB-o\fR option, without affecting the property that is stored on disk. The values specified on the command line override the values stored in the dataset. The \fB-nosuid\fR option is an alias for "nodevices,nosetuid". These properties are reported as "temporary" by the "\fBzfs get\fR" command. If the properties are changed while the dataset is mounted, the new setting overrides any temporary settings. .SS "User Properties" +.sp .LP In addition to the standard native properties, \fBZFS\fR supports arbitrary user properties. User properties have no effect on \fBZFS\fR behavior, but applications or administrators can use them to annotate datasets. +.sp .LP User property names must contain a colon (":") character, to distinguish them from native properties. They might contain lowercase letters, numbers, and the following punctuation characters: colon (":"), dash ("-"), period ("."), and underscore ("_"). The expected convention is that the property name is divided into two portions such as "\fImodule\fR:\fIproperty\fR", but this namespace is not enforced by \fBZFS\fR. User property names can be at most 256 characters, and cannot begin with a dash ("-"). +.sp .LP When making programmatic use of user properties, it is strongly suggested to use a reversed \fBDNS\fR domain name for the \fImodule\fR component of property names to reduce the chance that two independently-developed packages use the same property name for different purposes. Property names beginning with "com.sun." are reserved for use by Sun Microsystems. +.sp .LP The values of user properties are arbitrary strings, are always inherited, and are never validated. All of the commands that operate on properties ("zfs list", "zfs get", "zfs set", etc.) can be used to manipulate both native properties and user properties. Use the "\fBzfs inherit\fR" command to clear a user property . If the property is not defined in any parent dataset, it is removed entirely. Property values are limited to 1024 characters. .SS "Volumes as Swap or Dump Devices" +.sp .LP To set up a swap area, create a \fBZFS\fR volume of a specific size and then enable swap on that device. For more information, see the EXAMPLES section. +.sp .LP Do not swap to a file on a \fBZFS\fR file system. A \fBZFS\fR swap file configuration is not supported. +.sp .LP Using a \fBZFS\fR volume as a dump device is not supported. .SH SUBCOMMANDS +.sp .LP All subcommands that modify state are logged persistently to the pool in their original form. .sp @@ -752,7 +963,7 @@ Displays a help message. .ne 2 .mk .na -\fB\fBzfs create\fR [[\fB-o\fR property=value]...] \fIfilesystem\fR\fR +\fB\fBzfs create\fR [\fB-p\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR] ... \fIfilesystem\fR\fR .ad .sp .6 .RS 4n @@ -761,7 +972,19 @@ Creates a new \fBZFS\fR file system. The file system is automatically mounted ac .ne 2 .mk .na -\fB\fB-o\fR property=value\fR +\fB\fB-p\fR\fR +.ad +.RS 21n +.rt +Creates all the non-existing parent datasets. Datasets created in this manner are automatically mounted according to the "mountpoint" property inherited from their parent. Any property specified on the command line using the \fB-o\fR option is ignored. If +the target filesystem already exists, the operation completes successfully. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fB-o\fR \fIproperty\fR=\fIvalue\fR\fR .ad .RS 21n .rt @@ -775,7 +998,7 @@ error results if the same property is specified in multiple \fB-o\fR options. .ne 2 .mk .na -\fB\fBzfs create\fR [\fB-s\fR] [\fB-b\fR \fIblocksize\fR] [[\fB-o\fR property=value]...] \fB-V\fR \fIsize\fR \fIvolume\fR\fR +\fB\fBzfs create\fR [\fB-ps\fR] [\fB-b\fR \fIblocksize\fR] [\fB-o\fR \fIproperty\fR=\fIvalue\fR] ... \fB-V\fR \fIsize\fR \fIvolume\fR\fR .ad .sp .6 .RS 4n @@ -787,6 +1010,18 @@ the logical size as exported by the device. By default, a reservation of equal s .ne 2 .mk .na +\fB\fB-p\fR\fR +.ad +.RS 21n +.rt +Creates all the non-existing parent datasets. Datasets created in this manner are automatically mounted according to the "mountpoint" property inherited from their parent. Any property specified on the command line using the \fB-o\fR option is ignored. If +the target filesystem already exists, the operation completes successfully. +.RE + +.sp +.ne 2 +.mk +.na \fB\fB-s\fR\fR .ad .RS 21n @@ -798,7 +1033,7 @@ Creates a sparse volume with no reservation. See "volsize" in the Native Propert .ne 2 .mk .na -\fB\fB-o\fR property=value\fR +\fB\fB-o\fR \fIproperty\fR=\fIvalue\fR\fR .ad .RS 21n .rt @@ -837,7 +1072,7 @@ Destroys the given dataset. By default, the command unshares any file systems th .ad .RS 6n .rt -Recursively destroy all children. If a snapshot is specified, destroy all snapshots with this name in descendant file systems. +Recursively destroy all children. If a snapshot is specified, destroy all snapshots with this name in descendent file systems. .RE .sp @@ -848,7 +1083,7 @@ Recursively destroy all children. If a snapshot is specified, destroy all snapsh .ad .RS 6n .rt -Recursively destroy all dependents, including cloned file systems outside the target hierarchy. If a snapshot is specified, destroy all snapshots with this name in descendant file systems. +Recursively destroy all dependents, including cloned file systems outside the target hierarchy. If a snapshot is specified, destroy all snapshots with this name in descendent file systems. .RE .sp @@ -869,58 +1104,65 @@ Extreme care should be taken when applying either the \fB-r\fR or the \fB-f\fR o .ne 2 .mk .na -\fB\fBzfs clone\fR \fIsnapshot\fR \fIfilesystem\fR|\fIvolume\fR\fR +\fB\fBzfs snapshot\fR [\fB-r\fR] \fIfilesystem@snapname\fR|\fIvolume@snapname\fR\fR .ad .sp .6 .RS 4n -Creates a clone of the given snapshot. See the "Clones" section for details. The target dataset can be located anywhere in the \fBZFS\fR hierarchy, and is created as the same type as the original. -.RE - +Creates a snapshot with the given name. See the "Snapshots" section for details. .sp .ne 2 .mk .na -\fB\fBzfs promote\fR \fIfilesystem\fR\fR +\fB\fB-r\fR\fR .ad -.sp .6 -.RS 4n -Promotes a clone file system to no longer be dependent on its "origin" snapshot. This makes it possible to destroy the file system that the clone was created from. The clone parent-child dependency relationship is reversed, so that the "origin" file system -becomes a clone of the specified file system. -.sp -The snaphot that was cloned, and any snapshots previous to this snapshot, are now owned by the promoted clone. The space they use moves from the "origin" file system to the promoted clone, so enough space must be available to accommodate these snapshots. No new space is consumed -by this operation, but the space accounting is adjusted. The promoted clone must not have any conflicting snapshot names of its own. The "\fBrename\fR" subcommand can be used to rename any conflicting snapshots. +.RS 6n +.rt +Recursively create snapshots of all descendent datasets. Snapshots are taken atomically, so that all recursive snapshots correspond to the same moment in time. +.RE + .RE .sp .ne 2 .mk .na -\fB\fBzfs rename\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR\fR +\fB\fBzfs rollback\fR [\fB-rRf\fR] \fIsnapshot\fR\fR .ad .sp .6 .RS 4n -Renames the given dataset. The new target can be located anywhere in the \fBZFS\fR hierarchy, with the exception of snapshots. Snapshots can only be renamed within the parent file system or volume. When renaming a snapshot, the parent file system of the snapshot does -not need to be specified as part of the second argument. Renamed file systems can inherit new mount points, in which case they are unmounted and remounted at the new mount point. +Roll back the given dataset to a previous snapshot. When a dataset is rolled back, all data that has changed since the snapshot is discarded, and the dataset reverts to the state at the time of the snapshot. By default, the command refuses to roll back to a snapshot other than +the most recent one. In order to do so, all intermediate snapshots must be destroyed by specifying the \fB-r\fR option. +.sp +.ne 2 +.mk +.na +\fB\fB-r\fR\fR +.ad +.RS 6n +.rt +Recursively destroy any snapshots more recent than the one specified. .RE .sp .ne 2 .mk .na -\fB\fBzfs snapshot\fR [\fB-r\fR] \fIfilesystem@name\fR|\fIvolume@name\fR\fR +\fB\fB-R\fR\fR .ad -.sp .6 -.RS 4n -Creates a snapshot with the given name. See the "Snapshots" section for details. +.RS 6n +.rt +Recursively destroy any more recent snapshots, as well as any clones of those snapshots. +.RE + .sp .ne 2 .mk .na -\fB\fB-r\fR\fR +\fB\fB-f\fR\fR .ad .RS 6n .rt -Recursively create snapshots of all descendant datasets. Snapshots are taken atomically, so that all recursive snapshots correspond to the same moment in time. +Used with the \fB-R\fR option to force an unmount of any clone file systems that are to be destroyed. .RE .RE @@ -929,43 +1171,67 @@ Recursively create snapshots of all descendant datasets. Snapshots are taken ato .ne 2 .mk .na -\fB\fBzfs rollback\fR [\fB-rRf\fR] \fIsnapshot\fR\fR +\fB\fBzfs clone\fR [\fB-p\fR] \fIsnapshot\fR \fIfilesystem\fR|\fIvolume\fR\fR .ad .sp .6 .RS 4n -Roll back the given dataset to a previous snapshot. When a dataset is rolled back, all data that has changed since the snapshot is discarded, and the dataset reverts to the state at the time of the snapshot. By default, the command refuses to roll back to a snapshot other than -the most recent one. In order to do so, all intermediate snapshots must be destroyed by specifying the \fB-r\fR option. The file system is unmounted and remounted, if necessary. +Creates a clone of the given snapshot. See the "Clones" section for details. The target dataset can be located anywhere in the \fBZFS\fR hierarchy, and is created as the same type as the original. .sp .ne 2 .mk .na -\fB\fB-r\fR\fR +\fB\fB-p\fR\fR .ad .RS 6n .rt -Recursively destroy any snapshots more recent than the one specified. +Creates all the non-existing parent datasets. Datasets created in this manner are automatically mounted according to the "mountpoint" property inherited from their parent. If the target filesystem or volume already exists, the operation completes successfully. +.RE + .RE .sp .ne 2 .mk .na -\fB\fB-R\fR\fR +\fB\fBzfs promote\fR \fIclone-filesystem\fR\fR .ad -.RS 6n -.rt -Recursively destroy any more recent snapshots, as well as any clones of those snapshots. +.sp .6 +.RS 4n +Promotes a clone file system to no longer be dependent on its "origin" snapshot. This makes it possible to destroy the file system that the clone was created from. The clone parent-child dependency relationship is reversed, so that the "origin" file system +becomes a clone of the specified file system. +.sp +The snapshot that was cloned, and any snapshots previous to this snapshot, are now owned by the promoted clone. The space they use moves from the "origin" file system to the promoted clone, so enough space must be available to accommodate these snapshots. No new space is consumed +by this operation, but the space accounting is adjusted. The promoted clone must not have any conflicting snapshot names of its own. The "\fBrename\fR" subcommand can be used to rename any conflicting snapshots. .RE .sp .ne 2 .mk .na -\fB\fB-f\fR\fR +\fB\fBzfs rename\fR \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR\fR +.ad +.br +.na +\fB\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR\fR +.ad +.br +.na +\fB\fBzfs +rename\fR [\fB-p\fR] \fIfilesystem\fR|\fIvolume\fR \fIfilesystem\fR|\fIvolume\fR\fR +.ad +.sp .6 +.RS 4n +Renames the given dataset. The new target can be located anywhere in the \fBZFS\fR hierarchy, with the exception of snapshots. Snapshots can only be renamed within the parent file system or volume. When renaming a snapshot, the parent file system of the snapshot does +not need to be specified as part of the second argument. Renamed file systems can inherit new mount points, in which case they are unmounted and remounted at the new mount point. +.sp +.ne 2 +.mk +.na +\fB\fB-p\fR\fR .ad .RS 6n .rt -Force an unmount of any file systems using the "\fBunmount -f\fR" command. +Creates all the non-existing parent datasets. Datasets created in this manner are automatically mounted according to the "mountpoint" property inherited from their parent. .RE .RE @@ -974,7 +1240,22 @@ Force an unmount of any file systems using the "\fBunmount -f\fR" command. .ne 2 .mk .na -\fB\fBzfs\fR \fBlist\fR [\fB-rH\fR] [\fB-o\fR \fIprop\fR[,\fIprop\fR] ]... [ \fB-t\fR \fItype\fR[,\fItype\fR]...] [ \fB-s\fR \fIprop\fR [\fB-s\fR \fIprop\fR]... [ \fB-S\fR \fIprop\fR [\fB-S\fR \fIprop\fR]... [\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR|\fI/pathname\fR|.\fI/pathname\fR ...\fR +\fB\fBzfs rename\fR \fB-r\fR \fIsnapshot\fR \fIsnapshot\fR\fR +.ad +.sp .6 +.RS 4n +Recursively rename the snapshots of all descendent datasets. Snapshots are the only dataset that can be renamed recursively. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBzfs\fR \fBlist\fR [\fB-rH\fR] [\fB-o\fR \fIproperty\fR[,\fI\&...\fR]] [ \fB-t\fR \fItype\fR[,\fI\&...\fR]]\fR +.ad +.br +.na +\fB[ \fB-s\fR \fIproperty\fR ] ... [ \fB-S\fR \fIproperty\fR ] ... [\fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR] ...\fR .ad .sp .6 .RS 4n @@ -993,7 +1274,7 @@ name,used,available,referenced,mountpoint .na \fB\fB-H\fR\fR .ad -.RS 11n +.RS 15n .rt Used for scripting mode. Do not print headers and separate fields by a single tab instead of arbitrary whitespace. .RE @@ -1004,7 +1285,7 @@ Used for scripting mode. Do not print headers and separate fields by a single ta .na \fB\fB-r\fR\fR .ad -.RS 11n +.RS 15n .rt Recursively display any children of the dataset on the command line. .RE @@ -1013,9 +1294,9 @@ Recursively display any children of the dataset on the command line. .ne 2 .mk .na -\fB\fB-o\fR \fIprop\fR\fR +\fB\fB-o\fR \fIproperty\fR\fR .ad -.RS 11n +.RS 15n .rt A comma-separated list of properties to display. The property must be one of the properties described in the "Native Properties" section, or the special value "name" to display the dataset name. .RE @@ -1024,12 +1305,12 @@ A comma-separated list of properties to display. The property must be one of the .ne 2 .mk .na -\fB\fB-s\fR \fIprop\fR\fR +\fB\fB-s\fR \fIproperty\fR\fR .ad -.RS 11n +.RS 15n .rt A property to use for sorting the output by column in ascending order based on the value of the property. The property must be one of the properties described in the "Properties" section, or the special value "name" to sort by the dataset name. Multiple -properties can be specified at one time using multiple \fB-s\fR property options. Multiple \fB-s\fR options are evaluated from left to right in decreasing order of importance. +properties can be specified at one time using multiple \fB-s\fR property options. Multiple \fB-s\fR options are evaluated from left to right in decreasing order of importance. .sp The following is a list of sorting criteria: .RS +4 @@ -1062,9 +1343,9 @@ If no sorting options are specified the existing behavior of "\fBzfs list\fR" is .ne 2 .mk .na -\fB\fB-S\fR \fIprop\fR\fR +\fB\fB-S\fR \fIproperty\fR\fR .ad -.RS 11n +.RS 15n .rt Same as the \fB-s\fR option, but sorts by property in descending order. .RE @@ -1075,7 +1356,7 @@ Same as the \fB-s\fR option, but sorts by property in descending order. .na \fB\fB-t\fR \fItype\fR\fR .ad -.RS 11n +.RS 15n .rt A comma-separated list of types to display, where "type" is one of "filesystem", "snapshot" or "volume". For example, specifying "\fB-t snapshot\fR" displays only snapshots. .RE @@ -1098,7 +1379,7 @@ form with a suffix of "B", "K", "M", "G", "T", "P", "E", "Z" (for bytes, Kbytes, .ne 2 .mk .na -\fB\fBzfs get\fR [\fB-rHp\fR] [\fB-o\fR \fIfield\fR[,\fIfield\fR]...] [\fB-s\fR \fIsource\fR[,\fIsource\fR]...] \fIall\fR | \fIproperty\fR[,\fIproperty\fR]... \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ...\fR +\fB\fBzfs get\fR [\fB-rHp\fR] [\fB-o\fR \fIfield\fR[,...] [\fB-s\fR \fIsource\fR[,...] "\fIall\fR" | \fIproperty\fR[,...] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ...\fR .ad .sp .6 .RS 4n @@ -1201,42 +1482,70 @@ Recursively inherit the given property for all children. .ne 2 .mk .na -\fB\fBzfs mount\fR\fR +\fB\fBzfs upgrade\fR [\fB-v\fR]\fR .ad .sp .6 .RS 4n -Displays all \fBZFS\fR file systems currently mounted. +Displays a list of file systems that are not the most recent version. .RE .sp .ne 2 .mk .na -\fB\fBzfs mount\fR[\fB-o\fR \fIopts\fR] [\fB-O\fR] \fB-a\fR\fR +\fB\fBzfs upgrade\fR [\fB-r\fR] [\fB-V\fR \fIversion\fR] [\fB-a\fR | \fIfilesystem\fR]\fR .ad .sp .6 .RS 4n -Mounts all available \fBZFS\fR file systems. Invoked automatically as part of the boot process. +Upgrades file systems to a new on-disk version. Once this is done, the file systems will no longer be accessible on systems running older versions of the software. "\fBzfs send\fR" streams generated from new snapshots of these file systems can not be accessed +on systems running older versions of the software. +.sp +The file system version is independent of the pool version (see \fBzpool\fR(1M) for information on the "\fBzpool upgrade\fR" command). +.sp +The file system version does not have to be upgraded when the pool version is upgraded, and vice versa. .sp .ne 2 .mk .na -\fB\fB-o\fR \fIopts\fR\fR +\fB\fB-a\fR\fR .ad -.RS 11n +.RS 14n .rt -An optional comma-separated list of mount options to use temporarily for the duration of the mount. See the "Temporary Mount Point Properties" section for details. +Upgrade all file systems on all imported pools. .RE .sp .ne 2 .mk .na -\fB\fB-O\fR\fR +\fB\fIfilesystem\fR\fR .ad -.RS 11n +.RS 14n .rt -Perform an overlay mount. See \fBmount\fR(1M) for more information. +Upgrade the specified file system. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fB-r\fR\fR +.ad +.RS 14n +.rt +Upgrade the specified file system and all descendent file systems +.RE + +.sp +.ne 2 +.mk +.na +\fB\fB-V\fR \fIversion\fR\fR +.ad +.RS 14n +.rt +Upgrade to the specified \fIversion\fR. If the \fB-V\fR flag is not specified, this command upgrades to the most recent version. This option can only be used to increase the version number, and only up to the most recent version supported by this +software. .RE .RE @@ -1245,18 +1554,29 @@ Perform an overlay mount. See \fBmount\fR(1M) for more information. .ne 2 .mk .na -\fB\fBzfs mount\fR [\fB-o\fR \fIopts\fR] [\fB-O\fR] \fIfilesystem\fR\fR +\fB\fBzfs mount\fR\fR .ad .sp .6 .RS 4n -Mounts a specific \fBZFS\fR file system. This is typically not necessary, as file systems are automatically mounted when they are created or the mountpoint property has changed. See the "Mount Points" section for details. +Displays all \fBZFS\fR file systems currently mounted. +.RE + .sp .ne 2 .mk .na -\fB\fB-o\fR \fIopts\fR\fR +\fB\fBzfs mount\fR [\fB-vO\fR] [\fB-o\fR \fIoptions\fR] \fB-a\fR | \fIfilesystem\fR\fR .ad -.RS 11n +.sp .6 +.RS 4n +Mounts \fBZFS\fR file systems. Invoked automatically as part of the boot process. +.sp +.ne 2 +.mk +.na +\fB\fB-o\fR \fIoptions\fR\fR +.ad +.RS 14n .rt An optional comma-separated list of mount options to use temporarily for the duration of the mount. See the "Temporary Mount Point Properties" section for details. .RE @@ -1267,97 +1587,152 @@ An optional comma-separated list of mount options to use temporarily for the dur .na \fB\fB-O\fR\fR .ad -.RS 11n +.RS 14n .rt Perform an overlay mount. See \fBmount\fR(1M) for more information. .RE +.sp +.ne 2 +.mk +.na +\fB\fB-v\fR\fR +.ad +.RS 14n +.rt +Report mount progress. .RE .sp .ne 2 .mk .na -\fB\fBzfs unmount\fR \fB-a\fR\fR +\fB\fB-a\fR\fR .ad -.sp .6 -.RS 4n -Unmounts all currently mounted \fBZFS\fR file systems. Invoked automatically as part of the shutdown process. +.RS 14n +.rt +Mount all available \fBZFS\fR file systems. Invoked automatically as part of the boot process. .RE .sp .ne 2 .mk .na -\fB\fBzfs unmount\fR [\fB-f\fR] \fIfilesystem\fR|\fImountpoint\fR\fR +\fB\fIfilesystem\fR\fR +.ad +.RS 14n +.rt +Mount the specified filesystem. +.RE + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBzfs unmount\fR [\fB-f\fR] \fB-a\fR | \fIfilesystem\fR|\fImountpoint\fR\fR .ad .sp .6 .RS 4n -Unmounts the given file system. The command can also be given a path to a \fBZFS\fR file system mount point on the system. +Unmounts currently mounted \fBZFS\fR file systems. Invoked automatically as part of the shutdown process. .sp .ne 2 .mk .na \fB\fB-f\fR\fR .ad -.RS 6n +.RS 25n .rt Forcefully unmount the file system, even if it is currently in use. .RE +.sp +.ne 2 +.mk +.na +\fB\fB-a\fR\fR +.ad +.RS 25n +.rt +Unmount all available \fBZFS\fR file systems. Invoked automatically as part of the boot process. .RE .sp .ne 2 .mk .na -\fB\fBzfs share\fR \fB-a\fR\fR +\fB\fIfilesystem\fR|\fImountpoint\fR\fR .ad -.sp .6 -.RS 4n -Shares all available \fBZFS\fR file systems. This is invoked automatically as part of the boot process. +.RS 25n +.rt +Unmount the specified filesystem. The command can also be given a path to a \fBZFS\fR file system mount point on the system. +.RE + .RE .sp .ne 2 .mk .na -\fB\fBzfs share\fR \fIfilesystem\fR\fR +\fB\fBzfs share\fR \fB-a\fR | \fIfilesystem\fR\fR .ad .sp .6 .RS 4n -Shares a specific \fBZFS\fR file system according to the "sharenfs" property. File systems are shared when the "sharenfs" property is set. +Shares available \fBZFS\fR file systems. +.sp +.ne 2 +.mk +.na +\fB\fB-a\fR\fR +.ad +.RS 14n +.rt +Share all available \fBZFS\fR file systems. Invoked automatically as part of the boot process. .RE .sp .ne 2 .mk .na -\fB\fBzfs unshare\fR \fB-a\fR\fR +\fB\fIfilesystem\fR\fR .ad -.sp .6 -.RS 4n -Unshares all currently shared \fBZFS\fR file systems. This is invoked automatically as part of the shutdown process. +.RS 14n +.rt +Share the specified filesystem according to the "sharenfs" and "sharesmb" properties. File systems are shared when the "sharenfs" or "sharesmb" property is set. +.RE + .RE .sp .ne 2 .mk .na -\fB\fBzfs unshare\fR [\fB-F\fR] \fIfilesystem\fR|\fImountpoint\fR\fR +\fB\fBzfs unshare\fR \fB-a\fR | \fIfilesystem\fR|\fImountpoint\fR\fR .ad .sp .6 .RS 4n -Unshares the given file system. The command can also be given a path to a \fBZFS\fR file system shared on the system. +Unshares currently shared \fBZFS\fR file systems. This is invoked automatically as part of the shutdown process. .sp .ne 2 .mk .na -\fB\fB-F\fR\fR +\fB\fB-a\fR\fR .ad -.RS 6n +.RS 25n .rt -Forcefully unshare the file system, even if it is currently in use. +Unshare all available \fBZFS\fR file systems. Invoked automatically as part of the boot process. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fIfilesystem\fR|\fImountpoint\fR\fR +.ad +.RS 25n +.rt +Unshare the specified filesystem. The command can also be given a path to a \fBZFS\fR file system shared on the system. .RE .RE @@ -1366,27 +1741,64 @@ Forcefully unshare the file system, even if it is currently in use. .ne 2 .mk .na -\fB\fBzfs send\fR [\fB-i\fR \fIsnapshot1\fR] \fIsnapshot2\fR\fR +\fB\fBzfs send\fR [\fB-vR\fR] [\fB-\fR[\fB-iI\fR] \fIsnapshot\fR] \fIsnapshot\fR\fR .ad .sp .6 .RS 4n -Creates a stream representation of snapshot2, which is written to standard output. The output can be redirected to a file or to a different system (for example, using \fBssh\fR(1). By default, a full stream is generated. +Creates a stream representation of the second \fIsnapshot\fR, which is written to standard output. The output can be redirected to a file or to a different system (for example, using \fBssh\fR(1). By default, a full stream is generated. .sp .ne 2 .mk .na -\fB\fB-i\fR \fIsnapshot1\fR\fR +\fB\fB-i\fR \fIsnapshot\fR\fR .ad -.RS 16n +.RS 15n .rt -Generate an incremental stream from \fIsnapshot1\fR to \fIsnapshot2\fR. The incremental source \fIsnapshot1\fR can be specified as the last component of the snapshot name (for example, the part after the "@"), -and it is assumed to be from the same file system as \fIsnapshot2\fR. +Generate an incremental stream from the first \fIsnapshot\fR to the second \fIsnapshot\fR. The incremental source (the first \fIsnapshot\fR) can be specified as the last component of the snapshot name (for example, +the part after the "@"), and it is assumed to be from the same file system as the second \fIsnapshot\fR. +.sp +If the destination is a clone, the source may be the origin snapshot, which must be fully specified (for example, "pool/fs@origin", not just "@origin"). .RE +.sp +.ne 2 +.mk +.na +\fB\fB-I\fR \fIsnapshot\fR\fR +.ad +.RS 15n +.rt +Generate a stream package that sends all intermediary snapshots from the first snapshot to the second snapshot. For example, "\fB-I @a fs@d\fR" is similar to "\fB-i @a fs@b; -i @b fs@c; -i @c fs@d\fR". The incremental source snapshot +may be specified as with the \fB-i\fR option. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fB-R\fR\fR +.ad +.RS 15n +.rt +Generate a replication stream package, which will replicate the specified filesystem, and all descendant file systems, up to the named snapshot. When received, all properties, snapshots, descendent file systems, and clones are preserved. +.sp +If the \fB-i\fR or \fB-I\fR flags are used in conjunction with the \fB-R\fR flag, an incremental replication stream is generated. The current values of properties, and current snapshot and file system names are set when the stream is received. If the \fB-F\fR flag is specified when this stream is recieved, snapshots and file systems that do not exist on the sending side are destroyed. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fB-v\fR\fR +.ad +.RS 15n +.rt +Print verbose information about the stream package generated. .RE -.LP The format of the stream is evolving. No backwards compatibility is guaranteed. You may not be able to receive your streams on future versions of \fBZFS\fR. +.RE + .sp .ne 2 .mk @@ -1402,7 +1814,8 @@ The format of the stream is evolving. No backwards compatibility is guaranteed. Creates a snapshot whose contents are as specified in the stream provided on standard input. If a full stream is received, then a new file system is created as well. Streams are created using the "\fBzfs send\fR" subcommand, which by default creates a full stream. "\fBzfs recv\fR" can be used as an alias for "\fBzfs receive\fR". .sp -If an incremental stream is received, then the destination file system must already exist, and its most recent snapshot must match the incremental stream's source. The destination file system and all of its child file systems are unmounted and cannot be accessed during the receive operation. +If an incremental stream is received, then the destination file system must already exist, and its most recent snapshot must match the incremental stream's source. For \fBzvols\fR, the destination device link is destroyed and re-created, which means the \fBzvol\fR cannot +be accessed during the \fBreceive\fR operation. .sp The name of the snapshot (and file system, if a full stream is received) that this subcommand creates depends on the argument type and the \fB-d\fR option. .sp @@ -1438,7 +1851,7 @@ Print verbose information about the stream and the time required to perform the .ad .RS 6n .rt -Do not actually receive the stream. This can be useful in conjunction with the \fB-v\fR option to determine what name the receive operation would use. +Do not actually receive the stream. This can be useful in conjunction with the \fB-v\fR option to verify the name the receive operation would use. .RE .sp @@ -1449,7 +1862,8 @@ Do not actually receive the stream. This can be useful in conjunction with the \ .ad .RS 6n .rt -Force a rollback of the \fIfilesystem\fR to the most recent snapshot before performing the receive operation. +Force a rollback of the file system to the most recent snapshot before performing the receive operation. If receiving an incremental replication stream (for example, one generated by "z\fBfs send -R -[iI]\fR"), destroy snapshots and file systems that do +not exist on the sending side. .RE .RE @@ -1458,6 +1872,186 @@ Force a rollback of the \fIfilesystem\fR to the most recent snapshot before perf .ne 2 .mk .na +\fB\fBzfs allow\fR [\fB-ldug\fR] "\fIeveryone\fR"|\fIuser\fR|\fIgroup\fR[,...] \fIperm\fR|@\fIsetname\fR[,...] \fIfilesystem\fR| \fIvolume\fR\fR +.ad +.br +.na +\fB\fBzfs allow\fR [\fB-ld\fR] \fB-e\fR \fIperm\fR|@\fIsetname\fR[,...] \fIfilesystem\fR|\fIvolume\fR\fR +.ad +.sp .6 +.RS 4n +Delegates \fBZFS\fR administration permission for the file systems to non-privileged users. +.sp +.ne 2 +.mk +.na +\fB[\fB-ug\fR] "\fIeveryone\fR"|\fIuser\fR|\fIgroup\fR[,...]\fR +.ad +.sp .6 +.RS 4n +Specifies to whom the permissions are delegated. Multiple entities can be specified as a comma-separated list. If neither of the \fB-ug\fR options are specified, then the argument is interpreted preferentially as the keyword "everyone", then as a user name, +and lastly as a group name. To specify a user or group named "everyone", use the \fB-u\fR or \fB-g\fR options. To specify a group with the same name as a user, use the \fB-g\fR options. +.RE + +.sp +.ne 2 +.mk +.na +\fB[\fB-e\fR] \fIperm\fR|@\fIsetname\fR[,...]\fR +.ad +.sp .6 +.RS 4n +Specifies that the permissions be delegated to "everyone." Multiple permissions may be specified as a comma-separated list. Permission names are the same as \fBZFS\fR subcommand and property names. See the property list below. Property set names, which +begin with an "at sign" ("@") , may be specified. See the \fB-s\fR form below for details. +.RE + +.sp +.ne 2 +.mk +.na +\fB[\fB-ld\fR] \fIfilesystem\fR|\fIvolume\fR\fR +.ad +.sp .6 +.RS 4n +Specifies where the permissions are delegated. If neither of the \fB-ld\fR options are specified, or both are, then the permissions are allowed for the file system or volume, and all of its descendents. If only the \fB-l\fR option is used, then is allowed "locally" +only for the specified file system. If only the \fB-d\fR option is used, then is allowed only for the descendent file systems. +.RE + +.RE + +.sp +.LP +Permissions are generally the ability to use a \fBZFS\fR subcommand or change a \fBZFS\fR property. The following permissions are available: +.sp +.in +2 +.nf +NAME TYPE NOTES +allow subcommand Must also have the permission + that is being allowed. +clone subcommand Must also have the 'create' ability + and the 'mount' ability in the origin + file system. +create subcommand Must also have the 'mount' ability. +destroy subcommand Must also have the 'mount' ability. +mount subcommand Allows mount, unmount, and + create/remove zvol device links. +promote subcommand Must also have the 'mount' ability and + 'promote' ability in the origin file system. +receive subcommand Must also have the 'mount' ability and + the 'create' ability. +rename subcommand Must also have the 'mount' ability and + the 'create' ability in the new parent. +rollback subcommand Must also have the 'mount' ability. +snapshot subcommand Must also have the 'mount' ability. +share subcommand Allows share and unshare. +send subcommand + + +aclinherit property +aclmode property +atime property +canmount property +checksum property +compression property +copies property +devices property +exec property +mountpoint property +quota property +readonly property +recordsize property +reservation property +setuid property +shareiscsi property +sharenfs property +snapdir property +version property +volsize property +xattr property +zoned property +userprop other Allows changing any user property. +.fi +.in -2 +.sp + +.sp +.ne 2 +.mk +.na +\fB\fBzfs allow\fR \fB-c\fR \fIperm\fR|@\fIsetname\fR[,...] \fIfilesystem\fR|\fIvolume\fR\fR +.ad +.sp .6 +.RS 4n +Sets "create time" permissions. These permissions are granted (locally) to the creator of any newly-created descendent file system. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBzfs allow\fR \fB-s\fR @setname \fIperm\fR|@\fIsetname\fR[,...] \fIfilesystem\fR|\fIvolume\fR\fR +.ad +.sp .6 +.RS 4n +Defines or adds permissions to a permission set. The set can be used by other \fBzfs allow\fR commands for the specified file system and its descendents. Sets are evaluated dynamically, so changes to a set are immediately reflected. Permission sets follow the same +naming restrictions as ZFS file systems, but the name must begin with an "at sign" ("@"), and can be no more than 64 characters long. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBzfs unallow\fR [\fB-rldug\fR] "\fIeveryone\fR"|\fIuser\fR|\fIgroup\fR[,...] [\fIperm\fR|@\fIsetname\fR[, ...]] \fIfilesystem\fR|\fIvolume\fR\fR +.ad +.br +.na +\fB\fBzfs unallow\fR [\fB-rld\fR] \fB-e\fR [\fIperm\fR|@\fIsetname\fR [,...]] \fIfilesystem\fR|\fIvolume\fR\fR +.ad +.br +.na +\fB\fBzfs unallow\fR [\fB-r\fR] \fB-c\fR [\fIperm\fR|@\fIsetname\fR[,...]]\fR +.ad +.br +.na +\fB\fIfilesystem\fR|\fIvolume\fR\fR +.ad +.sp .6 +.RS 4n +Removes permissions that were granted with the "\fBzfs allow\fR" command. No permissions are explicitly denied, so other permissions granted are still in effect. For example, if the permission is granted by an ancestor. If no permissions are specified, +then all permissions for the specified \fIuser\fR, \fIgroup\fR, or \fIeveryone\fR are removed. Specifying "everyone" (or using the \fB-e\fR option) only removes the permissions that were granted to "everyone", +not all permissions for every user and group. See the "\fBzfs allow\fR" command for a description of the \fB-ldugec\fR options. +.sp +.ne 2 +.mk +.na +\fB\fB-r\fR\fR +.ad +.RS 6n +.rt +Recursively remove the permissions from this file system and all descendents. +.RE + +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBzfs unallow\fR [\fB-r\fR] \fB-s\fR @setname [\fIperm\fR|@\fIsetname\fR[,...]]\fR +.ad +.br +.na +\fB\fIfilesystem\fR|\fIvolume\fR\fR +.ad +.sp .6 +.RS 4n +Removes permissions from a permission set. If no permissions are specified, then all permissions are removed, thus removing the set entirely. +.RE + +.sp +.ne 2 +.mk +.na \fB\fBzfs jail\fR \fIjailid\fR \fIfilesystem\fR\fR .ad .sp .6 @@ -1480,6 +2074,7 @@ Detaches the given file system from the given jail. .SH EXAMPLES .LP \fBExample 1 \fRCreating a ZFS File System Hierarchy +.sp .LP The following commands create a file system named "\fBpool/home\fR" and a file system named "\fBpool/home/bob\fR". The mount point "\fB/export/home\fR" is set for the parent file system, and automatically inherited by the child file system. @@ -1496,6 +2091,7 @@ by the child file system. .LP \fBExample 2 \fRCreating a ZFS Snapshot +.sp .LP The following command creates a snapshot named "yesterday". This snapshot is mounted on demand in the ".zfs/snapshot" directory at the root of the "\fBpool/home/bob\fR" file system. @@ -1509,8 +2105,9 @@ The following command creates a snapshot named "yesterday". This snapshot is mou .LP \fBExample 3 \fRTaking and destroying multiple snapshots +.sp .LP -The following command creates snapshots named "\fByesterday\fR" of "\fBpool/home\fR" and all of its descendant file systems. Each snapshot is mounted on demand in the ".zfs/snapshot" directory at the root of its file system. The +The following command creates snapshots named "\fByesterday\fR" of "\fBpool/home\fR" and all of its descendent file systems. Each snapshot is mounted on demand in the ".zfs/snapshot" directory at the root of its file system. The second command destroys the newly created snapshots. .sp @@ -1524,6 +2121,7 @@ second command destroys the newly created snapshots. .LP \fBExample 4 \fRTurning Off Compression +.sp .LP The following commands turn compression off for all file systems under "\fBpool/home\fR", but explicitly turns it on for "\fBpool/home/anne\fR". @@ -1538,6 +2136,7 @@ The following commands turn compression off for all file systems under "\fBpool/ .LP \fBExample 5 \fRListing ZFS Datasets +.sp .LP The following command lists all active file systems and volumes in the system. @@ -1548,17 +2147,18 @@ The following command lists all active file systems and volumes in the system. NAME USED AVAIL REFER MOUNTPOINT - pool 100G 60G - /pool - pool/home 100G 60G - /export/home - pool/home/bob 40G 60G 40G /export/home/bob - pool/home/bob@yesterday 3M - 40G - - pool/home/anne 60G 60G 40G /export/home/anne + pool 450K 457G 18K /pool + pool/home 315K 457G 21K /export/home + pool/home/anne 18K 457G 18K /export/home/anne + pool/home/bob 276K 457G 276K /export/home/bob + pool/home/bob@yesterday 0 - 276K - .fi .in -2 .sp .LP \fBExample 6 \fRSetting a Quota on a ZFS File System +.sp .LP The following command sets a quota of 50 gbytes for "\fBpool/home/bob\fR". @@ -1572,6 +2172,7 @@ The following command sets a quota of 50 gbytes for "\fBpool/home/bob\fR". .LP \fBExample 7 \fRListing ZFS Properties +.sp .LP The following command lists all properties for "\fBpool/home/bob\fR". @@ -1583,18 +2184,17 @@ The following command lists all properties for "\fBpool/home/bob\fR". NAME PROPERTY VALUE SOURCE pool/home/bob type filesystem - - pool/home/bob creation Fri Feb 23 14:20 2007 - - pool/home/bob used 24.5K - + pool/home/bob creation Thu Jul 12 14:44 2007 - + pool/home/bob used 276K - pool/home/bob available 50.0G - - pool/home/bob referenced 24.5K - + pool/home/bob referenced 276K - pool/home/bob compressratio 1.00x - pool/home/bob mounted yes - pool/home/bob quota 50G local pool/home/bob reservation none default pool/home/bob recordsize 128K default - pool/home/bob mountpoint /pool/home/bob default - pool/home/bob sharenfs off default - pool/home/bob shareiscsi off default + pool/home/bob mountpoint /export/home/bob inherited from + pool/home pool/home/bob checksum on default pool/home/bob compression off default pool/home/bob atime on default @@ -1605,15 +2205,24 @@ The following command lists all properties for "\fBpool/home/bob\fR". pool/home/bob zoned off default pool/home/bob snapdir hidden default pool/home/bob aclmode groupmask default - pool/home/bob aclinherit secure default + pool/home/bob aclinherit restricted default pool/home/bob canmount on default + pool/home/bob nbmand off default + pool/home/bob shareiscsi off default + pool/home/bob sharesmb off default + pool/home/bob sharenfs off default pool/home/bob xattr on default + pool/home/bob refquota 10M local + pool/home/bob refreservation none default + pool/home/bob copies 1 default + pool/home/bob version 1 - .fi .in -2 .sp +.sp .LP The following command gets a single property value. @@ -1626,6 +2235,7 @@ on .in -2 .sp +.sp .LP The following command lists all properties with local settings for "\fBpool/home/bob\fR". @@ -1643,6 +2253,7 @@ The following command lists all properties with local settings for "\fBpool/home .LP \fBExample 8 \fRRolling Back a ZFS File System +.sp .LP The following command reverts the contents of "\fBpool/home/anne\fR" to the snapshot named "\fByesterday\fR", deleting all intermediate snapshots. @@ -1656,6 +2267,7 @@ The following command reverts the contents of "\fBpool/home/anne\fR" to the snap .LP \fBExample 9 \fRCreating a ZFS Clone +.sp .LP The following command creates a writable file system whose initial contents are the same as "\fBpool/home/bob@yesterday\fR". @@ -1669,6 +2281,7 @@ The following command creates a writable file system whose initial contents are .LP \fBExample 10 \fRPromoting a ZFS Clone +.sp .LP The following commands illustrate how to test out changes to a file system, and then replace the original file system with the changed one, using clones, clone promotion, and renaming: @@ -1692,6 +2305,7 @@ The following commands illustrate how to test out changes to a file system, and .LP \fBExample 11 \fRInheriting ZFS Properties +.sp .LP The following command causes "\fBpool/home/bob\fR" and "\fBpool/home/anne\fR" to inherit the "checksum" property from their parent. @@ -1705,6 +2319,7 @@ The following command causes "\fBpool/home/bob\fR" and "\fBpool/home/anne\fR" to .LP \fBExample 12 \fRRemotely Replicating ZFS Data +.sp .LP The following commands send a full stream and then an incremental stream to a remote machine, restoring them into "\fBpoolB/received/fs\fR@a" and "\fBpoolB/received/fs@b\fR", respectively. "\fBpoolB\fR" must contain the file system "\fBpoolB/received\fR", and must not initially contain "\fBpoolB/received/fs\fR". @@ -1721,30 +2336,31 @@ the file system "\fBpoolB/received\fR", and must not initially contain "\fBpoolB .sp .LP -\fBExample 13 \fRUsing the zfs receive -d Option +\fBExample 13 \fRUsing the zfs receive -d Option +.sp .LP The following command sends a full stream of "\fBpoolA/fsA/fsB@snap\fR" to a remote machine, receiving it into "\fBpoolB/received/fsA/fsB@snap\fR". The "\fBfsA/fsB@snap\fR" portion of the received snapshot's name -is determined from the name of the sent snapshot. "\fBpoolB\fR" must contain the file system "\fBpoolB/received\fR". If "\fBpoolB/received/fsA\fR" does not exist, it will be created as an empty file system. +is determined from the name of the sent snapshot. "\fBpoolB\fR" must contain the file system "\fBpoolB/received\fR". If "\fBpoolB/received/fsA\fR" does not exist, it is be created as an empty file system. .sp .in +2 .nf \fB# zfs send poolA/fsA/fsB@snap | \e - ssh host zfs receive -d poolB/received - \fR + ssh host zfs receive -d poolB/received\fR .fi .in -2 .sp .LP \fBExample 14 \fRCreating a ZFS volume as a Swap Device +.sp .LP The following example shows how to create a 5-Gbyte ZFS volume and then add the volume as a swap device. .sp .in +2 .nf -\fB# zfs create -V 5gb tank/vol +\fB# zfs create -V 5gb tank/vol # swap -a /dev/zvol/dsk/tank/vol\fR .fi .in -2 @@ -1752,6 +2368,7 @@ The following example shows how to create a 5-Gbyte ZFS volume and then add the .LP \fBExample 15 \fRSetting User Properties +.sp .LP The following example sets the user defined "com.example:department" property for a dataset. @@ -1765,6 +2382,7 @@ The following example sets the user defined "com.example:department" property fo .LP \fBExample 16 \fRCreating a ZFS Volume as a iSCSI Target Device +.sp .LP The following example shows how to create a \fBZFS\fR volume as an \fBiSCSI\fR target. @@ -1782,9 +2400,173 @@ Connections: 0 .in -2 .sp +.sp .LP After the \fBiSCSI\fR target is created, set up the \fBiSCSI\fR initiator. For more information about the Solaris \fBiSCSI\fR initiator, see the Solaris Administration Guide: Devices and File Systems. +.LP +\fBExample 17 \fRPerforming a Rolling Snapshot +.sp +.LP +The following example shows how to maintain a history of snapshots with a consistent naming scheme. To keep a week's worth of snapshots, the user destroys the oldest snapshot, renames the remaining snapshots, and then creates a new snapshot, as follows: + +.sp +.in +2 +.nf +\fB# zfs destroy -r pool/users@7daysago +# zfs rename -r pool/users@6daysago @7daysago +# zfs rename -r pool/users@5daysago @6daysago +\&... +# zfs rename -r pool/users@yesterday @2daysago +# zfs rename -r pool/users@today @yesterday +# zfs snapshot -r pool/users@today\fR +.fi +.in -2 +.sp + +.LP +\fBExample 18 \fRSetting sharenfs Property Options on a ZFS File System +.sp +.LP +The following commands show how to set "sharenfs" property options to enable \fBrw\fR access for a set of \fBIP\fR addresses and to enable root access for system \fBneo\fR on the \fBtank/home\fR file system. + +.sp +.in +2 +.nf +\fB# zfs set sharenfs='rw=@123.123.0.0/16,root=neo' tank/home\fR + +.fi +.in -2 +.sp + +.sp +.LP +If you are using \fBDNS\fR for host name resolution, specify the fully qualified hostname. + +.LP +\fBExample 19 \fRDelegating ZFS Administration Permissions on a ZFS Dataset +.sp +.LP +The following example shows how to set permissions so that user "\fBcindys\fR" can create, destroy, mount and take snapshots on \fBtank/cindys\fR. The permissions on \fBtank/cindys\fR are also displayed. + +.sp +.in +2 +.nf +\fB# zfs allow cindys create,destroy,mount,snapshot tank/cindys +# zfs allow tank/cindys\fR +------------------------------------------------------------- +Local+Descendent permissions on (tank/cindys) + user cindys create,destroy,mount,snapshot +------------------------------------------------------------- + +.fi +.in -2 +.sp + +.sp +.LP +Because the \fBtank/cindys\fR mount point permission is set to 755 by default, user \fBcindys\fR will be unable to mount file systems under \fBtank/cindys\fR. Set an \fBACL\fR similar to the following syntax to provide mount point access: +.sp +.in +2 +.nf +# chmod A+user:cindys:add_subdirectory:allow /tank/cindys +.fi +.in -2 +.sp + +.LP +\fBExample 20 \fRDelegating Create Time Permissions on a ZFS Dataset +.sp +.LP +The following example shows how to grant anyone in the group \fBstaff\fR to create file systems in \fBtank/users\fR. This syntax also allows staff members to destroy their own file systems, but not destroy anyone else's file system. The permissions on \fBtank/users\fR are also displayed. + +.sp +.in +2 +.nf +\fB# zfs allow staff create,mount tank/users +# zfs allow -c destroy tank/users +# zfs allow tank/users\fR +------------------------------------------------------------- +Create time permissions on (tank/users) + create,destroy +Local+Descendent permissions on (tank/users) + group staff create,mount +------------------------------------------------------------- +.fi +.in -2 +.sp + +.LP +\fBExample 21 \fRDefining and Granting a Permission Set on a ZFS Dataset +.sp +.LP +The following example shows how to define and grant a permission set on the \fBtank/users\fR file system. The permissions on \fBtank/users\fR are also displayed. + +.sp +.in +2 +.nf +\fB# zfs allow -s @pset create,destroy,snapshot,mount tank/users +# zfs allow staff @pset tank/users +# zfs allow tank/users +------------------------------------------------------------- +Permission sets on (tank/users) + @pset create,destroy,mount,snapshot +Create time permissions on (tank/users) + create,destroy +Local+Descendent permissions on (tank/users) + group staff @pset,create,mount +-------------------------------------------------------------\fR +.fi +.in -2 +.sp + +.LP +\fBExample 22 \fRDelegating Property Permissions on a ZFS Dataset +.sp +.LP +The following example shows to grant the ability to set quotas and reservations on the \fBusers/home\fR file system. The permissions on \fBusers/home\fR are also displayed. + +.sp +.in +2 +.nf +\fB# zfs allow cindys quota,reservation users/home +# zfs allow users/home\fR +------------------------------------------------------------- +Local+Descendent permissions on (users/home) + user cindys quota,reservation +------------------------------------------------------------- +cindys% zfs set quota=10G users/home/marks +cindys% zfs get quota users/home/marks +NAME PROPERTY VALUE SOURCE +users/home/marks quota 10G local +.fi +.in -2 +.sp + +.LP +\fBExample 23 \fRRemoving ZFS Delegated Permissions on a ZFS Dataset +.sp +.LP +The following example shows how to remove the snapshot permission from the \fBstaff\fR group on the \fBtank/users\fR file system. The permissions on \fBtank/users\fR are also displayed. + +.sp +.in +2 +.nf +\fB# zfs unallow staff snapshot tank/users +# zfs allow tank/users\fR +------------------------------------------------------------- +Permission sets on (tank/users) + @pset create,destroy,mount,snapshot +Create time permissions on (tank/users) + create,destroy +Local+Descendent permissions on (tank/users) + group staff @pset,create,mount +------------------------------------------------------------- +.fi +.in -2 +.sp + .SH EXIT STATUS +.sp .LP The following exit values are returned: .sp @@ -1821,6 +2603,7 @@ Invalid command line options were specified. .RE .SH ATTRIBUTES +.sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp @@ -1835,9 +2618,13 @@ ATTRIBUTE TYPEATTRIBUTE VALUE _ AvailabilitySUNWzfsu _ -Interface StabilityEvolving +Interface StabilityCommitted .TE .SH SEE ALSO +.sp +.LP +\fBgzip\fR(1), \fBssh\fR(1), \fBmount\fR(1M), \fBshare\fR(1M), \fBsharemgr\fR(1M), \fBunshare\fR(1M), \fBzonecfg\fR(1M), \fBzpool\fR(1M), \fBchmod\fR(2), \fBstat\fR(2), \fBfsync\fR(3c), \fBdfstab\fR(4), \fBattributes\fR(5) +.sp .LP -\fBgzip\fR(1), \fBssh\fR(1), \fBmount\fR(1M), \fBshare\fR(1M), \fBunshare\fR(1M), \fBzonecfg\fR(1M), \fBzpool\fR(1M), \fBchmod\fR(2), \fBstat\fR(2), \fBfsync\fR(3c), \fBdfstab\fR(4), \fBattributes\fR(5) +For information about using the \fBZFS\fR web-based management tool and other \fBZFS\fR features, see the \fIZFS Administration Guide\fR. diff --git a/cddl/contrib/opensolaris/cmd/zfs/zfs_iter.c b/cddl/contrib/opensolaris/cmd/zfs/zfs_iter.c index eb6b8b1..a22370a 100644 --- a/cddl/contrib/opensolaris/cmd/zfs/zfs_iter.c +++ b/cddl/contrib/opensolaris/cmd/zfs/zfs_iter.c @@ -19,12 +19,10 @@ * 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. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <libintl.h> #include <libuutil.h> #include <stddef.h> @@ -56,28 +54,43 @@ typedef struct zfs_node { typedef struct callback_data { uu_avl_t *cb_avl; - int cb_recurse; + int cb_flags; zfs_type_t cb_types; zfs_sort_column_t *cb_sortcol; - zfs_proplist_t **cb_proplist; + zprop_list_t **cb_proplist; } callback_data_t; uu_avl_pool_t *avl_pool; /* - * Called for each dataset. If the object the object is of an appropriate type, + * Include snaps if they were requested or if this a zfs list where types + * were not specified and the "listsnapshots" property is set on this pool. + */ +static int +zfs_include_snapshots(zfs_handle_t *zhp, callback_data_t *cb) +{ + zpool_handle_t *zph; + + if ((cb->cb_flags & ZFS_ITER_PROP_LISTSNAPS) == 0) + return (cb->cb_types & ZFS_TYPE_SNAPSHOT); + + zph = zfs_get_pool_handle(zhp); + return (zpool_get_prop_int(zph, ZPOOL_PROP_LISTSNAPS, NULL)); +} + +/* + * Called for each dataset. If the object is of an appropriate type, * add it to the avl tree and recurse over any children as necessary. */ -int +static int zfs_callback(zfs_handle_t *zhp, void *data) { callback_data_t *cb = data; int dontclose = 0; + int include_snaps = zfs_include_snapshots(zhp, cb); - /* - * If this object is of the appropriate type, add it to the AVL tree. - */ - if (zfs_get_type(zhp) & cb->cb_types) { + if ((zfs_get_type(zhp) & cb->cb_types) || + ((zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT) && include_snaps)) { uu_avl_index_t idx; zfs_node_t *node = safe_malloc(sizeof (zfs_node_t)); @@ -100,10 +113,12 @@ zfs_callback(zfs_handle_t *zhp, void *data) /* * Recurse if necessary. */ - if (cb->cb_recurse && (zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM || - (zfs_get_type(zhp) == ZFS_TYPE_VOLUME && (cb->cb_types & - ZFS_TYPE_SNAPSHOT)))) - (void) zfs_iter_children(zhp, zfs_callback, data); + if (cb->cb_flags & ZFS_ITER_RECURSE) { + if (zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) + (void) zfs_iter_filesystems(zhp, zfs_callback, data); + if ((zfs_get_type(zhp) != ZFS_TYPE_SNAPSHOT) && include_snaps) + (void) zfs_iter_snapshots(zhp, zfs_callback, data); + } if (!dontclose) zfs_close(zhp); @@ -118,7 +133,7 @@ zfs_add_sort_column(zfs_sort_column_t **sc, const char *name, zfs_sort_column_t *col; zfs_prop_t prop; - if ((prop = zfs_name_to_prop(name)) == ZFS_PROP_INVAL && + if ((prop = zfs_name_to_prop(name)) == ZPROP_INVAL && !zfs_prop_user(name)) return (-1); @@ -126,7 +141,7 @@ zfs_add_sort_column(zfs_sort_column_t **sc, const char *name, col->sc_prop = prop; col->sc_reverse = reverse; - if (prop == ZFS_PROP_INVAL) { + if (prop == ZPROP_INVAL) { col->sc_user_prop = safe_malloc(strlen(name) + 1); (void) strcpy(col->sc_user_prop, name); } @@ -243,7 +258,7 @@ zfs_sort(const void *larg, const void *rarg, void *data) * Otherwise, we compare 'lnum' and 'rnum'. */ lstr = rstr = NULL; - if (psc->sc_prop == ZFS_PROP_INVAL) { + if (psc->sc_prop == ZPROP_INVAL) { nvlist_t *luser, *ruser; nvlist_t *lval, *rval; @@ -257,10 +272,10 @@ zfs_sort(const void *larg, const void *rarg, void *data) if (lvalid) verify(nvlist_lookup_string(lval, - ZFS_PROP_VALUE, &lstr) == 0); + ZPROP_VALUE, &lstr) == 0); if (rvalid) verify(nvlist_lookup_string(rval, - ZFS_PROP_VALUE, &rstr) == 0); + ZPROP_VALUE, &rstr) == 0); } else if (zfs_prop_is_string(psc->sc_prop)) { lvalid = (zfs_prop_get(l, psc->sc_prop, lbuf, @@ -293,7 +308,7 @@ zfs_sort(const void *larg, const void *rarg, void *data) if (lstr) ret = strcmp(lstr, rstr); - if (lnum < rnum) + else if (lnum < rnum) ret = -1; else if (lnum > rnum) ret = 1; @@ -309,9 +324,9 @@ zfs_sort(const void *larg, const void *rarg, void *data) } int -zfs_for_each(int argc, char **argv, boolean_t recurse, zfs_type_t types, - zfs_sort_column_t *sortcol, zfs_proplist_t **proplist, zfs_iter_f callback, - void *data, boolean_t args_can_be_paths) +zfs_for_each(int argc, char **argv, int flags, zfs_type_t types, + zfs_sort_column_t *sortcol, zprop_list_t **proplist, + zfs_iter_f callback, void *data) { callback_data_t cb; int ret = 0; @@ -328,7 +343,7 @@ zfs_for_each(int argc, char **argv, boolean_t recurse, zfs_type_t types, } cb.cb_sortcol = sortcol; - cb.cb_recurse = recurse; + cb.cb_flags = flags; cb.cb_proplist = proplist; cb.cb_types = types; if ((cb.cb_avl = uu_avl_create(avl_pool, NULL, UU_DEFAULT)) == NULL) { @@ -341,7 +356,7 @@ zfs_for_each(int argc, char **argv, boolean_t recurse, zfs_type_t types, /* * If given no arguments, iterate over all datasets. */ - cb.cb_recurse = 1; + cb.cb_flags |= ZFS_ITER_RECURSE; ret = zfs_iter_root(g_zfs, zfs_callback, &cb); } else { int i; @@ -354,14 +369,14 @@ zfs_for_each(int argc, char **argv, boolean_t recurse, zfs_type_t types, * can take volumes as well. */ argtype = types; - if (recurse) { + if (flags & ZFS_ITER_RECURSE) { argtype |= ZFS_TYPE_FILESYSTEM; if (types & ZFS_TYPE_SNAPSHOT) argtype |= ZFS_TYPE_VOLUME; } for (i = 0; i < argc; i++) { - if (args_can_be_paths) { + if (flags & ZFS_ITER_ARGS_CAN_BE_PATHS) { zhp = zfs_path_to_zhandle(g_zfs, argv[i], argtype); } else { diff --git a/cddl/contrib/opensolaris/cmd/zfs/zfs_iter.h b/cddl/contrib/opensolaris/cmd/zfs/zfs_iter.h index 1f0ce8e..76a1108 100644 --- a/cddl/contrib/opensolaris/cmd/zfs/zfs_iter.h +++ b/cddl/contrib/opensolaris/cmd/zfs/zfs_iter.h @@ -19,15 +19,13 @@ * 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. */ #ifndef ZFS_ITER_H #define ZFS_ITER_H -#pragma ident "%Z%%M% %I% %E% SMI" - #ifdef __cplusplus extern "C" { #endif @@ -40,8 +38,12 @@ typedef struct zfs_sort_column { boolean_t sc_reverse; } zfs_sort_column_t; -int zfs_for_each(int, char **, boolean_t, zfs_type_t, zfs_sort_column_t *, - zfs_proplist_t **, zfs_iter_f, void *, boolean_t); +#define ZFS_ITER_RECURSE (1 << 0) +#define ZFS_ITER_ARGS_CAN_BE_PATHS (1 << 1) +#define ZFS_ITER_PROP_LISTSNAPS (1 << 2) + +int zfs_for_each(int, char **, int options, zfs_type_t, + zfs_sort_column_t *, zprop_list_t **, zfs_iter_f, void *); int zfs_add_sort_column(zfs_sort_column_t **, const char *, boolean_t); void zfs_free_sort_columns(zfs_sort_column_t *); diff --git a/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c b/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c index de15b00..6f5f92e 100644 --- a/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c +++ b/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c @@ -20,18 +20,17 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <assert.h> #include <ctype.h> #include <errno.h> #include <libgen.h> #include <libintl.h> #include <libuutil.h> +#include <libnvpair.h> #include <locale.h> #include <stddef.h> #include <stdio.h> @@ -44,8 +43,10 @@ #include <sys/mnttab.h> #include <sys/mount.h> #include <sys/stat.h> +#include <sys/avl.h> #include <libzfs.h> +#include <libuutil.h> #include "zfs_iter.h" #include "zfs_util.h" @@ -53,6 +54,7 @@ libzfs_handle_t *g_zfs; static FILE *mnttab_file; +static char history_str[HIS_MAX_RECORD_LEN]; static int zfs_do_clone(int argc, char **argv); static int zfs_do_create(int argc, char **argv); @@ -64,6 +66,7 @@ static int zfs_do_mount(int argc, char **argv); static int zfs_do_rename(int argc, char **argv); static int zfs_do_rollback(int argc, char **argv); static int zfs_do_set(int argc, char **argv); +static int zfs_do_upgrade(int argc, char **argv); static int zfs_do_snapshot(int argc, char **argv); static int zfs_do_unmount(int argc, char **argv); static int zfs_do_share(int argc, char **argv); @@ -71,13 +74,16 @@ static int zfs_do_unshare(int argc, char **argv); static int zfs_do_send(int argc, char **argv); static int zfs_do_receive(int argc, char **argv); static int zfs_do_promote(int argc, char **argv); +static int zfs_do_allow(int argc, char **argv); +static int zfs_do_unallow(int argc, char **argv); static int zfs_do_jail(int argc, char **argv); static int zfs_do_unjail(int argc, char **argv); /* - * These libumem hooks provide a reasonable set of defaults for the allocator's - * debugging facilities. + * Enable a reasonable set of defaults for libumem debugging on DEBUG builds. */ + +#ifdef DEBUG const char * _umem_debug_init(void) { @@ -89,6 +95,7 @@ _umem_logging_init(void) { return ("fail,contents"); /* $UMEM_LOGGING setting */ } +#endif typedef enum { HELP_CLONE, @@ -96,6 +103,7 @@ typedef enum { HELP_DESTROY, HELP_GET, HELP_INHERIT, + HELP_UPGRADE, HELP_JAIL, HELP_UNJAIL, HELP_LIST, @@ -109,7 +117,9 @@ typedef enum { HELP_SHARE, HELP_SNAPSHOT, HELP_UNMOUNT, - HELP_UNSHARE + HELP_UNSHARE, + HELP_ALLOW, + HELP_UNALLOW } zfs_help_t; typedef struct zfs_command { @@ -142,18 +152,20 @@ static zfs_command_t command_table[] = { { "set", zfs_do_set, HELP_SET }, { "get", zfs_do_get, HELP_GET }, { "inherit", zfs_do_inherit, HELP_INHERIT }, + { "upgrade", zfs_do_upgrade, HELP_UPGRADE }, { NULL }, { "mount", zfs_do_mount, HELP_MOUNT }, - { NULL }, { "unmount", zfs_do_unmount, HELP_UNMOUNT }, - { NULL }, { "share", zfs_do_share, HELP_SHARE }, - { NULL }, { "unshare", zfs_do_unshare, HELP_UNSHARE }, { NULL }, { "send", zfs_do_send, HELP_SEND }, { "receive", zfs_do_receive, HELP_RECEIVE }, { NULL }, + { "allow", zfs_do_allow, HELP_ALLOW }, + { NULL }, + { "unallow", zfs_do_unallow, HELP_UNALLOW }, + { NULL }, { "jail", zfs_do_jail, HELP_JAIL }, { "unjail", zfs_do_unjail, HELP_UNJAIL }, }; @@ -167,39 +179,41 @@ get_usage(zfs_help_t idx) { switch (idx) { case HELP_CLONE: - return (gettext("\tclone <snapshot> <filesystem|volume>\n")); + return (gettext("\tclone [-p] [-o property=value] ... " + "<snapshot> <filesystem|volume>\n")); case HELP_CREATE: - return (gettext("\tcreate [[-o property=value] ... ] " + return (gettext("\tcreate [-p] [-o property=value] ... " "<filesystem>\n" - "\tcreate [-s] [-b blocksize] [[-o property=value] ...]\n" - "\t -V <size> <volume>\n")); + "\tcreate [-ps] [-b blocksize] [-o property=value] ... " + "-V <size> <volume>\n")); case HELP_DESTROY: return (gettext("\tdestroy [-rRf] " "<filesystem|volume|snapshot>\n")); case HELP_GET: - return (gettext("\tget [-rHp] [-o field[,field]...] " - "[-s source[,source]...]\n" - "\t <all | property[,property]...> " + return (gettext("\tget [-rHp] [-o field[,...]] " + "[-s source[,...]]\n" + "\t <\"all\" | property[,...]> " "[filesystem|volume|snapshot] ...\n")); case HELP_INHERIT: return (gettext("\tinherit [-r] <property> " - "<filesystem|volume> ...\n")); + "<filesystem|volume|snapshot> ...\n")); + case HELP_UPGRADE: + return (gettext("\tupgrade [-v]\n" + "\tupgrade [-r] [-V version] <-a | filesystem ...>\n")); case HELP_JAIL: return (gettext("\tjail <jailid> <filesystem>\n")); case HELP_UNJAIL: return (gettext("\tunjail <jailid> <filesystem>\n")); case HELP_LIST: - return (gettext("\tlist [-rH] [-o property[,property]...] " - "[-t type[,type]...]\n" - "\t [-s property [-s property]...]" - " [-S property [-S property]...]\n" - "\t [filesystem|volume|snapshot] ...\n")); + return (gettext("\tlist [-rH] [-o property[,...]] " + "[-t type[,...]] [-s property] ...\n" + "\t [-S property] ... " + "[filesystem|volume|snapshot] ...\n")); case HELP_MOUNT: return (gettext("\tmount\n" - "\tmount [-o opts] [-O] -a\n" - "\tmount [-o opts] [-O] <filesystem>\n")); + "\tmount [-vO] [-o opts] <-a | filesystem>\n")); case HELP_PROMOTE: - return (gettext("\tpromote <clone filesystem>\n")); + return (gettext("\tpromote <clone-filesystem>\n")); case HELP_RECEIVE: return (gettext("\treceive [-vnF] <filesystem|volume|" "snapshot>\n" @@ -207,26 +221,45 @@ get_usage(zfs_help_t idx) case HELP_RENAME: return (gettext("\trename <filesystem|volume|snapshot> " "<filesystem|volume|snapshot>\n" + "\trename -p <filesystem|volume> <filesystem|volume>\n" "\trename -r <snapshot> <snapshot>")); case HELP_ROLLBACK: return (gettext("\trollback [-rRf] <snapshot>\n")); case HELP_SEND: - return (gettext("\tsend [-i <snapshot>] <snapshot>\n")); + return (gettext("\tsend [-R] [-[iI] snapshot] <snapshot>\n")); case HELP_SET: return (gettext("\tset <property=value> " - "<filesystem|volume> ...\n")); + "<filesystem|volume|snapshot> ...\n")); case HELP_SHARE: - return (gettext("\tshare -a\n" - "\tshare <filesystem>\n")); + return (gettext("\tshare <-a | filesystem>\n")); case HELP_SNAPSHOT: - return (gettext("\tsnapshot [-r] " - "<filesystem@name|volume@name>\n")); + return (gettext("\tsnapshot [-r] [-o property=value] ... " + "<filesystem@snapname|volume@snapname>\n")); case HELP_UNMOUNT: - return (gettext("\tunmount [-f] -a\n" - "\tunmount [-f] <filesystem|mountpoint>\n")); + return (gettext("\tunmount [-f] " + "<-a | filesystem|mountpoint>\n")); case HELP_UNSHARE: - return (gettext("\tunshare [-f] -a\n" - "\tunshare [-f] <filesystem|mountpoint>\n")); + return (gettext("\tunshare [-f] " + "<-a | filesystem|mountpoint>\n")); + case HELP_ALLOW: + return (gettext("\tallow [-ldug] " + "<\"everyone\"|user|group>[,...] <perm|@setname>[,...]\n" + "\t <filesystem|volume>\n" + "\tallow [-ld] -e <perm|@setname>[,...] " + "<filesystem|volume>\n" + "\tallow -c <perm|@setname>[,...] <filesystem|volume>\n" + "\tallow -s @setname <perm|@setname>[,...] " + "<filesystem|volume>\n")); + case HELP_UNALLOW: + return (gettext("\tunallow [-rldug] " + "<\"everyone\"|user|group>[,...]\n" + "\t [<perm|@setname>[,...]] <filesystem|volume>\n" + "\tunallow [-rld] -e [<perm|@setname>[,...]] " + "<filesystem|volume>\n" + "\tunallow [-r] -c [<perm|@setname>[,...]] " + "<filesystem|volume>\n" + "\tunallow [-r] -s @setname [<perm|@setname>[,...]] " + "<filesystem|volume>\n")); } abort(); @@ -250,20 +283,20 @@ safe_malloc(size_t size) } /* - * Callback routinue that will print out information for each of the + * Callback routine that will print out information for each of * the properties. */ -static zfs_prop_t -usage_prop_cb(zfs_prop_t prop, void *cb) +static int +usage_prop_cb(int prop, void *cb) { FILE *fp = cb; - (void) fprintf(fp, "\t%-13s ", zfs_prop_to_name(prop)); + (void) fprintf(fp, "\t%-15s ", zfs_prop_to_name(prop)); if (zfs_prop_readonly(prop)) - (void) fprintf(fp, " NO "); + (void) fprintf(fp, " NO "); else - (void) fprintf(fp, " YES "); + (void) fprintf(fp, "YES "); if (zfs_prop_inheritable(prop)) (void) fprintf(fp, " YES "); @@ -275,7 +308,7 @@ usage_prop_cb(zfs_prop_t prop, void *cb) else (void) fprintf(fp, "%s\n", zfs_prop_values(prop)); - return (ZFS_PROP_CONT); + return (ZPROP_CONT); } /* @@ -288,6 +321,7 @@ usage(boolean_t requested) { int i; boolean_t show_properties = B_FALSE; + boolean_t show_permissions = B_FALSE; FILE *fp = requested ? stdout : stderr; if (current_command == NULL) { @@ -318,29 +352,46 @@ usage(boolean_t requested) strcmp(current_command->name, "list") == 0)) show_properties = B_TRUE; + if (current_command != NULL && + (strcmp(current_command->name, "allow") == 0 || + strcmp(current_command->name, "unallow") == 0)) + show_permissions = B_TRUE; + if (show_properties) { (void) fprintf(fp, gettext("\nThe following properties are supported:\n")); - (void) fprintf(fp, "\n\t%-13s %s %s %s\n\n", + (void) fprintf(fp, "\n\t%-14s %s %s %s\n\n", "PROPERTY", "EDIT", "INHERIT", "VALUES"); /* Iterate over all properties */ - (void) zfs_prop_iter(usage_prop_cb, fp, B_FALSE); + (void) zprop_iter(usage_prop_cb, fp, B_FALSE, B_TRUE, + ZFS_TYPE_DATASET); (void) fprintf(fp, gettext("\nSizes are specified in bytes " "with standard units such as K, M, G, etc.\n")); - (void) fprintf(fp, gettext("\n\nUser-defined properties can " + (void) fprintf(fp, gettext("\nUser-defined properties can " "be specified by using a name containing a colon (:).\n")); + + } else if (show_permissions) { + (void) fprintf(fp, + gettext("\nThe following permissions are supported:\n")); + + zfs_deleg_permissions(); } else { /* * TRANSLATION NOTE: * "zfs set|get" must not be localised this is the * command name and arguments. */ + (void) fprintf(fp, gettext("\nFor the property list, run: zfs set|get\n")); + + (void) fprintf(fp, + gettext("\nFor the delegated permission list, run:" + " zfs allow|unallow\n")); } /* @@ -354,69 +405,143 @@ usage(boolean_t requested) exit(requested ? 0 : 2); } +static int +parseprop(nvlist_t *props) +{ + char *propname = optarg; + char *propval, *strval; + + if ((propval = strchr(propname, '=')) == NULL) { + (void) fprintf(stderr, gettext("missing " + "'=' for -o option\n")); + return (-1); + } + *propval = '\0'; + propval++; + if (nvlist_lookup_string(props, propname, &strval) == 0) { + (void) fprintf(stderr, gettext("property '%s' " + "specified multiple times\n"), propname); + return (-1); + } + if (nvlist_add_string(props, propname, propval) != 0) { + (void) fprintf(stderr, gettext("internal " + "error: out of memory\n")); + return (-1); + } + return (0); + +} + /* - * zfs clone <fs, snap, vol> fs + * zfs clone [-p] [-o prop=value] ... <snap> <fs | vol> * * Given an existing dataset, create a writable copy whose initial contents * are the same as the source. The newly created dataset maintains a * dependency on the original; the original cannot be destroyed so long as * the clone exists. + * + * The '-p' flag creates all the non-existing ancestors of the target first. */ static int zfs_do_clone(int argc, char **argv) { - zfs_handle_t *zhp; + zfs_handle_t *zhp = NULL; + boolean_t parents = B_FALSE; + nvlist_t *props; int ret; + int c; + + if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) { + (void) fprintf(stderr, gettext("internal error: " + "out of memory\n")); + return (1); + } /* check options */ - if (argc > 1 && argv[1][0] == '-') { - (void) fprintf(stderr, gettext("invalid option '%c'\n"), - argv[1][1]); - usage(B_FALSE); + while ((c = getopt(argc, argv, "o:p")) != -1) { + switch (c) { + case 'o': + if (parseprop(props)) + return (1); + break; + case 'p': + parents = B_TRUE; + break; + case '?': + (void) fprintf(stderr, gettext("invalid option '%c'\n"), + optopt); + goto usage; + } } + argc -= optind; + argv += optind; + /* check number of arguments */ - if (argc < 2) { + if (argc < 1) { (void) fprintf(stderr, gettext("missing source dataset " "argument\n")); - usage(B_FALSE); + goto usage; } - if (argc < 3) { + if (argc < 2) { (void) fprintf(stderr, gettext("missing target dataset " "argument\n")); - usage(B_FALSE); + goto usage; } - if (argc > 3) { + if (argc > 2) { (void) fprintf(stderr, gettext("too many arguments\n")); - usage(B_FALSE); + goto usage; } /* open the source dataset */ - if ((zhp = zfs_open(g_zfs, argv[1], ZFS_TYPE_SNAPSHOT)) == NULL) + if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_SNAPSHOT)) == NULL) return (1); + if (parents && zfs_name_valid(argv[1], ZFS_TYPE_FILESYSTEM | + ZFS_TYPE_VOLUME)) { + /* + * Now create the ancestors of the target dataset. If the + * target already exists and '-p' option was used we should not + * complain. + */ + if (zfs_dataset_exists(g_zfs, argv[1], ZFS_TYPE_FILESYSTEM | + ZFS_TYPE_VOLUME)) + return (0); + if (zfs_create_ancestors(g_zfs, argv[1]) != 0) + return (1); + } + /* pass to libzfs */ - ret = zfs_clone(zhp, argv[2], NULL); + ret = zfs_clone(zhp, argv[1], props); /* create the mountpoint if necessary */ if (ret == 0) { - zfs_handle_t *clone = zfs_open(g_zfs, argv[2], ZFS_TYPE_ANY); + zfs_handle_t *clone; + + clone = zfs_open(g_zfs, argv[1], ZFS_TYPE_DATASET); if (clone != NULL) { if ((ret = zfs_mount(clone, NULL, 0)) == 0) ret = zfs_share(clone); zfs_close(clone); } - zpool_log_history(g_zfs, argc, argv, argv[2], B_FALSE, B_FALSE); } zfs_close(zhp); + nvlist_free(props); - return (ret == 0 ? 0 : 1); + return (!!ret); + +usage: + if (zhp) + zfs_close(zhp); + nvlist_free(props); + usage(B_FALSE); + return (-1); } /* - * zfs create [-o prop=value] ... fs - * zfs create [-s] [-b blocksize] [-o prop=value] ... -V vol size + * zfs create [-p] [-o prop=value] ... fs + * zfs create [-ps] [-b blocksize] [-o prop=value] ... -V vol size * * Create a new dataset. This command can be used to create filesystems * and volumes. Snapshot creation is handled by 'zfs snapshot'. @@ -424,7 +549,10 @@ zfs_do_clone(int argc, char **argv) * * The '-s' flag applies only to volumes, and indicates that we should not try * to set the reservation for this volume. By default we set a reservation - * equal to the size for any volume. + * equal to the size for any volume. For pools with SPA_VERSION >= + * SPA_VERSION_REFRESERVATION, we set a refreservation instead. + * + * The '-p' flag creates all the non-existing ancestors of the target first. */ static int zfs_do_create(int argc, char **argv) @@ -434,12 +562,12 @@ zfs_do_create(int argc, char **argv) uint64_t volsize; int c; boolean_t noreserve = B_FALSE; + boolean_t bflag = B_FALSE; + boolean_t parents = B_FALSE; int ret = 1; - nvlist_t *props = NULL; + nvlist_t *props; uint64_t intval; - char *propname; - char *propval = NULL; - char *strval; + int canmount; if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) { (void) fprintf(stderr, gettext("internal error: " @@ -448,7 +576,7 @@ zfs_do_create(int argc, char **argv) } /* check options */ - while ((c = getopt(argc, argv, ":V:b:so:")) != -1) { + while ((c = getopt(argc, argv, ":V:b:so:p")) != -1) { switch (c) { case 'V': type = ZFS_TYPE_VOLUME; @@ -468,7 +596,11 @@ zfs_do_create(int argc, char **argv) } volsize = intval; break; + case 'p': + parents = B_TRUE; + break; case 'b': + bflag = B_TRUE; if (zfs_nicestrtonum(g_zfs, optarg, &intval) != 0) { (void) fprintf(stderr, gettext("bad volume " "block size '%s': %s\n"), optarg, @@ -485,25 +617,8 @@ zfs_do_create(int argc, char **argv) } break; case 'o': - propname = optarg; - if ((propval = strchr(propname, '=')) == NULL) { - (void) fprintf(stderr, gettext("missing " - "'=' for -o option\n")); - goto error; - } - *propval = '\0'; - propval++; - if (nvlist_lookup_string(props, propname, - &strval) == 0) { - (void) fprintf(stderr, gettext("property '%s' " - "specified multiple times\n"), propname); - goto error; - } - if (nvlist_add_string(props, propname, propval) != 0) { - (void) fprintf(stderr, gettext("internal " - "error: out of memory\n")); + if (parseprop(props)) goto error; - } break; case 's': noreserve = B_TRUE; @@ -520,9 +635,9 @@ zfs_do_create(int argc, char **argv) } } - if (noreserve && type != ZFS_TYPE_VOLUME) { - (void) fprintf(stderr, gettext("'-s' can only be used when " - "creating a volume\n")); + if ((bflag || noreserve) && type != ZFS_TYPE_VOLUME) { + (void) fprintf(stderr, gettext("'-s' and '-b' can only be " + "used when creating a volume\n")); goto badusage; } @@ -540,46 +655,83 @@ zfs_do_create(int argc, char **argv) goto badusage; } - if (type == ZFS_TYPE_VOLUME && !noreserve && - nvlist_lookup_string(props, zfs_prop_to_name(ZFS_PROP_RESERVATION), - &strval) != 0) { - if (nvlist_add_uint64(props, - zfs_prop_to_name(ZFS_PROP_RESERVATION), - volsize) != 0) { - (void) fprintf(stderr, gettext("internal " - "error: out of memory\n")); - nvlist_free(props); - return (1); + if (type == ZFS_TYPE_VOLUME && !noreserve) { + zpool_handle_t *zpool_handle; + uint64_t spa_version; + char *p; + zfs_prop_t resv_prop; + char *strval; + + if (p = strchr(argv[0], '/')) + *p = '\0'; + zpool_handle = zpool_open(g_zfs, argv[0]); + if (p != NULL) + *p = '/'; + if (zpool_handle == NULL) + goto error; + spa_version = zpool_get_prop_int(zpool_handle, + ZPOOL_PROP_VERSION, NULL); + zpool_close(zpool_handle); + if (spa_version >= SPA_VERSION_REFRESERVATION) + resv_prop = ZFS_PROP_REFRESERVATION; + else + resv_prop = ZFS_PROP_RESERVATION; + + if (nvlist_lookup_string(props, zfs_prop_to_name(resv_prop), + &strval) != 0) { + if (nvlist_add_uint64(props, + zfs_prop_to_name(resv_prop), volsize) != 0) { + (void) fprintf(stderr, gettext("internal " + "error: out of memory\n")); + nvlist_free(props); + return (1); + } } } + if (parents && zfs_name_valid(argv[0], type)) { + /* + * Now create the ancestors of target dataset. If the target + * already exists and '-p' option was used we should not + * complain. + */ + if (zfs_dataset_exists(g_zfs, argv[0], type)) { + ret = 0; + goto error; + } + if (zfs_create_ancestors(g_zfs, argv[0]) != 0) + goto error; + } + /* pass to libzfs */ if (zfs_create(g_zfs, argv[0], type, props) != 0) goto error; - if (propval != NULL) - *(propval - 1) = '='; - zpool_log_history(g_zfs, argc + optind, argv - optind, argv[0], - B_FALSE, B_FALSE); - - if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_ANY)) == NULL) + 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: @@ -789,7 +941,7 @@ zfs_do_destroy(int argc, char **argv) int ret; *cp = '\0'; - if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_ANY)) == NULL) + if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_DATASET)) == NULL) return (1); *cp = '@'; cp++; @@ -807,16 +959,13 @@ zfs_do_destroy(int argc, char **argv) if (ret) { (void) fprintf(stderr, gettext("no snapshots destroyed\n")); - } else { - zpool_log_history(g_zfs, argc + optind, argv - optind, - argv[0], B_FALSE, B_FALSE); } return (ret != 0); } /* Open the given dataset */ - if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_ANY)) == NULL) + if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_DATASET)) == NULL) return (1); cb.cb_target = zhp; @@ -849,7 +998,6 @@ zfs_do_destroy(int argc, char **argv) return (1); } - if (cb.cb_error || zfs_iter_dependents(zhp, B_FALSE, destroy_callback, &cb) != 0) { zfs_close(zhp); @@ -860,11 +1008,10 @@ zfs_do_destroy(int argc, char **argv) * Do the real thing. The callback will close the handle regardless of * whether it succeeds or not. */ + if (destroy_callback(zhp, &cb) != 0) return (1); - zpool_log_history(g_zfs, argc + optind, argv - optind, argv[0], - B_FALSE, B_FALSE); return (0); } @@ -894,11 +1041,11 @@ static int get_callback(zfs_handle_t *zhp, void *data) { char buf[ZFS_MAXPROPLEN]; - zfs_source_t sourcetype; + zprop_source_t sourcetype; char source[ZFS_MAXNAMELEN]; - libzfs_get_cbdata_t *cbp = data; + zprop_get_cbdata_t *cbp = data; nvlist_t *userprop = zfs_get_user_props(zhp); - zfs_proplist_t *pl = cbp->cb_proplist; + zprop_list_t *pl = cbp->cb_proplist; nvlist_t *propval; char *strval; char *sourceval; @@ -912,7 +1059,7 @@ get_callback(zfs_handle_t *zhp, void *data) pl == cbp->cb_proplist) continue; - if (pl->pl_prop != ZFS_PROP_INVAL) { + if (pl->pl_prop != ZPROP_INVAL) { if (zfs_prop_get(zhp, pl->pl_prop, buf, sizeof (buf), &sourcetype, source, sizeof (source), @@ -920,17 +1067,17 @@ get_callback(zfs_handle_t *zhp, void *data) if (pl->pl_all) continue; if (!zfs_prop_valid_for_type(pl->pl_prop, - ZFS_TYPE_ANY)) { + ZFS_TYPE_DATASET)) { (void) fprintf(stderr, gettext("No such property '%s'\n"), zfs_prop_to_name(pl->pl_prop)); continue; } - sourcetype = ZFS_SRC_NONE; + sourcetype = ZPROP_SRC_NONE; (void) strlcpy(buf, "-", sizeof (buf)); } - libzfs_print_one_property(zfs_get_name(zhp), cbp, + zprop_print_one_property(zfs_get_name(zhp), cbp, zfs_prop_to_name(pl->pl_prop), buf, sourcetype, source); } else { @@ -938,25 +1085,25 @@ get_callback(zfs_handle_t *zhp, void *data) pl->pl_user_prop, &propval) != 0) { if (pl->pl_all) continue; - sourcetype = ZFS_SRC_NONE; + sourcetype = ZPROP_SRC_NONE; strval = "-"; } else { verify(nvlist_lookup_string(propval, - ZFS_PROP_VALUE, &strval) == 0); + ZPROP_VALUE, &strval) == 0); verify(nvlist_lookup_string(propval, - ZFS_PROP_SOURCE, &sourceval) == 0); + ZPROP_SOURCE, &sourceval) == 0); if (strcmp(sourceval, zfs_get_name(zhp)) == 0) { - sourcetype = ZFS_SRC_LOCAL; + sourcetype = ZPROP_SRC_LOCAL; } else { - sourcetype = ZFS_SRC_INHERITED; + sourcetype = ZPROP_SRC_INHERITED; (void) strlcpy(source, sourceval, sizeof (source)); } } - libzfs_print_one_property(zfs_get_name(zhp), cbp, + zprop_print_one_property(zfs_get_name(zhp), cbp, pl->pl_user_prop, strval, sourcetype, source); } @@ -968,21 +1115,21 @@ get_callback(zfs_handle_t *zhp, void *data) static int zfs_do_get(int argc, char **argv) { - libzfs_get_cbdata_t cb = { 0 }; - boolean_t recurse = B_FALSE; - int i, c; + zprop_get_cbdata_t cb = { 0 }; + int i, c, flags = 0; char *value, *fields; int ret; - zfs_proplist_t fake_name = { 0 }; + zprop_list_t fake_name = { 0 }; /* * Set up default columns and sources. */ - cb.cb_sources = ZFS_SRC_ALL; + cb.cb_sources = ZPROP_SRC_ALL; cb.cb_columns[0] = GET_COL_NAME; cb.cb_columns[1] = GET_COL_PROPERTY; cb.cb_columns[2] = GET_COL_VALUE; cb.cb_columns[3] = GET_COL_SOURCE; + cb.cb_type = ZFS_TYPE_DATASET; /* check options */ while ((c = getopt(argc, argv, ":o:s:rHp")) != -1) { @@ -991,7 +1138,7 @@ zfs_do_get(int argc, char **argv) cb.cb_literal = B_TRUE; break; case 'r': - recurse = B_TRUE; + flags |= ZFS_ITER_RECURSE; break; case 'H': cb.cb_scripted = B_TRUE; @@ -1053,19 +1200,19 @@ zfs_do_get(int argc, char **argv) switch (getsubopt(&optarg, source_subopts, &value)) { case 0: - cb.cb_sources |= ZFS_SRC_LOCAL; + cb.cb_sources |= ZPROP_SRC_LOCAL; break; case 1: - cb.cb_sources |= ZFS_SRC_DEFAULT; + cb.cb_sources |= ZPROP_SRC_DEFAULT; break; case 2: - cb.cb_sources |= ZFS_SRC_INHERITED; + cb.cb_sources |= ZPROP_SRC_INHERITED; break; case 3: - cb.cb_sources |= ZFS_SRC_TEMPORARY; + cb.cb_sources |= ZPROP_SRC_TEMPORARY; break; case 4: - cb.cb_sources |= ZFS_SRC_NONE; + cb.cb_sources |= ZPROP_SRC_NONE; break; default: (void) fprintf(stderr, @@ -1094,7 +1241,8 @@ zfs_do_get(int argc, char **argv) fields = argv[0]; - if (zfs_get_proplist(g_zfs, fields, &cb.cb_proplist) != 0) + if (zprop_get_list(g_zfs, fields, &cb.cb_proplist, ZFS_TYPE_DATASET) + != 0) usage(B_FALSE); argc--; @@ -1118,13 +1266,13 @@ zfs_do_get(int argc, char **argv) cb.cb_first = B_TRUE; /* run for each object */ - ret = zfs_for_each(argc, argv, recurse, ZFS_TYPE_ANY, NULL, - &cb.cb_proplist, get_callback, &cb, B_FALSE); + ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_DATASET, NULL, + &cb.cb_proplist, get_callback, &cb); if (cb.cb_proplist == &fake_name) - zfs_free_proplist(fake_name.pl_next); + zprop_free_list(fake_name.pl_next); else - zfs_free_proplist(cb.cb_proplist); + zprop_free_list(cb.cb_proplist); return (ret); } @@ -1140,37 +1288,46 @@ zfs_do_get(int argc, char **argv) * useful for setting a property on a hierarchy-wide basis, regardless of any * local modifications for each dataset. */ -typedef struct inherit_cbdata { - char *cb_propname; - boolean_t cb_any_successful; -} inherit_cbdata_t; static int -inherit_callback(zfs_handle_t *zhp, void *data) +inherit_recurse_cb(zfs_handle_t *zhp, void *data) { - inherit_cbdata_t *cbp = data; - int ret; + char *propname = data; + zfs_prop_t prop = zfs_name_to_prop(propname); - ret = zfs_prop_inherit(zhp, cbp->cb_propname); - if (ret == 0) - cbp->cb_any_successful = B_TRUE; - return (ret != 0); + /* + * If we're doing it recursively, then ignore properties that + * are not valid for this type of dataset. + */ + if (prop != ZPROP_INVAL && + !zfs_prop_valid_for_type(prop, zfs_get_type(zhp))) + return (0); + + return (zfs_prop_inherit(zhp, propname) != 0); +} + +static int +inherit_cb(zfs_handle_t *zhp, void *data) +{ + char *propname = data; + + return (zfs_prop_inherit(zhp, propname) != 0); } static int zfs_do_inherit(int argc, char **argv) { - boolean_t recurse = B_FALSE; int c; zfs_prop_t prop; - inherit_cbdata_t cb; + char *propname; int ret; + int flags = 0; /* check options */ while ((c = getopt(argc, argv, "r")) != -1) { switch (c) { case 'r': - recurse = B_TRUE; + flags |= ZFS_ITER_RECURSE; break; case '?': default: @@ -1193,42 +1350,265 @@ zfs_do_inherit(int argc, char **argv) usage(B_FALSE); } - cb.cb_propname = argv[0]; + propname = argv[0]; argc--; argv++; - if ((prop = zfs_name_to_prop(cb.cb_propname)) != ZFS_PROP_INVAL) { + if ((prop = zfs_name_to_prop(propname)) != ZPROP_INVAL) { if (zfs_prop_readonly(prop)) { (void) fprintf(stderr, gettext( "%s property is read-only\n"), - cb.cb_propname); + propname); return (1); } if (!zfs_prop_inheritable(prop)) { (void) fprintf(stderr, gettext("'%s' property cannot " - "be inherited\n"), cb.cb_propname); + "be inherited\n"), propname); if (prop == ZFS_PROP_QUOTA || - prop == ZFS_PROP_RESERVATION) + prop == ZFS_PROP_RESERVATION || + prop == ZFS_PROP_REFQUOTA || + prop == ZFS_PROP_REFRESERVATION) (void) fprintf(stderr, gettext("use 'zfs set " - "%s=none' to clear\n"), cb.cb_propname); + "%s=none' to clear\n"), propname); return (1); } - } else if (!zfs_prop_user(cb.cb_propname)) { - (void) fprintf(stderr, gettext( - "invalid property '%s'\n"), - cb.cb_propname); + } else if (!zfs_prop_user(propname)) { + (void) fprintf(stderr, gettext("invalid property '%s'\n"), + propname); usage(B_FALSE); } - cb.cb_any_successful = B_FALSE; + if (flags & ZFS_ITER_RECURSE) { + ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_DATASET, + NULL, NULL, inherit_recurse_cb, propname); + } else { + ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_DATASET, + NULL, NULL, inherit_cb, propname); + } + + return (ret); +} + +typedef struct upgrade_cbdata { + uint64_t cb_numupgraded; + uint64_t cb_numsamegraded; + uint64_t cb_numfailed; + uint64_t cb_version; + boolean_t cb_newer; + boolean_t cb_foundone; + char cb_lastfs[ZFS_MAXNAMELEN]; +} upgrade_cbdata_t; + +static int +same_pool(zfs_handle_t *zhp, const char *name) +{ + int len1 = strcspn(name, "/@"); + const char *zhname = zfs_get_name(zhp); + int len2 = strcspn(zhname, "/@"); + + if (len1 != len2) + return (B_FALSE); + return (strncmp(name, zhname, len1) == 0); +} + +static int +upgrade_list_callback(zfs_handle_t *zhp, void *data) +{ + upgrade_cbdata_t *cb = data; + int version = zfs_prop_get_int(zhp, ZFS_PROP_VERSION); + + /* list if it's old/new */ + if ((!cb->cb_newer && version < ZPL_VERSION) || + (cb->cb_newer && version > ZPL_VERSION)) { + char *str; + if (cb->cb_newer) { + str = gettext("The following filesystems are " + "formatted using a newer software version and\n" + "cannot be accessed on the current system.\n\n"); + } else { + str = gettext("The following filesystems are " + "out of date, and can be upgraded. After being\n" + "upgraded, these filesystems (and any 'zfs send' " + "streams generated from\n" + "subsequent snapshots) will no longer be " + "accessible by older software versions.\n\n"); + } + + if (!cb->cb_foundone) { + (void) puts(str); + (void) printf(gettext("VER FILESYSTEM\n")); + (void) printf(gettext("--- ------------\n")); + cb->cb_foundone = B_TRUE; + } + + (void) printf("%2u %s\n", version, zfs_get_name(zhp)); + } + + return (0); +} + +static int +upgrade_set_callback(zfs_handle_t *zhp, void *data) +{ + upgrade_cbdata_t *cb = data; + int version = zfs_prop_get_int(zhp, ZFS_PROP_VERSION); + + if (cb->cb_version >= ZPL_VERSION_FUID) { + int spa_version; + + if (zfs_spa_version(zhp, &spa_version) < 0) + return (-1); + + if (spa_version < SPA_VERSION_FUID) { + /* can't upgrade */ + (void) printf(gettext("%s: can not be upgraded; " + "the pool version needs to first be upgraded\nto " + "version %d\n\n"), + zfs_get_name(zhp), SPA_VERSION_FUID); + cb->cb_numfailed++; + return (0); + } + } + + /* upgrade */ + if (version < cb->cb_version) { + char verstr[16]; + (void) snprintf(verstr, sizeof (verstr), + "%llu", cb->cb_version); + if (cb->cb_lastfs[0] && !same_pool(zhp, cb->cb_lastfs)) { + /* + * If they did "zfs upgrade -a", then we could + * be doing ioctls to different pools. We need + * to log this history once to each pool. + */ + verify(zpool_stage_history(g_zfs, history_str) == 0); + } + if (zfs_prop_set(zhp, "version", verstr) == 0) + cb->cb_numupgraded++; + else + cb->cb_numfailed++; + (void) strcpy(cb->cb_lastfs, zfs_get_name(zhp)); + } else if (version > cb->cb_version) { + /* can't downgrade */ + (void) printf(gettext("%s: can not be downgraded; " + "it is already at version %u\n"), + zfs_get_name(zhp), version); + cb->cb_numfailed++; + } else { + cb->cb_numsamegraded++; + } + return (0); +} - ret = zfs_for_each(argc, argv, recurse, - ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, NULL, NULL, - inherit_callback, &cb, B_FALSE); +/* + * zfs upgrade + * zfs upgrade -v + * zfs upgrade [-r] [-V <version>] <-a | filesystem> + */ +static int +zfs_do_upgrade(int argc, char **argv) +{ + boolean_t all = B_FALSE; + boolean_t showversions = B_FALSE; + int ret; + upgrade_cbdata_t cb = { 0 }; + char c; + int flags = ZFS_ITER_ARGS_CAN_BE_PATHS; - if (cb.cb_any_successful) { - zpool_log_history(g_zfs, argc + optind + 1, argv - optind - 1, - argv[0], B_FALSE, B_FALSE); + /* check options */ + while ((c = getopt(argc, argv, "rvV:a")) != -1) { + switch (c) { + case 'r': + flags |= ZFS_ITER_RECURSE; + break; + case 'v': + showversions = B_TRUE; + break; + case 'V': + if (zfs_prop_string_to_index(ZFS_PROP_VERSION, + optarg, &cb.cb_version) != 0) { + (void) fprintf(stderr, + gettext("invalid version %s\n"), optarg); + usage(B_FALSE); + } + break; + case 'a': + all = B_TRUE; + break; + case '?': + default: + (void) fprintf(stderr, gettext("invalid option '%c'\n"), + optopt); + usage(B_FALSE); + } + } + + argc -= optind; + argv += optind; + + if ((!all && !argc) && ((flags & ZFS_ITER_RECURSE) | cb.cb_version)) + usage(B_FALSE); + if (showversions && (flags & ZFS_ITER_RECURSE || all || + cb.cb_version || argc)) + usage(B_FALSE); + if ((all || argc) && (showversions)) + usage(B_FALSE); + if (all && argc) + usage(B_FALSE); + + if (showversions) { + /* Show info on available versions. */ + (void) printf(gettext("The following filesystem versions are " + "supported:\n\n")); + (void) printf(gettext("VER DESCRIPTION\n")); + (void) printf("--- -----------------------------------------" + "---------------\n"); + (void) printf(gettext(" 1 Initial ZFS filesystem version\n")); + (void) printf(gettext(" 2 Enhanced directory entries\n")); + (void) printf(gettext(" 3 Case insensitive and File system " + "unique identifer (FUID)\n")); + (void) printf(gettext("\nFor more information on a particular " + "version, including supported releases, see:\n\n")); + (void) printf("http://www.opensolaris.org/os/community/zfs/" + "version/zpl/N\n\n"); + (void) printf(gettext("Where 'N' is the version number.\n")); + ret = 0; + } else if (argc || all) { + /* Upgrade filesystems */ + if (cb.cb_version == 0) + cb.cb_version = ZPL_VERSION; + ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_FILESYSTEM, + NULL, NULL, upgrade_set_callback, &cb); + (void) printf(gettext("%llu filesystems upgraded\n"), + cb.cb_numupgraded); + if (cb.cb_numsamegraded) { + (void) printf(gettext("%llu filesystems already at " + "this version\n"), + cb.cb_numsamegraded); + } + if (cb.cb_numfailed != 0) + ret = 1; + } else { + /* List old-version filesytems */ + boolean_t found; + (void) printf(gettext("This system is currently running " + "ZFS filesystem version %llu.\n\n"), ZPL_VERSION); + + flags |= ZFS_ITER_RECURSE; + ret = zfs_for_each(0, NULL, flags, ZFS_TYPE_FILESYSTEM, + NULL, NULL, upgrade_list_callback, &cb); + + found = cb.cb_foundone; + cb.cb_foundone = B_FALSE; + cb.cb_newer = B_TRUE; + + ret = zfs_for_each(0, NULL, flags, ZFS_TYPE_FILESYSTEM, + NULL, NULL, upgrade_list_callback, &cb); + + if (!cb.cb_foundone && !found) { + (void) printf(gettext("All filesystems are " + "formatted with the current version.\n")); + } } return (ret); @@ -1240,7 +1620,7 @@ zfs_do_inherit(int argc, char **argv) * <dataset> ... * * -r Recurse over all children - * -H Scripted mode; elide headers and separate colums by tabs + * -H Scripted mode; elide headers and separate columns by tabs * -o Control which fields to display. * -t Control which object types to display. * -s Specify sort columns, descending order. @@ -1253,14 +1633,14 @@ zfs_do_inherit(int argc, char **argv) typedef struct list_cbdata { boolean_t cb_first; boolean_t cb_scripted; - zfs_proplist_t *cb_proplist; + zprop_list_t *cb_proplist; } list_cbdata_t; /* * Given a list of columns to display, output appropriate headers for each one. */ static void -print_header(zfs_proplist_t *pl) +print_header(zprop_list_t *pl) { char headerbuf[ZFS_MAXPROPLEN]; const char *header; @@ -1276,7 +1656,7 @@ print_header(zfs_proplist_t *pl) } right_justify = B_FALSE; - if (pl->pl_prop != ZFS_PROP_INVAL) { + if (pl->pl_prop != ZPROP_INVAL) { header = zfs_prop_column_name(pl->pl_prop); right_justify = zfs_prop_align_right(pl->pl_prop); } else { @@ -1302,7 +1682,7 @@ print_header(zfs_proplist_t *pl) * to the described layout. */ static void -print_dataset(zfs_handle_t *zhp, zfs_proplist_t *pl, int scripted) +print_dataset(zfs_handle_t *zhp, zprop_list_t *pl, boolean_t scripted) { boolean_t first = B_TRUE; char property[ZFS_MAXPROPLEN]; @@ -1323,7 +1703,7 @@ print_dataset(zfs_handle_t *zhp, zfs_proplist_t *pl, int scripted) } right_justify = B_FALSE; - if (pl->pl_prop != ZFS_PROP_INVAL) { + if (pl->pl_prop != ZPROP_INVAL) { if (zfs_prop_get(zhp, pl->pl_prop, property, sizeof (property), NULL, NULL, 0, B_FALSE) != 0) propstr = "-"; @@ -1337,7 +1717,7 @@ print_dataset(zfs_handle_t *zhp, zfs_proplist_t *pl, int scripted) propstr = "-"; else verify(nvlist_lookup_string(propval, - ZFS_PROP_VALUE, &propstr) == 0); + ZPROP_VALUE, &propstr) == 0); } width = pl->pl_width; @@ -1381,18 +1761,17 @@ static int zfs_do_list(int argc, char **argv) { int c; - boolean_t recurse = B_FALSE; boolean_t scripted = B_FALSE; static char default_fields[] = "name,used,available,referenced,mountpoint"; - int types = ZFS_TYPE_ANY; + int types = ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME; + boolean_t types_specified = B_FALSE; char *fields = NULL; - char *basic_fields = default_fields; list_cbdata_t cb = { 0 }; char *value; int ret; - char *type_subopts[] = { "filesystem", "volume", "snapshot", NULL }; zfs_sort_column_t *sortcol = NULL; + int flags = ZFS_ITER_PROP_LISTSNAPS | ZFS_ITER_ARGS_CAN_BE_PATHS; /* check options */ while ((c = getopt(argc, argv, ":o:rt:Hs:S:")) != -1) { @@ -1401,7 +1780,7 @@ zfs_do_list(int argc, char **argv) fields = optarg; break; case 'r': - recurse = B_TRUE; + flags |= ZFS_ITER_RECURSE; break; case 'H': scripted = B_TRUE; @@ -1424,7 +1803,12 @@ zfs_do_list(int argc, char **argv) break; case 't': types = 0; + types_specified = B_TRUE; + flags &= ~ZFS_ITER_PROP_LISTSNAPS; while (*optarg != '\0') { + static char *type_subopts[] = { "filesystem", + "volume", "snapshot", "all", NULL }; + switch (getsubopt(&optarg, type_subopts, &value)) { case 0: @@ -1436,6 +1820,10 @@ zfs_do_list(int argc, char **argv) case 2: types |= ZFS_TYPE_SNAPSHOT; break; + case 3: + types = ZFS_TYPE_DATASET; + break; + default: (void) fprintf(stderr, gettext("invalid type '%s'\n"), @@ -1460,35 +1848,46 @@ zfs_do_list(int argc, char **argv) argv += optind; if (fields == NULL) - fields = basic_fields; + fields = default_fields; /* - * If the user specifies '-o all', the zfs_get_proplist() doesn't + * If "-o space" and no types were specified, don't display snapshots. + */ + if (strcmp(fields, "space") == 0 && types_specified == B_FALSE) + types &= ~ZFS_TYPE_SNAPSHOT; + + /* + * If the user specifies '-o all', the zprop_get_list() doesn't * normally include the name of the dataset. For 'zfs list', we always * want this property to be first. */ - if (zfs_get_proplist(g_zfs, fields, &cb.cb_proplist) != 0) + if (zprop_get_list(g_zfs, fields, &cb.cb_proplist, ZFS_TYPE_DATASET) + != 0) usage(B_FALSE); cb.cb_scripted = scripted; cb.cb_first = B_TRUE; - ret = zfs_for_each(argc, argv, recurse, types, sortcol, &cb.cb_proplist, - list_callback, &cb, B_TRUE); + ret = zfs_for_each(argc, argv, flags, types, sortcol, &cb.cb_proplist, + list_callback, &cb); - zfs_free_proplist(cb.cb_proplist); + zprop_free_list(cb.cb_proplist); zfs_free_sort_columns(sortcol); - if (ret == 0 && cb.cb_first) + if (ret == 0 && cb.cb_first && !cb.cb_scripted) (void) printf(gettext("no datasets available\n")); return (ret); } /* - * zfs rename [-r] <fs | snap | vol> <fs | snap | vol> + * zfs rename <fs | snap | vol> <fs | snap | vol> + * zfs rename -p <fs | vol> <fs | vol> + * zfs rename -r <snap> <snap> * * Renames the given dataset to another of the same type. + * + * The '-p' flag creates all the non-existing ancestors of the target first. */ /* ARGSUSED */ static int @@ -1497,13 +1896,17 @@ zfs_do_rename(int argc, char **argv) zfs_handle_t *zhp; int c; int ret; - int recurse = 0; + boolean_t recurse = B_FALSE; + boolean_t parents = B_FALSE; /* check options */ - while ((c = getopt(argc, argv, "r")) != -1) { + while ((c = getopt(argc, argv, "pr")) != -1) { switch (c) { + case 'p': + parents = B_TRUE; + break; case 'r': - recurse = 1; + recurse = B_TRUE; break; case '?': default: @@ -1532,20 +1935,30 @@ zfs_do_rename(int argc, char **argv) usage(B_FALSE); } + if (recurse && parents) { + (void) fprintf(stderr, gettext("-p and -r options are mutually " + "exclusive\n")); + usage(B_FALSE); + } + if (recurse && strchr(argv[0], '@') == 0) { (void) fprintf(stderr, gettext("source dataset for recursive " "rename must be a snapshot\n")); usage(B_FALSE); } - if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_ANY)) == NULL) + if ((zhp = zfs_open(g_zfs, argv[0], parents ? ZFS_TYPE_FILESYSTEM | + ZFS_TYPE_VOLUME : ZFS_TYPE_DATASET)) == NULL) return (1); - ret = (zfs_rename(zhp, argv[1], recurse) != 0); + /* If we were asked and the name looks good, try to create ancestors. */ + if (parents && zfs_name_valid(argv[1], zfs_get_type(zhp)) && + zfs_create_ancestors(g_zfs, argv[1]) != 0) { + zfs_close(zhp); + return (1); + } - if (!ret) - zpool_log_history(g_zfs, argc + optind, argv - optind, argv[1], - B_FALSE, B_FALSE); + ret = (zfs_rename(zhp, argv[1], recurse) != 0); zfs_close(zhp); return (ret); @@ -1587,19 +2000,17 @@ zfs_do_promote(int argc, char **argv) ret = (zfs_promote(zhp) != 0); - if (!ret) - zpool_log_history(g_zfs, argc, argv, argv[1], B_FALSE, B_FALSE); zfs_close(zhp); return (ret); } /* - * zfs rollback [-rfR] <snapshot> + * zfs rollback [-rRf] <snapshot> * * -r Delete any intervening snapshots before doing rollback * -R Delete any snapshots and their clones - * -f Force unmount filesystems, even if they are in use. + * -f ignored for backwards compatability * * Given a filesystem, rollback to a specific snapshot, discarding any changes * since then and making it the active dataset. If more recent snapshots exist, @@ -1686,18 +2097,15 @@ zfs_do_rollback(int argc, char **argv) { int ret; int c; + boolean_t force = B_FALSE; rollback_cbdata_t cb = { 0 }; zfs_handle_t *zhp, *snap; char parentname[ZFS_MAXNAMELEN]; char *delim; - int force = 0; /* check options */ - while ((c = getopt(argc, argv, "rfR")) != -1) { + while ((c = getopt(argc, argv, "rRf")) != -1) { switch (c) { - case 'f': - force = 1; - break; case 'r': cb.cb_recurse = 1; break; @@ -1705,6 +2113,9 @@ zfs_do_rollback(int argc, char **argv) cb.cb_recurse = 1; cb.cb_doclones = 1; break; + case 'f': + force = B_TRUE; + break; case '?': (void) fprintf(stderr, gettext("invalid option '%c'\n"), optopt); @@ -1733,7 +2144,7 @@ zfs_do_rollback(int argc, char **argv) (void) strlcpy(parentname, argv[0], sizeof (parentname)); verify((delim = strrchr(parentname, '@')) != NULL); *delim = '\0'; - if ((zhp = zfs_open(g_zfs, parentname, ZFS_TYPE_ANY)) == NULL) { + if ((zhp = zfs_open(g_zfs, parentname, ZFS_TYPE_DATASET)) == NULL) { zfs_close(snap); return (1); } @@ -1757,11 +2168,6 @@ zfs_do_rollback(int argc, char **argv) */ ret = zfs_rollback(zhp, snap, force); - if (!ret) { - zpool_log_history(g_zfs, argc + optind, argv - optind, argv[0], - B_FALSE, B_FALSE); - } - out: zfs_close(snap); zfs_close(zhp); @@ -1780,7 +2186,6 @@ out: typedef struct set_cbdata { char *cb_propname; char *cb_value; - boolean_t cb_any_successful; } set_cbdata_t; static int @@ -1801,7 +2206,6 @@ set_callback(zfs_handle_t *zhp, void *data) } return (1); } - cbp->cb_any_successful = B_TRUE; return (0); } @@ -1831,7 +2235,8 @@ zfs_do_set(int argc, char **argv) /* validate property=value argument */ cb.cb_propname = argv[1]; - if ((cb.cb_value = strchr(cb.cb_propname, '=')) == NULL) { + if (((cb.cb_value = strchr(cb.cb_propname, '=')) == NULL) || + (cb.cb_value[1] == '\0')) { (void) fprintf(stderr, gettext("missing value in " "property=value argument\n")); usage(B_FALSE); @@ -1839,7 +2244,6 @@ zfs_do_set(int argc, char **argv) *cb.cb_value = '\0'; cb.cb_value++; - cb.cb_any_successful = B_FALSE; if (*cb.cb_propname == '\0') { (void) fprintf(stderr, @@ -1847,40 +2251,46 @@ zfs_do_set(int argc, char **argv) usage(B_FALSE); } - ret = zfs_for_each(argc - 2, argv + 2, B_FALSE, - ZFS_TYPE_ANY, NULL, NULL, set_callback, &cb, B_FALSE); - - if (cb.cb_any_successful) { - *(cb.cb_value - 1) = '='; - zpool_log_history(g_zfs, argc, argv, argv[2], B_FALSE, B_FALSE); - } + ret = zfs_for_each(argc - 2, argv + 2, NULL, + ZFS_TYPE_DATASET, NULL, NULL, set_callback, &cb); return (ret); } /* - * zfs snapshot [-r] <fs@snap> + * zfs snapshot [-r] [-o prop=value] ... <fs@snap> * * Creates a snapshot with the given name. While functionally equivalent to - * 'zfs create', it is a separate command to diffferentiate intent. + * 'zfs create', it is a separate command to differentiate intent. */ static int zfs_do_snapshot(int argc, char **argv) { - int recursive = B_FALSE; + boolean_t recursive = B_FALSE; int ret; char c; + nvlist_t *props; + + if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) { + (void) fprintf(stderr, gettext("internal error: " + "out of memory\n")); + return (1); + } /* check options */ - while ((c = getopt(argc, argv, ":r")) != -1) { + while ((c = getopt(argc, argv, "ro:")) != -1) { switch (c) { + case 'o': + if (parseprop(props)) + return (1); + break; case 'r': recursive = B_TRUE; break; case '?': (void) fprintf(stderr, gettext("invalid option '%c'\n"), optopt); - usage(B_FALSE); + goto usage; } } @@ -1890,25 +2300,28 @@ zfs_do_snapshot(int argc, char **argv) /* check number of arguments */ if (argc < 1) { (void) fprintf(stderr, gettext("missing snapshot argument\n")); - usage(B_FALSE); + goto usage; } if (argc > 1) { (void) fprintf(stderr, gettext("too many arguments\n")); - usage(B_FALSE); + goto usage; } - ret = zfs_snapshot(g_zfs, argv[0], recursive); + ret = zfs_snapshot(g_zfs, argv[0], recursive, props); + nvlist_free(props); if (ret && recursive) (void) fprintf(stderr, gettext("no snapshots were created\n")); - if (!ret) { - zpool_log_history(g_zfs, argc + optind, argv - optind, argv[0], - B_FALSE, B_FALSE); - } return (ret != 0); + +usage: + nvlist_free(props); + usage(B_FALSE); + return (-1); } /* - * zfs send [-i <@snap>] <fs@snap> + * zfs send [-v] -R [-i|-I <@snap>] <fs@snap> + * zfs send [-v] [-i|-I <@snap>] <fs@snap> * * Send a backup stream to stdout. */ @@ -1916,18 +2329,35 @@ static int zfs_do_send(int argc, char **argv) { char *fromname = NULL; + char *toname = NULL; char *cp; zfs_handle_t *zhp; + boolean_t doall = B_FALSE; + boolean_t replicate = B_FALSE; + boolean_t fromorigin = B_FALSE; + boolean_t verbose = B_FALSE; int c, err; /* check options */ - while ((c = getopt(argc, argv, ":i:")) != -1) { + while ((c = getopt(argc, argv, ":i:I:Rv")) != -1) { switch (c) { case 'i': if (fromname) usage(B_FALSE); fromname = optarg; break; + case 'I': + if (fromname) + usage(B_FALSE); + fromname = optarg; + doall = B_TRUE; + break; + case 'R': + replicate = B_TRUE; + break; + case 'v': + verbose = B_TRUE; + break; case ':': (void) fprintf(stderr, gettext("missing argument for " "'%c' option\n"), optopt); @@ -1960,37 +2390,62 @@ zfs_do_send(int argc, char **argv) return (1); } - if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_SNAPSHOT)) == NULL) + cp = strchr(argv[0], '@'); + if (cp == NULL) { + (void) fprintf(stderr, + gettext("argument must be a snapshot\n")); + usage(B_FALSE); + } + *cp = '\0'; + toname = cp + 1; + zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME); + if (zhp == NULL) return (1); /* * If they specified the full path to the snapshot, chop off - * everything except the short name of the snapshot. + * everything except the short name of the snapshot, but special + * case if they specify the origin. */ if (fromname && (cp = strchr(fromname, '@')) != NULL) { - if (cp != fromname && - strncmp(argv[0], fromname, cp - fromname + 1)) { - (void) fprintf(stderr, - gettext("incremental source must be " - "in same filesystem\n")); - usage(B_FALSE); - } - fromname = cp + 1; - if (strchr(fromname, '@') || strchr(fromname, '/')) { - (void) fprintf(stderr, - gettext("invalid incremental source\n")); - usage(B_FALSE); + char origin[ZFS_MAXNAMELEN]; + zprop_source_t src; + + (void) zfs_prop_get(zhp, ZFS_PROP_ORIGIN, + origin, sizeof (origin), &src, NULL, 0, B_FALSE); + + if (strcmp(origin, fromname) == 0) { + fromname = NULL; + fromorigin = B_TRUE; + } else { + *cp = '\0'; + if (cp != fromname && strcmp(argv[0], fromname)) { + (void) fprintf(stderr, + gettext("incremental source must be " + "in same filesystem\n")); + usage(B_FALSE); + } + fromname = cp + 1; + if (strchr(fromname, '@') || strchr(fromname, '/')) { + (void) fprintf(stderr, + gettext("invalid incremental source\n")); + usage(B_FALSE); + } } } - err = zfs_send(zhp, fromname, STDOUT_FILENO); + if (replicate && fromname == NULL) + doall = B_TRUE; + + err = zfs_send(zhp, fromname, toname, replicate, doall, fromorigin, + verbose, STDOUT_FILENO); zfs_close(zhp); return (err != 0); } /* - * zfs receive <fs@snap> + * zfs receive [-dnvF] <fs@snap> * * Restore a backup stream from stdin. */ @@ -1998,25 +2453,23 @@ static int zfs_do_receive(int argc, char **argv) { int c, err; - boolean_t isprefix = B_FALSE; - boolean_t dryrun = B_FALSE; - boolean_t verbose = B_FALSE; - boolean_t force = B_FALSE; + recvflags_t flags; + bzero(&flags, sizeof (recvflags_t)); /* check options */ while ((c = getopt(argc, argv, ":dnvF")) != -1) { switch (c) { case 'd': - isprefix = B_TRUE; + flags.isprefix = B_TRUE; break; case 'n': - dryrun = B_TRUE; + flags.dryrun = B_TRUE; break; case 'v': - verbose = B_TRUE; + flags.verbose = B_TRUE; break; case 'F': - force = B_TRUE; + flags.force = B_TRUE; break; case ':': (void) fprintf(stderr, gettext("missing argument for " @@ -2051,15 +2504,391 @@ zfs_do_receive(int argc, char **argv) return (1); } - err = zfs_receive(g_zfs, argv[0], isprefix, verbose, dryrun, force, - STDIN_FILENO); + err = zfs_receive(g_zfs, argv[0], flags, STDIN_FILENO, NULL); + + return (err != 0); +} + +typedef struct allow_cb { + int a_permcnt; + size_t a_treeoffset; +} allow_cb_t; - if (!err) { - zpool_log_history(g_zfs, argc + optind, argv - optind, argv[0], - B_FALSE, B_FALSE); +static void +zfs_print_perms(avl_tree_t *tree) +{ + zfs_perm_node_t *permnode; + + permnode = avl_first(tree); + while (permnode != NULL) { + (void) printf("%s", permnode->z_pname); + permnode = AVL_NEXT(tree, permnode); + if (permnode) + (void) printf(","); + else + (void) printf("\n"); } +} - return (err != 0); +/* + * Iterate over user/groups/everyone/... and the call perm_iter + * function to print actual permission when tree has >0 nodes. + */ +static void +zfs_iter_perms(avl_tree_t *tree, const char *banner, allow_cb_t *cb) +{ + zfs_allow_node_t *item; + avl_tree_t *ptree; + + item = avl_first(tree); + while (item) { + ptree = (void *)((char *)item + cb->a_treeoffset); + if (avl_numnodes(ptree)) { + if (cb->a_permcnt++ == 0) + (void) printf("%s\n", banner); + (void) printf("\t%s", item->z_key); + /* + * Avoid an extra space being printed + * for "everyone" which is keyed with a null + * string + */ + if (item->z_key[0] != '\0') + (void) printf(" "); + zfs_print_perms(ptree); + } + item = AVL_NEXT(tree, item); + } +} + +#define LINES "-------------------------------------------------------------\n" +static int +zfs_print_allows(char *ds) +{ + zfs_allow_t *curperms, *perms; + zfs_handle_t *zhp; + allow_cb_t allowcb = { 0 }; + char banner[MAXPATHLEN]; + + if (ds[0] == '-') + usage(B_FALSE); + + if (strrchr(ds, '@')) { + (void) fprintf(stderr, gettext("Snapshots don't have 'allow'" + " permissions\n")); + return (1); + } + if ((zhp = zfs_open(g_zfs, ds, ZFS_TYPE_DATASET)) == NULL) + return (1); + + if (zfs_perm_get(zhp, &perms)) { + (void) fprintf(stderr, + gettext("Failed to retrieve 'allows' on %s\n"), ds); + zfs_close(zhp); + return (1); + } + + zfs_close(zhp); + + if (perms != NULL) + (void) printf("%s", LINES); + for (curperms = perms; curperms; curperms = curperms->z_next) { + + (void) snprintf(banner, sizeof (banner), + "Permission sets on (%s)", curperms->z_setpoint); + allowcb.a_treeoffset = + offsetof(zfs_allow_node_t, z_localdescend); + allowcb.a_permcnt = 0; + zfs_iter_perms(&curperms->z_sets, banner, &allowcb); + + (void) snprintf(banner, sizeof (banner), + "Create time permissions on (%s)", curperms->z_setpoint); + allowcb.a_treeoffset = + offsetof(zfs_allow_node_t, z_localdescend); + allowcb.a_permcnt = 0; + zfs_iter_perms(&curperms->z_crperms, banner, &allowcb); + + + (void) snprintf(banner, sizeof (banner), + "Local permissions on (%s)", curperms->z_setpoint); + allowcb.a_treeoffset = offsetof(zfs_allow_node_t, z_local); + allowcb.a_permcnt = 0; + zfs_iter_perms(&curperms->z_user, banner, &allowcb); + zfs_iter_perms(&curperms->z_group, banner, &allowcb); + zfs_iter_perms(&curperms->z_everyone, banner, &allowcb); + + (void) snprintf(banner, sizeof (banner), + "Descendent permissions on (%s)", curperms->z_setpoint); + allowcb.a_treeoffset = offsetof(zfs_allow_node_t, z_descend); + allowcb.a_permcnt = 0; + zfs_iter_perms(&curperms->z_user, banner, &allowcb); + zfs_iter_perms(&curperms->z_group, banner, &allowcb); + zfs_iter_perms(&curperms->z_everyone, banner, &allowcb); + + (void) snprintf(banner, sizeof (banner), + "Local+Descendent permissions on (%s)", + curperms->z_setpoint); + allowcb.a_treeoffset = + offsetof(zfs_allow_node_t, z_localdescend); + allowcb.a_permcnt = 0; + zfs_iter_perms(&curperms->z_user, banner, &allowcb); + zfs_iter_perms(&curperms->z_group, banner, &allowcb); + zfs_iter_perms(&curperms->z_everyone, banner, &allowcb); + + (void) printf("%s", LINES); + } + zfs_free_allows(perms); + return (0); +} + +#define ALLOWOPTIONS "ldcsu:g:e" +#define UNALLOWOPTIONS "ldcsu:g:er" + +/* + * Validate options, and build necessary datastructure to display/remove/add + * permissions. + * Returns 0 - If permissions should be added/removed + * Returns 1 - If permissions should be displayed. + * Returns -1 - on failure + */ +int +parse_allow_args(int *argc, char **argv[], boolean_t unallow, + char **ds, int *recurse, nvlist_t **zperms) +{ + int c; + char *options = unallow ? UNALLOWOPTIONS : ALLOWOPTIONS; + zfs_deleg_inherit_t deleg_type = ZFS_DELEG_NONE; + zfs_deleg_who_type_t who_type = ZFS_DELEG_WHO_UNKNOWN; + char *who = NULL; + char *perms = NULL; + zfs_handle_t *zhp; + + while ((c = getopt(*argc, *argv, options)) != -1) { + switch (c) { + case 'l': + if (who_type == ZFS_DELEG_CREATE || + who_type == ZFS_DELEG_NAMED_SET) + usage(B_FALSE); + + deleg_type |= ZFS_DELEG_PERM_LOCAL; + break; + case 'd': + if (who_type == ZFS_DELEG_CREATE || + who_type == ZFS_DELEG_NAMED_SET) + usage(B_FALSE); + + deleg_type |= ZFS_DELEG_PERM_DESCENDENT; + break; + case 'r': + *recurse = B_TRUE; + break; + case 'c': + if (who_type != ZFS_DELEG_WHO_UNKNOWN) + usage(B_FALSE); + if (deleg_type) + usage(B_FALSE); + who_type = ZFS_DELEG_CREATE; + break; + case 's': + if (who_type != ZFS_DELEG_WHO_UNKNOWN) + usage(B_FALSE); + if (deleg_type) + usage(B_FALSE); + who_type = ZFS_DELEG_NAMED_SET; + break; + case 'u': + if (who_type != ZFS_DELEG_WHO_UNKNOWN) + usage(B_FALSE); + who_type = ZFS_DELEG_USER; + who = optarg; + break; + case 'g': + if (who_type != ZFS_DELEG_WHO_UNKNOWN) + usage(B_FALSE); + who_type = ZFS_DELEG_GROUP; + who = optarg; + break; + case 'e': + if (who_type != ZFS_DELEG_WHO_UNKNOWN) + usage(B_FALSE); + who_type = ZFS_DELEG_EVERYONE; + break; + default: + usage(B_FALSE); + break; + } + } + + if (deleg_type == 0) + deleg_type = ZFS_DELEG_PERM_LOCALDESCENDENT; + + *argc -= optind; + *argv += optind; + + if (unallow == B_FALSE && *argc == 1) { + /* + * Only print permissions if no options were processed + */ + if (optind == 1) + return (1); + else + usage(B_FALSE); + } + + /* + * initialize variables for zfs_build_perms based on number + * of arguments. + * 3 arguments ==> zfs [un]allow joe perm,perm,perm <dataset> or + * zfs [un]allow -s @set1 perm,perm <dataset> + * 2 arguments ==> zfs [un]allow -c perm,perm <dataset> or + * zfs [un]allow -u|-g <name> perm <dataset> or + * zfs [un]allow -e perm,perm <dataset> + * zfs unallow joe <dataset> + * zfs unallow -s @set1 <dataset> + * 1 argument ==> zfs [un]allow -e <dataset> or + * zfs [un]allow -c <dataset> + */ + + switch (*argc) { + case 3: + perms = (*argv)[1]; + who = (*argv)[0]; + *ds = (*argv)[2]; + + /* + * advance argc/argv for do_allow cases. + * for do_allow case make sure who have a know who type + * and its not a permission set. + */ + if (unallow == B_TRUE) { + *argc -= 2; + *argv += 2; + } else if (who_type != ZFS_DELEG_WHO_UNKNOWN && + who_type != ZFS_DELEG_NAMED_SET) + usage(B_FALSE); + break; + + case 2: + if (unallow == B_TRUE && (who_type == ZFS_DELEG_EVERYONE || + who_type == ZFS_DELEG_CREATE || who != NULL)) { + perms = (*argv)[0]; + *ds = (*argv)[1]; + } else { + if (unallow == B_FALSE && + (who_type == ZFS_DELEG_WHO_UNKNOWN || + who_type == ZFS_DELEG_NAMED_SET)) + usage(B_FALSE); + else if (who_type == ZFS_DELEG_WHO_UNKNOWN || + who_type == ZFS_DELEG_NAMED_SET) + who = (*argv)[0]; + else if (who_type != ZFS_DELEG_NAMED_SET) + perms = (*argv)[0]; + *ds = (*argv)[1]; + } + if (unallow == B_TRUE) { + (*argc)--; + (*argv)++; + } + break; + + case 1: + if (unallow == B_FALSE) + usage(B_FALSE); + if (who == NULL && who_type != ZFS_DELEG_CREATE && + who_type != ZFS_DELEG_EVERYONE) + usage(B_FALSE); + *ds = (*argv)[0]; + break; + + default: + usage(B_FALSE); + } + + if (strrchr(*ds, '@')) { + (void) fprintf(stderr, + gettext("Can't set or remove 'allow' permissions " + "on snapshots.\n")); + return (-1); + } + + if ((zhp = zfs_open(g_zfs, *ds, ZFS_TYPE_DATASET)) == NULL) + return (-1); + + if ((zfs_build_perms(zhp, who, perms, + who_type, deleg_type, zperms)) != 0) { + zfs_close(zhp); + return (-1); + } + zfs_close(zhp); + return (0); +} + +static int +zfs_do_allow(int argc, char **argv) +{ + char *ds; + nvlist_t *zperms = NULL; + zfs_handle_t *zhp; + int unused; + int ret; + + if ((ret = parse_allow_args(&argc, &argv, B_FALSE, &ds, + &unused, &zperms)) == -1) + return (1); + + if (ret == 1) + return (zfs_print_allows(argv[0])); + + if ((zhp = zfs_open(g_zfs, ds, ZFS_TYPE_DATASET)) == NULL) + return (1); + + if (zfs_perm_set(zhp, zperms)) { + zfs_close(zhp); + nvlist_free(zperms); + return (1); + } + nvlist_free(zperms); + zfs_close(zhp); + + return (0); +} + +static int +unallow_callback(zfs_handle_t *zhp, void *data) +{ + nvlist_t *nvp = (nvlist_t *)data; + int error; + + error = zfs_perm_remove(zhp, nvp); + if (error) { + (void) fprintf(stderr, gettext("Failed to remove permissions " + "on %s\n"), zfs_get_name(zhp)); + } + return (error); +} + +static int +zfs_do_unallow(int argc, char **argv) +{ + int recurse = B_FALSE; + char *ds; + int error; + nvlist_t *zperms = NULL; + int flags = 0; + + if (parse_allow_args(&argc, &argv, B_TRUE, + &ds, &recurse, &zperms) == -1) + return (1); + + if (recurse) + flags |= ZFS_ITER_RECURSE; + error = zfs_for_each(argc, argv, flags, + ZFS_TYPE_FILESYSTEM|ZFS_TYPE_VOLUME, NULL, + NULL, unallow_callback, (void *)zperms); + + if (zperms) + nvlist_free(zperms); + + return (error); } typedef struct get_all_cbdata { @@ -2067,14 +2896,35 @@ typedef struct get_all_cbdata { size_t cb_alloc; size_t cb_used; uint_t cb_types; + boolean_t cb_verbose; } get_all_cbdata_t; +#define CHECK_SPINNER 30 +#define SPINNER_TIME 3 /* seconds */ +#define MOUNT_TIME 5 /* seconds */ + static int get_one_dataset(zfs_handle_t *zhp, void *data) { + static char spin[] = { '-', '\\', '|', '/' }; + static int spinval = 0; + static int spincheck = 0; + static time_t last_spin_time = (time_t)0; get_all_cbdata_t *cbp = data; zfs_type_t type = zfs_get_type(zhp); + if (cbp->cb_verbose) { + if (--spincheck < 0) { + time_t now = time(NULL); + if (last_spin_time + SPINNER_TIME < now) { + (void) printf("\b%c", spin[spinval++ % 4]); + (void) fflush(stdout); + last_spin_time = now; + } + spincheck = CHECK_SPINNER; + } + } + /* * Interate over any nested datasets. */ @@ -2117,15 +2967,26 @@ get_one_dataset(zfs_handle_t *zhp, void *data) } static void -get_all_datasets(uint_t types, zfs_handle_t ***dslist, size_t *count) +get_all_datasets(uint_t types, zfs_handle_t ***dslist, size_t *count, + boolean_t verbose) { get_all_cbdata_t cb = { 0 }; cb.cb_types = types; + cb.cb_verbose = verbose; + + if (verbose) { + (void) printf("%s: *", gettext("Reading ZFS config")); + (void) fflush(stdout); + } (void) zfs_iter_root(g_zfs, get_one_dataset, &cb); *dslist = cb.cb_handles; *count = cb.cb_used; + + if (verbose) { + (void) printf("\b%s\n", gettext("done.")); + } } static int @@ -2167,15 +3028,17 @@ dataset_cmp(const void *a, const void *b) * Share or mount a dataset. */ static int -share_mount_one(zfs_handle_t *zhp, int op, int flags, boolean_t explicit, - const char *options) +share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol, + boolean_t explicit, const char *options) { char mountpoint[ZFS_MAXPROPLEN]; char shareopts[ZFS_MAXPROPLEN]; + char smbshareopts[ZFS_MAXPROPLEN]; const char *cmdname = op == OP_SHARE ? "share" : "mount"; struct mnttab mnt; uint64_t zoned, canmount; zfs_type_t type = zfs_get_type(zhp); + boolean_t shared_nfs, shared_smb; assert(type & (ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME)); @@ -2216,9 +3079,12 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, boolean_t explicit, sizeof (mountpoint), NULL, NULL, 0, B_FALSE) == 0); verify(zfs_prop_get(zhp, ZFS_PROP_SHARENFS, shareopts, sizeof (shareopts), NULL, NULL, 0, B_FALSE) == 0); + verify(zfs_prop_get(zhp, ZFS_PROP_SHARESMB, smbshareopts, + sizeof (smbshareopts), NULL, NULL, 0, B_FALSE) == 0); canmount = zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT); - if (op == OP_SHARE && strcmp(shareopts, "off") == 0) { + if (op == OP_SHARE && strcmp(shareopts, "off") == 0 && + strcmp(smbshareopts, "off") == 0) { if (!explicit) return (0); @@ -2240,9 +3106,8 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, boolean_t explicit, (void) fprintf(stderr, gettext("cannot %s '%s': " "legacy mountpoint\n"), cmdname, zfs_get_name(zhp)); - (void) fprintf(stderr, gettext("use %s to " - "%s this filesystem\n"), op == OP_SHARE ? - "share(1M)" : "mount(1M)", cmdname); + (void) fprintf(stderr, gettext("use %s(1M) to " + "%s this filesystem\n"), cmdname, cmdname); return (1); } @@ -2255,7 +3120,16 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, boolean_t explicit, 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); @@ -2263,6 +3137,8 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, boolean_t explicit, "'canmount' property is set to 'off'\n"), cmdname, zfs_get_name(zhp)); return (1); + } else if (canmount == ZFS_CANMOUNT_NOAUTO && !explicit) { + return (0); } /* @@ -2274,7 +3150,15 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, boolean_t explicit, */ switch (op) { case OP_SHARE: - if (zfs_is_shared_nfs(zhp, NULL)) { + + shared_nfs = zfs_is_shared_nfs(zhp, NULL); + shared_smb = zfs_is_shared_smb(zhp, NULL); + + if (shared_nfs && shared_smb || + (shared_nfs && strcmp(shareopts, "on") == 0 && + strcmp(smbshareopts, "off") == 0) || + (shared_smb && strcmp(smbshareopts, "on") == 0 && + strcmp(shareopts, "off") == 0)) { if (!explicit) return (0); @@ -2288,8 +3172,23 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, boolean_t explicit, zfs_mount(zhp, NULL, 0) != 0) return (1); - if (zfs_share_nfs(zhp) != 0) + if (protocol == NULL) { + if (zfs_shareall(zhp) != 0) + return (1); + } else if (strcmp(protocol, "nfs") == 0) { + if (zfs_share_nfs(zhp)) + return (1); + } else if (strcmp(protocol, "smb") == 0) { + if (zfs_share_smb(zhp)) + return (1); + } else { + (void) fprintf(stderr, gettext("cannot share " + "'%s': invalid share type '%s' " + "specified\n"), + zfs_get_name(zhp), protocol); return (1); + } + break; case OP_MOUNT: @@ -2352,24 +3251,93 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, boolean_t explicit, return (0); } +/* + * Reports progress in the form "(current/total)". Not thread-safe. + */ +static void +report_mount_progress(int current, int total) +{ + static int len; + static char *reverse = "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" + "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"; + static time_t last_progress_time; + time_t now = time(NULL); + + /* report 1..n instead of 0..n-1 */ + ++current; + + /* display header if we're here for the first time */ + if (current == 1) { + (void) printf(gettext("Mounting ZFS filesystems: ")); + len = 0; + } else if (current != total && last_progress_time + MOUNT_TIME >= now) { + /* too soon to report again */ + return; + } + + last_progress_time = now; + + /* back up to prepare for overwriting */ + if (len) + (void) printf("%*.*s", len, len, reverse); + + /* We put a newline at the end if this is the last one. */ + len = printf("(%d/%d)%s", current, total, current == total ? "\n" : ""); + (void) fflush(stdout); +} + +static void +append_options(char *mntopts, char *newopts) +{ + int len = strlen(mntopts); + + /* original length plus new string to append plus 1 for the comma */ + if (len + 1 + strlen(newopts) >= MNT_LINE_MAX) { + (void) fprintf(stderr, gettext("the opts argument for " + "'%c' option is too long (more than %d chars)\n"), + "-o", MNT_LINE_MAX); + usage(B_FALSE); + } + + if (*mntopts) + mntopts[len++] = ','; + + (void) strcpy(&mntopts[len], newopts); +} + static int share_mount(int op, int argc, char **argv) { int do_all = 0; + boolean_t verbose = B_FALSE; int c, ret = 0; - const char *options = NULL; + char *options = NULL; int types, flags = 0; /* check options */ - while ((c = getopt(argc, argv, op == OP_MOUNT ? ":ao:O" : "a")) + while ((c = getopt(argc, argv, op == OP_MOUNT ? ":avo:O" : "a")) != -1) { switch (c) { case 'a': do_all = 1; break; + case 'v': + verbose = B_TRUE; + break; case 'o': - options = optarg; + if (*optarg == '\0') { + (void) fprintf(stderr, gettext("empty mount " + "options (-o) specified\n")); + usage(B_FALSE); + } + + if (options == NULL) + options = safe_malloc(MNT_LINE_MAX + 1); + + /* option validation is done later */ + append_options(options, optarg); break; + case 'O': warnx("no overlay mounts support on FreeBSD, ignoring"); break; @@ -2392,20 +3360,22 @@ share_mount(int op, int argc, char **argv) if (do_all) { zfs_handle_t **dslist = NULL; size_t i, count = 0; + char *protocol = NULL; if (op == OP_MOUNT) { types = ZFS_TYPE_FILESYSTEM; } else if (argc > 0) { - if (strcmp(argv[0], "nfs") == 0) { + if (strcmp(argv[0], "nfs") == 0 || + strcmp(argv[0], "smb") == 0) { types = ZFS_TYPE_FILESYSTEM; } else if (strcmp(argv[0], "iscsi") == 0) { types = ZFS_TYPE_VOLUME; } else { (void) fprintf(stderr, gettext("share type " - "must be 'nfs' or 'iscsi'\n")); + "must be 'nfs', 'smb' or 'iscsi'\n")); usage(B_FALSE); } - + protocol = argv[0]; argc--; argv++; } else { @@ -2417,7 +3387,7 @@ share_mount(int op, int argc, char **argv) usage(B_FALSE); } - get_all_datasets(types, &dslist, &count); + get_all_datasets(types, &dslist, &count, verbose); if (count == 0) return (0); @@ -2425,8 +3395,11 @@ share_mount(int op, int argc, char **argv) qsort(dslist, count, sizeof (void *), dataset_cmp); for (i = 0; i < count; i++) { - if (share_mount_one(dslist[i], op, flags, B_FALSE, - options) != 0) + if (verbose) + report_mount_progress(i, count); + + if (share_mount_one(dslist[i], op, flags, protocol, + B_FALSE, options) != 0) ret = 1; zfs_close(dslist[i]); } @@ -2436,9 +3409,9 @@ share_mount(int op, int argc, char **argv) struct statfs *sfs; int i, n; - if (op == OP_SHARE) { + if ((op == OP_SHARE) || (options != NULL)) { (void) fprintf(stderr, gettext("missing filesystem " - "argument\n")); + "argument (specify -a for all)\n")); usage(B_FALSE); } @@ -2476,7 +3449,7 @@ share_mount(int op, int argc, char **argv) if ((zhp = zfs_open(g_zfs, argv[0], types)) == NULL) { ret = 1; } else { - ret = share_mount_one(zhp, op, flags, B_TRUE, + ret = share_mount_one(zhp, op, flags, NULL, B_TRUE, options); zfs_close(zhp); } @@ -2498,7 +3471,7 @@ zfs_do_mount(int argc, char **argv) } /* - * zfs share -a [nfs | iscsi] + * zfs share -a [nfs | iscsi | smb] * zfs share filesystem * * Share all filesystems, or share the given filesystem. @@ -2535,9 +3508,23 @@ unshare_unmount_path(int op, char *path, int flags, boolean_t is_manual) { zfs_handle_t *zhp; int ret; + struct stat64 statbuf; struct mnttab search = { 0 }, entry; const char *cmdname = (op == OP_SHARE) ? "unshare" : "unmount"; - char property[ZFS_MAXPROPLEN]; + ino_t path_inode; + + /* + * Search for the path in /etc/mnttab. Rather than looking for the + * specific path, which can be fooled by non-standard paths (i.e. ".." + * or "//"), we stat() the path and search for the corresponding + * (major,minor) device pair. + */ + if (stat64(path, &statbuf) != 0) { + (void) fprintf(stderr, gettext("cannot %s '%s': %s\n"), + cmdname, path, strerror(errno)); + return (1); + } + path_inode = statbuf.st_ino; /* * Search for the given (major,minor) pair in the mount table. @@ -2545,9 +3532,17 @@ unshare_unmount_path(int op, char *path, int flags, boolean_t is_manual) search.mnt_mountp = path; rewind(mnttab_file); if (getmntany(mnttab_file, &entry, &search) != 0) { - (void) fprintf(stderr, gettext("cannot %s '%s': not " - "currently mounted\n"), cmdname, path); - return (1); + if (op == OP_SHARE) { + (void) fprintf(stderr, gettext("cannot %s '%s': not " + "currently mounted\n"), cmdname, path); + return (1); + } + (void) fprintf(stderr, gettext("warning: %s not in mnttab\n"), + path); + if ((ret = umount2(path, flags)) != 0) + (void) fprintf(stderr, gettext("%s: %s\n"), path, + strerror(errno)); + return (ret != 0); } if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0) { @@ -2560,39 +3555,58 @@ unshare_unmount_path(int op, char *path, int flags, boolean_t is_manual) ZFS_TYPE_FILESYSTEM)) == NULL) return (1); - verify(zfs_prop_get(zhp, op == OP_SHARE ? - ZFS_PROP_SHARENFS : ZFS_PROP_MOUNTPOINT, property, - sizeof (property), NULL, NULL, 0, B_FALSE) == 0); + ret = 1; + if (stat64(entry.mnt_mountp, &statbuf) != 0) { + (void) fprintf(stderr, gettext("cannot %s '%s': %s\n"), + cmdname, path, strerror(errno)); + goto out; + } else if (statbuf.st_ino != path_inode) { + (void) fprintf(stderr, gettext("cannot " + "%s '%s': not a mountpoint\n"), cmdname, path); + goto out; + } if (op == OP_SHARE) { - if (strcmp(property, "off") == 0) { + char nfs_mnt_prop[ZFS_MAXPROPLEN]; + char smbshare_prop[ZFS_MAXPROPLEN]; + + verify(zfs_prop_get(zhp, ZFS_PROP_SHARENFS, nfs_mnt_prop, + sizeof (nfs_mnt_prop), NULL, NULL, 0, B_FALSE) == 0); + verify(zfs_prop_get(zhp, ZFS_PROP_SHARESMB, smbshare_prop, + sizeof (smbshare_prop), NULL, NULL, 0, B_FALSE) == 0); + + if (strcmp(nfs_mnt_prop, "off") == 0 && + strcmp(smbshare_prop, "off") == 0) { (void) fprintf(stderr, gettext("cannot unshare " "'%s': legacy share\n"), path); (void) fprintf(stderr, gettext("use " "unshare(1M) to unshare this filesystem\n")); - ret = 1; - } else if (!zfs_is_shared_nfs(zhp, NULL)) { + } else if (!zfs_is_shared(zhp)) { (void) fprintf(stderr, gettext("cannot unshare '%s': " "not currently shared\n"), path); - ret = 1; } else { - ret = zfs_unshareall_nfs(zhp); + ret = zfs_unshareall_bypath(zhp, path); } } else { + char mtpt_prop[ZFS_MAXPROPLEN]; + + verify(zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, mtpt_prop, + sizeof (mtpt_prop), NULL, NULL, 0, B_FALSE) == 0); + if (is_manual) { ret = zfs_unmount(zhp, NULL, flags); - } else if (strcmp(property, "legacy") == 0) { + } else if (strcmp(mtpt_prop, "legacy") == 0) { (void) fprintf(stderr, gettext("cannot unmount " "'%s': legacy mountpoint\n"), zfs_get_name(zhp)); (void) fprintf(stderr, gettext("use umount(1M) " "to unmount this filesystem\n")); - ret = 1; } else { ret = zfs_unmountall(zhp, flags); } } +out: zfs_close(zhp); return (ret != 0); @@ -2609,7 +3623,8 @@ unshare_unmount(int op, int argc, char **argv) int ret = 0; int types, c; zfs_handle_t *zhp; - char property[ZFS_MAXPROPLEN]; + char nfsiscsi_mnt_prop[ZFS_MAXPROPLEN]; + char sharesmb[ZFS_MAXPROPLEN]; /* check options */ while ((c = getopt(argc, argv, op == OP_SHARE ? "a" : "af")) != -1) { @@ -2695,18 +3710,35 @@ unshare_unmount(int op, int argc, char **argv) continue; } - verify(zfs_prop_get(zhp, op == OP_SHARE ? - ZFS_PROP_SHARENFS : ZFS_PROP_MOUNTPOINT, - property, sizeof (property), NULL, NULL, - 0, B_FALSE) == 0); - - /* Ignore legacy mounts and shares */ - if ((op == OP_SHARE && - strcmp(property, "off") == 0) || - (op == OP_MOUNT && - strcmp(property, "legacy") == 0)) { - zfs_close(zhp); - continue; + switch (op) { + case OP_SHARE: + verify(zfs_prop_get(zhp, ZFS_PROP_SHARENFS, + nfsiscsi_mnt_prop, + sizeof (nfsiscsi_mnt_prop), + NULL, NULL, 0, B_FALSE) == 0); + if (strcmp(nfsiscsi_mnt_prop, "off") != 0) + break; + verify(zfs_prop_get(zhp, ZFS_PROP_SHARESMB, + nfsiscsi_mnt_prop, + sizeof (nfsiscsi_mnt_prop), + NULL, NULL, 0, B_FALSE) == 0); + if (strcmp(nfsiscsi_mnt_prop, "off") == 0) + continue; + break; + case OP_MOUNT: + /* Ignore legacy mounts */ + verify(zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, + nfsiscsi_mnt_prop, + sizeof (nfsiscsi_mnt_prop), + 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; } node = safe_malloc(sizeof (unshare_unmount_node_t)); @@ -2746,7 +3778,7 @@ unshare_unmount(int op, int argc, char **argv) switch (op) { case OP_SHARE: - if (zfs_unshare_nfs(node->un_zhp, + if (zfs_unshareall_bypath(node->un_zhp, node->un_mountp) != 0) ret = 1; break; @@ -2774,7 +3806,8 @@ unshare_unmount(int op, int argc, char **argv) zfs_handle_t **dslist = NULL; size_t i, count = 0; - get_all_datasets(ZFS_TYPE_VOLUME, &dslist, &count); + get_all_datasets(ZFS_TYPE_VOLUME, &dslist, &count, + B_FALSE); if (count != 0) { qsort(dslist, count, sizeof (void *), @@ -2819,12 +3852,22 @@ unshare_unmount(int op, int argc, char **argv) if (zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) { verify(zfs_prop_get(zhp, op == OP_SHARE ? - ZFS_PROP_SHARENFS : ZFS_PROP_MOUNTPOINT, property, - sizeof (property), NULL, NULL, 0, B_FALSE) == 0); + ZFS_PROP_SHARENFS : ZFS_PROP_MOUNTPOINT, + nfsiscsi_mnt_prop, sizeof (nfsiscsi_mnt_prop), NULL, + NULL, 0, B_FALSE) == 0); switch (op) { case OP_SHARE: - if (strcmp(property, "off") == 0) { + verify(zfs_prop_get(zhp, ZFS_PROP_SHARENFS, + nfsiscsi_mnt_prop, + sizeof (nfsiscsi_mnt_prop), + NULL, NULL, 0, B_FALSE) == 0); + verify(zfs_prop_get(zhp, ZFS_PROP_SHARESMB, + sharesmb, sizeof (sharesmb), NULL, NULL, + 0, B_FALSE) == 0); + + if (strcmp(nfsiscsi_mnt_prop, "off") == 0 && + strcmp(sharesmb, "off") == 0) { (void) fprintf(stderr, gettext("cannot " "unshare '%s': legacy share\n"), zfs_get_name(zhp)); @@ -2832,18 +3875,18 @@ unshare_unmount(int op, int argc, char **argv) "unshare(1M) to unshare this " "filesystem\n")); ret = 1; - } else if (!zfs_is_shared_nfs(zhp, NULL)) { + } else if (!zfs_is_shared(zhp)) { (void) fprintf(stderr, gettext("cannot " "unshare '%s': not currently " "shared\n"), zfs_get_name(zhp)); ret = 1; - } else if (zfs_unshareall_nfs(zhp) != 0) { + } else if (zfs_unshareall(zhp) != 0) { ret = 1; } break; case OP_MOUNT: - if (strcmp(property, "legacy") == 0) { + if (strcmp(nfsiscsi_mnt_prop, "legacy") == 0) { (void) fprintf(stderr, gettext("cannot " "unmount '%s': legacy " "mountpoint\n"), zfs_get_name(zhp)); @@ -2865,10 +3908,11 @@ unshare_unmount(int op, int argc, char **argv) } else { assert(op == OP_SHARE); - verify(zfs_prop_get(zhp, ZFS_PROP_SHAREISCSI, property, - sizeof (property), NULL, NULL, 0, B_FALSE) == 0); + verify(zfs_prop_get(zhp, ZFS_PROP_SHAREISCSI, + nfsiscsi_mnt_prop, sizeof (nfsiscsi_mnt_prop), + NULL, NULL, 0, B_FALSE) == 0); - if (strcmp(property, "off") == 0) { + if (strcmp(nfsiscsi_mnt_prop, "off") == 0) { (void) fprintf(stderr, gettext("cannot unshare " "'%s': 'shareiscsi' property not set\n"), zfs_get_name(zhp)); @@ -2948,9 +3992,6 @@ do_jail(int argc, char **argv, int attach) ret = (zfs_jail(zhp, jailid, attach) != 0); - if (!ret) - zpool_log_history(g_zfs, argc, argv, argv[2], B_FALSE, B_FALSE); - zfs_close(zhp); return (ret); } @@ -3141,6 +4182,23 @@ do_volcheck(boolean_t isinit) return (zpool_iter(g_zfs, volcheck, &isinit) ? 1 : 0); } +static int +find_command_idx(char *command, int *idx) +{ + int i; + + for (i = 0; i < NCOMMAND; i++) { + if (command_table[i].name == NULL) + continue; + + if (strcmp(command, command_table[i].name) == 0) { + *idx = i; + return (0); + } + } + return (1); +} + int main(int argc, char **argv) { @@ -3160,6 +4218,9 @@ main(int argc, char **argv) return (1); } + zpool_set_history_str("zfs", argc, argv, history_str); + verify(zpool_stage_history(g_zfs, history_str) == 0); + libzfs_print_on_error(g_zfs, B_TRUE); if ((mnttab_file = fopen(MNTTAB, "r")) == NULL) { @@ -3218,18 +4279,14 @@ main(int argc, char **argv) /* * Run the appropriate command. */ - for (i = 0; i < NCOMMAND; i++) { - if (command_table[i].name == NULL) - continue; - - if (strcmp(cmdname, command_table[i].name) == 0) { - current_command = &command_table[i]; - ret = command_table[i].func(argc - 1, argv + 1); - break; - } - } - - if (i == NCOMMAND) { + if (find_command_idx(cmdname, &i) == 0) { + current_command = &command_table[i]; + ret = command_table[i].func(argc - 1, argv + 1); + } else if (strchr(cmdname, '=') != NULL) { + verify(find_command_idx("set", &i) == 0); + current_command = &command_table[i]; + ret = command_table[i].func(argc, argv); + } else { (void) fprintf(stderr, gettext("unrecognized " "command '%s'\n"), cmdname); usage(B_FALSE); |