Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -u option to 'zfs create' #11254

Merged
merged 1 commit into from Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions cmd/zfs/zfs_main.c
Expand Up @@ -270,7 +270,7 @@ get_usage(zfs_help_t idx)
return (gettext("\tclone [-p] [-o property=value] ... "
"<snapshot> <filesystem|volume>\n"));
case HELP_CREATE:
return (gettext("\tcreate [-Pnpv] [-o property=value] ... "
return (gettext("\tcreate [-Pnpuv] [-o property=value] ... "
"<filesystem>\n"
"\tcreate [-Pnpsv] [-b blocksize] [-o property=value] ... "
"-V <size> <volume>\n"));
Expand Down Expand Up @@ -1012,6 +1012,8 @@ default_volblocksize(zpool_handle_t *zhp, nvlist_t *props)
* check of arguments and properties, but does not check for permissions,
* available space, etc.
*
* The '-u' flag prevents the newly created file system from being mounted.
*
* The '-v' flag is for verbose output.
*
* The '-P' flag is used for parseable output. It implies '-v'.
Expand All @@ -1028,6 +1030,7 @@ zfs_do_create(int argc, char **argv)
boolean_t bflag = B_FALSE;
boolean_t parents = B_FALSE;
boolean_t dryrun = B_FALSE;
boolean_t nomount = B_FALSE;
boolean_t verbose = B_FALSE;
boolean_t parseable = B_FALSE;
int ret = 1;
Expand All @@ -1039,7 +1042,7 @@ zfs_do_create(int argc, char **argv)
nomem();

/* check options */
while ((c = getopt(argc, argv, ":PV:b:nso:pv")) != -1) {
while ((c = getopt(argc, argv, ":PV:b:nso:puv")) != -1) {
switch (c) {
case 'V':
type = ZFS_TYPE_VOLUME;
Expand Down Expand Up @@ -1086,6 +1089,9 @@ zfs_do_create(int argc, char **argv)
case 's':
noreserve = B_TRUE;
break;
case 'u':
nomount = B_TRUE;
break;
case 'v':
verbose = B_TRUE;
break;
Expand All @@ -1105,6 +1111,11 @@ zfs_do_create(int argc, char **argv)
"used when creating a volume\n"));
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;
argv += optind;
Expand Down Expand Up @@ -1265,6 +1276,11 @@ zfs_do_create(int argc, char **argv)
log_history = B_FALSE;
}

if (nomount) {
ret = 0;
goto error;
}

ret = zfs_mount_and_share(g_zfs, argv[0], ZFS_TYPE_DATASET);
error:
nvlist_free(props);
Expand Down
12 changes: 8 additions & 4 deletions man/man8/zfs-create.8
Expand Up @@ -30,7 +30,7 @@
.\" Copyright 2018 Nexenta Systems, Inc.
.\" Copyright 2019 Joyent, Inc.
.\"
.Dd June 30, 2019
.Dd December 1, 2020
.Dt ZFS-CREATE 8
.Os
.Sh NAME
Expand All @@ -39,7 +39,7 @@
.Sh SYNOPSIS
.Nm zfs
.Cm create
.Op Fl Pnpv
.Op Fl Pnpuv
.Oo Fl o Ar property Ns = Ns Ar value Oc Ns ...
.Ar filesystem
.Nm zfs
Expand All @@ -53,14 +53,16 @@
.It Xo
.Nm zfs
.Cm create
.Op Fl Pnpv
.Op Fl Pnpuv
.Oo Fl o Ar property Ns = Ns Ar value Oc Ns ...
.Ar filesystem
.Xc
Creates a new ZFS file system.
The file system is automatically mounted according to the
.Sy mountpoint
property inherited from the parent.
property inherited from the parent, unless the
.Fl u
option is used.
.Bl -tag -width "-o"
.It Fl o Ar property Ns = Ns Ar value
Sets the specified property as if the command
Expand Down Expand Up @@ -122,6 +124,8 @@ to
due to the use of the
.Fl o
option.
.It Fl u
Do not mount the newly created file system.
.It Fl v
Print verbose information about the created dataset.
.El
Expand Down
3 changes: 2 additions & 1 deletion tests/runfiles/common.run
Expand Up @@ -150,7 +150,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_010_neg', 'zfs_create_011_pos', 'zfs_create_012_pos',
'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']

[tests/functional/cli_root/zfs_destroy]
Expand Down
Expand Up @@ -19,6 +19,7 @@ dist_pkgdata_SCRIPTS = \
zfs_create_encrypted.ksh \
zfs_create_crypt_combos.ksh \
zfs_create_dryrun.ksh \
zfs_create_nomount.ksh \
zfs_create_verbose.ksh

dist_pkgdata_DATA = \
Expand Down
@@ -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"