[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC 07/10] QMP: Introduce the blockdev-media-insert co
From: |
Luiz Capitulino |
Subject: |
Re: [Qemu-devel] [RFC 07/10] QMP: Introduce the blockdev-media-insert command |
Date: |
Mon, 6 Jun 2011 11:58:47 -0300 |
On Mon, 06 Jun 2011 15:40:28 +0200
Markus Armbruster <address@hidden> wrote:
> Luiz Capitulino <address@hidden> writes:
>
> > This command inserts a new media in an already opened tray. It's only
> > available in QMP.
> >
> > Please, check the command's documentation (being introduced in this
> > commit) for a detailed description.
> >
> > Signed-off-by: Luiz Capitulino <address@hidden>
> > ---
> > blockdev.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> > blockdev.h | 1 +
> > qmp-commands.hx | 32 ++++++++++++++++++++++++++++++++
> > 3 files changed, 85 insertions(+), 0 deletions(-)
> >
> > diff --git a/blockdev.c b/blockdev.c
> > index 943905d..14c8312 100644
> > --- a/blockdev.c
> > +++ b/blockdev.c
> > @@ -721,6 +721,58 @@ static int tray_close(const char *device)
> > return 0;
> > }
> >
> > +static int media_insert(const char *device, const char *mediafile,
> > + const char *format)
> > +{
> > + BlockDriver *drv = NULL;
> > + BlockDriverState *bs;
> > + int bdrv_flags;
> > +
> > + bs = bdrv_removable_find(device);
> > + if (!bs) {
> > + return -1;
> > + }
> > +
> > + if (bdrv_is_locked(bs)) {
> > + qerror_report(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs));
> > + return -1;
> > + }
>
> Why fail if locked?
>
> If you managed to pry open the tray, I guess nothing should stop you
> from changing the media in it.
Makes sense.
>
> > +
> > + if (bdrv_is_inserted(bs)) {
> > + /* FIXME: will report undefined error in QMP */
> > + return -1;
> > + }
> > +
> > + if (!bs->tray_open) {
> > + /* FIXME: will report undefined error in QMP */
> > + return 1;
> > + }
> > +
> > + if (format) {
> > + drv = bdrv_find_whitelisted_format(format);
> > + if (!drv) {
> > + qerror_report(QERR_INVALID_BLOCK_FORMAT, format);
> > + return -1;
> > + }
> > + }
> > +
> > + bdrv_flags = bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR;
> > + bdrv_flags |= bdrv_is_snapshot(bs) ? BDRV_O_SNAPSHOT : 0;
> > + if (bdrv_open(bs, mediafile, bdrv_flags, drv) < 0) {
> > + qerror_report(QERR_OPEN_FILE_FAILED, mediafile);
> > + return -1;
> > + }
> > +
> > + return 0;
> > +}
> [...]
>
- [Qemu-devel] [RFC 01/10] block: bdrv_eject(): Add 'force' parameter, (continued)
- [Qemu-devel] [RFC 01/10] block: bdrv_eject(): Add 'force' parameter, Luiz Capitulino, 2011/06/03
- [Qemu-devel] [RFC 02/10] block: Rename bdrv_mon_event(), Luiz Capitulino, 2011/06/03
- [Qemu-devel] [RFC 03/10] QMP: query-block: Add the 'tray-open' key, Luiz Capitulino, 2011/06/03
- [Qemu-devel] [RFC 04/10] HMP: info block: Print the 'tray-open' key, Luiz Capitulino, 2011/06/03
- [Qemu-devel] [RFC 06/10] QMP: Introduce the blockdev-tray-close command, Luiz Capitulino, 2011/06/03
- [Qemu-devel] [RFC 07/10] QMP: Introduce the blockdev-media-insert command, Luiz Capitulino, 2011/06/03
- [Qemu-devel] [RFC 05/10] QMP: Introduce the blockdev-tray-open command, Luiz Capitulino, 2011/06/03
- Re: [Qemu-devel] [RFC 05/10] QMP: Introduce the blockdev-tray-open command, Markus Armbruster, 2011/06/06
[Qemu-devel] [RFC 08/10] QMP: Introduce the BLOCK_TRAY_OPEN and BLOCK_TRAY_CLOSE events, Luiz Capitulino, 2011/06/03
[Qemu-devel] [RFC 09/10] QMP/HMP: eject: Use blockdev-tray-open, Luiz Capitulino, 2011/06/03
[Qemu-devel] [RFC 10/10] QMP/HMP: change: Use QMP tray commands, Luiz Capitulino, 2011/06/03