* [Qemu-devel] [PATCH] scsi: add free_request callback
@ 2012-07-09 10:06 Paolo Bonzini
0 siblings, 0 replies; only message in thread
From: Paolo Bonzini @ 2012-07-09 10:06 UTC (permalink / raw)
To: qemu-devel; +Cc: kraxel
Most device models have a simple lifecycle for the hba_private field
and they can free it when a request is completed or cancelled.
However, in some cases it may be simpler to tie the lifetime
of hba_private to that of the included SCSIRequest. This patch
adds a free_request callback to SCSIBusInfo that lets an HBA
device model do exactly that.
Normally, device models use req->hba_private == NULL to flag requests
that have been completed already. Device models that use free_request
will still need to track this using a flag. This is the reason why
"converting" existing HBAs to use free_request adds complexity and
makes little sense. It is simply an additional convenience that is
provided by the SCSI layer. USB-attached storage will be the first
user.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi-bus.c | 5 +++++
hw/scsi.h | 1 +
2 files changed, 6 insertions(+)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index 559a815..b9f0a5d 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -1358,6 +1358,7 @@ static const char *scsi_command_name(uint8_t cmd)
SCSIRequest *scsi_req_ref(SCSIRequest *req)
{
+ assert(req->refcount > 0);
req->refcount++;
return req;
}
@@ -1366,6 +1367,10 @@ void scsi_req_unref(SCSIRequest *req)
{
assert(req->refcount > 0);
if (--req->refcount == 0) {
+ SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, req->dev->qdev.parent_bus);
+ if (bus->info->free_request && req->hba_private) {
+ bus->info->free_request(bus, req->hba_private);
+ }
if (req->ops->free_req) {
req->ops->free_req(req);
}
diff --git a/hw/scsi.h b/hw/scsi.h
index dd1cd45..a445724 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -136,6 +136,7 @@ struct SCSIBusInfo {
void (*save_request)(QEMUFile *f, SCSIRequest *req);
void *(*load_request)(QEMUFile *f, SCSIRequest *req);
+ void (*free_request)(SCSIBus *bus, void *priv);
};
#define TYPE_SCSI_BUS "SCSI"
--
1.7.10.2
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2012-07-09 10:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-09 10:06 [Qemu-devel] [PATCH] scsi: add free_request callback 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).