qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] buffer alignment for block backends


From: Stefano Stabellini
Subject: Re: [Qemu-devel] buffer alignment for block backends
Date: Thu, 09 Apr 2009 11:07:28 +0100
User-agent: Thunderbird 2.0.0.14 (X11/20080505)

Anthony Liguori wrote:

>> If you do not want to do that, another possible solution is to create a
>> new function called "qemu_blockalign" that would be implemented as
>> qemu_memalign(512, size);
> 
> This is fine, but this is purely an optimization, it cannot be relied 
> upon in the general case.
> 



If you are OK with this, a simple patch like the following is
acceptable, or do you prefer a more formal approach involving a new
function in the BlockDriver interface?

---

diff --git a/block.c b/block.c
index 74d19ad..1fdcfef 100644
--- a/block.c
+++ b/block.c
@@ -1376,7 +1376,7 @@ static BlockDriverAIOCB 
*bdrv_aio_rw_vector(BlockDriverState *bs,
     acb = qemu_aio_get(bs, cb, opaque);
     acb->is_write = is_write;
     acb->qiov = qiov;
-    acb->bounce = qemu_memalign(512, qiov->size);
+    acb->bounce = qemu_blockalign(qiov->size);
 
     if (!acb->bh)
         acb->bh = qemu_bh_new(bdrv_aio_bh_cb, acb);
@@ -1626,3 +1626,9 @@ BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
         return drv->bdrv_aio_ioctl(bs, req, buf, cb, opaque);
     return NULL;
 }
+
+void *qemu_blockalign(size_t size)
+{
+    return qemu_memalign(512, size);
+}
+
diff --git a/block.h b/block.h
index ca672a1..dba9f9d 100644
--- a/block.h
+++ b/block.h
@@ -176,4 +176,6 @@ int bdrv_put_buffer(BlockDriverState *bs, const uint8_t 
*buf,
 
 int bdrv_get_buffer(BlockDriverState *bs, uint8_t *buf, int64_t pos, int size);
 
+void *qemu_blockalign(size_t size);
+
 #endif
diff --git a/hw/ide.c b/hw/ide.c
index f187546..93b90b8 100644
--- a/hw/ide.c
+++ b/hw/ide.c
@@ -2788,7 +2788,7 @@ static void ide_init2(IDEState *ide_state,
 
     for(i = 0; i < 2; i++) {
         s = ide_state + i;
-        s->io_buffer = qemu_memalign(512, IDE_DMA_BUF_SECTORS*512 + 4);
+        s->io_buffer = qemu_blockalign(IDE_DMA_BUF_SECTORS*512 + 4);
         if (i == 0)
             s->bs = hd0;
         else




reply via email to

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