]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm/tests: names_template enhance
authorXiao Ni <xni@redhat.com>
Wed, 22 May 2024 08:50:43 +0000 (16:50 +0800)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Fri, 24 May 2024 08:04:55 +0000 (10:04 +0200)
For super1, if the length of hostname is >= 32, it doesn't add hostname
in metadata name. Fix this problem by checking the length of hostname.
Because other cases may use need to check this, so do the check in
do_setup.

And this patch adds a check if link /dev/md/name exists.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
test
tests/func.sh
tests/templates/names_template

diff --git a/test b/test
index 3da53f8711220ee35ae4237938c6882786d6be8f..814ce1992b0cc29699e2aba10fba7c8bd7cc3314 100755 (executable)
--- a/test
+++ b/test
@@ -11,6 +11,11 @@ system_speed_limit_min=0
 test_speed_limit_min=100
 test_speed_limit_max=500
 devlist=
+# If super1 metadata name doesn't have the same hostname with machine,
+# it's treated as foreign.
+# For example, /dev/md0 is created, stops it, then assemble it, the
+# device node will be /dev/md127 (127 is choosed by mdadm autumatically)
+is_foreign="no"
 
 savelogs=0
 exitonerror=1
index 221cff158f8c2ae0a748a922ff8781475f06f128..cfe83e552a2a0bf55509d31b1c52cd78f825ae45 100644 (file)
@@ -153,6 +153,18 @@ restore_system_speed_limit() {
        echo $system_speed_limit_max > /proc/sys/dev/raid/speed_limit_max
 }
 
+is_raid_foreign() {
+
+       # If the length of hostname is >= 32, super1 doesn't use
+       # hostname in metadata
+       hostname=$(hostname)
+       if [ `expr length $(hostname)` -lt 32 ]; then
+               is_foreign="no"
+       else
+               is_foreign="yes"
+       fi
+}
+
 do_setup() {
        trap cleanup 0 1 3 15
        trap ctrl_c 2
@@ -232,6 +244,7 @@ do_setup() {
        [ -f /proc/mdstat ] || modprobe md_mod
        echo 0 > /sys/module/md_mod/parameters/start_ro
        record_system_speed_limit
+       is_raid_foreign
 }
 
 # check various things
index 1b6cd14bf51d7d9e42f19b3732100af0f646383b..88ad5b8c6b384146ed3abe0503fac2d2713855da 100644 (file)
@@ -30,6 +30,7 @@ function names_verify() {
        local DEVNODE_NAME="$1"
        local WANTED_LINK="$2"
        local WANTED_NAME="$3"
+       local EXPECTED=""
 
        local RES="$(mdadm -D --export $DEVNODE_NAME | grep MD_DEVNAME)"
        if [[ "$?" != "0" ]]; then
@@ -38,7 +39,12 @@ function names_verify() {
        fi
 
        if [[ "$WANTED_LINK" != "empty" ]]; then
-               local EXPECTED="MD_DEVNAME=$WANTED_LINK"
+               EXPECTED="MD_DEVNAME=$WANTED_LINK"
+
+               if [ ! -b /dev/md/$WANTED_LINK ]; then
+                       echo "/dev/md/$WANTED_LINK doesn't exit"
+                       exit 1
+               fi
        fi
 
        if [[ "$RES" != "$EXPECTED" ]]; then
@@ -52,7 +58,11 @@ function names_verify() {
                exit 1
        fi
 
-       local EXPECTED="MD_NAME=$(hostname):$WANTED_NAME"
+       if [ $is_foreign == "no" ]; then
+               EXPECTED="MD_NAME=$(hostname):$WANTED_NAME"
+       else
+               EXPECTED="MD_NAME=$WANTED_NAME"
+       fi
        if [[ "$RES" != "$EXPECTED" ]]; then
                echo "$RES doesn't match $EXPECTED."
                exit 1