[PATCH] imsm: assign UUID of spare device based on ARRAY *device* keyword in mdadm configuration file.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If config has list of devices associated with container and it comprises given spare drive, UUID is set apporopriately to this container.
It allows to assign spare with proper container according
to content in devices parameter in configuration file.

Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@xxxxxxxxx>
---
 super-intel.c |   48 +++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/super-intel.c b/super-intel.c
index a196ca3..41a4cc6 100644
--- a/super-intel.c
+++ b/super-intel.c
@@ -1497,10 +1497,19 @@ static void getinfo_super_imsm_volume(struct supertype *st, struct mdinfo *info)
 	uuid_from_super_imsm(st, info->uuid);
 }
 
+static int matchfd2devnum(int fd, int maj, int min)
+{
+	struct stat st;
+	if (fstat(fd, &st) != 0)
+		return 1;
+	return ((int)major(st.st_rdev) == maj && (int)minor(st.st_rdev) == min);
+}
+
+
 /* check the config file to see if we can return a real uuid for this spare */
-static void fixup_container_spare_uuid(struct mdinfo *inf)
+static void fixup_container_spare_uuid(struct mdinfo *inf, struct dl *disk)
 {
-	struct mddev_ident_s *array_list;
+	struct mddev_ident_s *array_list, *first_match = NULL;
 
 	if (inf->array.level != LEVEL_CONTAINER ||
 	    memcmp(inf->uuid, uuid_match_any, sizeof(int[4])) != 0)
@@ -1520,12 +1529,41 @@ static void fixup_container_spare_uuid(struct mdinfo *inf)
 				_sst = NULL;
 
 			if (_sst) {
-				memcpy(inf->uuid, array_list->uuid, sizeof(int[4]));
+				char *devices = array_list->devices;
+
+				if (!first_match)
+					first_match = array_list;
+
+				while (disk && devices && *devices) {
+					char path[PATH_MAX];
+					char *p = devices;
+					int fd;
+
+					devices = strchr(devices, ',');
+					if (!devices)
+						devices = p + strlen(p);
+					if (devices-p < PATH_MAX) {
+						strncpy(path, p, devices - p);
+						if ((fd = open(path, O_RDONLY)) >= 0) {
+							if (matchfd2devnum(fd, disk->major, disk->minor)) {
+								free(_sst);
+								close(fd);
+								goto match;
+							}
+							close(fd);
+						}
+						if (*devices == ',')
+							devices++;
+					}
+				}
 				free(_sst);
-				break;
 			}
 		}
 	}
+match:;
+	if (!array_list)
+		array_list = first_match;
+	memcpy(inf->uuid, array_list->uuid, sizeof(int[4]));
 }
 
 static void getinfo_super_imsm(struct supertype *st, struct mdinfo *info)
@@ -1584,7 +1622,7 @@ static void getinfo_super_imsm(struct supertype *st, struct mdinfo *info)
 		uuid_from_super_imsm(st, info->uuid);
 	else {
 		memcpy(info->uuid, uuid_match_any, sizeof(int[4]));
-		fixup_container_spare_uuid(info);
+		fixup_container_spare_uuid(info, super->disks);
 	}
 }
 
-- 
1.6.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux