[libvirt] [PATCH 0/2] Introduce two new virsh commands

These two patches is to introduce two new virsh commands, one is eject-media, which is to eject media from CD or floppy drive, the other is insert-media, which is to insert media into CD or floppy drive. There are commands existed can be used to eject/insert media, such as "update-device", but it's not quite easy to use. That's the original intention of these patches. Both of the two commands only allow to operate on CDROM or floppy disk. [PATCH 1/2] virsh: Introduce two new commands to insert or eject media [PATCH 2/2] doc: Add docs for two new introduced commands Regards Osier

eject-media: eject media from CD or floppy drive. insert-media: insert media into CD or floppy drive. NB, only support CDROM or floppy disk. --- tools/virsh.c | 367 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 367 insertions(+), 0 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index d15d206..20a29f2 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -10295,6 +10295,371 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) } /* + * "eject-media" command + */ +static const vshCmdInfo info_eject_media[] = { + {"help", N_("eject media from CD or floppy drive")}, + {"desc", N_("Eject media from CD or floppy drive.")}, + {NULL, NULL} +}; + +static const vshCmdOptDef opts_eject_media[] = { + {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, + {"target", VSH_OT_DATA, VSH_OFLAG_REQ, N_("target of disk device")}, + {"current", VSH_OT_BOOL, 0, N_("can be either or both of --live and --config, " + "depends on implementation of hypervisor driver")}, + {"live", VSH_OT_BOOL, 0, N_("alter live configuration of running domain")}, + {"config", VSH_OT_BOOL, 0, N_("alter persistent configuration, effect observed on next boot")}, + {"force", VSH_OT_BOOL, 0, N_("force media ejection")}, + {NULL, 0, 0, NULL} +}; + +static bool +cmdEjectMedia(vshControl *ctl, const vshCmd *cmd) +{ + xmlDocPtr xml = NULL; + xmlXPathObjectPtr obj=NULL; + xmlXPathContextPtr ctxt = NULL; + xmlNodePtr cur = NULL; + xmlBufferPtr xml_buf = NULL; + virDomainPtr dom = NULL; + const char *target = NULL; + char *doc; + int i = 0, diff_tgt; + int ret; + bool functionReturn = false; + int flags = 0; + int config = vshCommandOptBool(cmd, "config"); + int live = vshCommandOptBool(cmd, "live"); + int current = vshCommandOptBool(cmd, "current"); + int force = vshCommandOptBool(cmd, "force"); + bool has_source = false; + + if (current) { + if (live || config) { + vshError(ctl, "%s", _("--current must be specified exclusively")); + return false; + } + flags = VIR_DOMAIN_AFFECT_CURRENT; + } else { + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; + } + + if (force) + flags |= VIR_DOMAIN_DEVICE_MODIFY_FORCE; + + if (!vshConnectionUsability(ctl, ctl->conn)) + goto cleanup; + + if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) + goto cleanup; + + if (vshCommandOptString(cmd, "target", &target) <= 0) + goto cleanup; + + doc = virDomainGetXMLDesc(dom, 0); + if (!doc) + goto cleanup; + + xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL, + XML_PARSE_NOENT | XML_PARSE_NONET | + XML_PARSE_NOWARNING); + VIR_FREE(doc); + if (!xml) { + vshError(ctl, "%s", _("Failed to get disk information")); + goto cleanup; + } + ctxt = xmlXPathNewContext(xml); + if (!ctxt) { + vshError(ctl, "%s", _("Failed to get disk information")); + goto cleanup; + } + + obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt); + if ((obj == NULL) || (obj->type != XPATH_NODESET) || + (obj->nodesetval == NULL) || (obj->nodesetval->nodeNr == 0)) { + vshError(ctl, "%s", _("Failed to get disk information")); + goto cleanup; + } + + /* search target */ + for (; i < obj->nodesetval->nodeNr; i++) { + xmlNodePtr n = obj->nodesetval->nodeTab[i]; + bool is_supported = false; + + /* Check if the disk is CDROM or floppy disk */ + if (xmlStrEqual(n->name, BAD_CAST "disk")) { + char *device_value = virXMLPropString(n, "device"); + + if (STREQ(device_value, "cdrom") || + STREQ(device_value, "floppy")) + is_supported = true; + + VIR_FREE(device_value); + } + + cur = obj->nodesetval->nodeTab[i]->children; + while (cur != NULL) { + if (cur->type == XML_ELEMENT_NODE && + xmlStrEqual(cur->name, BAD_CAST "target")) { + char *tmp_tgt = virXMLPropString(cur, "dev"); + + diff_tgt = STREQ(tmp_tgt, target); + VIR_FREE(tmp_tgt); + + if (diff_tgt && is_supported) { + goto hit; + } + } + + cur = cur->next; + } + } + vshError(ctl, _("No found CDROM or floppy disk whose target is %s"), target); + goto cleanup; + + hit: + xml_buf = xmlBufferCreate(); + if (!xml_buf) { + vshError(ctl, "%s", _("Failed to allocate memory")); + goto cleanup; + } + + cur = obj->nodesetval->nodeTab[i]->children; + while (cur != NULL) { + if (cur->type == XML_ELEMENT_NODE && + xmlStrEqual(cur->name, BAD_CAST "source")) { + xmlUnlinkNode(cur); + xmlFreeNode(cur); + has_source = true; + break; + } + + cur = cur->next; + } + + if (!has_source) { + vshError(ctl, _("The disk device whose target is '%s' doesn't " + "have media"), target); + goto cleanup; + } + + if (xmlNodeDump(xml_buf, xml, obj->nodesetval->nodeTab[i], 0, 0) < 0) { + vshError(ctl, "%s", _("Failed to create XML")); + goto cleanup; + } + + ret = virDomainUpdateDeviceFlags(dom, (char *)xmlBufferContent(xml_buf), flags); + + if (ret != 0) { + vshError(ctl, "%s", _("Failed to eject media")); + } else { + vshPrint(ctl, "%s", _("Media ejected successfully\n")); + functionReturn = true; + } + + cleanup: + xmlXPathFreeObject(obj); + xmlXPathFreeContext(ctxt); + if (xml) + xmlFreeDoc(xml); + if (xml_buf) + xmlBufferFree(xml_buf); + if (dom) + virDomainFree(dom); + return functionReturn; +} + +/* + * "insert-media" command + */ +static const vshCmdInfo info_insert_media[] = { + {"help", N_("insert media into CD or floppy drive")}, + {"desc", N_("Insert media into CD or floppy drive.")}, + {NULL, NULL} +}; + +static const vshCmdOptDef opts_insert_media[] = { + {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, + {"target", VSH_OT_DATA, VSH_OFLAG_REQ, N_("target of disk device")}, + {"source", VSH_OT_DATA, VSH_OFLAG_REQ, N_("source of the media")}, + {"current", VSH_OT_BOOL, 0, N_("can be either or both of --live and --config, " + "depends on implementation of hypervisor driver")}, + {"live", VSH_OT_BOOL, 0, N_("alter live configuration of running domain")}, + {"config", VSH_OT_BOOL, 0, N_("alter persistent configuration, effect observed on next boot")}, + {"force", VSH_OT_BOOL, 0, N_("force media insertion")}, + {NULL, 0, 0, NULL} +}; + +static bool +cmdInsertMedia(vshControl *ctl, const vshCmd *cmd) +{ + xmlDocPtr xml = NULL; + xmlXPathObjectPtr obj=NULL; + xmlXPathContextPtr ctxt = NULL; + xmlNodePtr cur = NULL; + xmlNodePtr new_node = NULL; + xmlBufferPtr xml_buf = NULL; + virDomainPtr dom = NULL; + const char *target = NULL; + const char *source = NULL; + char *doc; + int i = 0, diff_tgt; + int ret; + bool functionReturn = false; + int flags = 0; + const char *disk_type = NULL; + int config = vshCommandOptBool(cmd, "config"); + int live = vshCommandOptBool(cmd, "live"); + int current = vshCommandOptBool(cmd, "current"); + int force = vshCommandOptBool(cmd, "force"); + + if (current) { + if (live || config) { + vshError(ctl, "%s", _("--current must be specified exclusively")); + return false; + } + flags = VIR_DOMAIN_AFFECT_CURRENT; + } else { + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; + } + + if (force) + flags |= VIR_DOMAIN_DEVICE_MODIFY_FORCE; + + if (!vshConnectionUsability(ctl, ctl->conn)) + goto cleanup; + + if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) + goto cleanup; + + if (vshCommandOptString(cmd, "target", &target) <= 0) + goto cleanup; + + if (vshCommandOptString(cmd, "source", &source) <= 0) + goto cleanup; + + doc = virDomainGetXMLDesc(dom, 0); + if (!doc) + goto cleanup; + + xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL, + XML_PARSE_NOENT | XML_PARSE_NONET | + XML_PARSE_NOWARNING); + VIR_FREE(doc); + if (!xml) { + vshError(ctl, "%s", _("Failed to get disk information")); + goto cleanup; + } + ctxt = xmlXPathNewContext(xml); + if (!ctxt) { + vshError(ctl, "%s", _("Failed to get disk information")); + goto cleanup; + } + + obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt); + if ((obj == NULL) || (obj->type != XPATH_NODESET) || + (obj->nodesetval == NULL) || (obj->nodesetval->nodeNr == 0)) { + vshError(ctl, "%s", _("Failed to get disk information")); + goto cleanup; + } + + /* search target */ + for (; i < obj->nodesetval->nodeNr; i++) { + xmlNodePtr n = obj->nodesetval->nodeTab[i]; + bool is_supported = false; + + /* Check if the disk is CDROM or floppy disk */ + if (xmlStrEqual(n->name, BAD_CAST "disk")) { + disk_type = virXMLPropString(n, "type"); + char *device_value = virXMLPropString(n, "device"); + + if (STREQ(device_value, "cdrom") || + STREQ(device_value, "floppy")) + is_supported = true; + + VIR_FREE(device_value); + } + + cur = obj->nodesetval->nodeTab[i]->children; + while (cur != NULL) { + if (cur->type == XML_ELEMENT_NODE && + xmlStrEqual(cur->name, BAD_CAST "target")) { + char *tmp_tgt = virXMLPropString(cur, "dev"); + + diff_tgt = STREQ(tmp_tgt, target); + VIR_FREE(tmp_tgt); + + if (diff_tgt && is_supported) { + goto hit; + } + } + + cur = cur->next; + } + VIR_FREE(disk_type); + } + vshError(ctl, _("No found CDROM or floppy disk whose target is %s"), target); + goto cleanup; + + hit: + xml_buf = xmlBufferCreate(); + if (!xml_buf) { + vshError(ctl, "%s", _("Failed to allocate memory")); + goto cleanup; + } + + cur = obj->nodesetval->nodeTab[i]->children; + while (cur != NULL) { + if (cur->type == XML_ELEMENT_NODE && + xmlStrEqual(cur->name, BAD_CAST "source")) { + vshError(ctl, _("The disk device whose target is '%s' has media, " + "you may need to eject it first"), target); + goto cleanup; + } + + cur = cur->next; + } + + /* Insert node <source> */ + new_node = xmlNewNode(NULL, BAD_CAST "source"); + xmlNewProp(new_node, (const xmlChar *)disk_type, (const xmlChar *)source); + VIR_FREE(disk_type); + xmlAddChild(obj->nodesetval->nodeTab[i], new_node); + + if (xmlNodeDump(xml_buf, xml, obj->nodesetval->nodeTab[i], 0, 0) < 0) { + vshError(ctl, "%s", _("Failed to create XML")); + goto cleanup; + } + + ret = virDomainUpdateDeviceFlags(dom, (char *)xmlBufferContent(xml_buf), flags); + + if (ret != 0) { + vshError(ctl, "%s", _("Failed to insert media")); + } else { + vshPrint(ctl, "%s", _("Media inserted successfully\n")); + functionReturn = true; + } + + cleanup: + xmlXPathFreeObject(obj); + xmlXPathFreeContext(ctxt); + if (xml) + xmlFreeDoc(xml); + if (xml_buf) + xmlBufferFree(xml_buf); + if (dom) + virDomainFree(dom); + return functionReturn; +} + +/* * "detach-disk" command */ static const vshCmdInfo info_detach_disk[] = { @@ -11645,7 +12010,9 @@ static const vshCmdDef domManagementCmds[] = { {"dump", cmdDump, opts_dump, info_dump, 0}, {"dumpxml", cmdDumpXML, opts_dumpxml, info_dumpxml, 0}, {"edit", cmdEdit, opts_edit, info_edit, 0}, + {"eject-media", cmdEjectMedia, opts_eject_media, info_eject_media, 0}, {"inject-nmi", cmdInjectNMI, opts_inject_nmi, info_inject_nmi, 0}, + {"insert-media", cmdInsertMedia, opts_insert_media, info_insert_media, 0}, {"managedsave", cmdManagedSave, opts_managedsave, info_managedsave, 0}, {"managedsave-remove", cmdManagedSaveRemove, opts_managedsaveremove, info_managedsaveremove, 0}, -- 1.7.4

For commands eject-media and insert-media. --- tools/virsh.pod | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-) diff --git a/tools/virsh.pod b/tools/virsh.pod index 736b919..ccee715 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -927,6 +927,39 @@ option can be used to force device update, e.g., to eject a CD-ROM even if it is locked/mounted in the domain. See the documentation to learn about libvirt XML format for a device. +=item B<eject-media> I<domain-id> I<target> optional I<--current> +I<--live> I<--config> I<--force> + +Eject media from CD or floppy drive. The I<target> is the device as seen +from the domain. + +If I<--live> is specified, alter live configuration of running guest. +If I<--config> is specified, alter persistent configuration, effect observed +on next boot. +I<--current> can be either or both of I<live> and I<config>, depends on +the hypervisor's implementation. +Both I<--live> and I<--config> flags may be given, but I<--current> is +exclusive. If no flag is specified, behavior is different depending +on hypervisor. +The I<--force> option can be used to force media ejection. + +=item B<insert-media> I<domain-id> I<target> I<source> optional I<--current> +I<--live> I<--config> I<--force> + +Insert media into CD or floppy drive. The I<target> is the device as seen +from the domain. The I<source> specifies the path of the media which is to +be inserted. + +If I<--live> is specified, alter live configuration of running guest. +If I<--config> is specified, alter persistent configuration, effect observed +on next boot. +I<--current> can be either or both of I<live> and I<config>, depends on +the hypervisor's implementation. +Both I<--live> and I<--config> flags may be given, but I<--current> is +exclusive. If no flag is specified, behavior is different depending +on hypervisor. +The I<--force> option can be used to force media ejection. + =back =head1 VIRTUAL NETWORK COMMANDS -- 1.7.4

On 06/29/2011 06:19 AM, Osier Yang wrote:
These two patches is to introduce two new virsh commands, one is eject-media, which is to eject media from CD or floppy drive, the other is insert-media, which is to insert media into CD or floppy drive.
There are commands existed can be used to eject/insert media, such as "update-device", but it's not quite easy to use. That's the original intention of these patches.
Both of the two commands only allow to operate on CDROM or floppy disk.
[PATCH 1/2] virsh: Introduce two new commands to insert or eject media [PATCH 2/2] doc: Add docs for two new introduced commands
I think that we will eventually need even more; therefore, I'm thinking a more generic 'change-disk' command would be better than two specific 'eject-media' and 'insert-media' commands. Recent qemu added [1]: o blockdev-tray-open: opens the drive tray. Also Supports removing the inserted media. The BLOCK_TRAY_OPEN event is emitted if this command succeeds. o blockdev-tray-close: closes a drive tray. The BLOCK_TRAY_CLOSE event is emitted. o blockdev-media-insert: Inserts a media in the tray. The tray must empty and already opened. No event is emitted. along with updating to 'eject' and 'change' in terms of these more fundamental operations. [1] http://lists.nongnu.org/archive/html/qemu-devel/2011-06/msg00381.html That is, it should be possible to have libvirt issue a command to tell the guest's virtual cd tray to open, a command to tell the tray to close, and a command to tell qemu to change which disk is in the tray but leaving the tray open, and expose all of these through virsh. Meanwhile, it should also be possible to register for events to be told when the guest has initiated a tray open or tray close, although I'm not quite as sure that events need to be exposed through virsh. I think all of the new qemu monitor commands can be mapped into the existing virDomainUpdateDeviceFlags by way of adding a new XML attribute to the <device>/<disk>/<target> element for guest cdrom devices, as in: <disk> type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/path/to/my.iso'/> <target dev='hdc' bus=ide' tray='open'/> </disk> I don't think we need any new flags to virDomainUpdateDeviceFlags; rather, the additional xml attribute tray='open|closed' (omitted element implies closed) should be sufficient to correctly decide which monitor command(s) are necessary to get the virtual cdrom into the requested new state. Hmm, does qemu have a way at the command line to start a guest with the tray already open? If not, that feels like a missing qemu feature. But from the virsh aspect, it seems like a more generic change-disk is better than specific eject-media and insert-media commands: change-disk domain target {--current | [--live] [--config]} [--force] [{--open | --close}] {--keep | [media]} Change the state of the virtual cdrom disk <target> within <domain>. <--current>, <--live>, <--config> behave as usual. If <--force>, then force the change even if the disk was previously mounted by the guest. Either <--open> or <--close> may be specified to change the state of the virtual tray; if neither is given, the tray will be put back to its original state (although if it was already closed, the process involves temporarily opening the tray). If <--keep> is specified, then <--open> or <--close> only affects tray state without changing media. Otherwise, if <media> is specified, the contents of the tray are changed to the new media, and if <media> is omitted, then the tray is emptied. Examples: change-disk dom hdc --live /path/to/my.iso => checks for existing <disk><target dev='hdc'/></disk> and tray state. If tray state is closed, this creates new xml that changes the <source file='...'/>, and calls virDomainUpdateDeviceFlags with the new XML, which in turn attempts the 'change' monitor command which tries to open the tray, swap the media, then close the tray; this will fail if the guest has mounted the previous media and thus locked the tray. If tray state is open, then this maps to the 'blockdev-media-insert' monitor command that changes the media but leaves the tray open. change-disk dom hdc --live --force /path/to/my.iso => likewise, but with the force flag passed to virDomainUpdateDeviceFlags, and thus to the 'change' monitor command, so it should succeed change-disk dom hdc => changes the xml <source> to be empty, effectively removing the media from the disk change-disk dom hdc --open --keep => changes the xml to request the new tray=open attribute, but leaves <source> alone, so that the guest could initiate a tray-close action and see the same .iso that was previously in the disk change-disk dom hdc --close /path/to/my.iso => ensure that the new tray state is closed and contains the new iso, even if the tray was previously opened -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

于 2011年06月30日 00:26, Eric Blake 写道:
On 06/29/2011 06:19 AM, Osier Yang wrote:
These two patches is to introduce two new virsh commands, one is eject-media, which is to eject media from CD or floppy drive, the other is insert-media, which is to insert media into CD or floppy drive.
There are commands existed can be used to eject/insert media, such as "update-device", but it's not quite easy to use. That's the original intention of these patches.
Both of the two commands only allow to operate on CDROM or floppy disk.
[PATCH 1/2] virsh: Introduce two new commands to insert or eject media [PATCH 2/2] doc: Add docs for two new introduced commands
I think that we will eventually need even more; therefore, I'm thinking a more generic 'change-disk' command would be better than two specific 'eject-media' and 'insert-media' commands. Recent qemu added [1]:
o blockdev-tray-open: opens the drive tray. Also Supports removing the inserted media. The BLOCK_TRAY_OPEN event is emitted if this command succeeds. o blockdev-tray-close: closes a drive tray. The BLOCK_TRAY_CLOSE event is emitted. o blockdev-media-insert: Inserts a media in the tray. The tray must empty and already opened. No event is emitted.
along with updating to 'eject' and 'change' in terms of these more fundamental operations.
[1] http://lists.nongnu.org/archive/html/qemu-devel/2011-06/msg00381.html
These patches are still not pushed in qemu upstream, but good to known it, and agree with we need more if those patches are got pushed, so wait for some while.
That is, it should be possible to have libvirt issue a command to tell the guest's virtual cd tray to open, a command to tell the tray to close, and a command to tell qemu to change which disk is in the tray but leaving the tray open, and expose all of these through virsh.
Meanwhile, it should also be possible to register for events to be told when the guest has initiated a tray open or tray close, although I'm not quite as sure that events need to be exposed through virsh.
I think all of the new qemu monitor commands can be mapped into the existing virDomainUpdateDeviceFlags by way of adding a new XML attribute to the<device>/<disk>/<target> element for guest cdrom devices, as in:
<disk> type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/path/to/my.iso'/> <target dev='hdc' bus=ide' tray='open'/> </disk>
I don't think we need any new flags to virDomainUpdateDeviceFlags; rather, the additional xml attribute tray='open|closed' (omitted element implies closed) should be sufficient to correctly decide which monitor command(s) are necessary to get the virtual cdrom into the requested new state.
Hmm, does qemu have a way at the command line to start a guest with the tray already open? If not, that feels like a missing qemu feature.
But from the virsh aspect, it seems like a more generic change-disk is better than specific eject-media and insert-media commands:
change-disk domain target {--current | [--live] [--config]} [--force] [{--open | --close}] {--keep | [media]}
Change the state of the virtual cdrom disk<target> within<domain>. <--current>,<--live>,<--config> behave as usual. If<--force>, then force the change even if the disk was previously mounted by the guest. Either<--open> or<--close> may be specified to change the state of the virtual tray; if neither is given, the tray will be put back to its original state (although if it was already closed, the process involves temporarily opening the tray). If<--keep> is specified, then<--open> or<--close> only affects tray state without changing media. Otherwise, if<media> is specified, the contents of the tray are changed to the new media, and if<media> is omitted, then the tray is emptied.
Examples:
change-disk dom hdc --live /path/to/my.iso => checks for existing<disk><target dev='hdc'/></disk> and tray state. If tray state is closed, this creates new xml that changes the<source file='...'/>, and calls virDomainUpdateDeviceFlags with the new XML, which in turn attempts the 'change' monitor command which tries to open the tray, swap the media, then close the tray; this will fail if the guest has mounted the previous media and thus locked the tray. If tray state is open, then this maps to the 'blockdev-media-insert' monitor command that changes the media but leaves the tray open.
change-disk dom hdc --live --force /path/to/my.iso => likewise, but with the force flag passed to virDomainUpdateDeviceFlags, and thus to the 'change' monitor command, so it should succeed
change-disk dom hdc => changes the xml<source> to be empty, effectively removing the media from the disk
change-disk dom hdc --open --keep => changes the xml to request the new tray=open attribute, but leaves <source> alone, so that the guest could initiate a tray-close action and see the same .iso that was previously in the disk
change-disk dom hdc --close /path/to/my.iso => ensure that the new tray state is closed and contains the new iso, even if the tray was previously opened

On 2011年06月30日 00:26, Eric Blake wrote:
On 06/29/2011 06:19 AM, Osier Yang wrote:
These two patches is to introduce two new virsh commands, one is eject-media, which is to eject media from CD or floppy drive, the other is insert-media, which is to insert media into CD or floppy drive.
There are commands existed can be used to eject/insert media, such as "update-device", but it's not quite easy to use. That's the original intention of these patches.
Both of the two commands only allow to operate on CDROM or floppy disk.
[PATCH 1/2] virsh: Introduce two new commands to insert or eject media [PATCH 2/2] doc: Add docs for two new introduced commands
I think that we will eventually need even more; therefore, I'm thinking a more generic 'change-disk' command would be better than two specific 'eject-media' and 'insert-media' commands. Recent qemu added [1]:
o blockdev-tray-open: opens the drive tray. Also Supports removing the inserted media. The BLOCK_TRAY_OPEN event is emitted if this command succeeds. o blockdev-tray-close: closes a drive tray. The BLOCK_TRAY_CLOSE event is emitted. o blockdev-media-insert: Inserts a media in the tray. The tray must empty and already opened. No event is emitted.
along with updating to 'eject' and 'change' in terms of these more fundamental operations.
[1] http://lists.nongnu.org/archive/html/qemu-devel/2011-06/msg00381.html
There is no news for the these qemu patches since June. Should we still wait for that? We don't have to wait for the qemu patches if we seperate the media and tray management in virsh. i.e. insert-media & eject-media: for media management. tray-open & tray-close: for tray management (in future) OR change-media: for media management change-tray: for tray management Before the qemu introduce news monitor commands for media management, we can use current updateDeviceFlags API (which uses qemu's "change"), after the qemu commands for media management is introduced, we can add a simple switch to honor them. (Of course, we need to introduce new events support if qemu supports to emit events, but that's a separate work from virsh's point of view). On the other hand, from a user's point of view, separating management of media and tray could be more clear. However, having all the management scenarios for both tray and media in one command could be a bit confused. Thoughts? Regards, Osier

