From patchwork Thu Mar 8 17:15:08 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 145599 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 ED350B6FF9 for ; Fri, 9 Mar 2012 05:01:26 +1100 (EST) Received: from localhost ([::1]:34900 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5heW-0007GQ-PC for incoming@patchwork.ozlabs.org; Thu, 08 Mar 2012 13:01:24 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5gws-0005VU-KM for qemu-devel@nongnu.org; Thu, 08 Mar 2012 12:16:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S5gwM-0004ps-9M for qemu-devel@nongnu.org; Thu, 08 Mar 2012 12:16:18 -0500 Received: from mail-iy0-f173.google.com ([209.85.210.173]:47906) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5gwL-0004n5-VA for qemu-devel@nongnu.org; Thu, 08 Mar 2012 12:15:46 -0500 Received: by mail-iy0-f173.google.com with SMTP id j26so1015616iaf.4 for ; Thu, 08 Mar 2012 09:15:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=6F3nBfj18qUoZLlQ9Akgr05MLyMTHMrt8Az998diUIs=; b=nwL6t0v7kpOxrtmzcpadjli5sRfKBh6HiEkTYwo2LW2lAsZNs8AfESUjmtFJoflEsr DzU4b3mvp0De+oCBWxoL+uyock2mw9N6YxGAm+zU17YDlhtd7QAK1b4Kw6LHwfFzqY6p NmMu0b00P1XsFLXVVoHuRMILlWOkxo/1fwb6ptdqIivJdwgPoOgZRWCBI5SqYSrau8wf 0kUeRXfG+rD4ow0v7i8470L+5y+mnfNm1TSTrru8wwRLGII6XflCvz/yhfdekRHWyXTJ 7L8ZWshSOXNqcwPxnSyhyYIr8UVVrYxAvRqGPaoUJFs5mBRx96X82VCWmSV9tKfciLe6 nwgw== Received: by 10.42.108.6 with SMTP id f6mr6355463icp.7.1331226945235; Thu, 08 Mar 2012 09:15:45 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-182-16.ip50.fastwebnet.it. [93.34.182.16]) by mx.google.com with ESMTPS id s3sm2123819igw.17.2012.03.08.09.15.43 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 08 Mar 2012 09:15:44 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 8 Mar 2012 18:15:08 +0100 Message-Id: <1331226917-6658-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1331226917-6658-1-git-send-email-pbonzini@redhat.com> References: <1331226917-6658-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.210.173 Subject: [Qemu-devel] [RFC PATCH 08/17] block: kill the write zeroes operation 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 They do not provide anything more than the discard operations now. Remove them, and use discard instead in qemu-io and the tests. Signed-off-by: Paolo Bonzini --- block.c | 17 +-------------- block.h | 15 ++++++------- qemu-io.c | 50 +------------------------------------------- tests/qemu-iotests/031 | 6 ++-- tests/qemu-iotests/031.out | 4 +- 5 files changed, 14 insertions(+), 78 deletions(-) diff --git a/block.c b/block.c index 30b137f..af73497 100644 --- a/block.c +++ b/block.c @@ -50,7 +50,6 @@ typedef enum { BDRV_REQ_COPY_ON_READ = 0x1, - BDRV_REQ_ZERO_WRITE = 0x2, } BdrvRequestFlags; static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load); @@ -1849,12 +1848,7 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs, } tracked_request_begin(&req, bs, sector_num, nb_sectors, true); - - if (flags & BDRV_REQ_ZERO_WRITE) { - ret = bdrv_co_do_write_zeroes(bs, sector_num, nb_sectors, qiov); - } else { - ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, qiov); - } + ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, qiov); if (bs->dirty_bitmap) { set_dirty_bitmap(bs, sector_num, nb_sectors, 1); @@ -1877,15 +1871,6 @@ int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num, return bdrv_co_do_writev(bs, sector_num, nb_sectors, qiov, 0); } -int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs, - int64_t sector_num, int nb_sectors) -{ - trace_bdrv_co_write_zeroes(bs, sector_num, nb_sectors); - - return bdrv_co_do_writev(bs, sector_num, nb_sectors, NULL, - BDRV_REQ_ZERO_WRITE); -} - /** * Truncate file to 'offset' bytes (needed only for file protocols) */ diff --git a/block.h b/block.h index 7feda73..ef07bb0 100644 --- a/block.h +++ b/block.h @@ -151,14 +151,6 @@ int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); -/* - * Efficiently zero a region of the disk image. Note that this is a regular - * I/O request like read or write and should have a reasonable size. This - * function is not suitable for zeroing the entire image in a single request - * because it may allocate memory for the entire region. - */ -int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs, int64_t sector_num, - int nb_sectors); int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum); BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, @@ -196,6 +188,13 @@ BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num, BlockDriverCompletionFunc *cb, void *opaque); BlockDriverAIOCB *bdrv_aio_flush(BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque); + +/* + * Efficiently zero a region of the disk image. Note that this is a regular + * I/O request like read or write and should have a reasonable size. This + * function is not suitable for zeroing the entire image in a single request + * because it may allocate memory for the entire region. + */ BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque); diff --git a/qemu-io.c b/qemu-io.c index 8f28b6a..bb5f7b8 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -218,51 +218,6 @@ static int do_pwrite(char *buf, int64_t offset, int count, int *total) return 1; } -typedef struct { - int64_t offset; - int count; - int *total; - int ret; - bool done; -} CoWriteZeroes; - -static void coroutine_fn co_write_zeroes_entry(void *opaque) -{ - CoWriteZeroes *data = opaque; - - data->ret = bdrv_co_write_zeroes(bs, data->offset / BDRV_SECTOR_SIZE, - data->count / BDRV_SECTOR_SIZE); - data->done = true; - if (data->ret < 0) { - *data->total = data->ret; - return; - } - - *data->total = data->count; -} - -static int do_co_write_zeroes(int64_t offset, int count, int *total) -{ - Coroutine *co; - CoWriteZeroes data = { - .offset = offset, - .count = count, - .total = total, - .done = false, - }; - - co = qemu_coroutine_create(co_write_zeroes_entry); - qemu_coroutine_enter(co, &data); - while (!data.done) { - qemu_aio_wait(); - } - if (data.ret < 0) { - return data.ret; - } else { - return 1; - } -} - static int do_load_vmstate(char *buf, int64_t offset, int count, int *total) { *total = bdrv_load_vmstate(bs, (uint8_t *)buf, offset, count); @@ -688,7 +643,6 @@ static void write_help(void) " -P, -- use different pattern to fill file\n" " -C, -- report statistics in a machine parsable format\n" " -q, -- quiet mode, do not show I/O statistics\n" -" -z, -- write zeroes using bdrv_co_write_zeroes\n" "\n"); } @@ -717,7 +671,7 @@ static int write_f(int argc, char **argv) int total = 0; int pattern = 0xcd; - while ((c = getopt(argc, argv, "bCpP:qz")) != EOF) { + while ((c = getopt(argc, argv, "bCpP:q")) != EOF) { switch (c) { case 'b': bflag = 1; @@ -796,8 +750,6 @@ static int write_f(int argc, char **argv) cnt = do_pwrite(buf, offset, count, &total); } else if (bflag) { cnt = do_save_vmstate(buf, offset, count, &total); - } else if (zflag) { - cnt = do_co_write_zeroes(offset, count, &total); } else { cnt = do_write(buf, offset, count, &total); } diff --git a/tests/qemu-iotests/031 b/tests/qemu-iotests/031 index 9aee078..c88378e 100755 --- a/tests/qemu-iotests/031 +++ b/tests/qemu-iotests/031 @@ -1,6 +1,6 @@ #!/bin/bash # -# Test aligned and misaligned write zeroes operations. +# Test aligned and misaligned discard operations. # # Copyright (C) 2012 Red Hat, Inc. # @@ -50,7 +50,7 @@ echo echo "== preparing image ==" $QEMU_IO -c "write -P 0xa 0x200 0x400" $TEST_IMG | _filter_qemu_io $QEMU_IO -c "write -P 0xa 0x20000 0x600" $TEST_IMG | _filter_qemu_io -$QEMU_IO -c "write -z 0x400 0x20000" $TEST_IMG | _filter_qemu_io +$QEMU_IO -c "discard 0x400 0x20000" $TEST_IMG | _filter_qemu_io echo echo "== verifying patterns (1) ==" @@ -61,7 +61,7 @@ $QEMU_IO -c "read -P 0xa 0x20400 0x200" $TEST_IMG | _filter_qemu_io echo echo "== rewriting zeroes ==" $QEMU_IO -c "write -P 0xb 0x10000 0x10000" $TEST_IMG | _filter_qemu_io -$QEMU_IO -c "write -z 0x10000 0x10000" $TEST_IMG | _filter_qemu_io +$QEMU_IO -c "discard 0x10000 0x10000" $TEST_IMG | _filter_qemu_io echo echo "== verifying patterns (2) ==" diff --git a/tests/qemu-iotests/031.out b/tests/qemu-iotests/031.out index 3c990dd..788ccfe 100644 --- a/tests/qemu-iotests/031.out +++ b/tests/qemu-iotests/031.out @@ -6,7 +6,7 @@ wrote 1024/1024 bytes at offset 512 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) wrote 1536/1536 bytes at offset 131072 2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -wrote 131072/131072 bytes at offset 1024 +discard 131072/131072 bytes at offset 1024 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) == verifying patterns (1) == @@ -20,7 +20,7 @@ read 512/512 bytes at offset 132096 == rewriting zeroes == wrote 65536/65536 bytes at offset 65536 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -wrote 65536/65536 bytes at offset 65536 +discard 65536/65536 bytes at offset 65536 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) == verifying patterns (2) ==