]> sourceware.org Git - lvm2.git/commitdiff
tests: aux for mdadm
authorZdenek Kabelac <zkabelac@redhat.com>
Fri, 24 Apr 2015 22:37:27 +0000 (00:37 +0200)
committerZdenek Kabelac <zkabelac@redhat.com>
Fri, 24 Apr 2015 22:40:02 +0000 (00:40 +0200)
Implement aux helper fce for mdadm.

test/lib/aux.sh

index cc3718cd0f11353cb43b4ae97ceb6da7b8fb9c51..95c2f73716a615b040d890d6fd86c4fb5a091664 100644 (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)
This page took 0.04333 seconds and 5 git commands to generate.