mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2025-01-27 18:34:22 +03:00
zpool should detect invalid fs property on create
This change improve the handling of invalid filesystem properties when specified at pool creation: this is useful when 'zpool create -n' (dry run) is executed to detect invalid fs-level options (-O) before the actual command is run. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: loli10K <ezomori.nozomu@gmail.com> Closes #7620 Closes #7878
This commit is contained in:
parent
92b432139d
commit
5140a58f3b
@ -536,7 +536,6 @@ add_prop_list(const char *propname, char *propval, nvlist_t **props,
|
|||||||
boolean_t poolprop)
|
boolean_t poolprop)
|
||||||
{
|
{
|
||||||
zpool_prop_t prop = ZPOOL_PROP_INVAL;
|
zpool_prop_t prop = ZPOOL_PROP_INVAL;
|
||||||
zfs_prop_t fprop;
|
|
||||||
nvlist_t *proplist;
|
nvlist_t *proplist;
|
||||||
const char *normnm;
|
const char *normnm;
|
||||||
char *strval;
|
char *strval;
|
||||||
@ -580,10 +579,18 @@ add_prop_list(const char *propname, char *propval, nvlist_t **props,
|
|||||||
else
|
else
|
||||||
normnm = zpool_prop_to_name(prop);
|
normnm = zpool_prop_to_name(prop);
|
||||||
} else {
|
} else {
|
||||||
if ((fprop = zfs_name_to_prop(propname)) != ZPROP_INVAL) {
|
zfs_prop_t fsprop = zfs_name_to_prop(propname);
|
||||||
normnm = zfs_prop_to_name(fprop);
|
|
||||||
} else {
|
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;
|
normnm = propname;
|
||||||
|
} else {
|
||||||
|
(void) fprintf(stderr, gettext("property '%s' is "
|
||||||
|
"not a valid filesystem property\n"), propname);
|
||||||
|
return (2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,8 @@
|
|||||||
# actually creating the pool.
|
# actually creating the pool.
|
||||||
#
|
#
|
||||||
# STRATEGY:
|
# 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
|
# 2. Verify the pool has not been actually created
|
||||||
#
|
#
|
||||||
|
|
||||||
@ -67,20 +68,39 @@ if is_mpath_device $DISK; then
|
|||||||
partition_disk $SIZE $disk 1
|
partition_disk $SIZE $disk 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
typeset vspec="${disk}${SLICE_PREFIX}${SLICE0}"
|
||||||
# Make sure disk is clean before we use it
|
typeset goodprops=('' '-o comment=text' '-O checksum=on' '-O ns:prop=value')
|
||||||
#
|
typeset badprops=('-o ashift=9999' '-O doesnotexist=on' '-O volsize=10M')
|
||||||
create_pool $TESTPOOL ${disk}${SLICE_PREFIX}${SLICE0} > $tmpfile
|
|
||||||
destroy_pool $TESTPOOL
|
|
||||||
|
|
||||||
zpool create -n $TESTPOOL ${disk}${SLICE_PREFIX}${SLICE0} > $tmpfile
|
# 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
|
||||||
|
|
||||||
poolexists $TESTPOOL && \
|
log_must eval "zpool create -n $prop $TESTPOOL $vspec > $tmpfile"
|
||||||
log_fail "'zpool create -n <pool> <vspec> ...' fail."
|
|
||||||
|
|
||||||
str="would create '$TESTPOOL' with the following layout:"
|
poolexists $TESTPOOL && \
|
||||||
cat $tmpfile | grep "$str" >/dev/null 2>&1
|
log_fail "'zpool create -n <pool> <vspec> ...' fail."
|
||||||
(( $? != 0 )) && \
|
|
||||||
log_fail "'zpool create -n <pool> <vspec>...' is executed as unexpected."
|
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."
|
log_pass "'zpool create -n <pool> <vspec>...' success."
|
||||||
|
Loading…
Reference in New Issue
Block a user