Skip to content

Commit 0e4875b

Browse files
author
Darrick J. Wong
committed
xfs: define locking primitives for realtime groups
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 <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 87fe4c3 commit 0e4875b

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

fs/xfs/libxfs/xfs_rtgroup.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,52 @@ xfs_update_last_rtgroup_size(
149149
xfs_rtgroup_rele(rtg);
150150
return 0;
151151
}
152+
153+
/* Lock metadata inodes associated with this rt group. */
154+
void
155+
xfs_rtgroup_lock(
156+
struct xfs_rtgroup *rtg,
157+
unsigned int rtglock_flags)
158+
{
159+
ASSERT(!(rtglock_flags & ~XFS_RTGLOCK_ALL_FLAGS));
160+
ASSERT(!(rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED) ||
161+
!(rtglock_flags & XFS_RTGLOCK_BITMAP));
162+
163+
if (rtglock_flags & XFS_RTGLOCK_BITMAP)
164+
xfs_rtbitmap_lock(rtg_mount(rtg));
165+
else if (rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED)
166+
xfs_rtbitmap_lock_shared(rtg_mount(rtg), XFS_RBMLOCK_BITMAP);
167+
}
168+
169+
/* Unlock metadata inodes associated with this rt group. */
170+
void
171+
xfs_rtgroup_unlock(
172+
struct xfs_rtgroup *rtg,
173+
unsigned int rtglock_flags)
174+
{
175+
ASSERT(!(rtglock_flags & ~XFS_RTGLOCK_ALL_FLAGS));
176+
ASSERT(!(rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED) ||
177+
!(rtglock_flags & XFS_RTGLOCK_BITMAP));
178+
179+
if (rtglock_flags & XFS_RTGLOCK_BITMAP)
180+
xfs_rtbitmap_unlock(rtg_mount(rtg));
181+
else if (rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED)
182+
xfs_rtbitmap_unlock_shared(rtg_mount(rtg), XFS_RBMLOCK_BITMAP);
183+
}
184+
185+
/*
186+
* Join realtime group metadata inodes to the transaction. The ILOCKs will be
187+
* released on transaction commit.
188+
*/
189+
void
190+
xfs_rtgroup_trans_join(
191+
struct xfs_trans *tp,
192+
struct xfs_rtgroup *rtg,
193+
unsigned int rtglock_flags)
194+
{
195+
ASSERT(!(rtglock_flags & ~XFS_RTGLOCK_ALL_FLAGS));
196+
ASSERT(!(rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED));
197+
198+
if (rtglock_flags & XFS_RTGLOCK_BITMAP)
199+
xfs_rtbitmap_trans_join(tp);
200+
}

fs/xfs/libxfs/xfs_rtgroup.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,19 @@ xfs_rtxnum_t xfs_rtgroup_extents(struct xfs_mount *mp, xfs_rgnumber_t rgno);
197197

198198
int xfs_update_last_rtgroup_size(struct xfs_mount *mp,
199199
xfs_rgnumber_t prev_rgcount);
200+
201+
/* Lock the rt bitmap inode in exclusive mode */
202+
#define XFS_RTGLOCK_BITMAP (1U << 0)
203+
/* Lock the rt bitmap inode in shared mode */
204+
#define XFS_RTGLOCK_BITMAP_SHARED (1U << 1)
205+
206+
#define XFS_RTGLOCK_ALL_FLAGS (XFS_RTGLOCK_BITMAP | \
207+
XFS_RTGLOCK_BITMAP_SHARED)
208+
209+
void xfs_rtgroup_lock(struct xfs_rtgroup *rtg, unsigned int rtglock_flags);
210+
void xfs_rtgroup_unlock(struct xfs_rtgroup *rtg, unsigned int rtglock_flags);
211+
void xfs_rtgroup_trans_join(struct xfs_trans *tp, struct xfs_rtgroup *rtg,
212+
unsigned int rtglock_flags);
200213
#else
201214
static inline void xfs_free_rtgroups(struct xfs_mount *mp,
202215
xfs_rgnumber_t first_rgno, xfs_rgnumber_t end_rgno)
@@ -212,6 +225,9 @@ static inline int xfs_initialize_rtgroups(struct xfs_mount *mp,
212225

213226
# define xfs_rtgroup_extents(mp, rgno) (0)
214227
# define xfs_update_last_rtgroup_size(mp, rgno) (-EOPNOTSUPP)
228+
# define xfs_rtgroup_lock(rtg, gf) ((void)0)
229+
# define xfs_rtgroup_unlock(rtg, gf) ((void)0)
230+
# define xfs_rtgroup_trans_join(tp, rtg, gf) ((void)0)
215231
#endif /* CONFIG_XFS_RT */
216232

217233
#endif /* __LIBXFS_RTGROUP_H */

0 commit comments

Comments
 (0)