From patchwork Wed Sep 7 23:06:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yehuda Sadeh X-Patchwork-Id: 113843 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 87FBEB6F84 for ; Thu, 8 Sep 2011 08:59:16 +1000 (EST) Received: from localhost ([::1]:58922 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R1R5K-0004mL-4D for incoming@patchwork.ozlabs.org; Wed, 07 Sep 2011 18:59:10 -0400 Received: from eggs.gnu.org ([140.186.70.92]:53719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R1R4t-0003WW-LV for qemu-devel@nongnu.org; Wed, 07 Sep 2011 18:58:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R1R4q-0001xE-O6 for qemu-devel@nongnu.org; Wed, 07 Sep 2011 18:58:43 -0400 Received: from mail.hq.newdream.net ([66.33.206.127]:54232) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R1R4q-0001wt-G9 for qemu-devel@nongnu.org; Wed, 07 Sep 2011 18:58:40 -0400 Received: from mail.hq.newdream.net (localhost [127.0.0.1]) by mail.hq.newdream.net (Postfix) with ESMTP id 571ACC066; Wed, 7 Sep 2011 16:02:20 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=hq.newdream.net; h=from:to:cc :subject:date:message-id:in-reply-to:references:in-reply-to: references; q=dns; s=drama; b=s7RuscBrdfnwkdE5I7YDg1Pxfp8KZ5wuEY 2Q8j1wvthW3oHvGCFBYhGE5YJG/ketu2Umdq6oLVXOOlbZqLMHUyDzPjAD2KG82I PeKQtYSzQNqh74MX/UOMmN9nSB4KS3rWf1lT0YlTHyFN1XcRL2OTrcKw88ZEVA53 4IVuQoJmk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=hq.newdream.net; h=from:to :cc:subject:date:message-id:in-reply-to:references:in-reply-to: references; s=drama; bh=tf7rUGSQjfScnNvuWlvq+QPyCnc=; b=F2q6ycLu MxKmqX03XaCWYjMaREcPUZRjGWCoPMKz6Rs9bBWbUijfGXEeZ7gB/uYzW4NEIQpY hQjUKK+OORd1s1JLSVMdic4fUzbFT1ZGKZHjn8YvbCTzwcm4GMc1uuHWQuSqtTeN iFzWvBfy/cQvNsW2FQ42M+oTn9yL8C8cpq8= Received: from localhost.localdomain (aon.hq.newdream.net [64.111.111.107]) by mail.hq.newdream.net (Postfix) with ESMTPSA id 474EFC063; Wed, 7 Sep 2011 16:02:20 -0700 (PDT) From: Yehuda Sadeh To: qemu-devel@nongnu.org, ceph-devel@vger.kernel.org Date: Wed, 7 Sep 2011 16:06:52 -0700 Message-Id: <7c1ad306663bcacc60312d4d51ee6d266e075687.1315436097.git.yehuda@hq.newdream.net> X-Mailer: git-send-email 1.7.5.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 66.33.206.127 Cc: sage@newdream.net, yehudasa@gmail.com, Yehuda Sadeh Subject: [Qemu-devel] [PATCH 1/2] qemu-img: async write to block device when converting image 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 In order to improve image conversion process, instead of synchronously writing the destingation image, we keep a window of async writes. Signed-off-by: Yehuda Sadeh --- qemu-img.c | 28 +++++++++++++++++++++++----- 1 files changed, 23 insertions(+), 5 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index b205e98..0552746 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -622,6 +622,17 @@ static int compare_sectors(const uint8_t *buf1, const uint8_t *buf2, int n, } #define IO_BUF_SIZE (2 * 1024 * 1024) +#define IO_WRITE_WINDOW_THRESHOLD (32 * 1024 * 1024) + +static int write_window = 0; + +static void img_write_cb(void *opaque, int ret) +{ + QEMUIOVector *qiov = (QEMUIOVector *)opaque; + write_window -= qiov->iov->iov_len / 512; + qemu_iovec_destroy(qiov); + qemu_free(qiov); +} static int img_convert(int argc, char **argv) { @@ -980,6 +991,9 @@ static int img_convert(int argc, char **argv) should add a specific call to have the info to go faster */ buf1 = buf; while (n > 0) { + while (write_window > IO_WRITE_WINDOW_THRESHOLD / 512) { + qemu_aio_wait(); + } /* If the output image is being created as a copy on write image, copy all sectors even the ones containing only NUL bytes, because they may differ from the sectors in the base image. @@ -989,11 +1003,11 @@ static int img_convert(int argc, char **argv) already there is garbage, not 0s. */ if (!has_zero_init || out_baseimg || is_allocated_sectors(buf1, n, &n1)) { - ret = bdrv_write(out_bs, sector_num, buf1, n1); - if (ret < 0) { - error_report("error while writing"); - goto out; - } + QEMUIOVector *qiov = qemu_mallocz(sizeof(QEMUIOVector)); + qemu_iovec_init(qiov, 1); + qemu_iovec_add(qiov, (void *)buf1, n1 * 512); + bdrv_aio_writev(out_bs, sector_num, qiov, n1, img_write_cb, qiov); + write_window += n1; } sector_num += n1; n -= n1; @@ -1001,11 +1015,15 @@ static int img_convert(int argc, char **argv) } qemu_progress_print(local_progress, 100); } + while (write_window > 0) { + qemu_aio_wait(); + } } out: qemu_progress_end(); free_option_parameters(create_options); free_option_parameters(param); + bdrv_flush(out_bs); qemu_free(buf); if (out_bs) { bdrv_delete(out_bs);