
On Mon, May 29, 2017 at 14:08:53 -0400, Daniel Liu wrote:
The option allows someone to run domain-to-native on already existing domain without the need of supplying their XML. It is basically wrapper around 'virsh dumpxml | virsh domxml-to-native /dev/stdin'. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=835476 --- tools/virsh-domain.c | 52 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 12 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index ccb514ef9..929f9c896 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c
[...]
@@ -9859,30 +9863,54 @@ static const vshCmdOptDef opts_domxmltonative[] = { static bool cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd) { - bool ret = true; + bool ret = false; const char *format = NULL; - const char *xmlFile = NULL; - char *configData; - char *xmlData; + const char *domain = NULL; + const char *xml = NULL; + char *xmlData = NULL; + char *configData = NULL; unsigned int flags = 0; virshControlPtr priv = ctl->privData; + virDomainPtr dom = NULL;
if (vshCommandOptStringReq(ctl, cmd, "format", &format) < 0 || - vshCommandOptStringReq(ctl, cmd, "xml", &xmlFile) < 0) + vshCommandOptStringReq(ctl, cmd, "xml", &xml) < 0 || + vshCommandOptStringReq(ctl, cmd, "domain", &domain) < 0)
You don't need this variable after the check below, so it's pointless to extract it.
return false;
- if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &xmlData) < 0) + VSH_EXCLUSIVE_OPTIONS_VAR(domain, xml);
This macro is documented to work only on booleans, please don't use it on pointers.
+ + if (domain) { + if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) + return false; + } + + if (dom) { + xmlData = virDomainGetXMLDesc(dom, flags); + } else if (xml) { + if (virFileReadAll(xml, VSH_MAX_XML_FILE, &xmlData) < 0) + goto cleanup; + } + + if (!xmlData) { + vshError(ctl, "%s", + _("need either domain (ID, UUID, or name) or domain XML configuration file path"));
This line is very long.
return false;
You'll leak 'dom' here if it was looked up, but getting of the XML failed. Also the message is kind of wrong in that case, since you've provided a valid name, but the XML could not be requested
+ }
- configData = virConnectDomainXMLToNative(priv->conn, format, xmlData, flags); - if (configData != NULL) { - vshPrint(ctl, "%s", configData); - VIR_FREE(configData); + if (!(configData = virConnectDomainXMLToNative(priv->conn, format, xmlData, flags))) { + vshError(ctl, "%s", + _("convert from domain XML to native command failed"));
For 'xen' the output is not really a command, so this message also is not very good.
+ goto cleanup; } else { - ret = false; + vshPrint(ctl, "%s", configData); + ret = true;