From patchwork Wed Mar 16 13:22:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12782700 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 57187C433FE for ; Wed, 16 Mar 2022 13:23:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344803AbiCPNYX (ORCPT ); Wed, 16 Mar 2022 09:24:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238918AbiCPNYW (ORCPT ); Wed, 16 Mar 2022 09:24:22 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8836CA188; Wed, 16 Mar 2022 06:23:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1647436987; x=1678972987; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kCqIT6QE4X6rjqZGfyRVMUMbl6cnDFW78z03eIIrjMY=; b=nE1f0ZxYzkW4mhBTvgSz+l/quHxF2TrrSxIehT6vT9tjZBzL+uCSsUDw Ayxh81Jn5YdTZmN78gyI6HEw1yDv2WBlK2kmDquN+QZfoU1oZLFyNLRSK 1Nfy69yUsEQXzlYER65E1aKXKiRZIzV7ZM3GAzApQexUMpFY+7aUjd+vu SrnuNOlOfqtLKBKUMPmUU5cxuO8Wn8jf4LFYIq21JMzvl6YL32RKHnE3f ZGLTaIb7+lGegglZ3YxMI4EVRWgrI0XsTRlC6utbEfxPCdnxPIVQ2zUe7 WCUufyZ1XU46VsniVMgznXYeSUEx+tcI2nrBwE3UkmdgPO5728XlqZLqJ g==; X-IronPort-AV: E=Sophos;i="5.90,186,1643644800"; d="scan'208";a="299654875" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2022 21:23:07 +0800 IronPort-SDR: KZaIeq9tbwICFt4rR1PhVvJ0cgLtAVWn1gthIG8yDHMw1j/Z/Svoti2BS7pdcttAZ2yAswgemm NhhDuSxQIjl6h9VwwfYw46BExCn7+U67CUTkLYJEIx5vylhZ8tBHatkAVAJ8dzNX0NHpd4SSoJ K9PabBnj+/xE+HjZzt5VV7VnQBB24SVItS3FwP4hOiwtAP0sMNBYB5y0CiJW3PRHlgDF7FqQuu +JwLKIkXIVgh0VR+Mim7wwTpDIrWQfNfhia31PAqUv2zBocW+y8jAOiNKc9Bd7WqvITs1wWERV yUzcgL+DFiy5g/FLexwuh3cp 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; 16 Mar 2022 05:54:13 -0700 IronPort-SDR: h6pANHya6cNJa88DC1iwMORVk1t0Z8B8LtArPceHg4/YDHusZQRsHTopJVcfBLjNEgAKBLC9s7 vRFfQrslHKWv+DjIGaZO3sXCp154mYZstC46dBPLKmwOd9EzELnJrcoq1sG1rQpX2guq/0Dm/m ikfGZYO9mbEwHqD2ikSoBaKXda/+9FDhBIi1fdv0xA6Saw6zFOPaqFHoMGDt5DgZ2ctQ9Ccwf0 fubirgoV1fjxA5ei3Kudto/Gu//YByWevcAtSjtj5hDXW6Qrc0b8IeGqOE7eEPb306I8i8899s grk= WDCIronportException: Internal Received: from d2bbl13.ad.shared (HELO naota-xeon.wdc.com) ([10.225.55.209]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Mar 2022 06:23:06 -0700 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 v2 1/4] btrfs: mark resumed async balance as writing Date: Wed, 16 Mar 2022 22:22:37 +0900 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 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. Cc: stable@vger.kernel.org # 4.9+ Signed-off-by: Naohiro Aota Reviewed-by: Filipe Manana --- fs/btrfs/volumes.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 3fd17e87815a..3471698fd831 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4430,10 +4430,12 @@ static int balance_kthread(void *data) struct btrfs_fs_info *fs_info = data; int ret = 0; + sb_start_write(fs_info->sb); mutex_lock(&fs_info->balance_mutex); 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; } From patchwork Wed Mar 16 13:22:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12782702 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 4ECB7C4332F for ; Wed, 16 Mar 2022 13:23:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348810AbiCPNYZ (ORCPT ); Wed, 16 Mar 2022 09:24:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242794AbiCPNYW (ORCPT ); Wed, 16 Mar 2022 09:24:22 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C63D213E98; Wed, 16 Mar 2022 06:23:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1647436988; x=1678972988; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=alf05YzTWExykrDr4nOA1oxCnGH0bd9x1s4DBonX7yU=; b=Xit+ZN/FzCrV7/HYGmTAScYDXY6EJVI7bn3RXlPnYe3R0bDiRIjN2BbK 8qlB+ZWIBZkAnJYJ7mzR4mgCGGXNuIprQ/iW4+xFTwWuPc6fHEuwrU4I0 CRO5xrUEi802OnKQ8tZ+m5XGoVhdyBXd5vilgweOuCtFe+LIqzNT7h66w 2cPV9Y931EZbVA8fIQnjRwqhjKqFq6IeO+aXkMpmGA7QiMHUrNgtlK3OP ppq5Gh8onOrgzVANvxXhh0Uf7bi5m6CZuxgidFKOSyJaLF7m95RCHEpyX kFW8U3TD9LHZRl0qg8xXzZ8EcGzweR1gS5YfCBBDfdKQp3hI4hdeBAFFd g==; X-IronPort-AV: E=Sophos;i="5.90,186,1643644800"; d="scan'208";a="299654883" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2022 21:23:08 +0800 IronPort-SDR: M4OS0KtaXBDoGms6J0RzXV2gLiDrqDQSmmgykCmmWsK6f8aizVB9dBBz1ejgj/RaA3KbJXe1Ol fvwIOG44aKpBnSC0e1cSYVy11KOlC77AKssQW1u9Tk6vvd09MDbi8WiODILYK17GGTpXyX5AlH LIvQbVYLiWwlLmLt8npDn4KJSkrA5w64c4smuL3AeaZpJuEg5E/kPq4MzxedpeHcC/lUCNG8Sd TSw56JPfQ68nzU/O8oUFgrXre2weSFbyiV0m6dLpDA02BQc0LjabUZFWjJAKDWMNAXxLf5pMdp vSUMOdyS8/0vUvIpsY89l4RZ 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; 16 Mar 2022 05:54:14 -0700 IronPort-SDR: yGqvzEQDJlkkAM1Obt4VXtEv35c12+C1oO1SQ2rPKTlbv6pLZx01+kL7Y2Ykrmx7skmm7hBtJ5 xEZcuF0ZndyiYBQnY91dZzKJ+lFfvl9WyFSk5oxW5iSFmuMrN/LYBjFJSFm3Hxrnr48A3Y1iyN +PcZMLNXaKnrXLJ0xtcn29FUgfS0nO8ZMGBA3V7s7ZoDDnJQ+76OmU0txALqVGPtSbSD7XLJMD eLLcZtPQyn2WZ70uiGjh/etrUbGhHZuc3iycaXx5q7SJjFq7BIVwu3j5kvKQCr7orYeavPNMiQ Y9E= WDCIronportException: Internal Received: from d2bbl13.ad.shared (HELO naota-xeon.wdc.com) ([10.225.55.209]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Mar 2022 06:23:07 -0700 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 v2 2/4] btrfs: mark device addition as mnt_want_write_file Date: Wed, 16 Mar 2022 22:22:38 +0900 Message-Id: <4b8a439c276e774ab2402cbd5395061ea0bd3cde.1647436353.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-btrfs@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 mnt_want_write_file. This is also consistent with the removing device ioctl counterpart. Cc: stable@vger.kernel.org # 4.9+ Signed-off-by: Naohiro Aota Reported-by: kernel test robot --- fs/btrfs/ioctl.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 60c907b14547..a6982a1fde65 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3474,8 +3474,10 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) return ret; } -static long btrfs_ioctl_add_dev(struct btrfs_fs_info *fs_info, void __user *arg) +static long btrfs_ioctl_add_dev(struct file *file, void __user *arg) { + struct inode *inode = file_inode(file); + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_ioctl_vol_args *vol_args; bool restore_op = false; int ret; @@ -3488,6 +3490,10 @@ static long btrfs_ioctl_add_dev(struct btrfs_fs_info *fs_info, void __user *arg) return -EINVAL; } + ret = mnt_want_write_file(file); + if (ret) + return ret; + 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; @@ -3520,6 +3526,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); + mnt_drop_write_file(file); return ret; } @@ -5443,7 +5450,7 @@ long btrfs_ioctl(struct file *file, unsigned int case BTRFS_IOC_RESIZE: return btrfs_ioctl_resize(file, argp); case BTRFS_IOC_ADD_DEV: - return btrfs_ioctl_add_dev(fs_info, argp); + return btrfs_ioctl_add_dev(file, argp); case BTRFS_IOC_RM_DEV: return btrfs_ioctl_rm_dev(file, argp); case BTRFS_IOC_RM_DEV_V2: From patchwork Wed Mar 16 13:22:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12782703 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 ABA8CC433F5 for ; Wed, 16 Mar 2022 13:23:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348619AbiCPNY1 (ORCPT ); Wed, 16 Mar 2022 09:24:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345149AbiCPNYX (ORCPT ); Wed, 16 Mar 2022 09:24:23 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B66B9140FE; Wed, 16 Mar 2022 06:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1647436989; x=1678972989; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uhsr+hAyJHTjEB3uy9P7kpjmAwzMxcwAsXBKjsI5b2k=; b=N2lEjCZBfO6Wxoezs3ZrfsFEZHPiHahIYSIXfALDdM9oUCGTzKq3XNmC CE1aIdKji50HLLyQ3f0gC3MQd3LsaNdtcehrJJKLodgy9cuj9eHPkIc0V +jKvGkjMKQpCdd6WZIDcKxU+LE8/CRABO6LcAkO7QWB1daXB/xlTjwoqj egAonzxmgyiPyWujKUF36anV8QFkvvFmoSLZLptwJOETf96ZXILbe79rX qvxrwJtm66gMrUUfe+hh5BkDOTJxRwNOnCGS2C+oi/jRAbsH+Sn3y4KOz kcP0mKicCrZgcnJMv9bR2e0CkQk7mFyS7PBtUpcinePiiWdXhvp7A4L65 A==; X-IronPort-AV: E=Sophos;i="5.90,186,1643644800"; d="scan'208";a="299654886" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2022 21:23:09 +0800 IronPort-SDR: DHsl7/8JGLlotVDr6b8x4Cueb3+vkFM3ot5gbwbW10WgRGXhTNuiczo1E8t2VBgWA4c8WyWWHX B1cEYS6jTVJS81ICoZpYxSBZsAfwuI5QLRw0PwdcK4ifcADeMWmGWM2KBq7Le2Zn3dw80YP/01 HM3JVoq6zr2mlbHVb/7nXGIcPO3uSRK40kYcQrVJK3Tds6IBxvpUbrVJZ0gtxaFj1bNQFDq8bJ gEPI0OsvTIi6B56/wIsjaOJLeFmHrxhdIqjkY9fMgMgU4nAwS7T0wki2AIor3VhtzXXTCM27LB 4Ek4RP4GaokDsrpQ5jFqowdF 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; 16 Mar 2022 05:54:15 -0700 IronPort-SDR: 7ICxNgif4XgkY2QAIJV85q0m8sytyrsLRX9hdRwnYeFComOZnwJNi92XrC3or07giHjP/99NVs fuDJZBs4hLGoFE3phhGNzWTHhE+Q4n/hwaH7HP0GF/9mH4Uve3XDwOlW2xWBY3gMJ7vw2mVKX2 7+gq1nfmWx2F/RClbne3WFVnzI4LZZztDFDbqBZ0zp9LI35P8y3q663PWd/tMK8XxFuUT/U7eq 1Dzn1LkIBpkZ7OrdcU2a6T+mmX2UmbLixMLM6lM4oDRVwbIFMVn13hRkxYSQEnbDN+r2rDaPAC Emk= WDCIronportException: Internal Received: from d2bbl13.ad.shared (HELO naota-xeon.wdc.com) ([10.225.55.209]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Mar 2022 06:23:08 -0700 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 , Filipe Manana Subject: [PATCH v2 3/4] fs: add check functions for sb_start_{write,pagefault,intwrite} Date: Wed, 16 Mar 2022 22:22:39 +0900 Message-Id: <0737603ecc6baf785843d6e91992e6ef202c308c.1647436353.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-btrfs@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(). Reviewed-by: Filipe Manana Signed-off-by: Naohiro Aota --- 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 Wed Mar 16 13:22:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12782704 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 9B017C4332F for ; Wed, 16 Mar 2022 13:23:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356223AbiCPNY3 (ORCPT ); Wed, 16 Mar 2022 09:24:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348686AbiCPNYZ (ORCPT ); Wed, 16 Mar 2022 09:24:25 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F044E140FE; Wed, 16 Mar 2022 06:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1647436991; x=1678972991; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QjZyVW2Vmz9PfM7KmmbwgSWBd6UhTpv2ye+92Bbx6tI=; b=Xziow4cuik54hi8blkhJ1tB5szf7Et8jbdb46UUoKiQuNlRSU5mUzn5Y aZSiZzr+SLMLWfS1dAB7LHT7Z2SegCr8ZgqJ2l4cOEN4lA11POD9xjnQ7 ir2W7+TCck3XQ/gxG9dB0mcYISUK3KCm2pK+n68do/ZNURZqhwEWNhBMX soLEOAC7Cf9KybIGJWvO//HqFaSESCP+nSnKLJLSm2OnLk6ZVUEvrqhGX kSxEyKIWs4+AGeLuNEfU6FSBMXJiXQlO6gTR/GEaSSzvsZjqKEq2Xj9Qm HrwwwbSOV0oel/tM38enbqCIRWePw6rKGmp/IqO4UQfzPbuUwMXq+Fc6A A==; X-IronPort-AV: E=Sophos;i="5.90,186,1643644800"; d="scan'208";a="299654891" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 16 Mar 2022 21:23:10 +0800 IronPort-SDR: VIZpG+hzxKsXV83zWAoKKWRCw4fZnpCRZEunrq7EKTImnL0y0UvQdKYvVqpiQ/sYe416G2Vcyf x8mfdF4CAv/P6EcLS9mt4DvDPx5lHEqyT5cVpSlL9Jz3ZSFO2x/JCV9SrLnvOEsbsKMHBOsD+e W4nPl9jTNkLxtnApS/GR+ol/as83lpNHTqnlXoJLu6b2sRzy/IQGK42GLloAl6guT1CCvbO942 E1LR+5/RJhcpVlEftfry6lBT4kM/fj/n1df3YsljyFIUONK3L2z2AG5ptZkMWT5SqqZKKljDFh aI5swdztAc00DDv6eaJu8Lu7 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; 16 Mar 2022 05:54:17 -0700 IronPort-SDR: GMps7eOP8mqHYSEz31iuKTv3l681MnxrtnrOd/maTu+qcgCfi6QvSUyfr9JNPUbkdqLAwGAEFr YhBkU1hLv26k3a/+EXb5ydpWtQGw/dSyd9dSyCjsCbZmTIndlAPz1GayCPVeAtW0M8GJkMaRPT NxI8EuN2V4EsOt0Sl8iFI2mb/mPOecDo0ji+6waGOvGaVmzO42yNaCCJiBVPuCo/ZpnpvAMkdX 2hpQyyPsgMVMymyloZTmQFavxZ2boBQkW1fuaidco+sWVMJcg14Go1D8qhN8XsV0umIzL1UOzR scs= WDCIronportException: Internal Received: from d2bbl13.ad.shared (HELO naota-xeon.wdc.com) ([10.225.55.209]) by uls-op-cesaip01.wdc.com with ESMTP; 16 Mar 2022 06:23:10 -0700 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 , Filipe Manana Subject: [PATCH v2 4/4] btrfs: assert that relocation is protected with sb_start_write() Date: Wed, 16 Mar 2022 22:22:40 +0900 Message-Id: <3f88d51b35da92bf2391febd7186973cc9539e95.1647436353.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-btrfs@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. Reviewed-by: Filipe Manana Signed-off-by: Naohiro Aota --- fs/btrfs/volumes.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 3471698fd831..393fc7db99d3 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -3230,6 +3230,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");