Fix dsl_props_set_sync_impl to work with nested nvlist

When iterating over the input nvlist in dsl_props_set_sync_impl() when we don't
preserve the nvpair name before looking up ZPROP_VALUE, so when we later go to
process it nvpair_name() is always "value" and not the actual property name.

This fixes a couple of bugs in zfs_ioc_recv():
* Received properties were not restored correctly when failing to receive an
incremental send stream
* Received properties were not completely replaced by the new ones when
successfully receiving an incremental send stream

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
Closes #5497
This commit is contained in:
LOLi 2016-12-21 03:46:59 +01:00 committed by Brian Behlendorf
parent a3823f428d
commit 5f1346c299
4 changed files with 134 additions and 7 deletions

View File

@ -892,11 +892,15 @@ dsl_props_set_sync_impl(dsl_dataset_t *ds, zprop_source_t source,
while ((elem = nvlist_next_nvpair(props, elem)) != NULL) { while ((elem = nvlist_next_nvpair(props, elem)) != NULL) {
nvpair_t *pair = elem; nvpair_t *pair = elem;
const char *name = nvpair_name(pair);
if (nvpair_type(pair) == DATA_TYPE_NVLIST) { if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
/* /*
* dsl_prop_get_all_impl() returns properties in this * This usually happens when we reuse the nvlist_t data
* format. * returned by the counterpart dsl_prop_get_all_impl().
* For instance we do this to restore the original
* received properties when an error occurs in the
* zfs_ioc_recv() codepath.
*/ */
nvlist_t *attrs = fnvpair_value_nvlist(pair); nvlist_t *attrs = fnvpair_value_nvlist(pair);
pair = fnvlist_lookup_nvpair(attrs, ZPROP_VALUE); pair = fnvlist_lookup_nvpair(attrs, ZPROP_VALUE);
@ -904,14 +908,14 @@ dsl_props_set_sync_impl(dsl_dataset_t *ds, zprop_source_t source,
if (nvpair_type(pair) == DATA_TYPE_STRING) { if (nvpair_type(pair) == DATA_TYPE_STRING) {
const char *value = fnvpair_value_string(pair); const char *value = fnvpair_value_string(pair);
dsl_prop_set_sync_impl(ds, nvpair_name(pair), dsl_prop_set_sync_impl(ds, name,
source, 1, strlen(value) + 1, value, tx); source, 1, strlen(value) + 1, value, tx);
} else if (nvpair_type(pair) == DATA_TYPE_UINT64) { } else if (nvpair_type(pair) == DATA_TYPE_UINT64) {
uint64_t intval = fnvpair_value_uint64(pair); uint64_t intval = fnvpair_value_uint64(pair);
dsl_prop_set_sync_impl(ds, nvpair_name(pair), dsl_prop_set_sync_impl(ds, name,
source, sizeof (intval), 1, &intval, tx); source, sizeof (intval), 1, &intval, tx);
} else if (nvpair_type(pair) == DATA_TYPE_BOOLEAN) { } else if (nvpair_type(pair) == DATA_TYPE_BOOLEAN) {
dsl_prop_set_sync_impl(ds, nvpair_name(pair), dsl_prop_set_sync_impl(ds, name,
source, 0, 0, NULL, tx); source, 0, 0, NULL, tx);
} else { } else {
panic("invalid nvpair type"); panic("invalid nvpair type");

View File

@ -147,7 +147,7 @@ tests = ['zfs_receive_001_pos', 'zfs_receive_002_pos', 'zfs_receive_003_pos',
'zfs_receive_005_neg', 'zfs_receive_006_pos', 'zfs_receive_005_neg', 'zfs_receive_006_pos',
'zfs_receive_007_neg', 'zfs_receive_008_pos', 'zfs_receive_009_neg', 'zfs_receive_007_neg', 'zfs_receive_008_pos', 'zfs_receive_009_neg',
'zfs_receive_010_pos', 'zfs_receive_011_pos', 'zfs_receive_012_pos', 'zfs_receive_010_pos', 'zfs_receive_011_pos', 'zfs_receive_012_pos',
'zfs_receive_013_pos'] 'zfs_receive_013_pos', 'zfs_receive_014_pos']
[tests/functional/cli_root/zfs_rename] [tests/functional/cli_root/zfs_rename]
tests = ['zfs_rename_001_pos', 'zfs_rename_002_pos', 'zfs_rename_003_pos', tests = ['zfs_rename_001_pos', 'zfs_rename_002_pos', 'zfs_rename_003_pos',

View File

@ -14,4 +14,5 @@ dist_pkgdata_SCRIPTS = \
zfs_receive_010_pos.ksh \ zfs_receive_010_pos.ksh \
zfs_receive_011_pos.ksh \ zfs_receive_011_pos.ksh \
zfs_receive_012_pos.ksh \ zfs_receive_012_pos.ksh \
zfs_receive_013_pos.ksh zfs_receive_013_pos.ksh \
zfs_receive_014_pos.ksh

View File

@ -0,0 +1,122 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# 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.
#
# CDDL HEADER END
#
#
# Copyright 2016, loli10K. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
#
# DESCRIPTION:
# Verify ZFS successfully receive and restore properties.
#
# STRATEGY:
# 1. Create a filesystem.
# 2. Create a full stream with properties and receive it.
# 3. Create also an incremental stream without some properties and a truncated
# stream.
# 4. Fail to receive the truncated incremental stream and verify previously
# received properties are still present.
# 5. Receive the complete incremental send stream and verify that sent
# properties are successfully received.
#
verify_runnable "both"
orig=$TESTPOOL/$TESTFS1
dest=$TESTPOOL/$TESTFS2
typeset userprop=$(valid_user_property 8)
typeset userval=$(user_property_value 8)
typeset streamfile_full=/var/tmp/streamfile_full.$$
typeset streamfile_incr=/var/tmp/streamfile_incr.$$
typeset streamfile_trun=/var/tmp/streamfile_trun.$$
function cleanup
{
log_must $RM $streamfile_full
log_must $RM $streamfile_incr
log_must $RM $streamfile_trun
log_must $ZFS destroy -rf $orig
log_must $ZFS destroy -rf $dest
}
#
# Verify property $2 is set from source $4 on dataset $1 and has value $3.
#
# $1 checked dataset
# $2 user property
# $3 property value
# $4 source
#
function check_prop_source
{
typeset dataset=$1
typeset prop=$2
typeset value=$3
typeset source=$4
typeset chk_value=$(get_prop "$prop" "$dataset")
typeset chk_source=$(get_source "$prop" "$dataset")
if [[ "$chk_value" != "$value" || \
"$chk_source" != "$4" ]]
then
return 1
else
return 0
fi
}
log_assert "ZFS successfully receive and restore properties."
log_onexit cleanup
# 1. Create a filesystem.
log_must eval "$ZFS create $orig"
mntpnt=$(get_prop mountpoint $orig)
# 2. Create a full stream with properties and receive it.
log_must eval "$ZFS set compression='gzip-1' $orig"
log_must eval "$ZFS set '$userprop'='$userval' $orig"
log_must eval "$ZFS snapshot $orig@snap1"
log_must eval "$ZFS send -p $orig@snap1 > $streamfile_full"
log_must eval "$ZFS recv $dest < $streamfile_full"
log_must eval "check_prop_source $dest compression 'gzip-1' received"
log_must eval "check_prop_source $dest '$userprop' '$userval' received"
# 3. Create also an incremental stream without some properties and a truncated
# stream.
log_must eval "$ZFS set compression='gzip-2' $orig"
log_must eval "$ZFS inherit '$userprop' $orig"
log_must eval "$DD if=/dev/urandom of=$mntpnt/file bs=1024k count=10"
log_must eval "$ZFS snapshot $orig@snap2"
log_must eval "$ZFS send -p -i $orig@snap1 $orig@snap2 > $streamfile_incr"
log_must eval "$DD if=$streamfile_incr of=$streamfile_trun bs=1024k count=9"
log_must eval "$ZFS snapshot $orig@snap3"
log_must eval "$ZFS send -p -i $orig@snap1 $orig@snap3 > $streamfile_incr"
# 4. Fail to receive the truncated incremental stream and verify previously
# received properties are still present.
log_mustnot eval "$ZFS recv -F $dest < $streamfile_trun"
log_must eval "check_prop_source $dest compression 'gzip-1' received"
log_must eval "check_prop_source $dest '$userprop' '$userval' received"
# 5. Receive the complete incremental send stream and verify that sent
# properties are successfully received.
log_must eval "$ZFS recv -F $dest < $streamfile_incr"
log_must eval "check_prop_source $dest compression 'gzip-2' received"
log_must eval "check_prop_source $dest '$userprop' '-' '-'"
log_pass "ZFS properties are successfully received and restored."