[libvirt] [PATCH 5/8] Add additional error reporting to virsh.

Chris Lalancette clalance at redhat.com
Thu Jul 8 19:59:08 UTC 2010


With the change to make vshError() responsible for printing
all errors, there were some places in the code that would no
longer properly print errors.  The good news is that the vast
majority of virsh was already printing errors, so this patch
just cleans up the rest of the users to make them consistent.

Signed-off-by: Chris Lalancette <clalance at redhat.com>
---
 tools/virsh.c |  228 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 174 insertions(+), 54 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 015d038..3c48eee 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -638,18 +638,24 @@ cmdRunConsole(vshControl *ctl, virDomainPtr dom)
     }
 
     doc = virDomainGetXMLDesc(dom, 0);
-    if (!doc)
+    if (!doc) {
+        vshError(ctl, "%s", _("Failed to get the domain XML"));
         goto cleanup;
+    }
 
     xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL,
                      XML_PARSE_NOENT | XML_PARSE_NONET |
                      XML_PARSE_NOWARNING);
     VIR_FREE(doc);
-    if (!xml)
+    if (!xml) {
+        vshError(ctl, "%s", _("Failed to parse the domain XML"));
         goto cleanup;
+    }
     ctxt = xmlXPathNewContext(xml);
-    if (!ctxt)
+    if (!ctxt) {
+        vshError(ctl, "%s", _("Failed to allocate memory"));
         goto cleanup;
+    }
 
     tty = virXPathString("string(/domain/devices/console/@tty)", ctxt);
     if (tty) {
@@ -838,8 +844,10 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd)
     if (virDomainGetInfo(dom, &info) == 0)
         vshPrint(ctl, "%s\n",
                  _(vshDomainStateToString(info.state)));
-    else
+    else {
+        vshError(ctl, "%s", _("Failed to get domain info"));
         ret = FALSE;
+    }
 
     virDomainFree(dom);
     return ret;
@@ -1057,6 +1065,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
     }
 
     if (virDomainGetBlockInfo(dom, device, &info, 0) < 0) {
+        vshError(ctl, _("Failed to get block info for device '%s'"), device);
         virDomainFree(dom);
         return FALSE;
     }
@@ -1614,8 +1623,10 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
 
         memset(params, 0, sizeof(virSchedParameter)* nparams);
         ret = virDomainGetSchedulerParameters(dom, params, &nparams);
-        if (ret == -1)
+        if (ret == -1) {
+            vshError(ctl, "%s", _("Failed to get scheduler parameters"));
             goto cleanup;
+        }
 
         /* See if any params are being set */
         for (i = 0; i < nparams; i++){
@@ -1630,12 +1641,16 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
         /* Update parameters & refresh data */
         if (update) {
             ret = virDomainSetSchedulerParameters(dom, params, nparams);
-            if (ret == -1)
+            if (ret == -1) {
+                vshError(ctl, "%s", _("Failed to set scheduler parameters"));
                 goto cleanup;
+            }
 
             ret = virDomainGetSchedulerParameters(dom, params, &nparams);
-            if (ret == -1)
+            if (ret == -1) {
+                vshError(ctl, "%s", _("Failed to update scheduler parameters"));
                 goto cleanup;
+            }
         } else {
             /* See if we've tried to --set var=val.  If so, the fact that
                we reach this point (with update == 0) means that "var" did
@@ -1993,6 +2008,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
                  info.memory);
 
     } else {
+        vshError(ctl, "%s", _("Failed to get domain info"));
         ret = FALSE;
     }
 
@@ -2014,6 +2030,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
     memset(&secmodel, 0, sizeof secmodel);
     if (virNodeGetSecurityModel(ctl->conn, &secmodel) == -1) {
         if (last_error->code != VIR_ERR_NO_SUPPORT) {
+            vshError(ctl, "%s", _("Failed to get security model"));
             virDomainFree(dom);
             return FALSE;
         }
@@ -2026,6 +2043,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
             /* Security labels are only valid for active domains */
             memset(&seclabel, 0, sizeof seclabel);
             if (virDomainGetSecurityLabel(dom, &seclabel) == -1) {
+                vshError(ctl, "%s", _("Failed to get domain security label"));
                 virDomainFree(dom);
                 return FALSE;
             } else {
@@ -2115,6 +2133,7 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
             vshPrint(ctl, "%-17s %-.3lf %s\n", _("File total:"), val, unit);
         }
     } else {
+        vshError(ctl, "%s", _("Failed to get domain job info"));
         ret = FALSE;
     }
 cleanup:
@@ -2148,8 +2167,10 @@ cmdDomjobabort(vshControl *ctl, const vshCmd *cmd)
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
         return FALSE;
 
-    if (virDomainAbortJob(dom) < 0)
+    if (virDomainAbortJob(dom) < 0) {
+        vshError(ctl, "%s", _("Failed to abort domain job"));
         ret = FALSE;
+    }
 
     virDomainFree(dom);
     return ret;
@@ -2182,12 +2203,16 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
     cell = vshCommandOptInt(cmd, "cellno", &cell_given);
     if (!cell_given) {
         memory = virNodeGetFreeMemory(ctl->conn);
-        if (memory == 0)
+        if (memory == 0) {
+            vshError(ctl, "%s", _("Failed to get node free memory"));
             return FALSE;
+        }
     } else {
         ret = virNodeGetCellsFreeMemory(ctl->conn, &memory, cell, 1);
-        if (ret != 1)
+        if (ret != 1) {
+            vshError(ctl, "%s", _("Failed to get node cells free memory"));
             return FALSE;
+        }
     }
 
     if (cell == -1)
@@ -2231,11 +2256,13 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
         return FALSE;
 
     if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
+        vshError(ctl, "%s", _("Failed to get node info"));
         virDomainFree(dom);
         return FALSE;
     }
 
     if (virDomainGetInfo(dom, &info) != 0) {
+        vshError(ctl, "%s", _("Failed to get domain info"));
         virDomainFree(dom);
         return FALSE;
     }
