dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

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

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