From patchwork Fri Mar 11 07:38:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12777530 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 D45CEC4332F for ; Fri, 11 Mar 2022 07:38:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347161AbiCKHjp (ORCPT ); Fri, 11 Mar 2022 02:39:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231806AbiCKHjo (ORCPT ); Fri, 11 Mar 2022 02:39:44 -0500 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17F154F9C8; Thu, 10 Mar 2022 23:38:42 -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=1646984321; x=1678520321; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jeCPpho/pRrNLIRebS5xYxPYkhodGWGJai8/U6MxEg0=; b=K2J5PQMoLtr09xbq2HPiT4ErkAs9dMU6YUQx0/twaU7NLnQ1ivLp8g+h R7/V2IOCPr+h0DWhcJioye7l21XA4bv7x/PZiLrQ2sBQGFlGHKOWgUmY7 26bF13hE3dK8l+kFu8Jb1FwZPS59ptWDMoUWrA4f8UnxjCb+GOsaeQbmf FkWBbjxfpbc8PDRueamjIg3tvi1AJYXzeTeVnLSdOQE8HEXQQFadyaC+9 yhRmOh6cv612Wh1WUH93qw2FBEV4aSwx/XCYUDhs5zs5NRyloAdwhtowY 9EVqVzfE0he+uB1LE7cgY/aGAMF7rJYvMXN4zEiPlCykCq9spKVj3Dq4u g==; X-IronPort-AV: E=Sophos;i="5.90,173,1643644800"; d="scan'208";a="199899084" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Mar 2022 15:38:41 +0800 IronPort-SDR: sp0LjSXM2j1NgRZJga5DojHNsBS8sGX+Uip2fixd92nAnGYwBP3iZG/Sr/fLxQicCn00eHIEJf xEJhrXS5lhO0o8jAB72BMpW9XRLkypbvdEmC8kfGPI3ILXqdUdfKvFHKkN3dRHe4ZQ0sX7PxZK AMNrLu9DtfF4osrPci8briBs9vC8cr8TnF0s9au4tBsVmM/eRxahcjPB2DkTdHXRUjypplqCaM JRMb5uSZ+VCUIYqw3j2i+kfLXs7ocIP2ul7IgyLwTbqDsrjLXRvq9iTe0+MR9ItKTCzqOaVG/l L+a6xRJUJrckQChKnstAcyo+ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2022 23:10:54 -0800 IronPort-SDR: i9t84WH50XF/cEm+tBgwkGRKmJboI6Ud0p/+ICQ5JpYy3XuyW8XPsAT+q6HIskkMqs9TlsYnW9 r6NgrzRnLtSKFPXLK3PyJ+nxK4AyIHcAIK61vSAONhh7dvVatTx4ixCljHf0Rfkj8yKiCWZnHt YsJd6U3hC+AMWBqrhq8PPOcCgvYKKgVC/9bbBlqPAEUWA1wbQpDtT5vpS5Uld5JP/9mLQ6+bXR tCyxorqZRiLvhI2J2eJfDAlgEaqB9akm8VYaAbS/97UNRNz+Ev9QCvN7ErQyrkkKDP4T6s0HES YgQ= WDCIronportException: Internal Received: from dyv5jr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.50.231]) by uls-op-cesaip02.wdc.com with ESMTP; 10 Mar 2022 23:38:41 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: johannes.thumshirn@wdc.com, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, david@fromorbit.com, Naohiro Aota Subject: [PATCH 1/4] btrfs: mark resumed async balance as writing Date: Fri, 11 Mar 2022 16:38:02 +0900 Message-Id: <65730df62341500bfcbde7d86eeaa3e9b15f1bcb.1646983176.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When btrfs balance is interrupted with umount, the background balance resumes on the next mount. There is a potential deadlock with FS freezing here like as described in commit 26559780b953 ("btrfs: zoned: mark relocation as writing"). Mark the process as sb_writing. To preserve the order of sb_start_write() (or mnt_want_write_file()) and btrfs_exclop_start(), call sb_start_write() at btrfs_resume_balance_async() before taking fs_info->super_lock. Fixes: 5accdf82ba25 ("fs: Improve filesystem freezing handling") Cc: stable@vger.kernel.org Signed-off-by: Naohiro Aota --- fs/btrfs/volumes.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1be7cb2f955f..0d27d8d35c7a 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4443,6 +4443,7 @@ static int balance_kthread(void *data) if (fs_info->balance_ctl) ret = btrfs_balance(fs_info, fs_info->balance_ctl, NULL); mutex_unlock(&fs_info->balance_mutex); + sb_end_write(fs_info->sb); return ret; } @@ -4463,6 +4464,7 @@ int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info) return 0; } + sb_start_write(fs_info->sb); spin_lock(&fs_info->super_lock); ASSERT(fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE_PAUSED); fs_info->exclusive_operation = BTRFS_EXCLOP_BALANCE; From patchwork Fri Mar 11 07:38:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12777531 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 30C34C433EF for ; Fri, 11 Mar 2022 07:38:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347213AbiCKHju (ORCPT ); Fri, 11 Mar 2022 02:39:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347163AbiCKHjp (ORCPT ); Fri, 11 Mar 2022 02:39:45 -0500 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 437E14F9C8; Thu, 10 Mar 2022 23:38:43 -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=1646984321; x=1678520321; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pQ/vgMzfkUEI4czLqMfrA8jdkm3Ndae0jcZtDlW3SfE=; b=grvk6LY719VLvKULHRFBnjTZkXLLKgutpliq5ue9oTBJK4SPQqw79Xsr 9DCCVYFOn4I2vVfnK1TUdWMHfZThD+E/lFKjhaBX5nwHdfKyDmjqSXU+O N3OT7UPm2zGBmEP7VutCnFKSGSU6eK8x/lKh71Mn4RF5P+4DcIBqz1lgb vGS/aPMcs6tdih0o1hmD9pG3qgGVxk7DhbDbx695RM/yziaMzddZVc3C8 xuRVQuMPbI47ygQae8ElOzOQ6V/HdSGkgBptqQGo3yQXNoXq8OoXPWKq3 SCJ4slCF5MdbE051kA9lgcxY2ogznYm7lGfk411nHGQUxZlOZ2FNGLJNe g==; X-IronPort-AV: E=Sophos;i="5.90,173,1643644800"; d="scan'208";a="199899088" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Mar 2022 15:38:41 +0800 IronPort-SDR: es39VIfq94u1NqQPl+Gk8ilaoaOH3LcLbH9SuEgXhOpjZ8se+b8REEjtzuopkoOYTyQzNLQc2U 4e3cpFHrwzQjk7LajqQSibNYN/ZMvf68PoJT668BU1NaXFXODFjD3F2uWoD3Z/GrMNsf4SPfVR Hvq4Ho+ASi++wefTwyKR0uravAqbaqHlCRGCsRgd7+t8UHS+QwJmc+M8izIHur+wFsMNr8FXyy OxObmdp0jabls0W8y5XNNOgATHZMXAuyheh3xdgfWYCxKHjDlOZzDDwYLl0tr+PP6frxFbF5f9 PwQeUkl6XjkupM5DatzNKQ9y Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2022 23:10:55 -0800 IronPort-SDR: sXPNJCABsu0Ckwxwjr9cqUUWp6OZOszVo3mlhAY134jJUgK6fGm0Z0KHP1irz2LK+s1quFQhyJ Pd/7jlz0l3Luaq/1bh+GKy9YrRgeiPJZchiwY0g/b6mF43vLGP5K+ZpfHkvVfrH8X27jIJG4X/ 16YYhvlDYM+Cn8tGkhPzj+BhGW7jEPUUGWM/1LtKx5QzlEnTT8qeJTp3E/FesM3bkZmDjMOg5Z f4/uNPQkpkw1YZKO5x8Y+GXYWs56uMrkdufynucz2yRD1Wx10yNpGlHiJRKJr5UqsU9neZBCq/ FvU= WDCIronportException: Internal Received: from dyv5jr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.50.231]) by uls-op-cesaip02.wdc.com with ESMTP; 10 Mar 2022 23:38:42 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: johannes.thumshirn@wdc.com, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, david@fromorbit.com, Naohiro Aota Subject: [PATCH 2/4] btrfs: mark device addition as sb_writing Date: Fri, 11 Mar 2022 16:38:03 +0900 Message-Id: <09e63a62afe0c03bac24cfbfe37316f97e13e113.1646983176.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org btrfs_init_new_device() calls btrfs_relocate_sys_chunk() which incurs file-system internal writing. That writing can cause a deadlock with FS freezing like as described in like as described in commit 26559780b953 ("btrfs: zoned: mark relocation as writing"). Mark the device addition as sb_writing. This is also consistent with the removing device ioctl counterpart. Fixes: 5accdf82ba25 ("fs: Improve filesystem freezing handling") Cc: stable@vger.kernel.org Signed-off-by: Naohiro Aota --- fs/btrfs/ioctl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 238cee5b5254..ffa30fd3eed2 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3484,6 +3484,7 @@ static long btrfs_ioctl_add_dev(struct btrfs_fs_info *fs_info, void __user *arg) return -EINVAL; } + sb_start_write(fs_info->sb); if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_DEV_ADD)) { if (!btrfs_exclop_start_try_lock(fs_info, BTRFS_EXCLOP_DEV_ADD)) return BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS; @@ -3516,6 +3517,7 @@ static long btrfs_ioctl_add_dev(struct btrfs_fs_info *fs_info, void __user *arg) btrfs_exclop_balance(fs_info, BTRFS_EXCLOP_BALANCE_PAUSED); else btrfs_exclop_finish(fs_info); + sb_end_write(fs_info->sb); return ret; } From patchwork Fri Mar 11 07:38:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12777532 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 850B3C433FE for ; Fri, 11 Mar 2022 07:38:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347214AbiCKHjv (ORCPT ); Fri, 11 Mar 2022 02:39:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231806AbiCKHjq (ORCPT ); Fri, 11 Mar 2022 02:39:46 -0500 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D4D6541BD; Thu, 10 Mar 2022 23:38:44 -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=1646984322; x=1678520322; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aYgHb/WNHaZCE/viGgmF46/TgOrl1HXLBvnmPq9KaZE=; b=BU0yPepKlURQhdxEW/mxA/qyx01VIzO1PXpvDPADUVKLufBWWXYiD8cN P+38h4sqJRvIVjL9pWCiZNQtIV4Qls1pljAuMDUOhvGYcTNOYZLVDrAf4 vmezzRZUe6HNjYqADMODEdxswOu38kHWQUjrBlLEAZNwNHamUzFs8pfWn 7tyi32+P4YM1lOMHzy8UX8KyJnW4BJbCICyOiQ76dpuNIXZo65P1L3cLO bbO5gXOHIA+/AvvW0OyPV+OhIjwm0xi1EVwMcgeCEXUDR5O0NWbVwPteu xwMG/7cp0fdeUMmB7iTmPr8JmWEgap5iGT5GQTkInFdAMxWWeXaukbEAa g==; X-IronPort-AV: E=Sophos;i="5.90,173,1643644800"; d="scan'208";a="199899092" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Mar 2022 15:38:42 +0800 IronPort-SDR: BSm/FnfXWcKDfSEVy0WBY55ecVAL4kpz6MF4KoqHzr9FE5KFewuPoFBtB51ssFc57JELwg6CnO Q2t+UdsT75ZdWTRPojet6rYVKpHBoO7Abc/Br84ABFzGkaxdqY14NdKywI3YuZH5QfbkSXqnv7 if5zP26xLcDrRXbXyGXYES6at3LXwemHWJEq5KBO/2oqRxcWwDXs2xcM0bSn5AncZgVjKwM+4H KXW/f1m6wbYktoYJDHFbA23oCmRHdZXnj5U/8N126WZFBLQ9SY+KFfO0s+SmU5S4fpZ4uPHelD 9a8aa6mmLfn108gMTFFhlPcs Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2022 23:10:57 -0800 IronPort-SDR: fP4GHn30tO29Dw65gM+OCjtZ2ZtJPv9W5/3+aobzo9C8Pn0LM7YWyNZPaw3bkOVp4qWyL4d2bG avweEz9L2wOcSzmoS9IAkEamM8sRSMpopKN2JPlnilh2WtQTXRrq2ogi7NaWCpacqvNwYEaIkG 738rHsm3K1AKEB4TiSbyXEr5ryNaqMRi1xmmXxhgGKU3hPuqoBJYjZ9BnotaTX6P3zJsr1Fdup +7iUE0tzW4MrYBH9cCQssFDJKS5OV5MYRGLdNIsiMW5w9XrVQ+C8sKrUWuvAllIIHUckWfWEGe Wmk= WDCIronportException: Internal Received: from dyv5jr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.50.231]) by uls-op-cesaip02.wdc.com with ESMTP; 10 Mar 2022 23:38:44 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: johannes.thumshirn@wdc.com, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, david@fromorbit.com, Naohiro Aota Subject: [PATCH 3/4] fs: add check functions for sb_start_{write,pagefault,intwrite} Date: Fri, 11 Mar 2022 16:38:04 +0900 Message-Id: <407d74293ca164d44eb419d34c2365795e27c02f.1646983176.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add a function sb_write_started() to return if sb_start_write() is properly called. It is used in the next commit. Also, add the similar functions for sb_start_pagefault() and sb_start_intwrite(). Signed-off-by: Naohiro Aota Reviewed-by: Filipe Manana --- include/linux/fs.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index 27746a3da8fd..0c8714d64169 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1732,6 +1732,11 @@ static inline bool __sb_start_write_trylock(struct super_block *sb, int level) #define __sb_writers_release(sb, lev) \ percpu_rwsem_release(&(sb)->s_writers.rw_sem[(lev)-1], 1, _THIS_IP_) +static inline bool __sb_write_started(struct super_block *sb, int level) +{ + return lockdep_is_held_type(sb->s_writers.rw_sem + level - 1, 1); +} + /** * sb_end_write - drop write access to a superblock * @sb: the super we wrote to @@ -1797,6 +1802,11 @@ static inline bool sb_start_write_trylock(struct super_block *sb) return __sb_start_write_trylock(sb, SB_FREEZE_WRITE); } +static inline bool sb_write_started(struct super_block *sb) +{ + return __sb_write_started(sb, SB_FREEZE_WRITE); +} + /** * sb_start_pagefault - get write access to a superblock from a page fault * @sb: the super we write to @@ -1821,6 +1831,11 @@ static inline void sb_start_pagefault(struct super_block *sb) __sb_start_write(sb, SB_FREEZE_PAGEFAULT); } +static inline bool sb_pagefault_started(struct super_block *sb) +{ + return __sb_write_started(sb, SB_FREEZE_PAGEFAULT); +} + /** * sb_start_intwrite - get write access to a superblock for internal fs purposes * @sb: the super we write to @@ -1844,6 +1859,11 @@ static inline bool sb_start_intwrite_trylock(struct super_block *sb) return __sb_start_write_trylock(sb, SB_FREEZE_FS); } +static inline bool sb_intwrite_started(struct super_block *sb) +{ + return __sb_write_started(sb, SB_FREEZE_FS); +} + bool inode_owner_or_capable(struct user_namespace *mnt_userns, const struct inode *inode); From patchwork Fri Mar 11 07:38:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12777533 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 9BAB9C4332F for ; Fri, 11 Mar 2022 07:38:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347216AbiCKHjx (ORCPT ); Fri, 11 Mar 2022 02:39:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347173AbiCKHjr (ORCPT ); Fri, 11 Mar 2022 02:39:47 -0500 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80B1755208; Thu, 10 Mar 2022 23:38:45 -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=1646984323; x=1678520323; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4D1r2l1x0Nc7hKdRdIldPQPtNyBpfjRydgDwmsMl+Oo=; b=csDjoVJqa/JimWxiiEwkrqWwvdnu5nH2ge6J6g3VMQpRDz7ES8aEmlPa d4g6UgyI6D2YdlcjNTgJvC3ttimIy2akonwbuC1dcIWq1MoomqQ8FLcV/ NTqxRItaijMiuIMJcyNfFhFsmWz5KClDr/bYO+iYuSGpYKY+SZCMBvrLt cPKrwyuTVOlWkRxpwwuUQfqbvUmkIJQJXaPGjcMbhC6vv4SiQJ1C2yIjp ZZiyyQf9XrzGUlrlpALSEfHFVSELG2aqm0PkH0zoO5hBlTSdUYxNA4Smk PCzEAPIQU4n8wOVYumdquy+/rWTLHQlZSEZ0DbD/U0czMCz1PZaJVgK9l Q==; X-IronPort-AV: E=Sophos;i="5.90,173,1643644800"; d="scan'208";a="199899098" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 11 Mar 2022 15:38:43 +0800 IronPort-SDR: TI/HTqmY2p2s10YMwb4hEZVlgAf3adTMxFVIrXfOUweJSZi629qrKvJeQ4uKXvj/lqtL86LcHf QnO0bQ/8bHiyRTDLZjzNoBg8SuVplELJa6nHhXQ3Rfa92QRX8+ePCmdWsE6NKMAhf8vK5qg1Ez /DyjSj3Qzeb8B8b/y9mlkUxd9ccCkt66nsZg5NOn2VFDRI8u57MgdNSNmaKhe2DQv2FfeVRxsi Ze1f2+M3z4cBF6qs8BxqlcU0beBsxfqFAssh8k3+8/qT0G/dhzKeEfN7jEDSkXdXPv7Q4DJbBo 3NcMi195jlC/PA6OBwJZt/JF Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2022 23:10:58 -0800 IronPort-SDR: owNkfMOyxfjpTbPEnJp3MM/hvdGVjwzxTzvTBOF2bzvLuvOS3RiI5a3l6OBcFv2Y/Npen90Neo /NlMOf2Ph+fBq5qcwo7qfV0HOcqatke+O6H2Q39mD8G2TnoJ7lcsedLvO9bf2Xb8tNuuvpi5oG JUNzpRP2eUsoz3L/LAAN3a+TJ9wgJAuYO2Co9KUuarjowFj1etqvyEftUd2DQk3BB2cBriBB+X CiS+NTLYNxPY131QBTeQ2LvY3fvhoURXDNOhl3CTHIxKx4RLBvVorpS3iafMlxq6KEgUbqy1Pj bC0= WDCIronportException: Internal Received: from dyv5jr2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.50.231]) by uls-op-cesaip02.wdc.com with ESMTP; 10 Mar 2022 23:38:45 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: johannes.thumshirn@wdc.com, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, david@fromorbit.com, Naohiro Aota Subject: [PATCH 4/4] btrfs: assert that relocation is protected with sb_start_write() Date: Fri, 11 Mar 2022 16:38:05 +0900 Message-Id: <697674ea626a3d04218b02dbb12e07bdd851d3f0.1646983176.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org btrfs_relocate_chunk() initiates new ordered extents. They can cause a hang when a process is trying to thaw the filesystem. We should have called sb_start_write(), so the filesystem is not being frozen. Add an ASSERT to check it is protected. Signed-off-by: Naohiro Aota Reviewed-by: Filipe Manana --- fs/btrfs/volumes.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 0d27d8d35c7a..b558fd293ffa 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -3239,6 +3239,9 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset) u64 length; int ret; + /* Assert we called sb_start_write(), not to race with FS freezing */ + ASSERT(sb_write_started(fs_info->sb)); + if (btrfs_fs_incompat(fs_info, EXTENT_TREE_V2)) { btrfs_err(fs_info, "relocate: not supported on extent tree v2 yet");