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: 1128532 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p87Mwen6028875 for ; Wed, 7 Sep 2011 22:58:52 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751868Ab1IGW6k (ORCPT ); Wed, 7 Sep 2011 18:58:40 -0400 Received: from mail.hq.newdream.net ([66.33.206.127]:51827 "EHLO mail.hq.newdream.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755528Ab1IGW6i (ORCPT ); Wed, 7 Sep 2011 18:58:38 -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 Cc: sage@newdream.net, yehudasa@gmail.com, Yehuda Sadeh Subject: [PATCH 1/2] qemu-img: async write to block device when converting image 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: Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 07 Sep 2011 22:58:52 +0000 (UTC) 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);