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

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