[PATCH 02/41] libxfs: load metadata directory root at mount time

Darrick J. Wong
2024-12-06T23:40:10Z

From: Darrick J. Wong <djwong@kernel.org>

Load the metadata directory root inode into memory at mount time and
release it at unmount time.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
include/xfs_mount.h | 1 +
libxfs/init.c | 26 ++++++++++++++++++++++++++
2 files changed, 27 insertions(+)

diff --git a/include/xfs_mount.h b/include/xfs_mount.h
index c7fada9e2a6d70..6daf3f01ffa9cf 100644
--- a/include/xfs_mount.h
+++ b/include/xfs_mount.h
@@ -91,6 +91,7 @@ typedef struct xfs_mount {
uint8_t *m_rsum_cache;
struct xfs_inode *m_rbmip; /* pointer to bitmap inode */
struct xfs_inode *m_rsumip; /* pointer to summary inode */
+ struct xfs_inode *m_metadirip; /* ptr to metadata directory */
struct xfs_buftarg *m_ddev_targp;
struct xfs_buftarg *m_logdev_targp;
struct xfs_buftarg *m_rtdev_targp;
diff --git a/libxfs/init.c b/libxfs/init.c
index beb58706629d23..bf488c5d8533b1 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -619,6 +619,27 @@ libxfs_compute_all_maxlevels(

}

+/* Mount the metadata files under the metadata directory tree. */
+STATIC void
+libxfs_mount_setup_metadir(
+ struct xfs_mount *mp)
+{
+ int error;
+
+ /* Ignore filesystems that are under construction. */
+ if (mp->m_sb.sb_inprogress)
+ return;
+
+ error = -libxfs_metafile_iget(mp, mp->m_sb.sb_metadirino,
+ XFS_METAFILE_DIR, &mp->m_metadirip);
+ if (error) {
+ fprintf(stderr,
+ _("%s: Failed to load metadir root directory, error %d\n"),
+ progname, error);
+ return;
+ }
+}
+
/*
* precalculate the low space thresholds for dynamic speculative preallocation.
*/
@@ -800,6 +821,9 @@ libxfs_mount(
}
xfs_set_perag_data_loaded(mp);

+ if (xfs_has_metadir(mp))
+ libxfs_mount_setup_metadir(mp);
+
return mp;
out_da:
xfs_da_unmount(mp);
@@ -918,6 +942,8 @@ libxfs_umount(
int error;

libxfs_rtmount_destroy(mp);
+ if (mp->m_metadirip)
+ libxfs_irele(mp->m_metadirip);

/*
* Purge the buffer cache to write all dirty buffers to disk and free