671555
---
671555
 kpartx/bsd.c    |   35 ---------------
671555
 kpartx/dos.c    |    7 +--
671555
 kpartx/kpartx.c |  123 +++++++-------------------------------------------------
671555
 kpartx/kpartx.h |    1 
671555
 kpartx/sun.c    |   35 ---------------
671555
 5 files changed, 24 insertions(+), 177 deletions(-)
671555
671555
Index: multipath-tools-130222/kpartx/bsd.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/kpartx/bsd.c
671555
+++ multipath-tools-130222/kpartx/bsd.c
671555
@@ -50,10 +50,10 @@ int
671555
 read_bsd_pt(int fd, struct slice all, struct slice *sp, int ns) {
671555
 	struct bsd_disklabel *l;
671555
 	struct bsd_partition *p;
671555
-	unsigned int offset = all.start, end;
671555
+	unsigned int offset = all.start;
671555
 	int max_partitions;
671555
 	char *bp;
671555
-	int n = 0, i, j;
671555
+	int n = 0;
671555
 
671555
 	bp = getblock(fd, offset+1);    /* 1 sector suffices */
671555
 	if (bp == NULL)
671555
@@ -79,36 +79,5 @@ read_bsd_pt(int fd, struct slice all, st
671555
 			break;
671555
 		}
671555
 	}
671555
-	/*
671555
-	 * Convention has it that the bsd disklabel will always have
671555
-	 * the 'c' partition spanning the entire disk.
671555
-	 * So we have to check for contained slices.
671555
-	 */
671555
-	for(i = 0; i < n; i++) {
671555
-		if (sp[i].size == 0)
671555
-			continue;
671555
-
671555
-		end = sp[i].start + sp[i].size;
671555
-		for(j = 0; j < n; j ++) {
671555
-			if ( i == j )
671555
-				continue;
671555
-			if (sp[j].size == 0)
671555
-				continue;
671555
-
671555
-			if (sp[i].start < sp[j].start) {
671555
-				if (end > sp[j].start &&
671555
-				    end < sp[j].start + sp[j].size) {
671555
-					/* Invalid slice */
671555
-					fprintf(stderr,
671555
-						"bsd_disklabel: slice %d overlaps with %d\n", i , j);
671555
-					sp[i].size = 0;
671555
-				}
671555
-			} else {
671555
-				if (end <= sp[j].start + sp[j].size) {
671555
-					sp[i].container = j + 1;
671555
-				}
671555
-			}
671555
-		}
671555
-	}
671555
 	return n;
671555
 }
671555
Index: multipath-tools-130222/kpartx/dos.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/kpartx/dos.c
671555
+++ multipath-tools-130222/kpartx/dos.c
671555
@@ -16,7 +16,7 @@ is_extended(int type) {
671555
 }
671555
 
671555
 static int
