[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/2] uas: use scsi req refcounting + free_request ca
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [PATCH 2/2] uas: use scsi req refcounting + free_request callback |
Date: |
Mon, 9 Jul 2012 12:33:58 +0200 |
With the new free_request callback for SCSIBusInfo we can use scsi
request refcounting instead of our own for the uas request lifecycle.
Signed-off-by: Gerd Hoffmann <address@hidden>
---
hw/usb/dev-uas.c | 33 ++++++++++-----------------------
1 files changed, 10 insertions(+), 23 deletions(-)
diff --git a/hw/usb/dev-uas.c b/hw/usb/dev-uas.c
index 21fc80e..9b02ff4 100644
--- a/hw/usb/dev-uas.c
+++ b/hw/usb/dev-uas.c
@@ -123,11 +123,11 @@ struct UASRequest {
USBPacket *data;
bool data_async;
bool active;
+ bool complete;
uint32_t buf_off;
uint32_t buf_size;
uint32_t data_off;
uint32_t data_size;
- uint32_t refcount;
QTAILQ_ENTRY(UASRequest) next;
};
@@ -381,7 +381,7 @@ static void usb_uas_start_next_transfer(UASDevice *uas)
UASRequest *req;
QTAILQ_FOREACH(req, &uas->requests, next) {
- if (req->active) {
+ if (req->active || req->complete) {
continue;
}
if (req->req->cmd.mode == SCSI_XFER_FROM_DEV && uas->datain == NULL) {
@@ -408,12 +408,12 @@ static UASRequest *usb_uas_alloc_request(UASDevice *uas,
uas_ui *ui)
req->tag = be16_to_cpu(ui->hdr.tag);
req->lun = be64_to_cpu(ui->command.lun);
req->dev = usb_uas_get_dev(req->uas, req->lun);
- req->refcount = 1;
return req;
}
-static void usb_uas_release_request(UASRequest *req)
+static void usb_uas_scsi_free_request(SCSIBus *bus, void *priv)
{
+ UASRequest *req = priv;
UASDevice *uas = req->uas;
if (req == uas->datain) {
@@ -438,19 +438,6 @@ static UASRequest *usb_uas_find_request(UASDevice *uas,
uint16_t tag)
return NULL;
}
-static void usb_uas_ref_request(UASRequest *req)
-{
- req->refcount++;
-}
-
-static void usb_uas_unref_request(UASRequest *req)
-{
- req->refcount--;
- if (req->refcount == 0) {
- usb_uas_release_request(req);
- }
-}
-
static void usb_uas_scsi_transfer_data(SCSIRequest *r, uint32_t len)
{
UASRequest *req = r->hba_private;
@@ -472,13 +459,12 @@ static void usb_uas_scsi_command_complete(SCSIRequest *r,
UASDevice *uas = req->uas;
trace_usb_uas_scsi_complete(req->uas->dev.addr, req->tag, status, resid);
+ req->complete = true;
if (req->data) {
usb_uas_complete_data_packet(req);
}
usb_uas_queue_sense(req, status);
scsi_req_unref(req->req);
- req->req = NULL;
- usb_uas_unref_request(req);
usb_uas_start_next_transfer(uas);
}
@@ -487,7 +473,7 @@ static void usb_uas_scsi_request_cancelled(SCSIRequest *r)
UASRequest *req = r->hba_private;
/* FIXME: queue notification to status pipe? */
- usb_uas_unref_request(req);
+ scsi_req_unref(req->req);
}
static const struct SCSIBusInfo usb_uas_scsi_info = {
@@ -498,6 +484,7 @@ static const struct SCSIBusInfo usb_uas_scsi_info = {
.transfer_data = usb_uas_scsi_transfer_data,
.complete = usb_uas_scsi_command_complete,
.cancel = usb_uas_scsi_request_cancelled,
+ .free_request = usb_uas_scsi_free_request,
};
/* --------------------------------------------------------------------- */
@@ -706,17 +693,17 @@ static int usb_uas_handle_data(USBDevice *dev, USBPacket
*p)
ret = USB_RET_STALL;
break;
}
- usb_uas_ref_request(req);
+ scsi_req_ref(req->req);
req->data = p;
usb_uas_copy_data(req);
- if (p->result == p->iov.size || req->req == NULL) {
+ if (p->result == p->iov.size || req->complete) {
req->data = NULL;
ret = p->result;
} else {
req->data_async = true;
ret = USB_RET_ASYNC;
}
- usb_uas_unref_request(req);
+ scsi_req_unref(req->req);
usb_uas_start_next_transfer(uas);
break;
default:
--
1.7.1