[libvirt] [PATCH RFC 2/3] storage: Add new flag for libvirt_parthelper

John Ferlan jferlan at redhat.com
Fri Dec 4 22:16:55 UTC 2015


In order to be able to process disk storage pool's using a multipath
device to handle the partitions, libvirt_parthelper will need to know
about a feature available from multipath known as 'user_friendly_names'.

This feature causes multipath partitions to not include the "p"
partition separator unless the partition ends with a number in the
generated partition name of the device.

For example, device path "/dev/mapper/mpatha" would create partitions
"mpatha1", "mpatha2", etc. instead of "mpathap1", "mpathap2", etc.
If however, the device path ended with a number "/dev/mapper/mpatha1",
then the existing algorithm to generate names "mpatha1p1", "mpatha1p2",
etc. would be utilized.

In order to enable the feature, the appropriate storage pool flags bit
VIR_STORAGE_POOL_SOURCE_USER_FRIENDLY_NAMES will be checked and if so
pass a "-f" to the libvirt_parthelper which will process the "-f" flag
to utilize the new algorithm to process the generated partition names
that get then passed back to libvirt and processed against the device
mapper multipath (dm-#) names.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/storage/parthelper.c           | 15 ++++++++++++---
 src/storage/storage_backend_disk.c |  7 +++++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/storage/parthelper.c b/src/storage/parthelper.c
index 8de32fd..7a658ae 100644
--- a/src/storage/parthelper.c
+++ b/src/storage/parthelper.c
@@ -10,7 +10,7 @@
  * in a reliable fashion if merely after a list of partitions & sizes,
  * though it is fine for creating partitions.
  *
- * Copyright (C) 2007-2008, 2010, 2013 Red Hat, Inc.
+ * Copyright (C) 2007-2008, 2010, 2013, 2015 Red Hat, Inc.
  * Copyright (C) 2007-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -70,6 +70,7 @@ int main(int argc, char **argv)
     const char *path;
     char *canonical_path;
     const char *partsep;
+    bool user_friendly_names = false;
 
     if (setlocale(LC_ALL, "") == NULL ||
         bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
@@ -80,14 +81,22 @@ int main(int argc, char **argv)
 
     if (argc == 3 && STREQ(argv[2], "-g")) {
         cmd = DISK_GEOMETRY;
+    } else if (argc == 3 && STREQ(argv[2], "-f")) {
+        user_friendly_names = true;
     } else if (argc != 2) {
-        fprintf(stderr, _("syntax: %s DEVICE [-g]\n"), argv[0]);
+        fprintf(stderr, _("syntax: %s DEVICE [-g]|[-f]\n"), argv[0]);
         return 1;
     }
 
     path = argv[1];
     if (virIsDevMapperDevice(path)) {
-        partsep = "p";
+        /* The 'user_friendly_names' option will not append the partsep of "p"
+         * onto the name unless the 'path' ends in a number
+         */
+        if (c_isdigit(path[strlen(path)-1]) || !user_friendly_names)
+            partsep ="p";
+        else
+            partsep = "";
         if (VIR_STRDUP_QUIET(canonical_path, path) < 0)
             return 2;
     } else {
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index 7baecc1..63481c8 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -324,6 +324,13 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool,
                                pool->def->source.devices[0].path,
                                NULL);
 
+    /* Check for the presence of the user_friendly_names flags. Pass this
+     * along to the libvirt_parthelper as option '-f'. This will create
+     * slightly different names in the returned list.
+     */
+    if (pool->def->source.flags & VIR_STORAGE_POOL_SOURCE_USER_FRIENDLY_NAMES)
+        virCommandAddArg(cmd, "-f");
+
     /* If a volume is passed, virStorageBackendDiskMakeVol only updates the
      * pool allocation for that single volume.
      */
-- 
2.5.0




More information about the libvir-list mailing list