mapfile: fix relative devname resolution in resolve_md_path
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
--- mapfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mapfile.c +1 -1
@@ -381,7 +381,7 @@ static char *resolve_md_path(struct supertype *st, struct mdinfo *info, char *hostruct 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