[kpartx] Use mapname for device-mapper devices
authorHannes Reinecke <hare@suse.de>
Wed, 16 May 2007 07:35:35 +0000 (09:35 +0200)
committerChristophe Varoqui <cvaroqui@zezette.localdomain>
Mon, 21 May 2007 21:20:21 +0000 (23:20 +0200)
When kpartx is run on a device-mapper device it makes more sense
to use the mapname for generating the device name, not the supplied
commandline arguments. This way we can run kpartx on '/dev/dm-X'
and still get sensible names.

Signed-off-by: Hannes Reinecke <hare@suse.de>
kpartx/kpartx.c

index 0ee0cb3..b406b95 100644 (file)
@@ -193,6 +193,7 @@ main(int argc, char **argv){
        char * loopdev = NULL;
        char * delim = NULL;
        char *uuid = NULL;
+       char *mapname = NULL;
        int loopro = 0;
        int hotplug = 0;
        struct stat buf;
@@ -310,12 +311,19 @@ main(int argc, char **argv){
        
        off = find_devname_offset(device);
 
-       if (!loopdev)
+       if (!loopdev) {
                uuid = dm_mapuuid((unsigned int)MAJOR(buf.st_rdev),
                                  (unsigned int)MINOR(buf.st_rdev));
+               mapname = dm_mapname((unsigned int)MAJOR(buf.st_rdev),
+                                    (unsigned int)MINOR(buf.st_rdev));
+       }
+
        if (!uuid)
                uuid = device + off;
                
+       if (!mapname)
+               mapname = device + off;
+
        fd = open(device, O_RDONLY);
 
        if (fd == -1) {
@@ -365,7 +373,7 @@ main(int argc, char **argv){
                                        continue;
 
                                printf("%s%s%d : 0 %lu %s %lu\n",
-                                       device + off, delim, j+1,
+                                       mapname, delim, j+1,
                                        (unsigned long) slices[j].size, device,
                                        (unsigned long) slices[j].start);
                        }
@@ -374,7 +382,7 @@ main(int argc, char **argv){
                case DELETE:
                        for (j = 0; j < n; j++) {
                                if (safe_sprintf(partname, "%s%s%d",
-                                            device + off , delim, j+1)) {
+                                            mapname, delim, j+1)) {
                                        fprintf(stderr, "partname too small\n");
                                        exit(1);
                                }
@@ -407,7 +415,7 @@ main(int argc, char **argv){
                                        continue;
 
                                if (safe_sprintf(partname, "%s%s%d",
-                                            device + off , delim, j+1)) {
+                                            mapname, delim, j+1)) {
                                        fprintf(stderr, "partname too small\n");
                                        exit(1);
                                }