Add -u option to 'zfs create' that prevents file system from being

automatically mounted. This is similar to the 'zfs receive -u'.

MFC after:	1 week
This commit is contained in:
pjd 2012-04-24 13:44:46 +00:00
parent 337d2f2292
commit 35c58230e2
2 changed files with 19 additions and 6 deletions

View File

@ -35,7 +35,7 @@
.Op Fl \&? .Op Fl \&?
.Nm .Nm
.Cm create .Cm create
.Op Fl p .Op Fl pu
.Op Fl o Ar property Ns = Ns Ar value .Op Fl o Ar property Ns = Ns Ar value
.Ar ... filesystem .Ar ... filesystem
.Nm .Nm
@ -1354,7 +1354,7 @@ Displays a help message.
.It Xo .It Xo
.Nm .Nm
.Cm create .Cm create
.Op Fl p .Op Fl pu
.Op Fl o Ar property Ns = Ns Ar value .Op Fl o Ar property Ns = Ns Ar value
.Ar ... filesystem .Ar ... filesystem
.Xc .Xc
@ -1374,6 +1374,8 @@ line using the
.Fl o .Fl o
option is ignored. If the target filesystem already exists, the operation option is ignored. If the target filesystem already exists, the operation
completes successfully. completes successfully.
.It Fl u
Newly created file system is not mounted.
.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
.Qq Nm Cm set Ar property Ns = Ns Ar value .Qq Nm Cm set Ar property Ns = Ns Ar value

View File

@ -217,7 +217,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 [-p] [-o property=value] ... " return (gettext("\tcreate [-pu] [-o property=value] ... "
"<filesystem>\n" "<filesystem>\n"
"\tcreate [-ps] [-b blocksize] [-o property=value] ... " "\tcreate [-ps] [-b blocksize] [-o property=value] ... "
"-V <size> <volume>\n")); "-V <size> <volume>\n"));
@ -681,7 +681,7 @@ zfs_do_clone(int argc, char **argv)
} }
/* /*
* zfs create [-p] [-o prop=value] ... fs * zfs create [-pu] [-o prop=value] ... fs
* zfs create [-ps] [-b blocksize] [-o prop=value] ... -V vol size * zfs create [-ps] [-b blocksize] [-o prop=value] ... -V vol size
* *
* Create a new dataset. This command can be used to create filesystems * Create a new dataset. This command can be used to create filesystems
@ -694,6 +694,8 @@ zfs_do_clone(int argc, char **argv)
* SPA_VERSION_REFRESERVATION, we set a refreservation instead. * SPA_VERSION_REFRESERVATION, we set a refreservation instead.
* *
* The '-p' flag creates all the non-existing ancestors of the target first. * The '-p' flag creates all the non-existing ancestors of the target first.
*
* The '-u' flag prevents mounting of newly created file system.
*/ */
static int static int
zfs_do_create(int argc, char **argv) zfs_do_create(int argc, char **argv)
@ -705,6 +707,7 @@ zfs_do_create(int argc, char **argv)
boolean_t noreserve = B_FALSE; boolean_t noreserve = B_FALSE;
boolean_t bflag = B_FALSE; boolean_t bflag = B_FALSE;
boolean_t parents = B_FALSE; boolean_t parents = B_FALSE;
boolean_t nomount = B_FALSE;
int ret = 1; int ret = 1;
nvlist_t *props; nvlist_t *props;
uint64_t intval; uint64_t intval;
@ -714,7 +717,7 @@ zfs_do_create(int argc, char **argv)
nomem(); nomem();
/* check options */ /* check options */
while ((c = getopt(argc, argv, ":V:b:so:p")) != -1) { while ((c = getopt(argc, argv, ":V:b:so:pu")) != -1) {
switch (c) { switch (c) {
case 'V': case 'V':
type = ZFS_TYPE_VOLUME; type = ZFS_TYPE_VOLUME;
@ -754,6 +757,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 ':': case ':':
(void) fprintf(stderr, gettext("missing size " (void) fprintf(stderr, gettext("missing size "
"argument\n")); "argument\n"));
@ -771,6 +777,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 file system\n"));
goto badusage;
}
argc -= optind; argc -= optind;
argv += optind; argv += optind;
@ -853,7 +864,7 @@ zfs_do_create(int argc, char **argv)
* verbose error message to let the user know that their filesystem was * verbose error message to let the user know that their filesystem was
* in fact created, even if we failed to mount or share it. * in fact created, even if we failed to mount or share it.
*/ */
if (canmount == ZFS_CANMOUNT_ON) { if (!nomount && canmount == ZFS_CANMOUNT_ON) {
if (zfs_mount(zhp, NULL, 0) != 0) { if (zfs_mount(zhp, NULL, 0) != 0) {
(void) fprintf(stderr, gettext("filesystem " (void) fprintf(stderr, gettext("filesystem "
"successfully created, but not mounted\n")); "successfully created, but not mounted\n"));