Received: from eggs.gnu.org ([140.186.70.92]:44537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTa2n-0008B2-7S for qemu-devel@nongnu.org; Mon, 06 Jun 2011 09:40:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QTa2i-0001Fs-OR for qemu-devel@nongnu.org; Mon, 06 Jun 2011 09:40:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29999) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTa2i-0001Fi-8n for qemu-devel@nongnu.org; Mon, 06 Jun 2011 09:40:32 -0400 From: Markus Armbruster References: <1307127842-12102-1-git-send-email-lcapitulino@redhat.com> <1307127842-12102-8-git-send-email-lcapitulino@redhat.com> Date: Mon, 06 Jun 2011 15:40:28 +0200 In-Reply-To: <1307127842-12102-8-git-send-email-lcapitulino@redhat.com> (Luiz Capitulino's message of "Fri, 3 Jun 2011 16:03:59 -0300") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [RFC 07/10] QMP: Introduce the blockdev-media-insert command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: kwolf@redhat.com, amit.shah@redhat.com, aliguori@us.ibm.com, qemu-devel@nongnu.org Luiz Capitulino 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 > --- > 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. > + > + 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; > +} [...]