From patchwork Tue Sep 6 15:39:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 113634 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 6776EB6F77 for ; Wed, 7 Sep 2011 03:32:14 +1000 (EST) Received: from localhost ([::1]:57509 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0zVL-0001i0-Pr for incoming@patchwork.ozlabs.org; Tue, 06 Sep 2011 13:32:11 -0400 Received: from eggs.gnu.org ([140.186.70.92]:35517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0zVF-0001h8-D5 for qemu-devel@nongnu.org; Tue, 06 Sep 2011 13:32:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R0zVE-0002qM-Cc for qemu-devel@nongnu.org; Tue, 06 Sep 2011 13:32:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:65295) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0zVE-0002qB-2T for qemu-devel@nongnu.org; Tue, 06 Sep 2011 13:32:04 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p86HVqsI027870 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 6 Sep 2011 13:32:02 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p86FamTe015671; Tue, 6 Sep 2011 11:37:22 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Tue, 6 Sep 2011 17:39:43 +0200 Message-Id: <1315323586-23840-29-git-send-email-kwolf@redhat.com> In-Reply-To: <1315323586-23840-1-git-send-email-kwolf@redhat.com> References: <1315323586-23840-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 28/31] scsi: fix accounting of writes 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 Writes go through scsi_write_complete at least twice, the first time to get some data without having actually written anything. Because of this, the first time scsi_write_complete is called it will call bdrv_acct_done and account a read incorrectly. Fix this by looking at the aiocb. I am doing the same in scsi_read_complete for symmetry, but it is only needed in the (bogus) case of bdrv_aio_readv returning NULL. Signed-off-by: Paolo Bonzini Signed-off-by: Kevin Wolf --- hw/scsi-disk.c | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 5c652a2..c23c2b8 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -111,9 +111,10 @@ static void scsi_read_complete(void * opaque, int ret) SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); int n; - r->req.aiocb = NULL; - - bdrv_acct_done(s->bs, &r->acct); + if (r->req.aiocb != NULL) { + r->req.aiocb = NULL; + bdrv_acct_done(s->bs, &r->acct); + } if (ret) { if (scsi_handle_rw_error(r, -ret, SCSI_REQ_STATUS_RETRY_READ)) { @@ -235,9 +236,10 @@ static void scsi_write_complete(void * opaque, int ret) uint32_t len; uint32_t n; - r->req.aiocb = NULL; - - bdrv_acct_done(s->bs, &r->acct); + if (r->req.aiocb != NULL) { + r->req.aiocb = NULL; + bdrv_acct_done(s->bs, &r->acct); + } if (ret) { if (scsi_handle_rw_error(r, -ret, SCSI_REQ_STATUS_RETRY_WRITE)) {