Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kvxn3-0002DS-8J for qemu-devel@nongnu.org; Fri, 31 Oct 2008 13:28:05 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kvxn2-0002DE-MH for qemu-devel@nongnu.org; Fri, 31 Oct 2008 13:28:04 -0400 Received: from [199.232.76.173] (port=57592 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kvxn2-0002DB-H1 for qemu-devel@nongnu.org; Fri, 31 Oct 2008 13:28:04 -0400 Received: from savannah.gnu.org ([199.232.41.3]:46567 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 1Kvxn1-0004Q3-Qm for qemu-devel@nongnu.org; Fri, 31 Oct 2008 13:28:04 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1Kvxmz-00040o-08 for qemu-devel@nongnu.org; Fri, 31 Oct 2008 17:28:01 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1Kvxmy-00040g-P4 for qemu-devel@nongnu.org; Fri, 31 Oct 2008 17:28:00 +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: Fri, 31 Oct 2008 17:28:00 +0000 Subject: [Qemu-devel] [5574] fix bdrv_aio_read API breakage in qcow2 (Andrea Arcangeli) 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 Revision: 5574 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5574 Author: aliguori Date: 2008-10-31 17:28:00 +0000 (Fri, 31 Oct 2008) Log Message: ----------- fix bdrv_aio_read API breakage in qcow2 (Andrea Arcangeli) I noticed the qemu_aio_flush was doing nothing at all. And a flood of cmd_writeb commands leading to a noop-invocation of qemu_aio_flush were executed. In short all 'memset;goto redo' places must be fixed to use the bh and not to call the callback in the context of bdrv_aio_read or the bdrv_aio_read model falls apart. Reading from qcow2 holes is possible with phyisical readahead (kind of breada in linux buffer cache). This is needed at least for scsi, ide is lucky (or it has been band-aided against this API breakage by fixing the symptom and not the real bug). Same bug exists in qcow of course, can be fixed later as it's less urgent. Signed-off-by: Andrea Arcangeli Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/block-qcow2.c Modified: trunk/block-qcow2.c =================================================================== --- trunk/block-qcow2.c 2008-10-31 17:25:56 UTC (rev 5573) +++ trunk/block-qcow2.c 2008-10-31 17:28:00 UTC (rev 5574) @@ -1165,8 +1165,18 @@ uint64_t cluster_offset; uint8_t *cluster_data; BlockDriverAIOCB *hd_aiocb; + QEMUBH *bh; } QCowAIOCB; +static void qcow_aio_read_cb(void *opaque, int ret); +static void qcow_aio_read_bh(void *opaque) +{ + QCowAIOCB *acb = opaque; + qemu_bh_delete(acb->bh); + acb->bh = NULL; + qcow_aio_read_cb(opaque, 0); +} + static void qcow_aio_read_cb(void *opaque, int ret) { QCowAIOCB *acb = opaque; @@ -1182,7 +1192,6 @@ return; } - redo: /* post process the read buffer */ if (!acb->cluster_offset) { /* nothing to do */ @@ -1223,12 +1232,30 @@ if (acb->hd_aiocb == NULL) goto fail; } else { - goto redo; + if (acb->bh) { + ret = -EIO; + goto fail; + } + acb->bh = qemu_bh_new(qcow_aio_read_bh, acb); + if (!acb->bh) { + ret = -EIO; + goto fail; + } + qemu_bh_schedule(acb->bh); } } else { /* Note: in this case, no need to wait */ memset(acb->buf, 0, 512 * acb->n); - goto redo; + if (acb->bh) { + ret = -EIO; + goto fail; + } + acb->bh = qemu_bh_new(qcow_aio_read_bh, acb); + if (!acb->bh) { + ret = -EIO; + goto fail; + } + qemu_bh_schedule(acb->bh); } } else if (acb->cluster_offset & QCOW_OFLAG_COMPRESSED) { /* add AIO support for compressed blocks ? */ @@ -1236,7 +1263,16 @@ goto fail; memcpy(acb->buf, s->cluster_cache + index_in_cluster * 512, 512 * acb->n); - goto redo; + if (acb->bh) { + ret = -EIO; + goto fail; + } + acb->bh = qemu_bh_new(qcow_aio_read_bh, acb); + if (!acb->bh) { + ret = -EIO; + goto fail; + } + qemu_bh_schedule(acb->bh); } else { if ((acb->cluster_offset & 511) != 0) { ret = -EIO;