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 B2444C54EBE for ; Mon, 16 Jan 2023 05:50:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231760AbjAPFuD (ORCPT ); Mon, 16 Jan 2023 00:50:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231807AbjAPFt7 (ORCPT ); Mon, 16 Jan 2023 00:49:59 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6C2C9006 for ; Sun, 15 Jan 2023 21:49:57 -0800 (PST) Received: from [0.0.0.0] ([149.28.201.231]) by mail.gmx.net (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1Mw9UK-1oPBix12ma-00s7uj for ; Mon, 16 Jan 2023 06:49:56 +0100 Message-ID: <91f22f9d-26e6-e649-7323-26352b2ffb62@gmx.com> Date: Mon, 16 Jan 2023 13:49:53 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Content-Language: en-US To: "linux-btrfs@vger.kernel.org" From: Qu Wenruo Subject: Deadlock scenario for __btrfs_map_lock(), and remove the extra mirror (from target device) in the future. Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:1rBMTRcJ/ZOBhmlQ6yUUecORiAEBC/M4NWNoJU/Kmud6Kfrp1oG Rn/zXXkpoBrZtz9mI0JPznEGcY+KlTuVG8G8igPI3270GYRbmo3ZBqZMxujPW/578O9bRj9 qi3idDTNg1hYV4ZuDnriwEYF7nYJIrB1GHIizUNhs3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Q8Mr1yApNmZ/C5Lj40PDtb5eHY= Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Hi, During my scrub rework (read path using btrfs_submit_bio()), I hit a deadlock situation which can happen in replace. Although this situation can only happen when calling btrfs_map_block() during replace, currently we didn't do that inside scrub, so it's not possible to hit yet. But it should be possible if we trigger read-repair during replace. This happens in the following sequence: 1. We found the error in the sector 2. We need to read from the next mirror 3. We can use the extra mirror from replace target device 4. We call btrfs_map_block() for the extra mirror The the following call chain happens: __btrfs_map_block(mirror_num = 2) |- down_read(&dev_replace->rwsem); `- get_extra_mirror_from_replace() `- __btrfs_map_block() `- down_read(&dev_replace->rwsem); I can understand removing the ability of using replace device as a target may be too large a change. But we should at least not call __btrfs_map_block() inside __btrfs_map_block()... In the long run, I'd say using replace target device as an extra mirror is not that beneficial, and can be removed for cleaner code. Thanks, Qu