Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3944575pxj; Mon, 21 Jun 2021 09:55:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzb96loMXKXdB4PFfEmRvwTlNajbmSzMUH+eonK8g1jWHwys6TD6AlRuU/yMgq3IRgXJ3BR X-Received: by 2002:a05:6402:1a:: with SMTP id d26mr23312614edu.105.1624294552240; Mon, 21 Jun 2021 09:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624294552; cv=none; d=google.com; s=arc-20160816; b=jYr2D7tCTHLIWqbEfjmGxBYldrqdr/oJa24RtUy+pZfdIybDsbOT4yJc479be3cnqa 7eLx7JZ8Dba0rogJFQwxoGy3JC4jPHmPlixt+n7ZggvRUArGFXRtjgU9NnFOSBcZCh9t CoejKdPcP6Vo3DH1EiXsp/IcZCswgZfnDfEDukwrMpMX3lLg1qv/ijVmrZNZ/WHxHGTh KfKgG0laMgGAg0IaUwHjlbdlcQVDQ+FnJjLIUmtn/XCcUsSj20R+J/4L2rGjQ6yR8cxS TCZOP3bcgazI/HwpEXXint24gLV8EXX4NyCrx+xFlxtP3ZxTJOOXdd5lcWRBup1elg7N lqSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WROVsrI7zEd51dreZCObYhrJQLs2wm67KmrtY6dLoqU=; b=RY9AU//re2X+sJlFVgInYrNcAZpGP/GASChFr3TiMF+nX7WTuKw67uVwirzlb8Ro4f ZZK4STP1On8PkW/El6x0M/AvFAW7kzL2J2i7QPrKzVYmVWmNzZ40KRu9oOsOL8P1Ba9L S3LagqG7whF1D7nF9aDYeqwoTFzuZZ0Vu7ADubkx8JJTsXzH3KA7NEnwyV2FHYBR3QpO m2sd8CLtSxUU7eFcpi5dEBsPCXsBTHqciTYLEgsgJP/Fihjm1/+n71q80Sx9i01d506m sbP05CUeFeqpIm4y7460OfcFWorlLEujx4rw8YXoOp+aH9er0FwFumZ16OU5Ia+hmOPz x7Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ry/1vWZI"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id em10si10880890ejc.186.2021.06.21.09.55.30; Mon, 21 Jun 2021 09:55:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ry/1vWZI"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233111AbhFUQyN (ORCPT + 99 others); Mon, 21 Jun 2021 12:54:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:41348 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233384AbhFUQtn (ORCPT ); Mon, 21 Jun 2021 12:49:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0A6BD61360; Mon, 21 Jun 2021 16:34:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624293281; bh=LMB/EuOgP2l7rt4+DH9omDRGMomrcHldCdGNDTix6ts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ry/1vWZIsGcxj0QMAmzWV49Jsd99CEH0dcYPC/mrSDlr0x03L1NEr5nvuJxe0NDtO pDWxL+/RQTUb4nyYU2mNEV4touw4W/ftEvB1YGFx2p8zcH1zXFfA+dmfeI4PtNIMcs DNl2DlY+Jo/krnEVyVHSTvmag7zuEUjXlhqYIHmU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Sterba , Johannes Thumshirn , Naohiro Aota Subject: [PATCH 5.12 132/178] btrfs: zoned: fix negative space_info->bytes_readonly Date: Mon, 21 Jun 2021 18:15:46 +0200 Message-Id: <20210621154927.276671375@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154921.212599475@linuxfoundation.org> References: <20210621154921.212599475@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Naohiro Aota commit f9f28e5bd0baee9708c9011897196f06ae3a2733 upstream. Consider we have a using block group on zoned btrfs. |<- ZU ->|<- used ->|<---free--->| `- Alloc offset ZU: Zone unusable Marking the block group read-only will migrate the zone unusable bytes to the read-only bytes. So, we will have this. |<- RO ->|<- used ->|<--- RO --->| RO: Read only When marking it back to read-write, btrfs_dec_block_group_ro() subtracts the above "RO" bytes from the space_info->bytes_readonly. And, it moves the zone unusable bytes back and again subtracts those bytes from the space_info->bytes_readonly, leading to negative bytes_readonly. This can be observed in the output as eg.: Data, single: total=512.00MiB, used=165.21MiB, zone_unusable=16.00EiB Data, single: total=536870912, used=173256704, zone_unusable=18446744073603186688 This commit fixes the issue by reordering the operations. Link: https://github.com/naota/linux/issues/37 Reported-by: David Sterba Fixes: 169e0da91a21 ("btrfs: zoned: track unusable bytes for zones") CC: stable@vger.kernel.org # 5.12+ Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/block-group.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2347,16 +2347,16 @@ void btrfs_dec_block_group_ro(struct btr spin_lock(&sinfo->lock); spin_lock(&cache->lock); if (!--cache->ro) { - num_bytes = cache->length - cache->reserved - - cache->pinned - cache->bytes_super - - cache->zone_unusable - cache->used; - sinfo->bytes_readonly -= num_bytes; if (btrfs_is_zoned(cache->fs_info)) { /* Migrate zone_unusable bytes back */ cache->zone_unusable = cache->alloc_offset - cache->used; sinfo->bytes_zone_unusable += cache->zone_unusable; sinfo->bytes_readonly -= cache->zone_unusable; } + num_bytes = cache->length - cache->reserved - + cache->pinned - cache->bytes_super - + cache->zone_unusable - cache->used; + sinfo->bytes_readonly -= num_bytes; list_del_init(&cache->ro_list); } spin_unlock(&cache->lock);