@@ -277,6 +277,10 @@ static int bch2_btree_write_buffer_flush_locked(struct btree_trans *trans)
277
277
bool accounting_replay_done = test_bit (BCH_FS_accounting_replay_done , & c -> flags );
278
278
int ret = 0 ;
279
279
280
+ ret = bch2_journal_error (& c -> journal );
281
+ if (ret )
282
+ return ret ;
283
+
280
284
bch2_trans_unlock (trans );
281
285
bch2_trans_begin (trans );
282
286
@@ -491,7 +495,8 @@ static int fetch_wb_keys_from_journal(struct bch_fs *c, u64 seq)
491
495
return ret ;
492
496
}
493
497
494
- static int btree_write_buffer_flush_seq (struct btree_trans * trans , u64 seq )
498
+ static int btree_write_buffer_flush_seq (struct btree_trans * trans , u64 seq ,
499
+ bool * did_work )
495
500
{
496
501
struct bch_fs * c = trans -> c ;
497
502
struct btree_write_buffer * wb = & c -> btree_write_buffer ;
@@ -502,6 +507,8 @@ static int btree_write_buffer_flush_seq(struct btree_trans *trans, u64 seq)
502
507
503
508
fetch_from_journal_err = fetch_wb_keys_from_journal (c , seq );
504
509
510
+ * did_work |= wb -> inc .keys .nr || wb -> flushing .keys .nr ;
511
+
505
512
/*
506
513
* On memory allocation failure, bch2_btree_write_buffer_flush_locked()
507
514
* is not guaranteed to empty wb->inc:
@@ -521,17 +528,34 @@ static int bch2_btree_write_buffer_journal_flush(struct journal *j,
521
528
struct journal_entry_pin * _pin , u64 seq )
522
529
{
523
530
struct bch_fs * c = container_of (j , struct bch_fs , journal );
531
+ bool did_work = false;
524
532
525
- return bch2_trans_run (c , btree_write_buffer_flush_seq (trans , seq ));
533
+ return bch2_trans_run (c , btree_write_buffer_flush_seq (trans , seq , & did_work ));
526
534
}
527
535
528
536
int bch2_btree_write_buffer_flush_sync (struct btree_trans * trans )
529
537
{
530
538
struct bch_fs * c = trans -> c ;
539
+ bool did_work = false;
531
540
532
541
trace_and_count (c , write_buffer_flush_sync , trans , _RET_IP_ );
533
542
534
- return btree_write_buffer_flush_seq (trans , journal_cur_seq (& c -> journal ));
543
+ return btree_write_buffer_flush_seq (trans , journal_cur_seq (& c -> journal ), & did_work );
544
+ }
545
+
546
+ /*
547
+ * The write buffer requires flushing when going RO: keys in the journal for the
548
+ * write buffer don't have a journal pin yet
549
+ */
550
+ bool bch2_btree_write_buffer_flush_going_ro (struct bch_fs * c )
551
+ {
552
+ if (bch2_journal_error (& c -> journal ))
553
+ return false;
554
+
555
+ bool did_work = false;
556
+ bch2_trans_run (c , btree_write_buffer_flush_seq (trans ,
557
+ journal_cur_seq (& c -> journal ), & did_work ));
558
+ return did_work ;
535
559
}
536
560
537
561
int bch2_btree_write_buffer_flush_nocheck_rw (struct btree_trans * trans )
0 commit comments