Skip to content

Commit 69dbbfe

Browse files
Christoph Hellwiggregkh
authored andcommitted
xfs: decouple xfs_trans_alloc_empty from xfs_trans_alloc
[ Upstream commit 83a80e9 ] xfs_trans_alloc_empty only shares the very basic transaction structure allocation and initialization with xfs_trans_alloc. Split out a new __xfs_trans_alloc helper for that and otherwise decouple xfs_trans_alloc_empty from xfs_trans_alloc. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org> Stable-dep-of: d284551 ("xfs: fully decouple XFS_IBULK* flags from XFS_IWALK* flags") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent bce7a5c commit 69dbbfe

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

fs/xfs/xfs_trans.c

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,28 @@ xfs_trans_reserve(
241241
return error;
242242
}
243243

244+
static struct xfs_trans *
245+
__xfs_trans_alloc(
246+
struct xfs_mount *mp,
247+
uint flags)
248+
{
249+
struct xfs_trans *tp;
250+
251+
ASSERT(!(flags & XFS_TRANS_RES_FDBLKS) || xfs_has_lazysbcount(mp));
252+
253+
tp = kmem_cache_zalloc(xfs_trans_cache, GFP_KERNEL | __GFP_NOFAIL);
254+
if (!(flags & XFS_TRANS_NO_WRITECOUNT))
255+
sb_start_intwrite(mp->m_super);
256+
xfs_trans_set_context(tp);
257+
tp->t_flags = flags;
258+
tp->t_mountp = mp;
259+
INIT_LIST_HEAD(&tp->t_items);
260+
INIT_LIST_HEAD(&tp->t_busy);
261+
INIT_LIST_HEAD(&tp->t_dfops);
262+
tp->t_highest_agno = NULLAGNUMBER;
263+
return tp;
264+
}
265+
244266
int
245267
xfs_trans_alloc(
246268
struct xfs_mount *mp,
@@ -254,33 +276,16 @@ xfs_trans_alloc(
254276
bool want_retry = true;
255277
int error;
256278

279+
ASSERT(resp->tr_logres > 0);
280+
257281
/*
258282
* Allocate the handle before we do our freeze accounting and setting up
259283
* GFP_NOFS allocation context so that we avoid lockdep false positives
260284
* by doing GFP_KERNEL allocations inside sb_start_intwrite().
261285
*/
262286
retry:
263-
tp = kmem_cache_zalloc(xfs_trans_cache, GFP_KERNEL | __GFP_NOFAIL);
264-
if (!(flags & XFS_TRANS_NO_WRITECOUNT))
265-
sb_start_intwrite(mp->m_super);
266-
xfs_trans_set_context(tp);
267-
268-
/*
269-
* Zero-reservation ("empty") transactions can't modify anything, so
270-
* they're allowed to run while we're frozen.
271-
*/
272-
WARN_ON(resp->tr_logres > 0 &&
273-
mp->m_super->s_writers.frozen == SB_FREEZE_COMPLETE);
274-
ASSERT(!(flags & XFS_TRANS_RES_FDBLKS) ||
275-
xfs_has_lazysbcount(mp));
276-
277-
tp->t_flags = flags;
278-
tp->t_mountp = mp;
279-
INIT_LIST_HEAD(&tp->t_items);
280-
INIT_LIST_HEAD(&tp->t_busy);
281-
INIT_LIST_HEAD(&tp->t_dfops);
282-
tp->t_highest_agno = NULLAGNUMBER;
283-
287+
WARN_ON(mp->m_super->s_writers.frozen == SB_FREEZE_COMPLETE);
288+
tp = __xfs_trans_alloc(mp, flags);
284289
error = xfs_trans_reserve(tp, resp, blocks, rtextents);
285290
if (error == -ENOSPC && want_retry) {
286291
xfs_trans_cancel(tp);
@@ -329,9 +334,8 @@ xfs_trans_alloc_empty(
329334
struct xfs_mount *mp,
330335
struct xfs_trans **tpp)
331336
{
332-
struct xfs_trans_res resv = {0};
333-
334-
return xfs_trans_alloc(mp, &resv, 0, 0, XFS_TRANS_NO_WRITECOUNT, tpp);
337+
*tpp = __xfs_trans_alloc(mp, XFS_TRANS_NO_WRITECOUNT);
338+
return 0;
335339
}
336340

337341
/*

0 commit comments

Comments
 (0)