Blame SOURCES/mdadm-3.4-Use-dev_t-for-devnm2devid-and-devid2devnm.patch

7bdf8f
From 13db17bd1fcd68b5e5618fcd051ff4137f1ea413 Mon Sep 17 00:00:00 2001
7bdf8f
From: Mike Lovell <mlovell@bluehost.com>
7bdf8f
Date: Wed, 18 May 2016 12:23:13 -0600
7bdf8f
Subject: [PATCH 1/2] Use dev_t for devnm2devid and devid2devnm
7bdf8f
7bdf8f
Commit 4dd2df0966ec added a trip through makedev(), major(), and minor() for
7bdf8f
device major and minor numbers. This would cause mdadm to fail in operating
7bdf8f
on a device with a minor number bigger than (2^19)-1 due to it changing
7bdf8f
from dev_t to a signed int and back.
7bdf8f
7bdf8f
Where this was found as a problem was when a array was created with a device
7bdf8f
specified as a name like /dev/md/raidname and there were already 128 arrays
7bdf8f
on the system. In this case, mdadm would chose 1048575 ((2^20)-1) for the
7bdf8f
array and minor number. This would cause the major and minor number to become
7bdf8f
negative when generated from devnm2devid() and passed to major() and minor()
7bdf8f
in open_dev_excl(). open_dev_excl() would then call dev_open() which would
7bdf8f
detect the negative minor number and call open() on the *char containing the
7bdf8f
major:minor pair which isn't a valid file.
7bdf8f
7bdf8f
Signed-off-by: Mike Lovell <mlovell@bluehost.com>
7bdf8f
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
7bdf8f
---
7bdf8f
 Detail.c  | 4 ++--
7bdf8f
 Grow.c    | 2 +-
7bdf8f
 lib.c     | 2 +-
7bdf8f
 mapfile.c | 2 +-
7bdf8f
 mdadm.h   | 4 ++--
7bdf8f
 mdopen.c  | 4 ++--
7bdf8f
 util.c    | 6 +++---
7bdf8f
 7 files changed, 12 insertions(+), 12 deletions(-)
7bdf8f
7bdf8f
diff --git a/Detail.c b/Detail.c
7bdf8f
index 20c4553..7a984c8 100644
7bdf8f
--- a/Detail.c
7bdf8f
+++ b/Detail.c
7bdf8f
@@ -130,7 +130,7 @@ int Detail(char *dev, struct context *c)
7bdf8f
 		/* This is a subarray of some container.
7bdf8f
 		 * We want the name of the container, and the member
7bdf8f
 		 */
7bdf8f
-		int devid = devnm2devid(st->container_devnm);
7bdf8f
+		dev_t devid = devnm2devid(st->container_devnm);
7bdf8f
 		int cfd, err;
7bdf8f
 
7bdf8f
 		member = subarray;
7bdf8f
@@ -577,7 +577,7 @@ This is pretty boring
7bdf8f
 				char path[200];
7bdf8f
 				char vbuf[1024];
7bdf8f
 				int nlen = strlen(sra->sys_name);
7bdf8f
-				int devid;
7bdf8f
+				dev_t devid;
7bdf8f
 				if (de->d_name[0] == '.')
7bdf8f
 					continue;
