]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: define locking primitives for realtime groups
authorDarrick J. Wong <djwong@kernel.org>
Tue, 9 Jan 2024 17:39:56 +0000 (09:39 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 10 Apr 2024 00:21:38 +0000 (17:21 -0700)
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>
libxfs/xfs_rtgroup.c
libxfs/xfs_rtgroup.h

index 47056550c6e5ae33042d2621a38f7404927ab5d9..a56bb68036f1becc1f8d2079f8c46a2f45bb2458 100644 (file)
@@ -552,3 +552,36 @@ xfs_rtgroup_update_secondary_sbs(
 
        return saved_error ? saved_error : error;
 }
+
+/* Lock metadata inodes associated with this rt group. */
+void
+xfs_rtgroup_lock(
+       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) ||
+              !(rtglock_flags & XFS_RTGLOCK_BITMAP));
+
+       if (rtglock_flags & XFS_RTGLOCK_BITMAP)
+               xfs_rtbitmap_lock(tp, rtg->rtg_mount);
+       else if (rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED)
+               xfs_rtbitmap_lock_shared(rtg->rtg_mount, 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->rtg_mount);
+       else if (rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED)
+               xfs_rtbitmap_unlock_shared(rtg->rtg_mount, XFS_RBMLOCK_BITMAP);
+}
index be6bfdb3c044c64cf2fae6dd3ea270fc545131c6..3ff66b1669ecf0312005efe57d5da776f46b0dd0 100644 (file)
@@ -223,11 +223,25 @@ void xfs_rtgroup_update_super(struct xfs_buf *rtsb_bp,
                const struct xfs_buf *sb_bp);
 void xfs_rtgroup_log_super(struct xfs_trans *tp, const struct xfs_buf *sb_bp);
 int xfs_rtgroup_update_secondary_sbs(struct xfs_mount *mp);
+
+/* 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_trans *tp, struct xfs_rtgroup *rtg,
+               unsigned int rtglock_flags);
+void xfs_rtgroup_unlock(struct xfs_rtgroup *rtg, unsigned int rtglock_flags);
 #else
 # define xfs_rtgroup_block_count(mp, rgno)     (0)
 # define xfs_rtgroup_update_super(bp, sb_bp)   ((void)0)
 # define xfs_rtgroup_log_super(tp, sb_bp)      ((void)0)
 # define xfs_rtgroup_update_secondary_sbs(mp)  (0)
+# define xfs_rtgroup_lock(tp, rtg, gf)         ((void)0)
+# define xfs_rtgroup_unlock(rtg, gf)           ((void)0)
 #endif /* CONFIG_XFS_RT */
 
 #endif /* __LIBXFS_RTGROUP_H */