Skip to content

Commit d664965

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: insert the pag structures into the xarray later
Cleaning up is much easier if a structure can't be looked up yet, so only insert the pag once it is fully set up. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 201c5fa commit d664965

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

fs/xfs/libxfs/xfs_ag.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,6 @@ xfs_perag_alloc(
307307
if (!pag)
308308
return -ENOMEM;
309309

310-
pag->pag_agno = index;
311-
pag->pag_mount = mp;
312-
313-
error = xa_insert(&mp->m_perags, index, pag, GFP_KERNEL);
314-
if (error) {
315-
WARN_ON_ONCE(error == -EBUSY);
316-
goto out_free_pag;
317-
}
318-
319310
#ifdef __KERNEL__
320311
/* Place kernel structure only init below this point. */
321312
spin_lock_init(&pag->pag_ici_lock);
@@ -331,10 +322,7 @@ xfs_perag_alloc(
331322

332323
error = xfs_buf_cache_init(&pag->pag_bcache);
333324
if (error)
334-
goto out_remove_pag;
335-
336-
/* Active ref owned by mount indicates AG is online. */
337-
atomic_set(&pag->pag_active_ref, 1);
325+
goto out_defer_drain_free;
338326

339327
/*
340328
* Pre-calculated geometry
@@ -344,12 +332,23 @@ xfs_perag_alloc(
344332
__xfs_agino_range(mp, pag->block_count, &pag->agino_min,
345333
&pag->agino_max);
346334

335+
pag->pag_agno = index;
336+
pag->pag_mount = mp;
337+
/* Active ref owned by mount indicates AG is online. */
338+
atomic_set(&pag->pag_active_ref, 1);
339+
340+
error = xa_insert(&mp->m_perags, index, pag, GFP_KERNEL);
341+
if (error) {
342+
WARN_ON_ONCE(error == -EBUSY);
343+
goto out_buf_cache_destroy;
344+
}
345+
347346
return 0;
348347

349-
out_remove_pag:
348+
out_buf_cache_destroy:
349+
xfs_buf_cache_destroy(&pag->pag_bcache);
350+
out_defer_drain_free:
350351
xfs_defer_drain_free(&pag->pag_intents_drain);
351-
pag = xa_erase(&mp->m_perags, index);
352-
out_free_pag:
353352
kfree(pag);
354353
return error;
355354
}

0 commit comments

Comments
 (0)