On Mon, Dec 19, 2011 at 12:41:08PM +0800, Osier Yang wrote:
On 2011年06月30日 00:26, Eric Blake wrote:
On 06/29/2011 06:19 AM, Osier Yang wrote:
These two patches is to introduce two new virsh commands, one is eject-media, which is to eject media from CD or floppy drive, the other is insert-media, which is to insert media into CD or floppy drive.
There are commands existed can be used to eject/insert media, such as "update-device", but it's not quite easy to use. That's the original intention of these patches.
Both of the two commands only allow to operate on CDROM or floppy disk.
[PATCH 1/2] virsh: Introduce two new commands to insert or eject media [PATCH 2/2] doc: Add docs for two new introduced commands
I think that we will eventually need even more; therefore, I'm thinking a more generic 'change-disk' command would be better than two specific 'eject-media' and 'insert-media' commands. Recent qemu added [1]:
o blockdev-tray-open: opens the drive tray. Also Supports removing the inserted media. The BLOCK_TRAY_OPEN event is emitted if this command succeeds. o blockdev-tray-close: closes a drive tray. The BLOCK_TRAY_CLOSE event is emitted. o blockdev-media-insert: Inserts a media in the tray. The tray must empty and already opened. No event is emitted.
along with updating to 'eject' and 'change' in terms of these more fundamental operations.
[1] http://lists.nongnu.org/archive/html/qemu-devel/2011-06/msg00381.html
There is no news for the these qemu patches since June. Should we still wait for that?
We don't have to wait for the qemu patches if we seperate the media and tray management in virsh. i.e.
insert-media & eject-media: for media management. tray-open & tray-close: for tray management (in future)
OR
change-media: for media management change-tray: for tray management
Before the qemu introduce news monitor commands for media management, we can use current updateDeviceFlags API (which uses qemu's "change"), after the qemu commands for media management is introduced, we can add a simple switch to honor them. (Of course, we need to introduce new events support if qemu supports to emit events, but that's a separate work from virsh's point of view).
On the other hand, from a user's point of view, separating management of media and tray could be more clear. However, having all the management scenarios for both tray and media in one command could be a bit confused.
Thoughts?
I think there's a use for a syntactic sugar command for changing the media which can be done today with update device. That command shouldn't depend on the additionally useful command for opening/closing the tray. Dave
Regards, Osier
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (3)
-
Dave Allan
-
Eric Blake
-
Osier Yang