@@ -299,20 +299,17 @@ static void gfs2_ail1_wait(struct gfs2_sbd *sdp)
299
299
}
300
300
301
301
/**
302
- * gfs2_ail2_empty_one - Check whether or not a trans in the AIL has been synced
303
- * @sdp: the filesystem
304
- * @ai: the AIL entry
305
- *
302
+ * gfs2_ail_empty_tr - empty one of the ail lists for a transaction
306
303
*/
307
304
308
- static void gfs2_ail2_empty_one (struct gfs2_sbd * sdp , struct gfs2_trans * tr )
305
+ static void gfs2_ail_empty_tr (struct gfs2_sbd * sdp , struct gfs2_trans * tr ,
306
+ struct list_head * head )
309
307
{
310
- struct list_head * head = & tr -> tr_ail2_list ;
311
308
struct gfs2_bufdata * bd ;
312
309
313
310
while (!list_empty (head )) {
314
- bd = list_entry (head -> prev , struct gfs2_bufdata ,
315
- bd_ail_st_list );
311
+ bd = list_first_entry (head , struct gfs2_bufdata ,
312
+ bd_ail_st_list );
316
313
gfs2_assert (sdp , bd -> bd_tr == tr );
317
314
gfs2_remove_from_ail (bd );
318
315
}
@@ -334,7 +331,7 @@ static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail)
334
331
if (!rm )
335
332
continue ;
336
333
337
- gfs2_ail2_empty_one (sdp , tr );
334
+ gfs2_ail_empty_tr (sdp , tr , & tr -> tr_ail2_list );
338
335
list_del (& tr -> tr_list );
339
336
gfs2_assert_warn (sdp , list_empty (& tr -> tr_ail1_list ));
340
337
gfs2_assert_warn (sdp , list_empty (& tr -> tr_ail2_list ));
@@ -801,6 +798,40 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
801
798
log_pull_tail (sdp , tail );
802
799
}
803
800
801
+ /**
802
+ * ail_drain - drain the ail lists after a withdraw
803
+ * @sdp: Pointer to GFS2 superblock
804
+ */
805
+ static void ail_drain (struct gfs2_sbd * sdp )
806
+ {
807
+ struct gfs2_trans * tr ;
808
+
809
+ spin_lock (& sdp -> sd_ail_lock );
810
+ /*
811
+ * For transactions on the sd_ail1_list we need to drain both the
812
+ * ail1 and ail2 lists. That's because function gfs2_ail1_start_one
813
+ * (temporarily) moves items from its tr_ail1 list to tr_ail2 list
814
+ * before revokes are sent for that block. Items on the sd_ail2_list
815
+ * should have already gotten beyond that point, so no need.
816
+ */
817
+ while (!list_empty (& sdp -> sd_ail1_list )) {
818
+ tr = list_first_entry (& sdp -> sd_ail1_list , struct gfs2_trans ,
819
+ tr_list );
820
+ gfs2_ail_empty_tr (sdp , tr , & tr -> tr_ail1_list );
821
+ gfs2_ail_empty_tr (sdp , tr , & tr -> tr_ail2_list );
822
+ list_del (& tr -> tr_list );
823
+ kfree (tr );
824
+ }
825
+ while (!list_empty (& sdp -> sd_ail2_list )) {
826
+ tr = list_first_entry (& sdp -> sd_ail2_list , struct gfs2_trans ,
827
+ tr_list );
828
+ gfs2_ail_empty_tr (sdp , tr , & tr -> tr_ail2_list );
829
+ list_del (& tr -> tr_list );
830
+ kfree (tr );
831
+ }
832
+ spin_unlock (& sdp -> sd_ail_lock );
833
+ }
834
+
804
835
/**
805
836
* gfs2_log_flush - flush incore transaction(s)
806
837
* @sdp: the filesystem
@@ -811,11 +842,18 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
811
842
812
843
void gfs2_log_flush (struct gfs2_sbd * sdp , struct gfs2_glock * gl , u32 flags )
813
844
{
814
- struct gfs2_trans * tr ;
845
+ struct gfs2_trans * tr = NULL ;
815
846
enum gfs2_freeze_state state = atomic_read (& sdp -> sd_freeze_state );
816
847
817
848
down_write (& sdp -> sd_log_flush_lock );
818
849
850
+ /*
851
+ * Do this check while holding the log_flush_lock to prevent new
852
+ * buffers from being added to the ail via gfs2_pin()
853
+ */
854
+ if (gfs2_withdrawn (sdp ))
855
+ goto out ;
856
+
819
857
/* Log might have been flushed while we waited for the flush lock */
820
858
if (gl && !test_bit (GLF_LFLUSH , & gl -> gl_flags )) {
821
859
up_write (& sdp -> sd_log_flush_lock );
@@ -843,8 +881,14 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
843
881
sdp -> sd_log_num_revoke == sdp -> sd_log_committed_revoke );
844
882
845
883
gfs2_ordered_write (sdp );
884
+ if (gfs2_withdrawn (sdp ))
885
+ goto out ;
846
886
lops_before_commit (sdp , tr );
887
+ if (gfs2_withdrawn (sdp ))
888
+ goto out ;
847
889
gfs2_log_submit_bio (& sdp -> sd_log_bio , REQ_OP_WRITE );
890
+ if (gfs2_withdrawn (sdp ))
891
+ goto out ;
848
892
849
893
if (sdp -> sd_log_head != sdp -> sd_log_flush_head ) {
850
894
log_flush_wait (sdp );
@@ -854,6 +898,8 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
854
898
trace_gfs2_log_blocks (sdp , -1 );
855
899
log_write_header (sdp , flags );
856
900
}
901
+ if (gfs2_withdrawn (sdp ))
902
+ goto out ;
857
903
lops_after_commit (sdp , tr );
858
904
859
905
gfs2_log_lock (sdp );
@@ -892,6 +938,11 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
892
938
}
893
939
894
940
out :
941
+ if (gfs2_withdrawn (sdp )) {
942
+ ail_drain (sdp ); /* frees all transactions */
943
+ tr = NULL ;
944
+ }
945
+
895
946
trace_gfs2_log_flush (sdp , 0 , flags );
896
947
up_write (& sdp -> sd_log_flush_lock );
897
948
0 commit comments