qemu: Use 'effectiveBootIndex' to handle <os><boot dev='network'>

Fill in the effective boot index for network devices (or hostdev-backed
network devices via 'qemuProcessPrepareDeviceBootorder'. This patch
doesn't clean up the cruft to make it more obvious what's happening.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-10-01 16:18:13 +02:00
parent c90d17c812
commit c3bd60ddc6
2 changed files with 32 additions and 9 deletions

View File

@ -3706,7 +3706,7 @@ qemuBuildLegacyNicStr(virDomainNetDef *net)
char *
qemuBuildNicDevStr(virDomainDef *def,
virDomainNetDef *net,
unsigned int bootindex,
unsigned int bootindex G_GNUC_UNUSED,
size_t vhostfdSize,
virQEMUCaps *qemuCaps)
{
@ -3841,8 +3841,8 @@ qemuBuildNicDevStr(virDomainDef *def,
return NULL;
if (qemuBuildRomStr(&buf, &net->info) < 0)
return NULL;
if (bootindex)
virBufferAsprintf(&buf, ",bootindex=%u", bootindex);
if (net->info.effectiveBootIndex > 0)
virBufferAsprintf(&buf, ",bootindex=%u", net->info.effectiveBootIndex);
return virBufferContentAndReset(&buf);
}
@ -4628,7 +4628,7 @@ qemuBuildVideoCommandLine(virCommand *cmd,
char *
qemuBuildPCIHostdevDevStr(const virDomainDef *def,
virDomainHostdevDef *dev,
unsigned int bootIndex, /* used iff dev->info->bootIndex == 0 */
unsigned int bootIndex G_GNUC_UNUSED,
virQEMUCaps *qemuCaps G_GNUC_UNUSED)
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
@ -4660,10 +4660,8 @@ qemuBuildPCIHostdevDevStr(const virDomainDef *def,
pcisrc->addr.slot,
pcisrc->addr.function);
virBufferAsprintf(&buf, ",id=%s", dev->info->alias);
if (dev->info->bootIndex)
bootIndex = dev->info->bootIndex;
if (bootIndex)
virBufferAsprintf(&buf, ",bootindex=%u", bootIndex);
if (dev->info->effectiveBootIndex > 0)
virBufferAsprintf(&buf, ",bootindex=%u", dev->info->effectiveBootIndex);
if (qemuBuildDeviceAddressStr(&buf, def, dev->info) < 0)
return NULL;
if (qemuBuildRomStr(&buf, dev->info) < 0)

View File

@ -6270,6 +6270,7 @@ qemuProcessPrepareDeviceBootorder(virDomainDef *def)
unsigned int bootCD = 0;
unsigned int bootFloppy = 0;
unsigned int bootDisk = 0;
unsigned int bootNetwork = 0;
if (def->os.nBootDevs == 0)
return;
@ -6289,7 +6290,9 @@ qemuProcessPrepareDeviceBootorder(virDomainDef *def)
break;
case VIR_DOMAIN_BOOT_NET:
/* network boot is handled in network device formatting code */
bootNetwork = i + 1;
break;
case VIR_DOMAIN_BOOT_LAST:
default:
break;
@ -6321,6 +6324,28 @@ qemuProcessPrepareDeviceBootorder(virDomainDef *def)
break;
}
}
if (def->nnets > 0 && bootNetwork > 0) {
/* If network boot is enabled, the first network device gets enabled. If
* that one is backed by a host device, then we need to find the first
* corresponding host device */
if (virDomainNetGetActualType(def->nets[0]) == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
for (i = 0; i < def->nhostdevs; i++) {
virDomainHostdevDef *hostdev = def->hostdevs[i];
virDomainHostdevSubsys *subsys = &hostdev->source.subsys;
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED &&
hostdev->parentnet) {
hostdev->info->effectiveBootIndex = bootNetwork;
break;
}
}
} else {
def->nets[0]->info.effectiveBootIndex = bootNetwork;
}
}
}