mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +00:00
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 <source> 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 <xuhj@linux.vnet.ibm.com> Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
ab4823a062
commit
2d764cb472
@ -11569,7 +11569,8 @@ static const vshCmdInfo info_attach_disk[] = {
|
|||||||
|
|
||||||
static const vshCmdOptDef opts_attach_disk[] = {
|
static const vshCmdOptDef opts_attach_disk[] = {
|
||||||
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
|
{"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")},
|
{"target", VSH_OT_DATA, VSH_OFLAG_REQ, N_("target of disk device")},
|
||||||
{"driver", VSH_OT_STRING, 0, N_("driver of disk device")},
|
{"driver", VSH_OT_STRING, 0, N_("driver of disk device")},
|
||||||
{"subdriver", VSH_OT_STRING, 0, N_("subdriver 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)
|
if (vshCommandOptString(cmd, "source", &source) <= 0)
|
||||||
goto cleanup;
|
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)
|
if (vshCommandOptString(cmd, "target", &target) <= 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -11808,9 +11813,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (driver || subdriver || cache)
|
if (driver || subdriver || cache)
|
||||||
virBufferAddLit(&buf, "/>\n");
|
virBufferAddLit(&buf, "/>\n");
|
||||||
|
|
||||||
virBufferAsprintf(&buf, " <source %s='%s'/>\n",
|
if (source)
|
||||||
(isFile) ? "file" : "dev",
|
virBufferAsprintf(&buf, " <source %s='%s'/>\n",
|
||||||
source);
|
(isFile) ? "file" : "dev",
|
||||||
|
source);
|
||||||
virBufferAsprintf(&buf, " <target dev='%s'/>\n", target);
|
virBufferAsprintf(&buf, " <target dev='%s'/>\n", target);
|
||||||
if (mode)
|
if (mode)
|
||||||
virBufferAsprintf(&buf, " <%s/>\n", mode);
|
virBufferAsprintf(&buf, " <%s/>\n", mode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user