]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: port the bumplink function from the kernel
authorDarrick J. Wong <djwong@kernel.org>
Mon, 29 Jul 2024 23:23:02 +0000 (16:23 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:06 +0000 (17:01 -0700)
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 <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
include/xfs_inode.h
libxfs/util.c
mkfs/proto.c
repair/phase6.c

index c6e4f84bdc16a92ac2e451aceb2b0143d2bcb56d..45339b42621a619b8ea061c27ccea93d1f0992f0 100644 (file)
@@ -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 **);
index 2656c99a8ea7200270e68495c9144257c563196d..dc54e3ee66dbaac8810dd987bb1368527f1b3b92 100644 (file)
@@ -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.
index 5125ee44f4936b5bb15fcb988e4b6949c7fb8b86..a9a9b704a3ca96e104eb48bb52bc9fb53dd73e70 100644 (file)
@@ -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);
index 92a58db0d236b51709f21a7b5d96c714bd2dacd9..47dd9de2741cff82d9adda4e6eed71887767b931 100644 (file)
@@ -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);
 
                        /*