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

Osier Yang jyang at redhat.com
Thu Jun 30 07:28:04 UTC 2011


于 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
>




More information about the libvir-list mailing list