[libvirt RFCv11 10/33] tools: prepare cmdRestore to use parameters

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

 



Signed-off-by: Claudio Fontana <cfontana@xxxxxxx>
---
 tools/virsh-domain.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 120d0ef5f0..a3f007a1d2 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5316,15 +5316,21 @@ static bool
 cmdRestore(vshControl *ctl, const vshCmd *cmd)
 {
     const char *from = NULL;
+    virTypedParameterPtr params = NULL;
+    int nparams = 0;
+    int maxparams = 0;
     unsigned int flags = 0;
     const char *xmlfile = NULL;
     g_autofree char *xml = NULL;
     virshControl *priv = ctl->privData;
-    int rc;
-
-    if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
-        return false;
+    int rc = -1;
 
+    if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) {
+        goto out;
+    } else if (virTypedParamsAddString(&params, &nparams, &maxparams,
+                                       VIR_DOMAIN_SAVE_PARAM_FILE, from) < 0) {
+        goto out;
+    }
     if (vshCommandOptBool(cmd, "bypass-cache"))
         flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE;
     if (vshCommandOptBool(cmd, "running"))
@@ -5335,11 +5341,15 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd)
         flags |= VIR_DOMAIN_SAVE_RESET_NVRAM;
 
     if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0)
-        return false;
+        goto out;
 
-    if (xmlfile &&
-        virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0)
-        return false;
+    if (xmlfile) {
+        if (virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0)
+            goto out;
+        else if (virTypedParamsAddString(&params, &nparams, &maxparams,
+                                         VIR_DOMAIN_SAVE_PARAM_DXML, xml) < 0)
+            goto out;
+    }
 
     if (flags || xml) {
         rc = virDomainRestoreFlags(priv->conn, from, xml, flags);
@@ -5349,11 +5359,13 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd)
 
     if (rc < 0) {
         vshError(ctl, _("Failed to restore domain from %s"), from);
-        return false;
+        goto out;
     }
 
     vshPrintExtra(ctl, _("Domain restored from %s\n"), from);
-    return true;
+ out:
+    virTypedParamsFree(params, nparams);
+    return rc >= 0;
 }
 
 /*
-- 
2.26.2





[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]

  Powered by Linux