7bdf8f
 				sprintf(path, "/sys/block/%s/md/metadata_version",
7bdf8f
diff --git a/Grow.c b/Grow.c
7bdf8f
index 98b0fab..f184d9c 100755
7bdf8f
--- a/Grow.c
7bdf8f
+++ b/Grow.c
7bdf8f
@@ -3533,7 +3533,7 @@ int reshape_container(char *container, char *devname,
7bdf8f
 		int fd;
7bdf8f
 		struct mdstat_ent *mdstat;
7bdf8f
 		char *adev;
7bdf8f
-		int devid;
7bdf8f
+		dev_t devid;
7bdf8f
 
7bdf8f
 		sysfs_free(cc);
7bdf8f
 
7bdf8f
diff --git a/lib.c b/lib.c
7bdf8f
index 621edf3..3ee7659 100644
7bdf8f
--- a/lib.c
7bdf8f
+++ b/lib.c
7bdf8f
@@ -99,7 +99,7 @@ char *fd2kname(int fd)
7bdf8f
 	return NULL;
7bdf8f
 }
7bdf8f
 
7bdf8f
-char *devid2devnm(int devid)
7bdf8f
+char *devid2devnm(dev_t devid)
7bdf8f
 {
7bdf8f
 	char path[30];
7bdf8f
 	char link[200];
7bdf8f
diff --git a/mapfile.c b/mapfile.c
7bdf8f
index 243ded1..c89d403 100644
7bdf8f
--- a/mapfile.c
7bdf8f
+++ b/mapfile.c
7bdf8f
@@ -374,7 +374,7 @@ void RebuildMap(void)
7bdf8f
 			char dn[30];
7bdf8f
 			int dfd;
7bdf8f
 			int ok;
7bdf8f
-			int devid;
7bdf8f
+			dev_t devid;
7bdf8f
 			struct supertype *st;
7bdf8f
 			char *subarray = NULL;
7bdf8f
 			char *path;
7bdf8f
diff --git a/mdadm.h b/mdadm.h
7bdf8f
index b870585..3d6c638 100755
7bdf8f
--- a/mdadm.h
7bdf8f
+++ b/mdadm.h
7bdf8f
@@ -1440,8 +1440,8 @@ extern char *find_free_devnm(int use_partitions);
7bdf8f
 
7bdf8f
 extern void put_md_name(char *name);
7bdf8f
 extern char *devid2kname(int devid);
7bdf8f
-extern char *devid2devnm(int devid);
7bdf8f
-extern int devnm2devid(char *devnm);
7bdf8f
+extern char *devid2devnm(dev_t devid);
7bdf8f
+extern dev_t devnm2devid(char *devnm);
7bdf8f
 extern char *get_md_name(char *devnm);
7bdf8f
 
7bdf8f
 extern char DefaultConfFile[];
7bdf8f
diff --git a/mdopen.c b/mdopen.c
7bdf8f
index 28410f4..e71d758 100644
7bdf8f
--- a/mdopen.c
7bdf8f
+++ b/mdopen.c
7bdf8f
@@ -348,7 +348,7 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy,
7bdf8f
 		if (lstat(devname, &stb) == 0) {
7bdf8f
 			/* Must be the correct device, else error */
7bdf8f
 			if ((stb.st_mode&S_IFMT) != S_IFBLK ||
7bdf8f
-			    stb.st_rdev != (dev_t)devnm2devid(devnm)) {
7bdf8f
+			    stb.st_rdev != devnm2devid(devnm)) {
7bdf8f
 				pr_err("%s exists but looks wrong, please fix\n",
7bdf8f
 					devname);
7bdf8f
 				return -1;
7bdf8f
@@ -452,7 +452,7 @@ char *find_free_devnm(int use_partitions)
7bdf8f
 		if (!use_udev()) {
7bdf8f
 			/* make sure it is new to /dev too, at least as a
7bdf8f
 			 * non-standard */
7bdf8f
-			int devid = devnm2devid(devnm);
7bdf8f
+			dev_t devid = devnm2devid(devnm);
7bdf8f
 			if (devid) {
7bdf8f
 				char *dn = map_dev(major(devid),
7bdf8f
 						   minor(devid), 0);
7bdf8f
diff --git a/util.c b/util.c
7bdf8f
index 2bcb81f..31c407a 100644
7bdf8f
--- a/util.c
7bdf8f
+++ b/util.c
7bdf8f
@@ -928,7 +928,7 @@ int get_data_disks(int level, int layout, int raid_disks)
7bdf8f
 	return data_disks;
7bdf8f
 }
7bdf8f
 
7bdf8f
-int devnm2devid(char *devnm)
7bdf8f
+dev_t devnm2devid(char *devnm)
7bdf8f
 {
7bdf8f
 	/* First look in /sys/block/$DEVNM/dev for %d:%d
7bdf8f
 	 * If that fails, try parsing out a number
7bdf8f
@@ -1065,7 +1065,7 @@ int dev_open(char *dev, int flags)
7bdf8f
 
7bdf8f
 int open_dev_flags(char *devnm, int flags)
7bdf8f
 {
7bdf8f
-	int devid;
7bdf8f
+	dev_t devid;
7bdf8f
 	char buf[20];
7bdf8f
 
7bdf8f
 	devid = devnm2devid(devnm);
7bdf8f
@@ -1083,7 +1083,7 @@ int open_dev_excl(char *devnm)
7bdf8f
 	char buf[20];
7bdf8f
 	int i;
7bdf8f
 	int flags = O_RDWR;
7bdf8f
-	int devid = devnm2devid(devnm);
7bdf8f
+	dev_t devid = devnm2devid(devnm);
7bdf8f
 	long delay = 1000;
7bdf8f
 
7bdf8f
 	sprintf(buf, "%d:%d", major(devid), minor(devid));
7bdf8f
-- 
7bdf8f
2.7.4
7bdf8f