mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
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:
parent
894f3e0e57
commit
4b2998432a
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user