From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 54/55] scsi: push request restart to SCSIDevice
Date: Mon, 31 Oct 2011 14:30:29 +0100 [thread overview]
Message-ID: <1320067830-12093-55-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1320067830-12093-1-git-send-email-kwolf@redhat.com>
From: Paolo Bonzini <pbonzini@redhat.com>
The request restart mechanism is generic and could be reused for
scsi-generic. In the meanwhile, pushing it to SCSIDevice avoids
that scsi_dma_restart_bh looks at SCSIGenericReqs when working on
a scsi-block device.
The code is the same that is already in hw/scsi-disk.c, with
the type flags replaced by req->cmd.mode and a more generic way to
requeue SCSI_XFER_NONE commands.
I also added a missing call to qemu_del_vm_change_state_handler.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/scsi-bus.c | 56 +++++++++++++++++++++++++++++++++++++++++
hw/scsi-disk.c | 76 +++++--------------------------------------------------
hw/scsi.h | 5 +++
3 files changed, 68 insertions(+), 69 deletions(-)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index dfce5fb..e6ebbd5 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -8,6 +8,7 @@
static char *scsibus_get_fw_dev_path(DeviceState *dev);
static int scsi_req_parse(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf);
+static void scsi_req_dequeue(SCSIRequest *req);
static int scsi_build_sense(uint8_t *in_buf, int in_len,
uint8_t *buf, int len, bool fixed);
@@ -33,6 +34,53 @@ void scsi_bus_new(SCSIBus *bus, DeviceState *host, const SCSIBusInfo *info)
bus->qbus.allow_hotplug = 1;
}
+static void scsi_dma_restart_bh(void *opaque)
+{
+ SCSIDevice *s = opaque;
+ SCSIRequest *req, *next;
+
+ qemu_bh_delete(s->bh);
+ s->bh = NULL;
+
+ QTAILQ_FOREACH_SAFE(req, &s->requests, next, next) {
+ scsi_req_ref(req);
+ if (req->retry) {
+ req->retry = false;
+ switch (req->cmd.mode) {
+ case SCSI_XFER_FROM_DEV:
+ case SCSI_XFER_TO_DEV:
+ scsi_req_continue(req);
+ break;
+ case SCSI_XFER_NONE:
+ scsi_req_dequeue(req);
+ scsi_req_enqueue(req);
+ break;
+ }
+ }
+ scsi_req_unref(req);
+ }
+}
+
+void scsi_req_retry(SCSIRequest *req)
+{
+ /* No need to save a reference, because scsi_dma_restart_bh just
+ * looks at the request list. */
+ req->retry = true;
+}
+
+static void scsi_dma_restart_cb(void *opaque, int running, RunState state)
+{
+ SCSIDevice *s = opaque;
+
+ if (!running) {
+ return;
+ }
+ if (!s->bh) {
+ s->bh = qemu_bh_new(scsi_dma_restart_bh, s);
+ qemu_bh_schedule(s->bh);
+ }
+}
+
static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
{
SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
@@ -83,6 +131,10 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
dev->info = info;
QTAILQ_INIT(&dev->requests);
rc = dev->info->init(dev);
+ if (rc == 0) {
+ dev->vmsentry = qemu_add_vm_change_state_handler(scsi_dma_restart_cb,
+ dev);
+ }
err:
return rc;
@@ -92,6 +144,9 @@ static int scsi_qdev_exit(DeviceState *qdev)
{
SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
+ if (dev->vmsentry) {
+ qemu_del_vm_change_state_handler(dev->vmsentry);
+ }
if (dev->info->destroy) {
dev->info->destroy(dev);
}
@@ -586,6 +641,7 @@ int32_t scsi_req_enqueue(SCSIRequest *req)
static void scsi_req_dequeue(SCSIRequest *req)
{
trace_scsi_req_dequeue(req->dev->id, req->lun, req->tag);
+ req->retry = false;
if (req->enqueued) {
QTAILQ_REMOVE(&req->dev->requests, req, next);
req->enqueued = false;
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index bb07737..352d41f 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -42,12 +42,6 @@ do { fprintf(stderr, "scsi-disk: " fmt , ## __VA_ARGS__); } while (0)
#define SCSI_DMA_BUF_SIZE 131072
#define SCSI_MAX_INQUIRY_LEN 256
-#define SCSI_REQ_STATUS_RETRY 0x01
-#define SCSI_REQ_STATUS_RETRY_TYPE_MASK 0x06
-#define SCSI_REQ_STATUS_RETRY_READ 0x00
-#define SCSI_REQ_STATUS_RETRY_WRITE 0x02
-#define SCSI_REQ_STATUS_RETRY_FLUSH 0x04
-
typedef struct SCSIDiskState SCSIDiskState;
typedef struct SCSIDiskReq {
@@ -58,7 +52,6 @@ typedef struct SCSIDiskReq {
uint32_t buflen;
struct iovec iov;
QEMUIOVector qiov;
- uint32_t status;
BlockAcctCookie acct;
} SCSIDiskReq;
@@ -75,8 +68,7 @@ struct SCSIDiskState
bool tray_locked;
};
-static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);
-static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf);
+static int scsi_handle_rw_error(SCSIDiskReq *r, int error);
static void scsi_free_request(SCSIRequest *req)
{
@@ -102,7 +94,6 @@ static void scsi_cancel_io(SCSIRequest *req)
SCSIDiskReq *r = DO_UPCAST(SCSIDiskReq, req, req);
DPRINTF("Cancel tag=0x%x\n", req->tag);
- r->status &= ~(SCSI_REQ_STATUS_RETRY | SCSI_REQ_STATUS_RETRY_TYPE_MASK);
if (r->req.aiocb) {
bdrv_aio_cancel(r->req.aiocb);
@@ -139,7 +130,7 @@ static void scsi_read_complete(void * opaque, int ret)
}
if (ret) {
- if (scsi_handle_rw_error(r, -ret, SCSI_REQ_STATUS_RETRY_READ)) {
+ if (scsi_handle_rw_error(r, -ret)) {
goto done;
}
}
@@ -168,7 +159,7 @@ static void scsi_flush_complete(void * opaque, int ret)
}
if (ret < 0) {
- if (scsi_handle_rw_error(r, -ret, SCSI_REQ_STATUS_RETRY_FLUSH)) {
+ if (scsi_handle_rw_error(r, -ret)) {
goto done;
}
}
@@ -233,9 +224,9 @@ static void scsi_read_data(SCSIRequest *req)
* scsi_handle_rw_error always manages its reference counts, independent
* of the return value.
*/
-static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type)
+static int scsi_handle_rw_error(SCSIDiskReq *r, int error)
{
- int is_read = (type == SCSI_REQ_STATUS_RETRY_READ);
+ int is_read = (r->req.cmd.xfer == SCSI_XFER_FROM_DEV);
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
BlockErrorAction action = bdrv_get_on_error(s->qdev.conf.bs, is_read);
@@ -247,17 +238,10 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type)
if ((error == ENOSPC && action == BLOCK_ERR_STOP_ENOSPC)
|| action == BLOCK_ERR_STOP_ANY) {
- type &= SCSI_REQ_STATUS_RETRY_TYPE_MASK;
- r->status |= SCSI_REQ_STATUS_RETRY | type;
-
bdrv_mon_event(s->qdev.conf.bs, BDRV_ACTION_STOP, is_read);
vm_stop(RUN_STATE_IO_ERROR);
bdrv_iostatus_set_err(s->qdev.conf.bs, error);
-
- /* No need to save a reference, because scsi_dma_restart_bh just
- * looks at the request list. If a request is canceled, the
- * retry request is just dropped.
- */
+ scsi_req_retry(&r->req);
} else {
switch (error) {
case ENOMEDIUM:
@@ -290,7 +274,7 @@ static void scsi_write_complete(void * opaque, int ret)
}
if (ret) {
- if (scsi_handle_rw_error(r, -ret, SCSI_REQ_STATUS_RETRY_WRITE)) {
+ if (scsi_handle_rw_error(r, -ret)) {
goto done;
}
}
@@ -347,51 +331,6 @@ static void scsi_write_data(SCSIRequest *req)
}
}
-static void scsi_dma_restart_bh(void *opaque)
-{
- SCSIDiskState *s = opaque;
- SCSIRequest *req;
- SCSIDiskReq *r;
-
- qemu_bh_delete(s->bh);
- s->bh = NULL;
-
- QTAILQ_FOREACH(req, &s->qdev.requests, next) {
- r = DO_UPCAST(SCSIDiskReq, req, req);
- if (r->status & SCSI_REQ_STATUS_RETRY) {
- int status = r->status;
-
- r->status &=
- ~(SCSI_REQ_STATUS_RETRY | SCSI_REQ_STATUS_RETRY_TYPE_MASK);
-
- switch (status & SCSI_REQ_STATUS_RETRY_TYPE_MASK) {
- case SCSI_REQ_STATUS_RETRY_READ:
- scsi_read_data(&r->req);
- break;
- case SCSI_REQ_STATUS_RETRY_WRITE:
- scsi_write_data(&r->req);
- break;
- case SCSI_REQ_STATUS_RETRY_FLUSH:
- scsi_send_command(&r->req, r->req.cmd.buf);
- break;
- }
- }
- }
-}
-
-static void scsi_dma_restart_cb(void *opaque, int running, RunState state)
-{
- SCSIDiskState *s = opaque;
-
- if (!running) {
- return;
- }
- if (!s->bh) {
- s->bh = qemu_bh_new(scsi_dma_restart_bh, s);
- qemu_bh_schedule(s->bh);
- }
-}
-
/* Return a pointer to the data buffer. */
static uint8_t *scsi_get_buf(SCSIRequest *req)
{
@@ -1591,7 +1530,6 @@ static int scsi_initfn(SCSIDevice *dev)
}
bdrv_set_buffer_alignment(s->qdev.conf.bs, s->qdev.blocksize);
- qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
bdrv_iostatus_enable(s->qdev.conf.bs);
add_boot_device_path(s->qdev.conf.bootindex, &dev->qdev, ",0");
return 0;
diff --git a/hw/scsi.h b/hw/scsi.h
index fcc3455..ff8fdd0 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -3,6 +3,7 @@
#include "qdev.h"
#include "block.h"
+#include "sysemu.h"
#define MAX_SCSI_DEVS 255
@@ -52,6 +53,7 @@ struct SCSIRequest {
uint32_t sense_len;
bool enqueued;
bool io_canceled;
+ bool retry;
void *hba_private;
QTAILQ_ENTRY(SCSIRequest) next;
};
@@ -59,6 +61,8 @@ struct SCSIRequest {
struct SCSIDevice
{
DeviceState qdev;
+ VMChangeStateEntry *vmsentry;
+ QEMUBH *bh;
uint32_t id;
BlockConf conf;
SCSIDeviceInfo *info;
@@ -194,6 +198,7 @@ uint8_t *scsi_req_get_buf(SCSIRequest *req);
int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len);
void scsi_req_abort(SCSIRequest *req, int status);
void scsi_req_cancel(SCSIRequest *req);
+void scsi_req_retry(SCSIRequest *req);
void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense);
int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed);
SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lun);
--
1.7.6.4
next prev parent reply other threads:[~2011-10-31 13:28 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-31 13:29 [Qemu-devel] [PULL 00/55] Block patches Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 01/55] iSCSI block driver Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 02/55] Documentation: Add iSCSI section Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 03/55] Teach block/vdi about "discarded" (no longer allocated) blocks Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 04/55] qcow2: fix some errors and typo in qcow2.txt Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 05/55] block: Remove dead code Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 06/55] block: Fix bdrv_open use after free Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 07/55] qcow: Fix bdrv_write_compressed error handling Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 08/55] ide: Fix off-by-one error in array index check Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 09/55] vmdk: Fix use of uninitialised value Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 10/55] vmdk: Improve error handling Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 11/55] vmdk: Fix possible segfaults Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 12/55] Documentation: Describe NBD URL syntax Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 13/55] block: fix qcow2_co_flush deadlock Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 14/55] qemu-io: delete bs instead of leaking it Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 15/55] block: set bs->read_only before .bdrv_open() Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 16/55] block: reinitialize across bdrv_close()/bdrv_open() Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 17/55] Documentation: Add syntax for using sheepdog devices Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 18/55] scsi: pass correct sense code for ENOMEDIUM Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 19/55] atapi/scsi: unify definitions for MMC Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 20/55] atapi: move GESN definitions to scsi-defs.h Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 21/55] atapi: cleanup/fix mode sense results Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 22/55] scsi: notify the device when unit attention is reported Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 23/55] scsi-disk: report media changed via unit attention sense codes Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 24/55] scsi-disk: fix coding style issues (braces) Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 25/55] scsi-disk: add stubs for more MMC commands Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 26/55] scsi-disk: store valid mode pages in a table Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 27/55] atapi/scsi-disk: make mode page values coherent between the two Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 28/55] scsi-disk: support DVD profile in GET CONFIGURATION Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 29/55] scsi-disk: support READ DVD STRUCTURE Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 30/55] scsi-disk: report media changed via GET EVENT STATUS NOTIFICATION Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 31/55] scsi: move tcq/ndev to SCSIBusOps (now SCSIBusInfo) Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 32/55] qdev: switch children device list to QTAILQ Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 33/55] scsi: remove devs array from SCSIBus Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 34/55] scsi: implement REPORT LUNS for arbitrary LUNs Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 35/55] scsi: allow " Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 36/55] scsi: add channel to addressing Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 37/55] scsi-disk: fail READ CAPACITY if LBA != 0 but PMI == 0 Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 38/55] scsi-disk: fix retrying a flush Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 39/55] scsi-generic: drop SCSIGenericState Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 40/55] scsi-generic: remove scsi_req_fixup Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 41/55] scsi-generic: check ioctl statuses when SG_IO succeeds Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 42/55] scsi-generic: look at host status Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 43/55] scsi-generic: snoop READ CAPACITY commands to get block size Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 44/55] scsi-disk: do not duplicate BlockDriverState member Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 45/55] scsi-disk: remove cluster_size Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 46/55] scsi-disk: small clean up to INQUIRY Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 47/55] scsi: move max_lba to SCSIDevice Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 48/55] scsi: make reqops const Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 49/55] scsi: export scsi_generic_reqops Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 50/55] scsi: pass cdb to alloc_req Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 51/55] scsi: do not call transfer_data after canceling a request Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 52/55] scsi-disk: bump SCSIRequest reference count until aio completion runs Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 53/55] scsi-generic: " Kevin Wolf
2011-10-31 13:30 ` Kevin Wolf [this message]
2011-10-31 13:30 ` [Qemu-devel] [PATCH 55/55] scsi-disk: add scsi-block for device passthrough Kevin Wolf
2011-10-31 16:52 ` [Qemu-devel] [PULL 00/55] Block patches Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1320067830-12093-55-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).