Add -u option to 'zfs create'
Add -u option to 'zfs create' that prevents file system from being automatically mounted. This is similar to the 'zfs receive -u'. Authored by: pjd <pjd@FreeBSD.org> FreeBSD-commit: freebsd/freebsd@35c58230e2 Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Allan Jude <allan@klarasystems.com> Ported-by: Ryan Moeller <ryan@iXsystems.com> Signed-off-by: Ryan Moeller <ryan@iXsystems.com> Closes #11254
This commit is contained in:
parent
8f158ae6ad
commit
4b6e2a5a33
|
@ -270,7 +270,7 @@ get_usage(zfs_help_t idx)
|
||||||
return (gettext("\tclone [-p] [-o property=value] ... "
|
return (gettext("\tclone [-p] [-o property=value] ... "
|
||||||
"<snapshot> <filesystem|volume>\n"));
|
"<snapshot> <filesystem|volume>\n"));
|
||||||
case HELP_CREATE:
|
case HELP_CREATE:
|
||||||
return (gettext("\tcreate [-Pnpv] [-o property=value] ... "
|
return (gettext("\tcreate [-Pnpuv] [-o property=value] ... "
|
||||||
"<filesystem>\n"
|
"<filesystem>\n"
|
||||||
"\tcreate [-Pnpsv] [-b blocksize] [-o property=value] ... "
|
"\tcreate [-Pnpsv] [-b blocksize] [-o property=value] ... "
|
||||||
"-V <size> <volume>\n"));
|
"-V <size> <volume>\n"));
|
||||||
|
@ -1012,6 +1012,8 @@ default_volblocksize(zpool_handle_t *zhp, nvlist_t *props)
|
||||||
* check of arguments and properties, but does not check for permissions,
|
* check of arguments and properties, but does not check for permissions,
|
||||||
* available space, etc.
|
* available space, etc.
|
||||||
*
|
*
|
||||||
|
* The '-u' flag prevents the newly created file system from being mounted.
|
||||||
|
*
|
||||||
* The '-v' flag is for verbose output.
|
* The '-v' flag is for verbose output.
|
||||||
*
|
*
|
||||||
* The '-P' flag is used for parseable output. It implies '-v'.
|
* The '-P' flag is used for parseable output. It implies '-v'.
|
||||||
|
@ -1028,6 +1030,7 @@ zfs_do_create(int argc, char **argv)
|
||||||
boolean_t bflag = B_FALSE;
|
boolean_t bflag = B_FALSE;
|
||||||
boolean_t parents = B_FALSE;
|
boolean_t parents = B_FALSE;
|
||||||
boolean_t dryrun = B_FALSE;
|
boolean_t dryrun = B_FALSE;
|
||||||
|
boolean_t nomount = B_FALSE;
|
||||||
boolean_t verbose = B_FALSE;
|
boolean_t verbose = B_FALSE;
|
||||||
boolean_t parseable = B_FALSE;
|
boolean_t parseable = B_FALSE;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
@ -1039,7 +1042,7 @@ zfs_do_create(int argc, char **argv)
|
||||||
nomem();
|
nomem();
|
||||||
|
|
||||||
/* check options */
|
/* check options */
|
||||||
while ((c = getopt(argc, argv, ":PV:b:nso:pv")) != -1) {
|
while ((c = getopt(argc, argv, ":PV:b:nso:puv")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'V':
|
case 'V':
|
||||||
type = ZFS_TYPE_VOLUME;
|
type = ZFS_TYPE_VOLUME;
|
||||||
|
@ -1086,6 +1089,9 @@ zfs_do_create(int argc, char **argv)
|
||||||
case 's':
|
case 's':
|
||||||
noreserve = B_TRUE;
|
noreserve = B_TRUE;
|
||||||
break;
|
break;
|
||||||
|
case 'u':
|
||||||
|
nomount = B_TRUE;
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose = B_TRUE;
|
verbose = B_TRUE;
|
||||||
break;
|
break;
|
||||||
|
@ -1105,6 +1111,11 @@ zfs_do_create(int argc, char **argv)
|
||||||
"used when creating a volume\n"));
|
"used when creating a volume\n"));
|
||||||
goto badusage;
|
goto badusage;
|
||||||
}
|
}
|
||||||
|
if (nomount && type != ZFS_TYPE_FILESYSTEM) {
|
||||||
|
(void) fprintf(stderr, gettext("'-u' can only be "
|
||||||
|
"used when creating a filesystem\n"));
|
||||||
|
goto badusage;
|
||||||
|
}
|
||||||
|
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
@ -1265,6 +1276,11 @@ zfs_do_create(int argc, char **argv)
|
||||||
log_history = B_FALSE;
|
log_history = B_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nomount) {
|
||||||
|
ret = 0;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
ret = zfs_mount_and_share(g_zfs, argv[0], ZFS_TYPE_DATASET);
|
ret = zfs_mount_and_share(g_zfs, argv[0], ZFS_TYPE_DATASET);
|
||||||
error:
|
error:
|
||||||
nvlist_free(props);
|
nvlist_free(props);
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
.\" Copyright 2018 Nexenta Systems, Inc.
|
.\" Copyright 2018 Nexenta Systems, Inc.
|
||||||
.\" Copyright 2019 Joyent, Inc.
|
.\" Copyright 2019 Joyent, Inc.
|
||||||
.\"
|
.\"
|
||||||
.Dd June 30, 2019
|
.Dd December 1, 2020
|
||||||
.Dt ZFS-CREATE 8
|
.Dt ZFS-CREATE 8
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm zfs
|
.Nm zfs
|
||||||
.Cm create
|
.Cm create
|
||||||
.Op Fl Pnpv
|
.Op Fl Pnpuv
|
||||||
.Oo Fl o Ar property Ns = Ns Ar value Oc Ns ...
|
.Oo Fl o Ar property Ns = Ns Ar value Oc Ns ...
|
||||||
.Ar filesystem
|
.Ar filesystem
|
||||||
.Nm zfs
|
.Nm zfs
|
||||||
|
@ -53,14 +53,16 @@
|
||||||
.It Xo
|
.It Xo
|
||||||
.Nm zfs
|
.Nm zfs
|
||||||
.Cm create
|
.Cm create
|
||||||
.Op Fl Pnpv
|
.Op Fl Pnpuv
|
||||||
.Oo Fl o Ar property Ns = Ns Ar value Oc Ns ...
|
.Oo Fl o Ar property Ns = Ns Ar value Oc Ns ...
|
||||||
.Ar filesystem
|
.Ar filesystem
|
||||||
.Xc
|
.Xc
|
||||||
Creates a new ZFS file system.
|
Creates a new ZFS file system.
|
||||||
The file system is automatically mounted according to the
|
The file system is automatically mounted according to the
|
||||||
.Sy mountpoint
|
.Sy mountpoint
|
||||||
property inherited from the parent.
|
property inherited from the parent, unless the
|
||||||
|
.Fl u
|
||||||
|
option is used.
|
||||||
.Bl -tag -width "-o"
|
.Bl -tag -width "-o"
|
||||||
.It Fl o Ar property Ns = Ns Ar value
|
.It Fl o Ar property Ns = Ns Ar value
|
||||||
Sets the specified property as if the command
|
Sets the specified property as if the command
|
||||||
|
@ -122,6 +124,8 @@ to
|
||||||
due to the use of the
|
due to the use of the
|
||||||
.Fl o
|
.Fl o
|
||||||
option.
|
option.
|
||||||
|
.It Fl u
|
||||||
|
Do not mount the newly created file system.
|
||||||
.It Fl v
|
.It Fl v
|
||||||
Print verbose information about the created dataset.
|
Print verbose information about the created dataset.
|
||||||
.El
|
.El
|
||||||
|
|
|
@ -156,7 +156,8 @@ tests = ['zfs_create_001_pos', 'zfs_create_002_pos', 'zfs_create_003_pos',
|
||||||
'zfs_create_007_pos', 'zfs_create_008_neg', 'zfs_create_009_neg',
|
'zfs_create_007_pos', 'zfs_create_008_neg', 'zfs_create_009_neg',
|
||||||
'zfs_create_010_neg', 'zfs_create_011_pos', 'zfs_create_012_pos',
|
'zfs_create_010_neg', 'zfs_create_011_pos', 'zfs_create_012_pos',
|
||||||
'zfs_create_013_pos', 'zfs_create_014_pos', 'zfs_create_encrypted',
|
'zfs_create_013_pos', 'zfs_create_014_pos', 'zfs_create_encrypted',
|
||||||
'zfs_create_crypt_combos', 'zfs_create_dryrun', 'zfs_create_verbose']
|
'zfs_create_crypt_combos', 'zfs_create_dryrun', 'zfs_create_nomount',
|
||||||
|
'zfs_create_verbose']
|
||||||
tags = ['functional', 'cli_root', 'zfs_create']
|
tags = ['functional', 'cli_root', 'zfs_create']
|
||||||
|
|
||||||
[tests/functional/cli_root/zfs_destroy]
|
[tests/functional/cli_root/zfs_destroy]
|
||||||
|
|
|
@ -19,6 +19,7 @@ dist_pkgdata_SCRIPTS = \
|
||||||
zfs_create_encrypted.ksh \
|
zfs_create_encrypted.ksh \
|
||||||
zfs_create_crypt_combos.ksh \
|
zfs_create_crypt_combos.ksh \
|
||||||
zfs_create_dryrun.ksh \
|
zfs_create_dryrun.ksh \
|
||||||
|
zfs_create_nomount.ksh \
|
||||||
zfs_create_verbose.ksh
|
zfs_create_verbose.ksh
|
||||||
|
|
||||||
dist_pkgdata_DATA = \
|
dist_pkgdata_DATA = \
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
#!/bin/ksh -p
|
||||||
|
#
|
||||||
|
# This file and its contents are supplied under the terms of the
|
||||||
|
# Common Development and Distribution License ("CDDL"), version 1.0.
|
||||||
|
# You may only use this file in accordance with the terms of version
|
||||||
|
# 1.0 of the CDDL.
|
||||||
|
#
|
||||||
|
# A full copy of the text of the CDDL should have accompanied this
|
||||||
|
# source. A copy of the CDDL is also available via the Internet at
|
||||||
|
# http://www.illumos.org/license/CDDL.
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright 2020 iXsystems, Inc.
|
||||||
|
#
|
||||||
|
|
||||||
|
. $STF_SUITE/include/libtest.shlib
|
||||||
|
|
||||||
|
#
|
||||||
|
# DESCRIPTION:
|
||||||
|
# zfs create -u should leave the new file system unmounted.
|
||||||
|
# It should not work for a volume.
|
||||||
|
#
|
||||||
|
# STRATEGY:
|
||||||
|
# 1. Create a file system using -u and make sure the file system is not mounted.
|
||||||
|
# 3. Do it for a volume to verify it fails.
|
||||||
|
#
|
||||||
|
|
||||||
|
verify_runnable "both"
|
||||||
|
|
||||||
|
function cleanup
|
||||||
|
{
|
||||||
|
local ds
|
||||||
|
|
||||||
|
for ds in "$fs" "$vol"; do
|
||||||
|
datasetexists "$ds" && destroy_dataset "$ds"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
log_onexit cleanup
|
||||||
|
|
||||||
|
log_assert "zfs create -u leaves the new file system unmounted"
|
||||||
|
|
||||||
|
typeset fs="$TESTPOOL/$TESTFS1"
|
||||||
|
typeset vol="$TESTPOOL/$TESTVOL1"
|
||||||
|
|
||||||
|
log_must create_dataset "$fs" "-u"
|
||||||
|
log_mustnot ismounted "$fs"
|
||||||
|
|
||||||
|
log_mustnot zfs create -V $VOLSIZE -u "$vol"
|
||||||
|
|
||||||
|
log_pass "zfs create -u leaves the new file system unmounted"
|
Loading…
Reference in New Issue