kpartx: Add option '-f' to force devmap creation
authorHannes Reinecke <hare@suse.de>
Mon, 6 Dec 2010 07:38:10 +0000 (08:38 +0100)
committerHannes Reinecke <hare@suse.de>
Tue, 3 May 2011 07:54:21 +0000 (09:54 +0200)
Under some circumstances the user needs to override the
'no_partitions' feature of a multipath device.
This patch adds an option '-f' to facilitate this.

Signed-off-by: Libor Pechacek <lpechacek@novell.com>
Acked-by: Hannes Reinecke <hare@suse.de>
kpartx/kpartx.8
kpartx/kpartx.c

index 923be1e..5d73d31 100644 (file)
@@ -26,6 +26,9 @@ List partition mappings that would be added -a
 .B \-p
 set device name-partition number delimiter
 .TP
+.B \-f
+force creation of mappings; overrides 'no_partitions' feature
+.TP
 .B \-g
 force GUID partition table (GPT)
 .TP
index 5007ce2..05dfce7 100644 (file)
@@ -82,14 +82,16 @@ initpts(void)
        addpts("sun", read_sun_pt);
 }
 
-static char short_opts[] = "rladgvp:t:su";
+static char short_opts[] = "rladfgvp:t:su";
 
 /* Used in gpt.c */
 int force_gpt=0;
 
+int force_devmap=0;
+
 static int
 usage(void) {
-       printf("usage : kpartx [-a|-d|-l] [-v] wholedisk\n");
+       printf("usage : kpartx [-a|-d|-l] [-f] [-v] wholedisk\n");
        printf("\t-a add partition devmappings\n");
        printf("\t-r devmappings will be readonly\n");
        printf("\t-d del partition devmappings\n");
@@ -97,6 +99,7 @@ usage(void) {
        printf("\t-l list partitions devmappings that would be added by -a\n");
        printf("\t-p set device name-partition number delimiter\n");
        printf("\t-g force GUID partition table (GPT)\n");
+       printf("\t-f force devmap create\n");
        printf("\t-v verbose\n");
        printf("\t-s sync mode. Don't return until the partitions are created\n");
        return 1;
@@ -238,6 +241,8 @@ main(int argc, char **argv){
        while ((arg = getopt(argc, argv, short_opts)) != EOF) switch(arg) {
                case 'r':
                        ro=1;
+               case 'f':
+                       force_devmap=1;
                        break;
                case 'g':
                        force_gpt=1;
@@ -336,7 +341,8 @@ main(int argc, char **argv){
 
        if (!mapname)
                mapname = device + off;
-       else if (dm_no_partitions((unsigned int)MAJOR(buf.st_rdev),
+       else if (!force_devmap &&
+                dm_no_partitions((unsigned int)MAJOR(buf.st_rdev),
                                  (unsigned int)MINOR(buf.st_rdev))) {
                /* Feature 'no_partitions' is set, return */
                return 0;