@@ -2335,6 +2362,7 @@ cmdVcpupin(vshControl *ctl, const vshCmd *cmd)
     }
 
     if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
+        vshError(ctl, "%s", _("Failed to get node info"));
         virDomainFree(dom);
         return FALSE;
     }
@@ -2413,6 +2441,7 @@ cmdVcpupin(vshControl *ctl, const vshCmd *cmd)
     } while (cpulist);
 
     if (virDomainPinVcpu(dom, vcpu, cpumap, cpumaplen) != 0) {
+        vshError(ctl, "%s", _("Failed to pin domain vcpus"));
         ret = FALSE;
     }
 
@@ -2459,6 +2488,7 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
 
     maxcpu = virDomainGetMaxVcpus(dom);
     if (maxcpu <= 0) {
+        vshError(ctl, "%s", _("Failed to get domain maximum vcpus"));
         virDomainFree(dom);
         return FALSE;
     }
@@ -2470,6 +2500,7 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
     }
 
     if (virDomainSetVcpus(dom, count) != 0) {
+        vshError(ctl, "%s", _("Failed to set domain vcpus"));
         ret = FALSE;
     }
 
@@ -2527,6 +2558,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
     }
 
     if (virDomainSetMemory(dom, kilobytes) != 0) {
+        vshError(ctl, "%s", _("Failed to set domain memory"));
         ret = FALSE;
     }
 
@@ -2699,6 +2731,7 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%s", dump);
         VIR_FREE(dump);
     } else {
+        vshError(ctl, "%s", _("Failed to dump domain xml"));
         ret = FALSE;
     }
 
@@ -2745,6 +2778,7 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%s", xmlData);
         VIR_FREE(xmlData);
     } else {
+        vshError(ctl, "%s", _("Failed to convert native to domain xml"));
         ret = FALSE;
     }
 
@@ -2790,6 +2824,7 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%s", configData);
         VIR_FREE(configData);
     } else {
+        vshError(ctl, "%s", _("Failed to convert domain xml to native"));
         ret = FALSE;
     }
 
@@ -2986,7 +3021,10 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
         virDomainPtr ddom = NULL;
 
         dconn = virConnectOpenAuth (desturi, virConnectAuthPtrDefault, 0);
-        if (!dconn) goto done;
+        if (!dconn) {
+            vshError(ctl, _("Failed to open connection to '%s'"), desturi);
+            goto done;
+        }
 
         ddom = virDomainMigrate (dom, dconn, flags, dname, migrateuri, 0);
         if (ddom) {
@@ -3036,8 +3074,10 @@ cmdMigrateSetMaxDowntime(vshControl *ctl, const vshCmd *cmd)
         goto done;
     }
 
