From 4ef5b6a388a9cf0088fc385c3360e83650ac6f5f Mon Sep 17 00:00:00 2001 Message-Id: <4ef5b6a388a9cf0088fc385c3360e83650ac6f5f.1389183250.git.jdenemar@redhat.com> From: Chen Hanxiao Date: Wed, 8 Jan 2014 10:47:21 +0100 Subject: [PATCH] virsh: improve usability of '--print-xml' flag for attach-disk command https://bugzilla.redhat.com/show_bug.cgi?id=1049529 '--print-xml' option is very useful for doing some test. But we had to specify a real domain for it. This patch could enable us to specify a fake domain when using --print-xml option. Signed-off-by: Chen Hanxiao Signed-off-by: Eric Blake (cherry picked from commit 21f2d80b0cdf30fe3a6c942f9d7d6b17cb73ec66) Signed-off-by: Jiri Denemark --- tools/virsh-domain.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 3895f39..b017ec3 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -528,13 +528,6 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) if (live) flags |= VIR_DOMAIN_AFFECT_LIVE; - if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) - return false; - - if (persistent && - virDomainIsActive(dom) == 1) - flags |= VIR_DOMAIN_AFFECT_LIVE; - if (vshCommandOptStringReq(ctl, cmd, "source", &source) < 0 || vshCommandOptStringReq(ctl, cmd, "target", &target) < 0 || vshCommandOptStringReq(ctl, cmd, "driver", &driver) < 0 || @@ -672,6 +665,13 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) goto cleanup; } + if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) + goto cleanup; + + if (persistent && + virDomainIsActive(dom) == 1) + flags |= VIR_DOMAIN_AFFECT_LIVE; + if (flags) ret = virDomainAttachDeviceFlags(dom, xml, flags); else @@ -686,7 +686,8 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(xml); - virDomainFree(dom); + if (dom) + virDomainFree(dom); virBufferFreeAndReset(&buf); return functionReturn; } -- 1.8.5.2