When upgrading from a libvirt which didn't format private data of a
virStorageSource representing an iSCSI hostdev source, we might need to
generate some internal data so that the code still works as if it was
present in the status XML.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_domain.c | 54 ++++++++++++++++++-
.../disk-secinfo-upgrade-in.xml | 20 +++++++
.../disk-secinfo-upgrade-out.xml | 30 +++++++++++
3 files changed, 102 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 3141a94136..41e4d5dd0b 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5319,6 +5319,51 @@ qemuDomainVsockDefPostParse(virDomainVsockDefPtr vsock)
}
+/**
+ * qemuDomainDeviceHostdevDefPostParseRestoreSecAlias:
+ *
+ * Re-generate aliases for objects related to the storage source if they
+ * were not stored in the status XML by an older libvirt.
+ *
+ * Note that qemuCaps should be always present for a status XML.
+ */
+static int
+qemuDomainDeviceHostdevDefPostParseRestoreSecAlias(virDomainHostdevDefPtr hostdev,
+ virQEMUCapsPtr qemuCaps,
+ unsigned int parseFlags)
+{
+ qemuDomainStorageSourcePrivatePtr priv;
+ virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
+ virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = &scsisrc->u.iscsi;
+ g_autofree char *authalias = NULL;
+
+ if (!(parseFlags & VIR_DOMAIN_DEF_PARSE_STATUS) ||
+ !qemuCaps ||
+ !virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_SECRET))
+ return 0;
+
+ if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
+ hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI ||
+ scsisrc->protocol != VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI ||
+ !virQEMUCapsGet(qemuCaps, QEMU_CAPS_ISCSI_PASSWORD_SECRET) ||
+ !qemuDomainStorageSourceHasAuth(iscsisrc->src))
+ return 0;
+
+ if (!(priv = qemuDomainStorageSourcePrivateFetch(iscsisrc->src)))
+ return -1;
+
+ if (priv->secinfo)
+ return 0;
+
+ authalias = g_strdup_printf("%s-secret0", hostdev->info->alias);
+
+ if (qemuStorageSourcePrivateDataAssignSecinfo(&priv->secinfo, &authalias)
< 0)
+ return -1;
+
+ return 0;
+}
+
+
static int
qemuDomainHostdevDefMdevPostParse(virDomainHostdevSubsysMediatedDevPtr mdevsrc,
virQEMUCapsPtr qemuCaps)
@@ -5336,10 +5381,15 @@
qemuDomainHostdevDefMdevPostParse(virDomainHostdevSubsysMediatedDevPtr mdevsrc,
static int
qemuDomainHostdevDefPostParse(virDomainHostdevDefPtr hostdev,
- virQEMUCapsPtr qemuCaps)
+ virQEMUCapsPtr qemuCaps,
+ unsigned int parseFlags)
{
virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
+ if (qemuDomainDeviceHostdevDefPostParseRestoreSecAlias(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)
@@ -5414,7 +5464,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
break;
case VIR_DOMAIN_DEVICE_HOSTDEV:
- ret = qemuDomainHostdevDefPostParse(dev->data.hostdev, qemuCaps);
+ ret = qemuDomainHostdevDefPostParse(dev->data.hostdev, qemuCaps, parseFlags);
break;
case VIR_DOMAIN_DEVICE_TPM:
diff --git a/tests/qemustatusxml2xmldata/disk-secinfo-upgrade-in.xml
b/tests/qemustatusxml2xmldata/disk-secinfo-upgrade-in.xml
index ce55a70637..8023857ffe 100644
--- a/tests/qemustatusxml2xmldata/disk-secinfo-upgrade-in.xml
+++ b/tests/qemustatusxml2xmldata/disk-secinfo-upgrade-in.xml
@@ -491,6 +491,26 @@
<alias name='video0'/>
<address type='pci' domain='0x0000' bus='0x00'
slot='0x02' function='0x0'/>
</video>
+ <hostdev mode='subsystem' type='scsi' managed='yes'>
+ <source protocol='iscsi'
name='iqn.1992-01.com.example:storage/1'>
+ <host name='example.org' port='3260'/>
+ <auth username='myname'>
+ <secret type='iscsi' usage='mycluster_myname'/>
+ </auth>
+ </source>
+ <alias name='hostdev0'/>
+ <address type='drive' controller='0' bus='0'
target='2' unit='4'/>
+ </hostdev>
+ <hostdev mode='subsystem' type='scsi' managed='yes'>
+ <source protocol='iscsi'
name='iqn.1992-01.com.example:storage/2'>
+ <host name='example.org' port='3260'/>
+ <auth username='myname'>
+ <secret type='iscsi' usage='mycluster_myname'/>
+ </auth>
+ </source>
+ <alias name='hostdev1'/>
+ <address type='drive' controller='0' bus='0'
target='2' unit='5'/>
+ </hostdev>
<redirdev bus='usb' type='spicevmc'>
<alias name='redir0'/>
<address type='usb' bus='0' port='2'/>
diff --git a/tests/qemustatusxml2xmldata/disk-secinfo-upgrade-out.xml
b/tests/qemustatusxml2xmldata/disk-secinfo-upgrade-out.xml
index 5d3287606f..d5534fb0f5 100644
--- a/tests/qemustatusxml2xmldata/disk-secinfo-upgrade-out.xml
+++ b/tests/qemustatusxml2xmldata/disk-secinfo-upgrade-out.xml
@@ -513,6 +513,36 @@
<alias name='video0'/>
<address type='pci' domain='0x0000' bus='0x00'
slot='0x02' function='0x0'/>
</video>
+ <hostdev mode='subsystem' type='scsi' managed='yes'>
+ <source protocol='iscsi'
name='iqn.1992-01.com.example:storage/1'>
+ <host name='example.org' port='3260'/>
+ <privateData>
+ <objects>
+ <secret type='auth' alias='hostdev0-secret0'/>
+ </objects>
+ </privateData>
+ <auth username='myname'>
+ <secret type='iscsi' usage='mycluster_myname'/>
+ </auth>
+ </source>
+ <alias name='hostdev0'/>
+ <address type='drive' controller='0' bus='0'
target='2' unit='4'/>
+ </hostdev>
+ <hostdev mode='subsystem' type='scsi' managed='yes'>
+ <source protocol='iscsi'
name='iqn.1992-01.com.example:storage/2'>
+ <host name='example.org' port='3260'/>
+ <privateData>
+ <objects>
+ <secret type='auth' alias='hostdev1-secret0'/>
+ </objects>
+ </privateData>
+ <auth username='myname'>
+ <secret type='iscsi' usage='mycluster_myname'/>
+ </auth>
+ </source>
+ <alias name='hostdev1'/>
+ <address type='drive' controller='0' bus='0'
target='2' unit='5'/>
+ </hostdev>
<redirdev bus='usb' type='spicevmc'>
<alias name='redir0'/>
<address type='usb' bus='0' port='2'/>
--
2.26.2