qemu: Refactor the max memlock routine

Let's pull this hunk out into a function, so it can be reused
in another codepath that needs to do the same thing.

Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Eric Farman 2019-09-03 22:09:46 +02:00 committed by Pavel Hrdina
parent 894f3e0e57
commit 4b2998432a
3 changed files with 33 additions and 10 deletions

View File

@ -11968,6 +11968,36 @@ qemuDomainAdjustMaxMemLock(virDomainObjPtr vm)
return ret;
}
/**
* qemuDomainAdjustMaxMemLockHostdev:
* @vm: domain
* @hostdev: device
*
* Temporarily add the hostdev to the domain definition. This is needed
* because qemuDomainAdjustMaxMemLock() requires the hostdev to be already
* part of the domain definition, but other functions like
* qemuAssignDeviceHostdevAlias() expect it *not* to be there.
* A better way to handle this would be nice
*
* Returns: 0 on success, <0 on failure
*/
int
qemuDomainAdjustMaxMemLockHostdev(virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev)
{
int ret = 0;
vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
if (qemuDomainAdjustMaxMemLock(vm) < 0)
ret = -1;
vm->def->hostdevs[--(vm->def->nhostdevs)] = NULL;
return ret;
}
/**
* qemuDomainHasVcpuPids:
* @vm: Domain object

View File

@ -952,6 +952,8 @@ void qemuDomainUpdateCurrentMemorySize(virDomainObjPtr vm);
unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def);
int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm);
int qemuDomainAdjustMaxMemLockHostdev(virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev);
int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
virQEMUCapsPtr qemuCaps,

View File

@ -1621,17 +1621,8 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
break;
}
/* Temporarily add the hostdev to the domain definition. This is needed
* because qemuDomainAdjustMaxMemLock() requires the hostdev to be already
* part of the domain definition, but other functions like
* qemuAssignDeviceHostdevAlias() used below expect it *not* to be there.
* A better way to handle this would be nice */
vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
if (qemuDomainAdjustMaxMemLock(vm) < 0) {
vm->def->hostdevs[--(vm->def->nhostdevs)] = NULL;
if (qemuDomainAdjustMaxMemLockHostdev(vm, hostdev) < 0)
goto error;
}
vm->def->hostdevs[--(vm->def->nhostdevs)] = NULL;
if (qemuDomainNamespaceSetupHostdev(vm, hostdev) < 0)
goto error;