Skip to content

Commit 794f158

Browse files
authored
When receiving a stream with the large block flag, activate feature
ZFS send streams include a feature flag DMU_BACKUP_FEATURE_LARGE_BLOCKS to indicate the presence of large blocks in the dataset. On the sending side, this flag is included if the `-L` flag is passed to `zfs send` and the feature is active in the dataset. On the receive side, the stream is refused if the feature is active in the destination dataset but the stream does not include the feature flag. The problem is the feature is only activated when a large block is born. If a large block has been born in the destination, but never the source, the send can't work. This can arise when sending streams back and forth between two datasets. This commit fixes the problem by always activating the large blocks feature when receiving a stream with the large block feature flag. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com> Signed-off-by: Austin Wise <AustinWise@gmail.com> Closes #18105
1 parent 2301755 commit 794f158

5 files changed

Lines changed: 188 additions & 0 deletions

File tree

module/zfs/dmu_recv.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,22 @@ dmu_recv_begin_sync(void *arg, dmu_tx_t *tx)
10181018
dmu_buf_will_dirty(newds->ds_dbuf, tx);
10191019
dsl_dataset_phys(newds)->ds_flags |= DS_FLAG_INCONSISTENT;
10201020

1021+
/*
1022+
* When receiving, we refuse to accept streams that are missing the
1023+
* large block feature flag if the large block is already active
1024+
* (see ZFS_ERR_STREAM_LARGE_BLOCK_MISMATCH). To prevent this
1025+
* check from being spuriously triggered, we always activate
1026+
* the large block feature if the feature flag is present in the
1027+
* stream. This covers the case where the sending side has the feature
1028+
* active, but has since deleted the file containing large blocks.
1029+
*/
1030+
if (featureflags & DMU_BACKUP_FEATURE_LARGE_BLOCKS &&
1031+
!dsl_dataset_feature_is_active(newds, SPA_FEATURE_LARGE_BLOCKS)) {
1032+
dsl_dataset_activate_feature(newds->ds_object,
1033+
SPA_FEATURE_LARGE_BLOCKS, (void *)B_TRUE, tx);
1034+
newds->ds_feature[SPA_FEATURE_LARGE_BLOCKS] = (void *)B_TRUE;
1035+
}
1036+
10211037
/*
10221038
* Activate longname feature if received
10231039
*/

tests/runfiles/common.run

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@ tests = ['recv_dedup', 'recv_dedup_encrypted_zvol', 'rsend_001_pos',
997997
'send_freeobjects', 'send_realloc_files', 'send_realloc_encrypted_files',
998998
'send_spill_block', 'send_holds', 'send_hole_birth', 'send_mixed_raw',
999999
'send-wR_encrypted_zvol', 'send_partial_dataset', 'send_invalid',
1000+
'send_large_blocks_incremental', 'send_large_blocks_initial',
10001001
'send_doall', 'send_raw_spill_block', 'send_raw_ashift',
10011002
'send_raw_large_blocks', 'send_leak_keymaps']
10021003
tags = ['functional', 'rsend']

