From patchwork Mon Nov 18 23:04:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13879170 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3164F1D0DDE; Mon, 18 Nov 2024 23:04:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971087; cv=none; b=VWMQeZSpoj7ZEbm5Hie5mZJsX+ybwUEoq8T24JTWkdVkbMKMIE83B3vCsA02JmHDQRSU+CmqyEvYwWjBVVslXPFs1B1qQVBbEp7KCFL97NjGJtFewVHfYUQlF4/91qDb3L3qyI50IWM+WG4OOw1pLI6RC/wYujAScdJ60Wr93x4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971087; c=relaxed/simple; bh=jmJ4H6fsAxmvUhHg1MxFBsdBZX3AUZ6jOHO+8MLFBT0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EXuRb2+N1MhxqddRdU64IWIDQUbfV5ug29bOQmAA/lvLBZkilrvTsOqBF4noch9iOWV+Xckn3yQ2n7RAsUvuW516WXDQZ/c8K7lwgbF7QaA/egmrPu296j/0z8qntah74THZSrEtJXGxkY+lOWEGBKBA/KzrTChyGaDoWMXu7qA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ofi2ccV0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ofi2ccV0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FE72C4CECC; Mon, 18 Nov 2024 23:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731971087; bh=jmJ4H6fsAxmvUhHg1MxFBsdBZX3AUZ6jOHO+8MLFBT0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Ofi2ccV0N2DNh6FYsiAcx/pB38aEW+WhTDDHP3QsUNQ14RAV/KaaPVeXw/z7Ly0Wf xQmLy2OuX0LrkuAjyDyqvRjxzRx3gSKrfpQ6nRxwteGoLgvUvoPzLS5LJ6Q7KPJq/a xn3F9sITBCOIa+PjwOfn2P5+xdRYzPRkHhu8WsRbceLtiXWPV1Ad9PrGMOiC6kemGG wPLSQy1Eyy3A1SczwiEzZjCi0nRZkslg2ZNGzY2G7z0zxZr/vitQLr8bf58Ef1AlCc HqNPMB5MF/CG45R8mEOk84ptJTPH1tEhQaDoX3uQAaJrYOjTFz9NeeTrSrdxr2jLcz B080Mas4Bl3jw== Date: Mon, 18 Nov 2024 15:04:46 -0800 Subject: [PATCH 01/10] xfs: fix off-by-one error in fsmap's end_daddr usage From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: stable@vger.kernel.org, wozizhi@huawei.com, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173197084431.911325.16302324218533112215.stgit@frogsfrogsfrogs> In-Reply-To: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> References: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong In commit ca6448aed4f10a, we created an "end_daddr" variable to fix fsmap reporting when the end of the range requested falls in the middle of an unknown (aka free on the rmapbt) region. Unfortunately, I didn't notice that the the code sets end_daddr to the last sector of the device but then uses that quantity to compute the length of the synthesized mapping. Zizhi Wo later observed that when end_daddr isn't set, we still don't report the last fsblock on a device because in that case (aka when info->last is true), the info->high mapping that we pass to xfs_getfsmap_group_helper has a startblock that points to the last fsblock. This is also wrong because the code uses startblock to compute the length of the synthesized mapping. Fix the second problem by setting end_daddr unconditionally, and fix the first problem by setting start_daddr to one past the end of the range to query. Cc: # v6.11 Fixes: ca6448aed4f10a ("xfs: Fix missing interval for missing_owner in xfs fsmap") Signed-off-by: Darrick J. Wong Reported-by: Zizhi Wo Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_fsmap.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c index 82f2e0dd224997..3290dd8524a69a 100644 --- a/fs/xfs/xfs_fsmap.c +++ b/fs/xfs/xfs_fsmap.c @@ -163,7 +163,8 @@ struct xfs_getfsmap_info { xfs_daddr_t next_daddr; /* next daddr we expect */ /* daddr of low fsmap key when we're using the rtbitmap */ xfs_daddr_t low_daddr; - xfs_daddr_t end_daddr; /* daddr of high fsmap key */ + /* daddr of high fsmap key, or the last daddr on the device */ + xfs_daddr_t end_daddr; u64 missing_owner; /* owner of holes */ u32 dev; /* device id */ /* @@ -387,8 +388,8 @@ xfs_getfsmap_group_helper( * we calculated from userspace's high key to synthesize the record. * Note that if the btree query found a mapping, there won't be a gap. */ - if (info->last && info->end_daddr != XFS_BUF_DADDR_NULL) - frec->start_daddr = info->end_daddr; + if (info->last) + frec->start_daddr = info->end_daddr + 1; else frec->start_daddr = xfs_gbno_to_daddr(xg, startblock); @@ -736,11 +737,10 @@ xfs_getfsmap_rtdev_rtbitmap_helper( * we calculated from userspace's high key to synthesize the record. * Note that if the btree query found a mapping, there won't be a gap. */ - if (info->last && info->end_daddr != XFS_BUF_DADDR_NULL) { - frec.start_daddr = info->end_daddr; - } else { + if (info->last) + frec.start_daddr = info->end_daddr + 1; + else frec.start_daddr = xfs_rtb_to_daddr(mp, start_rtb); - } frec.len_daddr = XFS_FSB_TO_BB(mp, rtbcount); return xfs_getfsmap_helper(tp, info, &frec); @@ -933,7 +933,10 @@ xfs_getfsmap( struct xfs_trans *tp = NULL; struct xfs_fsmap dkeys[2]; /* per-dev keys */ struct xfs_getfsmap_dev handlers[XFS_GETFSMAP_DEVS]; - struct xfs_getfsmap_info info = { NULL }; + struct xfs_getfsmap_info info = { + .fsmap_recs = fsmap_recs, + .head = head, + }; bool use_rmap; int i; int error = 0; @@ -998,9 +1001,6 @@ xfs_getfsmap( info.next_daddr = head->fmh_keys[0].fmr_physical + head->fmh_keys[0].fmr_length; - info.end_daddr = XFS_BUF_DADDR_NULL; - info.fsmap_recs = fsmap_recs; - info.head = head; /* For each device we support... */ for (i = 0; i < XFS_GETFSMAP_DEVS; i++) { @@ -1013,17 +1013,23 @@ xfs_getfsmap( break; /* - * If this device number matches the high key, we have - * to pass the high key to the handler to limit the - * query results. If the device number exceeds the - * low key, zero out the low key so that we get - * everything from the beginning. + * If this device number matches the high key, we have to pass + * the high key to the handler to limit the query results, and + * set the end_daddr so that we can synthesize records at the + * end of the query range or device. */ if (handlers[i].dev == head->fmh_keys[1].fmr_device) { dkeys[1] = head->fmh_keys[1]; info.end_daddr = min(handlers[i].nr_sectors - 1, dkeys[1].fmr_physical); + } else { + info.end_daddr = handlers[i].nr_sectors - 1; } + + /* + * If the device number exceeds the low key, zero out the low + * key so that we get everything from the beginning. + */ if (handlers[i].dev > head->fmh_keys[0].fmr_device) memset(&dkeys[0], 0, sizeof(struct xfs_fsmap)); From patchwork Mon Nov 18 23:05:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13879171 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA3821E5717 for ; Mon, 18 Nov 2024 23:05:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971102; cv=none; b=XdJKAy23nEtyqnWsA/IE++SX1DAVgWXB97VK9JBta/0SxxoSZQ0eNXKnB6QUVtYB3Nfk6xCetL+Rfc8KppKlC6k/wD5qW0tbaVbfS7aYVFHKvlRofplBHr3WpkepyMC7VwjYFvQyTn/08Kke0k1XDupKAIpyPWJNyoDtoIWXBwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971102; c=relaxed/simple; bh=EyfBrxfYJDUB8ncykyWRLB/76vC+8xoUkRZLlOjGfEI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KICn/9Lx8O2OxbvKIjxp35fYPBgNMjK7PamIv2KGphJu/AkwEv/hGD6Kxc0DmBMUb0IjrxbPCvNljTMfiU8n3udcKktnOCk4zAZhK47OrgIvBAVHLD/XGlVf1LnNqbwhaH+MeU2Pa0/eDiideH1l2d3ZkmSdIWElsLruso7lYsU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KpJIF1JU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KpJIF1JU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9521C4CECC; Mon, 18 Nov 2024 23:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731971102; bh=EyfBrxfYJDUB8ncykyWRLB/76vC+8xoUkRZLlOjGfEI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KpJIF1JUQA11wEDXSklPzzFelvWTmcydU5S+Uw/eIFTiTZ8M79Due1lz1xmEs6Qse lA6X0Syvoz/UcbQ6xduF1fBIAd2Fw+SwoRbH2RCbc/lf/+5ymXaw9dHHxT3TR8jl5X bNumUUfzKpxfxLKP8ZRKVs9Tdroio/2dC7tGmE5ldQrCNxlfqMUo6kwWK+0J1nn0rl rmoOmQ6rcin69SX5ZLwfkzS0XjT0HWeXTH7RE5j11+SBEcoCTh8//SdxQQHg+zN0d3 4Flp+BxewzLbyWHzQK7BvLV08e/70TBslpVqAeJriZQF7yrBsTg2FBhE65G5e4hrPn G6egM2ojsaBvg== Date: Mon, 18 Nov 2024 15:05:02 -0800 Subject: [PATCH 02/10] xfs: metapath scrubber should use the already loaded inodes From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173197084448.911325.8377209709944240957.stgit@frogsfrogsfrogs> In-Reply-To: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> References: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Don't waste time in xchk_setup_metapath_dqinode doing a second lookup of the quota inodes, just grab them from the quotainfo structure. The whole point of this scrubber is to make sure that the dirents exist, so it's completely silly to do lookups. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/scrub/metapath.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/fs/xfs/scrub/metapath.c b/fs/xfs/scrub/metapath.c index b78db651346518..80467d6bc76389 100644 --- a/fs/xfs/scrub/metapath.c +++ b/fs/xfs/scrub/metapath.c @@ -196,36 +196,45 @@ xchk_setup_metapath_dqinode( struct xfs_scrub *sc, xfs_dqtype_t type) { + struct xfs_quotainfo *qi = sc->mp->m_quotainfo; struct xfs_trans *tp = NULL; struct xfs_inode *dp = NULL; struct xfs_inode *ip = NULL; - const char *path; int error; + if (!qi) + return -ENOENT; + + switch (type) { + case XFS_DQTYPE_USER: + ip = qi->qi_uquotaip; + break; + case XFS_DQTYPE_GROUP: + ip = qi->qi_gquotaip; + break; + case XFS_DQTYPE_PROJ: + ip = qi->qi_pquotaip; + break; + default: + ASSERT(0); + return -EINVAL; + } + if (!ip) + return -ENOENT; + error = xfs_trans_alloc_empty(sc->mp, &tp); if (error) return error; error = xfs_dqinode_load_parent(tp, &dp); - if (error) - goto out_cancel; - - error = xfs_dqinode_load(tp, dp, type, &ip); - if (error) - goto out_dp; - xfs_trans_cancel(tp); - tp = NULL; + if (error) + return error; - path = kasprintf(GFP_KERNEL, "%s", xfs_dqinode_path(type)); - error = xchk_setup_metapath_scan(sc, dp, path, ip); + error = xchk_setup_metapath_scan(sc, dp, + kstrdup(xfs_dqinode_path(type), GFP_KERNEL), ip); - xfs_irele(ip); -out_dp: xfs_irele(dp); -out_cancel: - if (tp) - xfs_trans_cancel(tp); return error; } #else From patchwork Mon Nov 18 23:05:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13879172 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C981E1E8825 for ; Mon, 18 Nov 2024 23:05:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971118; cv=none; b=CsNMZgBW7hnXNnlNQosYS74gUm1SdDaOyFNIi+BsGbqEINnrPW1/Zh9rc23ukEoXsx5/NvGv1DFNa9m8LEiy52d3SYqnYUdQSyqMPl//JzuRui1+MSBx5TLi1hVO5UWP8VTuGL/zT6H/mxWFe9YS1A0+rQWlDBdTcjzGcxZSv4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971118; c=relaxed/simple; bh=RClv7TgyUiAa7r9vBMdY+zDwG1IH5owph4dTxtgurHA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kwhT2pYbB02E7LOX6P3w2Nad4xABzygiRev+ek53oVocW+d9GrK2heDdhfEc1fKEO1TX0iVutcmebj6RFZozUXxE3svrZsPYAoy3xE1Ej4U7taefDBtKhAf6ZwaHQ9lb92TgEXkSqorPqP1vr5AH1eFbL4vQb9tPgTOUnuLZ7pY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LrUqf21b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LrUqf21b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 533D6C4CECF; Mon, 18 Nov 2024 23:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731971118; bh=RClv7TgyUiAa7r9vBMdY+zDwG1IH5owph4dTxtgurHA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=LrUqf21b1OILrE13ulC9HIkCm8q89DQ8992n5bynsCn9vG2jJPKvf4DIO6CfjaXQe Wt+sIQfVv44+N53RBdIjI1pJoXZlFRPrz3nKd25ILfyknUtZDA9dhFn7Ctr2tpvUvC 76gjMH8Dp8D6XQFNaPrzmOBKzpVs8dwYLi3wrECp332gf37P/S3M0FFj2roChlFf1W B/kY4HiUwnPpYuCN2oMaPNk4KkUeBZ5xG+WttEKtLWVlF3oPf2tWAeg++t++a1lTKD DqIp9hMq3klaYNoEHaLgHRPH3ycGOAooqqNl1dM0MIo3gQ33ZJ69Xzk5Kzhn9unU9t uUjVqiLgc+g7A== Date: Mon, 18 Nov 2024 15:05:17 -0800 Subject: [PATCH 03/10] xfs: keep quota directory inode loaded From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173197084464.911325.18182055244953182778.stgit@frogsfrogsfrogs> In-Reply-To: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> References: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong In the same vein as the previous patch, there's no point in the metapath scrub setup function doing a lookup on the quota metadir just so it can validate that lookups work correctly. Instead, retain the quota directory inode in memory so that we can check this. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/scrub/metapath.c | 37 ++++++------------------------------- fs/xfs/xfs_qm.c | 47 +++++++++++++++++++++++++---------------------- fs/xfs/xfs_qm.h | 1 + 3 files changed, 32 insertions(+), 53 deletions(-) diff --git a/fs/xfs/scrub/metapath.c b/fs/xfs/scrub/metapath.c index 80467d6bc76389..c678cba1ffc3f7 100644 --- a/fs/xfs/scrub/metapath.c +++ b/fs/xfs/scrub/metapath.c @@ -171,23 +171,13 @@ static int xchk_setup_metapath_quotadir( struct xfs_scrub *sc) { - struct xfs_trans *tp; - struct xfs_inode *dp = NULL; - int error; + struct xfs_quotainfo *qi = sc->mp->m_quotainfo; - error = xfs_trans_alloc_empty(sc->mp, &tp); - if (error) - return error; + if (!qi || !qi->qi_dirip) + return -ENOENT; - error = xfs_dqinode_load_parent(tp, &dp); - xfs_trans_cancel(tp); - if (error) - return error; - - error = xchk_setup_metapath_scan(sc, sc->mp->m_metadirip, - kasprintf(GFP_KERNEL, "quota"), dp); - xfs_irele(dp); - return error; + return xchk_setup_metapath_scan(sc, sc->mp->m_metadirip, + kstrdup("quota", GFP_KERNEL), qi->qi_dirip); } /* Scan a quota inode under the /quota directory. */ @@ -197,10 +187,7 @@ xchk_setup_metapath_dqinode( xfs_dqtype_t type) { struct xfs_quotainfo *qi = sc->mp->m_quotainfo; - struct xfs_trans *tp = NULL; - struct xfs_inode *dp = NULL; struct xfs_inode *ip = NULL; - int error; if (!qi) return -ENOENT; @@ -222,20 +209,8 @@ xchk_setup_metapath_dqinode( if (!ip) return -ENOENT; - error = xfs_trans_alloc_empty(sc->mp, &tp); - if (error) - return error; - - error = xfs_dqinode_load_parent(tp, &dp); - xfs_trans_cancel(tp); - if (error) - return error; - - error = xchk_setup_metapath_scan(sc, dp, + return xchk_setup_metapath_scan(sc, qi->qi_dirip, kstrdup(xfs_dqinode_path(type), GFP_KERNEL), ip); - - xfs_irele(dp); - return error; } #else # define xchk_setup_metapath_quotadir(...) (-ENOENT) diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c index b928b036990bc3..a4fa21dfd6b4ad 100644 --- a/fs/xfs/xfs_qm.c +++ b/fs/xfs/xfs_qm.c @@ -241,6 +241,10 @@ xfs_qm_destroy_quotainos( xfs_irele(qi->qi_pquotaip); qi->qi_pquotaip = NULL; } + if (qi->qi_dirip) { + xfs_irele(qi->qi_dirip); + qi->qi_dirip = NULL; + } } /* @@ -648,8 +652,7 @@ xfs_qm_init_timelimits( static int xfs_qm_load_metadir_qinos( struct xfs_mount *mp, - struct xfs_quotainfo *qi, - struct xfs_inode **dpp) + struct xfs_quotainfo *qi) { struct xfs_trans *tp; int error; @@ -658,7 +661,7 @@ xfs_qm_load_metadir_qinos( if (error) return error; - error = xfs_dqinode_load_parent(tp, dpp); + error = xfs_dqinode_load_parent(tp, &qi->qi_dirip); if (error == -ENOENT) { /* no quota dir directory, but we'll create one later */ error = 0; @@ -668,21 +671,21 @@ xfs_qm_load_metadir_qinos( goto out_trans; if (XFS_IS_UQUOTA_ON(mp)) { - error = xfs_dqinode_load(tp, *dpp, XFS_DQTYPE_USER, + error = xfs_dqinode_load(tp, qi->qi_dirip, XFS_DQTYPE_USER, &qi->qi_uquotaip); if (error && error != -ENOENT) goto out_trans; } if (XFS_IS_GQUOTA_ON(mp)) { - error = xfs_dqinode_load(tp, *dpp, XFS_DQTYPE_GROUP, + error = xfs_dqinode_load(tp, qi->qi_dirip, XFS_DQTYPE_GROUP, &qi->qi_gquotaip); if (error && error != -ENOENT) goto out_trans; } if (XFS_IS_PQUOTA_ON(mp)) { - error = xfs_dqinode_load(tp, *dpp, XFS_DQTYPE_PROJ, + error = xfs_dqinode_load(tp, qi->qi_dirip, XFS_DQTYPE_PROJ, &qi->qi_pquotaip); if (error && error != -ENOENT) goto out_trans; @@ -698,34 +701,33 @@ xfs_qm_load_metadir_qinos( STATIC int xfs_qm_create_metadir_qinos( struct xfs_mount *mp, - struct xfs_quotainfo *qi, - struct xfs_inode **dpp) + struct xfs_quotainfo *qi) { int error; - if (!*dpp) { - error = xfs_dqinode_mkdir_parent(mp, dpp); + if (!qi->qi_dirip) { + error = xfs_dqinode_mkdir_parent(mp, &qi->qi_dirip); if (error && error != -EEXIST) return error; } if (XFS_IS_UQUOTA_ON(mp) && !qi->qi_uquotaip) { - error = xfs_dqinode_metadir_create(*dpp, XFS_DQTYPE_USER, - &qi->qi_uquotaip); + error = xfs_dqinode_metadir_create(qi->qi_dirip, + XFS_DQTYPE_USER, &qi->qi_uquotaip); if (error) return error; } if (XFS_IS_GQUOTA_ON(mp) && !qi->qi_gquotaip) { - error = xfs_dqinode_metadir_create(*dpp, XFS_DQTYPE_GROUP, - &qi->qi_gquotaip); + error = xfs_dqinode_metadir_create(qi->qi_dirip, + XFS_DQTYPE_GROUP, &qi->qi_gquotaip); if (error) return error; } if (XFS_IS_PQUOTA_ON(mp) && !qi->qi_pquotaip) { - error = xfs_dqinode_metadir_create(*dpp, XFS_DQTYPE_PROJ, - &qi->qi_pquotaip); + error = xfs_dqinode_metadir_create(qi->qi_dirip, + XFS_DQTYPE_PROJ, &qi->qi_pquotaip); if (error) return error; } @@ -770,7 +772,6 @@ xfs_qm_init_metadir_qinos( struct xfs_mount *mp) { struct xfs_quotainfo *qi = mp->m_quotainfo; - struct xfs_inode *dp = NULL; int error; if (!xfs_has_quota(mp)) { @@ -779,20 +780,22 @@ xfs_qm_init_metadir_qinos( return error; } - error = xfs_qm_load_metadir_qinos(mp, qi, &dp); + error = xfs_qm_load_metadir_qinos(mp, qi); if (error) goto out_err; - error = xfs_qm_create_metadir_qinos(mp, qi, &dp); + error = xfs_qm_create_metadir_qinos(mp, qi); if (error) goto out_err; - xfs_irele(dp); + /* The only user of the quota dir inode is online fsck */ +#if !IS_ENABLED(CONFIG_XFS_ONLINE_SCRUB) + xfs_irele(qi->qi_dirip); + qi->qi_dirip = NULL; +#endif return 0; out_err: xfs_qm_destroy_quotainos(mp->m_quotainfo); - if (dp) - xfs_irele(dp); return error; } diff --git a/fs/xfs/xfs_qm.h b/fs/xfs/xfs_qm.h index e919c7f62f5780..35b64bc3a7a867 100644 --- a/fs/xfs/xfs_qm.h +++ b/fs/xfs/xfs_qm.h @@ -55,6 +55,7 @@ struct xfs_quotainfo { struct xfs_inode *qi_uquotaip; /* user quota inode */ struct xfs_inode *qi_gquotaip; /* group quota inode */ struct xfs_inode *qi_pquotaip; /* project quota inode */ + struct xfs_inode *qi_dirip; /* quota metadir */ struct list_lru qi_lru; int qi_dquots; struct mutex qi_quotaofflock;/* to serialize quotaoff */ From patchwork Mon Nov 18 23:05:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13879173 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63339153BE4; Mon, 18 Nov 2024 23:05:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971134; cv=none; b=khoy7Wpl2ki2JfHrpJ7uWw+ypsXxcMT4QJ7v5iTSKKAfa9gqTFUiNAGHK9SLTJ7WG/UclcShT1hLJygqtPtDSohNOFS1SeIExTWqJUlnnvI989A0ZIRL9vmXFRnt+1313m7FOxGToswRdjUYSb9D5cn/sKx7v9FdIX0jNPmF/mE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971134; c=relaxed/simple; bh=Z1R38SnehH6MB09rjsLVKG/DpEtCFdEVtBvmiBtwzRs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VWP5FJmgnQ7zHwrRYZWT5NXEqCjtp3rVri76E3/uGN5vD14L3Yrn6cDE+O/qKE63ZDcUopsVCckEZeOfQ1h0YPbVivLGixxL4mOm4NxdLwVXV34WFwf2z0MZlr3p+ldNn9FvtrbDZLeoiStG6vXLUCZKc0CdMJx+AsjAlbNfXq0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gUhqpemS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gUhqpemS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8875C4CECC; Mon, 18 Nov 2024 23:05:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731971134; bh=Z1R38SnehH6MB09rjsLVKG/DpEtCFdEVtBvmiBtwzRs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=gUhqpemSRhq6NmCLcWYN18N2Wa9W887z1dlvusLtaDPCBPNNHVRbQbDXaWCswy/F+ F6R661Ec3+//MB7HuFbalcax38JfD5b6WyFO6v7M3W4vJSa0V6HYyQUpTrcCf9tbVj nB/tnNaGlHnJgG0Pb5qME5MB9ydPHewgjTWkDn9HxowI2f1206Tt/JysbDLxnrWaE4 aZGMeGnarCWbwoT9q0eM/O79qdBaZWiwDTqQkWN1rTd5rLDZunKULek7mXOZtdsL3i 53Dsk2fM+Cbhrgzqxgqmr0XNTWVXlyZ4TfRq1xeWrPjCEMEH9N1/TFfrs7qogOLOMI 5fRdffg/Se6TQ== Date: Mon, 18 Nov 2024 15:05:33 -0800 Subject: [PATCH 04/10] xfs: return a 64-bit block count from xfs_btree_count_blocks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: stable@vger.kernel.org, linux-xfs@vger.kernel.org Message-ID: <173197084481.911325.2907716202971546808.stgit@frogsfrogsfrogs> In-Reply-To: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> References: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong With the nrext64 feature enabled, it's possible for a data fork to have 2^48 extent mappings. Even with a 64k fsblock size, that maps out to a bmbt containing more than 2^32 blocks. Therefore, this predicate must return a u64 count to avoid an integer wraparound that will cause scrub to do the wrong thing. It's unlikely that any such filesystem currently exists, because the incore bmbt would consume more than 64GB of kernel memory on its own, and so far nobody except me has driven a filesystem that far, judging from the lack of complaints. Cc: # v5.19 Fixes: df9ad5cc7a5240 ("xfs: Introduce macros to represent new maximum extent counts for data/attr forks") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_btree.c | 4 ++-- fs/xfs/libxfs/xfs_btree.h | 2 +- fs/xfs/libxfs/xfs_ialloc_btree.c | 4 +++- fs/xfs/scrub/agheader.c | 6 +++--- fs/xfs/scrub/agheader_repair.c | 6 +++--- fs/xfs/scrub/fscounters.c | 2 +- fs/xfs/scrub/ialloc.c | 4 ++-- fs/xfs/scrub/refcount.c | 2 +- fs/xfs/xfs_bmap_util.c | 2 +- 9 files changed, 17 insertions(+), 15 deletions(-) diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c index 2b5fc5fd16435d..c748866ef92368 100644 --- a/fs/xfs/libxfs/xfs_btree.c +++ b/fs/xfs/libxfs/xfs_btree.c @@ -5144,7 +5144,7 @@ xfs_btree_count_blocks_helper( int level, void *data) { - xfs_extlen_t *blocks = data; + xfs_filblks_t *blocks = data; (*blocks)++; return 0; @@ -5154,7 +5154,7 @@ xfs_btree_count_blocks_helper( int xfs_btree_count_blocks( struct xfs_btree_cur *cur, - xfs_extlen_t *blocks) + xfs_filblks_t *blocks) { *blocks = 0; return xfs_btree_visit_blocks(cur, xfs_btree_count_blocks_helper, diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h index 3b739459ebb0f4..c5bff273cae255 100644 --- a/fs/xfs/libxfs/xfs_btree.h +++ b/fs/xfs/libxfs/xfs_btree.h @@ -484,7 +484,7 @@ typedef int (*xfs_btree_visit_blocks_fn)(struct xfs_btree_cur *cur, int level, int xfs_btree_visit_blocks(struct xfs_btree_cur *cur, xfs_btree_visit_blocks_fn fn, unsigned int flags, void *data); -int xfs_btree_count_blocks(struct xfs_btree_cur *cur, xfs_extlen_t *blocks); +int xfs_btree_count_blocks(struct xfs_btree_cur *cur, xfs_filblks_t *blocks); union xfs_btree_rec *xfs_btree_rec_addr(struct xfs_btree_cur *cur, int n, struct xfs_btree_block *block); diff --git a/fs/xfs/libxfs/xfs_ialloc_btree.c b/fs/xfs/libxfs/xfs_ialloc_btree.c index 9b34896dd1a32f..6f270d8f4270cb 100644 --- a/fs/xfs/libxfs/xfs_ialloc_btree.c +++ b/fs/xfs/libxfs/xfs_ialloc_btree.c @@ -744,6 +744,7 @@ xfs_finobt_count_blocks( { struct xfs_buf *agbp = NULL; struct xfs_btree_cur *cur; + xfs_filblks_t blocks; int error; error = xfs_ialloc_read_agi(pag, tp, 0, &agbp); @@ -751,9 +752,10 @@ xfs_finobt_count_blocks( return error; cur = xfs_finobt_init_cursor(pag, tp, agbp); - error = xfs_btree_count_blocks(cur, tree_blocks); + error = xfs_btree_count_blocks(cur, &blocks); xfs_btree_del_cursor(cur, error); xfs_trans_brelse(tp, agbp); + *tree_blocks = blocks; return error; } diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c index 61f80a6410c738..1d41b85478da9d 100644 --- a/fs/xfs/scrub/agheader.c +++ b/fs/xfs/scrub/agheader.c @@ -458,7 +458,7 @@ xchk_agf_xref_btreeblks( { struct xfs_agf *agf = sc->sa.agf_bp->b_addr; struct xfs_mount *mp = sc->mp; - xfs_agblock_t blocks; + xfs_filblks_t blocks; xfs_agblock_t btreeblks; int error; @@ -507,7 +507,7 @@ xchk_agf_xref_refcblks( struct xfs_scrub *sc) { struct xfs_agf *agf = sc->sa.agf_bp->b_addr; - xfs_agblock_t blocks; + xfs_filblks_t blocks; int error; if (!sc->sa.refc_cur) @@ -840,7 +840,7 @@ xchk_agi_xref_fiblocks( struct xfs_scrub *sc) { struct xfs_agi *agi = sc->sa.agi_bp->b_addr; - xfs_agblock_t blocks; + xfs_filblks_t blocks; int error = 0; if (!xfs_has_inobtcounts(sc->mp)) diff --git a/fs/xfs/scrub/agheader_repair.c b/fs/xfs/scrub/agheader_repair.c index 0fad0baaba2f69..b45d2b32051a63 100644 --- a/fs/xfs/scrub/agheader_repair.c +++ b/fs/xfs/scrub/agheader_repair.c @@ -256,7 +256,7 @@ xrep_agf_calc_from_btrees( struct xfs_agf *agf = agf_bp->b_addr; struct xfs_mount *mp = sc->mp; xfs_agblock_t btreeblks; - xfs_agblock_t blocks; + xfs_filblks_t blocks; int error; /* Update the AGF counters from the bnobt. */ @@ -946,7 +946,7 @@ xrep_agi_calc_from_btrees( if (error) goto err; if (xfs_has_inobtcounts(mp)) { - xfs_agblock_t blocks; + xfs_filblks_t blocks; error = xfs_btree_count_blocks(cur, &blocks); if (error) @@ -959,7 +959,7 @@ xrep_agi_calc_from_btrees( agi->agi_freecount = cpu_to_be32(freecount); if (xfs_has_finobt(mp) && xfs_has_inobtcounts(mp)) { - xfs_agblock_t blocks; + xfs_filblks_t blocks; cur = xfs_finobt_init_cursor(sc->sa.pag, sc->tp, agi_bp); error = xfs_btree_count_blocks(cur, &blocks); diff --git a/fs/xfs/scrub/fscounters.c b/fs/xfs/scrub/fscounters.c index 4a50f8e0004092..ca23cf4db6c5ef 100644 --- a/fs/xfs/scrub/fscounters.c +++ b/fs/xfs/scrub/fscounters.c @@ -261,7 +261,7 @@ xchk_fscount_btreeblks( struct xchk_fscounters *fsc, xfs_agnumber_t agno) { - xfs_extlen_t blocks; + xfs_filblks_t blocks; int error; error = xchk_ag_init_existing(sc, agno, &sc->sa); diff --git a/fs/xfs/scrub/ialloc.c b/fs/xfs/scrub/ialloc.c index abad54c3621d44..4dc7c83dc08a40 100644 --- a/fs/xfs/scrub/ialloc.c +++ b/fs/xfs/scrub/ialloc.c @@ -650,8 +650,8 @@ xchk_iallocbt_xref_rmap_btreeblks( struct xfs_scrub *sc) { xfs_filblks_t blocks; - xfs_extlen_t inobt_blocks = 0; - xfs_extlen_t finobt_blocks = 0; + xfs_filblks_t inobt_blocks = 0; + xfs_filblks_t finobt_blocks = 0; int error; if (!sc->sa.ino_cur || !sc->sa.rmap_cur || diff --git a/fs/xfs/scrub/refcount.c b/fs/xfs/scrub/refcount.c index 2b6be75e942415..1c5e45cc64190c 100644 --- a/fs/xfs/scrub/refcount.c +++ b/fs/xfs/scrub/refcount.c @@ -491,7 +491,7 @@ xchk_refcount_xref_rmap( struct xfs_scrub *sc, xfs_filblks_t cow_blocks) { - xfs_extlen_t refcbt_blocks = 0; + xfs_filblks_t refcbt_blocks = 0; xfs_filblks_t blocks; int error; diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 1fe676710394e1..d08505bdfe17a3 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -112,7 +112,7 @@ xfs_bmap_count_blocks( struct xfs_mount *mp = ip->i_mount; struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); struct xfs_btree_cur *cur; - xfs_extlen_t btblocks = 0; + xfs_filblks_t btblocks = 0; int error; *nextents = 0; From patchwork Mon Nov 18 23:05:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13879174 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E94B41E909F; Mon, 18 Nov 2024 23:05:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971150; cv=none; b=C6t2KD/IJ4HbeHfiTPmpePt4jbViLVpw8esvr/9VMvZUpBWecmOfPLPk3SudJsVOovmSUg8cG2eT3NjfPQgVhwtIc5bZ832CP17QZdscVr2ocdFvjKn8CvWuR98kLJuo0SlPuepBY9vH4K9fkqAi9y3pbUNGoYiVpTRx29AV/Ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971150; c=relaxed/simple; bh=96Pae+UeVyDsjq0RGVcq5xt+TvbQKzRUBi7sUUINgOs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RQbPpX8QBw4LhIQvUIu2xu+m42neoUlLN0fUfTz0I5OYpzTFMlhrpaYWqoT0irPpd5KNZDejJe4csk4UbJvrnom2jOfjFpsr57X4IsjUNQVwYeZjkxC6fVXTwuWlJwNFDk8E9IlfZTcUv8MsCd22+fe92n4GWVLDD1Kszd4GP6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rP5qArkP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rP5qArkP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FD42C4CECC; Mon, 18 Nov 2024 23:05:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731971149; bh=96Pae+UeVyDsjq0RGVcq5xt+TvbQKzRUBi7sUUINgOs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=rP5qArkPiOwHm2AGt+WsnzXpP7tbjv6CQXeBpwv+cXkTCs3LttyW4CFEmZLnpexuJ 87aaqGoWhjxEwugW+5FVeLsDY0bqSAqHWzQRfzWnDGvOOlhUY2+w/c2vxY+kgdtoXH KC7GPU2Hn2+lFt4A9i2F2RzilNPJOcOsYjRA/YcAb3RpHgr144AaG6DSXvy4x9moOf w7njg6HBEvm3yGIHmRtvqHIVWu6HhNpfObYGVaqpm4o+KqynACbV0kDTYwmtUw+27y jaURtmX3impsG+hONk5gz7nPq2cmj8++k3wzQAhTv8Lu703WXIXRvJDWEPwZChxHZk TUiXBMSHb1YBg== Date: Mon, 18 Nov 2024 15:05:49 -0800 Subject: [PATCH 05/10] xfs: don't drop errno values when we fail to ficlone the entire range From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: stable@vger.kernel.org, linux-xfs@vger.kernel.org Message-ID: <173197084499.911325.9564765824006983077.stgit@frogsfrogsfrogs> In-Reply-To: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> References: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Way back when we first implemented FICLONE for XFS, life was simple -- either the the entire remapping completed, or something happened and we had to return an errno explaining what happened. Neither of those ioctls support returning partial results, so it's all or nothing. Then things got complicated when copy_file_range came along, because it actually can return the number of bytes copied, so commit 3f68c1f562f1e4 tried to make it so that we could return a partial result if the REMAP_FILE_CAN_SHORTEN flag is set. This is also how FIDEDUPERANGE can indicate that the kernel performed a partial deduplication. Unfortunately, the logic is wrong if an error stops the remapping and CAN_SHORTEN is not set. Because those callers cannot return partial results, it is an error for ->remap_file_range to return a positive quantity that is less than the @len passed in. Implementations really should be returning a negative errno in this case, because that's what btrfs (which introduced FICLONE{,RANGE}) did. Therefore, ->remap_range implementations cannot silently drop an errno that they might have when the number of bytes remapped is less than the number of bytes requested and CAN_SHORTEN is not set. Found by running generic/562 on a 64k fsblock filesystem and wondering why it reported corrupt files. Cc: # v4.20 Fixes: 3fc9f5e409319e ("xfs: remove xfs_reflink_remap_range") Really-Fixes: 3f68c1f562f1e4 ("xfs: support returning partial reflink results") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_file.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index b19916b11fd563..aba54e3c583661 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1228,6 +1228,14 @@ xfs_file_remap_range( xfs_iunlock2_remapping(src, dest); if (ret) trace_xfs_reflink_remap_range_error(dest, ret, _RET_IP_); + /* + * If the caller did not set CAN_SHORTEN, then it is not prepared to + * handle partial results -- either the whole remap succeeds, or we + * must say why it did not. In this case, any error should be returned + * to the caller. + */ + if (ret && remapped < len && !(remap_flags & REMAP_FILE_CAN_SHORTEN)) + return ret; return remapped > 0 ? remapped : ret; } From patchwork Mon Nov 18 23:06:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13879175 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 429041E7647; Mon, 18 Nov 2024 23:06:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971165; cv=none; b=tZ8inNISTbuFuIie44Q/ovup0PTk+gqhEVAKeSYQgOYXkNIua3swiPSgEez+7VWuC6oIvKwdqvWm8Mq+lbAIBMzr30hyU8qwMfgsuFyg5nrneUOK25UQhP+0JXDIOcw//qbiHgAQMon4jCKO0gZluvPVWSWS5BIzmdPMiAWV//Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971165; c=relaxed/simple; bh=XAwLHOUxahG/mP90Mk6jjoZYzomSv9T1f8vvMFpyXlc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dG4V6ErHAIafeq9crtPRn/5pmuCtPCzfSWEfdh7r2m0+KEDw3vQqM7j6+Xaciw2tznkT3AozRv2JF4qepFusQ0CKrugmS8T96OpO+J+0iMKhnvHLfdJ2+hpsnBKFFJs6tosLeq33c85dxcGz/MSgnlxOGkKnY1YvtMrBhNFIdpc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lWMelyy4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lWMelyy4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21721C4CECC; Mon, 18 Nov 2024 23:06:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731971165; bh=XAwLHOUxahG/mP90Mk6jjoZYzomSv9T1f8vvMFpyXlc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lWMelyy4NBNjGDdZeb72v46iPFmGnXgnZUaMvOQWbowkA49SmwsUYJZ0xvUKCuz2W JPDMdT9BJu+facIHFx74l0zMRHvonNNEMbvs1roKQeURMNmIiLbdM2yGrc72V5zyj7 +ZG6Yk+venE9W3praR9YwQKh6ZZpuZuFPY6u0n5ki783F+5bw2UO8M4suigjyLr9Y9 fNc7ub8/maK8MVaMlmUBzparIDIetwQPGwmgedX8ZjEIUBtwlz+tXkhnlut7m7xZkY FFIxkCxvbD1wzzR505d4cldBWNUf8CVXSWW1gC50bHgqESySWI5p0rLzh0tHk0cP3t AQ9kHs5T0lj8A== Date: Mon, 18 Nov 2024 15:06:04 -0800 Subject: [PATCH 06/10] xfs: separate healthy clearing mask during repair From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: stable@vger.kernel.org, linux-xfs@vger.kernel.org Message-ID: <173197084515.911325.13396294816751205852.stgit@frogsfrogsfrogs> In-Reply-To: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> References: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong In commit d9041681dd2f53 we introduced some XFS_SICK_*ZAPPED flags so that the inode record repair code could clean up a damaged inode record enough to iget the inode but still be able to remember that the higher level repair code needs to be called. As part of that, we introduced a xchk_mark_healthy_if_clean helper that is supposed to cause the ZAPPED state to be removed if that higher level metadata actually checks out. This was done by setting additional bits in sick_mask hoping that xchk_update_health will clear all those bits after a healthy scrub. Unfortunately, that's not quite what sick_mask means -- bits in that mask are indeed cleared if the metadata is healthy, but they're set if the metadata is NOT healthy. fsck is only intended to set the ZAPPED bits explicitly. If something else sets the CORRUPT/XCORRUPT state after the xchk_mark_healthy_if_clean call, we end up marking the metadata zapped. This can happen if the following sequence happens: 1. Scrub runs, discovers that the metadata is fine but could be optimized and calls xchk_mark_healthy_if_clean on a ZAPPED flag. That causes the ZAPPED flag to be set in sick_mask because the metadata is not CORRUPT or XCORRUPT. 2. Repair runs to optimize the metadata. 3. Some other metadata used for cross-referencing in (1) becomes corrupt. 4. Post-repair scrub runs, but this time it sets CORRUPT or XCORRUPT due to the events in (3). 5. Now the xchk_health_update sets the ZAPPED flag on the metadata we just repaired. This is not the correct state. Fix this by moving the "if healthy" mask to a separate field, and only ever using it to clear the sick state. Cc: # v6.8 Fixes: d9041681dd2f53 ("xfs: set inode sick state flags when we zap either ondisk fork") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/scrub/health.c | 57 ++++++++++++++++++++++++++++--------------------- fs/xfs/scrub/scrub.h | 6 +++++ 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/fs/xfs/scrub/health.c b/fs/xfs/scrub/health.c index ce86bdad37fa42..ccc6ca5934ca6a 100644 --- a/fs/xfs/scrub/health.c +++ b/fs/xfs/scrub/health.c @@ -71,7 +71,8 @@ /* Map our scrub type to a sick mask and a set of health update functions. */ enum xchk_health_group { - XHG_FS = 1, + XHG_NONE = 1, + XHG_FS, XHG_AG, XHG_INO, XHG_RTGROUP, @@ -83,6 +84,7 @@ struct xchk_health_map { }; static const struct xchk_health_map type_to_health_flag[XFS_SCRUB_TYPE_NR] = { + [XFS_SCRUB_TYPE_PROBE] = { XHG_NONE, 0 }, [XFS_SCRUB_TYPE_SB] = { XHG_AG, XFS_SICK_AG_SB }, [XFS_SCRUB_TYPE_AGF] = { XHG_AG, XFS_SICK_AG_AGF }, [XFS_SCRUB_TYPE_AGFL] = { XHG_AG, XFS_SICK_AG_AGFL }, @@ -133,7 +135,7 @@ xchk_mark_healthy_if_clean( { if (!(sc->sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT | XFS_SCRUB_OFLAG_XCORRUPT))) - sc->sick_mask |= mask; + sc->healthy_mask |= mask; } /* @@ -189,6 +191,7 @@ xchk_update_health( { struct xfs_perag *pag; struct xfs_rtgroup *rtg; + unsigned int mask = sc->sick_mask; bool bad; /* @@ -203,50 +206,56 @@ xchk_update_health( return; } - if (!sc->sick_mask) - return; - bad = (sc->sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT | XFS_SCRUB_OFLAG_XCORRUPT)); + if (!bad) + mask |= sc->healthy_mask; switch (type_to_health_flag[sc->sm->sm_type].group) { + case XHG_NONE: + break; case XHG_AG: + if (!mask) + return; pag = xfs_perag_get(sc->mp, sc->sm->sm_agno); if (bad) - xfs_group_mark_corrupt(pag_group(pag), sc->sick_mask); + xfs_group_mark_corrupt(pag_group(pag), mask); else - xfs_group_mark_healthy(pag_group(pag), sc->sick_mask); + xfs_group_mark_healthy(pag_group(pag), mask); xfs_perag_put(pag); break; case XHG_INO: if (!sc->ip) return; - if (bad) { - unsigned int mask = sc->sick_mask; - - /* - * If we're coming in for repairs then we don't want - * sickness flags to propagate to the incore health - * status if the inode gets inactivated before we can - * fix it. - */ - if (sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR) - mask |= XFS_SICK_INO_FORGET; + /* + * If we're coming in for repairs then we don't want sickness + * flags to propagate to the incore health status if the inode + * gets inactivated before we can fix it. + */ + if (sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR) + mask |= XFS_SICK_INO_FORGET; + if (!mask) + return; + if (bad) xfs_inode_mark_corrupt(sc->ip, mask); - } else - xfs_inode_mark_healthy(sc->ip, sc->sick_mask); + else + xfs_inode_mark_healthy(sc->ip, mask); break; case XHG_FS: + if (!mask) + return; if (bad) - xfs_fs_mark_corrupt(sc->mp, sc->sick_mask); + xfs_fs_mark_corrupt(sc->mp, mask); else - xfs_fs_mark_healthy(sc->mp, sc->sick_mask); + xfs_fs_mark_healthy(sc->mp, mask); break; case XHG_RTGROUP: + if (!mask) + return; rtg = xfs_rtgroup_get(sc->mp, sc->sm->sm_agno); if (bad) - xfs_group_mark_corrupt(rtg_group(rtg), sc->sick_mask); + xfs_group_mark_corrupt(rtg_group(rtg), mask); else - xfs_group_mark_healthy(rtg_group(rtg), sc->sick_mask); + xfs_group_mark_healthy(rtg_group(rtg), mask); xfs_rtgroup_put(rtg); break; default: diff --git a/fs/xfs/scrub/scrub.h b/fs/xfs/scrub/scrub.h index a7fda3e2b01377..5dbbe93cb49bfa 100644 --- a/fs/xfs/scrub/scrub.h +++ b/fs/xfs/scrub/scrub.h @@ -184,6 +184,12 @@ struct xfs_scrub { */ unsigned int sick_mask; + /* + * Clear these XFS_SICK_* flags but only if the scan is ok. Useful for + * removing ZAPPED flags after a repair. + */ + unsigned int healthy_mask; + /* next time we want to cond_resched() */ struct xchk_relax relax; From patchwork Mon Nov 18 23:06:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13879176 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C5EA1E767D; Mon, 18 Nov 2024 23:06:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971181; cv=none; b=HtWrIx/4cshNbdTlr3O129j3GUdr/ALQtDON13OnQMUuvSz59JJm87sjys+uf4kdoPbu12cNCp3mCljnNLdkYxlx4x1PldlOeMtS8cw69gvJdcbjcUE5ENpA87mY1NJCzVJun3VYdsQT5iuPys5FrH/070xgSidsxvug1rHSTGk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971181; c=relaxed/simple; bh=PvtW6tfIcNcUbhG3Xo1d2VxsQ+XoCeJz0XHMA34S+LI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ItjZjULqlP2Jpabhr2wnhOVvFGZQMEBSFnEKw+TOLuVTG39cYrR/tyj2QcFVMJ3+fz9Vmnw1uWN1Ge9GT1nF/JCu5OPpfTt8D3v350m9MbcQYgv8V4QNPScLC9ATGOfx/O0CdUBdlKrIX+NEynhuDBFrYKYOMP3Nk1QH1f8jIfU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Sxaym0uE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Sxaym0uE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B37B4C4CECF; Mon, 18 Nov 2024 23:06:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731971180; bh=PvtW6tfIcNcUbhG3Xo1d2VxsQ+XoCeJz0XHMA34S+LI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Sxaym0uETQAjbS1gBtnktWhIMExe7rQ8SEIdb90TkHF40dRITTgi9arFlWXYDUR7U 85X06PpKX+JEo+chs/j7/Y1kr2JXW22lYlzZHhujJmBRSD0KvePqlgwBzjZ3HUs5ue qzp8xO49q9p6KEhTDV1pzlup+EPAmxxrIAVRHEtnPYcBP9FA313hGHP2m7hvyg6wK+ pMz3laVO8yyjHALX1ydc0fWBAL3KOraeolNs4doXlTmvZZwyPjTxkCY0JsotOsFsOM KrdDNuUcgrM+5irc/GUsjEHGyiT5rOF2AYq34uWQB19WmCWuu7m/JCsbz3xWWD5fg/ w8wTemj8/utAg== Date: Mon, 18 Nov 2024 15:06:20 -0800 Subject: [PATCH 07/10] xfs: set XFS_SICK_INO_SYMLINK_ZAPPED explicitly when zapping a symlink From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: stable@vger.kernel.org, linux-xfs@vger.kernel.org Message-ID: <173197084532.911325.5157952313128832887.stgit@frogsfrogsfrogs> In-Reply-To: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> References: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong If we need to reset a symlink target to the "durr it's busted" string, then we clear the zapped flag as well. However, this should be using the provided helper so that we don't set the zapped state on an otherwise ok symlink. Cc: # v6.10 Fixes: 2651923d8d8db0 ("xfs: online repair of symbolic links") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/scrub/symlink_repair.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/xfs/scrub/symlink_repair.c b/fs/xfs/scrub/symlink_repair.c index d015a86ef460fb..953ce7be78dc2f 100644 --- a/fs/xfs/scrub/symlink_repair.c +++ b/fs/xfs/scrub/symlink_repair.c @@ -36,6 +36,7 @@ #include "scrub/tempfile.h" #include "scrub/tempexch.h" #include "scrub/reap.h" +#include "scrub/health.h" /* * Symbolic Link Repair @@ -233,7 +234,7 @@ xrep_symlink_salvage( * target zapped flag. */ if (buflen == 0) { - sc->sick_mask |= XFS_SICK_INO_SYMLINK_ZAPPED; + xchk_mark_healthy_if_clean(sc, XFS_SICK_INO_SYMLINK_ZAPPED); sprintf(target_buf, DUMMY_TARGET); } From patchwork Mon Nov 18 23:06:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13879177 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB8A4153BE4 for ; Mon, 18 Nov 2024 23:06:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971196; cv=none; b=OUfO7mXvepOO3n5EG2DgStQA6zdMSf/tU93LVlj9Q8ykNnx3dAEjikneBCOGc+7VhxROGoalrFeNdP5hGblnPFrqzrPqXWdmW+ZWKuH0t4uhy6FoNAYucvG9OMEvipXyzXHOkatIuS4ppBqDB7NxOUaXIrVbCu7lavMVVZKVdTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971196; c=relaxed/simple; bh=jpgtYhzEy0h6+jhMQGW8f72YX+1iogqws/uhpAFc434=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U5wn4NsWp6IvFKVTlCGlzRB+7f0xM+bHvnfdy36sH6OXm1qz3I2Wuf+/TT443Zbt5qbOv+rzA7hM/J5z9U6x9HHdo+WcxknX2X3Dxr7rQM2lqzHgiaLET4PzgKcRZOtv+ygR5Xpl5bY58SXElqRSnGvgBq6beNPy6sB2omfW0S4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mgWcF+iM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mgWcF+iM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A9B7C4CECC; Mon, 18 Nov 2024 23:06:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731971196; bh=jpgtYhzEy0h6+jhMQGW8f72YX+1iogqws/uhpAFc434=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=mgWcF+iMmPtflhQSphf6pycklhdTCAQCleeLyIJf+N6tHbNP3g7W3N7T7ewn3OMPE pK4LWKlLLWwxFGQgma//yeBkqtETcIR3yv5NWs3qqWQERVAivfbZlprDK0Oxx1WywX Q8S/41bwqCUQTbRk/QbkYUTfBbYStAlo2419ZcrpCjRHt9m2FUeAKKWpzZpTFc5Puw ZBus80bnQbc7hntNKmrEiZ5iKT3yoUEFAyT66KN1KkrBWPM3XQ/AKDV7No4pgCh09i qEqXl20yeAlX+B6zJFfhRLiJHj2hdOAV1D782Uc/cSf3N3ENdcDyKjMJ2o/zs2BIsR YuRUQlKhJ3PYg== Date: Mon, 18 Nov 2024 15:06:35 -0800 Subject: [PATCH 08/10] xfs: mark metadir repair tempfiles with IRECOVERY From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173197084549.911325.5472870057444935473.stgit@frogsfrogsfrogs> In-Reply-To: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> References: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Once in a long while, xfs/566 and xfs/801 report directory corruption in one of the metadata subdirectories while it's forcibly rebuilding all filesystem metadata. I observed the following sequence of events: 1. Initiate a repair of the parent pointers for the /quota/user file. This is the secret file containing user quota data. 2. The pptr repair thread creates a temporary file and begins staging parent pointers in the ondisk metadata in preparation for an exchange-range to commit the new pptr data. 3. At the same time, initiate a repair of the /quota directory itself. 4. The dir repair thread finds the temporary file from (2), scans it for parent pointers, and stages a dirent in its own temporary dir in preparation to commit the fixed directory. 5. The parent pointer repair completes and frees the temporary file. 6. The dir repair commits the new directory and scans it again. It finds the dirent that points to the old temporary file in (2) and marks the directory corrupt. Oops! Repair code must never scan the temporary files that other repair functions create to stage new metadata. They're not supposed to do that, but the predicate function xrep_is_tempfile is incorrect because it assumes that any XFS_DIFLAG2_METADATA file cannot ever be a temporary file, but xrep_tempfile_adjust_directory_tree creates exactly that. Fix this by setting the IRECOVERY flag on temporary metadata directory inodes and using that to correct the predicate. Repair code is supposed to erase all the data in temporary files before releasing them, so it's ok if a thread scans the temporary file after we drop IRECOVERY. Fixes: bb6cdd5529ff67 ("xfs: hide metadata inodes from everyone because they are special") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/scrub/tempfile.c | 10 ++++++++-- fs/xfs/xfs_inode.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/xfs/scrub/tempfile.c b/fs/xfs/scrub/tempfile.c index 4b7f7860e37ece..dc3802c7f678ce 100644 --- a/fs/xfs/scrub/tempfile.c +++ b/fs/xfs/scrub/tempfile.c @@ -223,6 +223,7 @@ xrep_tempfile_adjust_directory_tree( if (error) goto out_ilock; + xfs_iflags_set(sc->tempip, XFS_IRECOVERY); xfs_qm_dqdetach(sc->tempip); out_ilock: xrep_tempfile_iunlock(sc); @@ -246,6 +247,8 @@ xrep_tempfile_remove_metadir( ASSERT(sc->tp == NULL); + xfs_iflags_clear(sc->tempip, XFS_IRECOVERY); + xfs_ilock(sc->tempip, XFS_IOLOCK_EXCL); sc->temp_ilock_flags |= XFS_IOLOCK_EXCL; @@ -945,10 +948,13 @@ xrep_is_tempfile( /* * Files in the metadata directory tree also have S_PRIVATE set and - * IOP_XATTR unset, so we must distinguish them separately. + * IOP_XATTR unset, so we must distinguish them separately. We (ab)use + * the IRECOVERY flag to mark temporary metadir inodes knowing that the + * end of log recovery clears IRECOVERY, so the only ones that can + * exist during online repair are the ones we create. */ if (xfs_has_metadir(mp) && (ip->i_diflags2 & XFS_DIFLAG2_METADATA)) - return false; + return __xfs_iflags_test(ip, XFS_IRECOVERY); if (IS_PRIVATE(inode) && !(inode->i_opflags & IOP_XATTR)) return true; diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 2a4485fb990846..bd6b37beabacdd 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -231,7 +231,7 @@ xfs_iflags_clear(xfs_inode_t *ip, unsigned long flags) } static inline int -__xfs_iflags_test(xfs_inode_t *ip, unsigned long flags) +__xfs_iflags_test(const struct xfs_inode *ip, unsigned long flags) { return (ip->i_flags & flags); } From patchwork Mon Nov 18 23:06:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13879178 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AB95153BE4; Mon, 18 Nov 2024 23:06:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971212; cv=none; b=A+858ZHNjfmw4kM5X+jYoHP2FeNO1Kh7ECcnLt0XpuQcx/olOS8vM1zk3i1FOJrJqKYD4Rsxtj8Jg/63Vf9auarkNxv9xaT8S8RiFrX5yB/lOEdQkgttDJANEufKQudkE/wLms8VLoTYiE1Cl25UFVBTy6bZD3oBJcOoZpaRT3w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971212; c=relaxed/simple; bh=eLsu41YeD0HrTyRtmIQlUugqMJ3IXNNewNaUs639yJs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gdPhfypIst8pdtCb6TmvctNVDCSuv1epk5ODLCzOwGafU83cM8O1PE9l8GKQySSYAffJ2FTSJVcegxRsATnDAgVZeoY/hsyDYyJnR9GXYKveVK+TiTJiOSwKkcOvvvlAXdYi3GtfIJsTgHka8cCrwxWe64GC3So4UjN9p3h5yR4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D1mlkdsS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D1mlkdsS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE1ACC4CECC; Mon, 18 Nov 2024 23:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731971212; bh=eLsu41YeD0HrTyRtmIQlUugqMJ3IXNNewNaUs639yJs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=D1mlkdsSv5bzrYnReyWvYBEh8U5fhrjq44REhiIDXeSFlqh0xDysvzBdMaLoZJBg9 cctREXTyEraDCIWnsvZlYOI+TxXVVXl0Ls52CulTaGhhk9eIS6euP/zaEOTXS9ST9f wZ6pjs/T3Jxzoy7n+xHVlIklENwwe0k+DKCQDGcX4r1oqWZNcsp3W+mQB4FPiO65J7 4Sr+UgoN0t/ZM3vPKQ9lsEuwKUL0JFCUIrbuthFlZXZqV/imLg1PCgRNEDmCB50Kz9 Qczjb2ztJwA68O8JrGRmxo/hJ+iFI3ZBhoM6O8A+w0BH0BkOcDX7vw5PqHURuJUt6C 2rKaU/C0CM/+g== Date: Mon, 18 Nov 2024 15:06:51 -0800 Subject: [PATCH 09/10] xfs: fix null bno_hint handling in xfs_rtallocate_rtg From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: stable@vger.kernel.org, linux-xfs@vger.kernel.org Message-ID: <173197084566.911325.17606647892449835782.stgit@frogsfrogsfrogs> In-Reply-To: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> References: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong xfs_bmap_rtalloc initializes the bno_hint variable to NULLRTBLOCK (aka NULLFSBLOCK). If the allocation request is for a file range that's adjacent to an existing mapping, it will then change bno_hint to the blkno hint in the bmalloca structure. In other words, bno_hint is either a rt block number, or it's all 1s. Unfortunately, commit ec12f97f1b8a8f didn't take the NULLRTBLOCK state into account, which means that it tries to translate that into a realtime extent number. We then end up with an obnoxiously high rtx number and pointlessly feed that to the near allocator. This often fails and falls back to the by-size allocator. Seeing as we had no locality hint anyway, this is a waste of time. Fix the code to detect a lack of bno_hint correctly. This was detected by running xfs/009 with metadir enabled and a 28k rt extent size. Cc: # v6.12 Fixes: ec12f97f1b8a8f ("xfs: make the rtalloc start hint a xfs_rtblock_t") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_rtalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 0cb534d71119a5..fcfa6e0eb3ad2a 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1827,7 +1827,7 @@ xfs_rtallocate_rtg( * For an allocation to an empty file at offset 0, pick an extent that * will space things out in the rt area. */ - if (bno_hint) + if (bno_hint != NULLFSBLOCK) start = xfs_rtb_to_rtx(args.mp, bno_hint); else if (!xfs_has_rtgroups(args.mp) && initial_user_data) start = xfs_rtpick_extent(args.rtg, tp, maxlen); From patchwork Mon Nov 18 23:07:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13879179 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E434A1E908E for ; Mon, 18 Nov 2024 23:07:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971228; cv=none; b=m4a+dqj0VfKi14fD/crNRNp2SrOYejmiAQ1C3xbESZKulvDOXwzI56Hi/CQ2lo2ZEjtxb4NArs2ixrQfKblE6MDbuoPzUNXiCelm59Y2+gRUzBNIq9yLhz9VG2yHL8xHDVnd/brpBqwK+GFUUELOhTIGoQ2im00K37lpFXLUZwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731971228; c=relaxed/simple; bh=Dh4iXcgtG/qrc/VWDfyTd+YM+uKzGBaVs9a0zvvqgr0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eJTL4haD2aWTIU7bPsAKnFgAgbiOJK95ufBtyLMD57GApALtyYVh5PcWrg5Vg2D/0ysKUCwU0yDokIxjWUW5lX1Rd7trxIgQ9eM2Mx6COjFQRqOqrV/3SRYQTloGzM/Sj3WIbCReL47qcYGyMuvAkEuqBprn+/Ujt/0AveVu8K4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qj1h5KS9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qj1h5KS9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E253C4CED0; Mon, 18 Nov 2024 23:07:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731971227; bh=Dh4iXcgtG/qrc/VWDfyTd+YM+uKzGBaVs9a0zvvqgr0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Qj1h5KS90HuvyCbEgKq5mxo1a/3zyhhEepTCmdGTrhzwwqoxLyrxetoAG4wH+oSea 0jsyvkamPCYcOK2YWCqfosdFa1eChTSCk1v+m2s/JdM63asogaCF7gKJf1bfsaIqt/ Xfz4beW9SUiQCdha20RVMrsBsBZX7QcGJI0vznG5taCHzugIDKnLiQjdje0Fx/A5Lt c7myLhV1fAziIkhVw4Tr7+ZEPWmWvYTIo7lB9TE/5DxSG6YV+XTucB/AYbAmkdOhnj azDT6J+1dPQkEsXDYnkA/4SB30UYohuSEprm46PCBuT0il5cHqlGjSzdkUW9CF0/1j 9VWcNJV+aMFtA== Date: Mon, 18 Nov 2024 15:07:07 -0800 Subject: [PATCH 10/10] xfs: fix error bailout in xfs_rtginode_create From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: dan.carpenter@linaro.org, linux-xfs@vger.kernel.org Message-ID: <173197084583.911325.13436063890373729938.stgit@frogsfrogsfrogs> In-Reply-To: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> References: <173197084388.911325.10473700839283408918.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong smatch reported that we screwed up the error cleanup in this function. Fix it. Fixes: ae897e0bed0f54 ("xfs: support creating per-RTG files in growfs") Reported-by: Dan Carpenter Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_rtgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_rtgroup.c b/fs/xfs/libxfs/xfs_rtgroup.c index e74bb059f24fa1..4f3bfc884aff29 100644 --- a/fs/xfs/libxfs/xfs_rtgroup.c +++ b/fs/xfs/libxfs/xfs_rtgroup.c @@ -496,7 +496,7 @@ xfs_rtginode_create( error = xfs_metadir_create(&upd, S_IFREG); if (error) - return error; + goto out_cancel; xfs_rtginode_lockdep_setup(upd.ip, rtg_rgno(rtg), type);