From patchwork Mon Mar 7 09:50:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12771460 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46727C4167B for ; Mon, 7 Mar 2022 10:02:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239776AbiCGKDh (ORCPT ); Mon, 7 Mar 2022 05:03:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240616AbiCGKBJ (ORCPT ); Mon, 7 Mar 2022 05:01:09 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23BAA44741 for ; Mon, 7 Mar 2022 01:50:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1646646633; x=1678182633; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ul9GXlz1m+drUDFZI0YV7rX7GRPyTWgtJ0WYupYmPhU=; b=oaymshnbiFBkNTb5UOjPQEhG7n6CGz75pytqIaZyaiEfwb1XoOOZJSg7 LfwFmUFQLMkvFXB6095tJ0Aiein9VMhOaewCukoMt/vVEEN9/H10XdVjd k/qJuEPSk3T+5BadfrcAR235/TXoSTPYq8UyInpSe01PGcP+/F5XFrzSC DwAarxFThXEuPQphU8TS49zN4rYDbZ4jh0zjJP8mjLuiqiNcANbkLJpki O2SEtHYQ+D/TB47r3ng5P66ny2QAgPonkAUXLrxEQxYoR65Maf9UPyqe4 LvRXwYjOkrmeKG3EIIVeSUmQXBnj0a2GDZNjPsuDB9CXt9r0S+yjHO3VD A==; X-IronPort-AV: E=Sophos;i="5.90,161,1643644800"; d="scan'208";a="195612174" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 07 Mar 2022 17:50:32 +0800 IronPort-SDR: 3J87Af7d2k9E8GFpSdN0lX9M1sUxTgnwMzPLtxFBZmXp0MZU6zI+O5sKKJaQHXCzzUnxem0+Fh Axcv87C7v7XDzxUbbjqMJIuFf/dLiiayengi4UpyQgpSxkfwRaaiIM/jF3pF3a4mpZvZ+tu8m0 I0acVSkWXnHMmr2gIc8bJEe8E3UFb7Co7PQdSHMbf6MRgQWBlAlswUTGdBBNIfSIFmcfGOqaH/ KnOfczgEsXK2oB2GWjCTIUMJ2vUh1va2r4sVC6qALno5IqFaI/2JA7Oy7TbMjTGPibEE2aVtSA vNxcobNE7KbJode8s0xxfNQu Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2022 01:21:49 -0800 IronPort-SDR: Nq88JFKwhlFM66en81ksP6J/f1WfK2LPGJYeuzAojppEDpWcxvpr96vQ8hKgu14bgsBlue2VWI 709TrAi7otds1MCOi0Ks3Kcq4Wcf5tePiDwmElRfWIoVtUZw9XU/wchVs7Q14CLtnDSgLMdW+s 9D0FlooDdx2kNNk4US1l+LW5U9HHUCdigaeUfH2jXPcv+cSIvsWNIMPtnoYJdY0+MdAe6EFvQz rmWkaV8mXATP575LEsedcmAWFtyzxsqjjBfw7IzipuD90HdRQRRRoah3LkImlw5so6TvjdUgX8 nRU= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Mar 2022 01:50:31 -0800 From: Johannes Thumshirn To: David Sterba Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 1/2] btrfs: zoned: use rcu list in btrfs_can_activate_zone Date: Mon, 7 Mar 2022 01:50:24 -0800 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_can_activate_zone() can be called with the device_list_mutex already held, which will lead to a deadlock. As we're only traversing the list for reads we can switch from the device_list_mutex to an rcu traversal of the list. Fixes: a85f05e59bc1 ("btrfs: zoned: avoid chunk allocation if active block group has enough space") Cc: Naohiro Aota Signed-off-by: Johannes Thumshirn --- fs/btrfs/zoned.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index b7b5fac1c779..cf6341d45689 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1986,8 +1986,8 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags) ASSERT((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0); /* Check if there is a device with active zones left */ - mutex_lock(&fs_devices->device_list_mutex); - list_for_each_entry(device, &fs_devices->devices, dev_list) { + rcu_read_lock(); + list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) { struct btrfs_zoned_device_info *zinfo = device->zone_info; if (!device->bdev) @@ -1999,7 +1999,7 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags) break; } } - mutex_unlock(&fs_devices->device_list_mutex); + rcu_read_unlock(); return ret; } From patchwork Mon Mar 7 09:50:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12771459 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F181C35295 for ; Mon, 7 Mar 2022 10:02:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239671AbiCGKDf (ORCPT ); Mon, 7 Mar 2022 05:03:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240634AbiCGKBK (ORCPT ); Mon, 7 Mar 2022 05:01:10 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B76E445AFF for ; Mon, 7 Mar 2022 01:50:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1646646635; x=1678182635; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ypD+j6Cmo6mkpJTarsYyH2i5J8diq8WwgIvmdRTjxy8=; b=OH5TCin/VzMJzHkpYR4Zyeo9wBWLKMXuMm51gVxGOgAwmZIYOdrfGYOX /ZHhJUm0ak5KBCVU8emBVEOcEKqTNANZVszWHSN1aJ5/BKARONZezKU1J L4ZvyS/GkOzWs+HnzVqwTfiLlAsaTvHaK36BL6sHwD8TMcARgq+zwTg3K k8kxC6GhdTbjX/8hXaNpuokr3LWtrf8AIOPhaGD3X5i0hN4JvDQ00sdjT 8kdLQJwF43QC0sFYJvJqBBg+hir+uTuoEMLyDteUk+yW1ytuVtS0QbQt+ xBf3WGFmViT+DNhvArz8hnA1jUeRG64BNKWHI+4XX6I2UBx6BAKnWf6qa g==; X-IronPort-AV: E=Sophos;i="5.90,161,1643644800"; d="scan'208";a="195612175" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 07 Mar 2022 17:50:32 +0800 IronPort-SDR: TorB5DNRRUKAOW/Qg2ili+AoxB4M/YAhx8HvaBiWAeEKRcW3FJe2Do2VE/lH5ZgfTzcgSoiKf+ Bp50dBSg3yjoPWJQBVcC7VIyKqQGzOFYXT3PBSvOWMIdK6gHMBmaMWinbd6sXMIwOzjcZ9uG+z 2kkW3MJf45H5J2fAIFtbWpPB5MGOW+X0VuWBguszgq59XTMA6Kq7sNz7ytIQAFBHLv615SeTMR LP/oJ5Pe2oaU+r/51MExkvLv5CFoeOUGblIROfYnfoUc/OYQbPBAMfDTLBHbHt0yxiAbM7inox RZFQfkFv8SXIrJcAhmtPp+sl Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2022 01:21:50 -0800 IronPort-SDR: X7YJhNaKzYoSRBPjg+7xjNDqQAa3cVU9Ffb4UDFqIz2ep7Esu9yt13Jr5O2PvB4JLpY6hE/pHC 56NpTfdTjkeguygUyHLnJ6L9qTSpyiQ7HHa/Ulxohut+/oTwKgUSxWqdqY0i3St1fggsZsZ2K1 9sbTm50z5MvJq7uUOtCk4VsdOrVUxMNnxZ0lbyGSFbL9L/Sr5QGilf0gzJ2wsQ42bELkoRp6Yz i2wrE38rgsWPGAZ/IHPzzNLKZ1s5rydYyNDQLJBRMAO8ax3ceIG5sYNQ2skJuKBUp7FZSjFq1Y /w8= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Mar 2022 01:50:32 -0800 From: Johannes Thumshirn To: David Sterba Cc: Johannes Thumshirn , linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] btrfs: zoned: remove left over ASSERT() Date: Mon, 7 Mar 2022 01:50:25 -0800 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org With commit dcf5652291f6 ("btrfs: zoned: allow DUP on meta-data block groups") we started allowing DUP on meta-data block-groups, so the ASSERT()s in btrfs_can_activate_zone() and btrfs_zoned_get_device() are no longer valid and in fact even harmful. Fixes: dcf5652291f6 ("btrfs: zoned: allow DUP on meta-data block groups") Signed-off-by: Johannes Thumshirn --- fs/btrfs/zoned.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index cf6341d45689..e50fe388ccae 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1801,7 +1801,6 @@ struct btrfs_device *btrfs_zoned_get_device(struct btrfs_fs_info *fs_info, map = em->map_lookup; /* We only support single profile for now */ - ASSERT(map->num_stripes == 1); device = map->stripes[0].dev; free_extent_map(em); @@ -1982,9 +1981,6 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags) if (!btrfs_is_zoned(fs_devices->fs_info)) return true; - /* Non-single profiles are not supported yet */ - ASSERT((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0); - /* Check if there is a device with active zones left */ rcu_read_lock(); list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) { @@ -2055,6 +2051,38 @@ void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 len btrfs_put_block_group(block_group); } +static void btrfs_zone_finish_endio_workfn(struct work_struct *work) +{ + struct btrfs_block_group *bg = + container_of(work, struct btrfs_block_group, zone_finish_work); + + wait_on_extent_buffer_writeback(bg->last_eb); + free_extent_buffer(bg->last_eb); + btrfs_zone_finish_endio(bg->fs_info, bg->start, bg->length); + btrfs_put_block_group(bg); +} + +void btrfs_schedule_zone_finish_bg(struct btrfs_block_group *bg, + struct extent_buffer *eb) +{ + if (!bg->seq_zone || + eb->start + eb->len * 2 <= bg->start + bg->zone_capacity) + return; + + if (WARN_ON(bg->zone_finish_work.func == + btrfs_zone_finish_endio_workfn)) { + pr_info("double scheduling BG %llu\n", bg->start); + return; + } + + /* For the work */ + btrfs_get_block_group(bg); + atomic_inc(&eb->refs); + bg->last_eb = eb; + INIT_WORK(&bg->zone_finish_work, btrfs_zone_finish_endio_workfn); + queue_work(system_unbound_wq, &bg->zone_finish_work); +} + void btrfs_clear_data_reloc_bg(struct btrfs_block_group *bg) { struct btrfs_fs_info *fs_info = bg->fs_info;