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

Re: [libvirt] [PATCH 14/17] virsh-snapshot: Refactor cmdSnapshotDumpXML



On 2013年01月22日 02:07, Peter Krempa wrote:
This patch simplifies error paths and switches to use
vshCommandOptStringReq for argument retrieval in cmdSnapshotDumpXML
---
  tools/virsh-snapshot.c | 19 +++++++------------
  1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index f76c40e..c980b5b 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -1775,31 +1775,26 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd)
      if (vshCommandOptBool(cmd, "security-info"))
          flags |= VIR_DOMAIN_XML_SECURE;

-    dom = vshCommandOptDomain(ctl, cmd, NULL);
-    if (dom == NULL)
-        goto cleanup;
+    if (vshCommandOptStringReq(ctl, cmd, "snapshotname",&name)<  0)
+        return false;

-    if (vshCommandOptString(cmd, "snapshotname",&name)<= 0)
-        goto cleanup;
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        return false;

-    snapshot = virDomainSnapshotLookupByName(dom, name, 0);
-    if (snapshot == NULL)
+    if (!(snapshot = virDomainSnapshotLookupByName(dom, name, 0)))
          goto cleanup;

-    xml = virDomainSnapshotGetXMLDesc(snapshot, flags);
-    if (!xml)
+    if (!(xml = virDomainSnapshotGetXMLDesc(snapshot, flags)))
          goto cleanup;

      vshPrint(ctl, "%s", xml);
-
      ret = true;

  cleanup:
      VIR_FREE(xml);
      if (snapshot)
          virDomainSnapshotFree(snapshot);
-    if (dom)
-        virDomainFree(dom);
+    virDomainFree(dom);

      return ret;
  }

ACK


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