summaryrefslogtreecommitdiff
path: root/test/shell/lvresize-fs-crypt.sh
blob: 4bef771dcdaf316e50a8e31104f2b07f3618d0d9 (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
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash

# Copyright (C) 2007-2016 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA


SKIP_WITH_LVMPOLLD=1

. lib/inittest

aux prepare_vg 3 256

which mkfs.xfs || skip

# Tests require a libblkid version that shows FSLASTBLOCK
lvcreate -n $lv1 -L 300 $vg
mkfs.xfs -f "$DM_DEV_DIR/$vg/$lv1"
blkid -p "$DM_DEV_DIR/$vg/$lv1" | grep FSLASTBLOCK || skip
lvchange -an $vg
lvremove $vg/$lv1

mount_dir="mnt_lvresize_cr"
mkdir -p "$mount_dir"

# dm-crypt device on lv
cr="$PREFIX-$lv-cr"

# lvextend ext4 on LUKS1
lvcreate -n $lv -L 256M $vg
echo 93R4P4pIqAH8 | cryptsetup luksFormat -i1 --type luks1 "$DM_DEV_DIR/$vg/$lv"
echo 93R4P4pIqAH8 | cryptsetup luksOpen "$DM_DEV_DIR/$vg/$lv" $cr
mkfs.ext4 /dev/mapper/$cr
mount /dev/mapper/$cr "$mount_dir"
dd if=/dev/zero of="$mount_dir/zeros1" bs=1M count=200 conv=fdatasync
df --output=size "$mount_dir" |tee df1
lvextend -L+200M --fs resize $vg/$lv
check lv_field $vg/$lv lv_size "456.00m"
df --output=size "$mount_dir" |tee df2
not diff df1 df2
umount "$mount_dir"
cryptsetup close $cr
lvchange -an $vg/$lv
lvremove $vg/$lv

# lvreduce ext4 on LUKS1
lvcreate -n $lv -L 456M $vg
echo 93R4P4pIqAH8 | cryptsetup luksFormat -i1 --type luks1 "$DM_DEV_DIR/$vg/$lv"
echo 93R4P4pIqAH8 | cryptsetup luksOpen "$DM_DEV_DIR/$vg/$lv" $cr
mkfs.ext4 /dev/mapper/$cr
mount /dev/mapper/$cr "$mount_dir"
dd if=/dev/zero of="$mount_dir/zeros1" bs=1M count=200 conv=fdatasync
df --output=size "$mount_dir" |tee df1
lvresize -L-100M --yes --fs resize $vg/$lv
check lv_field $vg/$lv lv_size "356.00m"
df --output=size "$mount_dir" |tee df2
not diff df1 df2
umount "$mount_dir"
cryptsetup close $cr
lvchange -an $vg/$lv
lvremove $vg/$lv

# lvextend xfs on LUKS1
lvcreate -n $lv -L 256M $vg
echo 93R4P4pIqAH8 | cryptsetup luksFormat -i1 --type luks1 "$DM_DEV_DIR/$vg/$lv"
echo 93R4P4pIqAH8 | cryptsetup luksOpen "$DM_DEV_DIR/$vg/$lv" $cr
mkfs.xfs /dev/mapper/$cr
mount /dev/mapper/$cr "$mount_dir"
dd if=/dev/zero of="$mount_dir/zeros1" bs=1M count=200 conv=fdatasync
df --output=size "$mount_dir" |tee df1
lvextend -L+200M --fs resize $vg/$lv
check lv_field $vg/$lv lv_size "456.00m"
df --output=size "$mount_dir" |tee df2
not diff df1 df2
umount "$mount_dir"
cryptsetup close $cr
lvchange -an $vg/$lv
lvremove $vg/$lv

# lvreduce xfs on LUKS1
lvcreate -n $lv -L 456M $vg
echo 93R4P4pIqAH8 | cryptsetup luksFormat -i1 --type luks1 "$DM_DEV_DIR/$vg/$lv"
echo 93R4P4pIqAH8 | cryptsetup luksOpen "$DM_DEV_DIR/$vg/$lv" $cr
mkfs.xfs /dev/mapper/$cr
mount /dev/mapper/$cr "$mount_dir"
dd if=/dev/zero of="$mount_dir/zeros1" bs=1M count=200 conv=fdatasync
df --output=size "$mount_dir" |tee df1
# xfs cannot be reduced
not lvresize -L-100M --yes --fs resize $vg/$lv
check lv_field $vg/$lv lv_size "456.00m"
df --output=size "$mount_dir" |tee df2
diff df1 df2
umount "$mount_dir"
cryptsetup close $cr
lvchange -an $vg/$lv
lvremove $vg/$lv

# lvextend ext4 on plain crypt (no header)
lvcreate -n $lv -L 256M $vg
echo 93R4P4pIqAH8 | cryptsetup create $cr "$DM_DEV_DIR/$vg/$lv"
mkfs.ext4 /dev/mapper/$cr
mount /dev/mapper/$cr "$mount_dir"
dd if=/dev/zero of="$mount_dir/zeros1" bs=1M count=200 conv=fdatasync
df --output=size "$mount_dir" |tee df1
# fails when no fs is found for --fs resize
not lvextend -L+200M --yes --fs resize $vg/$lv
check lv_field $vg/$lv lv_size "256.00m"
df --output=size "$mount_dir" |tee df2
diff df1 df2
umount "$mount_dir"
cryptsetup close $cr
lvchange -an $vg/$lv
lvremove $vg/$lv

# lvreduce ext4 on plain crypt (no header)
lvcreate -n $lv -L 456M $vg
echo 93R4P4pIqAH8 | cryptsetup create $cr "$DM_DEV_DIR/$vg/$lv"
mkfs.ext4 /dev/mapper/$cr
mount /dev/mapper/$cr "$mount_dir"
dd if=/dev/zero of="$mount_dir/zeros1" bs=1M count=200 conv=fdatasync
df --output=size "$mount_dir" |tee df1
# fails when no fs is found for --fs resize
not lvresize -L-100M --yes --fs resize $vg/$lv
check lv_field $vg/$lv lv_size "456.00m"
df --output=size "$mount_dir" |tee df2
diff df1 df2
umount "$mount_dir"
cryptsetup close $cr
lvchange -an $vg/$lv
lvremove $vg/$lv

# lvresize uses helper only for crypt dev resize
# because the fs was resized separately beforehand
lvcreate -n $lv -L 456M $vg
echo 93R4P4pIqAH8 | cryptsetup luksFormat -i1 --type luks1 "$DM_DEV_DIR/$vg/$lv"
echo 93R4P4pIqAH8 | cryptsetup luksOpen "$DM_DEV_DIR/$vg/$lv" $cr
mkfs.ext4 /dev/mapper/$cr
mount /dev/mapper/$cr "$mount_dir"
dd if=/dev/zero of="$mount_dir/zeros1" bs=1M count=100 conv=fdatasync
df --output=size "$mount_dir" |tee df1
# resize only the fs (to 256M), not the crypt dev or LV
umount "$mount_dir"
resize2fs /dev/mapper/$cr 262144k
mount /dev/mapper/$cr "$mount_dir"
# this lvresize will not resize the fs (which is already reduced
# to smaller than the requested LV size), but lvresize will use
# the helper to resize the crypt dev before resizing the LV.
# Using --fs resize is required to allow lvresize to look above
# the lv at crypt&fs layers for potential resizing.  Without
# --fs resize, lvresize fails because it sees that crypt resize
# is needed and --fs resize is needed to enable that.
not lvresize -L-100 $vg/$lv
lvresize -L-100M --fs resize $vg/$lv
check lv_field $vg/$lv lv_size "356.00m"
df --output=size "$mount_dir" |tee df2
not diff df1 df2
umount "$mount_dir"
cryptsetup close $cr
lvchange -an $vg/$lv
lvremove $vg/$lv

# test with LUKS2?

vgremove -ff $vg