@@ -72,7 +72,7 @@ unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct)
7272 *
7373 */
7474
75- void gfs2_remove_from_ail (struct gfs2_bufdata * bd )
75+ static void gfs2_remove_from_ail (struct gfs2_bufdata * bd )
7676{
7777 bd -> bd_tr = NULL ;
7878 list_del_init (& bd -> bd_ail_st_list );
@@ -467,8 +467,9 @@ void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks)
467467{
468468 atomic_add (blks , & sdp -> sd_log_blks_free );
469469 trace_gfs2_log_blocks (sdp , blks );
470- gfs2_assert_withdraw (sdp , atomic_read (& sdp -> sd_log_blks_free ) <=
471- sdp -> sd_jdesc -> jd_blocks );
470+ gfs2_assert_withdraw (sdp , !sdp -> sd_jdesc ||
471+ atomic_read (& sdp -> sd_log_blks_free ) <=
472+ sdp -> sd_jdesc -> jd_blocks );
472473 if (atomic_read (& sdp -> sd_log_blks_needed ))
473474 wake_up (& sdp -> sd_log_waitq );
474475}
@@ -800,9 +801,9 @@ void gfs2_flush_revokes(struct gfs2_sbd *sdp)
800801 /* number of revokes we still have room for */
801802 unsigned int max_revokes = atomic_read (& sdp -> sd_log_revokes_available );
802803
803- gfs2_log_lock ( sdp );
804+ spin_lock ( & sdp -> sd_log_lock );
804805 gfs2_ail1_empty (sdp , max_revokes );
805- gfs2_log_unlock ( sdp );
806+ spin_unlock ( & sdp -> sd_log_lock );
806807}
807808
808809/**
@@ -983,57 +984,97 @@ static void empty_ail1_list(struct gfs2_sbd *sdp)
983984 }
984985}
985986
987+ static void gfs2_trans_drain_list (struct gfs2_sbd * sdp , struct list_head * list )
988+ {
989+ struct gfs2_bufdata * bd ;
990+
991+ while (!list_empty (list )) {
992+ bd = list_first_entry (list , struct gfs2_bufdata , bd_list );
993+ struct buffer_head * bh = bd -> bd_bh ;
994+
995+ WARN_ON_ONCE (!buffer_pinned (bh ));
996+ clear_buffer_pinned (bh );
997+ trace_gfs2_pin (bd , 0 );
998+ atomic_dec (& sdp -> sd_log_pinned );
999+ list_del_init (& bd -> bd_list );
1000+ brelse (bh );
1001+ }
1002+ }
1003+
9861004/**
987- * trans_drain - drain the buf and databuf queue for a failed transaction
1005+ * gfs2_trans_drain - drain the buf and databuf queue for a failed transaction
1006+ * @sdp: the filesystem
9881007 * @tr: the transaction to drain
9891008 *
9901009 * When this is called, we're taking an error exit for a log write that failed
9911010 * but since we bypassed the after_commit functions, we need to remove the
9921011 * items from the buf and databuf queue.
9931012 */
994- static void trans_drain ( struct gfs2_trans * tr )
1013+ static void gfs2_trans_drain ( struct gfs2_sbd * sdp , struct gfs2_trans * tr )
9951014{
996- struct gfs2_bufdata * bd ;
997- struct list_head * head ;
998-
9991015 if (!tr )
10001016 return ;
1017+ gfs2_trans_drain_list (sdp , & tr -> tr_buf );
1018+ gfs2_trans_drain_list (sdp , & tr -> tr_databuf );
1019+ }
10011020
1002- head = & tr -> tr_buf ;
1003- while (!list_empty (head )) {
1004- bd = list_first_entry (head , struct gfs2_bufdata , bd_list );
1021+ void gfs2_remove_from_journal (struct buffer_head * bh , int meta )
1022+ {
1023+ struct address_space * mapping = bh -> b_folio -> mapping ;
1024+ struct gfs2_sbd * sdp = gfs2_mapping2sbd (mapping );
1025+ struct gfs2_bufdata * bd = bh -> b_private ;
1026+ struct gfs2_trans * tr = current -> journal_info ;
1027+ int was_pinned = 0 ;
1028+
1029+ if (test_clear_buffer_pinned (bh )) {
1030+ trace_gfs2_pin (bd , 0 );
1031+ atomic_dec (& sdp -> sd_log_pinned );
10051032 list_del_init (& bd -> bd_list );
1006- if (!list_empty (& bd -> bd_ail_st_list ))
1007- gfs2_remove_from_ail (bd );
1008- kmem_cache_free (gfs2_bufdata_cachep , bd );
1033+ if (tr ) {
1034+ if (meta == REMOVE_META )
1035+ tr -> tr_num_buf_rm ++ ;
1036+ else
1037+ tr -> tr_num_databuf_rm ++ ;
1038+ set_bit (TR_TOUCHED , & tr -> tr_flags );
1039+ }
1040+ was_pinned = 1 ;
1041+ brelse (bh );
10091042 }
1010- head = & tr -> tr_databuf ;
1011- while (!list_empty (head )) {
1012- bd = list_first_entry (head , struct gfs2_bufdata , bd_list );
1013- list_del_init (& bd -> bd_list );
1014- if (!list_empty (& bd -> bd_ail_st_list ))
1043+ if (bd ) {
1044+ if (bd -> bd_tr ) {
1045+ if (tr )
1046+ gfs2_trans_add_revoke (sdp , bd );
1047+ else
1048+ gfs2_remove_from_ail (bd );
1049+ } else if (was_pinned ) {
1050+ bh -> b_private = NULL ;
1051+ kmem_cache_free (gfs2_bufdata_cachep , bd );
1052+ } else if (!list_empty (& bd -> bd_ail_st_list ) &&
1053+ !list_empty (& bd -> bd_ail_gl_list )) {
10151054 gfs2_remove_from_ail (bd );
1016- kmem_cache_free ( gfs2_bufdata_cachep , bd );
1055+ }
10171056 }
1057+ clear_buffer_dirty (bh );
1058+ clear_buffer_uptodate (bh );
10181059}
10191060
10201061/**
1021- * gfs2_log_flush - flush incore transaction(s)
1062+ * __gfs2_log_flush - flush incore transaction(s)
10221063 * @sdp: The filesystem
10231064 * @gl: The glock structure to flush. If NULL, flush the whole incore log
10241065 * @flags: The log header flags: GFS2_LOG_HEAD_FLUSH_* and debug flags
10251066 *
10261067 */
10271068
1028- void gfs2_log_flush (struct gfs2_sbd * sdp , struct gfs2_glock * gl , u32 flags )
1069+ static void __gfs2_log_flush (struct gfs2_sbd * sdp , struct gfs2_glock * gl ,
1070+ u32 flags )
10291071{
10301072 struct gfs2_trans * tr = NULL ;
10311073 unsigned int reserved_blocks = 0 , used_blocks = 0 ;
10321074 bool frozen = test_bit (SDF_FROZEN , & sdp -> sd_flags );
10331075 unsigned int first_log_head ;
10341076 unsigned int reserved_revokes = 0 ;
10351077
1036- down_write (& sdp -> sd_log_flush_lock );
10371078 trace_gfs2_log_flush (sdp , 1 , flags );
10381079
10391080repeat :
@@ -1110,7 +1151,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
11101151 goto out_withdraw ;
11111152 lops_after_commit (sdp , tr );
11121153
1113- gfs2_log_lock ( sdp );
1154+ spin_lock ( & sdp -> sd_log_lock );
11141155 sdp -> sd_log_blks_reserved = 0 ;
11151156
11161157 spin_lock (& sdp -> sd_ail_lock );
@@ -1119,7 +1160,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
11191160 tr = NULL ;
11201161 }
11211162 spin_unlock (& sdp -> sd_ail_lock );
1122- gfs2_log_unlock ( sdp );
1163+ spin_unlock ( & sdp -> sd_log_lock );
11231164
11241165 if (!(flags & GFS2_LOG_HEAD_FLUSH_NORMAL )) {
11251166 if (!sdp -> sd_log_idle ) {
@@ -1145,13 +1186,16 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
11451186 gfs2_assert_withdraw (sdp , used_blocks < reserved_blocks );
11461187 gfs2_log_release (sdp , reserved_blocks - used_blocks );
11471188 }
1148- up_write (& sdp -> sd_log_flush_lock );
11491189 gfs2_trans_free (sdp , tr );
11501190 trace_gfs2_log_flush (sdp , 0 , flags );
11511191 return ;
11521192
11531193out_withdraw :
1154- trans_drain (tr );
1194+ if (sdp -> sd_jdesc -> jd_log_bio ) {
1195+ bio_io_error (sdp -> sd_jdesc -> jd_log_bio );
1196+ sdp -> sd_jdesc -> jd_log_bio = NULL ;
1197+ }
1198+ gfs2_trans_drain (sdp , tr );
11551199 /**
11561200 * If the tr_list is empty, we're withdrawing during a log
11571201 * flush that targets a transaction, but the transaction was
@@ -1166,6 +1210,13 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
11661210 goto out_end ;
11671211}
11681212
1213+ void gfs2_log_flush (struct gfs2_sbd * sdp , struct gfs2_glock * gl , u32 flags )
1214+ {
1215+ down_write (& sdp -> sd_log_flush_lock );
1216+ __gfs2_log_flush (sdp , gl , flags );
1217+ up_write (& sdp -> sd_log_flush_lock );
1218+ }
1219+
11691220/**
11701221 * gfs2_merge_trans - Merge a new transaction into a cached transaction
11711222 * @sdp: the filesystem
@@ -1200,7 +1251,7 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
12001251 unsigned int unused ;
12011252 unsigned int maxres ;
12021253
1203- gfs2_log_lock ( sdp );
1254+ spin_lock ( & sdp -> sd_log_lock );
12041255
12051256 if (sdp -> sd_log_tr ) {
12061257 gfs2_merge_trans (sdp , tr );
@@ -1218,7 +1269,7 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
12181269 gfs2_log_release (sdp , unused );
12191270 sdp -> sd_log_blks_reserved = reserved ;
12201271
1221- gfs2_log_unlock ( sdp );
1272+ spin_unlock ( & sdp -> sd_log_lock );
12221273}
12231274
12241275static inline int gfs2_jrnl_flush_reqd (struct gfs2_sbd * sdp )
@@ -1297,19 +1348,25 @@ int gfs2_logd(void *data)
12971348 break ;
12981349
12991350 if (gfs2_jrnl_flush_reqd (sdp ) || t == 0 ) {
1351+ down_write (& sdp -> sd_log_flush_lock );
13001352 gfs2_ail1_empty (sdp , 0 );
1301- gfs2_log_flush (sdp , NULL , GFS2_LOG_HEAD_FLUSH_NORMAL |
1302- GFS2_LFC_LOGD_JFLUSH_REQD );
1353+ __gfs2_log_flush (sdp , NULL ,
1354+ GFS2_LOG_HEAD_FLUSH_NORMAL |
1355+ GFS2_LFC_LOGD_JFLUSH_REQD );
1356+ up_write (& sdp -> sd_log_flush_lock );
13031357 }
13041358
13051359 if (test_bit (SDF_FORCE_AIL_FLUSH , & sdp -> sd_flags ) ||
13061360 gfs2_ail_flush_reqd (sdp )) {
13071361 clear_bit (SDF_FORCE_AIL_FLUSH , & sdp -> sd_flags );
1362+ down_write (& sdp -> sd_log_flush_lock );
13081363 gfs2_ail1_start (sdp );
13091364 gfs2_ail1_wait (sdp );
13101365 gfs2_ail1_empty (sdp , 0 );
1311- gfs2_log_flush (sdp , NULL , GFS2_LOG_HEAD_FLUSH_NORMAL |
1312- GFS2_LFC_LOGD_AIL_FLUSH_REQD );
1366+ __gfs2_log_flush (sdp , NULL ,
1367+ GFS2_LOG_HEAD_FLUSH_NORMAL |
1368+ GFS2_LFC_LOGD_AIL_FLUSH_REQD );
1369+ up_write (& sdp -> sd_log_flush_lock );
13131370 }
13141371
13151372 t = gfs2_tune_get (sdp , gt_logd_secs ) * HZ ;
0 commit comments