@@ -2252,72 +2252,26 @@ xfs_buf_cmp(
22522252 return 0 ;
22532253}
22542254
2255- /*
2256- * Submit buffers for write. If wait_list is specified, the buffers are
2257- * submitted using sync I/O and placed on the wait list such that the caller can
2258- * iowait each buffer. Otherwise async I/O is used and the buffers are released
2259- * at I/O completion time. In either case, buffers remain locked until I/O
2260- * completes and the buffer is released from the queue.
2261- */
2262- static int
2263- xfs_buf_delwri_submit_buffers (
2264- struct list_head * buffer_list ,
2265- struct list_head * wait_list )
2255+ static bool
2256+ xfs_buf_delwri_submit_prep (
2257+ struct xfs_buf * bp )
22662258{
2267- struct xfs_buf * bp , * n ;
2268- int pinned = 0 ;
2269- struct blk_plug plug ;
2270-
2271- list_sort (NULL , buffer_list , xfs_buf_cmp );
2272-
2273- blk_start_plug (& plug );
2274- list_for_each_entry_safe (bp , n , buffer_list , b_list ) {
2275- if (!wait_list ) {
2276- if (!xfs_buf_trylock (bp ))
2277- continue ;
2278- if (xfs_buf_ispinned (bp )) {
2279- xfs_buf_unlock (bp );
2280- pinned ++ ;
2281- continue ;
2282- }
2283- } else {
2284- xfs_buf_lock (bp );
2285- }
2286-
2287- /*
2288- * Someone else might have written the buffer synchronously or
2289- * marked it stale in the meantime. In that case only the
2290- * _XBF_DELWRI_Q flag got cleared, and we have to drop the
2291- * reference and remove it from the list here.
2292- */
2293- if (!(bp -> b_flags & _XBF_DELWRI_Q )) {
2294- xfs_buf_list_del (bp );
2295- xfs_buf_relse (bp );
2296- continue ;
2297- }
2298-
2299- trace_xfs_buf_delwri_split (bp , _RET_IP_ );
2300-
2301- /*
2302- * If we have a wait list, each buffer (and associated delwri
2303- * queue reference) transfers to it and is submitted
2304- * synchronously. Otherwise, drop the buffer from the delwri
2305- * queue and submit async.
2306- */
2307- bp -> b_flags &= ~_XBF_DELWRI_Q ;
2308- bp -> b_flags |= XBF_WRITE ;
2309- if (wait_list ) {
2310- bp -> b_flags &= ~XBF_ASYNC ;
2311- list_move_tail (& bp -> b_list , wait_list );
2312- } else {
2313- bp -> b_flags |= XBF_ASYNC ;
2314- xfs_buf_list_del (bp );
2315- }
2316- xfs_buf_submit (bp );
2259+ /*
2260+ * Someone else might have written the buffer synchronously or marked it
2261+ * stale in the meantime. In that case only the _XBF_DELWRI_Q flag got
2262+ * cleared, and we have to drop the reference and remove it from the
2263+ * list here.
2264+ */
2265+ if (!(bp -> b_flags & _XBF_DELWRI_Q )) {
2266+ xfs_buf_list_del (bp );
2267+ xfs_buf_relse (bp );
2268+ return false;
23172269 }
2318- blk_finish_plug (& plug );
23192270
2320- return pinned ;
2271+ trace_xfs_buf_delwri_split (bp , _RET_IP_ );
2272+ bp -> b_flags &= ~_XBF_DELWRI_Q ;
2273+ bp -> b_flags |= XBF_WRITE ;
2274+ return true;
23212275}
23222276
23232277/*
@@ -2340,7 +2294,30 @@ int
23402294xfs_buf_delwri_submit_nowait (
23412295 struct list_head * buffer_list )
23422296{
2343- return xfs_buf_delwri_submit_buffers (buffer_list , NULL );
2297+ struct xfs_buf * bp , * n ;
2298+ int pinned = 0 ;
2299+ struct blk_plug plug ;
2300+
2301+ list_sort (NULL , buffer_list , xfs_buf_cmp );
2302+
2303+ blk_start_plug (& plug );
2304+ list_for_each_entry_safe (bp , n , buffer_list , b_list ) {
2305+ if (!xfs_buf_trylock (bp ))
2306+ continue ;
2307+ if (xfs_buf_ispinned (bp )) {
2308+ xfs_buf_unlock (bp );
2309+ pinned ++ ;
2310+ continue ;
2311+ }
2312+ if (!xfs_buf_delwri_submit_prep (bp ))
2313+ continue ;
2314+ bp -> b_flags |= XBF_ASYNC ;
2315+ xfs_buf_list_del (bp );
2316+ xfs_buf_submit (bp );
2317+ }
2318+ blk_finish_plug (& plug );
2319+
2320+ return pinned ;
23442321}
23452322
23462323/*
@@ -2357,9 +2334,21 @@ xfs_buf_delwri_submit(
23572334{
23582335 LIST_HEAD (wait_list );
23592336 int error = 0 , error2 ;
2360- struct xfs_buf * bp ;
2337+ struct xfs_buf * bp , * n ;
2338+ struct blk_plug plug ;
23612339
2362- xfs_buf_delwri_submit_buffers (buffer_list , & wait_list );
2340+ list_sort (NULL , buffer_list , xfs_buf_cmp );
2341+
2342+ blk_start_plug (& plug );
2343+ list_for_each_entry_safe (bp , n , buffer_list , b_list ) {
2344+ xfs_buf_lock (bp );
2345+ if (!xfs_buf_delwri_submit_prep (bp ))
2346+ continue ;
2347+ bp -> b_flags &= ~XBF_ASYNC ;
2348+ list_move_tail (& bp -> b_list , & wait_list );
2349+ xfs_buf_submit (bp );
2350+ }
2351+ blk_finish_plug (& plug );
23632352
23642353 /* Wait for IO to complete. */
23652354 while (!list_empty (& wait_list )) {
0 commit comments