Add option for forcible unmounting dataset while receiving snapshot.

Currently when the dataset is in use we can't receive snapshots.

    zfs send test/1@asd | zfs recv -FM test/2
    cannot unmount '/test/2': Device busy

This commits add option 'M' which attempts to forcibly unmount the
dataset.  Thanks to this we can enforce receiving snapshots in a
single step.

Note that this functionality is not supported on Linux because the
VFS will prevent active mounted filesystems from being unmounted,
even with the force option.  This is the intended VFS behavior.

Test cases were added to verify the expected behavior based on
the platform.

Discussed-with: Pawel Jakub Dawidek <pjd@FreeBSD.org>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Allan Jude <allanjude@freebsd.org>
External-issue: https://reviews.freebsd.org/D22306
Closes #9904
This commit is contained in:
Mariusz Zaborski
2020-03-17 18:08:32 +01:00
committed by GitHub
parent 80d98a8f3a
commit a57d3d45d6
7 changed files with 113 additions and 14 deletions
+4 -3
View File
@@ -208,9 +208,10 @@ tests = ['zfs_receive_001_pos', 'zfs_receive_002_pos', 'zfs_receive_003_pos',
'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_013_pos', 'zfs_receive_014_pos', 'zfs_receive_015_pos',
'receive-o-x_props_override', 'zfs_receive_from_encrypted',
'zfs_receive_to_encrypted', 'zfs_receive_raw',
'zfs_receive_raw_incremental', 'zfs_receive_-e', 'zfs_receive_raw_-d']
'zfs_receive_016_pos', 'receive-o-x_props_override',
'zfs_receive_from_encrypted', 'zfs_receive_to_encrypted',
'zfs_receive_raw', 'zfs_receive_raw_incremental', 'zfs_receive_-e',
'zfs_receive_raw_-d']
tags = ['functional', 'cli_root', 'zfs_receive']
[tests/functional/cli_root/zfs_rename]
@@ -17,6 +17,7 @@ dist_pkgdata_SCRIPTS = \
zfs_receive_013_pos.ksh \
zfs_receive_014_pos.ksh \
zfs_receive_015_pos.ksh \
zfs_receive_016_pos.ksh \
receive-o-x_props_override.ksh \
zfs_receive_from_encrypted.ksh \
zfs_receive_to_encrypted.ksh \
@@ -0,0 +1,85 @@
#!/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 (c) 2020 by Mariusz Zaborski <oshogbo@FreeBSD.org>.
#
# DESCRIPTION:
# Verify 'zfs recv' can forcibly unmount filesystem while receiving
# stream.
#
# STRATEGY:
# 1. Create snapshot of file system
# 2. Make a zfs filesystem mountpoint busy
# 3. Receive filesystem with force flag.
# 4. Verify that stream was received or failed on Linux.
#
. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
verify_runnable "both"
function cleanup
{
cd $curpath
for snap in $init_snap $rst_snap; do
snapexists $snap && \
destroy_snapshot $snap
done
datasetexists $rst_root && \
destroy_dataset $rst_root
for file in $full_bkup
do
[[ -e $file ]] && \
log_must rm -f $file
done
[[ -d $TESTDIR1 ]] && \
log_must rm -rf $TESTDIR1
}
log_assert "Verify 'zfs recv' can forcibly unmount busy filesystem."
log_onexit cleanup
curpath=`dirname $0`
init_snap=$TESTPOOL/$TESTFS@init_snap
full_bkup=$TEST_BASE_DIR/fullbkup.$$
rst_root=$TESTPOOL/rst_ctr
rst_snap=$rst_root@init_snap
log_note "Verify 'zfs recv' can forcible unmount busy filesystem."
# Preparation
log_must zfs create $rst_root
[[ ! -d $TESTDIR1 ]] && \
log_must mkdir -p $TESTDIR1
log_must zfs set mountpoint=$TESTDIR1 $rst_root
log_must zfs snapshot $init_snap
log_must eval "zfs send $init_snap > $full_bkup"
# Test
log_must cd $TESTDIR1
if is_linux; then
# Linux does not support it.
log_mustnot zfs receive -MF $rst_snap < $full_bkup
else
log_must zfs receive -MF $rst_snap < $full_bkup
fi
log_pass "The busy filesystem was unmounted or busy as expected."