]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: monitor: Refactor error handling for 'savevm'
authorPeter Krempa <pkrempa@redhat.com>
Fri, 15 Jan 2016 11:53:30 +0000 (12:53 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 25 Jan 2016 06:21:25 +0000 (07:21 +0100)
Unify few error conditions into a single error reporting case.

src/qemu/qemu_monitor_text.c

index 316a942aea972928632125c88f73d73ffc69a8a2..0801f84eac29153fb198f29bb8afefabaf8f678f 100644 (file)
@@ -2640,7 +2640,10 @@ int qemuMonitorTextSetDrivePassphrase(qemuMonitorPtr mon,
     return ret;
 }
 
-int qemuMonitorTextCreateSnapshot(qemuMonitorPtr mon, const char *name)
+
+int
+qemuMonitorTextCreateSnapshot(qemuMonitorPtr mon,
+                              const char *name)
 {
     char *cmd = NULL;
     char *reply = NULL;
@@ -2654,21 +2657,16 @@ int qemuMonitorTextCreateSnapshot(qemuMonitorPtr mon, const char *name)
     if (qemuMonitorHMPCommand(mon, cmd, &reply))
         goto cleanup;
 
-    if (strstr(reply, "Error while creating snapshot") != NULL) {
+    if (strstr(reply, "Error while creating snapshot") ||
+        strstr(reply, "Could not open VM state file") ||
+        (strstr(reply, "Error") && strstr(reply, "while writing VM"))) {
         virReportError(VIR_ERR_OPERATION_FAILED,
                        _("Failed to take snapshot: %s"), reply);
         goto cleanup;
-    } else if (strstr(reply, "No block device can accept snapshots") != NULL) {
+    } else if (strstr(reply, "No block device can accept snapshots")) {
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                        _("this domain does not have a device to take snapshots"));
         goto cleanup;
-    } else if (strstr(reply, "Could not open VM state file") != NULL) {
-        virReportError(VIR_ERR_OPERATION_FAILED, "%s", reply);
-        goto cleanup;
-    } else if (strstr(reply, "Error") != NULL
-             && strstr(reply, "while writing VM") != NULL) {
-        virReportError(VIR_ERR_OPERATION_FAILED, "%s", reply);
-        goto cleanup;
     }
 
     ret = 0;