From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LwivP-000490-Ob for qemu-devel@nongnu.org; Wed, 22 Apr 2009 16:20:07 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LwivP-00048h-0t for qemu-devel@nongnu.org; Wed, 22 Apr 2009 16:20:07 -0400 Received: from [199.232.76.173] (port=52906 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LwivO-00048d-Tv for qemu-devel@nongnu.org; Wed, 22 Apr 2009 16:20:06 -0400 Received: from savannah.gnu.org ([199.232.41.3]:39463 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LwivO-0008Fp-Iw for qemu-devel@nongnu.org; Wed, 22 Apr 2009 16:20:06 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LwivL-0007on-0I for qemu-devel@nongnu.org; Wed, 22 Apr 2009 20:20:04 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LwivJ-0007nb-19 for qemu-devel@nongnu.org; Wed, 22 Apr 2009 20:20:01 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Wed, 22 Apr 2009 20:20:01 +0000 Subject: [Qemu-devel] [7229] implement qemu_blockalign (Stefano Stabellini) List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 7229 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7229 Author: aliguori Date: 2009-04-22 20:20:00 +0000 (Wed, 22 Apr 2009) Log Message: ----------- implement qemu_blockalign (Stefano Stabellini) this patch adds a buffer_alignment field to BlockDriverState and implements a qemu_blockalign function that uses that field to allocate a memory aligned buffer to be used by the block driver. buffer_alignment is initialized to 512 but each block driver can set a different value (at the moment none of them do). This patch modifies ide.c, block-qcow.c, block-qcow2.c and block.c to use qemu_blockalign instead of qemu_memalign. There is only one place left that still uses qemu_memalign to allocate buffers used by block drivers that is posix-aio-compat:handle_aiocb_rw because it is not possible to get the BlockDriverState from that function. However I think it is not important because posix-aio-compat already deals with driver specific code so it is supposed to know its own needs. Signed-off-by: Stefano Stabellini Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/block-qcow.c trunk/block-qcow2.c trunk/block-raw-posix.c trunk/block.c trunk/block_int.h trunk/hw/ide.c Modified: trunk/block-qcow.c =================================================================== --- trunk/block-qcow.c 2009-04-22 15:19:53 UTC (rev 7228) +++ trunk/block-qcow.c 2009-04-22 20:20:00 UTC (rev 7229) @@ -641,7 +641,7 @@ acb->sector_num = sector_num; acb->qiov = qiov; if (qiov->niov > 1) - acb->buf = acb->orig_buf = qemu_memalign(512, qiov->size); + acb->buf = acb->orig_buf = qemu_blockalign(bs, qiov->size); else acb->buf = (uint8_t *)qiov->iov->iov_base; acb->nb_sectors = nb_sectors; @@ -736,7 +736,7 @@ acb->sector_num = sector_num; acb->qiov = qiov; if (qiov->niov > 1) { - acb->buf = acb->orig_buf = qemu_memalign(512, qiov->size); + acb->buf = acb->orig_buf = qemu_blockalign(bs, qiov->size); qemu_iovec_to_buffer(qiov, acb->buf); } else { acb->buf = (uint8_t *)qiov->iov->iov_base; Modified: trunk/block-qcow2.c =================================================================== --- trunk/block-qcow2.c 2009-04-22 15:19:53 UTC (rev 7228) +++ trunk/block-qcow2.c 2009-04-22 20:20:00 UTC (rev 7229) @@ -1412,7 +1412,7 @@ acb->sector_num = sector_num; acb->qiov = qiov; if (qiov->niov > 1) { - acb->buf = acb->orig_buf = qemu_memalign(512, qiov->size); + acb->buf = acb->orig_buf = qemu_blockalign(bs, qiov->size); if (is_write) qemu_iovec_to_buffer(qiov, acb->buf); } else { Modified: trunk/block-raw-posix.c =================================================================== --- trunk/block-raw-posix.c 2009-04-22 15:19:53 UTC (rev 7228) +++ trunk/block-raw-posix.c 2009-04-22 20:20:00 UTC (rev 7229) @@ -165,7 +165,7 @@ s->fd = fd; s->aligned_buf = NULL; if ((flags & BDRV_O_NOCACHE)) { - s->aligned_buf = qemu_memalign(512, ALIGNED_BUFFER_SIZE); + s->aligned_buf = qemu_blockalign(bs, ALIGNED_BUFFER_SIZE); if (s->aligned_buf == NULL) { ret = -errno; close(fd); Modified: trunk/block.c =================================================================== --- trunk/block.c 2009-04-22 15:19:53 UTC (rev 7228) +++ trunk/block.c 2009-04-22 20:20:00 UTC (rev 7229) @@ -362,6 +362,8 @@ bs->is_temporary = 0; bs->encrypted = 0; bs->valid_key = 0; + /* buffer_alignment defaulted to 512, drivers can change this value */ + bs->buffer_alignment = 512; if (flags & BDRV_O_SNAPSHOT) { BlockDriverState *bs1; @@ -1390,7 +1392,7 @@ 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(bs, qiov->size); if (!acb->bh) acb->bh = qemu_bh_new(bdrv_aio_bh_cb, acb); @@ -1640,3 +1642,8 @@ return drv->bdrv_aio_ioctl(bs, req, buf, cb, opaque); return NULL; } + +void *qemu_blockalign(BlockDriverState *bs, size_t size) +{ + return qemu_memalign((bs && bs->buffer_alignment) ? bs->buffer_alignment : 512, size); +} Modified: trunk/block_int.h =================================================================== --- trunk/block_int.h 2009-04-22 15:19:53 UTC (rev 7228) +++ trunk/block_int.h 2009-04-22 20:20:00 UTC (rev 7229) @@ -145,6 +145,9 @@ /* Whether the disk can expand beyond total_sectors */ int growable; + /* the memory alignment required for the buffers handled by this driver */ + int buffer_alignment; + /* NOTE: the following infos are only hints for real hardware drivers. They are not used by the block driver */ int cyls, heads, secs, translation; @@ -173,6 +176,8 @@ BlockDriverCompletionFunc *cb, void *opaque); void qemu_aio_release(void *p); +void *qemu_blockalign(BlockDriverState *bs, size_t size); + extern BlockDriverState *bdrv_first; #endif /* BLOCK_INT_H */ Modified: trunk/hw/ide.c =================================================================== --- trunk/hw/ide.c 2009-04-22 15:19:53 UTC (rev 7228) +++ trunk/hw/ide.c 2009-04-22 20:20:00 UTC (rev 7229) @@ -2788,11 +2788,11 @@ for(i = 0; i < 2; i++) { s = ide_state + i; - s->io_buffer = qemu_memalign(512, IDE_DMA_BUF_SECTORS*512 + 4); if (i == 0) s->bs = hd0; else s->bs = hd1; + s->io_buffer = qemu_blockalign(s->bs, IDE_DMA_BUF_SECTORS*512 + 4); if (s->bs) { bdrv_get_geometry(s->bs, &nb_sectors); bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);