From patchwork Fri Feb 14 17:05:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 320492 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 8AAEA2C00AC for ; Sat, 15 Feb 2014 04:05:59 +1100 (EST) Received: from localhost ([::1]:52945 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WEMD7-0004QV-BX for incoming@patchwork.ozlabs.org; Fri, 14 Feb 2014 12:05:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WEMCb-0004Ou-Id for qemu-devel@nongnu.org; Fri, 14 Feb 2014 12:05:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WEMCT-0004cw-5R for qemu-devel@nongnu.org; Fri, 14 Feb 2014 12:05:25 -0500 Received: from mail-wg0-x232.google.com ([2a00:1450:400c:c00::232]:60692) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WEMCS-0004cq-Ux for qemu-devel@nongnu.org; Fri, 14 Feb 2014 12:05:17 -0500 Received: by mail-wg0-f50.google.com with SMTP id z12so595286wgg.29 for ; Fri, 14 Feb 2014 09:05:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=TuZ5DSGXYGwHIpkDoI9lHzgUKrqxBs9WsSKttBqHOW8=; b=By8mujEbKwOjRpONWsKBzF58PqNo0feI+9KUE/ObY7geeBbQU7T5/wqLuuPPlmmpnD D3WkLFYBEpmMHqImsoXFzfGy/u70rmK2Xo9pYXQUx1D0HbNUeqjxppSpeOpMivH6OG85 +rDJx7FA6DrvOq2Gi2ULTYN9OIH2mZvck2S4UQrgJU5+zVSMGeyk17IL9RI+FUtkKxu3 le/A11TCi0ek/4JL3kbIXWXa5ZqeBBCM88aV8OHFQw0jZhHBSArV2cGvpE0UsL2duZN0 vqKhYCa9oM54A0hUYqfiU/twh/YoCg2NGAT/8v/DdrdfP41PNqJKVdsMwd4k75trLJr1 K81w== X-Received: by 10.194.203.200 with SMTP id ks8mr2582568wjc.61.1392397515870; Fri, 14 Feb 2014 09:05:15 -0800 (PST) Received: from localhost (95-91-232-189-dynip.superkabel.de. [95.91.232.189]) by mx.google.com with ESMTPSA id k10sm14054175wjf.11.2014.02.14.09.05.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Feb 2014 09:05:15 -0800 (PST) Date: Fri, 14 Feb 2014 18:05:13 +0100 From: Stefan Hajnoczi To: Kevin Wolf Message-ID: <20140214170512.GA7660@stefanha-thinkpad.redhat.com> References: <52F65880.9000307@redhat.com> <1391878202-27440-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1391878202-27440-1-git-send-email-kwolf@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::232 Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@redhat.com Subject: Re: [Qemu-devel] [PATCH v2] qcow2: Set zero flag for discarded clusters 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 On Sat, Feb 08, 2014 at 05:50:02PM +0100, Kevin Wolf wrote: > Instead of making the backing file contents visible again after a discard > request, set the zero flag if possible (i.e. on version >= 3). > > Signed-off-by: Kevin Wolf > Reviewed-by: Max Reitz > --- > block/qcow2-cluster.c | 22 ++++++++++++++++++++-- > 1 file changed, 20 insertions(+), 2 deletions(-) > > diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c > index 25d45d1..9461969 100644 > --- a/block/qcow2-cluster.c > +++ b/block/qcow2-cluster.c > @@ -1333,13 +1333,31 @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset, > uint64_t old_offset; > > old_offset = be64_to_cpu(l2_table[l2_index + i]); > - if ((old_offset & L2E_OFFSET_MASK) == 0) { > + > + /* > + * Make sure that a discarded area reads back as zeroes for v3 images > + * (we cannot do it for v2 without actually writing a zero-filled > + * buffer). We can skip the operation if the cluster is already marked > + * as zero, or if it's unallocated and we don't have a backing file. > + * > + * TODO We might want to use bdrv_get_block_status(bs) here, but we're > + * holding s->lock, so that doesn't work today. > + */ > + if (!!(old_offset & QCOW_OFLAG_ZERO)) { > + continue; > + } > + > + if ((old_offset & L2E_OFFSET_MASK) == 0 && !bs->backing_hd) { > continue; > } > > /* First remove L2 entries */ > qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table); > - l2_table[l2_index + i] = cpu_to_be64(0); > + if (s->qcow_version >= 3) { > + l2_table[l2_index + i] = cpu_to_be64(QCOW_OFLAG_ZERO); > + } else { > + l2_table[l2_index + i] = cpu_to_be64(0); > + } > > /* Then decrease the refcount */ > qcow2_free_any_clusters(bs, old_offset, 1, type); Oops, this breaks qemu-iotests 046. I have dropped it from the pull request. 046 1s ... - output mismatch (see 046.out.bad) Failures: 046 Failed 1 of 1 tests --- 046.out 2014-02-03 16:06:23.917196159 +0100 +++ 046.out.bad 2014-02-14 18:02:01.577193856 +0100 @@ -187,10 +187,12 @@ 24 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 8192/8192 bytes at offset 516096 8 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Pattern verification failed at offset 524288, 24576 bytes read 24576/24576 bytes at offset 524288 24 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 8192/8192 bytes at offset 548864 8 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Pattern verification failed at offset 557056, 8192 bytes read 8192/8192 bytes at offset 557056 8 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 57344/57344 bytes at offset 565248 @@ -199,10 +201,12 @@ 24 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 8192/8192 bytes at offset 647168 8 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Pattern verification failed at offset 655360, 24576 bytes read 24576/24576 bytes at offset 655360 24 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 8192/8192 bytes at offset 679936 8 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Pattern verification failed at offset 688128, 8192 bytes read 8192/8192 bytes at offset 688128 8 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 57344/57344 bytes at offset 696320