diff options
-rw-r--r-- | cmd/zfs/zfs_main.c | 20 | ||||
-rw-r--r-- | man/man8/zfs-create.8 | 12 | ||||
-rw-r--r-- | tests/runfiles/common.run | 3 | ||||
-rw-r--r-- | tests/zfs-tests/tests/functional/cli_root/zfs_create/Makefile.am | 1 | ||||
-rwxr-xr-x | tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_nomount.ksh | 51 |
5 files changed, 80 insertions, 7 deletions
diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 340a7db96..8064f6363 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -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")); @@ -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'. @@ -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; @@ -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; @@ -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; @@ -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; @@ -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); diff --git a/man/man8/zfs-create.8 b/man/man8/zfs-create.8 index 9c5c959b3..5a4f9a32a 100644 --- a/man/man8/zfs-create.8 +++ b/man/man8/zfs-create.8 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/runfiles/common.run b/tests/runfiles/common.run index 7ca4194e1..d6077e292 100644 --- a/tests/runfiles/common.run +++ b/tests/runfiles/common.run @@ -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_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] diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_create/Makefile.am index cb65507ae..7515753c1 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/Makefile.am @@ -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 = \ diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_nomount.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_nomount.ksh new file mode 100755 index 000000000..e1fbbe63a --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_nomount.ksh @@ -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" |