Patchwork [RFC,01/10] block: bdrv_eject(): Add 'force' parameter

login
register
mail settings
Submitter Luiz Capitulino
Date June 3, 2011, 7:03 p.m.
Message ID <1307127842-12102-2-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/98631/
State New
Headers show

Comments

Luiz Capitulino - June 3, 2011, 7:03 p.m.
It's purpose is to skip the media locked test. This is going to be used
by the blockdev-tray-open QMP command.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 block.c        |    4 ++--
 block.h        |    2 +-
 block/raw.c    |    2 +-
 hw/ide/atapi.c |    2 +-
 hw/scsi-disk.c |    2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

Patch

diff --git a/block.c b/block.c
index effa86f..a3d0556 100644
--- a/block.c
+++ b/block.c
@@ -2752,12 +2752,12 @@  int bdrv_media_changed(BlockDriverState *bs)
 /**
  * If eject_flag is TRUE, eject the media. Otherwise, close the tray
  */
-int bdrv_eject(BlockDriverState *bs, int eject_flag)
+int bdrv_eject(BlockDriverState *bs, int eject_flag, int force)
 {
     BlockDriver *drv = bs->drv;
     int ret;
 
-    if (bs->locked) {
+    if (bs->locked && !force) {
         return -EBUSY;
     }
 
diff --git a/block.h b/block.h
index da7d39c..131812c 100644
--- a/block.h
+++ b/block.h
@@ -186,7 +186,7 @@  int bdrv_is_inserted(BlockDriverState *bs);
 int bdrv_media_changed(BlockDriverState *bs);
 int bdrv_is_locked(BlockDriverState *bs);
 void bdrv_set_locked(BlockDriverState *bs, int locked);
-int bdrv_eject(BlockDriverState *bs, int eject_flag);
+int bdrv_eject(BlockDriverState *bs, int eject_flag, int force);
 void bdrv_set_change_cb(BlockDriverState *bs,
                         void (*change_cb)(void *opaque, int reason),
                         void *opaque);
diff --git a/block/raw.c b/block/raw.c
index b0f72d6..0e23c7c 100644
--- a/block/raw.c
+++ b/block/raw.c
@@ -77,7 +77,7 @@  static int raw_is_inserted(BlockDriverState *bs)
 
 static int raw_eject(BlockDriverState *bs, int eject_flag)
 {
-    return bdrv_eject(bs->file, eject_flag);
+    return bdrv_eject(bs->file, eject_flag, 0);
 }
 
 static int raw_set_locked(BlockDriverState *bs, int locked)
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index fe2fb0b..8af6e23 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -897,7 +897,7 @@  static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
     eject = (buf[4] >> 1) & 1;
 
     if (eject) {
-        err = bdrv_eject(s->bs, !start);
+        err = bdrv_eject(s->bs, !start, 0);
     }
 
     switch (err) {
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index a8c7372..d3f982e 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -872,7 +872,7 @@  static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
     case START_STOP:
         if (s->drive_kind == SCSI_CD && (req->cmd.buf[4] & 2)) {
             /* load/eject medium */
-            bdrv_eject(s->bs, !(req->cmd.buf[4] & 1));
+            bdrv_eject(s->bs, !(req->cmd.buf[4] & 1), 0);
         }
 	break;
     case ALLOW_MEDIUM_REMOVAL: