mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 09:17:52 +03:00
qemu: Implement the driver methods
* src/qemu/qemu_driver.c: new qemuDomainScreenshot() function * 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: Monitor command
This commit is contained in:
parent
6a1f5f568f
commit
9936aecfd1
@ -2486,6 +2486,94 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *
|
||||
qemuDomainScreenshot(virDomainPtr dom,
|
||||
virStreamPtr st,
|
||||
unsigned int screen,
|
||||
unsigned int flags ATTRIBUTE_UNUSED)
|
||||
{
|
||||
struct qemud_driver *driver = dom->conn->privateData;
|
||||
virDomainObjPtr vm;
|
||||
qemuDomainObjPrivatePtr priv;
|
||||
char *tmp = NULL;
|
||||
int tmp_fd = -1;
|
||||
char *ret = NULL;
|
||||
|
||||
qemuDriverLock(driver);
|
||||
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
||||
qemuDriverUnlock(driver);
|
||||
|
||||
if (!vm) {
|
||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
virUUIDFormat(dom->uuid, uuidstr);
|
||||
qemuReportError(VIR_ERR_NO_DOMAIN,
|
||||
_("no domain matching uuid '%s'"), uuidstr);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
priv = vm->privateData;
|
||||
|
||||
if (qemuDomainObjBeginJob(vm) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!virDomainObjIsActive(vm)) {
|
||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
||||
"%s", _("domain is not running"));
|
||||
goto endjob;
|
||||
}
|
||||
|
||||
/* Well, even if qemu allows multiple graphic cards, heads, whatever,
|
||||
* screenshot command does not */
|
||||
if (screen) {
|
||||
qemuReportError(VIR_ERR_INVALID_ARG,
|
||||
"%s", _("currently is supported only taking "
|
||||
"screenshots of screen ID 0"));
|
||||
goto endjob;
|
||||
}
|
||||
|
||||
if (virAsprintf(&tmp, "%s/qemu.screendump.XXXXXX", driver->cacheDir) < 0) {
|
||||
virReportOOMError();
|
||||
goto endjob;
|
||||
}
|
||||
|
||||
if ((tmp_fd = mkstemp(tmp)) == -1) {
|
||||
virReportSystemError(errno, _("mkstemp(\"%s\") failed"), tmp);
|
||||
goto endjob;
|
||||
}
|
||||
|
||||
qemuDomainObjEnterMonitor(vm);
|
||||
if (qemuMonitorScreendump(priv->mon, tmp) < 0) {
|
||||
qemuDomainObjExitMonitor(vm);
|
||||
goto endjob;
|
||||
}
|
||||
qemuDomainObjExitMonitor(vm);
|
||||
|
||||
if (VIR_CLOSE(tmp_fd) < 0) {
|
||||
virReportSystemError(errno, _("unable to close %s"), tmp);
|
||||
goto endjob;
|
||||
}
|
||||
|
||||
if (virFDStreamOpenFile(st, tmp, 0, 0, O_RDONLY, true) < 0) {
|
||||
qemuReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||
_("unable to open stream"));
|
||||
goto endjob;
|
||||
}
|
||||
|
||||
ret = strdup("image/x-portable-pixmap");
|
||||
|
||||
endjob:
|
||||
VIR_FORCE_CLOSE(tmp_fd);
|
||||
VIR_FREE(tmp);
|
||||
|
||||
if (qemuDomainObjEndJob(vm) == 0)
|
||||
vm = NULL;
|
||||
|
||||
cleanup:
|
||||
if (vm)
|
||||
virDomainObjUnlock(vm);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void processWatchdogEvent(void *data, void *opaque)
|
||||
{
|
||||
int ret;
|
||||
@ -7171,7 +7259,7 @@ static virDriver qemuDriver = {
|
||||
qemudDomainSave, /* domainSave */
|
||||
qemuDomainRestore, /* domainRestore */
|
||||
qemudDomainCoreDump, /* domainCoreDump */
|
||||
NULL, /* domainScreenshot */
|
||||
qemuDomainScreenshot, /* domainScreenshot */
|
||||
qemudDomainSetVcpus, /* domainSetVcpus */
|
||||
qemudDomainSetVcpusFlags, /* domainSetVcpusFlags */
|
||||
qemudDomainGetVcpusFlags, /* domainGetVcpusFlags */
|
||||
|
@ -2242,3 +2242,23 @@ int qemuMonitorInjectNMI(qemuMonitorPtr mon)
|
||||
ret = qemuMonitorTextInjectNMI(mon);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorScreendump(qemuMonitorPtr mon,
|
||||
const char *file)
|
||||
{
|
||||
int ret;
|
||||
|
||||
VIR_DEBUG("mon=%p, file=%s", mon, file);
|
||||
|
||||
if (!mon) {
|
||||
qemuReportError(VIR_ERR_INVALID_ARG,"%s",
|
||||
_("monitor must not be NULL"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mon->json)
|
||||
ret = qemuMonitorJSONScreendump(mon, file);
|
||||
else
|
||||
ret = qemuMonitorTextScreendump(mon, file);
|
||||
return ret;
|
||||
}
|
||||
|
@ -425,6 +425,9 @@ int qemuMonitorArbitraryCommand(qemuMonitorPtr mon,
|
||||
|
||||
int qemuMonitorInjectNMI(qemuMonitorPtr mon);
|
||||
|
||||
int qemuMonitorScreendump(qemuMonitorPtr mon,
|
||||
const char *file);
|
||||
|
||||
/**
|
||||
* When running two dd process and using <> redirection, we need a
|
||||
* shell that will not truncate files. These two strings serve that
|
||||
|
@ -2540,3 +2540,26 @@ cleanup:
|
||||
virJSONValueFree(reply);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorJSONScreendump(qemuMonitorPtr mon,
|
||||
const char *file)
|
||||
{
|
||||
int ret;
|
||||
virJSONValuePtr cmd, reply = NULL;
|
||||
|
||||
cmd = qemuMonitorJSONMakeCommand("screendump",
|
||||
"s:filename", file,
|
||||
NULL);
|
||||
|
||||
if (!cmd)
|
||||
return -1;
|
||||
|
||||
ret = qemuMonitorJSONCommand(mon, cmd, &reply);
|
||||
|
||||
if (ret == 0)
|
||||
ret = qemuMonitorJSONCheckError(cmd, reply);
|
||||
|
||||
virJSONValueFree(cmd);
|
||||
virJSONValueFree(reply);
|
||||
return ret;
|
||||
}
|
||||
|
@ -205,4 +205,9 @@ int qemuMonitorJSONArbitraryCommand(qemuMonitorPtr mon,
|
||||
bool hmp);
|
||||
|
||||
int qemuMonitorJSONInjectNMI(qemuMonitorPtr mon);
|
||||
|
||||
int qemuMonitorJSONScreendump(qemuMonitorPtr mon,
|
||||
const char *file);
|
||||
|
||||
|
||||
#endif /* QEMU_MONITOR_JSON_H */
|
||||
|
@ -2655,3 +2655,34 @@ fail:
|
||||
cmd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Returns -1 on error, -2 if not supported */
|
||||
int qemuMonitorTextScreendump(qemuMonitorPtr mon, const char *file)
|
||||
{
|
||||
char *cmd = NULL;
|
||||
char *reply = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (virAsprintf(&cmd, "screendump %s", file) < 0){
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) {
|
||||
qemuReportError(VIR_ERR_OPERATION_FAILED,
|
||||
"%s", _("taking screenshot failed"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (strstr(reply, "unknown command:")) {
|
||||
ret = -2;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(reply);
|
||||
VIR_FREE(cmd);
|
||||
return ret;
|
||||
}
|
||||
|
@ -199,4 +199,7 @@ int qemuMonitorTextArbitraryCommand(qemuMonitorPtr mon, const char *cmd,
|
||||
char **reply);
|
||||
|
||||
int qemuMonitorTextInjectNMI(qemuMonitorPtr mon);
|
||||
|
||||
int qemuMonitorTextScreendump(qemuMonitorPtr mon, const char *file);
|
||||
|
||||
#endif /* QEMU_MONITOR_TEXT_H */
|
||||
|
Loading…
Reference in New Issue
Block a user