From patchwork Thu Feb 16 20:33:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143757 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 3C154C61DA4 for ; Thu, 16 Feb 2023 20:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229536AbjBPUeC (ORCPT ); Thu, 16 Feb 2023 15:34:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjBPUeB (ORCPT ); Thu, 16 Feb 2023 15:34:01 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA0F77288 for ; Thu, 16 Feb 2023 12:33:59 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6651760C1A for ; Thu, 16 Feb 2023 20:33:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C538FC433D2; Thu, 16 Feb 2023 20:33:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579638; bh=FEcFkezD4pW+sJtiz41JVyBH/XDqxVkDRoGSRNfWgJo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ZI9LSVJsOtVyYthrU9dANhc4IYGq72C1GkqXwXtZ/InliZJd2sGSKvLzU9f7RsOFi taRpWcg3hYezRnR+Wsgi/jajoMhuYBOSSsulXT7f4koxg6Vx5jvi2VI3X6oOXFwvat OszzY5lVy0eTW9xuc9OFs7XO3h066waLal4hMx7vY1UVH/EhIojpek8IKrRuaOpl37 jfgTrgChS3kCCRHX1nWaoeBVZ1uoqHNr4x57yHay3brf7q0jg3xE2URgLPF14DS24j JRAw0w0pXi9qF1aNDnBSLZKTnki1bJiPeu+CR+1xjRbLuKbYMLDeTd0fbXJHx3JiQf L0LIp8pkLXJVg== Date: Thu, 16 Feb 2023 12:33:58 -0800 Subject: [PATCH 05/28] xfs: Hold inode locks in xfs_trans_alloc_dir From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , Catherine Hoang , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872440.3473407.9158565302104798420.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Modify xfs_trans_alloc_dir to hold locks after return. Caller will be responsible for manual unlock. We will need this later to hold locks across parent pointer operations Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Reviewed-by: Catherine Hoang --- fs/xfs/xfs_inode.c | 14 ++++++++++++-- fs/xfs/xfs_trans.c | 9 +++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 772e3f105b7b..e292688ee608 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1279,10 +1279,15 @@ xfs_link( if (xfs_has_wsync(mp) || xfs_has_dirsync(mp)) xfs_trans_set_sync(tp); - return xfs_trans_commit(tp); + error = xfs_trans_commit(tp); + xfs_iunlock(tdp, XFS_ILOCK_EXCL); + xfs_iunlock(sip, XFS_ILOCK_EXCL); + return error; error_return: xfs_trans_cancel(tp); + xfs_iunlock(tdp, XFS_ILOCK_EXCL); + xfs_iunlock(sip, XFS_ILOCK_EXCL); std_return: if (error == -ENOSPC && nospace_error) error = nospace_error; @@ -2518,15 +2523,20 @@ xfs_remove( error = xfs_trans_commit(tp); if (error) - goto std_return; + goto out_unlock; if (is_dir && xfs_inode_is_filestream(ip)) xfs_filestream_deassociate(ip); + xfs_iunlock(ip, XFS_ILOCK_EXCL); + xfs_iunlock(dp, XFS_ILOCK_EXCL); return 0; out_trans_cancel: xfs_trans_cancel(tp); + out_unlock: + xfs_iunlock(ip, XFS_ILOCK_EXCL); + xfs_iunlock(dp, XFS_ILOCK_EXCL); std_return: return error; } diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index 7bd16fbff534..43f4b0943f49 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -1356,6 +1356,8 @@ xfs_trans_alloc_ichange( * The caller must ensure that the on-disk dquots attached to this inode have * already been allocated and initialized. The ILOCKs will be dropped when the * transaction is committed or cancelled. + * + * Caller is responsible for unlocking the inodes manually upon return */ int xfs_trans_alloc_dir( @@ -1386,8 +1388,8 @@ xfs_trans_alloc_dir( xfs_lock_two_inodes(dp, XFS_ILOCK_EXCL, ip, XFS_ILOCK_EXCL); - xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL); - xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); + xfs_trans_ijoin(tp, dp, 0); + xfs_trans_ijoin(tp, ip, 0); error = xfs_qm_dqattach_locked(dp, false); if (error) { @@ -1410,6 +1412,9 @@ xfs_trans_alloc_dir( if (error == -EDQUOT || error == -ENOSPC) { if (!retried) { xfs_trans_cancel(tp); + xfs_iunlock(dp, XFS_ILOCK_EXCL); + if (dp != ip) + xfs_iunlock(ip, XFS_ILOCK_EXCL); xfs_blockgc_free_quota(dp, 0); retried = true; goto retry;