xfs: define locking primitives for realtime groups
authorDarrick J. Wong <djwong@kernel.org>
Mon, 4 Nov 2024 04:19:05 +0000 (20:19 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 5 Nov 2024 21:38:35 +0000 (13:38 -0800)
Define helper functions to lock all metadata inodes related to a
realtime group.  There's not much to look at now, but this will become
important when we add per-rtgroup metadata files and online fsck code
for them.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/libxfs/xfs_rtgroup.c
fs/xfs/libxfs/xfs_rtgroup.h

index 9d3842e..e3f167c 100644 (file)
@@ -149,3 +149,52 @@ xfs_update_last_rtgroup_size(
        xfs_rtgroup_rele(rtg);
        return 0;
 }
+
+/* Lock metadata inodes associated with this rt group. */
+void
+xfs_rtgroup_lock(
+       struct xfs_rtgroup      *rtg,
+       unsigned int            rtglock_flags)
+{
+       ASSERT(!(rtglock_flags & ~XFS_RTGLOCK_ALL_FLAGS));
+       ASSERT(!(rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED) ||
+              !(rtglock_flags & XFS_RTGLOCK_BITMAP));
+
+       if (rtglock_flags & XFS_RTGLOCK_BITMAP)
+               xfs_rtbitmap_lock(rtg_mount(rtg));
+       else if (rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED)
+               xfs_rtbitmap_lock_shared(rtg_mount(rtg), XFS_RBMLOCK_BITMAP);
+}
+
+/* Unlock metadata inodes associated with this rt group. */
+void
+xfs_rtgroup_unlock(
+       struct xfs_rtgroup      *rtg,
+       unsigned int            rtglock_flags)
+{
+       ASSERT(!(rtglock_flags & ~XFS_RTGLOCK_ALL_FLAGS));
+       ASSERT(!(rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED) ||
+              !(rtglock_flags & XFS_RTGLOCK_BITMAP));
+
+       if (rtglock_flags & XFS_RTGLOCK_BITMAP)
+               xfs_rtbitmap_unlock(rtg_mount(rtg));
+       else if (rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED)
+               xfs_rtbitmap_unlock_shared(rtg_mount(rtg), XFS_RBMLOCK_BITMAP);
+}
+
+/*
+ * Join realtime group metadata inodes to the transaction.  The ILOCKs will be
+ * released on transaction commit.
+ */
+void
+xfs_rtgroup_trans_join(
+       struct xfs_trans        *tp,
+       struct xfs_rtgroup      *rtg,
+       unsigned int            rtglock_flags)
+{
+       ASSERT(!(rtglock_flags & ~XFS_RTGLOCK_ALL_FLAGS));
+       ASSERT(!(rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED));
+
+       if (rtglock_flags & XFS_RTGLOCK_BITMAP)
+               xfs_rtbitmap_trans_join(tp);
+}
index 8872c27..7d82eb7 100644 (file)
@@ -197,6 +197,19 @@ xfs_rtxnum_t xfs_rtgroup_extents(struct xfs_mount *mp, xfs_rgnumber_t rgno);
 
 int xfs_update_last_rtgroup_size(struct xfs_mount *mp,
                xfs_rgnumber_t prev_rgcount);
+
+/* Lock the rt bitmap inode in exclusive mode */
+#define XFS_RTGLOCK_BITMAP             (1U << 0)
+/* Lock the rt bitmap inode in shared mode */
+#define XFS_RTGLOCK_BITMAP_SHARED      (1U << 1)
+
+#define XFS_RTGLOCK_ALL_FLAGS  (XFS_RTGLOCK_BITMAP | \
+                                XFS_RTGLOCK_BITMAP_SHARED)
+
+void xfs_rtgroup_lock(struct xfs_rtgroup *rtg, unsigned int rtglock_flags);
+void xfs_rtgroup_unlock(struct xfs_rtgroup *rtg, unsigned int rtglock_flags);
+void xfs_rtgroup_trans_join(struct xfs_trans *tp, struct xfs_rtgroup *rtg,
+               unsigned int rtglock_flags);
 #else
 static inline void xfs_free_rtgroups(struct xfs_mount *mp,
                xfs_rgnumber_t first_rgno, xfs_rgnumber_t end_rgno)
@@ -212,6 +225,9 @@ static inline int xfs_initialize_rtgroups(struct xfs_mount *mp,
 
 # define xfs_rtgroup_extents(mp, rgno)         (0)
 # define xfs_update_last_rtgroup_size(mp, rgno)        (-EOPNOTSUPP)
+# define xfs_rtgroup_lock(rtg, gf)             ((void)0)
+# define xfs_rtgroup_unlock(rtg, gf)           ((void)0)
+# define xfs_rtgroup_trans_join(tp, rtg, gf)   ((void)0)
 #endif /* CONFIG_XFS_RT */
 
 #endif /* __LIBXFS_RTGROUP_H */