From patchwork Thu May 26 10:56:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 97538 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EA54EB6F70 for ; Thu, 26 May 2011 20:57:38 +1000 (EST) Received: from localhost ([::1]:35159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPYFy-0002PV-9n for incoming@patchwork.ozlabs.org; Thu, 26 May 2011 06:57:34 -0400 Received: from eggs.gnu.org ([140.186.70.92]:56004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPYFY-0002Fi-PG for qemu-devel@nongnu.org; Thu, 26 May 2011 06:57:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QPYFX-0003ZK-E2 for qemu-devel@nongnu.org; Thu, 26 May 2011 06:57:08 -0400 Received: from mail-wy0-f173.google.com ([74.125.82.173]:47990) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPYFX-0003Ru-9Z for qemu-devel@nongnu.org; Thu, 26 May 2011 06:57:07 -0400 Received: by mail-wy0-f173.google.com with SMTP id 42so463044wyb.4 for ; Thu, 26 May 2011 03:57:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:subject:date:message-id:x-mailer :in-reply-to:references; bh=JrmoGduIA7W6BJQkyCD/zxUknmN11/g15c6KyHy0/x0=; b=hwPgW3ZsKxOUlet8oEwU7MSzH98OnBw2yhBTT59vRHMCRzVYgzB07COaUcNauXD+s+ hSy2SGKjHvQv9QB4RTf8EbO1c2XV/m9mekbvvKPmFHq88LZb3TNP2g07vFBBuxrGfPyE 9noVWZzDSPVnKIiOfzjG1JPMS4T8dvVkCjQgk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; b=LoDI03fJb3t3vZSA2PpSaI470w17A3gNrHOWJtTgig+Gk8pTSk663EQugG+SIZGnfM BVZyt0W4RgDTdbYAxqQpT0C0c/U6HVipKXXLVe5sa/biG4U7kw7Mr3sdbkLNsJCoekjh DQPRxPptsZej+MdaupUPkR/Z5+5yUy0XrAMBY= Received: by 10.216.235.133 with SMTP id u5mr4296982weq.101.1306407426157; Thu, 26 May 2011 03:57:06 -0700 (PDT) Received: from localhost.localdomain (93-34-184-88.ip51.fastwebnet.it [93.34.184.88]) by mx.google.com with ESMTPS id k16sm293060wed.8.2011.05.26.03.57.05 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 May 2011 03:57:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 26 May 2011 12:56:35 +0200 Message-Id: <1306407411-4290-10-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1306407411-4290-1-git-send-email-pbonzini@redhat.com> References: <1306407411-4290-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 74.125.82.173 Subject: [Qemu-devel] [PATCH v5 09/25] scsi: commonize purging requests 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 The code for canceling requests upon reset is already the same. Clean it up and move it to scsi-bus.c. Signed-off-by: Paolo Bonzini Reviewed-by: Christoph Hellwig --- hw/scsi-bus.c | 12 ++++++++++++ hw/scsi-disk.c | 18 ++---------------- hw/scsi-generic.c | 18 ++---------------- hw/scsi.h | 1 + 4 files changed, 17 insertions(+), 32 deletions(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 46f60e1..cb3ba5f 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -549,6 +549,18 @@ void scsi_req_complete(SCSIRequest *req) scsi_req_unref(req); } +void scsi_device_purge_requests(SCSIDevice *sdev) +{ + SCSIRequest *req; + + while (!QTAILQ_EMPTY(&sdev->requests)) { + req = QTAILQ_FIRST(&sdev->requests); + sdev->info->cancel_io(req); + scsi_req_dequeue(req); + scsi_req_unref(req); + } +} + static char *scsibus_get_fw_dev_path(DeviceState *dev) { SCSIDevice *d = (SCSIDevice*)dev; diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index f7c09c9..38fbb05 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1147,26 +1147,12 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf) return len; } -static void scsi_disk_purge_requests(SCSIDiskState *s) -{ - SCSIDiskReq *r; - - while (!QTAILQ_EMPTY(&s->qdev.requests)) { - r = DO_UPCAST(SCSIDiskReq, req, QTAILQ_FIRST(&s->qdev.requests)); - if (r->req.aiocb) { - bdrv_aio_cancel(r->req.aiocb); - } - scsi_req_dequeue(&r->req); - scsi_req_unref(&r->req); - } -} - static void scsi_disk_reset(DeviceState *dev) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev.qdev, dev); uint64_t nb_sectors; - scsi_disk_purge_requests(s); + scsi_device_purge_requests(&s->qdev); bdrv_get_geometry(s->bs, &nb_sectors); nb_sectors /= s->cluster_size; @@ -1180,7 +1166,7 @@ static void scsi_destroy(SCSIDevice *dev) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); - scsi_disk_purge_requests(s); + scsi_device_purge_requests(&s->qdev); blockdev_mark_auto_del(s->qdev.conf.bs); } diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c index 3740432..72c4cc7 100644 --- a/hw/scsi-generic.c +++ b/hw/scsi-generic.c @@ -424,32 +424,18 @@ static int get_stream_blocksize(BlockDriverState *bdrv) return (buf[9] << 16) | (buf[10] << 8) | buf[11]; } -static void scsi_generic_purge_requests(SCSIGenericState *s) -{ - SCSIGenericReq *r; - - while (!QTAILQ_EMPTY(&s->qdev.requests)) { - r = DO_UPCAST(SCSIGenericReq, req, QTAILQ_FIRST(&s->qdev.requests)); - if (r->req.aiocb) { - bdrv_aio_cancel(r->req.aiocb); - } - scsi_req_dequeue(&r->req); - scsi_req_unref(&r->req); - } -} - static void scsi_generic_reset(DeviceState *dev) { SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev.qdev, dev); - scsi_generic_purge_requests(s); + scsi_device_purge_requests(&s->qdev); } static void scsi_destroy(SCSIDevice *d) { SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d); - scsi_generic_purge_requests(s); + scsi_device_purge_requests(&s->qdev); blockdev_mark_auto_del(s->qdev.conf.bs); } diff --git a/hw/scsi.h b/hw/scsi.h index 19bd1ae..f1d8888 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -114,5 +114,6 @@ int scsi_req_parse(SCSIRequest *req, uint8_t *buf); void scsi_req_print(SCSIRequest *req); void scsi_req_data(SCSIRequest *req, int len); void scsi_req_complete(SCSIRequest *req); +void scsi_device_purge_requests(SCSIDevice *sdev); #endif