diff mbox series

[22/22] xfs: create library function to reset root inodes

Message ID 154630929346.18437.14185691799928569579.stgit@magnolia (mailing list archive)
State New, archived
Headers show
Series xfs: hoist inode operations to libxfs | expand

Commit Message

Darrick J. Wong Jan. 1, 2019, 2:21 a.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Create a library function to reset a root inode, which xfs_repair will
take advantage of in xfsprogs.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/libxfs/xfs_inode_util.c |   24 ++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_inode_util.h |    1 +
 2 files changed, 25 insertions(+)

Comments

Christoph Hellwig Jan. 17, 2019, 2:25 p.m. UTC | #1
On Mon, Dec 31, 2018 at 06:21:33PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Create a library function to reset a root inode, which xfs_repair will
> take advantage of in xfsprogs.

And which will just add dead code to the kernel?
Darrick J. Wong Jan. 17, 2019, 11:29 p.m. UTC | #2
On Thu, Jan 17, 2019 at 06:25:25AM -0800, Christoph Hellwig wrote:
> On Mon, Dec 31, 2018 at 06:21:33PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Create a library function to reset a root inode, which xfs_repair will
> > take advantage of in xfsprogs.
> 
> And which will just add dead code to the kernel?

Fair enough, it can live in xfs_repair.

--D
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c
index 01a320747ddf..00cda9046c8e 100644
--- a/fs/xfs/libxfs/xfs_inode_util.c
+++ b/fs/xfs/libxfs/xfs_inode_util.c
@@ -416,6 +416,30 @@  xfs_ialloc(
 	return 0;
 }
 
+/*
+ * Forcibly reinitialize a fixed-location inode, such as a filesystem root
+ * directory or the realtime metadata inodes.  The inode must not otherwise be
+ * in use, and the inode's forks must already be empty.
+ */
+int
+xfs_fixed_inode_reset(
+	struct xfs_trans		*tp,
+	umode_t				mode,
+	struct xfs_inode		*ip)
+{
+	struct xfs_ialloc_args	args = {
+		.ops			= &xfs_default_ialloc_ops,
+		.nlink			= S_ISDIR(mode) ? 2 : 1,
+		.mode			= mode,
+	};
+	struct xfs_mount		*mp = tp->t_mountp;
+
+	ip->i_d.di_version = xfs_sb_version_hascrc(&mp->m_sb) ? 3 : 2;
+
+	xfs_inode_init(tp, &args, ip);
+	return 0;
+}
+
 /*
  * Allocates a new inode from disk and return a pointer to the
  * incore copy. This routine will internally commit the current
diff --git a/fs/xfs/libxfs/xfs_inode_util.h b/fs/xfs/libxfs/xfs_inode_util.h
index 4918379b682e..5a6f1a348a47 100644
--- a/fs/xfs/libxfs/xfs_inode_util.h
+++ b/fs/xfs/libxfs/xfs_inode_util.h
@@ -97,6 +97,7 @@  extern const struct xfs_ialloc_ops xfs_default_ialloc_ops;
 
 int xfs_dir_ialloc(struct xfs_trans **tpp, const struct xfs_ialloc_args *args,
 		   struct xfs_inode **ipp);
+int xfs_fixed_inode_reset(struct xfs_trans *tp, umode_t mode, struct xfs_inode *ip);
 
 int xfs_iunlink(struct xfs_trans *tp, struct xfs_inode *ip);
 int xfs_iunlink_remove(struct xfs_trans *tp, struct xfs_inode *ip);