dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/util-Introduce2-md_get_array_info.patch

b7f731
From 9cd39f015558dba82c293a4433b481b921ceec87 Mon Sep 17 00:00:00 2001
b7f731
From: Jes Sorensen <Jes.Sorensen@gmail.com>
b7f731
Date: Wed, 29 Mar 2017 14:35:41 -0400
b7f731
Subject: [RHEL7.5 PATCH 037/169] util: Introduce md_get_array_info()
b7f731
b7f731
Remove most direct ioctl calls for GET_ARRAY_INFO, except for one,
b7f731
which will be addressed in the next patch.
b7f731
b7f731
This is the start of the effort to clean up the use of ioctl calls and
b7f731
introduce a more structured API, which will use sysfs and fall back to
b7f731
ioctl for backup.
b7f731
b7f731
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
b7f731
---
b7f731
 Create.c      |  5 ++---
b7f731
 Detail.c      |  2 +-
b7f731
 Grow.c        | 31 ++++++++++++++++---------------
b7f731
 Incremental.c | 11 +++++------
b7f731
 Manage.c      | 13 ++++++-------
b7f731
 Monitor.c     |  7 ++++---
b7f731
 Query.c       |  7 ++++---
b7f731
 mdadm.h       |  1 +
b7f731
 mdassemble.c  |  2 +-
b7f731
 util.c        | 14 +++++++++++---
b7f731
 10 files changed, 51 insertions(+), 42 deletions(-)
