qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 4/4] Reallocate dma buffers in read/write path if ne


From: Ryan Harper
Subject: [Qemu-devel] [PATCH 4/4] Reallocate dma buffers in read/write path if needed
Date: Fri, 3 Oct 2008 17:05:31 -0500

The default buffer size breaks up larger read/write requests unnecessarily.
When we encounter requests larger than the default dma buffer, reallocate the
buffer to support the request.

Signed-off-by: Ryan Harper <address@hidden>


diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index f2b4814..a94f10a 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -192,10 +192,14 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag)
     }
 
     n = r->sector_count;
-    if (n > SCSI_DMA_BUF_SIZE / 512)
-        n = SCSI_DMA_BUF_SIZE / 512;
-
     r->buf_len = n * 512;
+
+    /* if the request is larger than the default, allocate a larger buffer */
+    if (r->buf_len > SCSI_DMA_BUF_SIZE) {
+        qemu_free(r->dma_buf);
+        r->dma_buf = qemu_memalign(512, r->buf_len);
+    }
+
     r->aiocb = bdrv_aio_read(s->bdrv, r->sector, r->dma_buf, n,
                              scsi_read_complete, r);
     if (r->aiocb == NULL)
@@ -224,7 +228,7 @@ static int scsi_write_data(SCSIDevice *d, uint32_t tag)
 {
     SCSIDeviceState *s = d->state;
     SCSIRequest *r;
-    uint32_t n, len;
+    uint32_t n;
 
     DPRINTF("Write data tag=0x%x\n", tag);
     r = scsi_find_request(s, tag);
@@ -243,10 +247,13 @@ static int scsi_write_data(SCSIDevice *d, uint32_t tag)
 
     /* 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;
+    r->buf_len = r->sector_count * 512;
+
+    /* if the request is larger than the default, allocate a larger buffer */
+    if (r->buf_len > SCSI_DMA_BUF_SIZE) {
+        qemu_free(r->dma_buf);
+        r->dma_buf = qemu_memalign(512, r->buf_len);
+    }
 
     /* number of sectors to submit */
     n = r->buf_len / 512;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]