Skip to content

Commit 8b71377

Browse files
wcaChristopher Siden
authored andcommitted
3745 zpool create should treat -O mountpoint and -m the same
3811 zpool create -o altroot=/xyz -O mountpoint=/mnt ignores the mountpoint option Reviewed by: Matthew Ahrens <mahrens@delphix.com> Approved by: Christopher Siden <christopher.siden@delphix.com>
1 parent fc7a6e3 commit 8b71377

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

usr/src/cmd/zpool/zpool_main.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ zpool_do_create(int argc, char **argv)
677677
goto errout;
678678
break;
679679
case 'm':
680+
/* Equivalent to -O mountpoint=optarg */
680681
mountpoint = optarg;
681682
break;
682683
case 'o':
@@ -715,8 +716,18 @@ zpool_do_create(int argc, char **argv)
715716
*propval = '\0';
716717
propval++;
717718

718-
if (add_prop_list(optarg, propval, &fsprops, B_FALSE))
719+
/*
720+
* Mountpoints are checked and then added later.
721+
* Uniquely among properties, they can be specified
722+
* more than once, to avoid conflict with -m.
723+
*/
724+
if (0 == strcmp(optarg,
725+
zfs_prop_to_name(ZFS_PROP_MOUNTPOINT))) {
726+
mountpoint = propval;
727+
} else if (add_prop_list(optarg, propval, &fsprops,
728+
B_FALSE)) {
719729
goto errout;
730+
}
720731
break;
721732
case ':':
722733
(void) fprintf(stderr, gettext("missing argument for "
@@ -833,6 +844,18 @@ zpool_do_create(int argc, char **argv)
833844
}
834845
}
835846

847+
/*
848+
* Now that the mountpoint's validity has been checked, ensure that
849+
* the property is set appropriately prior to creating the pool.
850+
*/
851+
if (mountpoint != NULL) {
852+
ret = add_prop_list(zfs_prop_to_name(ZFS_PROP_MOUNTPOINT),
853+
mountpoint, &fsprops, B_FALSE);
854+
if (ret != 0)
855+
goto errout;
856+
}
857+
858+
ret = 1;
836859
if (dryrun) {
837860
/*
838861
* For a dry run invocation, print out a basic message and run
@@ -867,21 +890,19 @@ zpool_do_create(int argc, char **argv)
867890
if (nvlist_exists(props, propname))
868891
continue;
869892

870-
if (add_prop_list(propname, ZFS_FEATURE_ENABLED,
871-
&props, B_TRUE) != 0)
893+
ret = add_prop_list(propname,
894+
ZFS_FEATURE_ENABLED, &props, B_TRUE);
895+
if (ret != 0)
872896
goto errout;
873897
}
874898
}
899+
900+
ret = 1;
875901
if (zpool_create(g_zfs, poolname,
876902
nvroot, props, fsprops) == 0) {
877903
zfs_handle_t *pool = zfs_open(g_zfs, poolname,
878904
ZFS_TYPE_FILESYSTEM);
879905
if (pool != NULL) {
880-
if (mountpoint != NULL)
881-
verify(zfs_prop_set(pool,
882-
zfs_prop_to_name(
883-
ZFS_PROP_MOUNTPOINT),
884-
mountpoint) == 0);
885906
if (zfs_mount(pool, NULL, 0) == 0)
886907
ret = zfs_shareall(pool);
887908
zfs_close(pool);

usr/src/lib/libzfs/common/libzfs_pool.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,6 @@ zpool_create(libzfs_handle_t *hdl, const char *pool, nvlist_t *nvroot,
10801080
nvlist_t *zc_fsprops = NULL;
10811081
nvlist_t *zc_props = NULL;
10821082
char msg[1024];
1083-
char *altroot;
10841083
int ret = -1;
10851084

10861085
(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
@@ -1179,21 +1178,6 @@ zpool_create(libzfs_handle_t *hdl, const char *pool, nvlist_t *nvroot,
11791178
}
11801179
}
11811180

1182-
/*
1183-
* If this is an alternate root pool, then we automatically set the
1184-
* mountpoint of the root dataset to be '/'.
1185-
*/
1186-
if (nvlist_lookup_string(props, zpool_prop_to_name(ZPOOL_PROP_ALTROOT),
1187-
&altroot) == 0) {
1188-
zfs_handle_t *zhp;
1189-
1190-
verify((zhp = zfs_open(hdl, pool, ZFS_TYPE_DATASET)) != NULL);
1191-
verify(zfs_prop_set(zhp, zfs_prop_to_name(ZFS_PROP_MOUNTPOINT),
1192-
"/") == 0);
1193-
1194-
zfs_close(zhp);
1195-
}
1196-
11971181
create_failed:
11981182
zcmd_free_nvlists(&zc);
11991183
nvlist_free(zc_props);

usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_005_pos.ksh

100644100755
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,16 @@ do
103103
[[ "$mpt" != "$mpt_val" ]] && \
104104
log_fail "The value of mountpoint property is different\
105105
from the output of zfs mount"
106-
if [[ "$opt" == "-R $TESTDIR1" ]] || [[ "$opt" == "-m $TESTDIR1" ]];
107-
then
106+
if [[ "$opt" == "-m $TESTDIR1" ]]; then
108107
[[ ! -d $TESTDIR1 ]] && \
109108
log_fail "$TESTDIR1 is not created auotmatically."
110109
[[ "$mpt" != "$TESTDIR1" ]] && \
111110
log_fail "$TESTPOOL is not mounted on $TESTDIR1."
111+
elif [[ "$opt" == "-R $TESTDIR1" ]]; then
112+
[[ ! -d $TESTDIR1/$TESTPOOL ]] && \
113+
log_fail "$TESTDIR1/$TESTPOOL is not created auotmatically."
114+
[[ "$mpt" != "$TESTDIR1/$TESTPOOL" ]] && \
115+
log_fail "$TESTPOOL is not mounted on $TESTDIR1/$TESTPOOL."
112116
else
113117
[[ ! -d ${TESTDIR1}$TESTDIR1 ]] && \
114118
log_fail "${TESTDIR1}$TESTDIR1 is not created automatically."

0 commit comments

Comments
 (0)