tests/zfs-tests/tests/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,8 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
20602060
functional/rsend/send_holds.ksh \
20612061
functional/rsend/send_hole_birth.ksh \
20622062
functional/rsend/send_invalid.ksh \
2063+
functional/rsend/send_large_blocks_incremental.ksh \
2064+
functional/rsend/send_large_blocks_initial.ksh \
20632065
functional/rsend/send_leak_keymaps.ksh \
20642066
functional/rsend/send-L_toggle.ksh \
20652067
functional/rsend/send_mixed_raw.ksh \
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/ksh -p
2+
# SPDX-License-Identifier: CDDL-1.0
3+
4+
#
5+
# This file and its contents are supplied under the terms of the
6+
# Common Development and Distribution License ("CDDL"), version 1.0.
7+
# You may only use this file in accordance with the terms of version
8+
# 1.0 of the CDDL.
9+
#
10+
# A full copy of the text of the CDDL should have accompanied this
11+
# source. A copy of the CDDL is also available via the Internet at
12+
# http://www.illumos.org/license/CDDL.
13+
#
14+
15+
#
16+
# Copyright (c) 2026 by Austin Wise. All rights reserved.
17+
#
18+
19+
. $STF_SUITE/tests/functional/rsend/rsend.kshlib
20+
. $STF_SUITE/include/properties.shlib
21+
22+
#
23+
# Description:
24+
# Verifies that an incremental receive activates the large block feature when the stream was sent
25+
# from a dataset whose large block feature was activated.
26+
#
27+
# Strategy:
28+
# 1. Create a dataset with 1MB recordsize.
29+
# 2. Create a snapshot at where the feature is inactive.
30+
# 3. Create and delete a large file to activate the large_blocks feature.
31+
# 4. Create a snapshot where the feature is active.
32+
# 5. Send the initial snapshot to a second dataset, where the large_blocks feature remains inactive.
33+
# 6. Send the second snapshot to the dataset incrementally, which should activate the large_blocks feature.
34+
#
35+
36+
verify_runnable "both"
37+
38+
log_assert "Verify incremental receive handles inactive large_blocks feature correctly."
39+
40+
function cleanup
41+
{
42+
cleanup_pool $POOL
43+
cleanup_pool $POOL2
44+
}
45+
log_onexit cleanup
46+
47+
function assert_feature_state {
48+
typeset pool=$1
49+
typeset expected_state=$2
50+
51+
typeset actual_state=$(zpool get -H -o value feature@large_blocks $pool)
52+
log_note "Zpool $pool feature@large_blocks=$actual_state"
53+
if [[ "$actual_state" != "$expected_state" ]]; then
54+
log_fail "pool $pool feature@large_blocks=$actual_state (expected '$expected_state')"
55+
fi
56+
}
57+
58+
typeset srcfs=$POOL/src
59+
typeset destfs=$POOL2/dest
60+
61+
# Create a dataset with a large recordsize (1MB) where the feature is inactive in the initial snapshot
62+
# but active in a later snapshots.
63+
log_must zfs create -o recordsize=1M $srcfs
64+
typeset mntpnt=$(get_prop mountpoint $srcfs)
65+
log_must zfs snapshot $srcfs@feature-inactive
66+
log_must dd if=/dev/urandom of=$mntpnt/big.bin bs=1M count=1
67+
log_must zpool sync $POOL
68+
log_must rm $mntpnt/big.bin
69+
log_must zfs snapshot $srcfs@feature-active
70+
71+
# Assert initial state of pools
72+
assert_feature_state $POOL "active"
73+
assert_feature_state $POOL2 "enabled"
74+
75+
# Initial send does not activate feature.
76+
log_must eval "zfs send -p -L $srcfs@feature-inactive | zfs receive $destfs"
77+
assert_feature_state $POOL2 "enabled"
78+
79+
# Incremental send activates feature.
80+
log_must eval "zfs send -L -i $srcfs@feature-inactive $srcfs@feature-active | zfs receive $destfs"
81+
assert_feature_state $POOL2 "active"
82+
83+
log_pass "Feature activation propagated successfully."
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/ksh -p
2+
# SPDX-License-Identifier: CDDL-1.0
3+
4+
#
5+
# This file and its contents are supplied under the terms of the
6+
# Common Development and Distribution License ("CDDL"), version 1.0.
7+
# You may only use this file in accordance with the terms of version
8+
# 1.0 of the CDDL.
9+
#
10+
# A full copy of the text of the CDDL should have accompanied this
11+
# source. A copy of the CDDL is also available via the Internet at
12+
# http://www.illumos.org/license/CDDL.
13+
#
14+
15+
#
16+
# Copyright (c) 2026 by Austin Wise. All rights reserved.
17+
#
18+
19+
. $STF_SUITE/tests/functional/rsend/rsend.kshlib
20+
. $STF_SUITE/include/properties.shlib
21+
22+
#
23+
# Description:
24+
# Verifies that creating a dataset from a send stream propagates the activation of the large blocks
25+
# feature, even if the send stream contains no large blocks.
26+
# Regression test for https://github.com/openzfs/zfs/issues/18101
27+
#
28+
# Strategy:
29+
# 1. Create a dataset with 1MB recordsize.
30+
# 2. Create and delete a large file to activate the large_blocks feature.
31+
# 3. Send a full stream to a second dataset.
32+
# 4. Send an incremental send back to the original dataset.
33+
#
34+
35+
verify_runnable "both"
36+
37+
log_assert "Verify incremental receive handles inactive large_blocks feature correctly."
38+
39+
function cleanup
40+
{
41+
cleanup_pool $POOL
42+
cleanup_pool $POOL2
43+
}
44+
log_onexit cleanup
45+
46+
function assert_feature_state {
47+
typeset pool=$1
48+
typeset expected_state=$2
49+
50+
typeset actual_state=$(zpool get -H -o value feature@large_blocks $pool)
51+
log_note "Zpool $pool feature@large_blocks=$actual_state"
52+
if [[ "$actual_state" != "$expected_state" ]]; then
53+
log_fail "pool $pool feature@large_blocks=$actual_state (expected '$expected_state')"
54+
fi
55+
}
56+
57+
typeset repro=$POOL/repro
58+
typeset second=$POOL2/second
59+
60+
# Create a dataset with a large recordsize (1MB)
61+
log_must zfs create -o recordsize=1M $repro
62+
typeset mntpnt=$(get_prop mountpoint $repro)
63+
64+
# Activate the large_blocks feature by creating a large file, then delete it
65+
# This leaves the feature 'active' on the dataset level even though large blocks no longer exist.
66+
log_must dd if=/dev/urandom of=$mntpnt/big.bin bs=1M count=1
67+
log_must zpool sync $POOL
68+
log_must rm $mntpnt/big.bin
69+
70+
# Assert initial state of pools
71+
assert_feature_state $POOL "active"
72+
assert_feature_state $POOL2 "enabled"
73+
74+
# Create initial snapshot and send to 'second' dataset.
75+
# The send stream will have the large blocks feature flag active but not actually contain any large blocks.
76+
log_must zfs snapshot $repro@initial
77+
log_must eval "zfs send -p -L $repro@initial | zfs receive $second"
78+
assert_feature_state $POOL2 "active"
79+
80+
# Send an incremental stream back to the original dataset.
81+
# The send stream should have the large_blocks feature flag despite no large blocks ever being
82+
# born in the 'second' dataset.
83+
log_must zfs snapshot $second@second
84+
log_must eval "zfs send -L -i $second@initial $second@second | zfs receive -F $repro"
85+
86+
log_pass "Feature activation propagated successfully."

0 commit comments

Comments
 (0)