diff options
author | Darrick J. Wong <darrick.wong@oracle.com> | 2020-10-25 17:15:58 -0700 |
---|---|---|
committer | Darrick J. Wong <darrick.wong@oracle.com> | 2020-10-26 18:32:28 -0700 |
commit | 9267eb67bf8aaec6c5241eeacf39bc59efc78261 (patch) | |
tree | 9477e7ad219f2b5fa4f372f56de5dfd25d946317 /fs | |
parent | 03a9e0c50d969e6026d5ecc90757eb6c7f05fef9 (diff) |
xfs: hoist inode free function to libxfs
Create a libxfs helper function that marks an inode free on disk.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/xfs/libxfs/xfs_inode_util.c | 55 | ||||
-rw-r--r-- | fs/xfs/libxfs/xfs_inode_util.h | 4 | ||||
-rw-r--r-- | fs/xfs/xfs_inode.c | 40 |
3 files changed, 60 insertions, 39 deletions
diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c index 11ce877ad978..8e7c6b9d9ec6 100644 --- a/fs/xfs/libxfs/xfs_inode_util.c +++ b/fs/xfs/libxfs/xfs_inode_util.c @@ -19,6 +19,7 @@ #include "xfs_health.h" #include "xfs_error.h" #include "xfs_trace.h" +#include "xfs_inode_item.h" uint16_t xfs_flags2diflags( @@ -933,3 +934,57 @@ xfs_bumplink( inc_nlink(VFS_I(ip)); xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); } + +/* Mark an inode free on disk. */ +int +xfs_dir_ifree( + struct xfs_trans *tp, + struct xfs_inode *ip, + struct xfs_icluster *xic) +{ + struct xfs_inode_log_item *iip = ip->i_itemp; + int error; + + /* + * Pull the on-disk inode from the AGI unlinked list. + */ + error = xfs_iunlink_remove(tp, ip); + if (error) + return error; + + error = xfs_difree(tp, ip->i_ino, xic); + if (error) + return error; + + /* + * Free any local-format data sitting around before we reset the + * data fork to extents format. Note that the attr fork data has + * already been freed by xfs_attr_inactive. + */ + if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL) { + kmem_free(ip->i_df.if_u1.if_data); + ip->i_df.if_u1.if_data = NULL; + ip->i_df.if_bytes = 0; + } + + VFS_I(ip)->i_mode = 0; /* mark incore inode as free */ + ip->i_d.di_flags = 0; + ip->i_d.di_flags2 = ip->i_mount->m_ino_geo.new_diflags2; + ip->i_d.di_dmevmask = 0; + ip->i_d.di_forkoff = 0; /* mark the attr fork not in use */ + ip->i_df.if_format = XFS_DINODE_FMT_EXTENTS; + + /* Don't attempt to replay owner changes for a deleted inode */ + spin_lock(&iip->ili_lock); + iip->ili_fields &= ~(XFS_ILOG_AOWNER | XFS_ILOG_DOWNER); + spin_unlock(&iip->ili_lock); + + /* + * Bump the generation count so no one will be confused + * by reincarnations of this inode. + */ + VFS_I(ip)->i_generation++; + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); + + return 0; +} diff --git a/fs/xfs/libxfs/xfs_inode_util.h b/fs/xfs/libxfs/xfs_inode_util.h index f140f849048a..e11583c50abd 100644 --- a/fs/xfs/libxfs/xfs_inode_util.h +++ b/fs/xfs/libxfs/xfs_inode_util.h @@ -6,6 +6,8 @@ #ifndef __XFS_INODE_UTIL_H__ #define __XFS_INODE_UTIL_H__ +struct xfs_icluster; + uint16_t xfs_flags2diflags(struct xfs_inode *ip, unsigned int xflags); uint64_t xfs_flags2diflags2(struct xfs_inode *ip, unsigned int xflags); uint32_t xfs_dic2xflags(uint16_t di_flags, uint64_t di_flags2, @@ -50,6 +52,8 @@ int xfs_iunlink(struct xfs_trans *tp, struct xfs_inode *ip); int xfs_iunlink_remove(struct xfs_trans *tp, struct xfs_inode *ip); int xfs_droplink(struct xfs_trans *tp, struct xfs_inode *ip); void xfs_bumplink(struct xfs_trans *tp, struct xfs_inode *ip); +int xfs_dir_ifree(struct xfs_trans *tp, struct xfs_inode *ip, + struct xfs_icluster *xic); /* The libxfs client must provide these iunlink helper functions. */ int xfs_iunlink_init(struct xfs_perag *pag); diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 5be3a52b94df..c946b51b040a 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2073,7 +2073,6 @@ xfs_ifree( { int error; struct xfs_icluster xic = { 0 }; - struct xfs_inode_log_item *iip = ip->i_itemp; ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); ASSERT(VFS_I(ip)->i_nlink == 0); @@ -2081,47 +2080,10 @@ xfs_ifree( ASSERT(ip->i_d.di_size == 0 || !S_ISREG(VFS_I(ip)->i_mode)); ASSERT(ip->i_d.di_nblocks == 0); - /* - * Pull the on-disk inode from the AGI unlinked list. - */ - error = xfs_iunlink_remove(tp, ip); + error = xfs_dir_ifree(tp, ip, &xic); if (error) return error; - error = xfs_difree(tp, ip->i_ino, &xic); - if (error) - return error; - - /* - * Free any local-format data sitting around before we reset the - * data fork to extents format. Note that the attr fork data has - * already been freed by xfs_attr_inactive. - */ - if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL) { - kmem_free(ip->i_df.if_u1.if_data); - ip->i_df.if_u1.if_data = NULL; - ip->i_df.if_bytes = 0; - } - - VFS_I(ip)->i_mode = 0; /* mark incore inode as free */ - ip->i_d.di_flags = 0; - ip->i_d.di_flags2 = ip->i_mount->m_ino_geo.new_diflags2; - ip->i_d.di_dmevmask = 0; - ip->i_d.di_forkoff = 0; /* mark the attr fork not in use */ - ip->i_df.if_format = XFS_DINODE_FMT_EXTENTS; - - /* Don't attempt to replay owner changes for a deleted inode */ - spin_lock(&iip->ili_lock); - iip->ili_fields &= ~(XFS_ILOG_AOWNER | XFS_ILOG_DOWNER); - spin_unlock(&iip->ili_lock); - - /* - * Bump the generation count so no one will be confused - * by reincarnations of this inode. - */ - VFS_I(ip)->i_generation++; - xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); - if (xic.deleted) error = xfs_ifree_cluster(ip, tp, &xic); |