提交 4b299843 编写于 作者: E Eric Farman 提交者: Pavel Hrdina

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: NEric Farman <farman@linux.ibm.com>
Reviewed-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: NPavel Hrdina <phrdina@redhat.com>
上级 894f3e0e
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册