[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 2/6] conf: Introduce new XML tag "mode" for disk source



There are two ways to use a iSCSI LUN as disk source for qemu.

* The LUN's path showed up on host, e.g.
  /dev/disk/by-path/ip-$ip:3260-iscsi-$iqn-fc18:iscsi.iscsi0-lun-1

* The libiscsi URI, e.g.
  iscsi://demo.org:6000/iqn.1992-01.com.example/1

For a "volume" type disk, if the specified "pool" is of iscsi
type, we should support to use the LUN either of above 2 ways.
That's why to introduce a new XML tag "mode" for the disk source
(libvirt should support iscsi pool with libiscsi, but it's another
new feature, which should be done later).

The "mode" can be either of "host" or "uri". "host" to indicate
use the LUN with the path showed up on host. "uri" to indicate
use it with the libiscsi URI (future patches may support to use
network type libvirt storage too, e.g. Ceph, that's why to use
a more general name "uri").
---
 docs/formatdomain.html.in     |  9 ++++++++-
 docs/schemas/domaincommon.rng |  8 ++++++++
 src/conf/domain_conf.c        | 24 +++++++++++++++++++++++-
 src/conf/domain_conf.h        | 22 ++++++++++++++++++++++
 tests/qemuxml2xmltest.c       |  1 +
 5 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 755d084..4e344a2 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1557,7 +1557,14 @@
         <code>pool</code> and <code>volume</code>. Attribute <code>pool</code>
         specifies the name of storage pool (managed by libvirt) where the disk
         source resides, and attribute <code>volume</code> specifies the name of
-        storage volume (managed by libvirt) used as the disk source.
+        storage volume (managed by libvirt) used as the disk source. For a
+        "volume" type disk, if the underlying storage pool is "iscsi", attribute
+        <code>mode</code> (<span class="since">since 1.0.7</span>) can be used
+        to indicate how to represent the LUN as the disk source. value "host"
+        indicate to use the LUN's path showed up on host, e.g.
+        /dev/disk/by-path/ip-10.11.12.9:3260-iscsi-iqn.2013-06.fc:iscsi.iscsi0-lun-1)
+        . Value "uri" indicates to use the libiscsi URI, e.g.
+        file=iscsi://demo.org:6000/iqn.1992-01.com.example/1. Defaults to "host".
         <span class="since">Since 0.0.3; <code>type='dir'</code> since
         0.7.5; <code>type='network'</code> since
         0.8.7; <code>protocol='iscsi'</code> since 1.0.4;
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 3cace35..ac61582 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1145,6 +1145,14 @@
                   <ref name="volName"/>
                 </attribute>
                 <optional>
+                  <attribute name="mode">
+                    <choice>
+                      <value>host</value>
+                      <value>uri</value>
+                    </choice>
+                  </attribute>
+                </optional>
+                <optional>
                   <ref name="startupPolicy"/>
                 </optional>
                 <optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3e81013..009a8aa 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -756,6 +756,12 @@ VIR_ENUM_IMPL(virDomainDiskDiscard, VIR_DOMAIN_DISK_DISCARD_LAST,
               "unmap",
               "ignore")
 
+VIR_ENUM_IMPL(virDomainDiskSourcePoolMode,
+              VIR_DOMAIN_DISK_SOURCE_POOL_MODE_LAST,
+              "default",
+              "host",
+              "uri")
+
 #define VIR_DOMAIN_XML_WRITE_FLAGS  VIR_DOMAIN_XML_SECURE
 #define VIR_DOMAIN_XML_READ_FLAGS   VIR_DOMAIN_XML_INACTIVE
 
@@ -4600,10 +4606,12 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node,
 {
     char *pool = NULL;
     char *volume = NULL;
+    char *mode = NULL;
     int ret = -1;
 
     pool = virXMLPropString(node, "pool");
     volume = virXMLPropString(node, "volume");
+    mode = virXMLPropString(node, "mode");
 
     /* CD-ROM and Floppy allows no source */
     if (!pool && !volume)
@@ -4621,6 +4629,14 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node,
         goto cleanup;
     }
 
+    if (mode && (def->srcpool->mode =
+                 virDomainDiskSourcePoolModeTypeFromString(mode)) <= 0) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("unknown source mode '%s' for volume type disk"),
+                       mode);
+        goto cleanup;
+    }
+
     def->srcpool->pool = pool;
     pool = NULL;
     def->srcpool->volume = volume;
@@ -4631,6 +4647,7 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node,
 cleanup:
     VIR_FREE(pool);
     VIR_FREE(volume);
+    VIR_FREE(mode);
     return ret;
 }
 
@@ -13856,9 +13873,14 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
         case VIR_DOMAIN_DISK_TYPE_VOLUME:
             virBufferAddLit(buf, "      <source");
 
-            if (def->srcpool)
+            if (def->srcpool) {
                 virBufferAsprintf(buf, " pool='%s' volume='%s'",
                                   def->srcpool->pool, def->srcpool->volume);
+                if (def->srcpool->mode)
+                    virBufferAsprintf(buf, " mode='%s'",
+                                      virDomainDiskSourcePoolModeTypeToString(def->srcpool->mode));
+            }
+
             if (def->startupPolicy)
                 virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index b8edb1e..d57b7c3 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -646,11 +646,32 @@ struct _virDomainBlockIoTuneInfo {
 };
 typedef virDomainBlockIoTuneInfo *virDomainBlockIoTuneInfoPtr;
 
+/*
+ * Used for volume "type" disk to indicate how to represent
+ * the disk source if the specified "pool" is of iscsi type.
+ */
+enum virDomainDiskSourcePoolMode {
+    VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DEFAULT = 0,
+
+    /* Use the path showed up on host, e.g.
+     * /dev/disk/by-path/ip-$ip-iscsi-$iqn:iscsi.iscsi-pool0-lun-1
+     */
+    VIR_DOMAIN_DISK_SOURCE_POOL_MODE_HOST,
+
+    /* Use the URI. E.g.
+     * file=iscsi://demo.org:6000/iqn.1992-01.com.example/1.
+     */
+    VIR_DOMAIN_DISK_SOURCE_POOL_MODE_URI,
+
+    VIR_DOMAIN_DISK_SOURCE_POOL_MODE_LAST
+};
+
 typedef struct _virDomainDiskSourcePoolDef virDomainDiskSourcePoolDef;
 struct _virDomainDiskSourcePoolDef {
     char *pool; /* pool name */
     char *volume; /* volume name */
     int voltype; /* enum virStorageVolType, internal only */
+    int mode; /* enum virDomainDiskSourcePoolMode */
 };
 typedef virDomainDiskSourcePoolDef *virDomainDiskSourcePoolDefPtr;
 
@@ -2497,6 +2518,7 @@ VIR_ENUM_DECL(virDomainDiskSecretType)
 VIR_ENUM_DECL(virDomainDeviceSGIO)
 VIR_ENUM_DECL(virDomainDiskTray)
 VIR_ENUM_DECL(virDomainDiskDiscard)
+VIR_ENUM_DECL(virDomainDiskSourcePoolMode)
 VIR_ENUM_DECL(virDomainIoEventFd)
 VIR_ENUM_DECL(virDomainVirtioEventIdx)
 VIR_ENUM_DECL(virDomainDiskCopyOnRead)
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 06e4206..cb14cb9 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -261,6 +261,7 @@ mymain(void)
 
     DO_TEST("disk-scsi-disk-vpd");
     DO_TEST("disk-source-pool");
+    DO_TEST("disk-source-pool-mode");
 
     DO_TEST("disk-drive-discard");
 
-- 
1.8.1.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]