{
struct qemud_driver *driver = dom->conn->privateData;
virDomainObjPtr vm;
- char cmd[256], *info = NULL;
char *tmp = NULL;
int fd = -1, ret = -1;
goto cleanup;
}
- if (flags == VIR_MEMORY_VIRTUAL)
- /* Issue the memsave command. */
- snprintf (cmd, sizeof cmd, "memsave %llu %zi \"%s\"", offset, size, tmp);
- else
- /* Issue the pmemsave command. */
- snprintf (cmd, sizeof cmd, "pmemsave %llu %zi \"%s\"", offset, size, tmp);
-
- if (qemudMonitorCommand (vm, cmd, &info) < 0) {
- qemudReportError (dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
- "%s", _("'memsave' command failed"));
- goto cleanup;
+ if (flags == VIR_MEMORY_VIRTUAL) {
+ if (qemuMonitorSaveVirtualMemory(vm, offset, size, tmp) < 0)
+ goto cleanup;
+ } else {
+ if (qemuMonitorSavePhysicalMemory(vm, offset, size, tmp) < 0)
+ goto cleanup;
}
- DEBUG ("%s: (p)memsave reply: %s", vm->def->name, info);
-
/* Read the memory file into buffer. */
if (saferead (fd, buffer, size) == (ssize_t) -1) {
virReportSystemError (dom->conn, errno,
cleanup:
VIR_FREE(tmp);
- VIR_FREE(info);
if (fd >= 0) close (fd);
unlink (tmp);
if (vm)
return ret;
}
+static int qemuMonitorSaveMemory(const virDomainObjPtr vm,
+ const char *cmdtype,
+ unsigned long long offset,
+ size_t length,
+ const char *path)
+{
+ char *cmd = NULL;
+ char *reply = NULL;
+ char *safepath = NULL;
+ int ret = -1;
+
+ if (!(safepath = qemudEscapeMonitorArg(path))) {
+ virReportOOMError(NULL);
+ goto cleanup;
+ }
+
+ if (virAsprintf(&cmd, "%s %llu %zi \"%s\"", cmdtype, offset, length, safepath) < 0) {
+ virReportOOMError(NULL);
+ goto cleanup;
+ }
+
+ if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
+ qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
+ _("could save memory region to '%s'"), path);
+ goto cleanup;
+ }
+
+ /* XXX what is printed on failure ? */
+
+ ret = 0;
+
+cleanup:
+ VIR_FREE(cmd);
+ VIR_FREE(reply);
+ VIR_FREE(safepath);
+ return ret;
+}
+
+
+int qemuMonitorSaveVirtualMemory(const virDomainObjPtr vm,
+ unsigned long long offset,
+ size_t length,
+ const char *path)
+{
+ return qemuMonitorSaveMemory(vm, "memsave", offset, length, path);
+}
+
+int qemuMonitorSavePhysicalMemory(const virDomainObjPtr vm,
+ unsigned long long offset,
+ size_t length,
+ const char *path)
+{
+ return qemuMonitorSaveMemory(vm, "pmemsave", offset, length, path);
+}
const char *devname,
const char *newmedia);
+
+int qemuMonitorSaveVirtualMemory(const virDomainObjPtr vm,
+ unsigned long long offset,
+ size_t length,
+ const char *path);
+int qemuMonitorSavePhysicalMemory(const virDomainObjPtr vm,
+ unsigned long long offset,
+ size_t length,
+ const char *path);
+
#endif /* QEMU_MONITOR_TEXT_H */