-    if (virDomainMigrateSetMaxDowntime(dom, downtime, 0))
+    if (virDomainMigrateSetMaxDowntime(dom, downtime, 0) < 0) {
+        vshError(ctl, "%s", _("Failed to set migration maximum downtime"));
         goto done;
+    }
 
     ret = TRUE;
 
@@ -3262,6 +3302,7 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%s", dump);
         VIR_FREE(dump);
     } else {
+        vshError(ctl, "%s", _("Failed to dumpxml for network"));
         ret = FALSE;
     }
 
@@ -3304,8 +3345,10 @@ cmdInterfaceEdit (vshControl *ctl, const vshCmd *cmd)
 
     /* Get the XML configuration of the interface. */
     doc = virInterfaceGetXMLDesc (iface, flags);
-    if (!doc)
+    if (!doc) {
+        vshError(ctl, "%s", _("Failed to get xml for interface"));
         goto cleanup;
+    }
 
     /* Create and open the temporary file. */
     tmp = editWriteToTempFile (ctl, doc);
@@ -3331,8 +3374,10 @@ cmdInterfaceEdit (vshControl *ctl, const vshCmd *cmd)
      * losing a connection or the interface going away.
      */
     doc_reread = virInterfaceGetXMLDesc (iface, flags);
-    if (!doc_reread)
+    if (!doc_reread) {
+        vshError(ctl, "%s", _("Failed to re-read interface xml"));
         goto cleanup;
+    }
 
     if (STRNEQ (doc, doc_reread)) {
         vshError(ctl, "%s",
@@ -3343,8 +3388,10 @@ cmdInterfaceEdit (vshControl *ctl, const vshCmd *cmd)
     /* Everything checks out, so redefine the interface. */
     virInterfaceFree (iface);
     iface = virInterfaceDefineXML (ctl->conn, doc_edited, 0);
-    if (!iface)
+    if (!iface) {
+        vshError(ctl, "%s", _("Failed to define new interface XML"));
         goto cleanup;
+    }
 
     vshPrint (ctl, _("Interface %s XML configuration edited.\n"),
               virInterfaceGetName(iface));
@@ -3851,6 +3898,7 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%s", dump);
         VIR_FREE(dump);
     } else {
+        vshError(ctl, "%s", _("Failed to get xml for interface"));
         ret = FALSE;
     }
 
@@ -4139,6 +4187,7 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%s", dump);
         VIR_FREE(dump);
     } else {
+        vshError(ctl, "%s", _("Failed to get nwfilter XML"));
         ret = FALSE;
     }
 
@@ -4246,8 +4295,10 @@ cmdNWFilterEdit (vshControl *ctl, const vshCmd *cmd)
 
     /* Get the XML configuration of the interface. */
     doc = virNWFilterGetXMLDesc (nwfilter, 0);
-    if (!doc)
+    if (!doc) {
+        vshError(ctl, "%s", _("Failed to get nwfilter XML"));
         goto cleanup;
+    }
 
     /* Create and open the temporary file. */
     tmp = editWriteToTempFile (ctl, doc);
@@ -4273,8 +4324,10 @@ cmdNWFilterEdit (vshControl *ctl, const vshCmd *cmd)
      * losing a connection or the interface going away.
      */
     doc_reread = virNWFilterGetXMLDesc (nwfilter, 0);
-    if (!doc_reread)
+    if (!doc_reread) {
+        vshError(ctl, "%s", _("Failed to re-read nwfilter XML"));
         goto cleanup;
+    }
 
     if (STRNEQ (doc, doc_reread)) {
         vshError(ctl, "%s",
@@ -4285,8 +4338,10 @@ cmdNWFilterEdit (vshControl *ctl, const vshCmd *cmd)
     /* Everything checks out, so redefine the interface. */
     virNWFilterFree (nwfilter);
     nwfilter = virNWFilterDefineXML (ctl->conn, doc_edited);
-    if (!nwfilter)
+    if (!nwfilter) {
+        vshError(ctl, "%s", _("Failed to define new nwfilter XML"));
         goto cleanup;
+    }
 
     vshPrint (ctl, _("Network filter %s XML configuration edited.\n"),
               virNWFilterGetName(nwfilter));
@@ -4904,6 +4959,7 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%s", dump);
         VIR_FREE(dump);
     } else {
+        vshError(ctl, "%s", _("Failed to get XML for pool"));
         ret = FALSE;
     }
 
@@ -5539,6 +5595,7 @@ cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
             vshPrint(ctl, "%-15s %2.2lf %s\n", _("Available:"), val, unit);
         }
     } else {
+        vshError(ctl, "%s", _("Failed to get pool info"));
         ret = FALSE;
     }
 
