diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 924f01d3eb1f28e53e6b44157f8b416ecdbd1499..65c3be58d318a5684b0148cfd50e7c1495a39a4e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8623,6 +8623,35 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef, return 0; } + +static void +qemuDomainAttachDeviceLiveAndConfigHomogenize(const virDomainDeviceDef *devConf, + virDomainDeviceDefPtr devLive) +{ + /* + * Fixup anything that needs to be identical in the live and + * config versions of DeviceDef, but might not be. Do this by + * changing the contents of devLive. This is done after all + * post-parse tweaks and validation, so be very careful about what + * changes are made. (For example, it would be a very bad idea to + * change assigned PCI, scsi, or sata addresses, as it could lead + * to a conflict and there would be nothing to catch it except + * qemu itself!) + */ + + /* MAC address should be identical in both DeviceDefs, but if it + * wasn't specified in the XML, and was instead autogenerated, it + * will be different for the two since they are each the result of + * a separate parser call. If it *was* specified, it will already + * be the same, so copying does no harm. + */ + + if (devConf->type == VIR_DOMAIN_DEVICE_NET) + virMacAddrSet(&devLive->data.net->mac, &devConf->data.net->mac); + +} + + static int qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm, virQEMUDriverPtr driver, @@ -8633,6 +8662,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm, virDomainDefPtr vmdef = NULL; g_autoptr(virQEMUDriverConfig) cfg = NULL; virDomainDeviceDefPtr devConf = NULL; + virDomainDeviceDef devConfSave = { 0 }; virDomainDeviceDefPtr devLive = NULL; int ret = -1; unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE | @@ -8657,6 +8687,13 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm, parse_flags))) goto cleanup; + /* + * devConf will be NULLed out by + * qemuDomainAttachDeviceConfig(), so save it for later use by + * qemuDomainAttachDeviceLiveAndConfigHomogenize() + */ + devConfSave = *devConf; + if (virDomainDeviceValidateAliasForHotplug(vm, devConf, VIR_DOMAIN_AFFECT_CONFIG) < 0) goto cleanup; @@ -8678,6 +8715,9 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObjPtr vm, parse_flags))) goto cleanup; + if (flags & VIR_DOMAIN_AFFECT_CONFIG) + qemuDomainAttachDeviceLiveAndConfigHomogenize(&devConfSave, devLive); + if (virDomainDeviceValidateAliasForHotplug(vm, devLive, VIR_DOMAIN_AFFECT_LIVE) < 0) goto cleanup;