Signed-off-by: Claudio Fontana <cfontana(a)suse.de>
---
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 a3b0749fa9..2d90fba9b7 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(¶ms, &nparams, &maxparams,
+ VIR_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(¶ms, &nparams, &maxparams,
+ VIR_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.35.3