From patchwork Mon Jul 9 10:06:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 169737 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 0640C2C0209 for ; Mon, 9 Jul 2012 20:06:58 +1000 (EST) Received: from localhost ([::1]:57028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoArn-0006rb-Qb for incoming@patchwork.ozlabs.org; Mon, 09 Jul 2012 06:06:55 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48870) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoArd-0006r9-LW for qemu-devel@nongnu.org; Mon, 09 Jul 2012 06:06:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SoArY-0008B8-UJ for qemu-devel@nongnu.org; Mon, 09 Jul 2012 06:06:45 -0400 Received: from mail-gh0-f173.google.com ([209.85.160.173]:36503) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoArY-0008At-Nw for qemu-devel@nongnu.org; Mon, 09 Jul 2012 06:06:40 -0400 Received: by ghrr14 with SMTP id r14so10699165ghr.4 for ; Mon, 09 Jul 2012 03:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=MkNZzXvGtgmn72JHjS+ZcxwH8sGkKJZivK5ZX9mteB4=; b=bMdErzraDVJKx3nD09d4MudzMBnqeSHWmgYnt1IlpY0TqwyTbA+ohxhrCVMrlPP/eZ Ja5jwXjjAiwQUq0/vLs+xc8aJi4esSIVeiNY7saG6zHHqhIvELAYA6mEt7oPAPbUS1E9 H+mF3qAdK7sIw3hvV9j2EjrXys3gFZfgXEyqrw0+5lmEIPwr2XGZnSuomYq5MMZJS2Qw enAg5P0oshlc2WDM5MYcv2Ul7U/721VZprnIwMXz+O5ZdOBtOIM515iSN70onOL6O+ee HKzXSIwqaGKuygEH/WAUHTuASPe/ANUiO1ofbQLJ1x2sKeqNi2Z6iwS1O8PxDXz4Iz4J lkPw== Received: by 10.66.77.71 with SMTP id q7mr64525257paw.0.1341828398703; Mon, 09 Jul 2012 03:06:38 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-189-113.ip51.fastwebnet.it. [93.34.189.113]) by mx.google.com with ESMTPS id gk3sm25928082pbc.69.2012.07.09.03.06.35 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 09 Jul 2012 03:06:37 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 9 Jul 2012 12:06:28 +0200 Message-Id: <1341828388-30511-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.10.2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.173 Cc: kraxel@redhat.com Subject: [Qemu-devel] [PATCH] 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 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 --- 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"