]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_016_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_receive / zfs_receive_016_pos.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
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 # CDDL HEADER END
15 #
16 # Copyright (c) 2020 by Mariusz Zaborski <oshogbo@FreeBSD.org>.
17
18 #
19 # DESCRIPTION:
20 # Verify 'zfs recv' can forcibly unmount filesystem while receiving
21 # stream.
22 #
23 # STRATEGY:
24 # 1. Create snapshot of file system
25 # 2. Make a zfs filesystem mountpoint busy
26 # 3. Receive filesystem with force flag.
27 # 4. Verify that stream was received or failed on Linux.
28 #
29
30 . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
31
32 verify_runnable "both"
33
34 function cleanup
35 {
36         cd $curpath
37
38         for snap in $init_snap $rst_snap; do
39                 snapexists $snap && \
40                         destroy_snapshot $snap
41         done
42
43         datasetexists $rst_root && \
44                 destroy_dataset $rst_root
45
46         for file in $full_bkup
47         do
48                 [[ -e $file ]] && \
49                         log_must rm -f $file
50         done
51
52         [[ -d $TESTDIR1 ]] && \
53                 log_must rm -rf $TESTDIR1
54 }
55
56 log_assert "Verify 'zfs recv' can forcibly unmount busy filesystem."
57 log_onexit cleanup
58
59 curpath=`dirname $0`
60 init_snap=$TESTPOOL/$TESTFS@init_snap
61 full_bkup=$TEST_BASE_DIR/fullbkup.$$
62 rst_root=$TESTPOOL/rst_ctr
63 rst_snap=$rst_root@init_snap
64
65 log_note "Verify 'zfs recv' can forcible unmount busy filesystem."
66
67 # Preparation
68 log_must zfs create $rst_root
69 [[ ! -d $TESTDIR1 ]] && \
70         log_must mkdir -p $TESTDIR1
71 log_must zfs set mountpoint=$TESTDIR1 $rst_root
72
73 log_must zfs snapshot $init_snap
74 log_must eval "zfs send $init_snap > $full_bkup"
75
76 # Test
77 log_must cd $TESTDIR1
78 if is_linux; then
79     # Linux does not support it.
80     log_mustnot zfs receive -MF $rst_snap < $full_bkup
81 else
82     log_must zfs receive -MF $rst_snap < $full_bkup
83 fi
84
85 log_pass "The busy filesystem was unmounted or busy as expected."