Skip to contentSkip to conversation

mapfile: fix relative devname resolution in resolve_md_path

PATCH New Milan P. Gandhi 1 participant 1 message Nov 2 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mapfile: fix relative devname resolution in resolve_md_path

When an array is defined in mdadm.conf using a relative device name (e.g., 'ARRAY customalias UUID=...'), resolve_md_path() fails to resolve it under DEV_MD_DIR during mapfile reconstruction.

The outer condition:

    if (match && match->devname && match->devname[0] == '/')
requires the configured devname to start with '/', rendering the nested
relative path handling unreachable:
    if (path[0] != '/') {
        strcpy(namebuf, DEV_MD_DIR);
        strcat(namebuf, path);
        path = namebuf;
    }

Consequently, commands that rebuild the runtime map (such as 'mdadm --incremental --rebuild-map') bypass the configured relative alias and fall back to the superblock's metadata name, creating an inconsistency with assemble-time symlink creation.

Drop the redundant 'match->devname[0] == '/'' check from the outer conditional so relative device names configured in mdadm.conf reach the nested block, receive the DEV_MD_DIR prefix, and resolve to /dev/md/<name>.

Test reproduction (RAID1 created with metadata name 'origarray', mdadm.conf configured with 'ARRAY customalias UUID=<UUID>'):

    # rm -f /run/mdadm/map /dev/md/customalias

Before patch (unpatched mdadm):
# mdadm --incremental --rebuild-map --config=/tmp/test_mdadm.conf # cat /run/mdadm/map
md99 1.2 fb1db62a:62817869:f8c2ab3f:f422a06d /dev/md/origarray

After patch (patched mdadm):
# ./mdadm --incremental --rebuild-map --config=/tmp/test_mdadm.conf # cat /run/mdadm/map
md99 1.2 55f91d31:c1cc4a13:a18b124d:a8b77987 /dev/md/customalias

Fixes 360b463696e8 ("mapfile - when rebuilding, choose an appropriate name is none is found.")
---
 mapfile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mapfile.c +1 -1
index 2f198a92..f1cdee7a 100644
@@ -381,7 +381,7 @@ static char *resolve_md_path(struct supertype *st, struct mdinfo *info, char *ho
 	struct stat stb;
 	int unum = -1;
 
-	if (match && match->devname && match->devname[0] == '/') {
+	if (match && match->devname) {
 		char *path = match->devname;
 
 		if (path[0] != '/') {
Signature · 1 line
2.56.0