]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Introduce new XML tag "mode" for disk source
authorJohn Ferlan <jferlan@redhat.com>
Thu, 18 Jul 2013 17:18:03 +0000 (13:18 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 22 Jul 2013 18:01:04 +0000 (14:01 -0400)
There are two ways to use a iSCSI LUN as disk source for qemu.

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

 * The libiscsi URI from the storage pool source element host attribute, 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 in 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 "direct". Use "host" to indicate
use of the LUN with the path as it shows up on host. Use "direct" to
indicate to use it with the source pool host URI (future patches may support
to use network type libvirt storage too, e.g. Ceph)

docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/conf/domain_conf.h
tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool-mode.xml [new file with mode: 0644]
tests/qemuxml2xmltest.c

index b1c3bfca3eecbbfdb3e47bf2b304af48a728f8c0..7601aaaf546df6ff34b563e6d3a5d20bbe3b3e46 100644 (file)
         <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.1.1</span>) can be used
+        to indicate how to represent the LUN as the disk source. The value
+        "host" indicates to use the LUN's path as it shows up on host, e.g.
+        /dev/disk/by-path/ip-10.11.12.9:3260-iscsi-iqn.2013-06.fc:iscsi.iscsi0-lun-1).
+        The value "direct" indicates to use the storage pool's
+        <code>source</code> element <code>host</code> attribute as the
+        disk source for the libiscsi URI, e.g.
+        file=iscsi://demo.org:6000/iqn.1992-01.com.example/1.
         <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;
index 7a6852b3779401f04c01cc5f591748b1bc629e24..745b959a8f09f43f1abe40e9cc2681a539c7183a 100644 (file)
                 <attribute name="volume">
                   <ref name="volName"/>
                 </attribute>
+                <optional>
+                  <attribute name="mode">
+                    <choice>
+                      <value>host</value>
+                      <value>direct</value>
+                    </choice>
+                  </attribute>
+                </optional>
                 <optional>
                   <ref name="startupPolicy"/>
                 </optional>
index 308a96beef586999196d0738c3cddeb0694d541e..297553c23af20a7d0ee7c29d09aeeeb35b628178 100644 (file)
@@ -761,6 +761,11 @@ VIR_ENUM_IMPL(virDomainDiskDiscard, VIR_DOMAIN_DISK_DISCARD_LAST,
               "default",
               "unmap",
               "ignore")
+VIR_ENUM_IMPL(virDomainDiskSourcePoolMode,
+              VIR_DOMAIN_DISK_SOURCE_POOL_MODE_LAST,
+              "default",
+              "host",
+              "direct")
 
 #define VIR_DOMAIN_XML_WRITE_FLAGS  VIR_DOMAIN_XML_SECURE
 #define VIR_DOMAIN_XML_READ_FLAGS   VIR_DOMAIN_XML_INACTIVE
@@ -4645,10 +4650,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)
@@ -4664,6 +4671,14 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node,
     if (VIR_ALLOC(def->srcpool) < 0)
         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;
@@ -4674,6 +4689,7 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node,
 cleanup:
     VIR_FREE(pool);
     VIR_FREE(volume);
+    VIR_FREE(mode);
     return ret;
 }
 
@@ -14157,9 +14173,13 @@ 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);
 
index 00d3c3a4ab3a6574408330afececcd13d2e587ca..900fb01f056fd82ce677fbd2b829224be6a063b3 100644 (file)
@@ -652,11 +652,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 as it shows 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 from the storage pool source element host attribute. E.g.
+     * file=iscsi://demo.org:6000/iqn.1992-01.com.example/1.
+     */
+    VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT,
+
+    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;
 
@@ -2554,6 +2575,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/qemuxml2argvdata/qemuxml2argv-disk-source-pool-mode.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool-mode.xml
new file mode 100644 (file)
index 0000000..b907633
--- /dev/null
@@ -0,0 +1,48 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <disk type='volume' device='cdrom'>
+      <source pool='blk-pool0' volume='blk-pool0-vol0' mode='host' startupPolicy='optional'>
+        <seclabel model='selinux' relabel='yes'>
+          <label>system_u:system_r:public_content_t:s0</label>
+        </seclabel>
+      </source>
+      <target dev='hda' bus='ide'/>
+      <readonly/>
+      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
+    </disk>
+    <disk type='volume' device='cdrom'>
+      <source pool='blk-pool0' volume='blk-pool0-vol1' mode='direct' startupPolicy='optional'>
+        <seclabel model='selinux' relabel='yes'>
+          <label>system_u:system_r:public_content_t:s0</label>
+        </seclabel>
+      </source>
+      <target dev='hda' bus='ide'/>
+      <readonly/>
+      <address type='drive' controller='0' bus='0' target='0' unit='2'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <source file='/tmp/idedisk.img'/>
+      <target dev='hdc' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='3'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='ide' index='0'/>
+    <controller type='ide' index='1'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
index 76570c5c9560ed6ea5b554caea03062c8eee478a..77cac3f68733c22340cd354d231f542c81f4ebc6 100644 (file)
@@ -264,6 +264,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");