From mboxrd@z Thu Jan 1 00:00:00 1970 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 From: Kevin Wolf 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> Subject: [Qemu-devel] [PATCH 28/31] scsi: fix accounting of writes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@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)) { -- 1.7.6