1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

tests: aux for mdadm

Implement aux helper fce for mdadm.
This commit is contained in:
Zdenek Kabelac 2015-04-25 00:37:27 +02:00
parent f50229041b
commit 1e3c135d71

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Copyright (C) 2011-2012 Red Hat, Inc. All rights reserved.
# Copyright (C) 2011-2015 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
@ -256,6 +256,8 @@ kill_listed_processes() {
}
teardown() {
test -f MD_DEV && cleanup_md_dev
echo -n "## teardown..."
if test -f TESTNAME ; then
@ -387,6 +389,69 @@ cleanup_scsi_debug_dev() {
rm -f SCSI_DEBUG_DEV LOOP
}
prepare_md_dev() {
local level=$1
local rchunk=$2
local rdevs=$3
local maj=$(mdadm --version 2>&1) || skip "mdadm tool is missing!"
local mddev
cleanup_md_dev
rm -f debug.log strace.log MD_DEV MD_DEV_PV MD_DEVICES
# Have MD use a non-standard name to avoid colliding with an existing MD device
# - mdadm >= 3.0 requires that non-standard device names be in /dev/md/
# - newer mdadm _completely_ defers to udev to create the associated device node
maj=${maj##*- v}
maj=${maj%%.*}
[ "$maj" -ge 3 ] && \
mddev=/dev/md/md_lvm_test0 || \
mddev=/dev/md_lvm_test0
mdadm --create --metadata=1.0 "$mddev" --auto=md --level $level --chunk $rchunk --raid-devices=$rdevs "${@:4}"
test -b "$mddev" || skip "mdadm has not create device!"
# LVM/DM will see this device
case "$DM_DEV_DIR" in
"/dev") readlink -f "$mddev" ;;
*) cp -LR "$mddev" "$DM_DEV_DIR"
echo "$DM_DEV_DIR/md_lvm_test0" ;;
esac > MD_DEV_PV
echo "$mddev" > MD_DEV
notify_lvmetad $(< MD_DEV_PV)
printf "%s\n" "${@:4}" > MD_DEVICES
for mddev in "${@:4}"; do
notify_lvmetad "$mddev"
done
}
cleanup_md_dev() {
test -f MD_DEV || return 0
local IFS=$IFS_NL
local dev=$(< MD_DEV)
udev_wait
mdadm --stop "$dev" || true
test "$DM_DEV_DIR" != "/dev" && rm -f "$DM_DEV_DIR/$(basename $dev)"
notify_lvmetad $(< MD_DEV_PV)
for dev in $(< MD_DEVICES); do
mdadm --zero-superblock "$dev" || true
notify_lvmetad "$dev"
done
udev_wait
if [ -b "$mddev" ]; then
# mdadm doesn't always cleanup the device node
# sleeps offer hack to defeat: 'md: md127 still in use'
# see: https://bugzilla.redhat.com/show_bug.cgi?id=509908#c25
sleep 2
rm -f "$mddev"
fi
rm -f MD_DEV MD_DEVICES MD_DEV_PV
}
prepare_backing_dev() {
if test -f BACKING_DEV; then
BACKING_DEV=$(< BACKING_DEV)