Debian Codegraph @

sparsify/test-virt-sparsify-in-place.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`. -
2 # libguestfs virt-sparsify --in-place test script
3 # Copyright (C) 2011-2025 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 source ../tests/functions.shscip-shell source . . `../tests/functions.sh`.
20 set -e
21 set -x
22
23 skip_if_skipped
24
25 rmscip-shell system . . rm. -f test-virt-sparsify-in-place.img
26
27 # Create a filesystem, fill it with data, then delete the data. Then
28 # prove that sparsifying it reduces the size of the final filesystem.
29
30 $VG guestfish \
31 -N test-virt-sparsify-in-place.img=bootrootlv:/dev/VG/LV:ext4:ext4:400M:32M:gpt <<EOF
32 mount /dev/VG/LV /
33 mkdir /boot
34 mount /dev/sda1 /boot
35 fill 1 300M /big
36 fill 1 10M /boot/big
37 sync
38 rm /big
39 rm /boot/big
40 umount-all
41 EOF
42
43 size_before=$(duscip-shell system . . du. -s test-virt-sparsify-in-place.img | awkscip-shell system . . awk. '{print $1}')
44
45 $VG virt-sparsify --debug-gc --in-place --format raw test-virt-sparsify-in-place.img || {
46 if [scip-shell system . . `[`. "$?" -eq 3 ]; then
47 rmscip-shell system . . rm. test-virt-sparsify-in-place.img
48 echoscip-shell system . . echo. "$0: discard not supported in virt-sparsify"
49 exit 77
50 fi
51 exit 1
52 }
53
54 size_after=$(duscip-shell system . . du. -s test-virt-sparsify-in-place.img | awkscip-shell system . . awk. '{print $1}')
55
56 echoscip-shell system . . echo. "test virt-sparsify: $size_before K -> $size_after K"
57
58 if [scip-shell system . . `[`. $size_before -lt 310000 ]; then
59 echoscip-shell system . . echo. "test virt-sparsify --in-place: size_before ($size_before) too small"
60 exit 1
61 fi
62
63 # The space we're expecting to recover is 300 + 10 MB, so as long as
64 # size_before - size_after > 300000 it shows we have recovered the
65 # majority of the file space and sparsification is working. (RHBZ#1079210)
66
67 if [scip-shell system . . `[`. $((size_before-size_after)) -le 300000 ]; then
68 echoscip-shell system . . echo. "test virt-sparsify --in-place: size_after ($size_after) too large"
69 echoscip-shell system . . echo. "sparsification failed"
70 exit 1
71 fi
72
73 rmscip-shell system . . rm. test-virt-sparsify-in-place.img