671555
-read_extended_partition(int fd, struct partition *ep, int en,
671555
+read_extended_partition(int fd, struct partition *ep,
671555
 			struct slice *sp, int ns)
671555
 {
671555
 	struct partition p;
671555
@@ -53,7 +53,6 @@ read_extended_partition(int fd, struct p
671555
 			if (n < ns) {
671555
 				sp[n].start = here + le32_to_cpu(p.start_sect);
671555
 				sp[n].size = le32_to_cpu(p.nr_sects);
671555
-				sp[n].container = en + 1;
671555
 				n++;
671555
 			} else {
671555
 				fprintf(stderr,
671555
@@ -98,7 +97,9 @@ read_dos_pt(int fd, struct slice all, st
671555
 			break;
671555
 		}
671555
 		if (is_extended(p.sys_type)) {
671555
-			n += read_extended_partition(fd, &p, i, sp+n, ns-n);
671555
+			n += read_extended_partition(fd, &p, sp+n, ns-n);
671555
+			/* hide the extended partition itself */
671555
+			sp[i].size = 2;
671555
 		}
671555
 	}
671555
 	return n;
671555
Index: multipath-tools-130222/kpartx/kpartx.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/kpartx/kpartx.c
671555
+++ multipath-tools-130222/kpartx/kpartx.c
671555
@@ -192,7 +192,7 @@ get_hotplug_device(void)
671555
 
671555
 int
671555
 main(int argc, char **argv){
671555
-	int i, j, m, n, op, off, arg, c, d, ro=0;
671555
+	int i, j, m, n, op, off, arg, ro=0;
671555
 	int fd = -1;
671555
 	struct slice all;
671555
 	struct pt *ptp;
671555
@@ -381,49 +381,30 @@ main(int argc, char **argv){
671555
 		else
671555
 			continue;
671555
 
671555
+		/*
671555
+ 		 * test for overlap, as in the case of an extended partition
671555
+ 		 * zero their size to avoid mapping
671555
+ 		 */
671555
+		for (j = 0; j < n; j++) {
671555
+			for (m = j + 1; m < n; m++) {
671555
+				if (slices[m].start > slices[j].start &&
671555
+				    slices[m].start < slices[j].start +
671555
+				    slices[j].size)
671555
+					slices[j].size = 0;
671555
+			}
671555
+		}
671555
+
671555
 		switch(what) {
671555
 		case LIST:
671555
-			for (j = 0, c = 0, m = 0; j < n; j++) {
671555
+			for (j = 0; j < n; j++) {
671555
 				if (slices[j].size == 0)
671555
 					continue;
671555
-				if (slices[j].container > 0) {
671555
-					c++;
671555
-					continue;
671555
-				}
671555
-
671555
-				slices[j].minor = m++;
671555
 
671555
 				printf("%s%s%d : 0 %" PRIu64 " %s %" PRIu64"\n",
671555
 				       mapname, delim, j+1,
671555
 				       slices[j].size, device,
671555
 				       slices[j].start);
671555
 			}
671555
-			/* Loop to resolve contained slices */
671555
-			d = c;
671555
-			while (c) {
671555
-				for (j = 0; j < n; j++) {
671555
-					uint64_t start;
671555
-					int k = slices[j].container - 1;
671555
-
671555
-					if (slices[j].size == 0)
671555
-						continue;
671555
-					if (slices[j].minor > 0)
671555
-						continue;
671555
-					if (slices[j].container == 0)
671555
-						continue;
671555
-					slices[j].minor = m++;
671555
-
671555
-					start = slices[j].start - slices[k].start;
671555
-					printf("%s%s%d : 0 %" PRIu64 " /dev/dm-%d %" PRIu64 "\n",
671555
-					       mapname, delim, j+1,
671555
-					       slices[j].size,
671555
-					       slices[k].minor, start);
671555
-					c--;
671555
-				}
671555
-				/* Terminate loop if nothing more to resolve */
671555
-				if (d == c)
671555
-					break;
671555
-			}
671555
 
671555
 			break;
671555
 
671555
@@ -462,16 +443,10 @@ main(int argc, char **argv){
671555
 		case ADD:
671555
 		case UPDATE:
671555
 			/* ADD and UPDATE share the same code that adds new partitions. */
671555
-			for (j = 0, c = 0; j < n; j++) {
671555
+			for (j = 0; j < n; j++) {
671555
 				if (slices[j].size == 0)
671555
 					continue;
671555
 
671555
-				/* Skip all contained slices */
671555
-				if (slices[j].container > 0) {
671555
-					c++;
671555
-					continue;
671555
-				}
671555
-
671555
 				if (safe_sprintf(partname, "%s%s%d",
671555
 					     mapname, delim, j+1)) {
671555
 					fprintf(stderr, "partname too small\n");
671555
@@ -512,72 +487,6 @@ main(int argc, char **argv){
671555
 					       slices[j].minor, slices[j].size,
671555
 					       DM_TARGET, params);
671555
 			}
671555
-			/* Loop to resolve contained slices */
671555
-			d = c;
671555
-			while (c) {
671555
-				for (j = 0; j < n; j++) {
671555
-					uint64_t start;
671555
-					int k = slices[j].container - 1;
671555
-
671555
-					if (slices[j].size == 0)
671555
-						continue;
671555
-
671555
-					/* Skip all existing slices */
671555
-					if (slices[j].minor > 0)
671555
-						continue;
671555
-
671555
-					/* Skip all simple slices */
671555
-					if (slices[j].container == 0)
671555
-						continue;
671555
-
671555
-					/* Check container slice */
671555
-					if (slices[k].size == 0)
671555
-						fprintf(stderr, "Invalid slice %d\n",
671555
-							k);
671555
-
671555
-					if (safe_sprintf(partname, "%s%s%d",
671555
-							 mapname, delim, j+1)) {
671555
-						fprintf(stderr, "partname too small\n");
671555
-						exit(1);
671555
-					}
671555
-					strip_slash(partname);
671555
-
671555
-					start = slices[j].start - slices[k].start;
671555
-					if (safe_sprintf(params, "%d:%d %" PRIu64,
671555
-							 slices[k].major,
671555
-							 slices[k].minor,
671555
-							 start)) {
671555
-						fprintf(stderr, "params too small\n");
671555
-						exit(1);
671555
-					}
671555
-
671555
-					op = (dm_map_present(partname) ?
671555
-					      DM_DEVICE_RELOAD : DM_DEVICE_CREATE);
671555
-
671555
-					dm_addmap(op, partname, DM_TARGET, params,
671555
-						  slices[j].size, ro, uuid, j+1,
671555
-						  buf.st_mode & 0777,
671555
-						  buf.st_uid, buf.st_gid,
671555
-						  &cookie);
671555
-
671555
-					if (op == DM_DEVICE_RELOAD)
671555
-						dm_simplecmd(DM_DEVICE_RESUME,
671555
-							     partname, 1,
671555
-							     &cookie);
671555
-
671555
-					dm_devn(partname, &slices[j].major,
671555
-						&slices[j].minor);
671555
-
671555
-					if (verbose)
671555
-						printf("add map %s : 0 %" PRIu64 " %s %s\n",
671555
-						       partname, slices[j].size,
671555
-						       DM_TARGET, params);
671555
-					c--;
671555
-				}
671555
-				/* Terminate loop */
671555
-				if (d == c)
671555
-					break;
671555
-			}
671555
 
671555
 			if (what == ADD) {
671555
 				/* Skip code that removes devmappings for deleted partitions */
671555
Index: multipath-tools-130222/kpartx/kpartx.h
671555
===================================================================
671555
--- multipath-tools-130222.orig/kpartx/kpartx.h
671555
+++ multipath-tools-130222/kpartx/kpartx.h
671555
@@ -24,7 +24,6 @@
671555
 struct slice {
671555
 	uint64_t start;
671555
 	uint64_t size;
671555
-	int container;
671555
 	int major;
671555
 	int minor;
671555
 };
671555
Index: multipath-tools-130222/kpartx/sun.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/kpartx/sun.c
671555
+++ multipath-tools-130222/kpartx/sun.c
671555
@@ -62,8 +62,8 @@ int
671555
 read_sun_pt(int fd, struct slice all, struct slice *sp, int ns) {
671555
 	struct sun_disk_label *l;
671555
 	struct sun_raw_part *s;
671555
-	unsigned int offset = all.start, end;
671555
-	int i, j, n;
671555
+	unsigned int offset = all.start;
671555
+	int i, n;
671555
 	char *bp;
671555
 
671555
 	bp = getblock(fd, offset);
671555
@@ -95,37 +95,6 @@ read_sun_pt(int fd, struct slice all, st
671555
 			break;
671555
 		}
671555
 	}
671555
-	/*
671555
-	 * Convention has it that the SUN disklabel will always have
671555
-	 * the 'c' partition spanning the entire disk.
671555
-	 * So we have to check for contained slices.
671555
-	 */
671555
-	for(i = 0; i < SUN_DISK_MAXPARTITIONS; i++) {
671555
-		if (sp[i].size == 0)
671555
-			continue;
671555
-
671555
-		end = sp[i].start + sp[i].size;
671555
-		for(j = 0; j < SUN_DISK_MAXPARTITIONS; j ++) {
671555
-			if ( i == j )
671555
-				continue;
671555
-			if (sp[j].size == 0)
671555
-				continue;
671555
-
671555
-			if (sp[i].start < sp[j].start) {
671555
-				if (end > sp[j].start &&
671555
-				    end < sp[j].start + sp[j].size) {
671555
-					/* Invalid slice */
671555
-					fprintf(stderr,
671555
-						"sun_disklabel: slice %d overlaps with %d\n", i , j);
671555
-					sp[i].size = 0;
671555
-				}
671555
-			} else {
671555
-				if (end <= sp[j].start + sp[j].size) {
671555
-					sp[i].container = j + 1;
671555
-				}
671555
-			}
671555
-		}
671555
-	}
671555
 	return n;
671555
 }
671555