xfs_repair: use library functions for orphanage creation
Use new library functions to create lost+found.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h
index 91f73ca..3137eab 100644
--- a/libxfs/libxfs_api_defs.h
+++ b/libxfs/libxfs_api_defs.h
@@ -113,6 +113,8 @@
#define xfs_dir2_shrink_inode libxfs_dir2_shrink_inode
#define xfs_dir_createname libxfs_dir_createname
+#define xfs_dir_create_new_child libxfs_dir_create_new_child
+#define xfs_dir_ialloc libxfs_dir_ialloc
#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 6391a39..e928722 100644
--- a/repair/phase6.c
+++ b/repair/phase6.c
@@ -867,19 +867,23 @@
* orphanage name == lost+found
*/
static xfs_ino_t
-mk_orphanage(xfs_mount_t *mp)
+mk_orphanage(
+ struct xfs_mount *mp)
{
- xfs_ino_t ino;
- xfs_trans_t *tp;
- xfs_inode_t *ip;
- xfs_inode_t *pip;
- ino_tree_node_t *irec;
- int ino_offset = 0;
- int i;
- int error;
- const int mode = 0755;
- int nres;
- struct xfs_name xname;
+ struct xfs_ialloc_args args = {
+ .nlink = 2,
+ .mode = 0755 | S_IFDIR,
+ };
+ struct xfs_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;
/*
* check for an existing lost+found first, if it exists, return
@@ -893,6 +897,7 @@
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;
@@ -908,23 +913,11 @@
if (i)
res_failed(i);
- /*
- * use iget/ijoin instead of trans_iget because the ialloc
- * wrapper can commit the transaction and start a new one
- */
-/* i = -libxfs_iget(mp, NULL, mp->m_sb.sb_rootino, 0, &pip,
- &xfs_default_ifork_ops);
- if (i)
- do_error(_("%d - couldn't iget root inode to make %s\n"),
- i, ORPHANAGE);*/
-
- error = -libxfs_inode_alloc(&tp, pip, mode|S_IFDIR,
- 1, 0, &zerocr, &zerofsx, &ip);
+ error = -libxfs_dir_ialloc(&tp, &args, &ip);
if (error) {
do_error(_("%s inode allocation failed %d\n"),
ORPHANAGE, error);
}
- inc_nlink(VFS_I(ip)); /* account for . */
ino = ip->i_ino;
irec = find_inode_rec(mp,
@@ -965,26 +958,22 @@
/*
* create the actual entry
*/
- error = -libxfs_dir_createname(tp, pip, &xname, ip->i_ino, nres);
+ error = -libxfs_dir_create_new_child(tp, nres, pip, &xname, ip);
if (error)
do_error(
_("can't make %s, createname error %d\n"),
ORPHANAGE, error);
/*
- * 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.
*/
- inc_nlink(VFS_I(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"),