]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_repair: use library functions for orphanage creation
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Jul 2024 21:21:37 +0000 (14:21 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 31 Jul 2024 01:46:43 +0000 (18:46 -0700)
Use new library functions to create lost+found.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libxfs/libxfs_api_defs.h
repair/phase6.c

index 1a5fdaa59edd0b0c60ed96028167da58bb3d060b..48fed384a527422210a00cb40c166a2dc754198e 100644 (file)
 #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
index 2c4f230105c0f26db5baf3750458b232c2ce0fe4..ba28edaa41c24cbd128dcbc560defb6945320665 100644 (file)
@@ -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);
 }