@@ -5772,7 +5829,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
     virBufferAddLit(&buf, "</volume>\n");
 
     if (virBufferError(&buf)) {
-        vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
+        vshError(ctl, "%s", _("Failed to allocate XML buffer"));
         return FALSE;
     }
     xml = virBufferContentAndReset(&buf);
@@ -6072,12 +6129,14 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
 
     origxml = virStorageVolGetXMLDesc(origvol, 0);
-    if (!origxml)
+    if (!origxml) {
+        vshError(ctl, "%s", _("Failed to get storage volume XML"));
         goto cleanup;
+    }
 
     newxml = makeCloneXML(origxml, name);
     if (!newxml) {
-        vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
+        vshError(ctl, "%s", _("Failed to allocate XML buffer"));
         goto cleanup;
     }
 
@@ -6231,6 +6290,7 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd)
         val = prettyCapacity(info.allocation, &unit);
         vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit);
     } else {
+        vshError(ctl, "%s", _("Failed to get storage volume info"));
         ret = FALSE;
     }
 
@@ -6272,6 +6332,7 @@ cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%s", dump);
         VIR_FREE(dump);
     } else {
+        vshError(ctl, "%s", _("Failed to get storage volume XML"));
         ret = FALSE;
     }
 
@@ -6591,8 +6652,10 @@ cmdSecretDumpXML(vshControl *ctl, const vshCmd *cmd)
         return FALSE;
 
     xml = virSecretGetXMLDesc(secret, 0);
-    if (xml == NULL)
+    if (xml == NULL) {
+        vshError(ctl, "%s", _("Failed to get secret XML"));
         goto cleanup;
+    }
     vshPrint(ctl, "%s", xml);
     VIR_FREE(xml);
     ret = TRUE;
@@ -6692,8 +6755,10 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
         return FALSE;
 
     value = virSecretGetValue(secret, &value_size, 0);
-    if (value == NULL)
+    if (value == NULL) {
+        vshError(ctl, "%s", _("Failed to get secret value"));
         goto cleanup;
+    }
 
     base64_encode_alloc((char *)value, value_size, &base64);
     memset(value, 0, value_size);
@@ -7101,6 +7166,7 @@ cmdNodeDeviceDumpXML (vshControl *ctl, const vshCmd *cmd)
 
     xml = virNodeDeviceGetXMLDesc(device, 0);
     if (!xml) {
+        vshError(ctl, "%s", _("Failed to get node device XML"));
         virNodeDeviceFree(device);
         return FALSE;
     }
@@ -7324,18 +7390,24 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
         return FALSE;
 
     doc = virDomainGetXMLDesc(dom, 0);
-    if (!doc)
+    if (!doc) {
+        vshError(ctl, "%s", _("Failed to get domain XML"));
         goto cleanup;
+    }
 
     xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL,
                      XML_PARSE_NOENT | XML_PARSE_NONET |
                      XML_PARSE_NOWARNING);
     VIR_FREE(doc);
-    if (!xml)
+    if (!xml) {
+        vshError(ctl, "%s", _("Failed to parse domain XML"));
         goto cleanup;
+    }
     ctxt = xmlXPathNewContext(xml);
-    if (!ctxt)
+    if (!ctxt) {
+        vshError(ctl, "%s", _("Failed to allocate memory"));
         goto cleanup;
+    }
 
     obj = xmlXPathEval(BAD_CAST "string(/domain/devices/graphics[@type='vnc']/@port)", ctxt);
     if ((obj == NULL) || (obj->type != XPATH_STRING) ||
@@ -7398,18 +7470,24 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
         return FALSE;
 
     doc = virDomainGetXMLDesc(dom, 0);
-    if (!doc)
+    if (!doc) {
+        vshError(ctl, "%s", _("Failed to get domain XML"));
         goto cleanup;
+    }
 
     xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL,
                      XML_PARSE_NOENT | XML_PARSE_NONET |
                      XML_PARSE_NOWARNING);
     VIR_FREE(doc);
-    if (!xml)
+    if (!xml) {
+        vshError(ctl, "%s", _("Failed to parse domain XML"));
         goto cleanup;
+    }
     ctxt = xmlXPathNewContext(xml);
