xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/rsend/send_freeobjects.ksh (revision 946342a260bbae359b48bf142ec1fe40792ee862)
1#!/bin/ksh
2
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright (c) 2017 by Lawrence Livermore National Security, LLC.
16#
17
18. $STF_SUITE/include/libtest.shlib
19. $STF_SUITE/tests/functional/rsend/rsend.kshlib
20
21#
22# Description:
23# Verify FREEOBJECTS record frees sequential objects (See
24# https://github.com/zfsonlinux/zfs/issues/6694)
25#
26# Strategy:
27# 1. Create three files with sequential object numbers, f1 f2 and f3
28# 2. Delete f2
29# 3. Take snapshot A
30# 4. Delete f3
31# 5. Take snapshot B
32# 6. Receive a full send of A
33# 7. Receive an incremental send of B
34# 8. Fail test if f3 exists on received snapshot B
35#
36
37verify_runnable "both"
38
39log_assert "Verify FREEOBJECTS record frees sequential objects"
40
41sendds=sendfo
42recvds=recvfo
43f1=/$POOL/$sendds/f1
44f2=/$POOL/$sendds/f2
45f3=/$POOL/$sendds/f3
46
47#
48# We need to set xattr=sa and dnodesize=legacy to guarantee sequential
49# object numbers for this test. Otherwise, if we used directory-based
50# xattrs, SELinux extended attributes might consume intervening object
51# numbers.
52#
53log_must zfs create -o xattr=sa -o dnodesize=legacy $POOL/$sendds
54
55tries=100
56for ((i=0; i<$tries; i++)); do
57	touch $f1 $f2 $f3
58	o1=$(ls -li $f1 | awk '{print $1}')
59	o2=$(ls -li $f2 | awk '{print $1}')
60	o3=$(ls -li $f3 | awk '{print $1}')
61
62	if [[ $o2 -ne $(( $o1 + 1 )) ]] || [[ $o3 -ne $(( $o2 + 1 )) ]]; then
63		rm -f $f1 $f2 $f3
64	else
65		break
66	fi
67done
68
69if [[ $i -eq $tries ]]; then
70	log_fail "Failed to create three sequential objects"
71fi
72
73log_must rm $f2
74log_must zfs snap $POOL/$sendds@A
75log_must rm $f3
76log_must zfs snap $POOL/$sendds@B
77log_must eval "zfs send $POOL/$sendds@A | zfs recv $POOL/$recvds"
78log_must eval "zfs send -i $POOL/$sendds@A $POOL/$sendds@B |" \
79	"zfs recv $POOL/$recvds"
80log_mustnot zdb $POOL/$recvds@B $o3
81log_pass "Verify FREEOBJECTS record frees sequential objects"
82