]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Re-enable mdadm --monitor ... for /dev/mdX
authorDr. Joachim Schneider <jesmx@hal.rhein-neckar.de>
Sat, 6 Sep 2025 18:28:07 +0000 (20:28 +0200)
committerXiaoNi87 <xni@redhat.com>
Wed, 24 Sep 2025 03:13:38 +0000 (11:13 +0800)
This fixes a regression introduced with
commit 84d969be8f6d ("Monitor: use snprintf to fill device name"):

With this fix

  mdadm --monitor --scan -1 -p <pgm>

is possible again for /dev/mdX without symlink in /dev/md/.

The bug can be reproduced by these steps:

(a) Create block devices for testing:

    $ dd if=/dev/zero of=/tmp/d0.bin bs=1M count=16
    $ dd if=/dev/zero of=/tmp/d1.bin bs=1M count=16

    $ losetup -f /tmp/d0.bin
    $ losetup -f /tmp/d1.bin
    $ losetup
    NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE   DIO LOG-SEC
    /dev/loop1         0      0         0  0 /tmp/d1.bin   0     512
    /dev/loop0         0      0         0  0 /tmp/d0.bin   0     512

(b) Create RAID-1 array '/dev/md0':

    $ mdadm --create /dev/md0 --level=1 --raid-devices=2  \
      /dev/loop0 /dev/loop1
    ...
    mdadm: array /dev/md0 started.

(c) Check:

    $ cat /proc/mdstat
    Personalities : [raid1]
    md0 : active raid1 loop1[1] loop0[0]
          15360 blocks super 1.2 [2/2] [UU]

    unused devices: <none>

(d) Create 'mdadm.conf':

    $ mdadm --detail --scan > /tmp/mdadm.conf
    $ cat /tmp/mdadm.conf
    ARRAY /dev/md0 metadata=1.2 UUID=c0280f55:9c32e4ff:34f85ea3:08d1331b

(e) Use this bash script ('/tmp/report') for 'mdadm --monitor':

    [[ $# -lt 2 ]] && exit 0

    problem="$1"
    shift
    array="$1"
    shift
    args="$*"

    echo "MD REPORT: ${problem} with ${array}: ${args}"

(f) Call mdamd in monitor mode:

    $ mdadm --monitor  -c /tmp/mdadm.conf --scan -1 -p /tmp/report

    Without the fix one gets this output:

      mdadm: DeviceDisappeared event detected on md device /dev/md/md0
      MD REPORT: DeviceDisappeared with /dev/md/md0:
      mdadm: NewArray event detected on md device /dev/md0
      MD REPORT: NewArray with /dev/md0:

    Only the output of the 'report'-script:

      $ mdadm  --monitor  -c /tmp/mdadm.conf --scan -1  \
        -p /tmp/report 2>/dev/null
      MD REPORT: DeviceDisappeared with /dev/md/md0:
      MD REPORT: NewArray with /dev/md0:

    With the fix no (warning) output is produced:

      $ /tmp/mdadm-FIXED  --monitor  -c /tmp/mdadm.conf --scan -1 \
        -p /tmp/report

Signed-off-by: Dr. Joachim Schneider <jesmx@hal.rhein-neckar.de>
mdmonitor.c

index 22b0a818f9bd8addfda2f2f3b487dc67e1b1c52e..314dafb4588bdecb63ec9c68ff73cd6758d6e211 100644 (file)
@@ -256,8 +256,8 @@ int Monitor(struct mddev_dev *devlist,
                                continue;
 
                        st = xcalloc(1, sizeof *st);
-                       snprintf(st->devname, MD_NAME_MAX + sizeof(DEV_MD_DIR), DEV_MD_DIR "%s",
-                                basename(mdlist->devname));
+                       snprintf(st->devname, sizeof(st->devname), "%s%s",
+                                '/' == *mdlist->devname ? "" : DEV_MD_DIR, mdlist->devname);
                        if (!is_mddev(st->devname)) {
                                free(st);
                                continue;