From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:34994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0bmI-0003i9-O5 for qemu-devel@nongnu.org; Mon, 05 Sep 2011 12:12:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R0bmF-00041N-TU for qemu-devel@nongnu.org; Mon, 05 Sep 2011 12:12:06 -0400 Received: from mail-gw0-f45.google.com ([74.125.83.45]:64013) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0bmF-00041F-R2 for qemu-devel@nongnu.org; Mon, 05 Sep 2011 12:12:03 -0400 Received: by gwb19 with SMTP id 19so3289353gwb.4 for ; Mon, 05 Sep 2011 09:12:03 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 5 Sep 2011 18:11:51 +0200 Message-Id: <1315239111-13874-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH] scsi: fix accounting of writes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: hch@lst.de 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 --- 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 dba1cfa..bdeba14 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -149,9 +149,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)) { @@ -254,9 +255,10 @@ static void scsi_write_complete(void * opaque, int ret) SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); 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