mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-31 21:18:26 +03:00
d9e8895a96
dm-integrity stores checksums of the data written to an LV, and returns an error if data read from the LV does not match the previously saved checksum. When used on raid images, dm-raid will correct the error by reading the block from another image, and the device user sees no error. The integrity metadata (checksums) are stored on an internal LV allocated by lvm for each linear image. The internal LV is allocated on the same PV as the image. Create a raid LV with an integrity layer over each raid image (for raid levels 1,4,5,6,10): lvcreate --type raidN --raidintegrity y [options] Add an integrity layer to images of an existing raid LV: lvconvert --raidintegrity y LV Remove the integrity layer from images of a raid LV: lvconvert --raidintegrity n LV Settings Use --raidintegritymode journal|bitmap (journal is default) to configure the method used by dm-integrity to ensure crash consistency. Initialization When integrity is added to an LV, the kernel needs to initialize the integrity metadata/checksums for all blocks in the LV. The data corruption checking performed by dm-integrity will only operate on areas of the LV that are already initialized. The progress of integrity initialization is reported by the "syncpercent" LV reporting field (and under the Cpy%Sync lvs column.) Example: create a raid1 LV with integrity: $ lvcreate --type raid1 -m1 --raidintegrity y -n rr -L1G foo Creating integrity metadata LV rr_rimage_0_imeta with size 12.00 MiB. Logical volume "rr_rimage_0_imeta" created. Creating integrity metadata LV rr_rimage_1_imeta with size 12.00 MiB. Logical volume "rr_rimage_1_imeta" created. Logical volume "rr" created. $ lvs -a foo LV VG Attr LSize Origin Cpy%Sync rr foo rwi-a-r--- 1.00g 4.93 [rr_rimage_0] foo gwi-aor--- 1.00g [rr_rimage_0_iorig] 41.02 [rr_rimage_0_imeta] foo ewi-ao---- 12.00m [rr_rimage_0_iorig] foo -wi-ao---- 1.00g [rr_rimage_1] foo gwi-aor--- 1.00g [rr_rimage_1_iorig] 39.45 [rr_rimage_1_imeta] foo ewi-ao---- 12.00m [rr_rimage_1_iorig] foo -wi-ao---- 1.00g [rr_rmeta_0] foo ewi-aor--- 4.00m [rr_rmeta_1] foo ewi-aor--- 4.00m
229 lines
5.4 KiB
Bash
229 lines
5.4 KiB
Bash
#!/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
|
|
|
|
SKIP_WITH_LVMPOLLD=1
|
|
|
|
. lib/inittest
|
|
|
|
aux have_integrity 1 5 0 || skip
|
|
which mkfs.xfs || skip
|
|
|
|
mnt="mnt"
|
|
mkdir -p $mnt
|
|
|
|
aux prepare_devs 5 64
|
|
|
|
for i in `seq 1 16384`; do echo -n "A" >> fileA; done
|
|
for i in `seq 1 16384`; do echo -n "B" >> fileB; done
|
|
for i in `seq 1 16384`; do echo -n "C" >> fileC; done
|
|
|
|
# generate random data
|
|
dd if=/dev/urandom of=randA bs=512K count=2
|
|
dd if=/dev/urandom of=randB bs=512K count=3
|
|
dd if=/dev/urandom of=randC bs=512K count=4
|
|
|
|
_prepare_vg() {
|
|
vgcreate $SHARED $vg "$dev1" "$dev2" "$dev3" "$dev4" "$dev5"
|
|
pvs
|
|
}
|
|
|
|
_add_new_data_to_mnt() {
|
|
mkfs.xfs -f "$DM_DEV_DIR/$vg/$lv1"
|
|
|
|
mount "$DM_DEV_DIR/$vg/$lv1" $mnt
|
|
|
|
# add original data
|
|
cp randA $mnt
|
|
cp randB $mnt
|
|
cp randC $mnt
|
|
mkdir $mnt/1
|
|
cp fileA $mnt/1
|
|
cp fileB $mnt/1
|
|
cp fileC $mnt/1
|
|
mkdir $mnt/2
|
|
cp fileA $mnt/2
|
|
cp fileB $mnt/2
|
|
cp fileC $mnt/2
|
|
}
|
|
|
|
_add_more_data_to_mnt() {
|
|
mkdir $mnt/more
|
|
cp fileA $mnt/more
|
|
cp fileB $mnt/more
|
|
cp fileC $mnt/more
|
|
cp randA $mnt/more
|
|
cp randB $mnt/more
|
|
cp randC $mnt/more
|
|
}
|
|
|
|
_verify_data_on_mnt() {
|
|
diff randA $mnt/randA
|
|
diff randB $mnt/randB
|
|
diff randC $mnt/randC
|
|
diff fileA $mnt/1/fileA
|
|
diff fileB $mnt/1/fileB
|
|
diff fileC $mnt/1/fileC
|
|
diff fileA $mnt/2/fileA
|
|
diff fileB $mnt/2/fileB
|
|
diff fileC $mnt/2/fileC
|
|
}
|
|
|
|
_verify_data_on_lv() {
|
|
lvchange -ay $vg/$lv1
|
|
mount "$DM_DEV_DIR/$vg/$lv1" $mnt
|
|
_verify_data_on_mnt
|
|
rm $mnt/randA
|
|
rm $mnt/randB
|
|
rm $mnt/randC
|
|
rm -rf $mnt/1
|
|
rm -rf $mnt/2
|
|
umount $mnt
|
|
lvchange -an $vg/$lv1
|
|
}
|
|
|
|
_sync_percent() {
|
|
local checklv=$1
|
|
get lv_field "$checklv" sync_percent | cut -d. -f1
|
|
}
|
|
|
|
_wait_recalc() {
|
|
local checklv=$1
|
|
|
|
for i in $(seq 1 10) ; do
|
|
sync=$(_sync_percent "$checklv")
|
|
echo "sync_percent is $sync"
|
|
|
|
if test "$sync" = "100"; then
|
|
return
|
|
fi
|
|
|
|
sleep 1
|
|
done
|
|
|
|
echo "timeout waiting for recalc"
|
|
return 1
|
|
}
|
|
|
|
# lvrename
|
|
_prepare_vg
|
|
lvcreate --type raid1 -m1 --raidintegrity y -n $lv1 -l 8 $vg
|
|
_wait_recalc $vg/${lv1}_rimage_0
|
|
_wait_recalc $vg/${lv1}_rimage_1
|
|
_add_new_data_to_mnt
|
|
umount $mnt
|
|
lvrename $vg/$lv1 $vg/$lv2
|
|
mount "$DM_DEV_DIR/$vg/$lv2" $mnt
|
|
_verify_data_on_mnt
|
|
umount $mnt
|
|
lvchange -an $vg/$lv2
|
|
lvremove $vg/$lv2
|
|
vgremove -ff $vg
|
|
|
|
# lvconvert --replace
|
|
# an existing dev is replaced with another dev
|
|
# lv must be active
|
|
_prepare_vg
|
|
lvcreate --type raid1 -m1 --raidintegrity y -n $lv1 -l 8 $vg "$dev1" "$dev2"
|
|
_wait_recalc $vg/${lv1}_rimage_0
|
|
_wait_recalc $vg/${lv1}_rimage_1
|
|
_add_new_data_to_mnt
|
|
lvconvert --replace "$dev1" $vg/$lv1 "$dev3"
|
|
lvs -a -o+devices $vg > out
|
|
cat out
|
|
grep "$dev2" out
|
|
grep "$dev3" out
|
|
not grep "$dev1" out
|
|
_add_more_data_to_mnt
|
|
_verify_data_on_mnt
|
|
umount $mnt
|
|
lvchange -an $vg/$lv1
|
|
_verify_data_on_lv
|
|
lvremove $vg/$lv1
|
|
vgremove -ff $vg
|
|
|
|
# lvconvert --replace
|
|
# same as prev but with bitmap mode
|
|
_prepare_vg
|
|
lvcreate --type raid1 -m1 --raidintegrity y --raidintegritymode bitmap -n $lv1 -l 8 $vg "$dev1" "$dev2"
|
|
_wait_recalc $vg/${lv1}_rimage_0
|
|
_wait_recalc $vg/${lv1}_rimage_1
|
|
_add_new_data_to_mnt
|
|
lvconvert --replace "$dev1" $vg/$lv1 "$dev3"
|
|
lvs -a -o+devices $vg > out
|
|
cat out
|
|
grep "$dev2" out
|
|
grep "$dev3" out
|
|
not grep "$dev1" out
|
|
_add_more_data_to_mnt
|
|
_verify_data_on_mnt
|
|
umount $mnt
|
|
lvchange -an $vg/$lv1
|
|
_verify_data_on_lv
|
|
lvremove $vg/$lv1
|
|
vgremove -ff $vg
|
|
|
|
# lvconvert --repair
|
|
# while lv is active a device goes missing (with rimage,rmeta,imeta,orig).
|
|
# lvconvert --repair should replace the missing dev with another,
|
|
# (like lvconvert --replace does for a dev that's not missing).
|
|
_prepare_vg
|
|
lvcreate --type raid1 -m1 --raidintegrity y -n $lv1 -l 8 $vg "$dev1" "$dev2"
|
|
_wait_recalc $vg/${lv1}_rimage_0
|
|
_wait_recalc $vg/${lv1}_rimage_1
|
|
_add_new_data_to_mnt
|
|
aux disable_dev "$dev2"
|
|
lvs -a -o+devices $vg > out
|
|
cat out
|
|
grep unknown out
|
|
lvconvert -vvvv -y --repair $vg/$lv1
|
|
lvs -a -o+devices $vg > out
|
|
cat out
|
|
not grep "$dev2" out
|
|
not grep unknown out
|
|
_add_more_data_to_mnt
|
|
_verify_data_on_mnt
|
|
umount $mnt
|
|
lvchange -an $vg/$lv1
|
|
lvremove $vg/$lv1
|
|
aux enable_dev "$dev2"
|
|
vgremove -ff $vg
|
|
|
|
# lvchange activationmode
|
|
# a device is missing (with rimage,rmeta,imeta,iorig), the lv
|
|
# is already inactive, and it cannot be activated, with
|
|
# activationmode degraded or partial, or in any way,
|
|
# until integrity is removed.
|
|
|
|
_prepare_vg
|
|
lvcreate --type raid1 -m1 --raidintegrity y -n $lv1 -l 8 $vg "$dev1" "$dev2"
|
|
_wait_recalc $vg/${lv1}_rimage_0
|
|
_wait_recalc $vg/${lv1}_rimage_1
|
|
_add_new_data_to_mnt
|
|
umount $mnt
|
|
lvchange -an $vg/$lv1
|
|
aux disable_dev "$dev2"
|
|
lvs -a -o+devices $vg
|
|
not lvchange -ay $vg/$lv1
|
|
not lvchange -ay --activationmode degraded $vg/$lv1
|
|
not lvchange -ay --activationmode partial $vg/$lv1
|
|
lvconvert --raidintegrity n $vg/$lv1
|
|
lvchange -ay --activationmode degraded $vg/$lv1
|
|
mount "$DM_DEV_DIR/$vg/$lv1" $mnt
|
|
_add_more_data_to_mnt
|
|
_verify_data_on_mnt
|
|
umount $mnt
|
|
lvchange -an $vg/$lv1
|
|
lvremove $vg/$lv1
|
|
aux enable_dev "$dev2"
|
|
vgremove -ff $vg
|
|
|