提交 e7093b39 编写于 作者: P Pavel Hrdina

qemu_monitor: search memballoon QOM device path using alias

Commit 4a585a88 introduced searching QOM device path by alias, let's use it for
memballoon too.  This may speedup the search because in most cases we will find
the correct QOM device path directly by using alias without the need for the
recursion code.
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 4a585a88
......@@ -2455,7 +2455,7 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period,
}
qemuDomainObjEnterMonitor(driver, vm);
r = qemuMonitorSetMemoryStatsPeriod(priv->mon, period);
r = qemuMonitorSetMemoryStatsPeriod(priv->mon, def->memballoon, period);
if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto endjob;
if (r < 0) {
......@@ -11003,7 +11003,8 @@ qemuDomainMemoryStats(virDomainPtr dom,
if (vm->def->memballoon &&
vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) {
qemuDomainObjEnterMonitor(driver, vm);
ret = qemuMonitorGetMemoryStats(qemuDomainGetMonitor(vm), stats, nr_stats);
ret = qemuMonitorGetMemoryStats(qemuDomainGetMonitor(vm),
vm->def->memballoon, stats, nr_stats);
if (qemuDomainObjExitMonitor(driver, vm) < 0)
ret = -1;
......
......@@ -1068,11 +1068,12 @@ qemuMonitorSetOptions(qemuMonitorPtr mon, virJSONValuePtr options)
* This feature was added to QEMU 1.5.
*/
static void
qemuMonitorInitBalloonObjectPath(qemuMonitorPtr mon)
qemuMonitorInitBalloonObjectPath(qemuMonitorPtr mon,
virDomainMemballoonDefPtr balloon)
{
ssize_t i, nprops = 0;
int flp_ret = 0;
char *path = NULL;
const char *name;
qemuMonitorJSONListPathPtr *bprops = NULL;
if (mon->balloonpath) {
......@@ -1084,16 +1085,20 @@ qemuMonitorInitBalloonObjectPath(qemuMonitorPtr mon)
}
mon->ballooninit = true;
flp_ret = qemuMonitorJSONFindLinkPath(mon, "virtio-balloon-pci", NULL, &path);
if (flp_ret == -2) {
/* pci object was not found retry search for ccw object */
if (qemuMonitorJSONFindLinkPath(mon, "virtio-balloon-ccw",
NULL, &path) < 0)
return;
} else if (flp_ret < 0) {
switch (balloon->info.type) {
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
name = "virtio-balloon-pci";
break;
case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
name = "virtio-balloon-ccw";
break;
default:
return;
}
if (qemuMonitorJSONFindLinkPath(mon, name, balloon->info.alias, &path) < 0)
return;
nprops = qemuMonitorJSONGetObjectListPaths(mon, path, &bprops);
if (nprops < 0)
goto cleanup;
......@@ -1718,6 +1723,7 @@ qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
int
qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
virDomainMemballoonDefPtr balloon,
virDomainMemoryStatPtr stats,
unsigned int nr_stats)
{
......@@ -1726,7 +1732,7 @@ qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
QEMU_CHECK_MONITOR(mon);
if (mon->json) {
qemuMonitorInitBalloonObjectPath(mon);
qemuMonitorInitBalloonObjectPath(mon, balloon);
return qemuMonitorJSONGetMemoryStats(mon, mon->balloonpath,
stats, nr_stats);
} else {
......@@ -1744,6 +1750,7 @@ qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
*/
int
qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
virDomainMemballoonDefPtr balloon,
int period)
{
int ret = -1;
......@@ -1758,7 +1765,7 @@ qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
if (period < 0)
return -1;
qemuMonitorInitBalloonObjectPath(mon);
qemuMonitorInitBalloonObjectPath(mon, balloon);
if (mon->balloonpath) {
ret = qemuMonitorJSONSetMemoryStatsPeriod(mon, mon->balloonpath,
period);
......
......@@ -397,9 +397,11 @@ int qemuMonitorGetVirtType(qemuMonitorPtr mon,
int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
unsigned long long *currmem);
int qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
virDomainMemballoonDefPtr balloon,
virDomainMemoryStatPtr stats,
unsigned int nr_stats);
int qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
virDomainMemballoonDefPtr balloon,
int period);
int qemuMonitorBlockIOStatusToError(const char *status);
......
......@@ -4268,19 +4268,17 @@ qemuProcessSetupBalloon(virQEMUDriverPtr driver,
{
unsigned long long balloon = vm->def->mem.cur_balloon;
qemuDomainObjPrivatePtr priv = vm->privateData;
int period;
int ret = -1;
if (!virDomainDefHasMemballoon(vm->def))
return 0;
period = vm->def->memballoon->period;
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
goto cleanup;
if (period)
qemuMonitorSetMemoryStatsPeriod(priv->mon, period);
if (vm->def->memballoon->period)
qemuMonitorSetMemoryStatsPeriod(priv->mon, vm->def->memballoon,
vm->def->memballoon->period);
if (qemuMonitorSetBalloon(priv->mon, balloon) < 0)
goto cleanup;
......@@ -6022,7 +6020,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO &&
vm->def->memballoon->period) {
qemuDomainObjEnterMonitor(driver, vm);
qemuMonitorSetMemoryStatsPeriod(priv->mon,
qemuMonitorSetMemoryStatsPeriod(priv->mon, vm->def->memballoon,
vm->def->memballoon->period);
if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto error;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册