aboutsummaryrefslogtreecommitdiffstats
diff options
authorCarlos Maiolino <cem@kernel.org>2025-01-28 11:40:36 +0100
committerCarlos Maiolino <cem@kernel.org>2025-01-31 15:06:05 +0100
commit479ae68478d9c98436a6e6b8254457df025e03c8 (patch)
tree9ed731524ccd2f212e402cb8d92ed3f1bc3b91d0
parentee10f6fcdb961e810d7b16be1285319c15c78ef6 (diff)
downloadxfs-linux-479ae68478d9c98436a6e6b8254457df025e03c8.tar.gz
Add couple helpers to alloc/free xfs_busy_extents
There are a couple locations which repeats the same code pattern to alloc/free the xfs_busy_extents list. Those aren't suuuper useful now, but will come in hand on the following patches to decouple the busy_extents list from the cil context. Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
-rw-r--r--fs/xfs/xfs_discard.c13
-rw-r--r--fs/xfs/xfs_extent_busy.h14
2 files changed, 19 insertions, 8 deletions
diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
index 3f2403a7b49ca3..88f82eeda70e2b 100644
--- a/fs/xfs/xfs_discard.c
+++ b/fs/xfs/xfs_discard.c
@@ -362,18 +362,16 @@ xfs_trim_perag_extents(
do {
struct xfs_busy_extents *extents;
- extents = kzalloc(sizeof(*extents), GFP_KERNEL);
+ extents = xfs_busy_extents_alloc(GFP_KERNEL);
if (!extents) {
error = -ENOMEM;
break;
}
-
extents->owner = extents;
- INIT_LIST_HEAD(&extents->extent_list);
error = xfs_trim_gather_extents(pag, &tcur, extents);
if (error) {
- kfree(extents);
+ xfs_busy_extents_free(extents);
break;
}
@@ -710,16 +708,15 @@ xfs_trim_rtgroup_extents(
* trims the extents returned.
*/
do {
- tr.extents = kzalloc(sizeof(*tr.extents), GFP_KERNEL);
+ tr.extents = xfs_busy_extents_alloc(GFP_KERNEL);
if (!tr.extents) {
error = -ENOMEM;
break;
}
+ tr.extents->owner = tr.extents;
tr.queued = 0;
tr.batch = XFS_DISCARD_MAX_EXAMINE;
- tr.extents->owner = tr.extents;
- INIT_LIST_HEAD(&tr.extents->extent_list);
xfs_rtgroup_lock(rtg, XFS_RTGLOCK_BITMAP_SHARED);
error = xfs_rtalloc_query_range(rtg, tp, low, high,
@@ -728,7 +725,7 @@ xfs_trim_rtgroup_extents(
if (error == -ECANCELED)
error = 0;
if (error) {
- kfree(tr.extents);
+ xfs_busy_extents_free(tr.extents);
break;
}
diff --git a/fs/xfs/xfs_extent_busy.h b/fs/xfs/xfs_extent_busy.h
index f069b04e8ea184..c164f08985c480 100644
--- a/fs/xfs/xfs_extent_busy.h
+++ b/fs/xfs/xfs_extent_busy.h
@@ -43,6 +43,20 @@ struct xfs_busy_extents {
void *owner;
};
+static inline struct xfs_busy_extents*
+xfs_busy_extents_alloc(gfp_t flags) {
+ struct xfs_busy_extents *e = kzalloc(sizeof(struct xfs_busy_extents),
+ flags);
+
+ if (e)
+ INIT_LIST_HEAD(&e->extent_list);
+
+ return e;
+}
+static inline void xfs_busy_extents_free(struct xfs_busy_extents *e) {
+ kfree(e);
+}
+
void xfs_extent_busy_insert(struct xfs_trans *tp, struct xfs_group *xg,
xfs_agblock_t bno, xfs_extlen_t len, unsigned int flags);
void xfs_extent_busy_insert_discard(struct xfs_group *xg, xfs_agblock_t bno,