From patchwork Wed Mar 3 08:55:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12114777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4238CC4332D for ; Thu, 4 Mar 2021 00:20:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D2F264E59 for ; Thu, 4 Mar 2021 00:20:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385549AbhCDATT (ORCPT ); Wed, 3 Mar 2021 19:19:19 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:53180 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356764AbhCCKsU (ORCPT ); Wed, 3 Mar 2021 05:48:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1614768500; x=1646304500; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f6ImAg6emvQmJv8zhWVsxpXCRemcjfAsHZ2qZ7dGbPg=; b=BcGmyhco+312lIDqQuBkGJKDZJQQmtMp4sl5BOYGRLLo92kIBM13g9J/ 6eU6O5Iuq0vInE8K4sU0RXH2INXbmAwDa5fofrxCIoYtp8e/YAlGcPZQr KZtQ1nknxKqETH3BUTGEPCxViTx/1YJZHkwLjNn3/DYjgWX+gdj6aCVUY 5FLWlQPrRTLvAQeCmcMFswg5aAMi+AXBywpPb3D8Z+GjptkJOUZIlydFn P5IXydfsF6B8WrxXFJVU0jtg44JLCvMEJByXh5uY/WloYgTXwgtX+v3c+ 7bmL7Fhp2MKeo5IWGC6fh95Rs/Z40dJL3WN5p1Uqpfv+YJhCfDl/IXsFF g==; IronPort-SDR: q7fmtAaUGHpsOiaMt7kBT4OrTZeXZkf9NbbWSJjjYDSUrF8k1iAocZTLKjhlJx35G/C5HPqvPU Ayj+3J2iVuXVop8oklhaGWFq+TfoQk2GTAhuvqJp44lvE/4tk8OBTlA2W5yBk8sQ8UWZBj3ua/ rZMrVUd5zFOBKGeJqJwlWhSeTPrfHLpnajrpBVdz0jVaCiFsbAbTEU8FH+UzDLpdX6P/xKjTes bDhSHeQLTGzdLX4PKU2193uJmliuS9v7BILKzAyDYBlSxrItwFnjJg9YuaPdEmUcy/qHKVBDPC wRE= X-IronPort-AV: E=Sophos;i="5.81,219,1610380800"; d="scan'208";a="271857768" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Mar 2021 16:55:54 +0800 IronPort-SDR: UZ6+B6i7DkX2b29PKy4+TzIle9Qim/0gIGVWimah7BZSfe/1MhGfGvdUP77pAA7uz9mvL408oR C0XeVF1bNoOWn/gG2kSAHECh++k+T040ynhIwKl1VyU7mPgcuap9543Z4yVDn30f/k6Fgzbqqd B+i9NA1Zr0DnGw1UYdWScaSpMWIfzDfc6hK9vDiyPEdcPgxgxnGvoGkKp0B/Jj+Ig15BLariu5 zesEpy+D/CxWPn0044KepbpasrIyb+U0S9F9QavS2GrTmTiFc8tqzlNIFz/UHvYwh/YZDiPl5H RO4NoJ+4sVzR3f4L99HtMX/h Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2021 00:37:09 -0800 IronPort-SDR: AcZK7KjqGCFQSlCRBsi8M9LBlj02tVGtu4hgm4vHTWat777MVgS/BlbiLFWPSqchkwbLFjCztT jBVuSCJOJFFIG//jwpT7eZXXHwF3vZ5EHfiDBfvecuiiFuGPL3Oe/vM4L65qRpiHCpC1Ug/UVV DAdTggdicLSggBrlJF55PSZTq5iBDz04Ld4NohHhsLwSwVyr2IqlhJvi8t4len1GkUNZ6uZvUI MBht5Ep+xxCTtqGoQ3gkT62hgQ6Wjj3XCMDRKZV9oVJBHM2JyMdMmXm6QFyX6TGycxW2LcLvdW f6s= WDCIronportException: Internal Received: from jpf010014.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.91]) by uls-op-cesaip01.wdc.com with ESMTP; 03 Mar 2021 00:55:53 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, dsterba@suse.com Cc: linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 1/3] btrfs: zoned: use sector_t to get zone sectors Date: Wed, 3 Mar 2021 17:55:46 +0900 Message-Id: <8068e2e54817aff858207101677e442a21eb10e3.1614760899.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We need to use sector_t for zone_sectors, or it set the zone size = 0 when the size >= 4GB (= 2^24 sectors) by shifting the zone_sectors value by SECTOR_SHIFT. Fixes: 5b316468983d ("btrfs: get zone information of zoned block devices") Signed-off-by: Naohiro Aota --- fs/btrfs/zoned.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 9a5cf153da89..1324bb6c3946 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -269,7 +269,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device) sector_t sector = 0; struct blk_zone *zones = NULL; unsigned int i, nreported = 0, nr_zones; - unsigned int zone_sectors; + sector_t zone_sectors; char *model, *emulated; int ret; From patchwork Wed Mar 3 08:55:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12115049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37B40C15503 for ; Thu, 4 Mar 2021 00:27:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0DEFD64E62 for ; Thu, 4 Mar 2021 00:27:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389334AbhCDATW (ORCPT ); Wed, 3 Mar 2021 19:19:22 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:53246 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357249AbhCCKtH (ORCPT ); Wed, 3 Mar 2021 05:49:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1614768546; x=1646304546; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+kQZIq5ZqHuqmSavJsQFkjIM7cuk0e5XBPEli2rM270=; b=DENB2iFwvZ5uYo5w9VtNNfHIwiM7gB1Oul6l9uyo/cdqS/RO9laE5YFC LqFoD9DyMREAkPSefSUSQfgul+ftil8UvR3wdl1ZoJkeKOrU9JJJrD1rZ JTidiU3slSV9H7WNF3s3Wa2yQDr7rpaypsgVXOAOxLJbYplNaAKjHPH6M oN2IYYjo/HFchuDF1evpfiHB4yZn4BNy2AH8AR1t1YQDHUFKMOvdCqsqf +a+FWxA4iX5a88tjlhpd9brIPXOIVHpi4P/Fy+IMxN+ENJMcyYKz8L6we Y0eesacCZLFenhNgXae+P1hLVCqSgTDPdhcAn93cmWoryhMoDqiveEcGn w==; IronPort-SDR: AfjUnC2Y6vPF79yP5+prj1jY0AsoJsdfGqHNwjU+iHilDxR443bzxbqxyMs2RA8IB99mb9HOIL 8K40X64UlLrJp+Edgm6/QlmHoe0qB0rjLmcgjtEmCBS6h1nvhQYN0fRIGDdSW/RBtwwF2jbj/1 pAkk0SQngacuuhAYktKbnX+/o9Q749kqwfuQL3gQi16FnO6p3d4JQ5Tj7AIJaBpbJP/nLaGQ8k Ll+0HMPOHntTUQrw+KjU+Pb84JTVhhdtfB08wtgwhDDR48EG/iDQ56GgK4hajHg3H0fAPmMQgQ uPg= X-IronPort-AV: E=Sophos;i="5.81,219,1610380800"; d="scan'208";a="271857769" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Mar 2021 16:55:55 +0800 IronPort-SDR: OmRSHPYdWcWcaoxxA5bueIc9HI8oMsuC0PeMv3GsVfmvdq08U4ZyFSM0DrAHwxHS1XddQ3f/wv sT8RMR0IlMsNhby84FXK/H9rFQPpKUyP9stokOu+YM98k7KKITdUZ88SNciVWFcQ1VN727aoXP AshFuyu2+WwazbCXvGXWUSxXWLw8WcEfM57lhdUipZ4n3vsZjIYWzBjbI6NLsSNki6K+m/VLk6 29K6bHDTcdd97f9WIGbV8OmnAJAlL2WgQUUepWmavAJCo8g/6N6wgu6DIwqEeERBjYyiWrB6zn enxixgweC8yL4YKeA92DSBuB Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2021 00:37:10 -0800 IronPort-SDR: C4fwHlnctbeatCivshzcw6hXw2Dz0oQ7CaXb41YHdxgsVaOX4jnH7WYqvvyg6M5zpZ9Opu76k4 ExcFE3smyrL+WS2EsCVB+MLqVo/j4P+ppWpQ3UJpPXCfC/9jl7DXUPEd6lnt9mqTEr/Kr9vER7 bCngdSrKUEA4kta3WRmzlQIzaePqNU2BCONC9/Z/p7rN/fNDCtx8XfaHpLIUhQA42w6RPP/T2H TOh3EBwnOLJF3uUd3PnueZenRsBgm5tDDCK+CmBZ1SLwW69s6MeJLEnUI62+LdWihoktvN+gwI 8Tk= WDCIronportException: Internal Received: from jpf010014.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.91]) by uls-op-cesaip01.wdc.com with ESMTP; 03 Mar 2021 00:55:54 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, dsterba@suse.com Cc: linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 2/3] btrfs: zoned: move superblock logging zone location Date: Wed, 3 Mar 2021 17:55:47 +0900 Message-Id: X-Mailer: git-send-email 2.30.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This commit moves the location of superblock logging zones basing on the fixed address instead of the fixed zone number. By locating the superblock zones using fixed addresses, we can scan a dumped file system image without the zone information. And, no drawbacks exist. The following zones are reserved as the circular buffer on zoned btrfs. - The primary superblock: zone at LBA 0 and the next zone - The first copy: zone at LBA 16G and the next zone - The second copy: zone at LBA 256G and the next zone If the location of the zones are outside of disk, we don't record the superblock copy. The addresses are much larger than the usual superblock copies locations. The copies' locations are decided to support possible future larger zone size, not to overlap the log zones. We support zone size up to 8GB. Signed-off-by: Naohiro Aota --- fs/btrfs/zoned.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 1324bb6c3946..b8f50dc9fbb0 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -24,6 +24,15 @@ /* Number of superblock log zones */ #define BTRFS_NR_SB_LOG_ZONES 2 +/* Location of superblock log zones */ +#define BTRFS_FIRST_SB_LOG_ZONE SZ_16G +#define BTRFS_SECOND_SB_LOG_ZONE (256ULL * SZ_1G) +#define BTRFS_FIRST_SB_LOG_ZONE_SHIFT const_ilog2(BTRFS_FIRST_SB_LOG_ZONE) +#define BTRFS_SECOND_SB_LOG_ZONE_SHIFT const_ilog2(BTRFS_SECOND_SB_LOG_ZONE) + +/* Max size of supported zone size */ +#define BTRFS_MAX_ZONE_SIZE SZ_8G + static int copy_zone_info_cb(struct blk_zone *zone, unsigned int idx, void *data) { struct blk_zone *zones = data; @@ -112,10 +121,9 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones, /* * The following zones are reserved as the circular buffer on ZONED btrfs. - * - The primary superblock: zones 0 and 1 - * - The first copy: zones 16 and 17 - * - The second copy: zones 1024 or zone at 256GB which is minimum, and - * the following one + * - The primary superblock: zone at LBA 0 and the next zone + * - The first copy: zone at LBA 16G and the next zone + * - The second copy: zone at LBA 256G and the next zone */ static inline u32 sb_zone_number(int shift, int mirror) { @@ -123,8 +131,8 @@ static inline u32 sb_zone_number(int shift, int mirror) switch (mirror) { case 0: return 0; - case 1: return 16; - case 2: return min_t(u64, btrfs_sb_offset(mirror) >> shift, 1024); + case 1: return 1 << (BTRFS_FIRST_SB_LOG_ZONE_SHIFT - shift); + case 2: return 1 << (BTRFS_SECOND_SB_LOG_ZONE_SHIFT - shift); } return 0; @@ -300,10 +308,25 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device) zone_sectors = bdev_zone_sectors(bdev); } - nr_sectors = bdev_nr_sectors(bdev); /* Check if it's power of 2 (see is_power_of_2) */ ASSERT(zone_sectors != 0 && (zone_sectors & (zone_sectors - 1)) == 0); zone_info->zone_size = zone_sectors << SECTOR_SHIFT; + + /* + * We must reject devices with a zone size larger than 8GB to avoid + * overlap between the super block primary and first copy fixed log + * locations. + */ + if (zone_info->zone_size > BTRFS_MAX_ZONE_SIZE) { + btrfs_err_in_rcu(fs_info, + "zoned: %s: zone size %llu is too large", + rcu_str_deref(device->name), + zone_info->zone_size); + ret = -EINVAL; + goto out; + } + + nr_sectors = bdev_nr_sectors(bdev); zone_info->zone_size_shift = ilog2(zone_info->zone_size); zone_info->max_zone_append_size = (u64)queue_max_zone_append_sectors(queue) << SECTOR_SHIFT; From patchwork Wed Mar 3 08:55:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12114775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37D19C432C3 for ; Thu, 4 Mar 2021 00:20:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 063BC64E6C for ; Thu, 4 Mar 2021 00:20:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1392433AbhCDATY (ORCPT ); Wed, 3 Mar 2021 19:19:24 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:11621 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378454AbhCCKuO (ORCPT ); Wed, 3 Mar 2021 05:50:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1614768613; x=1646304613; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hT5t8N9+1eafwIxw5Z/2lU8vPYtbe54WI5/O9RtLDqQ=; b=r3onRhWraccP8NtIfMo/pmi4+jFQt7zxFag2uZUo+423coegr+dsf+fn 8Y8+QFgYmm+NWcWckI8k1SNIrM0yEJdu6R1MGBxR7iHEOudjCasgEjdMR LqjvaWEI/C6VFj3CLHz0D3O95pi8SMfaL3vbGpPiHmQE4EKp7eCZwdI6z P7zLp2y7/Qv29tst2cYDijVfbGbLjbzwRzy+KZgE4eRXfTY50pgnvE1GA Kwg6JyaR9afgTVDS+4zGGisDtT/pdW8SgvD5D9AfwCV/s/p7xvvn+25ci saTfnlFDQ/LOx2dW+4HNgPVyGe8gTSMd0MZLuonMlXUD39YpLxdbBPhE9 Q==; IronPort-SDR: jhyTxsC2MffB0Gz96Lk43wYm88FzsSQWJxpkFyBulAJ/TSpGJZM+eRQm9IzBUXuBl6EV+XbpVK ZEzRW5Qwtun3YSpN0iPILAdKvDYL6gi8PN3GZYJIhV6ARdqH53szfKxhE5GAmBLSPilktk54X6 FIAMNgcC4qlt3bw/OYSX2DBdHM5DnEWmmOi3neoyWABHqLsy+6qFTAr4V3Nkowh2KGWWWu9emq iVoy++sU0W7MiLn6hYhqFgxPAgfGjIg0A26tnvnbri9PDiIiJtHfMJRAvBt4Yd4LeDyI0r+wYM GoA= X-IronPort-AV: E=Sophos;i="5.81,219,1610380800"; d="scan'208";a="271857773" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Mar 2021 16:55:56 +0800 IronPort-SDR: xOaPvzZflYV/TvHvT9Ki0qRJUfb18FBwgodMtrPMmsZyRncYNEznkAOtJTZGaGk3MwZeThBVFq 1Iy3WlyaOVCO0UvjFUpSzETW82BJ+JQpGRMYSg7G9JF+4LYBZB7uai3XLYRMj9UszBswvDqNPI TGWSEoyVVKDtmdU37EuNE8W5hzfZ8C+ryroUBIc3yYU74i/zjQNWvMRDBY9byX5POctA2+XOtg QAymv/v6Fa++8mJx03eO6AeHeUFUDaF8/YPsTfqWuFWs3UQMYeHUHKeRIwC5+G2VT+Z2ryd/4E mjNXhYVGhE8hW283UTDx3ygc Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2021 00:37:11 -0800 IronPort-SDR: DB1WoSh8PWnnFqVj03JC+stgK7jcvRhtLjJwqM7pOlB13+nJI8JMe1C7R27zQkuoLayls0D+12 0o+ayc/3urcnvZvRpQkIM50sG7DolxU0Lk6UU9B3/XfsoyFxj49prY/NLvATNxsRliiWQwiI/s vk1sZKJda2LsF5dEEfWW2GZBFRQlnvX99AGPAoPZV1SXUY95PxxubWt1dFcXPYtmh+JMAfwMpz t41Rb5NQ55nRACAlszwYCtjcs83pKZi/KjjGY7Bou78a75Ch8h8uuevTKuP+M2hqgfso0/rFQX SrU= WDCIronportException: Internal Received: from jpf010014.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.91]) by uls-op-cesaip01.wdc.com with ESMTP; 03 Mar 2021 00:55:55 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, dsterba@suse.com Cc: linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 3/3] btrfs: zoned: do not account freed region of read-only block group as zone_unusable Date: Wed, 3 Mar 2021 17:55:48 +0900 Message-Id: <1ce4bb0b205a2068770ca310f9217e761c0916c7.1614760899.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We migrate zone unusable bytes to read-only bytes when a block group is set to read-only, and account all the free region as bytes_readonly. Thus, we should not increase block_group->zone_unusable when the block group is read-only. Fixes: 169e0da91a21 ("btrfs: zoned: track unusable bytes for zones") Signed-off-by: Naohiro Aota --- fs/btrfs/free-space-cache.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 711a6a751ae9..81835153f747 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -2555,7 +2555,12 @@ static int __btrfs_add_free_space_zoned(struct btrfs_block_group *block_group, to_unusable = size - to_free; ctl->free_space += to_free; - block_group->zone_unusable += to_unusable; + /* + * If the block group is read-only, we should account freed + * space into bytes_readonly. + */ + if (!block_group->ro) + block_group->zone_unusable += to_unusable; spin_unlock(&ctl->tree_lock); if (!used) { spin_lock(&block_group->lock);