From patchwork Thu Jul 12 13:08:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 170651 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 325AD2C021D for ; Thu, 12 Jul 2012 23:09:13 +1000 (EST) Received: from localhost ([::1]:41403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SpJ8p-0006Ai-0x for incoming@patchwork.ozlabs.org; Thu, 12 Jul 2012 09:09:11 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SpJ8T-0005vX-Ou for qemu-devel@nongnu.org; Thu, 12 Jul 2012 09:08:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SpJ8M-0007iM-DK for qemu-devel@nongnu.org; Thu, 12 Jul 2012 09:08:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19057) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SpJ8M-0007hd-4n for qemu-devel@nongnu.org; Thu, 12 Jul 2012 09:08:42 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6CD8fkv009131 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 12 Jul 2012 09:08:41 -0400 Received: from rincewind.home.kraxel.org (ovpn-116-66.ams2.redhat.com [10.36.116.66]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q6CD8dCR020360; Thu, 12 Jul 2012 09:08:40 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 4FAF541221; Thu, 12 Jul 2012 15:08:39 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 12 Jul 2012 15:08:34 +0200 Message-Id: <1342098519-23261-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1342098519-23261-1-git-send-email-kraxel@redhat.com> References: <1342098519-23261-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Gerd Hoffmann Subject: [Qemu-devel] [PATCH 1/6] scsi: add free_request callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Paolo Bonzini 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 Signed-off-by: Gerd Hoffmann --- hw/scsi-bus.c | 5 +++++ hw/scsi.h | 1 + 2 files changed, 6 insertions(+), 0 deletions(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 5ad1013..dc74063 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -1354,6 +1354,7 @@ static const char *scsi_command_name(uint8_t cmd) SCSIRequest *scsi_req_ref(SCSIRequest *req) { + assert(req->refcount > 0); req->refcount++; return req; } @@ -1362,6 +1363,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 76f06d4..367a346 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -134,6 +134,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"