]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shutdown: get only active md arrays.
authorMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Tue, 29 Mar 2022 10:49:54 +0000 (12:49 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 6 Apr 2022 20:56:40 +0000 (21:56 +0100)
Current md_list_get() implementation filters all block devices, started from
"md*". This is ambiguous because list could contain:
- partitions created upon md device (mdXpY)
- external metadata container- specific type of md array.

For partitions there is no issue, because they aren't handle STOP_ARRAY
ioctl sent later. It generates misleading errors only.

Second case is more problematic because containers are not locked in kernel.
They are stopped even if container member array is active. For that reason
reboot or shutdown flow could be blocked because metadata manager cannot be
restarted after switch root on shutdown.

Add filters to remove partitions and containers from md_list. Partitions
can be excluded by DEVTYPE. Containers are determined by MD_LEVEL
property, we are excluding all with "container" value.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
src/shutdown/umount.c

index 3e9e241499a5f0a552b3321e31e5d92198653f28..820aa8e286858988b2c9c2d3a1363a54324fd397 100644 (file)
@@ -352,9 +352,14 @@ static int md_list_get(MountPoint **head) {
         if (r < 0)
                 return r;
 
+        /* Filter out partitions. */
+        r = sd_device_enumerator_add_match_property(e, "DEVTYPE", "disk");
+        if (r < 0)
+                return r;
+
         FOREACH_DEVICE(e, d) {
                 _cleanup_free_ char *p = NULL;
-                const char *dn;
+                const char *dn, *md_level;
                 MountPoint *m;
                 dev_t devnum;
 
@@ -362,6 +367,17 @@ static int md_list_get(MountPoint **head) {
                     sd_device_get_devname(d, &dn) < 0)
                         continue;
 
+                r = sd_device_get_property_value(d, "MD_LEVEL", &md_level);
+                if (r < 0) {
+                        log_warning_errno(r, "Failed to get MD_LEVEL property for %s, ignoring: %m", dn);
+                        continue;
+                }
+
+                /* MD "containers" are a special type of MD devices, used for external metadata.
+                 * Since it doesn't provide RAID functionality in itself we don't need to stop it. */
+                if (streq(md_level, "container"))
+                        continue;
+
                 p = strdup(dn);
                 if (!p)
                         return -ENOMEM;