From patchwork Thu May 26 03:48:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9136549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 89CE16075A for ; Thu, 26 May 2016 03:49:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D2DD279E2 for ; Thu, 26 May 2016 03:49:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 710F6282DF; Thu, 26 May 2016 03:49:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C3E1A279E2 for ; Thu, 26 May 2016 03:49:32 +0000 (UTC) Received: from localhost ([::1]:36245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5mIb-0001zo-2b for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 May 2016 23:49:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5mIC-0001zF-UJ for qemu-devel@nongnu.org; Wed, 25 May 2016 23:49:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5mIA-00043G-Op for qemu-devel@nongnu.org; Wed, 25 May 2016 23:49:03 -0400 Received: from resqmta-po-09v.sys.comcast.net ([2001:558:fe16:19:96:114:154:168]:48401) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5mIA-00042z-K1 for qemu-devel@nongnu.org; Wed, 25 May 2016 23:49:02 -0400 Received: from resomta-po-18v.sys.comcast.net ([96.114.154.242]) by comcast with SMTP id 5mHObvA6nd8265mIAb7OFj; Thu, 26 May 2016 03:49:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1464234542; bh=d2gt/ERKAH8kjjRr1/djFAjr2SAZxDPic0gVg5mzWpQ=; h=Received:Received:From:To:Subject:Date:Message-Id; b=Wn/ZwBsDOiKCmgoBdJiOCO09I6qkl5sCt2+1omI6dsFXXbR1ibBwG0QSo+P5JKMhi UQ72mEjvTOqRqs1OhPTudGsegCg9sIGhrQe3cVmsqUsu/Co+ifK3PXIRn5qa9Ke5tm RL5XX+rNcF1/EE+J+beKQGrumCv0EdVahAzRKth37AzOhFKqH+7dyfadaXCXpr1FYV 3+syDvuFrYPCZRSPvmsiV7GiH5mULXy2lVVj9+WVY/mxIxAPFI6aPGYoHfSIBElrn5 Y9oGqjMOshmeXTkYwE182ouMfpqUSWkE1Xdgh6I6jSRho+Z1+AAgGLS0wZvP7o9RvW 3dzkNcL2JPMfQ== Received: from red.localdomain ([24.10.254.122]) by resomta-po-18v.sys.comcast.net with comcast id yrop1s00E2fD5rL01rp1lP; Thu, 26 May 2016 03:49:01 +0000 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 25 May 2016 21:48:46 -0600 Message-Id: <1464234529-13018-3-git-send-email-eblake@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1464234529-13018-1-git-send-email-eblake@redhat.com> References: <1464234529-13018-1-git-send-email-eblake@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:558:fe16:19:96:114:154:168 Subject: [Qemu-devel] [PATCH v3 2/5] qcow2: simplify logic in qcow2_co_write_zeroes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, den@openvz.org, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Denis V. Lunev" Unaligned requests will occupy only one cluster. This is true since the previous commit. Simplify the code taking this consideration into account. In other words, the caller is now buggy if it ever passes us an unaligned request that crosses cluster boundaries (the only requests that can cross boundaries will be aligned). There are no other changes so far. Signed-off-by: Denis V. Lunev Reviewed-by: Eric Blake CC: Eric Blake CC: Kevin Wolf Message-Id: <1463476543-3087-3-git-send-email-den@openvz.org> --- block/qcow2.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index c9306a7..2f73201 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2438,33 +2438,20 @@ static coroutine_fn int qcow2_co_write_zeroes(BlockDriverState *bs, int tail = (sector_num + nb_sectors) % s->cluster_sectors; if (head != 0 || tail != 0) { - int64_t cl_end = -1; + int64_t cl_start = sector_num - head; - sector_num -= head; - nb_sectors += head; + assert(cl_start + s->cluster_sectors >= sector_num + nb_sectors); - if (tail != 0) { - nb_sectors += s->cluster_sectors - tail; - } + sector_num = cl_start; + nb_sectors = s->cluster_sectors; if (!is_zero_cluster(bs, sector_num)) { return -ENOTSUP; } - if (nb_sectors > s->cluster_sectors) { - /* Technically the request can cover 2 clusters, f.e. 4k write - at s->cluster_sectors - 2k offset. One of these cluster can - be zeroed, one unallocated */ - cl_end = sector_num + nb_sectors - s->cluster_sectors; - if (!is_zero_cluster(bs, cl_end)) { - return -ENOTSUP; - } - } - qemu_co_mutex_lock(&s->lock); /* We can have new write after previous check */ - if (!is_zero_cluster_top_locked(bs, sector_num) || - (cl_end > 0 && !is_zero_cluster_top_locked(bs, cl_end))) { + if (!is_zero_cluster_top_locked(bs, sector_num)) { qemu_co_mutex_unlock(&s->lock); return -ENOTSUP; }