From patchwork Tue Jul 2 00:56:52 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: 13718763 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 E4D97EDE for ; Tue, 2 Jul 2024 00:56: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=1719881813; cv=none; b=bVbrGJrz/97i42db4UUDyx0rwuaa36ITJirIF1NVLBnQHQbJ7aeKm3k8wdjd4uaxL0xC6Q3ojQnycK646UrSJumYSQBKWTNeUMTbvLBW4g+0eqG0Pska+P5j/2MGoeDmOIGoEZbB+4zdbK6Obb8S4Aa6x7zR+x6YZmRl2ixaX74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719881813; c=relaxed/simple; bh=EHOcpvxzPw44FX1BI9a2UwZ76fsyFsNsXbbEjvetask=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ewq5oO4pwuSOWSDRSJ2lW5dhmiFXr+7i13iwhHWt5ic6gw9DoQBjkBINb1k8WOPVHBG/h8ZrhVKzcvrwE2XNZEFlI077WXsch+yn4BQCrlQc99o/RF4VAzuwX6DljvDj3FfWmCfCDZG20ihspriD0d+OPGMGDvivzmEgGkqWOG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lvNBjBDI; 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="lvNBjBDI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE131C116B1; Tue, 2 Jul 2024 00:56:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719881812; bh=EHOcpvxzPw44FX1BI9a2UwZ76fsyFsNsXbbEjvetask=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lvNBjBDIxS+heCO5/wP/ZTXLLYSAg5956HdW4mTb7/pX1zfWI9rFNMBYTtjB/ewLO FYme+ePNSEnFWVfJcBaFWzsawm9yhbQHkZhqK06io/24PgnFM5XpaKkWX/4tdVv8sI /Hm9VPFbbBGvonkUOqA4T1v/1Vd36qfNSfjBNtfODc/ftNzrtjc7vWwwocuyFv3nOL LTLukgv8bS6cWWDHQ2cxfClu9lJSkIRtEVEEQFSgQfRjInzJLE3xMRScu8IBQZLFhu fZ3KGRAjfgrRJuqSzf6PmpvgLgVXtdgzCVU3Pzw8p3uSB94+X3U4p/zkdnccz4hoUp WnzuWEYOA9nPw== Date: Mon, 01 Jul 2024 17:56:52 -0700 Subject: [PATCH 1/3] xfs_{db,repair}: add an explicit owner field to xfs_da_args From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988117239.2006964.2035449041267157890.stgit@frogsfrogsfrogs> In-Reply-To: <171988117219.2006964.1550137506522221205.stgit@frogsfrogsfrogs> References: <171988117219.2006964.1550137506522221205.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Update these two utilities to set the owner field of the da args structure prior to calling directory and extended attribute functions. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- db/namei.c | 1 + repair/phase6.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/db/namei.c b/db/namei.c index 6de0621616a6..41ccaa04b659 100644 --- a/db/namei.c +++ b/db/namei.c @@ -447,6 +447,7 @@ listdir( struct xfs_da_args args = { .dp = dp, .geo = dp->i_mount->m_dir_geo, + .owner = dp->i_ino, }; int error; diff --git a/repair/phase6.c b/repair/phase6.c index 1e985e7db068..92a58db0d236 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -1401,6 +1401,7 @@ dir2_kill_block( args.trans = tp; args.whichfork = XFS_DATA_FORK; args.geo = mp->m_dir_geo; + args.owner = ip->i_ino; if (da_bno >= mp->m_dir_geo->leafblk && da_bno < mp->m_dir_geo->freeblk) error = -libxfs_da_shrink_inode(&args, da_bno, bp); else @@ -1505,6 +1506,7 @@ longform_dir2_entry_check_data( struct xfs_da_args da = { .dp = ip, .geo = mp->m_dir_geo, + .owner = ip->i_ino, }; @@ -2294,6 +2296,7 @@ longform_dir2_entry_check( /* is this a block, leaf, or node directory? */ args.dp = ip; args.geo = mp->m_dir_geo; + args.owner = ip->i_ino; fmt = libxfs_dir2_format(&args, &error); /* check directory "data" blocks (ie. name/inode pairs) */ From patchwork Tue Jul 2 00:57: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: 13718764 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 803DF6FC3 for ; Tue, 2 Jul 2024 00:57:08 +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=1719881828; cv=none; b=fwam//MCPaZn4kxgunpfHEFkdU9lOy4aj8HjI/IuuDiyfKiulYSKiOT1C84gZyQV4JiEYYzu2+mSgdSaJh8V/ZPnufQD9GcZ5XBq+PaorMZ1UaM4UNX1325NObiWIe1ek3Iu++BCerQ0nCK0AW1yrAbd6O7Ny/YSVj2GaU6yrj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719881828; c=relaxed/simple; bh=C4xplnEop356k8k4mzzu0yisNV+Pf+o7bA8bi6kLjEU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VzLi9Zw4fHUSK97HI2gAGKFgd53SE6hn9Ksro2KowoVlpmgS9R/3UFVifWT9eSI5vFkO14VfCeQczQqi5PHCmQORgCGTeDS+WD2cXYLMeSIQW+WCrnhZP5ZE3zld/HKIspqPKcmYvKE8+VPkicIVrF7jnkzrwEGg1hZcixlbyUo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jc+yKMxU; 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="Jc+yKMxU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EF3BC116B1; Tue, 2 Jul 2024 00:57:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719881828; bh=C4xplnEop356k8k4mzzu0yisNV+Pf+o7bA8bi6kLjEU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Jc+yKMxUp4SYcErt7wqwV4BKSFBiBJT7t0ZxWdL/SRa0KZ1E9eCW7Av2Zsdd5nSLE eKVM/7OQRYseTuve7XtThWIgsTnXLUe58zxOuA0ul1yHDPxZ5zya7ehYV+c77MD1Ty HbQhCKjEO04B28WIOilLzVETPkTfcjjcRD7JmTwl6Go9vEKxu6vJcGzbAyFXUQV9lI jZbZF7FZnsDYnPITpuZMLUSsY0RkfFhSifgaLaypCZ82bGyokpRVAtBFiFObZrPmTg MPheEy7WvaJBc1QVzg2CGTctAa3Pb3N5kaBS55Eau9Mf1hMWPUOoIFZmwiOz/gMzwR +f+tWJSriwytw== Date: Mon, 01 Jul 2024 17:57:07 -0700 Subject: [PATCH 2/3] libxfs: port the bumplink function from the kernel From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988117255.2006964.327302486814604596.stgit@frogsfrogsfrogs> In-Reply-To: <171988117219.2006964.1550137506522221205.stgit@frogsfrogsfrogs> References: <171988117219.2006964.1550137506522221205.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Port the xfs_bumplink function from the kernel and use it to replace raw calls to inc_nlink. The next patch will need this common function to prevent integer overflows in the link count. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- include/xfs_inode.h | 2 ++ libxfs/util.c | 17 +++++++++++++++++ mkfs/proto.c | 4 ++-- repair/phase6.c | 10 +++++----- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/include/xfs_inode.h b/include/xfs_inode.h index c6e4f84bdc16..45339b42621a 100644 --- a/include/xfs_inode.h +++ b/include/xfs_inode.h @@ -359,6 +359,8 @@ extern void libxfs_trans_ichgtime(struct xfs_trans *, struct xfs_inode *, int); extern int libxfs_iflush_int (struct xfs_inode *, struct xfs_buf *); +void libxfs_bumplink(struct xfs_trans *tp, struct xfs_inode *ip); + /* Inode Cache Interfaces */ extern int libxfs_iget(struct xfs_mount *, struct xfs_trans *, xfs_ino_t, uint, struct xfs_inode **); diff --git a/libxfs/util.c b/libxfs/util.c index 2656c99a8ea7..dc54e3ee66db 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -240,6 +240,23 @@ xfs_inode_propagate_flags( ip->i_diflags |= di_flags; } +/* + * Increment the link count on an inode & log the change. + */ +void +libxfs_bumplink( + struct xfs_trans *tp, + struct xfs_inode *ip) +{ + struct inode *inode = VFS_I(ip); + + xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG); + + inc_nlink(inode); + + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); +} + /* * Initialise a newly allocated inode and return the in-core inode to the * caller locked exclusively. diff --git a/mkfs/proto.c b/mkfs/proto.c index 5125ee44f493..a9a9b704a3ca 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -591,7 +591,7 @@ parseproto( &creds, fsxp, &ip); if (error) fail(_("Inode allocation failed"), error); - inc_nlink(VFS_I(ip)); /* account for . */ + libxfs_bumplink(tp, ip); /* account for . */ if (!pip) { pip = ip; mp->m_sb.sb_rootino = ip->i_ino; @@ -601,7 +601,7 @@ parseproto( libxfs_trans_ijoin(tp, pip, 0); xname.type = XFS_DIR3_FT_DIR; newdirent(mp, tp, pip, &xname, ip->i_ino); - inc_nlink(VFS_I(pip)); + libxfs_bumplink(tp, pip); libxfs_trans_log_inode(tp, pip, XFS_ILOG_CORE); } newdirectory(mp, tp, ip, pip); diff --git a/repair/phase6.c b/repair/phase6.c index 92a58db0d236..47dd9de2741c 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -947,7 +947,7 @@ mk_orphanage(xfs_mount_t *mp) do_error(_("%s inode allocation failed %d\n"), ORPHANAGE, error); } - inc_nlink(VFS_I(ip)); /* account for . */ + libxfs_bumplink(tp, ip); /* account for . */ ino = ip->i_ino; irec = find_inode_rec(mp, @@ -999,7 +999,7 @@ mk_orphanage(xfs_mount_t *mp) * for .. in the new directory, and update the irec copy of the * on-disk nlink so we don't fail the link count check later. */ - inc_nlink(VFS_I(pip)); + libxfs_bumplink(tp, pip); irec = find_inode_rec(mp, XFS_INO_TO_AGNO(mp, mp->m_sb.sb_rootino), XFS_INO_TO_AGINO(mp, mp->m_sb.sb_rootino)); add_inode_ref(irec, 0); @@ -1094,7 +1094,7 @@ mv_orphanage( if (irec) add_inode_ref(irec, ino_offset); else - inc_nlink(VFS_I(orphanage_ip)); + libxfs_bumplink(tp, orphanage_ip); libxfs_trans_log_inode(tp, orphanage_ip, XFS_ILOG_CORE); err = -libxfs_dir_createname(tp, ino_p, &xfs_name_dotdot, @@ -1103,7 +1103,7 @@ mv_orphanage( do_error( _("creation of .. entry failed (%d)\n"), err); - inc_nlink(VFS_I(ino_p)); + libxfs_bumplink(tp, ino_p); libxfs_trans_log_inode(tp, ino_p, XFS_ILOG_CORE); err = -libxfs_trans_commit(tp); if (err) @@ -1128,7 +1128,7 @@ mv_orphanage( if (irec) add_inode_ref(irec, ino_offset); else - inc_nlink(VFS_I(orphanage_ip)); + libxfs_bumplink(tp, orphanage_ip); libxfs_trans_log_inode(tp, orphanage_ip, XFS_ILOG_CORE); /* From patchwork Tue Jul 2 00:57:23 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: 13718765 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 5D2108479 for ; Tue, 2 Jul 2024 00:57:24 +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=1719881844; cv=none; b=PH2nqgTn8m7hLRVd3jHET0ry3afrWERYe1EmQXgeNANG082HFJReh1ZuhiE/yswUqACMxJumlGmDJqPyXRnhylWkO638l5OUHZrI77pC6xxdr5DNJxyDEWB1LTV4+kkEnTjNa+2AhrMk7Wh47Xmgjt2f9mC3bGprSor55JVNYWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719881844; c=relaxed/simple; bh=eAHHtJtidsdXzK6CgHAr8tiHlw8gS5EbEzlyeawA+iw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hQNl/Ulm3e/o1DJm65mNs7PjSwYTd2KYc1D8dj7G3Mu0eCi2v+6YTa22s4jsjbUxzsL7EQjoqzcrFkIucoM3pAOYpAXeV28c9xA09Ql8oO+ENA7Ovh6gptndzskyHGxNV3fk3FFWpSpSVAoa5EkfNSWnfPUev9nI0C0uIrr8PXU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LIXtG3rA; 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="LIXtG3rA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3DD7C116B1; Tue, 2 Jul 2024 00:57:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719881844; bh=eAHHtJtidsdXzK6CgHAr8tiHlw8gS5EbEzlyeawA+iw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=LIXtG3rA0T5FBMaJvZ8ChIB+tnBiO/2QeJ0w6WCGXyXASPptcIreQOGfOyKDecoz/ u1KyfEBV6tcjQS3oNrOR2fNYtfBedA6m/+EEfEeJbWHCmhMFOg8GqseGotdPRYhDA8 THlDxg3T4myPTysm7uRahdqKkUb97c5fehVdy1A08nXlaNbzGh7+ZIApo8QBP05Ull X6op10cboULn3eMq6b1OB9PrgqkVDiet4OsXl+g7f7/9yWWaA3Vs9itxvFqglkWFnr z4b3KOxYsQy+3gb76njeqt7Wm4Z6oX6FoiEFkEUzyc1WFLOOEVeUxdyQra+gqjY/KN 0dETGlYW4La+w== Date: Mon, 01 Jul 2024 17:57:23 -0700 Subject: [PATCH 3/3] mkfs/repair: pin inodes that would otherwise overflow link count From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988117270.2006964.11531106267384216498.stgit@frogsfrogsfrogs> In-Reply-To: <171988117219.2006964.1550137506522221205.stgit@frogsfrogsfrogs> References: <171988117219.2006964.1550137506522221205.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Update userspace utilities not to allow integer overflows of inode link counts to result in a file that is referenced by parent directories but has zero link count. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/util.c | 3 ++- repair/incore_ino.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libxfs/util.c b/libxfs/util.c index dc54e3ee66db..74eea0fcbe07 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -252,7 +252,8 @@ libxfs_bumplink( xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG); - inc_nlink(inode); + if (inode->i_nlink != XFS_NLINK_PINNED) + inc_nlink(inode); xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); } diff --git a/repair/incore_ino.c b/repair/incore_ino.c index 0dd7a2f060fb..b0b41a2cc5c5 100644 --- a/repair/incore_ino.c +++ b/repair/incore_ino.c @@ -108,7 +108,8 @@ void add_inode_ref(struct ino_tree_node *irec, int ino_offset) nlink_grow_16_to_32(irec); /*FALLTHRU*/ case sizeof(uint32_t): - irec->ino_un.ex_data->counted_nlinks.un32[ino_offset]++; + if (irec->ino_un.ex_data->counted_nlinks.un32[ino_offset] != XFS_NLINK_PINNED) + irec->ino_un.ex_data->counted_nlinks.un32[ino_offset]++; break; default: ASSERT(0);