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

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