-    if (!ctxt)
+    if (!ctxt) {
+        vshError(ctl, "%s", _("Failed to allocate memory"));
         goto cleanup;
+    }
 
     obj = xmlXPathEval(BAD_CAST "string(/domain/devices/console/@tty)", ctxt);
     if ((obj == NULL) || (obj->type != XPATH_STRING) ||
@@ -7790,20 +7868,22 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
     mac = vshCommandOptString(cmd, "mac", NULL);
 
     doc = virDomainGetXMLDesc(dom, 0);
-    if (!doc)
+    if (!doc) {
+        vshError(ctl, "%s", _("Failed to get domain XML"));
         goto cleanup;
+    }
 
     xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL,
                      XML_PARSE_NOENT | XML_PARSE_NONET |
                      XML_PARSE_NOWARNING);
     VIR_FREE(doc);
     if (!xml) {
-        vshError(ctl, "%s", _("Failed to get interface information"));
+        vshError(ctl, "%s", _("Failed to parse domain XML"));
         goto cleanup;
     }
     ctxt = xmlXPathNewContext(xml);
     if (!ctxt) {
-        vshError(ctl, "%s", _("Failed to get interface information"));
+        vshError(ctl, "%s", _("Failed to allocate memory"));
         goto cleanup;
     }
 
@@ -8072,20 +8152,22 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
 
     doc = virDomainGetXMLDesc(dom, 0);
-    if (!doc)
+    if (!doc) {
+        vshError(ctl, "%s", _("Failed to get domain XML"));
         goto cleanup;
+    }
 
     xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL,
                      XML_PARSE_NOENT | XML_PARSE_NONET |
                      XML_PARSE_NOWARNING);
     VIR_FREE(doc);
     if (!xml) {
-        vshError(ctl, "%s", _("Failed to get disk information"));
+        vshError(ctl, "%s", _("Failed to parse domain XML"));
         goto cleanup;
     }
     ctxt = xmlXPathNewContext(xml);
     if (!ctxt) {
-        vshError(ctl, "%s", _("Failed to get disk information"));
+        vshError(ctl, "%s", _("Failed to allocate memory"));
         goto cleanup;
     }
 
@@ -8569,8 +8651,10 @@ cmdEdit (vshControl *ctl, const vshCmd *cmd)
 
     /* Get the XML configuration of the domain. */
     doc = virDomainGetXMLDesc (dom, flags);
-    if (!doc)
+    if (!doc) {
+        vshError(ctl, "%s", _("Failed to get domain XML"));
         goto cleanup;
+    }
 
     /* Create and open the temporary file. */
     tmp = editWriteToTempFile (ctl, doc);
@@ -8596,8 +8680,10 @@ cmdEdit (vshControl *ctl, const vshCmd *cmd)
      * losing a connection or the domain going away.
      */
     doc_reread = virDomainGetXMLDesc (dom, flags);