b7f731
b7f731
diff --git a/Create.c b/Create.c
b7f731
index 10e7d10..0e0778f 100644
b7f731
--- a/Create.c
b7f731
+++ b/Create.c
b7f731
@@ -156,8 +156,7 @@ int Create(struct supertype *st, char *mddev,
b7f731
 		memset(&inf, 0, sizeof(inf));
b7f731
 		fd = open(devlist->devname, O_RDONLY);
b7f731
 		if (fd >= 0 &&
b7f731
-		    ioctl(fd, GET_ARRAY_INFO, &inf) == 0 &&
b7f731
-		    inf.raid_disks == 0) {
b7f731
+		    md_get_array_info(fd, &inf) == 0 && inf.raid_disks == 0) {
b7f731
 			/* yep, looks like a container */
b7f731
 			if (st) {
b7f731
 				rv = st->ss->load_container(st, fd,
b7f731
@@ -634,7 +633,7 @@ int Create(struct supertype *st, char *mddev,
b7f731
 	} else {
b7f731
 		mdu_array_info_t inf;
b7f731
 		memset(&inf, 0, sizeof(inf));
b7f731
-		ioctl(mdfd, GET_ARRAY_INFO, &inf);
b7f731
+		md_get_array_info(mdfd, &inf);
b7f731
 		if (inf.working_disks != 0) {
b7f731
 			pr_err("another array by this name is already running.\n");
b7f731
 			goto abort_locked;
b7f731
diff --git a/Detail.c b/Detail.c
b7f731
index 136875b..d7e886a 100644
b7f731
--- a/Detail.c
b7f731
+++ b/Detail.c
b7f731
@@ -107,7 +107,7 @@ int Detail(char *dev, struct context *c)
b7f731
 	external = (sra != NULL && sra->array.major_version == -1
b7f731
 		    && sra->array.minor_version == -2);
b7f731
 	st = super_by_fd(fd, &subarray);
b7f731
-	if (ioctl(fd, GET_ARRAY_INFO, &array) == 0) {
b7f731
+	if (md_get_array_info(fd, &array) == 0) {
b7f731
 		inactive = 0;
b7f731
 	} else if (errno == ENODEV && sra) {
b7f731
 		if (sra->array.major_version == -1 &&
b7f731
diff --git a/Grow.c b/Grow.c
b7f731
index 6405f0e..4eab5cc 100755
b7f731
--- a/Grow.c
b7f731
+++ b/Grow.c
b7f731
@@ -115,7 +115,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
b7f731
 	struct supertype *st = NULL;
b7f731
 	char *subarray = NULL;
b7f731
 
b7f731
-	if (ioctl(fd, GET_ARRAY_INFO, &info.array) < 0) {
b7f731
+	if (md_get_array_info(fd, &info.array) < 0) {
b7f731
 		pr_err("cannot get array info for %s\n", devname);
b7f731
 		return 1;
b7f731
 	}
b7f731
@@ -221,7 +221,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
b7f731
 	 * Now go through and update all superblocks
b7f731
 	 */
b7f731
 
b7f731
-	if (ioctl(fd, GET_ARRAY_INFO, &info.array) < 0) {
b7f731
+	if (md_get_array_info(fd, &info.array) < 0) {
b7f731
 		pr_err("cannot get array info for %s\n", devname);
b7f731
 		return 1;
b7f731
 	}
b7f731
@@ -328,7 +328,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
b7f731
 			devname, bmf.pathname);
b7f731
 		return 1;
b7f731
 	}
b7f731
-	if (ioctl(fd, GET_ARRAY_INFO, &array) != 0) {
b7f731
+	if (md_get_array_info(fd, &array) != 0) {
b7f731
 		pr_err("cannot get array status for %s\n", devname);
b7f731
 		return 1;
b7f731
 	}
b7f731
@@ -1784,7 +1784,7 @@ int Grow_reshape(char *devname, int fd,
b7f731
 	struct mdinfo info;
b7f731
 	struct mdinfo *sra;
b7f731
 
b7f731
-	if (ioctl(fd, GET_ARRAY_INFO, &array) < 0) {
b7f731
+	if (md_get_array_info(fd, &array) < 0) {
b7f731
 		pr_err("%s is not an active md array - aborting\n",
b7f731
 			devname);
b7f731
 		return 1;
b7f731
@@ -2030,7 +2030,7 @@ int Grow_reshape(char *devname, int fd,
b7f731
 					/* get array parameters after takeover
b7f731
 					 * to change one parameter at time only
b7f731
 					 */
b7f731
-					rv = ioctl(fd, GET_ARRAY_INFO, &array);
b7f731
+					rv = md_get_array_info(fd, &array);
b7f731
 				}
b7f731
 			}
b7f731
 			/* make sure mdmon is
b7f731
@@ -2072,7 +2072,7 @@ int Grow_reshape(char *devname, int fd,
b7f731
 			/* go back to raid0, drop parity disk
b7f731
 			 */
b7f731
 			sysfs_set_str(sra, NULL, "level", "raid0");
b7f731
-			ioctl(fd, GET_ARRAY_INFO, &array);
b7f731
+			md_get_array_info(fd, &array);
b7f731
 		}
b7f731
 
b7f731
 size_change_error:
b7f731
@@ -2101,7 +2101,7 @@ size_change_error:
b7f731
 			    sysfs_set_str(sra, NULL, "resync_start", "none") < 0)
b7f731
 				pr_err("--assume-clean not supported with --grow on this kernel\n");
b7f731
 		}
b7f731
-		ioctl(fd, GET_ARRAY_INFO, &array);
b7f731
+		md_get_array_info(fd, &array);
b7f731
 		s->size = get_component_size(fd)/2;
b7f731
 		if (s->size == 0)
b7f731
 			s->size = array.size;
b7f731
@@ -2267,7 +2267,7 @@ size_change_error:
b7f731
 			rv =1 ;
b7f731
 		}
b7f731
 		if (s->layout_str) {
b7f731
-			if (ioctl(fd, GET_ARRAY_INFO, &array) != 0) {
b7f731
+			if (md_get_array_info(fd, &array) != 0) {
b7f731
 				dprintf("Cannot get array information.\n");
b7f731
 				goto release;
b7f731
 			}
b7f731
@@ -2830,7 +2830,7 @@ static int impose_reshape(struct mdinfo *sra,
b7f731
 						 * reshape->after.data_disks);
b7f731
 	}
b7f731
 
b7f731
-	ioctl(fd, GET_ARRAY_INFO, &array);
b7f731
+	md_get_array_info(fd, &array);
b7f731
 	if (info->array.chunk_size == info->new_chunk &&
b7f731
 	    reshape->before.layout == reshape->after.layout &&
b7f731
 	    st->ss->external == 0) {
b7f731
@@ -2885,7 +2885,7 @@ static int impose_level(int fd, int level, char *devname, int verbose)
b7f731
 	struct mdinfo info;
b7f731
 	sysfs_init(&info, fd, NULL);
b7f731
 
b7f731
-	ioctl(fd, GET_ARRAY_INFO, &array);
b7f731
+	md_get_array_info(fd, &array);
b7f731
 	if (level == 0 &&
b7f731
 	    (array.level >= 4 && array.level <= 6)) {
b7f731
 		/* To convert to RAID0 we need to fail and
b7f731
@@ -2921,7 +2921,7 @@ static int impose_level(int fd, int level, char *devname, int verbose)
b7f731
 			      makedev(disk.major, disk.minor));
b7f731
 		}
b7f731
 		/* Now fail anything left */
b7f731
-		ioctl(fd, GET_ARRAY_INFO, &array);
b7f731
+		md_get_array_info(fd, &array);
b7f731
 		for (d = 0, found = 0;
b7f731
 		     d < MAX_DISKS && found < array.nr_disks;
b7f731
 		     d++) {
b7f731
@@ -3042,7 +3042,7 @@ static int reshape_array(char *container, int fd, char *devname,
b7f731
 	/* when reshaping a RAID0, the component_size might be zero.
b7f731
 	 * So try to fix that up.
b7f731
 	 */
b7f731
-	if (ioctl(fd, GET_ARRAY_INFO, &array) != 0) {
b7f731
+	if (md_get_array_info(fd, &array) != 0) {
b7f731
 		dprintf("Cannot get array information.\n");
b7f731
 		goto release;
b7f731
 	}
b7f731
@@ -3230,7 +3230,7 @@ static int reshape_array(char *container, int fd, char *devname,
b7f731
 		 * some more changes: layout, raid_disks, chunk_size
b7f731
 		 */
b7f731
 		/* read current array info */
b7f731
-		if (ioctl(fd, GET_ARRAY_INFO, &array) != 0) {
b7f731
+		if (md_get_array_info(fd, &array) != 0) {
b7f731
 			dprintf("Cannot get array information.\n");
b7f731
 			goto release;
b7f731
 		}
b7f731
@@ -4994,8 +4994,9 @@ int Grow_continue_command(char *devname, int fd,
b7f731
 		int d;
b7f731
 		int cnt = 5;
b7f731
 		dprintf_cont("native array (%s)\n", devname);
b7f731
-		if (ioctl(fd, GET_ARRAY_INFO, &array.array) < 0) {
b7f731
-			pr_err("%s is not an active md array - aborting\n", devname);
b7f731
+		if (md_get_array_info(fd, &array.array) < 0) {
b7f731
+			pr_err("%s is not an active md array - aborting\n",
b7f731
+			       devname);
b7f731
 			ret_val = 1;
b7f731
 			goto Grow_continue_command_exit;
b7f731
 		}
b7f731
diff --git a/Incremental.c b/Incremental.c
b7f731
index 81afc7e..1f12c77 100644
b7f731
--- a/Incremental.c
b7f731
+++ b/Incremental.c
b7f731
@@ -398,7 +398,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
b7f731
 		    && ! policy_action_allows(policy, st->ss->name,
b7f731
 					      act_re_add)
b7f731
 		    && c->runstop < 1) {
b7f731
-			if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0) {
b7f731
+			if (md_get_array_info(mdfd, &ainf) == 0) {
b7f731
 				pr_err("not adding %s to active array (without --run) %s\n",
b7f731
 				       devname, chosen_name);
b7f731
 				rv = 2;
b7f731
@@ -549,7 +549,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
b7f731
 	/*   + add any bitmap file  */
b7f731
 	/*   + start the array (auto-readonly). */
b7f731
 
b7f731
-	if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0) {
b7f731
+	if (md_get_array_info(mdfd, &ainf) == 0) {
b7f731
 		if (c->export) {
b7f731
 			printf("MD_STARTED=already\n");
b7f731
 		} else if (c->verbose >= 0)
b7f731
@@ -664,7 +664,7 @@ static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
b7f731
 	struct mdinfo *d;
b7f731
 	mdu_array_info_t ra;
b7f731
 
b7f731
-	if (ioctl(mdfd, GET_ARRAY_INFO, &ra) == 0)
b7f731
+	if (md_get_array_info(mdfd, &ra) == 0)
b7f731
 		return; /* not safe to remove from active arrays
b7f731
 			 * without thinking more */
b7f731
 
b7f731
@@ -837,7 +837,7 @@ static int container_members_max_degradation(struct map_ent *map, struct map_ent
b7f731
 		if (afd < 0)
b7f731
 			continue;
b7f731
 		/* most accurate information regarding array degradation */
b7f731
-		if (ioctl(afd, GET_ARRAY_INFO, &array) >= 0) {
b7f731
+		if (md_get_array_info(afd, &array) >= 0) {
b7f731
 			int degraded = array.raid_disks - array.active_disks -
b7f731
 				       array.spare_disks;
b7f731
 			if (degraded > max_degraded)
b7f731
@@ -1390,8 +1390,7 @@ restart:
b7f731
 				rv = 1;
b7f731
 			continue;
b7f731
 		}
b7f731
-		if (ioctl(mdfd, GET_ARRAY_INFO, &array) == 0 ||
b7f731
-		    errno != ENODEV) {
b7f731
+		if (md_get_array_info(mdfd, &array) == 0 || errno != ENODEV) {
b7f731
 			close(mdfd);
b7f731
 			continue;
b7f731
 		}
b7f731
diff --git a/Manage.c b/Manage.c
b7f731
index 55218d9..24ed370 100644
b7f731
--- a/Manage.c
b7f731
+++ b/Manage.c
b7f731
@@ -95,7 +95,7 @@ int Manage_ro(char *devname, int fd, int readonly)
b7f731
 		goto out;
b7f731
 	}
b7f731
 #endif
b7f731
-	if (ioctl(fd, GET_ARRAY_INFO, &array)) {
b7f731
+	if (md_get_array_info(fd, &array)) {
b7f731
 		pr_err("%s does not appear to be active.\n",
b7f731
 			devname);
b7f731
 		rv = 1;
b7f731
@@ -539,7 +539,7 @@ static void add_faulty(struct mddev_dev *dv, int fd, char disp)
b7f731
 	int remaining_disks;
b7f731
 	int i;
b7f731
 
b7f731
-	if (ioctl(fd, GET_ARRAY_INFO, &array) != 0)
b7f731
+	if (md_get_array_info(fd, &array) != 0)
b7f731
 		return;
b7f731
 
b7f731
 	remaining_disks = array.nr_disks;
b7f731
@@ -565,7 +565,7 @@ static void add_detached(struct mddev_dev *dv, int fd, char disp)
b7f731
 	int remaining_disks;
b7f731
 	int i;
b7f731
 
b7f731
-	if (ioctl(fd, GET_ARRAY_INFO, &array) != 0)
b7f731
+	if (md_get_array_info(fd, &array) != 0)
b7f731
 		return;
b7f731
 
b7f731
 	remaining_disks = array.nr_disks;
b7f731
@@ -602,7 +602,7 @@ static void add_set(struct mddev_dev *dv, int fd, char set_char)
b7f731
 	int copies, set;
b7f731
 	int i;
b7f731
 
b7f731
-	if (ioctl(fd, GET_ARRAY_INFO, &array) != 0)
b7f731
+	if (md_get_array_info(fd, &array) != 0)
b7f731
 		return;
b7f731
 	if (array.level != 10)
b7f731
 		return;
b7f731
@@ -1383,9 +1383,8 @@ int Manage_subdevs(char *devname, int fd,
b7f731
 	int busy = 0;
b7f731
 	int raid_slot = -1;
b7f731
 
b7f731
-	if (ioctl(fd, GET_ARRAY_INFO, &array)) {
b7f731
-		pr_err("Cannot get array info for %s\n",
b7f731
-			devname);
b7f731
+	if (md_get_array_info(fd, &array)) {
b7f731
+		pr_err("Cannot get array info for %s\n", devname);
b7f731
 		goto abort;
b7f731
 	}
b7f731
 	sysfs_init(&info, fd, NULL);
b7f731
diff --git a/Monitor.c b/Monitor.c
b7f731
index bdd3e63..0a0a1e2 100644
b7f731
--- a/Monitor.c
b7f731
+++ b/Monitor.c
b7f731
@@ -497,7 +497,7 @@ static int check_array(struct state *st, struct mdstat_ent *mdstat,
b7f731
 		return 0;
b7f731
 	}
b7f731
 	fcntl(fd, F_SETFD, FD_CLOEXEC);
b7f731
-	if (ioctl(fd, GET_ARRAY_INFO, &array)<0) {
b7f731
+	if (md_get_array_info(fd, &array) < 0) {
b7f731
 		if (!st->err)
b7f731
 			alert("DeviceDisappeared", dev, NULL, ainfo);
b7f731
 		st->err++;
b7f731
@@ -709,9 +709,10 @@ static int add_new_arrays(struct mdstat_ent *mdstat, struct state **statelist,
b7f731
 
b7f731
 			st->devname = xstrdup(name);
b7f731
 			if ((fd = open(st->devname, O_RDONLY)) < 0 ||
b7f731
-			    ioctl(fd, GET_ARRAY_INFO, &array)< 0) {
b7f731
+			    md_get_array_info(fd, &array) < 0) {
b7f731
 				/* no such array */
b7f731
-				if (fd >=0) close(fd);
b7f731
+				if (fd >= 0)
b7f731
+					close(fd);
b7f731
 				put_md_name(st->devname);
b7f731
 				free(st->devname);
b7f731
 				if (st->metadata) {
b7f731
diff --git a/Query.c b/Query.c
b7f731
index fbc1d10..cae75d1 100644
b7f731
--- a/Query.c
b7f731
+++ b/Query.c
b7f731
@@ -53,9 +53,10 @@ int Query(char *dev)
b7f731
 	}
b7f731
 
b7f731
 	vers = md_get_version(fd);
b7f731
-	if (ioctl(fd, GET_ARRAY_INFO, &array)<0)
b7f731
+	if (md_get_array_info(fd, &array) < 0)
b7f731
 		ioctlerr = errno;
b7f731
-	else ioctlerr = 0;
b7f731
+	else
b7f731
+		ioctlerr = 0;
b7f731
 
b7f731
 	fstat(fd, &stb;;
b7f731
 
b7f731
@@ -100,7 +101,7 @@ int Query(char *dev)
b7f731
 			activity = "undetected";
b7f731
 			if (mddev && (fd = open(mddev, O_RDONLY))>=0) {
b7f731
 				if (md_get_version(fd) >= 9000 &&
b7f731
-				    ioctl(fd, GET_ARRAY_INFO, &array)>= 0) {
b7f731
+				    md_get_array_info(fd, &array) >= 0) {
b7f731
 					if (ioctl(fd, GET_DISK_INFO, &disc) >= 0 &&
b7f731
 					    makedev((unsigned)disc.major,(unsigned)disc.minor) == stb.st_rdev)
b7f731
 						activity = "active";
b7f731
diff --git a/mdadm.h b/mdadm.h
b7f731
index dbf1f92..7770585 100644
b7f731
--- a/mdadm.h
b7f731
+++ b/mdadm.h
b7f731
@@ -1405,6 +1405,7 @@ extern int Restore_metadata(char *dev, char *dir, struct context *c,
b7f731
 			    struct supertype *st, int only);
b7f731
 
b7f731
 extern int md_get_version(int fd);
b7f731
+int md_get_array_info(int fd, struct mdu_array_info_s *array);
b7f731
 extern int get_linux_version(void);
b7f731
 extern int mdadm_version(char *version);
b7f731
 extern unsigned long long parse_size(char *size);
b7f731
diff --git a/mdassemble.c b/mdassemble.c
b7f731
index 471ffeb..a24b324 100644
b7f731
--- a/mdassemble.c
b7f731
+++ b/mdassemble.c
b7f731
@@ -67,7 +67,7 @@ int main(int argc, char *argv[])
b7f731
 			if (strcasecmp(array_list->devname, "<ignore>") == 0)
b7f731
 				continue;
b7f731
 			mdfd = open_mddev(array_list->devname, 0);
b7f731
-			if (mdfd >= 0 && ioctl(mdfd, GET_ARRAY_INFO, &array) == 0) {
b7f731
+			if (mdfd >= 0 && md_get_array_info(mdfd, &array) == 0) {
b7f731
 				rv |= Manage_ro(array_list->devname, mdfd, -1); /* make it readwrite */
b7f731
 				continue;
b7f731
 			}
b7f731
diff --git a/util.c b/util.c
b7f731
index 374015e..725877d 100644
b7f731
--- a/util.c
b7f731
+++ b/util.c
b7f731
@@ -212,6 +212,15 @@ int cluster_release_dlmlock(int lockid)
b7f731
 #endif
b7f731
 
b7f731
 /*
b7f731
+ * Get array info from the kernel. Longer term we want to deprecate the
b7f731
+ * ioctl and get it from sysfs.
b7f731
+ */
b7f731
+int md_get_array_info(int fd, struct mdu_array_info_s *array)
b7f731
+{
b7f731
+	return ioctl(fd, GET_ARRAY_INFO, array);
b7f731
+}
b7f731
+
b7f731
+/*
b7f731
  * Parse a 128 bit uuid in 4 integers
b7f731
  * format is 32 hexx nibbles with options :.<space> separator
b7f731
  * If not exactly 32 hex digits are found, return 0
b7f731
@@ -539,8 +548,7 @@ int enough_fd(int fd)
b7f731
 	int i, rv;
b7f731
 	char *avail;
b7f731
 
b7f731
-	if (ioctl(fd, GET_ARRAY_INFO, &array) != 0 ||
b7f731
-	    array.raid_disks <= 0)
b7f731
+	if (md_get_array_info(fd, &array) != 0 || array.raid_disks <= 0)
b7f731
 		return 0;
b7f731
 	avail = xcalloc(array.raid_disks, 1);
b7f731
 	for (i = 0; i < MAX_DISKS && array.nr_disks > 0; i++) {
b7f731
@@ -1175,7 +1183,7 @@ struct supertype *super_by_fd(int fd, char **subarrayp)
b7f731
 		minor = sra->array.minor_version;
b7f731
 		verstr = sra->text_version;
b7f731
 	} else {
b7f731
-		if (ioctl(fd, GET_ARRAY_INFO, &array))
b7f731
+		if (md_get_array_info(fd, &array))
b7f731
 			array.major_version = array.minor_version = 0;
b7f731
 		vers = array.major_version;
b7f731
 		minor = array.minor_version;
b7f731
-- 
b7f731
2.7.4
b7f731