qemu: adjust the maxmemlock limit when hotplugging a vDPA device

and re-adjust if the hotplug fails.

This fixes a bug found during testing of
https://bugzilla.redhat.com/1939776, which was supposed to be resolved
by commit 98e22ff749, but failed to account for the case of device
hotplug.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Laine Stump 2021-05-21 14:51:05 -04:00
parent 7b8bec4560
commit 97075dff5c

View File

@ -1191,6 +1191,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
int ret = -1;
bool releaseaddr = false;
bool iface_connected = false;
bool adjustmemlock = false;
virDomainNetType actualType;
const virNetDevBandwidth *actualBandwidth;
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
@ -1369,6 +1370,10 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
break;
case VIR_DOMAIN_NET_TYPE_VDPA:
if (qemuDomainAdjustMaxMemLock(vm, false) < 0)
goto cleanup;
adjustmemlock = true;
if ((vdpafd = qemuInterfaceVDPAConnect(net)) < 0)
goto cleanup;
break;
@ -1549,6 +1554,13 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
*/
virDomainNetRemoveByObj(vm->def, net);
/* if we adjusted the memlock limit (for a vDPA device) then
* we need to re-adjust since we won't be using the device
* after all
*/
if (adjustmemlock)
qemuDomainAdjustMaxMemLock(vm, false);
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
if (conn)
virDomainNetReleaseActualDevice(conn, vm->def, net);