Commit b7e23c0e authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Chandan Babu R
Browse files

xfs: refactor realtime inode locking



Create helper functions to deal with locking realtime metadata inodes.
This enables us to maintain correct locking order once we start adding
the realtime rmap and refcount btree inodes.

Signed-off-by: default avatar"Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Signed-off-by: default avatarChandan Babu R <chandanbabu@kernel.org>
parent 330c4f94
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -5418,12 +5418,9 @@ __xfs_bunmapi(

	if (isrt) {
		/*
		 * Synchronize by locking the bitmap inode.
		 * Synchronize by locking the realtime bitmap.
		 */
		xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL|XFS_ILOCK_RTBITMAP);
		xfs_trans_ijoin(tp, mp->m_rbmip, XFS_ILOCK_EXCL);
		xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL|XFS_ILOCK_RTSUM);
		xfs_trans_ijoin(tp, mp->m_rsumip, XFS_ILOCK_EXCL);
		xfs_rtbitmap_lock(tp, mp);
	}

	extno = 0;
+57 −0
Original line number Diff line number Diff line
@@ -1168,3 +1168,60 @@ xfs_rtsummary_wordcount(
	blocks = xfs_rtsummary_blockcount(mp, rsumlevels, rbmblocks);
	return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
}

/*
 * Lock both realtime free space metadata inodes for a freespace update.  If a
 * transaction is given, the inodes will be joined to the transaction and the
 * ILOCKs will be released on transaction commit.
 */
void
xfs_rtbitmap_lock(
	struct xfs_trans	*tp,
	struct xfs_mount	*mp)
{
	xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP);
	if (tp)
		xfs_trans_ijoin(tp, mp->m_rbmip, XFS_ILOCK_EXCL);

	xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL | XFS_ILOCK_RTSUM);
	if (tp)
		xfs_trans_ijoin(tp, mp->m_rsumip, XFS_ILOCK_EXCL);
}

/* Unlock both realtime free space metadata inodes after a freespace update. */
void
xfs_rtbitmap_unlock(
	struct xfs_mount	*mp)
{
	xfs_iunlock(mp->m_rsumip, XFS_ILOCK_EXCL | XFS_ILOCK_RTSUM);
	xfs_iunlock(mp->m_rbmip, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP);
}

/*
 * Lock the realtime free space metadata inodes for a freespace scan.  Callers
 * must walk metadata blocks in order of increasing file offset.
 */
void
xfs_rtbitmap_lock_shared(
	struct xfs_mount	*mp,
	unsigned int		rbmlock_flags)
{
	if (rbmlock_flags & XFS_RBMLOCK_BITMAP)
		xfs_ilock(mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);

	if (rbmlock_flags & XFS_RBMLOCK_SUMMARY)
		xfs_ilock(mp->m_rsumip, XFS_ILOCK_SHARED | XFS_ILOCK_RTSUM);
}

/* Unlock the realtime free space metadata inodes after a freespace scan. */
void
xfs_rtbitmap_unlock_shared(
	struct xfs_mount	*mp,
	unsigned int		rbmlock_flags)
{
	if (rbmlock_flags & XFS_RBMLOCK_SUMMARY)
		xfs_iunlock(mp->m_rsumip, XFS_ILOCK_SHARED | XFS_ILOCK_RTSUM);

	if (rbmlock_flags & XFS_RBMLOCK_BITMAP)
		xfs_iunlock(mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
}
+17 −0
Original line number Diff line number Diff line
@@ -360,6 +360,19 @@ xfs_filblks_t xfs_rtsummary_blockcount(struct xfs_mount *mp,
		unsigned int rsumlevels, xfs_extlen_t rbmblocks);
unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp,
		unsigned int rsumlevels, xfs_extlen_t rbmblocks);

void xfs_rtbitmap_lock(struct xfs_trans *tp, struct xfs_mount *mp);
void xfs_rtbitmap_unlock(struct xfs_mount *mp);

/* Lock the rt bitmap inode in shared mode */
#define XFS_RBMLOCK_BITMAP	(1U << 0)
/* Lock the rt summary inode in shared mode */
#define XFS_RBMLOCK_SUMMARY	(1U << 1)

void xfs_rtbitmap_lock_shared(struct xfs_mount *mp,
		unsigned int rbmlock_flags);
void xfs_rtbitmap_unlock_shared(struct xfs_mount *mp,
		unsigned int rbmlock_flags);
#else /* CONFIG_XFS_RT */
# define xfs_rtfree_extent(t,b,l)			(-ENOSYS)
# define xfs_rtfree_blocks(t,rb,rl)			(-ENOSYS)
@@ -378,6 +391,10 @@ xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)
# define xfs_rtbitmap_wordcount(mp, r)			(0)
# define xfs_rtsummary_blockcount(mp, l, b)		(0)
# define xfs_rtsummary_wordcount(mp, l, b)		(0)
# define xfs_rtbitmap_lock(tp, mp)		do { } while (0)
# define xfs_rtbitmap_unlock(mp)		do { } while (0)
# define xfs_rtbitmap_lock_shared(mp, lf)	do { } while (0)
# define xfs_rtbitmap_unlock_shared(mp, lf)	do { } while (0)
#endif /* CONFIG_XFS_RT */

#endif /* __XFS_RTBITMAP_H__ */
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include "xfs_error.h"
#include "xfs_quota.h"
#include "xfs_exchmaps.h"
#include "xfs_rtbitmap.h"
#include "scrub/scrub.h"
#include "scrub/common.h"
#include "scrub/trace.h"
+2 −2
Original line number Diff line number Diff line
@@ -415,7 +415,7 @@ xchk_fscount_count_frextents(
	if (!xfs_has_realtime(mp))
		return 0;

	xfs_ilock(sc->mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
	xfs_rtbitmap_lock_shared(sc->mp, XFS_RBMLOCK_BITMAP);
	error = xfs_rtalloc_query_all(sc->mp, sc->tp,
			xchk_fscount_add_frextent, fsc);
	if (error) {
@@ -424,7 +424,7 @@ xchk_fscount_count_frextents(
	}

out_unlock:
	xfs_iunlock(sc->mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
	xfs_rtbitmap_unlock_shared(sc->mp, XFS_RBMLOCK_BITMAP);
	return error;
}
#else
Loading