From patchwork Mon Apr 8 19:02:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10889983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 54EC517E1 for ; Mon, 8 Apr 2019 19:04:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BA492097A for ; Mon, 8 Apr 2019 19:04:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F3E5283C3; Mon, 8 Apr 2019 19:04:47 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D91852654B for ; Mon, 8 Apr 2019 19:04:46 +0000 (UTC) Received: from localhost ([127.0.0.1]:57524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDZZW-0002xR-7d for patchwork-qemu-devel@patchwork.kernel.org; Mon, 08 Apr 2019 15:04:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37638) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDZXh-0001k9-Vd for qemu-devel@nongnu.org; Mon, 08 Apr 2019 15:02:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDZXe-0007HM-DU for qemu-devel@nongnu.org; Mon, 08 Apr 2019 15:02:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55618) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hDZXT-0007Ba-Mh; Mon, 08 Apr 2019 15:02:39 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4461D81DFB; Mon, 8 Apr 2019 19:02:36 +0000 (UTC) Received: from blue.redhat.com (ovpn-117-110.phx2.redhat.com [10.3.117.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0A6460C70; Mon, 8 Apr 2019 19:02:35 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 8 Apr 2019 14:02:30 -0500 Message-Id: <20190408190233.10321-2-eblake@redhat.com> In-Reply-To: <20190408190233.10321-1-eblake@redhat.com> References: <20190408190233.10321-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 08 Apr 2019 19:02:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/4] nbd/server: Fix blockstatus trace 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: Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Don't increment remaining_bytes until we know that we will actually be including the current block status extent in the reply; otherwise, the value traced will include a bytes value that is oversized by the length of the next block status extent which did not get sent because it instead ended the loop. Fixes: fb7afc79 Signed-off-by: Eric Blake Message-Id: <20190403030526.12258-2-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 218a2aa5e65..1b8c8619896 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1880,17 +1880,12 @@ static int blockstatus_to_extents(BlockDriverState *bs, uint64_t offset, flags = (ret & BDRV_BLOCK_ALLOCATED ? 0 : NBD_STATE_HOLE) | (ret & BDRV_BLOCK_ZERO ? NBD_STATE_ZERO : 0); - offset += num; - remaining_bytes -= num; if (first_extent) { extent->flags = flags; extent->length = num; first_extent = false; - continue; - } - - if (flags == extent->flags) { + } else if (flags == extent->flags) { /* extend current extent */ extent->length += num; } else { @@ -1903,6 +1898,8 @@ static int blockstatus_to_extents(BlockDriverState *bs, uint64_t offset, extent->flags = flags; extent->length = num; } + offset += num; + remaining_bytes -= num; } extents_end = extent + 1;