xfs: add a flag to release log items on commit
authorChristoph Hellwig <hch@lst.de>
Sat, 29 Jun 2019 02:27:32 +0000 (19:27 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Sat, 29 Jun 2019 02:27:32 +0000 (19:27 -0700)
We have various items that are released from ->iop_comitting.  Add a
flag to just call ->iop_release from the commit path to avoid tons
of boilerplate code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
fs/xfs/xfs_bmap_item.c
fs/xfs/xfs_extfree_item.c
fs/xfs/xfs_icreate_item.c
fs/xfs/xfs_refcount_item.c
fs/xfs/xfs_rmap_item.c
fs/xfs/xfs_trans.c
fs/xfs/xfs_trans.h

index bb5fff120ef529d8c2f183f71eda0430c6457538..6c3c03770b3f11bc115dac8a805f12a731615658 100644 (file)
@@ -209,39 +209,14 @@ xfs_bud_item_release(
        kmem_zone_free(xfs_bud_zone, budp);
 }
 
-/*
- * When the bud item is committed to disk, all we need to do is delete our
- * reference to our partner bui item and then free ourselves. Since we're
- * freeing ourselves we must return -1 to keep the transaction code from
- * further referencing this item.
- */
-STATIC xfs_lsn_t
-xfs_bud_item_committed(
-       struct xfs_log_item     *lip,
-       xfs_lsn_t               lsn)
-{
-       struct xfs_bud_log_item *budp = BUD_ITEM(lip);
-
-       /*
-        * Drop the BUI reference regardless of whether the BUD has been
-        * aborted. Once the BUD transaction is constructed, it is the sole
-        * responsibility of the BUD to release the BUI (even if the BUI is
-        * aborted due to log I/O error).
-        */
-       xfs_bui_release(budp->bud_buip);
-       kmem_zone_free(xfs_bud_zone, budp);
-
-       return (xfs_lsn_t)-1;
-}
-
 /*
  * This is the ops vector shared by all bud log items.
  */
 static const struct xfs_item_ops xfs_bud_item_ops = {
+       .flags          = XFS_ITEM_RELEASE_WHEN_COMMITTED,
        .iop_size       = xfs_bud_item_size,
        .iop_format     = xfs_bud_item_format,
        .iop_release    = xfs_bud_item_release,
-       .iop_committed  = xfs_bud_item_committed,
 };
 
 /*
index 70df190079950d962de4f540cc6c86b2f629f4a1..811923231bb7ad1125cff4db4a58776d51342f98 100644 (file)
@@ -308,39 +308,14 @@ xfs_efd_item_release(
        xfs_efd_item_free(efdp);
 }
 
-/*
- * When the efd item is committed to disk, all we need to do is delete our
- * reference to our partner efi item and then free ourselves. Since we're
- * freeing ourselves we must return -1 to keep the transaction code from further
- * referencing this item.
- */
-STATIC xfs_lsn_t
-xfs_efd_item_committed(
-       struct xfs_log_item     *lip,
-       xfs_lsn_t               lsn)
-{
-       struct xfs_efd_log_item *efdp = EFD_ITEM(lip);
-
-       /*
-        * Drop the EFI reference regardless of whether the EFD has been
-        * aborted. Once the EFD transaction is constructed, it is the sole
-        * responsibility of the EFD to release the EFI (even if the EFI is
-        * aborted due to log I/O error).
-        */
-       xfs_efi_release(efdp->efd_efip);
-       xfs_efd_item_free(efdp);
-
-       return (xfs_lsn_t)-1;
-}
-
 /*
  * This is the ops vector shared by all efd log items.
  */
 static const struct xfs_item_ops xfs_efd_item_ops = {
+       .flags          = XFS_ITEM_RELEASE_WHEN_COMMITTED,
        .iop_size       = xfs_efd_item_size,
        .iop_format     = xfs_efd_item_format,
        .iop_release    = xfs_efd_item_release,
-       .iop_committed  = xfs_efd_item_committed,
 };
 
 /*
index 9aceb35dce24687a0d2d5d461510547e22187f38..ac9918da5f4a54e38befc195537e94c756f6462f 100644 (file)
@@ -63,30 +63,14 @@ xfs_icreate_item_release(
        kmem_zone_free(xfs_icreate_zone, ICR_ITEM(lip));
 }
 
-/*
- * Because we have ordered buffers being tracked in the AIL for the inode
- * creation, we don't need the create item after this. Hence we can free
- * the log item and return -1 to tell the caller we're done with the item.
- */
-STATIC xfs_lsn_t
-xfs_icreate_item_committed(
-       struct xfs_log_item     *lip,
-       xfs_lsn_t               lsn)
-{
-       struct xfs_icreate_item *icp = ICR_ITEM(lip);
-
-       kmem_zone_free(xfs_icreate_zone, icp);
-       return (xfs_lsn_t)-1;
-}
-
 /*
  * This is the ops vector shared by all buf log items.
  */
 static const struct xfs_item_ops xfs_icreate_item_ops = {
+       .flags          = XFS_ITEM_RELEASE_WHEN_COMMITTED,
        .iop_size       = xfs_icreate_item_size,
        .iop_format     = xfs_icreate_item_format,
        .iop_release    = xfs_icreate_item_release,
-       .iop_committed  = xfs_icreate_item_committed,
 };
 
 
index 9f8fb23dcc8105e83ab3b805c24588790f39fedd..5b03478c5d1f6c65586f30a137b8455acd677ba8 100644 (file)
@@ -213,39 +213,14 @@ xfs_cud_item_release(
        kmem_zone_free(xfs_cud_zone, cudp);
 }
 
-/*
- * When the cud item is committed to disk, all we need to do is delete our
- * reference to our partner cui item and then free ourselves. Since we're
- * freeing ourselves we must return -1 to keep the transaction code from
- * further referencing this item.
- */
-STATIC xfs_lsn_t
-xfs_cud_item_committed(
-       struct xfs_log_item     *lip,
-       xfs_lsn_t               lsn)
-{
-       struct xfs_cud_log_item *cudp = CUD_ITEM(lip);
-
-       /*
-        * Drop the CUI reference regardless of whether the CUD has been
-        * aborted. Once the CUD transaction is constructed, it is the sole
-        * responsibility of the CUD to release the CUI (even if the CUI is
-        * aborted due to log I/O error).
-        */
-       xfs_cui_release(cudp->cud_cuip);
-       kmem_zone_free(xfs_cud_zone, cudp);
-
-       return (xfs_lsn_t)-1;
-}
-
 /*
  * This is the ops vector shared by all cud log items.
  */
 static const struct xfs_item_ops xfs_cud_item_ops = {
+       .flags          = XFS_ITEM_RELEASE_WHEN_COMMITTED,
        .iop_size       = xfs_cud_item_size,
        .iop_format     = xfs_cud_item_format,
        .iop_release    = xfs_cud_item_release,
-       .iop_committed  = xfs_cud_item_committed,
 };
 
 /*
index e907bd169de5731ce759bcee8789d6f3a708fa65..3fbc7c5ffa96f4020bfa226b498c93d26acfa2d4 100644 (file)
@@ -234,39 +234,14 @@ xfs_rud_item_release(
        kmem_zone_free(xfs_rud_zone, rudp);
 }
 
-/*
- * When the rud item is committed to disk, all we need to do is delete our
- * reference to our partner rui item and then free ourselves. Since we're
- * freeing ourselves we must return -1 to keep the transaction code from
- * further referencing this item.
- */
-STATIC xfs_lsn_t
-xfs_rud_item_committed(
-       struct xfs_log_item     *lip,
-       xfs_lsn_t               lsn)
-{
-       struct xfs_rud_log_item *rudp = RUD_ITEM(lip);
-
-       /*
-        * Drop the RUI reference regardless of whether the RUD has been
-        * aborted. Once the RUD transaction is constructed, it is the sole
-        * responsibility of the RUD to release the RUI (even if the RUI is
-        * aborted due to log I/O error).
-        */
-       xfs_rui_release(rudp->rud_ruip);
-       kmem_zone_free(xfs_rud_zone, rudp);
-
-       return (xfs_lsn_t)-1;
-}
-
 /*
  * This is the ops vector shared by all rud log items.
  */
 static const struct xfs_item_ops xfs_rud_item_ops = {
+       .flags          = XFS_ITEM_RELEASE_WHEN_COMMITTED,
        .iop_size       = xfs_rud_item_size,
        .iop_format     = xfs_rud_item_format,
        .iop_release    = xfs_rud_item_release,
-       .iop_committed  = xfs_rud_item_committed,
 };
 
 /*
index 261c51486d7abb2a2aae3e9151bf98c2ea6cb274..b026f87608cec851252d7b961605f9875afa7886 100644 (file)
@@ -851,6 +851,12 @@ xfs_trans_committed_bulk(
 
                if (aborted)
                        set_bit(XFS_LI_ABORTED, &lip->li_flags);
+
+               if (lip->li_ops->flags & XFS_ITEM_RELEASE_WHEN_COMMITTED) {
+                       lip->li_ops->iop_release(lip);
+                       continue;
+               }
+
                if (lip->li_ops->iop_committed)
                        item_lsn = lip->li_ops->iop_committed(lip, commit_lsn);
                else
index 522c1d565aa412c152a2afb837d5892a1740ab7d..ef5fd5db535086aa62ed8b0fe53e8684f9fee1db 100644 (file)
@@ -67,6 +67,7 @@ typedef struct xfs_log_item {
        { (1 << XFS_LI_DIRTY),          "DIRTY" }
 
 struct xfs_item_ops {
+       unsigned flags;
        void (*iop_size)(xfs_log_item_t *, int *, int *);
        void (*iop_format)(xfs_log_item_t *, struct xfs_log_vec *);
        void (*iop_pin)(xfs_log_item_t *);
@@ -78,6 +79,12 @@ struct xfs_item_ops {
        void (*iop_error)(xfs_log_item_t *, xfs_buf_t *);
 };
 
+/*
+ * Release the log item as soon as committed.  This is for items just logging
+ * intents that never need to be written back in place.
+ */
+#define XFS_ITEM_RELEASE_WHEN_COMMITTED        (1 << 0)
+
 void   xfs_log_item_init(struct xfs_mount *mp, struct xfs_log_item *item,
                          int type, const struct xfs_item_ops *ops);