mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 22:03:49 +03:00
qemu: domain: Regenerate hostdev source private data
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@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
3aca4865a8
commit
dd339e86db
@ -5089,6 +5089,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)
|
||||
@ -5106,10 +5151,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)
|
||||
@ -5184,7 +5234,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:
|
||||
|
@ -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'/>
|
||||
|
@ -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'/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user