]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
libxfs: remove libxfs_dir_ialloc
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Jul 2024 21:21:34 +0000 (14:21 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 31 Jul 2024 01:46:42 +0000 (18:46 -0700)
This function no longer exists in the kernel, and it's not really needed
in userspace either.  There are two users of it: repair and mkfs.
xfs_repair and xfs_db do not have useful cred and fsxattr structures so
they can call libxfs_dialloc and libxfs_icreate directly.  For mkfs
we'll move the guts of libxfs_dir_ialloc into proto.c as a creatproto
function that handles setting user/group ids, and move struct cred to
mkfs since it's now the only user.

This gets us ready to hoist the rest of the inode initialization code to
libxfs for metadata directories.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
db/iunlink.c
include/xfs_inode.h
libxfs/inode.c
libxfs/libxfs_api_defs.h
mkfs/proto.c
repair/phase6.c

index 256c85560192b3fd7ce02d944bb43ccd45f7f8ef..47e14ed24d744dd5323d7704c19a571c3ce88a42 100644 (file)
@@ -309,10 +309,14 @@ static int
 create_unlinked(
        struct xfs_mount        *mp)
 {
-       struct cred             cr = { };
-       struct fsxattr          fsx = { };
+       struct xfs_icreate_args args = {
+               .idmap          = libxfs_nop_idmap,
+               .mode           = S_IFREG | 0600,
+               .flags          = XFS_ICREATE_TMPFILE,
+       };
        struct xfs_inode        *ip;
        struct xfs_trans        *tp;
+       xfs_ino_t               ino;
        unsigned int            resblks;
        int                     error;
 
@@ -324,8 +328,13 @@ create_unlinked(
                return error;
        }
 
-       error = -libxfs_dir_ialloc(&tp, NULL, S_IFREG | 0600, 0, 0, &cr, &fsx,
-                       &ip);
+       error = -libxfs_dialloc(&tp, 0, args.mode, &ino);
+       if (error) {
+               dbprintf(_("alloc inode: %s\n"), strerror(error));
+               goto out_cancel;
+       }
+
+       error = -libxfs_icreate(tp, ino, &args, &ip);
        if (error) {
                dbprintf(_("create inode: %s\n"), strerror(error));
                goto out_cancel;
index b661fc0c808b7e06a7a40808d5c2b7ca1d05e483..24a91147481d30fcdcaf23d39c5463891f6e53eb 100644 (file)
@@ -399,17 +399,6 @@ static inline bool xfs_is_always_cow_inode(struct xfs_inode *ip)
        return false;
 }
 
-/* Always set the child's GID to this value, even if the parent is setgid. */
-#define CRED_FORCE_GID (1U << 0)
-struct cred {
-       uid_t           cr_uid;
-       gid_t           cr_gid;
-       unsigned int    cr_flags;
-};
-
-extern int     libxfs_dir_ialloc (struct xfs_trans **, struct xfs_inode *,
-                               mode_t, nlink_t, xfs_dev_t, struct cred *,
-                               struct fsxattr *, struct xfs_inode **);
 extern void    libxfs_trans_inode_alloc_buf (struct xfs_trans *,
                                struct xfs_buf *);
 
@@ -419,6 +408,9 @@ extern int  libxfs_iflush_int (struct xfs_inode *, struct xfs_buf *);
 
 void libxfs_bumplink(struct xfs_trans *tp, struct xfs_inode *ip);
 
+int libxfs_icreate(struct xfs_trans *tp, xfs_ino_t ino,
+               const struct xfs_icreate_args *args, struct xfs_inode **ipp);
+
 /* Inode Cache Interfaces */
 extern int     libxfs_iget(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
                                uint, struct xfs_inode **);
index 56cc896902815d0bc3f8c6c0671312bc7c2850af..680885c633887f4cd7c053d6a71e16d3a2d6d853 100644 (file)
@@ -213,7 +213,7 @@ xfs_inode_init(
  * Initialise a newly allocated inode and return the in-core inode to the
  * caller locked exclusively.
  */
-static int
+int
 libxfs_icreate(
        struct xfs_trans        *tp,
        xfs_ino_t               ino,
@@ -303,81 +303,6 @@ libxfs_iflush_int(
        return 0;
 }
 
-/*
- * Wrapper around call to libxfs_ialloc. Takes care of committing and
- * allocating a new transaction as needed.
- *
- * Originally there were two copies of this code - one in mkfs, the
- * other in repair - now there is just the one.
- */
-int
-libxfs_dir_ialloc(
-       struct xfs_trans        **tpp,
-       struct xfs_inode        *dp,
-       mode_t                  mode,
-       nlink_t                 nlink,
-       xfs_dev_t               rdev,
-       struct cred             *cr,
-       struct fsxattr          *fsx,
-       struct xfs_inode        **ipp)
-{
-       struct xfs_icreate_args args = {
-               .pip            = dp,
-               .mode           = mode,
-       };
-       struct xfs_inode        *ip;
-       struct inode            *inode;
-       xfs_ino_t               parent_ino = dp ? dp->i_ino : 0;
-       xfs_ino_t               ino;
-       int                     error;
-
-       if (dp && xfs_has_parent(dp->i_mount))
-               args.flags |= XFS_ICREATE_INIT_XATTRS;
-
-       /* Only devices get rdev numbers */
-       switch (mode & S_IFMT) {
-       case S_IFCHR:
-       case S_IFBLK:
-               args.rdev = rdev;
-               break;
-       }
-
-       /*
-        * Call the space management code to pick the on-disk inode to be
-        * allocated.
-        */
-       error = xfs_dialloc(tpp, parent_ino, mode, &ino);
-       if (error)
-               return error;
-
-       error = libxfs_icreate(*tpp, ino, &args, &ip);
-       if (error)
-               return error;
-
-       inode = VFS_I(ip);
-       i_uid_write(inode, cr->cr_uid);
-       if (cr->cr_flags & CRED_FORCE_GID)
-               i_gid_write(inode, cr->cr_gid);
-       set_nlink(inode, nlink);
-
-       /* If there is no parent dir, initialize the file from fsxattr data. */
-       if (dp == NULL) {
-               ip->i_projid = fsx->fsx_projid;
-               ip->i_extsize = fsx->fsx_extsize;
-               ip->i_diflags = xfs_flags2diflags(ip, fsx->fsx_xflags);
-
-               if (xfs_has_v3inodes(ip->i_mount)) {
-                       ip->i_diflags2 = xfs_flags2diflags2(ip,
-                                                       fsx->fsx_xflags);
-                       ip->i_cowextsize = fsx->fsx_cowextsize;
-               }
-       }
-
-       xfs_trans_log_inode(*tpp, ip, XFS_ILOG_CORE);
-       *ipp = ip;
-       return 0;
-}
-
 /*
  * Inode cache stubs.
  */
index 87f2ccf93fe21cb09706abc6e3f688890a30f8c5..384e812f21283c98b560275b9e900acedb19333c 100644 (file)
 #define xfs_da_shrink_inode            libxfs_da_shrink_inode
 #define xfs_defer_cancel               libxfs_defer_cancel
 #define xfs_defer_finish               libxfs_defer_finish
+#define xfs_dialloc                    libxfs_dialloc
 #define xfs_dinode_calc_crc            libxfs_dinode_calc_crc
 #define xfs_dinode_good_version                libxfs_dinode_good_version
 #define xfs_dinode_verify              libxfs_dinode_verify
index 8e16eb1506f1efffc035d49d0ccd4dcca8fa9242..58edc59f7152cdff00a0959991dfd72a877e9dd2 100644 (file)
@@ -405,6 +405,70 @@ newpptr(
        return ret;
 }
 
+struct cred {
+       uid_t                   cr_uid;
+       gid_t                   cr_gid;
+};
+
+static int
+creatproto(
+       struct xfs_trans        **tpp,
+       struct xfs_inode        *dp,
+       mode_t                  mode,
+       xfs_dev_t               rdev,
+       struct cred             *cr,
+       struct fsxattr          *fsx,
+       struct xfs_inode        **ipp)
+{
+       struct xfs_icreate_args args = {
+               .idmap          = libxfs_nop_idmap,
+               .pip            = dp,
+               .rdev           = rdev,
+               .mode           = mode,
+       };
+       struct xfs_inode        *ip;
+       struct inode            *inode;
+       xfs_ino_t               parent_ino = dp ? dp->i_ino : 0;
+       xfs_ino_t               ino;
+       int                     error;
+
+       if (dp && xfs_has_parent(dp->i_mount))
+               args.flags |= XFS_ICREATE_INIT_XATTRS;
+
+       /*
+        * Call the space management code to pick the on-disk inode to be
+        * allocated.
+        */
+       error = -libxfs_dialloc(tpp, parent_ino, mode, &ino);
+       if (error)
+               return error;
+
+       error = -libxfs_icreate(*tpp, ino, &args, &ip);
+       if (error)
+               return error;
+
+       inode = VFS_I(ip);
+       i_uid_write(inode, cr->cr_uid);
+       i_gid_write(inode, cr->cr_gid);
+
+       /* If there is no parent dir, initialize the file from fsxattr data. */
+       if (dp == NULL) {
+               ip->i_projid = fsx->fsx_projid;
+               ip->i_extsize = fsx->fsx_extsize;
+               ip->i_diflags = xfs_flags2diflags(ip, fsx->fsx_xflags);
+
+               if (xfs_has_v3inodes(ip->i_mount)) {
+                       ip->i_diflags2 = xfs_flags2diflags2(ip,
+                                                       fsx->fsx_xflags);
+                       ip->i_cowextsize = fsx->fsx_cowextsize;
+               }
+       }
+
+       libxfs_trans_log_inode(*tpp, ip, XFS_ILOG_CORE);
+       *ipp = ip;
+       return 0;
+}
+
 static void
 parseproto(
        xfs_mount_t     *mp,
@@ -505,7 +569,6 @@ parseproto(
        mode |= val;
        creds.cr_uid = (int)getnum(getstr(pp), 0, 0, false);
        creds.cr_gid = (int)getnum(getstr(pp), 0, 0, false);
-       creds.cr_flags = CRED_FORCE_GID;
        xname.name = (unsigned char *)name;
        xname.len = name ? strlen(name) : 0;
        xname.type = 0;
@@ -515,8 +578,8 @@ parseproto(
                buf = newregfile(pp, &len);
                tp = getres(mp, XFS_B_TO_FSB(mp, len));
                ppargs = newpptr(mp);
-               error = -libxfs_dir_ialloc(&tp, pip, mode|S_IFREG, 1, 0,
-                                          &creds, fsxp, &ip);
+               error = creatproto(&tp, pip, mode | S_IFREG, 0, &creds, fsxp,
+                               &ip);
                if (error)
                        fail(_("Inode allocation failed"), error);
                writefile(tp, ip, buf, len);
@@ -539,8 +602,8 @@ parseproto(
                }
                tp = getres(mp, XFS_B_TO_FSB(mp, llen));
                ppargs = newpptr(mp);
-               error = -libxfs_dir_ialloc(&tp, pip, mode|S_IFREG, 1, 0,
-                                         &creds, fsxp, &ip);
+               error = creatproto(&tp, pip, mode | S_IFREG, 0, &creds, fsxp,
+                               &ip);
                if (error)
                        fail(_("Inode pre-allocation failed"), error);
 
@@ -562,7 +625,7 @@ parseproto(
                ppargs = newpptr(mp);
                majdev = getnum(getstr(pp), 0, 0, false);
                mindev = getnum(getstr(pp), 0, 0, false);
-               error = -libxfs_dir_ialloc(&tp, pip, mode|S_IFBLK, 1,
+               error = creatproto(&tp, pip, mode | S_IFBLK,
                                IRIX_MKDEV(majdev, mindev), &creds, fsxp, &ip);
                if (error) {
                        fail(_("Inode allocation failed"), error);
@@ -578,7 +641,7 @@ parseproto(
                ppargs = newpptr(mp);
                majdev = getnum(getstr(pp), 0, 0, false);
                mindev = getnum(getstr(pp), 0, 0, false);
-               error = -libxfs_dir_ialloc(&tp, pip, mode|S_IFCHR, 1,
+               error = creatproto(&tp, pip, mode | S_IFCHR,
                                IRIX_MKDEV(majdev, mindev), &creds, fsxp, &ip);
                if (error)
                        fail(_("Inode allocation failed"), error);
@@ -591,8 +654,8 @@ parseproto(
        case IF_FIFO:
                tp = getres(mp, 0);
                ppargs = newpptr(mp);
-               error = -libxfs_dir_ialloc(&tp, pip, mode|S_IFIFO, 1, 0,
-                               &creds, fsxp, &ip);
+               error = creatproto(&tp, pip, mode | S_IFIFO, 0, &creds, fsxp,
+                               &ip);
                if (error)
                        fail(_("Inode allocation failed"), error);
                libxfs_trans_ijoin(tp, pip, 0);
@@ -604,8 +667,8 @@ parseproto(
                len = (int)strlen(buf);
                tp = getres(mp, XFS_B_TO_FSB(mp, len));
                ppargs = newpptr(mp);
-               error = -libxfs_dir_ialloc(&tp, pip, mode|S_IFLNK, 1, 0,
-                               &creds, fsxp, &ip);
+               error = creatproto(&tp, pip, mode | S_IFLNK, 0, &creds, fsxp,
+                               &ip);
                if (error)
                        fail(_("Inode allocation failed"), error);
                writesymlink(tp, ip, buf, len);
@@ -615,11 +678,10 @@ parseproto(
                break;
        case IF_DIRECTORY:
                tp = getres(mp, 0);
-               error = -libxfs_dir_ialloc(&tp, pip, mode|S_IFDIR, 1, 0,
-                               &creds, fsxp, &ip);
+               error = creatproto(&tp, pip, mode | S_IFDIR, 0, &creds, fsxp,
+                               &ip);
                if (error)
                        fail(_("Inode allocation failed"), error);
-               libxfs_bumplink(tp, ip);                /* account for . */
                if (!pip) {
                        pip = ip;
                        mp->m_sb.sb_rootino = ip->i_ino;
@@ -714,14 +776,13 @@ rtinit(
 
        memset(&creds, 0, sizeof(creds));
        memset(&fsxattrs, 0, sizeof(fsxattrs));
-       error = -libxfs_dir_ialloc(&tp, NULL, S_IFREG, 1, 0,
-                                       &creds, &fsxattrs, &rbmip);
+       error = creatproto(&tp, NULL, S_IFREG, 0, &creds, &fsxattrs, &rbmip);
        if (error) {
                fail(_("Realtime bitmap inode allocation failed"), error);
        }
        /*
         * Do our thing with rbmip before allocating rsumip,
-        * because the next call to ialloc() may
+        * because the next call to createproto may
         * commit the transaction in which rbmip was allocated.
         */
        mp->m_sb.sb_rbmino = rbmip->i_ino;
@@ -731,8 +792,7 @@ rtinit(
        libxfs_trans_log_inode(tp, rbmip, XFS_ILOG_CORE);
        libxfs_log_sb(tp);
        mp->m_rbmip = rbmip;
-       error = -libxfs_dir_ialloc(&tp, NULL, S_IFREG, 1, 0,
-                                       &creds, &fsxattrs, &rsumip);
+       error = creatproto(&tp, NULL, S_IFREG, 0, &creds, &fsxattrs, &rsumip);
        if (error) {
                fail(_("Realtime summary inode allocation failed"), error);
        }
index ad067ba0ac875c873fe53269abd6ab036b6024f8..7a569428446ca40549d11b587e6f22a68e514855 100644 (file)
@@ -20,8 +20,6 @@
 #include "versions.h"
 #include "repair/pptr.h"
 
-static struct cred             zerocr;
-static struct fsxattr          zerofsx;
 static xfs_ino_t               orphanage_ino;
 
 /*
@@ -891,20 +889,27 @@ mk_root_dir(xfs_mount_t *mp)
  * 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_parent_args *ppargs = NULL;
+       struct xfs_icreate_args args = {
+               .idmap          = libxfs_nop_idmap,
+               .mode           = S_IFDIR | 0755,
+       };
+       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;
+
+       if (xfs_has_parent(mp))
+               args.flags |= XFS_ICREATE_INIT_XATTRS;
 
        i = -libxfs_parent_start(mp, &ppargs);
        if (i)
@@ -922,6 +927,7 @@ mk_orphanage(xfs_mount_t *mp)
                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;
@@ -939,23 +945,15 @@ mk_orphanage(xfs_mount_t *mp)
        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);
-       if (i)
-               do_error(_("%d - couldn't iget root inode to make %s\n"),
-                       i, ORPHANAGE);*/
-
-       error = -libxfs_dir_ialloc(&tp, pip, mode|S_IFDIR,
-                                       1, 0, &zerocr, &zerofsx, &ip);
-       if (error) {
+       error = -libxfs_dialloc(&tp, mp->m_sb.sb_rootino, args.mode, &ino);
+       if (error)
                do_error(_("%s inode allocation failed %d\n"),
                        ORPHANAGE, error);
-       }
-       libxfs_bumplink(tp, ip);                /* account for . */
-       ino = ip->i_ino;
+
+       error = -libxfs_icreate(tp, ino, &args, &ip);
+       if (error)
+               do_error(_("%s inode initialization failed %d\n"),
+                       ORPHANAGE, error);
 
        irec = find_inode_rec(mp,
                        XFS_INO_TO_AGNO(mp, ino),
@@ -3344,8 +3342,6 @@ phase6(xfs_mount_t *mp)
 
        parent_ptr_init(mp);
 
-       memset(&zerocr, 0, sizeof(struct cred));
-       memset(&zerofsx, 0, sizeof(struct fsxattr));
        orphanage_ino = 0;
 
        do_log(_("Phase 6 - check inode connectivity...\n"));