From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LrrAM-0005mp-GB for qemu-devel@nongnu.org; Thu, 09 Apr 2009 06:07:26 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LrrAH-0005mc-Bl for qemu-devel@nongnu.org; Thu, 09 Apr 2009 06:07:25 -0400 Received: from [199.232.76.173] (port=40130 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LrrAG-0005mZ-W2 for qemu-devel@nongnu.org; Thu, 09 Apr 2009 06:07:21 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:27270) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LrrAG-0003zp-Ij for qemu-devel@nongnu.org; Thu, 09 Apr 2009 06:07:20 -0400 Received: from [10.80.225.184] ([10.80.225.184]) by smtp01.ad.xensource.com (8.13.1/8.13.1) with ESMTP id n39A7CVf001039 for ; Thu, 9 Apr 2009 03:07:12 -0700 Message-ID: <49DDC8E0.50900@eu.citrix.com> Date: Thu, 09 Apr 2009 11:07:28 +0100 From: Stefano Stabellini MIME-Version: 1.0 Subject: Re: [Qemu-devel] buffer alignment for block backends References: <49DCA80A.1020808@eu.citrix.com> <49DCF2C0.9070704@codemonkey.ws> In-Reply-To: <49DCF2C0.9070704@codemonkey.ws> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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" 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