From: Xu He Jie Date: Tue, 8 Nov 2011 07:16:34 +0000 (+0800) Subject: virsh: Add VSH_OFLAG_EMPTY_OK for attach-disk command X-Git-Tag: v0.9.8-rc1~231 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d764cb4724cf03b95a53f5f44a80939fb16bc47;p=thirdparty%2Flibvirt.git virsh: Add VSH_OFLAG_EMPTY_OK for attach-disk command As the description of removing CDROM media from http://wiki.libvirt.org/page/QEMUSwitchToLibvirt#eject_DEV Add flag 'VSH_OFLAG_EMPTY_OK' to the option 'source' of attach-disk Then avoid outputting in the XML if 'source' was empty, rather than trusting libvirt domain_conf.c to understand an empty string. Signed-off-by: Xu He Jie Signed-off-by: Eric Blake --- diff --git a/tools/virsh.c b/tools/virsh.c index 5544a41165..eed727b8f1 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -11569,7 +11569,8 @@ static const vshCmdInfo info_attach_disk[] = { static const vshCmdOptDef opts_attach_disk[] = { {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, - {"source", VSH_OT_DATA, VSH_OFLAG_REQ, N_("source of disk device")}, + {"source", VSH_OT_DATA, VSH_OFLAG_REQ | VSH_OFLAG_EMPTY_OK, + N_("source of disk device")}, {"target", VSH_OT_DATA, VSH_OFLAG_REQ, N_("target of disk device")}, {"driver", VSH_OT_STRING, 0, N_("driver of disk device")}, {"subdriver", VSH_OT_STRING, 0, N_("subdriver of disk device")}, @@ -11754,6 +11755,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "source", &source) <= 0) goto cleanup; + /* Allow empty string as a placeholder that implies no source, for + * use in adding a cdrom drive with no disk. */ + if (!*source) + source = NULL; if (vshCommandOptString(cmd, "target", &target) <= 0) goto cleanup; @@ -11808,9 +11813,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) if (driver || subdriver || cache) virBufferAddLit(&buf, "/>\n"); - virBufferAsprintf(&buf, " \n", - (isFile) ? "file" : "dev", - source); + if (source) + virBufferAsprintf(&buf, " \n", + (isFile) ? "file" : "dev", + source); virBufferAsprintf(&buf, " \n", target); if (mode) virBufferAsprintf(&buf, " <%s/>\n", mode);