[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 13/35] block: Leave enforcing tray lock to device mo
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 13/35] block: Leave enforcing tray lock to device models |
Date: |
Mon, 12 Sep 2011 16:19:12 +0200 |
From: Markus Armbruster <address@hidden>
The device model knows best when to accept the guest's eject command.
No need to detour through the block layer.
bdrv_eject() can't fail anymore. Make it void.
Signed-off-by: Markus Armbruster <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 7 +------
block.h | 2 +-
hw/ide/atapi.c | 29 +++++++++--------------------
hw/scsi-disk.c | 3 +++
4 files changed, 14 insertions(+), 27 deletions(-)
diff --git a/block.c b/block.c
index 8c86251..7408fa9 100644
--- a/block.c
+++ b/block.c
@@ -3051,18 +3051,13 @@ 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)
+void bdrv_eject(BlockDriverState *bs, int eject_flag)
{
BlockDriver *drv = bs->drv;
- if (eject_flag && bs->locked) {
- return -EBUSY;
- }
-
if (drv && drv->bdrv_eject) {
drv->bdrv_eject(bs, eject_flag);
}
- return 0;
}
int bdrv_is_locked(BlockDriverState *bs)
diff --git a/block.h b/block.h
index 8ec409f..5d941e9 100644
--- a/block.h
+++ b/block.h
@@ -208,7 +208,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);
+void bdrv_eject(BlockDriverState *bs, int eject_flag);
void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
BlockDriverState *bdrv_find(const char *name);
BlockDriverState *bdrv_next(BlockDriverState *bs);
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index d9db6de..afb27c6 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -905,33 +905,22 @@ static void cmd_seek(IDEState *s, uint8_t* buf)
static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
{
- int sense, err = 0;
+ int sense;
bool start = buf[4] & 1;
bool loej = buf[4] & 2; /* load on start, eject on !start */
if (loej) {
- err = bdrv_eject(s->bs, !start);
- }
-
- switch (err) {
- case 0:
- ide_atapi_cmd_ok(s);
- break;
- case -EBUSY:
- sense = SENSE_NOT_READY;
- if (bdrv_is_inserted(s->bs)) {
- sense = SENSE_ILLEGAL_REQUEST;
+ if (!start && s->tray_locked) {
+ sense = bdrv_is_inserted(s->bs)
+ ? SENSE_NOT_READY : SENSE_ILLEGAL_REQUEST;
+ ide_atapi_cmd_error(s, sense, ASC_MEDIA_REMOVAL_PREVENTED);
+ return;
}
- ide_atapi_cmd_error(s, sense, ASC_MEDIA_REMOVAL_PREVENTED);
- break;
- default:
- ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);
- break;
- }
-
- if (loej && !err) {
+ bdrv_eject(s->bs, !start);
s->tray_open = !start;
}
+
+ ide_atapi_cmd_ok(s);
}
static void cmd_mechanism_status(IDEState *s, uint8_t* buf)
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index e7358e3..65783a7 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -830,6 +830,9 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
bool loej = req->cmd.buf[4] & 2; /* load on start, eject on !start */
if (s->qdev.type == TYPE_ROM && loej) {
+ if (!start && s->tray_locked) {
+ return;
+ }
bdrv_eject(s->bs, !start);
s->tray_open = !start;
}
--
1.7.6
- [Qemu-devel] [PATCH 04/35] ide: Reject ATA commands specific to drive kinds, (continued)
- [Qemu-devel] [PATCH 04/35] ide: Reject ATA commands specific to drive kinds, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 01/35] qcow2: removed unused depends_on field, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 03/35] ide: Use a table to declare which drive kinds accept each command, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 05/35] ide/atapi: Clean up misleading name in cmd_start_stop_unit(), Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 02/35] ide: Fix ATA command READ to set ATAPI signature for CD-ROM, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 07/35] scsi-disk: Factor out scsi_disk_emulate_start_stop(), Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 08/35] scsi-disk: Track tray open/close state, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 11/35] ide/atapi: Track tray locked state, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 10/35] block: Drop tray status tracking, no longer used, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 09/35] block: Revert entanglement of bdrv_is_inserted() with tray status, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 13/35] block: Leave enforcing tray lock to device models,
Kevin Wolf <=
- [Qemu-devel] [PATCH 14/35] block: Drop medium lock tracking, ask device models instead, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 16/35] rbd: allow client id to be specified in config string, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 21/35] ide/atapi: Preserve tray state on migration, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 12/35] scsi-disk: Track tray locked state, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 15/35] block: Rename bdrv_set_locked() to bdrv_lock_medium(), Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 22/35] block: Clean up remaining users of "removable", Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 20/35] scsi-disk: Fix START_STOP to fail when it can't eject, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 28/35] block: Reset buffer alignment on detach, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 24/35] block: Show whether the virtual tray is open in info block, Kevin Wolf, 2011/09/12
- [Qemu-devel] [PATCH 31/35] ide/atapi scsi-disk: Make monitor eject -f, then change work, Kevin Wolf, 2011/09/12