1616#include "xfs_log.h"
1717#include "xfs_log_priv.h"
1818#include "xfs_trace.h"
19-
20- struct workqueue_struct * xfs_discard_wq ;
19+ #include "xfs_discard.h"
2120
2221/*
2322 * Allocate a new ticket. Failing to get a new ticket makes it really hard to
@@ -103,7 +102,7 @@ xlog_cil_ctx_alloc(void)
103102
104103 ctx = kmem_zalloc (sizeof (* ctx ), KM_NOFS );
105104 INIT_LIST_HEAD (& ctx -> committing );
106- INIT_LIST_HEAD (& ctx -> busy_extents );
105+ INIT_LIST_HEAD (& ctx -> busy_extents . extent_list );
107106 INIT_LIST_HEAD (& ctx -> log_items );
108107 INIT_LIST_HEAD (& ctx -> lv_chain );
109108 INIT_WORK (& ctx -> push_work , xlog_cil_push_work );
@@ -132,7 +131,7 @@ xlog_cil_push_pcp_aggregate(
132131
133132 if (!list_empty (& cilpcp -> busy_extents )) {
134133 list_splice_init (& cilpcp -> busy_extents ,
135- & ctx -> busy_extents );
134+ & ctx -> busy_extents . extent_list );
136135 }
137136 if (!list_empty (& cilpcp -> log_items ))
138137 list_splice_init (& cilpcp -> log_items , & ctx -> log_items );
@@ -708,76 +707,6 @@ xlog_cil_free_logvec(
708707 }
709708}
710709
711- static void
712- xlog_discard_endio_work (
713- struct work_struct * work )
714- {
715- struct xfs_cil_ctx * ctx =
716- container_of (work , struct xfs_cil_ctx , discard_endio_work );
717- struct xfs_mount * mp = ctx -> cil -> xc_log -> l_mp ;
718-
719- xfs_extent_busy_clear (mp , & ctx -> busy_extents , false);
720- kmem_free (ctx );
721- }
722-
723- /*
724- * Queue up the actual completion to a thread to avoid IRQ-safe locking for
725- * pagb_lock. Note that we need a unbounded workqueue, otherwise we might
726- * get the execution delayed up to 30 seconds for weird reasons.
727- */
728- static void
729- xlog_discard_endio (
730- struct bio * bio )
731- {
732- struct xfs_cil_ctx * ctx = bio -> bi_private ;
733-
734- INIT_WORK (& ctx -> discard_endio_work , xlog_discard_endio_work );
735- queue_work (xfs_discard_wq , & ctx -> discard_endio_work );
736- bio_put (bio );
737- }
738-
739- static void
740- xlog_discard_busy_extents (
741- struct xfs_mount * mp ,
742- struct xfs_cil_ctx * ctx )
743- {
744- struct list_head * list = & ctx -> busy_extents ;
745- struct xfs_extent_busy * busyp ;
746- struct bio * bio = NULL ;
747- struct blk_plug plug ;
748- int error = 0 ;
749-
750- ASSERT (xfs_has_discard (mp ));
751-
752- blk_start_plug (& plug );
753- list_for_each_entry (busyp , list , list ) {
754- trace_xfs_discard_extent (mp , busyp -> agno , busyp -> bno ,
755- busyp -> length );
756-
757- error = __blkdev_issue_discard (mp -> m_ddev_targp -> bt_bdev ,
758- XFS_AGB_TO_DADDR (mp , busyp -> agno , busyp -> bno ),
759- XFS_FSB_TO_BB (mp , busyp -> length ),
760- GFP_NOFS , & bio );
761- if (error && error != - EOPNOTSUPP ) {
762- xfs_info (mp ,
763- "discard failed for extent [0x%llx,%u], error %d" ,
764- (unsigned long long )busyp -> bno ,
765- busyp -> length ,
766- error );
767- break ;
768- }
769- }
770-
771- if (bio ) {
772- bio -> bi_private = ctx ;
773- bio -> bi_end_io = xlog_discard_endio ;
774- submit_bio (bio );
775- } else {
776- xlog_discard_endio_work (& ctx -> discard_endio_work );
777- }
778- blk_finish_plug (& plug );
779- }
780-
781710/*
782711 * Mark all items committed and clear busy extents. We free the log vector
783712 * chains in a separate pass so that we unpin the log items as quickly as
@@ -807,8 +736,8 @@ xlog_cil_committed(
807736 xfs_trans_committed_bulk (ctx -> cil -> xc_log -> l_ailp , & ctx -> lv_chain ,
808737 ctx -> start_lsn , abort );
809738
810- xfs_extent_busy_sort (& ctx -> busy_extents );
811- xfs_extent_busy_clear (mp , & ctx -> busy_extents ,
739+ xfs_extent_busy_sort (& ctx -> busy_extents . extent_list );
740+ xfs_extent_busy_clear (mp , & ctx -> busy_extents . extent_list ,
812741 xfs_has_discard (mp ) && !abort );
813742
814743 spin_lock (& ctx -> cil -> xc_push_lock );
@@ -817,10 +746,14 @@ xlog_cil_committed(
817746
818747 xlog_cil_free_logvec (& ctx -> lv_chain );
819748
820- if (!list_empty (& ctx -> busy_extents ))
821- xlog_discard_busy_extents (mp , ctx );
822- else
823- kmem_free (ctx );
749+ if (!list_empty (& ctx -> busy_extents .extent_list )) {
750+ ctx -> busy_extents .mount = mp ;
751+ ctx -> busy_extents .owner = ctx ;
752+ xfs_discard_extents (mp , & ctx -> busy_extents );
753+ return ;
754+ }
755+
756+ kmem_free (ctx );
824757}
825758
826759void
0 commit comments