You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

328 lines
8.4 KiB

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