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>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2020-09-09 17:58:34 +02:00
parent 8e008c1013
commit 482c52b177
4 changed files with 69 additions and 0 deletions

View File

@ -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 static int
qemuDomainHostdevDefMdevPostParse(virDomainHostdevSubsysMediatedDevPtr mdevsrc, qemuDomainHostdevDefMdevPostParse(virDomainHostdevSubsysMediatedDevPtr mdevsrc,
virQEMUCapsPtr qemuCaps) virQEMUCapsPtr qemuCaps)
@ -5327,6 +5378,10 @@ qemuDomainHostdevDefPostParse(virDomainHostdevDefPtr hostdev,
parseFlags) < 0) parseFlags) < 0)
return -1; return -1;
if (qemuDomainDeviceHostdevDefPostParseRestoreBackendAlias(hostdev, qemuCaps,
parseFlags) < 0)
return -1;
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV && hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
qemuDomainHostdevDefMdevPostParse(&subsys->u.mdev, qemuCaps) < 0) qemuDomainHostdevDefMdevPostParse(&subsys->u.mdev, qemuCaps) < 0)

View File

@ -234,6 +234,7 @@
<flag name='dump-completed'/> <flag name='dump-completed'/>
<flag name='hda-output'/> <flag name='hda-output'/>
<flag name='blockdev'/> <flag name='blockdev'/>
<flag name='blockdev-hostdev-scsi'/>
</qemuCaps> </qemuCaps>
<devices> <devices>
<device alias='rng0'/> <device alias='rng0'/>

View File

@ -232,6 +232,7 @@
<flag name='isa-serial'/> <flag name='isa-serial'/>
<flag name='dump-completed'/> <flag name='dump-completed'/>
<flag name='hda-output'/> <flag name='hda-output'/>
<flag name='blockdev-hostdev-scsi'/>
</qemuCaps> </qemuCaps>
<devices> <devices>
<device alias='rng0'/> <device alias='rng0'/>

View File

@ -232,6 +232,7 @@
<flag name='isa-serial'/> <flag name='isa-serial'/>
<flag name='dump-completed'/> <flag name='dump-completed'/>
<flag name='hda-output'/> <flag name='hda-output'/>
<flag name='blockdev-hostdev-scsi'/>
</qemuCaps> </qemuCaps>
<devices> <devices>
<device alias='rng0'/> <device alias='rng0'/>
@ -517,6 +518,9 @@
<source protocol='iscsi' name='iqn.1992-01.com.example:storage/1'> <source protocol='iscsi' name='iqn.1992-01.com.example:storage/1'>
<host name='example.org' port='3260'/> <host name='example.org' port='3260'/>
<privateData> <privateData>
<nodenames>
<nodename type='storage' name='libvirt-hostdev0-backend'/>
</nodenames>
<objects> <objects>
<secret type='auth' alias='hostdev0-secret0'/> <secret type='auth' alias='hostdev0-secret0'/>
</objects> </objects>
@ -532,6 +536,9 @@
<source protocol='iscsi' name='iqn.1992-01.com.example:storage/2'> <source protocol='iscsi' name='iqn.1992-01.com.example:storage/2'>
<host name='example.org' port='3260'/> <host name='example.org' port='3260'/>
<privateData> <privateData>
<nodenames>
<nodename type='storage' name='libvirt-hostdev1-backend'/>
</nodenames>
<objects> <objects>
<secret type='auth' alias='hostdev1-secret0'/> <secret type='auth' alias='hostdev1-secret0'/>
</objects> </objects>
@ -547,6 +554,11 @@
<source> <source>
<adapter name='scsi_host0'/> <adapter name='scsi_host0'/>
<address bus='0' target='0' unit='0'/> <address bus='0' target='0' unit='0'/>
<privateData>
<nodenames>
<nodename type='storage' name='libvirt-hostdev2-backend'/>
</nodenames>
</privateData>
</source> </source>
<alias name='hostdev2'/> <alias name='hostdev2'/>
<address type='drive' controller='0' bus='0' target='2' unit='6'/> <address type='drive' controller='0' bus='0' target='2' unit='6'/>