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

zpool should detect invalid fsproperty on create #7878

Merged
merged 1 commit into from
Sep 13, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ add_prop_list(const char *propname, char *propval, nvlist_t **props,
boolean_t poolprop)
{
zpool_prop_t prop = ZPOOL_PROP_INVAL;
zfs_prop_t fprop;
nvlist_t *proplist;
const char *normnm;
char *strval;
Expand Down Expand Up @@ -580,10 +579,18 @@ add_prop_list(const char *propname, char *propval, nvlist_t **props,
else
normnm = zpool_prop_to_name(prop);
} else {
if ((fprop = zfs_name_to_prop(propname)) != ZPROP_INVAL) {
normnm = zfs_prop_to_name(fprop);
} else {
zfs_prop_t fsprop = zfs_name_to_prop(propname);

if (zfs_prop_valid_for_type(fsprop, ZFS_TYPE_FILESYSTEM,
B_FALSE)) {
normnm = zfs_prop_to_name(fsprop);
} else if (zfs_prop_user(propname) ||
zfs_prop_userquota(propname)) {
normnm = propname;
} else {
(void) fprintf(stderr, gettext("property '%s' is "
"not a valid filesystem property\n"), propname);
return (2);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
# actually creating the pool.
#
# STRATEGY:
# 1. Create storage pool with -n option
# 1. Create storage pool with -n option; this should only work when valid
# properties are specified on the command line
# 2. Verify the pool has not been actually created
#

Expand Down Expand Up @@ -67,20 +68,39 @@ if is_mpath_device $DISK; then
partition_disk $SIZE $disk 1
fi

#
# Make sure disk is clean before we use it
#
create_pool $TESTPOOL ${disk}${SLICE_PREFIX}${SLICE0} > $tmpfile
destroy_pool $TESTPOOL

zpool create -n $TESTPOOL ${disk}${SLICE_PREFIX}${SLICE0} > $tmpfile

poolexists $TESTPOOL && \
log_fail "'zpool create -n <pool> <vspec> ...' fail."

str="would create '$TESTPOOL' with the following layout:"
cat $tmpfile | grep "$str" >/dev/null 2>&1
(( $? != 0 )) && \
log_fail "'zpool create -n <pool> <vspec>...' is executed as unexpected."
typeset vspec="${disk}${SLICE_PREFIX}${SLICE0}"
typeset goodprops=('' '-o comment=text' '-O checksum=on' '-O ns:prop=value')
typeset badprops=('-o ashift=9999' '-O doesnotexist=on' '-O volsize=10M')

# Verify zpool create -n with valid pool-level and fs-level options
for prop in "${goodprops[@]}"
do
#
# Make sure disk is clean before we use it
#
create_pool $TESTPOOL $vspec > $tmpfile
destroy_pool $TESTPOOL

log_must eval "zpool create -n $prop $TESTPOOL $vspec > $tmpfile"

poolexists $TESTPOOL && \
log_fail "'zpool create -n <pool> <vspec> ...' fail."

str="would create '$TESTPOOL' with the following layout:"
grep "$str" $tmpfile >/dev/null 2>&1 || \
log_fail "'zpool create -n <pool> <vspec>...' is executed as unexpected."
done

# Verify zpool create -n with invalid options
for prop in "${badprops[@]}"
do
#
# Make sure disk is clean before we use it
#
create_pool $TESTPOOL $vspec > $tmpfile
destroy_pool $TESTPOOL

log_mustnot zpool create -n $prop $TESTPOOL $vspec
done

log_pass "'zpool create -n <pool> <vspec>...' success."