summaryrefslogtreecommitdiff
path: root/test/shell/cache-single-repair.sh
blob: f465e366a79e749650c28c4321b86a5956cf7b04 (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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/env bash

# Copyright (C) 2018 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

# Test single lv cache options

SKIP_WITH_LVMPOLLD=1

. lib/inittest

mkfs_mount_umount()
{
        lvt=$1

        lvchange -ay $vg/$lvt

        mkfs.xfs -f -s size=4096 "$DM_DEV_DIR/$vg/$lvt"
        mount "$DM_DEV_DIR/$vg/$lvt" "$mount_dir"
        cp pattern1 "$mount_dir/pattern1"
        dd if=/dev/zero of="$mount_dir/zeros2M" bs=1M count=32 conv=fdatasync
        umount "$mount_dir"

        lvchange -an $vg/$lvt
}

mount_umount()
{
        lvt=$1

        lvchange -ay $vg/$lvt

        mount "$DM_DEV_DIR/$vg/$lvt" "$mount_dir"
        diff pattern1 "$mount_dir/pattern1"
        dd if="$mount_dir/zeros2M" of=/dev/null bs=1M count=32
        umount "$mount_dir"

        lvchange -an $vg/$lvt
}

aux have_cache 1 10 0 || skip
which mkfs.xfs || skip

mount_dir="mnt"
mkdir -p "$mount_dir"

# generate random data
dd if=/dev/urandom of=pattern1 bs=512K count=1

aux prepare_devs 6

vgcreate $SHARED $vg "$dev1" "$dev2" "$dev3" "$dev4" "$dev5" "$dev6"

#
# writethrough
# no corruption of cachevol
#

lvcreate -n $lv1 -l 16 -an $vg "$dev1" "$dev2"
lvcreate -n $lv2 -l 4 -an $vg "$dev3"
lvcreate -n $lv3 -l 4 -an $vg "$dev4"

lvconvert -y --type cache --cachevol $lv2 --cachemode writethrough $vg/$lv1

mkfs_mount_umount $lv1

lvconvert -y --repaircachevol $lv2 $vg/$lv3

# new cache is valid since it was just copied from existing
lvchange -ay $vg/$lv3
cache_check "$DM_DEV_DIR/$vg/$lv3"
lvchange -an $vg/$lv3

# use new cache for main lv
lvconvert -y --replacecachevol $lv2 $vg/$lv3

# old cache is valid since it was never damaged
lvchange -ay $vg/$lv2
cache_check "$DM_DEV_DIR/$vg/$lv2"
lvchange -an $vg/$lv2

mount_umount $lv1

lvremove $vg/$lv1
lvremove $vg/$lv2

#
# writeback
# no corruption of cachevol
#

lvcreate -n $lv1 -l 16 -an $vg "$dev1" "$dev2"
lvcreate -n $lv2 -l 4 -an $vg "$dev3"
lvcreate -n $lv3 -l 4 -an $vg "$dev4"

lvconvert -y --type cache --cachevol $lv2 --cachemode writeback $vg/$lv1

mkfs_mount_umount $lv1

lvconvert -y --repaircachevol $lv2 $vg/$lv3

# new cache is valid since it was just copied from existing
lvchange -ay $vg/$lv3
cache_check "$DM_DEV_DIR/$vg/$lv3"
lvchange -an $vg/$lv3

# use new cache for main lv
lvconvert -y --replacecachevol $lv2 $vg/$lv3

# old cache is valid since it was never damaged
lvchange -ay $vg/$lv2
cache_check "$DM_DEV_DIR/$vg/$lv2"
lvchange -an $vg/$lv2

mount_umount $lv1

lvremove $vg/$lv1
lvremove $vg/$lv2

#
# writethrough, unrepairable cachevol damage
#

lvcreate -n $lv1 -l 16 -an $vg "$dev1" "$dev2"
lvcreate -n $lv2 -l 4 -an $vg "$dev3"
lvcreate -n $lv3 -l 4 -an $vg "$dev4"

lvconvert -y --type cache --cachevol $lv2 --cachemode writethrough $vg/$lv1

mkfs_mount_umount $lv1

# damage the current cache so it's not repairable
# lvchange -y -ay $vg/$lv2
# dd if=/dev/zero of="$DM_DEV_DIR/mapper/$vg-$lv2" bs=1M count=1 oflag=direct
dd if=/dev/zero of="$dev3" bs=1M count=1 seek=1 oflag=direct
# verify it's not repairable
lvs -a $vg
lvchange -y -ay $vg/$lv2
lvs -a $vg
ls "$DM_DEV_DIR/mapper/$vg-$lv2"
not cache_check "$DM_DEV_DIR/mapper/$vg-$lv2"
lvchange -an $vg/$lv2

# cache_repair fails
not lvconvert -y --repaircachevol $lv2 $vg/$lv3

# drop the cache
lvconvert --splitcache $vg/$lv1

lvremove $vg/$lv1
lvremove $vg/$lv2
lvremove $vg/$lv3


#
# writeback, unrepairable cachevol damage
#

lvcreate -n $lv1 -l 16 -an $vg "$dev1" "$dev2"
lvcreate -n $lv2 -l 4 -an $vg "$dev3"
lvcreate -n $lv3 -l 4 -an $vg "$dev4"

lvconvert -y --type cache --cachevol $lv2 --cachemode writeback $vg/$lv1

mkfs_mount_umount $lv1

# damage the current cache so it's not repairable
# lvchange -y -ay $vg/$lv2
# dd if=/dev/zero of="$DM_DEV_DIR/mapper/$vg-$lv2" bs=1M count=16 oflag=direct
dd if=/dev/zero of="$dev3" bs=1M count=1 seek=1 oflag=direct
# verify it's not repairable
lvs -a $vg
lvchange -y -ay $vg/$lv2
lvs -a $vg
ls "$DM_DEV_DIR/mapper/$vg-$lv2"
not cache_check "$DM_DEV_DIR/mapper/$vg-$lv2"
lvchange -an $vg/$lv2

# cache_repair fails
not lvconvert -y --repaircachevol $lv2 $vg/$lv3

# drop the cache
# N.B. this split doesn't seem to sync anything, and doesn't
# seem to see/report any problems.
lvconvert --splitcache $vg/$lv1

lvremove $vg/$lv1
lvremove $vg/$lv2
lvremove $vg/$lv3


#
# TODO: inflict some plausible cachevol damage that can be repaired
# by cache_repair.
#