Blame SOURCES/0032-mdadm-add-no-devices-to-avoid-component-devices-deta.patch

2910d5
From d11abe4bd5cad39803726ddff1888674e417bda5 Mon Sep 17 00:00:00 2001
2910d5
From: Coly Li <colyli@suse.de>
2910d5
Date: Wed, 31 Jul 2019 13:29:29 +0800
2910d5
Subject: [RHEL7.8 PATCH V2 32/47] mdadm: add --no-devices to avoid component
2910d5
 devices detail information
2910d5
2910d5
When people assemble a md raid device with a large number of
2910d5
component deivces (e.g. 1500 DASD disks), the raid device detail
2910d5
information generated by 'mdadm --detail --export $devnode' is very
2910d5
large. It is because the detail information contains information of
2910d5
all the component disks (even the missing/failed ones).
2910d5
2910d5
In such condition, when udev-md-raid-arrays.rules is triggered and
2910d5
internally calls "mdadm --detail --no-devices --export $devnode",
2910d5
user may observe systemd error message ""invalid message length". It
2910d5
is because the following on-stack raw message buffer in systemd code
2910d5
is not big enough,
2910d5
        systemd/src/libudev/libudev-monitor.c
2910d5
        _public_ struct udev_device *udev_monito ...
2910d5
                struct ucred *cred;
2910d5
                union {
2910d5
                        struct udev_monitor_netlink_header nlh;
2910d5
                        char raw[8192];
2910d5
                } buf;
2910d5
Even change size of raw[] from 8KB to larger size, it may still be not
2910d5
enough for detail message of a md raid device with much larger number of
2910d5
component devices.
2910d5
2910d5
To fix this problem, an extra option '--no-devices' is added (the
2910d5
original idea is proposed by Neil Brown). When printing detailed
2910d5
information of a md raid device, if '--no-devices' is specified, then
2910d5
all component devices information will not be printed, then the output
2910d5
message size can be restricted to a small number, even with the systemd
2910d5
only has 8KB on-disk raw buffer, the md raid array udev rules can work
2910d5
correctly without failure message.
2910d5
2910d5
Signed-off-by: Coly Li <colyli@suse.de>
2910d5
Reviewed-by: NeilBrown <neilb@suse.com>
2910d5
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2910d5
---
2910d5
 Detail.c | 24 ++++++++++++++++--------
2910d5
 ReadMe.c |  1 +
2910d5
 mdadm.c  |  4 ++++
2910d5
 mdadm.h  |  2 ++
2910d5
 4 files changed, 23 insertions(+), 8 deletions(-)
2910d5
2910d5
diff --git a/Detail.c b/Detail.c
2910d5
index 20ea03a..ad60434 100644
2910d5
--- a/Detail.c
2910d5
+++ b/Detail.c
2910d5
@@ -56,7 +56,7 @@ int Detail(char *dev, struct context *c)
2910d5
 	 */
2910d5
 	int fd = open(dev, O_RDONLY);
2910d5
 	mdu_array_info_t array;
2910d5
-	mdu_disk_info_t *disks;
2910d5
+	mdu_disk_info_t *disks = NULL;
2910d5
 	int next;
2910d5
 	int d;
2910d5
 	time_t atime;
2910d5
@@ -280,7 +280,7 @@ int Detail(char *dev, struct context *c)
2910d5
 			}
2910d5
 			map_free(map);
2910d5
 		}
2910d5
-		if (sra) {
2910d5
+		if (!c->no_devices && sra) {
2910d5
 			struct mdinfo *mdi;
2910d5
 			for (mdi  = sra->devs; mdi; mdi = mdi->next) {
2910d5
 				char *path;
2910d5
@@ -655,12 +655,17 @@ This is pretty boring
2910d5
 			printf("\n\n");
2910d5
 		}
2910d5
 
2910d5
-		if (array.raid_disks)
2910d5
-			printf("    Number   Major   Minor   RaidDevice State\n");
2910d5
-		else
2910d5
-			printf("    Number   Major   Minor   RaidDevice\n");
2910d5
+		if (!c->no_devices) {
2910d5
+			if (array.raid_disks)
2910d5
+				printf("    Number   Major   Minor   RaidDevice State\n");
2910d5
+			else
2910d5
+				printf("    Number   Major   Minor   RaidDevice\n");
2910d5
+		}
2910d5
 	}
2910d5
-	free(info);
2910d5
+
2910d5
+	/* if --no_devices specified, not print component devices info */
2910d5
+	if (c->no_devices)
2910d5
+		goto skip_devices_state;
2910d5
 
2910d5
 	for (d = 0; d < max_disks * 2; d++) {
2910d5
 		char *dv;
2910d5
@@ -747,6 +752,8 @@ This is pretty boring
2910d5
 		if (!c->brief)
2910d5
 			printf("\n");
2910d5
 	}
2910d5
+
2910d5
+skip_devices_state:
2910d5
 	if (spares && c->brief && array.raid_disks)
2910d5
 		printf(" spares=%d", spares);
2910d5
 	if (c->brief && st && st->sb)
2910d5
@@ -766,8 +773,9 @@ This is pretty boring
2910d5
 	    !enough(array.level, array.raid_disks, array.layout, 1, avail))
2910d5
 		rv = 2;
2910d5
 
2910d5
-	free(disks);
2910d5
 out:
2910d5
+	free(info);
2910d5
+	free(disks);
2910d5
 	close(fd);
2910d5
 	free(subarray);
2910d5
 	free(avail);
2910d5
diff --git a/ReadMe.c b/ReadMe.c
2910d5
index 12ccf83..eaf1042 100644
2910d5
--- a/ReadMe.c
2910d5
+++ b/ReadMe.c
2910d5
@@ -181,6 +181,7 @@ struct option long_options[] = {
2910d5
 
2910d5
     /* For Detail/Examine */
2910d5
     {"brief",	  0, 0, Brief},
2910d5
+    {"no-devices",0, 0, NoDevices},
2910d5
     {"export",	  0, 0, 'Y'},
2910d5
     {"sparc2.2",  0, 0, Sparc22},
2910d5
     {"test",      0, 0, 't'},
2910d5
diff --git a/mdadm.c b/mdadm.c
2910d5
index 25a1abd..1fb8086 100644
2910d5
--- a/mdadm.c
2910d5
+++ b/mdadm.c
2910d5
@@ -159,6 +159,10 @@ int main(int argc, char *argv[])
2910d5
 			c.brief = 1;
2910d5
 			continue;
2910d5
 
2910d5
+		case NoDevices:
2910d5
+			c.no_devices = 1;
2910d5
+			continue;
2910d5
+
2910d5
 		case 'Y': c.export++;
2910d5
 			continue;
2910d5
 
2910d5
diff --git a/mdadm.h b/mdadm.h
2910d5
index d61a9ca..43b07d5 100644
2910d5
--- a/mdadm.h
2910d5
+++ b/mdadm.h
2910d5
@@ -440,6 +440,7 @@ enum special_options {
2910d5
 	NoSharing,
2910d5
 	HelpOptions,
2910d5
 	Brief,
2910d5
+	NoDevices,
2910d5
 	ManageOpt,
2910d5
 	Add,
2910d5
 	AddSpare,
2910d5
@@ -550,6 +551,7 @@ struct context {
2910d5
 	int	runstop;
2910d5
 	int	verbose;
2910d5
 	int	brief;
2910d5
+	int	no_devices;
2910d5
 	int	force;
2910d5
 	char	*homehost;
2910d5
 	int	require_homehost;
2910d5
-- 
2910d5
2.7.5
2910d5