[PATCH v4 7/8] qemu: Implement the driver methods

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* 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
---
 src/qemu/qemu_driver.c       |   90 +++++++++++++++++++++++++++++++++++++++++-
 src/qemu/qemu_monitor.c      |   20 +++++++++
 src/qemu/qemu_monitor.h      |    3 +
 src/qemu/qemu_monitor_json.c |   23 +++++++++++
 src/qemu/qemu_monitor_json.h |    5 ++
 src/qemu/qemu_monitor_text.c |   31 ++++++++++++++
 src/qemu/qemu_monitor_text.h |    3 +
 7 files changed, 174 insertions(+), 1 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 482f177..c0cd407 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -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; charset=binary");
+
+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 */
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index f031514..421a81e 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -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;
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index b84e230..ee3e14d 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -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
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 047a81f..32da893 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -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;
+}
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index f2dc4d2..3158882 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -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 */
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 1d90c1b..b83809c 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -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;
+}
diff --git a/src/qemu/qemu_monitor_text.h b/src/qemu/qemu_monitor_text.h
index dbae72b..1ee1179 100644
--- a/src/qemu/qemu_monitor_text.h
+++ b/src/qemu/qemu_monitor_text.h
@@ -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 */
-- 
1.7.5.rc3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]