blob: e5fe8825769de90457bda66a8629b39b34cc5048 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2011 Oracle All Rights Reserved.
#
# FS QA Test No. btrfs/002
#
# Extented btrfs snapshot test cases
#
. ./common/preamble
_begin_fstest auto snapshot
. ./common/filter
_supported_fs btrfs
_require_scratch
_scratch_mkfs > /dev/null 2>&1 || _fail "mkfs failed"
_scratch_mount
# Create and save sha256sum
# arg1 FS to generate sha256
# arg2 File name to save the sha256 output
_save_checksum()
{
local i=0
>$2
cd $1
for i in `find . -type f`; do sha256sum $i >> $2; done
cd $OLDPWD
}
# Verify the sha256sum for a FS
# arg1 FS to be tested
# arg2 sha256 file
_verify_checksum()
{
cd $1
[ -f $2 ] || _fail "checksum file $2 not found"
sha256sum -c $2 | grep "FAILED"
cd $OLDPWD
}
# Create a snapshot
# arg1 dest dir
# Return snapshot name in the SNAPNAME
_create_snap()
{
local x
[ -d $1 ] || _fail "Destination dir $1 not present"
SNAPNAME=`mktemp -u $SCRATCH_MNT/snap.XXXXXX`
$BTRFS_UTIL_PROG subvolume snapshot $1 $SNAPNAME > /dev/null || _fail "snapshot create failed"
}
# Reads and writes new data but does not allocate new blocks
# arg1 FS to be modified
_read_modify_write()
{
local i
local FSIZE
for i in `find $1 -type f`
do
FSIZE=`stat -t $i | cut -d" " -f2`
dd if=$i of=/dev/null obs=$FSIZE count=1 status=noxfer 2>/dev/null &
_ddt of=$i obs=$FSIZE count=1 status=noxfer 2>/dev/null &
done
wait $!
}
# Fills the allocated blocks
# arg1 FS in question
_fill_blk()
{
local FSIZE
local BLKS
local NBLK
local FALLOC
local WS
for i in `find /$1 -type f`
do
FSIZE=`stat -t $i | cut -d" " -f2`
BLKS=`stat -c "%B" $i`
NBLK=`stat -c "%b" $i`
FALLOC=$(($BLKS * $NBLK))
WS=$(($FALLOC - $FSIZE))
_ddt of=$i oseek=$FSIZE obs=$WS count=1 status=noxfer 2>/dev/null &
done
wait $!
}
# Append a random size to the files
# arg1 : FS in question
_append_file()
{
local FSIZE
local X
local N
local i
N=0
for i in `find $1 -type f`
do
if [ $N == 0 ]; then
X=$i
FSIZE=`stat -t $X | cut -d" " -f2`
dd if=$X of=$X seek=1 bs=$FSIZE obs=$FSIZE count=1 status=noxfer 2>/dev/null &
N=$(($N+1))
continue
fi
FSIZE=`stat -t $i | cut -d" " -f2`
dd if=$X of=$i seek=1 bs=$FSIZE obs=$FSIZE count=1 status=noxfer 2>/dev/null &
X=$i
done
wait $!
}
# sv1 - is just a name nothing spl
firstvol="$SCRATCH_MNT/sv1"
$BTRFS_UTIL_PROG subvolume create $firstvol > /dev/null || _fail "btrfs subvolume create $firstvol failed"
dirp=`mktemp -duq $firstvol/dir.XXXXXX`
_populate_fs -n 1 -f 20 -d 10 -r $dirp -s 10 -c
SNAPNAME=0
_create_snap $firstvol
_save_checksum $firstvol $tmp.sv1.sum
_verify_checksum $SNAPNAME $tmp.sv1.sum
#Append1 the files
_fill_blk $SNAPNAME
_verify_checksum $firstvol $tmp.sv1.sum
#Append2 the files
_append_file $SNAPNAME
_verify_checksum $firstvol $tmp.sv1.sum
#read modify write
_read_modify_write $SNAPNAME
_verify_checksum $firstvol $tmp.sv1.sum
#nested snapshot test
src_vol=$firstvol
for i in `seq 1 7`; do
SNAPNAME=0
_create_snap $src_vol
_verify_checksum $SNAPNAME $tmp.sv1.sum
src_vol=$SNAPNAME
done
# file delete test
SNAPNAME=0
_create_snap $firstvol
tname=`echo $SNAPNAME | rev | cut -d"/" -f1 | rev`
_save_checksum $SNAPNAME $tmp.$tname.sum
\rm -rf $firstvol/*
_verify_checksum $SNAPNAME $tmp.$tname.sum
_scratch_unmount || _fail "unmount failed"
echo "Silence is golden"
status=0; exit
|