1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

Add monitor API for checking whether KVM is enabled

When attaching to an external QEMU process, it is neccessary
to check if the process is using KVM or not. This can be done
using a monitor command

* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
  src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
  src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h: Add
  API for checking if KVM is enabled
This commit is contained in:
Daniel P. Berrange 2011-06-17 15:31:45 +01:00
parent 80a4ee4695
commit 7760eaa050
6 changed files with 95 additions and 0 deletions

View File

@ -1122,6 +1122,27 @@ int qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
return ret;
}
int qemuMonitorGetVirtType(qemuMonitorPtr mon,
int *virtType)
{
int ret;
VIR_DEBUG("mon=%p", mon);
if (!mon) {
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
_("monitor must not be NULL"));
return -1;
}
if (mon->json)
ret = qemuMonitorJSONGetVirtType(mon, virtType);
else
ret = qemuMonitorTextGetVirtType(mon, virtType);
return ret;
}
int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
unsigned long *currmem)
{

View File

@ -191,6 +191,8 @@ int qemuMonitorSystemPowerdown(qemuMonitorPtr mon);
int qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
int **pids);
int qemuMonitorGetVirtType(qemuMonitorPtr mon,
int *virtType);
int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
unsigned long *currmem);
int qemuMonitorGetMemoryStats(qemuMonitorPtr mon,

View File

@ -1042,6 +1042,52 @@ int qemuMonitorJSONGetCPUInfo(qemuMonitorPtr mon,
}
int qemuMonitorJSONGetVirtType(qemuMonitorPtr mon,
int *virtType)
{
int ret;
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-kvm",
NULL);
virJSONValuePtr reply = NULL;
*virtType = VIR_DOMAIN_VIRT_QEMU;
if (!cmd)
return -1;
ret = qemuMonitorJSONCommand(mon, cmd, &reply);
if (ret == 0)
ret = qemuMonitorJSONCheckError(cmd, reply);
if (ret == 0) {
virJSONValuePtr data;
bool val = false;
if (!(data = virJSONValueObjectGet(reply, "return"))) {
qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("info kvm reply was missing return data"));
ret = -1;
goto cleanup;
}
if (virJSONValueObjectGetBoolean(data, "enabled", &val) < 0) {
qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("info kvm reply missing 'running' field"));
ret = -1;
goto cleanup;
}
if (val)
*virtType = VIR_DOMAIN_VIRT_KVM;
}
cleanup:
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
}
/*
* Returns: 0 if balloon not supported, +1 if balloon query worked
* or -1 on failure

View File

@ -53,6 +53,8 @@ int qemuMonitorJSONSystemReset(qemuMonitorPtr mon);
int qemuMonitorJSONGetCPUInfo(qemuMonitorPtr mon,
int **pids);
int qemuMonitorJSONGetVirtType(qemuMonitorPtr mon,
int *virtType);
int qemuMonitorJSONGetBalloonInfo(qemuMonitorPtr mon,
unsigned long *currmem);
int qemuMonitorJSONGetMemoryStats(qemuMonitorPtr mon,

View File

@ -512,6 +512,28 @@ error:
return 0;
}
int qemuMonitorTextGetVirtType(qemuMonitorPtr mon,
int *virtType)
{
char *reply = NULL;
*virtType = VIR_DOMAIN_VIRT_QEMU;
if (qemuMonitorHMPCommand(mon, "info kvm", &reply) < 0) {
qemuReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("could not query kvm status"));
return -1;
}
if (strstr(reply, "enabled"))
*virtType = VIR_DOMAIN_VIRT_KVM;
VIR_FREE(reply);
return 0;
}
static int parseMemoryStat(char **text, unsigned int tag,
const char *search, virDomainMemoryStatPtr stat)
{

View File

@ -50,6 +50,8 @@ int qemuMonitorTextSystemReset(qemuMonitorPtr mon);
int qemuMonitorTextGetCPUInfo(qemuMonitorPtr mon,
int **pids);
int qemuMonitorTextGetVirtType(qemuMonitorPtr mon,
int *virtType);
int qemuMonitorTextGetBalloonInfo(qemuMonitorPtr mon,
unsigned long *currmem);
int qemuMonitorTextGetMemoryStats(qemuMonitorPtr mon,