From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KlsmP-0002pu-80 for qemu-devel@nongnu.org; Fri, 03 Oct 2008 18:05:45 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KlsmN-0002p6-5Q for qemu-devel@nongnu.org; Fri, 03 Oct 2008 18:05:43 -0400 Received: from [199.232.76.173] (port=51474 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KlsmM-0002p3-Vc for qemu-devel@nongnu.org; Fri, 03 Oct 2008 18:05:43 -0400 Received: from e33.co.us.ibm.com ([32.97.110.151]:36354) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KlsmM-0007MO-1q for qemu-devel@nongnu.org; Fri, 03 Oct 2008 18:05:42 -0400 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e33.co.us.ibm.com (8.13.8/8.13.8) with ESMTP id m93M5eS2002230 for ; Fri, 3 Oct 2008 18:05:40 -0400 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id m93M5eSx123030 for ; Fri, 3 Oct 2008 16:05:40 -0600 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m93M5eO4001356 for ; Fri, 3 Oct 2008 16:05:40 -0600 From: Ryan Harper Date: Fri, 3 Oct 2008 17:05:30 -0500 Message-Id: <1223071531-31817-4-git-send-email-ryanh@us.ibm.com> In-Reply-To: <1223071531-31817-1-git-send-email-ryanh@us.ibm.com> References: <1223071531-31817-1-git-send-email-ryanh@us.ibm.com> Subject: [Qemu-devel] [PATCH 3/4] Refactor scsi-disk layer for queue'ing writes Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Ryan Harper , kvm@vger.kernel.org Refactor scsi write path to match the simpler, faster scsi read path. No need to call into the write completion function to calculate the request buf length. Signed-off-by: Ryan Harper diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 16b3215..f2b4814 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -208,25 +208,14 @@ static void scsi_write_complete(void * opaque, int ret) { SCSIRequest *r = (SCSIRequest *)opaque; SCSIDeviceState *s = r->dev; - uint32_t len; if (ret) { fprintf(stderr, "scsi-disc: IO write error\n"); exit(1); } - r->aiocb = NULL; - if (r->sector_count == 0) { - scsi_command_complete(r, SENSE_NO_SENSE); - } else { - len = r->sector_count * 512; - if (len > SCSI_DMA_BUF_SIZE) { - len = SCSI_DMA_BUF_SIZE; - } - r->buf_len = len; - DPRINTF("Write complete tag=0x%x more=%d\n", r->tag, len); - s->completion(s->opaque, SCSI_REASON_DATA, r->tag, len); - } + DPRINTF("Write complete tag=0x%x more=%d\n", r->tag, r->buf_len); + s->completion(s->opaque, SCSI_REASON_DATA, r->tag, r->buf_len); } /* Write data to a scsi device. Returns nonzero on failure. @@ -235,7 +224,7 @@ static int scsi_write_data(SCSIDevice *d, uint32_t tag) { SCSIDeviceState *s = d->state; SCSIRequest *r; - uint32_t n; + uint32_t n, len; DPRINTF("Write data tag=0x%x\n", tag); r = scsi_find_request(s, tag); @@ -244,8 +233,22 @@ static int scsi_write_data(SCSIDevice *d, uint32_t tag) scsi_command_complete(r, SENSE_HARDWARE_ERROR); return 1; } + DPRINTF("Write sector_count=%d\n", r->sector_count); + if (r->sector_count == 0) { + scsi_command_complete(r, SENSE_NO_SENSE); + return 0; + } if (r->aiocb) BADF("Data transfer already in progress\n"); + + /* we know the len of the request and with the max size of the scsi buffer, + * we can calculate buf_len needed */ + len = r->sector_count * 512; + if (len > SCSI_DMA_BUF_SIZE) + len = SCSI_DMA_BUF_SIZE; + r->buf_len = len; + + /* number of sectors to submit */ n = r->buf_len / 512; if (n) { r->aiocb = bdrv_aio_write(s->bdrv, r->sector, r->dma_buf, n,