* [Qemu-devel] [PATCH 0/2] scsi: Fixes around eject
@ 2016-09-14 10:17 Fam Zheng
2016-09-14 10:17 ` [Qemu-devel] [PATCH 1/2] scsi-disk: Cleaning up around tray open state Fam Zheng
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Fam Zheng @ 2016-09-14 10:17 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini
The first patch fixes what Paolo noticed wrong earlier today.
The second patch fixes a related crash with virtio-scsi data plane. It
supersedes
https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg02243.html
Fam Zheng (2):
scsi-disk: Cleaning up around tray open state
virtio-scsi: Don't abort when media is ejected
hw/scsi/scsi-disk.c | 22 ++++++++--------------
hw/scsi/virtio-scsi.c | 15 +++++++++------
2 files changed, 17 insertions(+), 20 deletions(-)
--
2.7.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 1/2] scsi-disk: Cleaning up around tray open state
2016-09-14 10:17 [Qemu-devel] [PATCH 0/2] scsi: Fixes around eject Fam Zheng
@ 2016-09-14 10:17 ` Fam Zheng
2016-09-14 10:17 ` [Qemu-devel] [PATCH 2/2] virtio-scsi: Don't abort when media is ejected Fam Zheng
2016-09-14 10:25 ` [Qemu-devel] [PATCH 0/2] scsi: Fixes around eject Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Fam Zheng @ 2016-09-14 10:17 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini
Even if tray is not open, it can be empty (blk_is_inserted() == false).
Handle both cases correctly by replacing the s->tray_open checks with
blk_is_available(), which is an AND of the two.
Also simplify successive checks of them into blk_is_available(), in a
couple cases.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
hw/scsi/scsi-disk.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 99c9d61..3d5e48e 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -396,7 +396,7 @@ static void scsi_read_data(SCSIRequest *req)
return;
}
- if (s->tray_open) {
+ if (!blk_is_available(req->dev->conf.blk)) {
scsi_read_complete(r, -ENOMEDIUM);
return;
}
@@ -519,7 +519,7 @@ static void scsi_write_data(SCSIRequest *req)
scsi_write_complete_noio(r, 0);
return;
}
- if (s->tray_open) {
+ if (!blk_is_available(req->dev->conf.blk)) {
scsi_write_complete_noio(r, -ENOMEDIUM);
return;
}
@@ -792,10 +792,7 @@ static inline bool media_is_dvd(SCSIDiskState *s)
if (s->qdev.type != TYPE_ROM) {
return false;
}
- if (!blk_is_inserted(s->qdev.conf.blk)) {
- return false;
- }
- if (s->tray_open) {
+ if (!blk_is_available(s->qdev.conf.blk)) {
return false;
}
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
@@ -808,10 +805,7 @@ static inline bool media_is_cd(SCSIDiskState *s)
if (s->qdev.type != TYPE_ROM) {
return false;
}
- if (!blk_is_inserted(s->qdev.conf.blk)) {
- return false;
- }
- if (s->tray_open) {
+ if (!blk_is_available(s->qdev.conf.blk)) {
return false;
}
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
@@ -875,7 +869,7 @@ static int scsi_read_dvd_structure(SCSIDiskState *s, SCSIDiskReq *r,
}
if (format != 0xff) {
- if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) {
+ if (!blk_is_available(s->qdev.conf.blk)) {
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
return -1;
}
@@ -1857,7 +1851,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
break;
default:
- if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) {
+ if (!blk_is_available(s->qdev.conf.blk)) {
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
return 0;
}
@@ -1886,7 +1880,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
memset(outbuf, 0, r->buflen);
switch (req->cmd.buf[0]) {
case TEST_UNIT_READY:
- assert(!s->tray_open && blk_is_inserted(s->qdev.conf.blk));
+ assert(blk_is_available(s->qdev.conf.blk));
break;
case INQUIRY:
buflen = scsi_disk_emulate_inquiry(req, outbuf);
@@ -2126,7 +2120,7 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf)
command = buf[0];
- if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) {
+ if (!blk_is_available(s->qdev.conf.blk)) {
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
return 0;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 2/2] virtio-scsi: Don't abort when media is ejected
2016-09-14 10:17 [Qemu-devel] [PATCH 0/2] scsi: Fixes around eject Fam Zheng
2016-09-14 10:17 ` [Qemu-devel] [PATCH 1/2] scsi-disk: Cleaning up around tray open state Fam Zheng
@ 2016-09-14 10:17 ` Fam Zheng
2016-09-14 10:25 ` [Qemu-devel] [PATCH 0/2] scsi: Fixes around eject Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Fam Zheng @ 2016-09-14 10:17 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini
With an ejected block backend, blk_get_aio_context() would return
qemu_aio_context. In this case don't assert.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
hw/scsi/virtio-scsi.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index ce57ef6..e596b64 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -236,6 +236,13 @@ static void virtio_scsi_cancel_notify(Notifier *notifier, void *data)
g_free(n);
}
+static inline void virtio_scsi_ctx_check(VirtIOSCSI *s, SCSIDevice *d)
+{
+ if (s->dataplane_started && d && blk_is_available(d->conf.blk)) {
+ assert(blk_get_aio_context(d->conf.blk) == s->ctx);
+ }
+}
+
/* Return 0 if the request is ready to be completed and return to guest;
* -EINPROGRESS if the request is submitted and will be completed later, in the
* case of async cancellation. */
@@ -247,9 +254,7 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
int target;
int ret = 0;
- if (s->dataplane_started && d) {
- assert(blk_get_aio_context(d->conf.blk) == s->ctx);
- }
+ virtio_scsi_ctx_check(s, d);
/* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE". */
req->resp.tmf.response = VIRTIO_SCSI_S_OK;
@@ -539,9 +544,7 @@ static bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req
virtio_scsi_complete_cmd_req(req);
return false;
}
- if (s->dataplane_started) {
- assert(blk_get_aio_context(d->conf.blk) == s->ctx);
- }
+ virtio_scsi_ctx_check(s, d);
req->sreq = scsi_req_new(d, req->req.cmd.tag,
virtio_scsi_get_lun(req->req.cmd.lun),
req->req.cmd.cdb, req);
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] scsi: Fixes around eject
2016-09-14 10:17 [Qemu-devel] [PATCH 0/2] scsi: Fixes around eject Fam Zheng
2016-09-14 10:17 ` [Qemu-devel] [PATCH 1/2] scsi-disk: Cleaning up around tray open state Fam Zheng
2016-09-14 10:17 ` [Qemu-devel] [PATCH 2/2] virtio-scsi: Don't abort when media is ejected Fam Zheng
@ 2016-09-14 10:25 ` Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2016-09-14 10:25 UTC (permalink / raw)
To: Fam Zheng, qemu-devel, qemu-stable
On 14/09/2016 12:17, Fam Zheng wrote:
> The first patch fixes what Paolo noticed wrong earlier today.
>
> The second patch fixes a related crash with virtio-scsi data plane. It
> supersedes
>
> https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg02243.html
>
> Fam Zheng (2):
> scsi-disk: Cleaning up around tray open state
> virtio-scsi: Don't abort when media is ejected
>
> hw/scsi/scsi-disk.c | 22 ++++++++--------------
> hw/scsi/virtio-scsi.c | 15 +++++++++------
> 2 files changed, 17 insertions(+), 20 deletions(-)
>
Cc: qemu-stable <qemu-stable@nongnu.org>
Queued for 2.8, thanks.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-09-14 10:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-14 10:17 [Qemu-devel] [PATCH 0/2] scsi: Fixes around eject Fam Zheng
2016-09-14 10:17 ` [Qemu-devel] [PATCH 1/2] scsi-disk: Cleaning up around tray open state Fam Zheng
2016-09-14 10:17 ` [Qemu-devel] [PATCH 2/2] virtio-scsi: Don't abort when media is ejected Fam Zheng
2016-09-14 10:25 ` [Qemu-devel] [PATCH 0/2] scsi: Fixes around eject Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).