From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 2/2] uas: use scsi req refcounting + free_request callback
Date: Mon, 9 Jul 2012 12:33:58 +0200 [thread overview]
Message-ID: <1341830038-27504-3-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1341830038-27504-1-git-send-email-kraxel@redhat.com>
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 <kraxel@redhat.com>
---
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
next prev parent reply other threads:[~2012-07-09 10:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-09 10:33 [Qemu-devel] [PATCH 0/2] usb/scsi: usb attached scsi emulation Gerd Hoffmann
2012-07-09 10:33 ` [Qemu-devel] [PATCH 1/2] usb: add " Gerd Hoffmann
2012-07-09 10:33 ` Gerd Hoffmann [this message]
2012-07-09 10:39 ` [Qemu-devel] [PATCH 0/2] usb/scsi: " Gerd Hoffmann
2012-07-09 10:45 ` Paolo Bonzini
2012-07-09 12:22 ` Gerd Hoffmann
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=1341830038-27504-3-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=pbonzini@redhat.com \
--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).