-    if (!doc_reread)
+    if (!doc_reread) {
+        vshError(ctl, "%s", _("Failed to re-read domain XML"));
         goto cleanup;
+    }
 
     if (STRNEQ (doc, doc_reread)) {
         vshError(ctl,
@@ -8608,8 +8694,10 @@ cmdEdit (vshControl *ctl, const vshCmd *cmd)
     /* Everything checks out, so redefine the domain. */
     virDomainFree (dom);
     dom = virDomainDefineXML (ctl->conn, doc_edited);
-    if (!dom)
+    if (!dom) {
+        vshError(ctl, "%s", _("Failed to define new domain XML"));
         goto cleanup;
+    }
 
     vshPrint (ctl, _("Domain %s XML configuration edited.\n"),
               virDomainGetName(dom));
@@ -8731,21 +8819,29 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
     }
 
     snapshot = virDomainSnapshotCreateXML(dom, buffer, 0);
-    if (snapshot == NULL)
+    if (snapshot == NULL) {
+        vshError(ctl, "%s", _("Failed to create domain snapshot"));
         goto cleanup;
+    }
 
     doc = virDomainSnapshotGetXMLDesc(snapshot, 0);
-    if (!doc)
+    if (!doc) {
+        vshError(ctl, "%s", _("Failed to get domain snapshot XML"));
         goto cleanup;
+    }
 
     xml = xmlReadDoc((const xmlChar *) doc, "domainsnapshot.xml", NULL,
                      XML_PARSE_NOENT | XML_PARSE_NONET |
                      XML_PARSE_NOWARNING);
-    if (!xml)
+    if (!xml) {
+        vshError(ctl, "%s", _("Failed to parse domain snapshot XML"));
         goto cleanup;
+    }
     ctxt = xmlXPathNewContext(xml);
-    if (!ctxt)
+    if (!ctxt) {
+        vshError(ctl, "%s", _("Failed to allocate memory"));
         goto cleanup;
+    }
 
     name = virXPathString("string(/domainsnapshot/name)", ctxt);
     if (!name) {
@@ -8806,17 +8902,23 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
 
     current = virDomainHasCurrentSnapshot(dom, 0);
-    if (current < 0)
+    if (current < 0) {
+        vshError(ctl, "%s", _("Failed to get domain current snapshot"));
         goto cleanup;
+    }
     else if (current) {
         char *xml;
 
-        if (!(snapshot = virDomainSnapshotCurrent(dom, 0)))
+        if (!(snapshot = virDomainSnapshotCurrent(dom, 0))) {
+            vshError(ctl, "%s", _("Failed to fetch domain current snapshot"));
             goto cleanup;
+        }
 
         xml = virDomainSnapshotGetXMLDesc(snapshot, 0);
-        if (!xml)
+        if (!xml) {
+            vshError(ctl, "%s", _("Failed to get domain snapshot XML"));
             goto cleanup;
+        }
 
         vshPrint(ctl, "%s", xml);
         VIR_FREE(xml);
@@ -8874,19 +8976,25 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
 
     numsnaps = virDomainSnapshotNum(dom, 0);
 
-    if (numsnaps < 0)
+    if (numsnaps < 0) {
+        vshError(ctl, "%s", _("Failed to get number of domain snapshots"));
         goto cleanup;
+    }
 
     vshPrint(ctl, " %-20s %-25s %s\n", _("Name"), _("Creation Time"), _("State"));
     vshPrint(ctl, "---------------------------------------------------\n");
 
     if (numsnaps) {
-        if (VIR_ALLOC_N(names, numsnaps) < 0)
+        if (VIR_ALLOC_N(names, numsnaps) < 0) {
+            vshError(ctl, "%s", _("Failed to allocate memory"));
             goto cleanup;
+        }
 
         actual = virDomainSnapshotListNames(dom, names, numsnaps, 0);
-        if (actual < 0)
+        if (actual < 0) {
+            vshError(ctl, "%s", _("Failed to list domain snapshots"));
             goto cleanup;
+        }
 
         qsort(&names[0], actual, sizeof(char*), namesorter);
 
@@ -8988,12 +9096,16 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd)
     }
 
     snapshot = virDomainSnapshotLookupByName(dom, name, 0);
-    if (snapshot == NULL)
+    if (snapshot == NULL) {
+        vshError(ctl, "%s", _("Failed to lookup domain snapshot"));
         goto cleanup;
+    }
 
     xml = virDomainSnapshotGetXMLDesc(snapshot, 0);
-    if (!xml)
+    if (!xml) {
+        vshError(ctl, "%s", _("Failed to get domain snapshot XML"));
         goto cleanup;
+    }
 
     vshPrint(ctl, "%s", xml);
 
@@ -9046,11 +9158,15 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd)
     }
 
     snapshot = virDomainSnapshotLookupByName(dom, name, 0);
-    if (snapshot == NULL)
+    if (snapshot == NULL) {
+        vshError(ctl, "%s", _("Failed to lookup domain snapshot"));
         goto cleanup;
+    }
 
-    if (virDomainRevertToSnapshot(snapshot, 0) < 0)
+    if (virDomainRevertToSnapshot(snapshot, 0) < 0) {
+        vshError(ctl, "%s", _("Failed to revert to domain snapshot"));
         goto cleanup;
+    }
 
     ret = TRUE;
 
@@ -9105,11 +9221,15 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd)
         flags |= VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN;
 
     snapshot = virDomainSnapshotLookupByName(dom, name, 0);
-    if (snapshot == NULL)
+    if (snapshot == NULL) {
+        vshError(ctl, "%s", _("Failed to lookup domain snapshot"));
         goto cleanup;
+    }
 
-    if (virDomainSnapshotDelete(snapshot, flags) < 0)
+    if (virDomainSnapshotDelete(snapshot, flags) < 0) {
+        vshError(ctl, "%s", _("Failed to delete domain snapshot"));
         goto cleanup;
+    }
 
     ret = TRUE;
 
-- 
1.7.1.1




More information about the libvir-list mailing list