From patchwork Mon Mar 19 17:07:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 147591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AA264B6FD6 for ; Tue, 20 Mar 2012 04:09:14 +1100 (EST) Received: from localhost ([::1]:50463 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9g52-0007dk-DK for incoming@patchwork.ozlabs.org; Mon, 19 Mar 2012 13:09:12 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9g4T-0006bi-75 for qemu-devel@nongnu.org; Mon, 19 Mar 2012 13:08:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S9g43-0008WC-LB for qemu-devel@nongnu.org; Mon, 19 Mar 2012 13:08:36 -0400 Received: from mail-gy0-f173.google.com ([209.85.160.173]:45936) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9g43-0008Vw-DH for qemu-devel@nongnu.org; Mon, 19 Mar 2012 13:08:11 -0400 Received: by ghrr14 with SMTP id r14so6555548ghr.4 for ; Mon, 19 Mar 2012 10:08:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=G7QoNpgZvtZ3NXuJyU/e12AJySnNSN39Rze0DeqEj8Q=; b=VJe+JmylU599QFJDr9eGMlIeBjQytNuhJ9WYxL3kBERo5LX9xDJwTPtLpCI68WNQVI WJy/puU2pOa2IAST+EiFSZKVPHkO6WMNncCSwjZYpGfvZOo0MWMD2ahZ0ulb4dR8SEbi pU85Lpe5OfZIYfQt5y/fy62vCaJowl6iodngw19XBekdg82VdPsLQU5Jm5ureM4/E4Cb GmaZI8A+2Kpx+Hx3woHdcNwoHAc1RCi8W0gw8/opeRkksL8j7XzBebwXtpBX9ScdyMsz gN4Z5u5GbBSgo9jStwNcV1YbXVcSnzxN46G8uh6xyWOWJRtvMgeOfIqbvUHZmQ1DJAjO XHUA== Received: by 10.68.221.106 with SMTP id qd10mr26740997pbc.161.1332176889455; Mon, 19 Mar 2012 10:08:09 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-182-16.ip50.fastwebnet.it. [93.34.182.16]) by mx.google.com with ESMTPS id o2sm11731982pbb.45.2012.03.19.10.08.05 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 19 Mar 2012 10:08:08 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 19 Mar 2012 18:07:46 +0100 Message-Id: <1332176871-26158-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1332176871-26158-1-git-send-email-pbonzini@redhat.com> References: <1332176871-26158-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.173 Cc: kwolf@redhat.com, sw@weilnetz.de Subject: [Qemu-devel] [PATCH v2 2/7] vdi: move end-of-I/O handling at the end X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The next step is to take code that only triggers after the first operation, and move it at the end of vdi_aio_read_cb and vdi_aio_write_cb. Acked-by: Stefan Weil Signed-off-by: Paolo Bonzini --- block/vdi.c | 123 +++++++++++++++++++++++++++-------------------------------- 1 files changed, 56 insertions(+), 67 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index 35edc90..4b780db 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -533,20 +533,7 @@ static int vdi_aio_read_cb(void *opaque, int ret) uint32_t sector_in_block; uint32_t n_sectors; - logout("%u sectors read\n", acb->n_sectors); - restart: - acb->nb_sectors -= acb->n_sectors; - - if (acb->nb_sectors == 0) { - /* request completed */ - ret = 0; - goto done; - } - - acb->sector_num += acb->n_sectors; - acb->buf += acb->n_sectors * SECTOR_SIZE; - block_index = acb->sector_num / s->block_sectors; sector_in_block = acb->sector_num % s->block_sectors; n_sectors = s->block_sectors - sector_in_block; @@ -573,11 +560,16 @@ restart: qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); ret = bdrv_co_readv(bs->file, offset, n_sectors, &acb->hd_qiov); } - if (ret >= 0) { + logout("%u sectors read\n", acb->n_sectors); + + acb->nb_sectors -= acb->n_sectors; + acb->sector_num += acb->n_sectors; + acb->buf += acb->n_sectors * SECTOR_SIZE; + + if (ret >= 0 && acb->nb_sectors > 0) { goto restart; } -done: if (acb->qiov->niov > 1) { qemu_iovec_from_buffer(acb->qiov, acb->orig_buf, acb->qiov->size); qemu_vfree(acb->orig_buf); @@ -609,56 +601,6 @@ static int vdi_aio_write_cb(void *opaque, int ret) uint32_t n_sectors; restart: - acb->nb_sectors -= acb->n_sectors; - acb->sector_num += acb->n_sectors; - acb->buf += acb->n_sectors * SECTOR_SIZE; - - if (acb->nb_sectors == 0) { - logout("finished data write\n"); - acb->n_sectors = 0; - ret = 0; - if (acb->header_modified) { - VdiHeader *header = acb->block_buffer; - logout("now writing modified header\n"); - assert(VDI_IS_ALLOCATED(acb->bmap_first)); - *header = s->header; - vdi_header_to_le(header); - acb->header_modified = 0; - acb->hd_iov.iov_base = acb->block_buffer; - acb->hd_iov.iov_len = SECTOR_SIZE; - qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); - ret = bdrv_co_writev(bs->file, 0, 1, &acb->hd_qiov); - } - if (ret >= 0 && VDI_IS_ALLOCATED(acb->bmap_first)) { - /* One or more new blocks were allocated. */ - uint64_t offset; - uint32_t bmap_first; - uint32_t bmap_last; - g_free(acb->block_buffer); - acb->block_buffer = NULL; - bmap_first = acb->bmap_first; - bmap_last = acb->bmap_last; - logout("now writing modified block map entry %u...%u\n", - bmap_first, bmap_last); - /* Write modified sectors from block map. */ - bmap_first /= (SECTOR_SIZE / sizeof(uint32_t)); - bmap_last /= (SECTOR_SIZE / sizeof(uint32_t)); - n_sectors = bmap_last - bmap_first + 1; - offset = s->bmap_sector + bmap_first; - acb->bmap_first = VDI_UNALLOCATED; - acb->hd_iov.iov_base = (void *)((uint8_t *)&s->bmap[0] + - bmap_first * SECTOR_SIZE); - acb->hd_iov.iov_len = n_sectors * SECTOR_SIZE; - qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); - logout("will write %u block map sectors starting from entry %u\n", - n_sectors, bmap_first); - ret = bdrv_co_writev(bs->file, offset, n_sectors, &acb->hd_qiov); - } - goto done; - } - - logout("%u sectors written\n", acb->n_sectors); - block_index = acb->sector_num / s->block_sectors; sector_in_block = acb->sector_num % s->block_sectors; n_sectors = s->block_sectors - sector_in_block; @@ -709,11 +651,58 @@ restart: qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); ret = bdrv_co_writev(bs->file, offset, n_sectors, &acb->hd_qiov); } - if (ret >= 0) { + + acb->nb_sectors -= acb->n_sectors; + acb->sector_num += acb->n_sectors; + acb->buf += acb->n_sectors * SECTOR_SIZE; + + logout("%u sectors written\n", acb->n_sectors); + if (ret >= 0 && acb->nb_sectors > 0) { goto restart; } -done: + logout("finished data write\n"); + if (ret >= 0) { + ret = 0; + if (acb->header_modified) { + VdiHeader *header = acb->block_buffer; + logout("now writing modified header\n"); + assert(VDI_IS_ALLOCATED(acb->bmap_first)); + *header = s->header; + vdi_header_to_le(header); + acb->header_modified = 0; + acb->hd_iov.iov_base = acb->block_buffer; + acb->hd_iov.iov_len = SECTOR_SIZE; + qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); + ret = bdrv_co_writev(bs->file, 0, 1, &acb->hd_qiov); + } + if (ret >= 0 && VDI_IS_ALLOCATED(acb->bmap_first)) { + /* One or more new blocks were allocated. */ + uint64_t offset; + uint32_t bmap_first; + uint32_t bmap_last; + g_free(acb->block_buffer); + acb->block_buffer = NULL; + bmap_first = acb->bmap_first; + bmap_last = acb->bmap_last; + logout("now writing modified block map entry %u...%u\n", + bmap_first, bmap_last); + /* Write modified sectors from block map. */ + bmap_first /= (SECTOR_SIZE / sizeof(uint32_t)); + bmap_last /= (SECTOR_SIZE / sizeof(uint32_t)); + n_sectors = bmap_last - bmap_first + 1; + offset = s->bmap_sector + bmap_first; + acb->bmap_first = VDI_UNALLOCATED; + acb->hd_iov.iov_base = (void *)((uint8_t *)&s->bmap[0] + + bmap_first * SECTOR_SIZE); + acb->hd_iov.iov_len = n_sectors * SECTOR_SIZE; + qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1); + logout("will write %u block map sectors starting from entry %u\n", + n_sectors, bmap_first); + ret = bdrv_co_writev(bs->file, offset, n_sectors, &acb->hd_qiov); + } + } + if (acb->qiov->niov > 1) { qemu_vfree(acb->orig_buf); }