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

[PATCH 09/17] qemu: domain: Fill in (i)SCSI backend nodename if it is not present in status XML



For upgrade reasons so that we can modify the used nodename we must
generate the old version for all status XMLs which don't have it stored
explicitly.

The change will be required as using the user-provided alias may result
in too-long nodenames which will be rejected by qemu.

Add code which fills in the appropriate old value and add test cases to
validate that it's added and also that existing nodenames are not
overwritten.

Signed-off-by: Peter Krempa <pkrempa redhat com>
---
 src/qemu/qemu_domain.c                      | 55 +++++++++++++++++++++
 tests/qemustatusxml2xmldata/modern-in.xml   |  1 +
 tests/qemustatusxml2xmldata/upgrade-in.xml  |  1 +
 tests/qemustatusxml2xmldata/upgrade-out.xml | 12 +++++
 4 files changed, 69 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 0ed132a829..89f2c2c09b 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5301,6 +5301,57 @@ qemuDomainDeviceHostdevDefPostParseRestoreSecAlias(virDomainHostdevDefPtr hostde
 }


+/**
+ * qemuDomainDeviceHostdevDefPostParseRestoreBackendAlias:
+ *
+ * Re-generate backend alias if it wasn't stored in the status XML by an older
+ * libvirtd.
+ *
+ * Note that qemuCaps should be always present for a status XML.
+ */
+static int
+qemuDomainDeviceHostdevDefPostParseRestoreBackendAlias(virDomainHostdevDefPtr hostdev,
+                                                       virQEMUCapsPtr qemuCaps,
+                                                       unsigned int parseFlags)
+{
+    virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
+    virStorageSourcePtr src;
+
+    if (!(parseFlags & VIR_DOMAIN_DEF_PARSE_STATUS))
+        return 0;
+
+    if (!qemuCaps ||
+        hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
+        hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI ||
+        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV_HOSTDEV_SCSI))
+        return 0;
+
+    switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+    case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE:
+        if (!scsisrc->u.host.src &&
+            !(scsisrc->u.host.src = virStorageSourceNew()))
+            return -1;
+
+        src = scsisrc->u.host.src;
+        break;
+
+    case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI:
+        src = scsisrc->u.iscsi.src;
+        break;
+
+    case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_LAST:
+    default:
+        virReportEnumRangeError(virDomainHostdevSCSIProtocolType, scsisrc->protocol);
+        return -1;
+    }
+
+    if (!src->nodestorage)
+        src->nodestorage = g_strdup_printf("libvirt-%s-backend", hostdev->info->alias);
+
+    return 0;
+}
+
+
 static int
 qemuDomainHostdevDefMdevPostParse(virDomainHostdevSubsysMediatedDevPtr mdevsrc,
                                   virQEMUCapsPtr qemuCaps)
@@ -5327,6 +5378,10 @@ qemuDomainHostdevDefPostParse(virDomainHostdevDefPtr hostdev,
                                                            parseFlags) < 0)
         return -1;

+    if (qemuDomainDeviceHostdevDefPostParseRestoreBackendAlias(hostdev, qemuCaps,
+                                                               parseFlags) < 0)
+        return -1;
+
     if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
         hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
         qemuDomainHostdevDefMdevPostParse(&subsys->u.mdev, qemuCaps) < 0)
diff --git a/tests/qemustatusxml2xmldata/modern-in.xml b/tests/qemustatusxml2xmldata/modern-in.xml
index 0a3990bd3e..5a5d5b8983 100644
--- a/tests/qemustatusxml2xmldata/modern-in.xml
+++ b/tests/qemustatusxml2xmldata/modern-in.xml
@@ -234,6 +234,7 @@
     <flag name='dump-completed'/>
     <flag name='hda-output'/>
     <flag name='blockdev'/>
+    <flag name='blockdev-hostdev-scsi'/>
   </qemuCaps>
   <devices>
     <device alias='rng0'/>
diff --git a/tests/qemustatusxml2xmldata/upgrade-in.xml b/tests/qemustatusxml2xmldata/upgrade-in.xml
index 1942eacfa4..7fa56429f4 100644
--- a/tests/qemustatusxml2xmldata/upgrade-in.xml
+++ b/tests/qemustatusxml2xmldata/upgrade-in.xml
@@ -232,6 +232,7 @@
     <flag name='isa-serial'/>
     <flag name='dump-completed'/>
     <flag name='hda-output'/>
+    <flag name='blockdev-hostdev-scsi'/>
   </qemuCaps>
   <devices>
     <device alias='rng0'/>
diff --git a/tests/qemustatusxml2xmldata/upgrade-out.xml b/tests/qemustatusxml2xmldata/upgrade-out.xml
index ee3c1b49b0..962d25ce2e 100644
--- a/tests/qemustatusxml2xmldata/upgrade-out.xml
+++ b/tests/qemustatusxml2xmldata/upgrade-out.xml
@@ -232,6 +232,7 @@
     <flag name='isa-serial'/>
     <flag name='dump-completed'/>
     <flag name='hda-output'/>
+    <flag name='blockdev-hostdev-scsi'/>
   </qemuCaps>
   <devices>
     <device alias='rng0'/>
@@ -517,6 +518,9 @@
         <source protocol='iscsi' name='iqn.1992-01.com.example:storage/1'>
           <host name='example.org' port='3260'/>
           <privateData>
+            <nodenames>
+              <nodename type='storage' name='libvirt-hostdev0-backend'/>
+            </nodenames>
             <objects>
               <secret type='auth' alias='hostdev0-secret0'/>
             </objects>
@@ -532,6 +536,9 @@
         <source protocol='iscsi' name='iqn.1992-01.com.example:storage/2'>
           <host name='example.org' port='3260'/>
           <privateData>
+            <nodenames>
+              <nodename type='storage' name='libvirt-hostdev1-backend'/>
+            </nodenames>
             <objects>
               <secret type='auth' alias='hostdev1-secret0'/>
             </objects>
@@ -547,6 +554,11 @@
         <source>
           <adapter name='scsi_host0'/>
           <address bus='0' target='0' unit='0'/>
+          <privateData>
+            <nodenames>
+              <nodename type='storage' name='libvirt-hostdev2-backend'/>
+            </nodenames>
+          </privateData>
         </source>
         <alias name='hostdev2'/>
         <address type='drive' controller='0' bus='0' target='2' unit='6'/>
-- 
2.26.2


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