Now 00createnames doesn't check Create names=yes config. Without this config, mdadm creates /dev/md127 device node when mdadm --create /dev/md/test. With this config, it creates /dev/md_test. This patch only adds the check. If it has this config, it returns directly without error. And this case has an error. 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. And this patch adds a check if device node exists. Signed-off-by: Xiao Ni <xni@xxxxxxxxxx> --- tests/00createnames | 9 +++++++++ tests/templates/names_template | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/00createnames b/tests/00createnames index a95e7d2bb085..2eb3d9331dda 100644 --- a/tests/00createnames +++ b/tests/00createnames @@ -3,6 +3,15 @@ set -x -e # Test how <devname> and --name= are handled for create mode. +create_with_name=`cat /etc/mdadm.conf | grep "^Create*.names=yes"` + +if [ -n "$create_with_name" ]; then + exit 0 +fi + +#The following cases don't consider the names=yes setting in mdadm.conf +#It needs to add the respecting cases which consider names=yes config + # The most trivial case. names_create "/dev/md/name" names_verify "/dev/md127" "name" "name" diff --git a/tests/templates/names_template b/tests/templates/names_template index 1b6cd14bf51d..4c7ff8c27f73 100644 --- a/tests/templates/names_template +++ b/tests/templates/names_template @@ -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 @@ -46,13 +47,25 @@ function names_verify() { exit 1 fi + if [ -b /dev/md/$WANTED_LINK ]; then + echo "/dev/md/$WANTED_LINK doesn't exit" + fi + local RES="$(mdadm -D --export $DEVNODE_NAME | grep MD_NAME)" if [[ "$?" != "0" ]]; then echo "Cannot get metadata from $dev0." exit 1 fi - local EXPECTED="MD_NAME=$(hostname):$WANTED_NAME" + #If the lenght of hostname is >= 32, super1 doesn't use hostname + #in metadata + local is_super1="$(mdadm -D --export $DEVNODE_NAME | grep MD_METADATA=1.2)" + hostname=$(hostname) + if [ -n "$is_super1" -a `expr length $(hostname)` -lt 32 ]; 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 -- 2.32.0 (Apple Git-132)