diff mbox series

[4/4] xfs_repair: use library functions for orphanage creation

Message ID 172783103438.4038674.13322754481588384282.stgit@frogsfrogsfrogs (mailing list archive)
State Not Applicable, archived
Headers show
Series [1/4] xfs_repair: fix exchrange upgrade | expand

Commit Message

Darrick J. Wong Oct. 2, 2024, 1:26 a.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

Use new library functions to create lost+found.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 libxfs/libxfs_api_defs.h |    1 +
 repair/phase6.c          |   53 ++++++++++++++++++----------------------------
 2 files changed, 22 insertions(+), 32 deletions(-)

Comments

Christoph Hellwig Oct. 2, 2024, 5:58 a.m. UTC | #1
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h
index ee9794782..a4173e5f7 100644
--- a/libxfs/libxfs_api_defs.h
+++ b/libxfs/libxfs_api_defs.h
@@ -148,6 +148,7 @@ 
 #define xfs_dir2_shrink_inode		libxfs_dir2_shrink_inode
 
 #define xfs_dir_createname		libxfs_dir_createname
+#define xfs_dir_create_child		libxfs_dir_create_child
 #define xfs_dir_init			libxfs_dir_init
 #define xfs_dir_ino_validate		libxfs_dir_ino_validate
 #define xfs_dir_lookup			libxfs_dir_lookup
diff --git a/repair/phase6.c b/repair/phase6.c
index 2c4f23010..ba28edaa4 100644
--- a/repair/phase6.c
+++ b/repair/phase6.c
@@ -826,19 +826,23 @@  mk_orphanage(
 		.idmap		= libxfs_nop_idmap,
 		.mode		= S_IFDIR | 0755,
 	};
+	struct xfs_name		xname = {
+		.name		= (unsigned char *)ORPHANAGE,
+		.len		= strlen(ORPHANAGE),
+		.type		= XFS_DIR3_FT_DIR,
+	};
+	struct xfs_dir_update	du = {
+		.name		= &xname,
+	};
 	struct xfs_trans	*tp;
-	struct xfs_inode	*ip;
-	struct xfs_inode	*pip;
 	struct ino_tree_node	*irec;
 	xfs_ino_t		ino;
 	int			ino_offset = 0;
 	int			i;
 	int			error;
 	int			nres;
-	struct xfs_name		xname;
-	struct xfs_parent_args	*ppargs = NULL;
 
-	i = -libxfs_parent_start(mp, &ppargs);
+	i = -libxfs_parent_start(mp, &du.ppargs);
 	if (i)
 		do_error(_("%d - couldn't allocate parent pointer for %s\n"),
 			i, ORPHANAGE);
@@ -849,18 +853,15 @@  mk_orphanage(
 	 * would have been cleared in phase3 and phase4.
 	 */
 
-	i = -libxfs_iget(mp, NULL, mp->m_sb.sb_rootino, 0, &pip);
+	i = -libxfs_iget(mp, NULL, mp->m_sb.sb_rootino, 0, &du.dp);
 	if (i)
 		do_error(_("%d - couldn't iget root inode to obtain %s\n"),
 			i, ORPHANAGE);
 
-	args.pip = pip;
-	xname.name = (unsigned char *)ORPHANAGE;
-	xname.len = strlen(ORPHANAGE);
-	xname.type = XFS_DIR3_FT_DIR;
+	args.pip = du.dp;
 
 	/* If the lookup of /lost+found succeeds, return the inumber. */
-	error = -libxfs_dir_lookup(NULL, pip, &xname, &ino, NULL);
+	error = -libxfs_dir_lookup(NULL, du.dp, &xname, &ino, NULL);
 	if (error == 0)
 		goto out_pip;
 
@@ -877,7 +878,7 @@  mk_orphanage(
 		do_error(_("%s inode allocation failed %d\n"),
 			ORPHANAGE, error);
 
-	error = -libxfs_icreate(tp, ino, &args, &ip);
+	error = -libxfs_icreate(tp, ino, &args, &du.ip);
 	if (error)
 		do_error(_("%s inode initialization failed %d\n"),
 			ORPHANAGE, error);
@@ -915,49 +916,37 @@  mk_orphanage(
 	 * now that we know the transaction will stay around,
 	 * add the root inode to it
 	 */
-	libxfs_trans_ijoin(tp, pip, 0);
+	libxfs_trans_ijoin(tp, du.dp, 0);
 
 	/*
 	 * create the actual entry
 	 */
-	error = -libxfs_dir_createname(tp, pip, &xname, ip->i_ino, nres);
+	error = -libxfs_dir_create_child(tp, nres, &du);
 	if (error)
 		do_error(
 		_("can't make %s, createname error %d\n"),
 			ORPHANAGE, error);
-	add_parent_ptr(ip->i_ino, (unsigned char *)ORPHANAGE, pip, false);
-
-	if (ppargs) {
-		error = -libxfs_parent_addname(tp, ppargs, pip, &xname, ip);
-		if (error)
-			do_error(
- _("can't make %s, parent addname error %d\n"),
-					ORPHANAGE, error);
-	}
+	add_parent_ptr(du.ip->i_ino, (unsigned char *)ORPHANAGE, du.dp, false);
 
 	/*
-	 * bump up the link count in the root directory to account
-	 * for .. in the new directory, and update the irec copy of the
+	 * We bumped up the link count in the root directory to account
+	 * for .. in the new directory, so now update the irec copy of the
 	 * on-disk nlink so we don't fail the link count check later.
 	 */
-	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);
 	set_inode_disk_nlinks(irec, 0, get_inode_disk_nlinks(irec, 0) + 1);
 
-	libxfs_trans_log_inode(tp, pip, XFS_ILOG_CORE);
-	libxfs_dir_init(tp, ip, pip);
-	libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
 	error = -libxfs_trans_commit(tp);
 	if (error) {
 		do_error(_("%s directory creation failed -- bmapf error %d\n"),
 			ORPHANAGE, error);
 	}
-	libxfs_irele(ip);
+	libxfs_irele(du.ip);
 out_pip:
-	libxfs_irele(pip);
-	libxfs_parent_finish(mp, ppargs);
+	libxfs_irele(du.dp);
+	libxfs_parent_finish(mp, du.ppargs);
 
 	return(ino);
 }