xfs: collapse the ->create_done functions
authorDarrick J. Wong <djwong@kernel.org>
Thu, 30 Nov 2023 20:17:37 +0000 (12:17 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 7 Dec 2023 02:45:16 +0000 (18:45 -0800)
Move the meat of the ->create_done function helpers into ->create_done
to reduce the amount of boilerplate.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/xfs_attr_item.c
fs/xfs/xfs_bmap_item.c
fs/xfs/xfs_extfree_item.c
fs/xfs/xfs_refcount_item.c
fs/xfs/xfs_rmap_item.c

index c815811d937aadae9dd19a284f85046068c56c56..27553388da99cb93b6c1936cc6ef8738bc66edfb 100644 (file)
@@ -33,8 +33,6 @@ struct kmem_cache             *xfs_attrd_cache;
 
 static const struct xfs_item_ops xfs_attri_item_ops;
 static const struct xfs_item_ops xfs_attrd_item_ops;
-static struct xfs_attrd_log_item *xfs_trans_get_attrd(struct xfs_trans *tp,
-                                       struct xfs_attri_log_item *attrip);
 
 static inline struct xfs_attri_log_item *ATTRI_ITEM(struct xfs_log_item *lip)
 {
@@ -732,27 +730,6 @@ xlog_recover_attri_commit_pass2(
        return 0;
 }
 
-/*
- * This routine is called to allocate an "attr free done" log item.
- */
-static struct xfs_attrd_log_item *
-xfs_trans_get_attrd(struct xfs_trans           *tp,
-                 struct xfs_attri_log_item     *attrip)
-{
-       struct xfs_attrd_log_item               *attrdp;
-
-       ASSERT(tp != NULL);
-
-       attrdp = kmem_cache_zalloc(xfs_attrd_cache, GFP_NOFS | __GFP_NOFAIL);
-
-       xfs_log_item_init(tp->t_mountp, &attrdp->attrd_item, XFS_LI_ATTRD,
-                         &xfs_attrd_item_ops);
-       attrdp->attrd_attrip = attrip;
-       attrdp->attrd_format.alfd_alf_id = attrip->attri_format.alfi_id;
-
-       return attrdp;
-}
-
 /* Get an ATTRD so we can process all the attrs. */
 static struct xfs_log_item *
 xfs_attr_create_done(
@@ -760,10 +737,22 @@ xfs_attr_create_done(
        struct xfs_log_item             *intent,
        unsigned int                    count)
 {
+       struct xfs_attri_log_item       *attrip;
+       struct xfs_attrd_log_item       *attrdp;
+
        if (!intent)
                return NULL;
 
-       return &xfs_trans_get_attrd(tp, ATTRI_ITEM(intent))->attrd_item;
+       attrip = ATTRI_ITEM(intent);
+
+       attrdp = kmem_cache_zalloc(xfs_attrd_cache, GFP_NOFS | __GFP_NOFAIL);
+
+       xfs_log_item_init(tp->t_mountp, &attrdp->attrd_item, XFS_LI_ATTRD,
+                         &xfs_attrd_item_ops);
+       attrdp->attrd_attrip = attrip;
+       attrdp->attrd_format.alfd_alf_id = attrip->attri_format.alfi_id;
+
+       return &attrdp->attrd_item;
 }
 
 const struct xfs_defer_op_type xfs_attr_defer_type = {
index 0be7a1224a81ccfa48d3745086590034a0b51063..f3421e615e1c70fdab9945849850019d1070172b 100644 (file)
@@ -221,22 +221,6 @@ static const struct xfs_item_ops xfs_bud_item_ops = {
        .iop_intent     = xfs_bud_item_intent,
 };
 
-static struct xfs_bud_log_item *
-xfs_trans_get_bud(
-       struct xfs_trans                *tp,
-       struct xfs_bui_log_item         *buip)
-{
-       struct xfs_bud_log_item         *budp;
-
-       budp = kmem_cache_zalloc(xfs_bud_cache, GFP_KERNEL | __GFP_NOFAIL);
-       xfs_log_item_init(tp->t_mountp, &budp->bud_item, XFS_LI_BUD,
-                         &xfs_bud_item_ops);
-       budp->bud_buip = buip;
-       budp->bud_format.bud_bui_id = buip->bui_format.bui_id;
-
-       return budp;
-}
-
 /* Sort bmap intents by inode. */
 static int
 xfs_bmap_update_diff_items(
@@ -321,14 +305,23 @@ xfs_bmap_update_create_intent(
        return &buip->bui_item;
 }
 
-/* Get an BUD so we can process all the deferred rmap updates. */
+/* Get an BUD so we can process all the deferred bmap updates. */
 static struct xfs_log_item *
 xfs_bmap_update_create_done(
        struct xfs_trans                *tp,
        struct xfs_log_item             *intent,
        unsigned int                    count)
 {
-       return &xfs_trans_get_bud(tp, BUI_ITEM(intent))->bud_item;
+       struct xfs_bui_log_item         *buip = BUI_ITEM(intent);
+       struct xfs_bud_log_item         *budp;
+
+       budp = kmem_cache_zalloc(xfs_bud_cache, GFP_KERNEL | __GFP_NOFAIL);
+       xfs_log_item_init(tp->t_mountp, &budp->bud_item, XFS_LI_BUD,
+                         &xfs_bud_item_ops);
+       budp->bud_buip = buip;
+       budp->bud_format.bud_bui_id = buip->bui_format.bui_id;
+
+       return &budp->bud_item;
 }
 
 /* Take a passive ref to the AG containing the space we're mapping. */
index 44bbf620e0cf525771c8745ff549e16073973080..518569c64e9cb0cde367dbef5cdcd02198ae355d 100644 (file)
@@ -303,38 +303,6 @@ static const struct xfs_item_ops xfs_efd_item_ops = {
        .iop_intent     = xfs_efd_item_intent,
 };
 
-/*
- * Allocate an "extent free done" log item that will hold nextents worth of
- * extents.  The caller must use all nextents extents, because we are not
- * flexible about this at all.
- */
-static struct xfs_efd_log_item *
-xfs_trans_get_efd(
-       struct xfs_trans                *tp,
-       struct xfs_efi_log_item         *efip,
-       unsigned int                    nextents)
-{
-       struct xfs_efd_log_item         *efdp;
-
-       ASSERT(nextents > 0);
-
-       if (nextents > XFS_EFD_MAX_FAST_EXTENTS) {
-               efdp = kzalloc(xfs_efd_log_item_sizeof(nextents),
-                               GFP_KERNEL | __GFP_NOFAIL);
-       } else {
-               efdp = kmem_cache_zalloc(xfs_efd_cache,
-                                       GFP_KERNEL | __GFP_NOFAIL);
-       }
-
-       xfs_log_item_init(tp->t_mountp, &efdp->efd_item, XFS_LI_EFD,
-                         &xfs_efd_item_ops);
-       efdp->efd_efip = efip;
-       efdp->efd_format.efd_nextents = nextents;
-       efdp->efd_format.efd_efi_id = efip->efi_format.efi_id;
-
-       return efdp;
-}
-
 /*
  * Fill the EFD with all extents from the EFI when we need to roll the
  * transaction and continue with a new EFI.
@@ -428,7 +396,26 @@ xfs_extent_free_create_done(
        struct xfs_log_item             *intent,
        unsigned int                    count)
 {
-       return &xfs_trans_get_efd(tp, EFI_ITEM(intent), count)->efd_item;
+       struct xfs_efi_log_item         *efip = EFI_ITEM(intent);
+       struct xfs_efd_log_item         *efdp;
+
+       ASSERT(count > 0);
+
+       if (count > XFS_EFD_MAX_FAST_EXTENTS) {
+               efdp = kzalloc(xfs_efd_log_item_sizeof(count),
+                               GFP_KERNEL | __GFP_NOFAIL);
+       } else {
+               efdp = kmem_cache_zalloc(xfs_efd_cache,
+                                       GFP_KERNEL | __GFP_NOFAIL);
+       }
+
+       xfs_log_item_init(tp->t_mountp, &efdp->efd_item, XFS_LI_EFD,
+                         &xfs_efd_item_ops);
+       efdp->efd_efip = efip;
+       efdp->efd_format.efd_nextents = count;
+       efdp->efd_format.efd_efi_id = efip->efi_format.efi_id;
+
+       return &efdp->efd_item;
 }
 
 /* Take a passive ref to the AG containing the space we're freeing. */
index a66bb6aa2e5dbd537ce5d481e52573bbe5068e56..d218a9ed4d820e8bc6a7bb5063f9461af9edbed7 100644 (file)
@@ -227,22 +227,6 @@ static const struct xfs_item_ops xfs_cud_item_ops = {
        .iop_intent     = xfs_cud_item_intent,
 };
 
-static struct xfs_cud_log_item *
-xfs_trans_get_cud(
-       struct xfs_trans                *tp,
-       struct xfs_cui_log_item         *cuip)
-{
-       struct xfs_cud_log_item         *cudp;
-
-       cudp = kmem_cache_zalloc(xfs_cud_cache, GFP_KERNEL | __GFP_NOFAIL);
-       xfs_log_item_init(tp->t_mountp, &cudp->cud_item, XFS_LI_CUD,
-                         &xfs_cud_item_ops);
-       cudp->cud_cuip = cuip;
-       cudp->cud_format.cud_cui_id = cuip->cui_format.cui_id;
-
-       return cudp;
-}
-
 /* Sort refcount intents by AG. */
 static int
 xfs_refcount_update_diff_items(
@@ -328,7 +312,16 @@ xfs_refcount_update_create_done(
        struct xfs_log_item             *intent,
        unsigned int                    count)
 {
-       return &xfs_trans_get_cud(tp, CUI_ITEM(intent))->cud_item;
+       struct xfs_cui_log_item         *cuip = CUI_ITEM(intent);
+       struct xfs_cud_log_item         *cudp;
+
+       cudp = kmem_cache_zalloc(xfs_cud_cache, GFP_KERNEL | __GFP_NOFAIL);
+       xfs_log_item_init(tp->t_mountp, &cudp->cud_item, XFS_LI_CUD,
+                         &xfs_cud_item_ops);
+       cudp->cud_cuip = cuip;
+       cudp->cud_format.cud_cui_id = cuip->cui_format.cui_id;
+
+       return &cudp->cud_item;
 }
 
 /* Take a passive ref to the AG containing the space we're refcounting. */
index d668eb4d099ec294cc6d577f0bdb42912e40e411..96e0c2b0d0594cdcc28db2ff9e7a22d814f8206a 100644 (file)
@@ -225,22 +225,6 @@ static const struct xfs_item_ops xfs_rud_item_ops = {
        .iop_intent     = xfs_rud_item_intent,
 };
 
-static struct xfs_rud_log_item *
-xfs_trans_get_rud(
-       struct xfs_trans                *tp,
-       struct xfs_rui_log_item         *ruip)
-{
-       struct xfs_rud_log_item         *rudp;
-
-       rudp = kmem_cache_zalloc(xfs_rud_cache, GFP_KERNEL | __GFP_NOFAIL);
-       xfs_log_item_init(tp->t_mountp, &rudp->rud_item, XFS_LI_RUD,
-                         &xfs_rud_item_ops);
-       rudp->rud_ruip = ruip;
-       rudp->rud_format.rud_rui_id = ruip->rui_format.rui_id;
-
-       return rudp;
-}
-
 /* Set the map extent flags for this reverse mapping. */
 static void
 xfs_trans_set_rmap_flags(
@@ -353,7 +337,16 @@ xfs_rmap_update_create_done(
        struct xfs_log_item             *intent,
        unsigned int                    count)
 {
-       return &xfs_trans_get_rud(tp, RUI_ITEM(intent))->rud_item;
+       struct xfs_rui_log_item         *ruip = RUI_ITEM(intent);
+       struct xfs_rud_log_item         *rudp;
+
+       rudp = kmem_cache_zalloc(xfs_rud_cache, GFP_KERNEL | __GFP_NOFAIL);
+       xfs_log_item_init(tp->t_mountp, &rudp->rud_item, XFS_LI_RUD,
+                         &xfs_rud_item_ops);
+       rudp->rud_ruip = ruip;
+       rudp->rud_format.rud_rui_id = ruip->rui_format.rui_id;
+
+       return &rudp->rud_item;
 }
 
 /* Take a passive ref to the AG containing the space we're rmapping. */