From patchwork Tue May 4 12:20:59 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 51599 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1FFEFB7D28 for ; Tue, 4 May 2010 22:33:29 +1000 (EST) Received: from localhost ([127.0.0.1]:58703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9HIX-00009z-5M for incoming@patchwork.ozlabs.org; Tue, 04 May 2010 08:32:25 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O9H7s-0005Pw-TL for qemu-devel@nongnu.org; Tue, 04 May 2010 08:21:25 -0400 Received: from [140.186.70.92] (port=50525 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9H7l-0005MR-7S for qemu-devel@nongnu.org; Tue, 04 May 2010 08:21:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O9H7b-0008Vu-8l for qemu-devel@nongnu.org; Tue, 04 May 2010 08:21:17 -0400 Received: from thoth.sbs.de ([192.35.17.2]:16838) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O9H7a-0008US-Rr for qemu-devel@nongnu.org; Tue, 04 May 2010 08:21:07 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.12.11.20060308/8.12.11) with ESMTP id o44CL4MD019597; Tue, 4 May 2010 14:21:05 +0200 Received: from localhost.localdomain (mchn012c.mchp.siemens.de [139.25.109.167] (may be forged)) by mail1.siemens.de (8.12.11.20060308/8.12.11) with ESMTP id o44CL3ew030959; Tue, 4 May 2010 14:21:04 +0200 From: Jan Kiszka To: Anthony Liguori Date: Tue, 4 May 2010 14:20:59 +0200 Message-Id: X-Mailer: git-send-email 1.6.0.2 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: qemu-devel@nongnu.org, Gerd Hoffmann Subject: [Qemu-devel] [PATCH 1/5] SCSI: Add disk reset handler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Ensure that pending requests of an SCSI disk are purged on system reset and also restore max_lba. The latter is no only present in the reset handler as that one is called after init as well. Signed-off-by: Jan Kiszka --- hw/scsi-disk.c | 35 +++++++++++++++++++++++++++-------- 1 files changed, 27 insertions(+), 8 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 77cb1da..b8d805f 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1010,22 +1010,45 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, } } -static void scsi_destroy(SCSIDevice *dev) +static void scsi_disk_purge_requests(SCSIDiskState *s) { - SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); 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_remove_request(r); } +} + +static void scsi_disk_reset(DeviceState *dev) +{ + SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev.qdev, dev); + uint64_t nb_sectors; + + scsi_disk_purge_requests(s); + + bdrv_get_geometry(s->bs, &nb_sectors); + nb_sectors /= s->cluster_size; + if (nb_sectors) { + nb_sectors--; + } + s->max_lba = nb_sectors; +} + +static void scsi_destroy(SCSIDevice *dev) +{ + SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); + + scsi_disk_purge_requests(s); drive_uninit(s->qdev.conf.dinfo); } static int scsi_disk_initfn(SCSIDevice *dev) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); - uint64_t nb_sectors; if (!s->qdev.conf.dinfo || !s->qdev.conf.dinfo->bdrv) { error_report("scsi-disk: drive property not set"); @@ -1046,11 +1069,6 @@ static int scsi_disk_initfn(SCSIDevice *dev) s->cluster_size = s->qdev.blocksize / 512; s->qdev.type = TYPE_DISK; - bdrv_get_geometry(s->bs, &nb_sectors); - nb_sectors /= s->cluster_size; - if (nb_sectors) - nb_sectors--; - s->max_lba = nb_sectors; qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s); return 0; } @@ -1059,6 +1077,7 @@ static SCSIDeviceInfo scsi_disk_info = { .qdev.name = "scsi-disk", .qdev.desc = "virtual scsi disk or cdrom", .qdev.size = sizeof(SCSIDiskState), + .qdev.reset = scsi_disk_reset, .init = scsi_disk_initfn, .destroy = scsi_destroy, .send_command = scsi_send_command,