gfs2: some cleanups
Andreas Gruenbacher
maintainercover gfs2: some cleanups
Here are some code cleanups.
Andreas Gruenbacher (4):
gfs2: list_for_each_entry_safe conversion
gfs2: Remove unnecessary list heads
gfs2: gfs2_trans_remove_revoke cleanup
gfs2: gfs2_glock_remove_revoke cleanup
fs/gfs2/bmap.c | 5 ++--- fs/gfs2/glock.c | 7 ++----- fs/gfs2/glops.c | 3 +-- fs/gfs2/log.c | 35 +++++++++++++++-------------------- fs/gfs2/log.h | 2 +- fs/gfs2/lops.c | 30 ++++++++---------------------- fs/gfs2/quota.c | 5 ++--- fs/gfs2/recovery.c | 11 ++++------- fs/gfs2/super.c | 10 ++++------ fs/gfs2/trans.c | 16 +++++++--------- 10 files changed, 46 insertions(+), 78 deletions(-)
Signature · 1 line
2.56.1
Andreas Gruenbacher
maintainerPATCH 1/4 gfs2: list_for_each_entry_safe conversion
Replace the following list iterations that don't drop the list lock:
while (!list_empty(list)) {
entry = list_first_entry(list, type, field);
list_del(&entry->field);
}with the preferred equivalent form:
list_for_each_entry_safe(entry, tmp, list, field) {
list_del(&entry->field);
}--- fs/gfs2/bmap.c | 5 ++--- fs/gfs2/glock.c | 7 ++----- fs/gfs2/log.c | 21 +++++++-------------- fs/gfs2/lops.c | 20 ++++++-------------- fs/gfs2/quota.c | 5 ++--- fs/gfs2/recovery.c | 6 ++---- fs/gfs2/super.c | 10 ++++------ 7 files changed, 25 insertions(+), 49 deletions(-)
fs/gfs2/bmap.c +2 -3
@@ -2228,10 +2228,9 @@ int gfs2_file_dealloc(struct gfs2_inode *ip)void gfs2_free_journal_extents (struct gfs2_jdesc *jd) { -struct gfs2_journal_extent *jext; +struct gfs2_journal_extent *jext, *tmp; -while (!list_empty (&jd->extent_list)) { - jext = list_first_entry(&jd->extent_list, struct gfs2_journal_extent, list); +list_for_each_entry_safe (jext, tmp, &jd->extent_list, list) {list_del (&jext->list);kfree (jext); }
fs/gfs2/glock.c +2 -5
@@ -179,12 +179,9 @@ void gfs2_glock_free_later(struct gfs2_glock *gl) {static void gfs2_free_dead_glocks (struct gfs2_sbd *sdp) { -struct list_head *list = &sdp->sd_dead_glocks; - -while (!list_empty (list)) { -struct gfs2_glock *gl; +struct gfs2_glock *gl, *tmp; - gl = list_first_entry(list, struct gfs2_glock, gl_dead); +list_for_each_entry_safe (gl, tmp, &sdp->sd_dead_glocks, gl_dead) {list_del (&gl->gl_dead);__gfs2_glock_free (gl); }
fs/gfs2/log.c +7 -14
@@ -281,11 +281,9 @@ static void gfs2_log_update_head(struct gfs2_sbd *sdp)static void gfs2_ail_empty_tr (struct gfs2_sbd *sdp,struct gfs2_trans *tr,struct list_head *head) { -struct gfs2_bufdata *bd; +struct gfs2_bufdata *bd, *tmp; -while (!list_empty (head)) { - bd = list_first_entry(head, struct gfs2_bufdata, - bd_ail_st_list); +list_for_each_entry_safe (bd, tmp, head, bd_ail_st_list) {gfs2_assert (sdp, bd->bd_tr == tr);gfs2_remove_from_ail (bd); }
@@ -933,7 +931,7 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags)*/ void gfs2_ail_drain (struct gfs2_sbd *sdp) { -struct gfs2_trans *tr; +struct gfs2_trans *tr, *tmp;spin_lock (&sdp->sd_ail_lock);/*
@@ -943,17 +941,13 @@ void gfs2_ail_drain(struct gfs2_sbd *sdp)* before revokes are sent for that block. Items on the sd_ail2_list * should have already gotten beyond that point, so no need. */ -while (!list_empty (&sdp->sd_ail1_list)) { - tr = list_first_entry(&sdp->sd_ail1_list, struct gfs2_trans, - tr_list); +list_for_each_entry_safe (tr, tmp, &sdp->sd_ail1_list, tr_list) {gfs2_ail_empty_tr (sdp, tr, &tr->tr_ail1_list);gfs2_ail_empty_tr (sdp, tr, &tr->tr_ail2_list);list_del (&tr->tr_list);gfs2_trans_free (sdp, tr); } -while (!list_empty (&sdp->sd_ail2_list)) { - tr = list_first_entry(&sdp->sd_ail2_list, struct gfs2_trans, - tr_list); +list_for_each_entry_safe (tr, tmp, &sdp->sd_ail2_list, tr_list) {gfs2_ail_empty_tr (sdp, tr, &tr->tr_ail2_list);list_del (&tr->tr_list);gfs2_trans_free (sdp, tr);
@@ -989,10 +983,9 @@ static void empty_ail1_list(struct gfs2_sbd *sdp)static void gfs2_trans_drain_list (struct gfs2_sbd *sdp,struct list_head *list) { -struct gfs2_bufdata *bd; +struct gfs2_bufdata *bd, *tmp; -while (!list_empty (list)) { - bd = list_first_entry(list, struct gfs2_bufdata, bd_list); +list_for_each_entry_safe (bd, tmp, list, bd_list) {struct buffer_head *bh = bd->bd_bh;WARN_ON_ONCE (!buffer_pinned (bh));
fs/gfs2/lops.c +6 -14
@@ -726,15 +726,12 @@ static void buf_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)static void buf_lo_after_commit (struct gfs2_sbd *sdp,struct gfs2_trans *tr) { -struct list_head *head; -struct gfs2_bufdata *bd; +struct gfs2_bufdata *bd, *tmp;if (tr ==NULL )return ; - head = &tr->tr_buf; -while (!list_empty (head)) { - bd = list_first_entry(head, struct gfs2_bufdata, bd_list); +list_for_each_entry_safe (bd, tmp, &tr->tr_buf, bd_list) {list_del_init (&bd->bd_list);gfs2_unpin (sdp, bd->bd_bh, tr); }
@@ -889,12 +886,10 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)void gfs2_drain_revokes (struct gfs2_sbd *sdp) { -struct list_head *head = &sdp->sd_log_revokes; -struct gfs2_bufdata *bd; +struct gfs2_bufdata *bd, *tmp;struct gfs2_glock *gl; -while (!list_empty (head)) { - bd = list_first_entry(head, struct gfs2_bufdata, bd_list); +list_for_each_entry_safe (bd, tmp, &sdp->sd_log_revokes, bd_list) {list_del_init (&bd->bd_list); gl = bd->bd_gl;gfs2_glock_remove_revoke (gl);
@@ -1070,15 +1065,12 @@ static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass)static void databuf_lo_after_commit (struct gfs2_sbd *sdp,struct gfs2_trans *tr) { -struct list_head *head; -struct gfs2_bufdata *bd; +struct gfs2_bufdata *bd, *tmp;if (tr ==NULL )return ; - head = &tr->tr_databuf; -while (!list_empty (head)) { - bd = list_first_entry(head, struct gfs2_bufdata, bd_list); +list_for_each_entry_safe (bd, tmp, &tr->tr_databuf, bd_list) {list_del_init (&bd->bd_list);gfs2_unpin (sdp, bd->bd_bh, tr); }
fs/gfs2/quota.c +2 -3
@@ -137,10 +137,9 @@ static void gfs2_qd_dispose(struct gfs2_quota_data *qd)static void gfs2_qd_list_dispose (struct list_head *list) { -struct gfs2_quota_data *qd; +struct gfs2_quota_data *qd, *tmp; -while (!list_empty (list)) { - qd = list_first_entry(list, struct gfs2_quota_data, qd_lru); +list_for_each_entry_safe (qd, tmp, list, qd_lru) {list_del (&qd->qd_lru);gfs2_qd_dispose (qd);
fs/gfs2/recovery.c +2 -4
@@ -106,11 +106,9 @@ int gfs2_revoke_check(struct gfs2_jdesc *jd, u64 blkno, unsigned int where)void gfs2_revoke_clean (struct gfs2_jdesc *jd) { -struct list_head *head = &jd->jd_revoke_list; -struct gfs2_revoke_replay *rr; +struct gfs2_revoke_replay *rr, *tmp; -while (!list_empty (head)) { - rr = list_first_entry(head, struct gfs2_revoke_replay, rr_list); +list_for_each_entry_safe (rr, tmp, &jd->jd_revoke_list, rr_list) {list_del (&rr->rr_list);kfree (rr); }
fs/gfs2/super.c +4 -6
@@ -59,7 +59,7 @@ enum evict_behavior {void gfs2_jindex_free (struct gfs2_sbd *sdp) {struct list_head list; -struct gfs2_jdesc *jd; +struct gfs2_jdesc *jd, *tmp;spin_lock (&sdp->sd_jindex_spin);list_add (&list, &sdp->sd_jindex_list);
@@ -71,8 +71,7 @@ void gfs2_jindex_free(struct gfs2_sbd *sdp) sdp->sd_jdesc =NULL ;up_write (&sdp->sd_log_flush_lock); -while (!list_empty (&list)) { - jd = list_first_entry(&list, struct gfs2_jdesc, jd_list); +list_for_each_entry_safe (jd, tmp, &list, jd_list) {BUG_ON (jd->jd_log_bio);gfs2_free_journal_extents (jd);list_del (&jd->jd_list);
@@ -324,7 +323,7 @@ struct lfcc {static int gfs2_lock_fs_check_clean (struct gfs2_sbd *sdp) {struct gfs2_jdesc *jd; -struct lfcc *lfcc; +struct lfcc *lfcc, *tmp;LIST_HEAD (list);struct gfs2_log_header_host lh;int error, error2;
@@ -381,8 +380,7 @@ static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp)gfs2_assert_withdraw (sdp, !error2); out: -while (!list_empty (&list)) { - lfcc = list_first_entry(&list, struct lfcc, list); +list_for_each_entry_safe (lfcc, tmp, &list, list) {list_del (&lfcc->list);gfs2_glock_dq_uninit (&lfcc->gh);kfree (lfcc);
Signature · 1 line
2.56.1
Andreas Gruenbacher
maintainerPATCH 2/4 gfs2: Remove unnecessary list heads
In reply to Andreas GruenbacherRemove a few list_head pointers: they don't provide any advantages and make the code more difficult to follow.
--- fs/gfs2/glops.c | 3 +-- fs/gfs2/log.c | 8 +++----- fs/gfs2/lops.c | 3 +-- fs/gfs2/recovery.c | 5 ++--- 4 files changed, 7 insertions(+), 12 deletions(-)
fs/gfs2/glops.c +1 -2
@@ -59,14 +59,13 @@ static void __gfs2_ail_flush(struct gfs2_glock *gl, bool fsync, unsigned int nr_revokes) {struct gfs2_sbd *sdp =glock_sbd (gl); -struct list_head *head = &gl->gl_ail_list;struct gfs2_bufdata *bd, *tmp;struct buffer_head *bh;const unsigned long b_state = (1UL << BH_Dirty)|(1UL << BH_Pinned)|(1UL << BH_Lock);spin_lock (&sdp->sd_log_lock);spin_lock (&sdp->sd_ail_lock); -list_for_each_entry_safe_reverse (bd, tmp, head, bd_ail_gl_list) { +list_for_each_entry_safe_reverse (bd, tmp, &gl->gl_ail_list, bd_ail_gl_list) {if (nr_revokes ==0 )break ; bh = bd->bd_bh;
fs/gfs2/log.c +3 -5
@@ -198,7 +198,6 @@ static void dump_ail_list(struct gfs2_sbd *sdp)void gfs2_ail1_flush (struct gfs2_sbd *sdp,struct writeback_control *wbc) { -struct list_head *head = &sdp->sd_ail1_list;struct gfs2_trans *tr;struct blk_plug plug;int ret;
@@ -215,7 +214,7 @@ void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc)dump_ail_list (sdp); goto out; } -list_for_each_entry_reverse (tr, head, tr_list) { +list_for_each_entry_reverse (tr, &sdp->sd_ail1_list, tr_list) {if (wbc->nr_to_write <=0 )break ; ret =gfs2_ail1_start_one (sdp, wbc, tr, &plug);
@@ -403,18 +402,17 @@ static void __ail2_empty(struct gfs2_sbd *sdp, struct gfs2_trans *tr)static void ail2_empty (struct gfs2_sbd *sdp,unsigned int new_tail) { -struct list_head *ail2_list = &sdp->sd_ail2_list;unsigned int old_tail = sdp->sd_log_tail;struct gfs2_trans *tr, *safe;spin_lock (&sdp->sd_ail_lock);if (old_tail <= new_tail) { -list_for_each_entry_safe (tr, safe, ail2_list, tr_list) { +list_for_each_entry_safe (tr, safe, &sdp->sd_ail2_list, tr_list) {if (old_tail <= tr->tr_first && tr->tr_first < new_tail)__ail2_empty (sdp, tr); } }else { -list_for_each_entry_safe (tr, safe, ail2_list, tr_list) { +list_for_each_entry_safe (tr, safe, &sdp->sd_ail2_list, tr_list) {if (old_tail <= tr->tr_first || tr->tr_first < new_tail)__ail2_empty (sdp, tr); }
fs/gfs2/lops.c +1 -2
@@ -849,7 +849,6 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) {struct gfs2_meta_header *mh;unsigned int offset; -struct list_head *head = &sdp->sd_log_revokes;struct gfs2_bufdata *bd;struct page *page;unsigned int length;
@@ -862,7 +861,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) page =gfs2_get_log_desc (sdp,GFS2_LOG_DESC_REVOKE , length, sdp->sd_log_num_revoke); offset =sizeof (struct gfs2_log_descriptor ); -list_for_each_entry (bd, head, bd_list) { +list_for_each_entry (bd, &sdp->sd_log_revokes, bd_list) { sdp->sd_log_num_revoke--;if (offset +sizeof (u64) > sdp->sd_sb.sb_bsize) {
fs/gfs2/recovery.c +2 -3
@@ -55,10 +55,9 @@ int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk,int gfs2_revoke_add (struct gfs2_jdesc *jd,u64 blkno,unsigned int where) { -struct list_head *head = &jd->jd_revoke_list;struct gfs2_revoke_replay *rr =NULL , *iter; -list_for_each_entry (iter, head, rr_list) { +list_for_each_entry (iter, &jd->jd_revoke_list, rr_list) {if (iter->rr_blkno == blkno) { rr = iter;break ;
@@ -76,7 +75,7 @@ int gfs2_revoke_add(struct gfs2_jdesc *jd, u64 blkno, unsigned int where) rr->rr_blkno = blkno; rr->rr_where = where; -list_add (&rr->rr_list, head); +list_add (&rr->rr_list, &jd->jd_revoke_list);return 1 ; }
Signature · 1 line
2.56.1
Andreas Gruenbacher
maintainerPATCH 3/4 gfs2: gfs2_trans_remove_revoke cleanup
In reply to Andreas GruenbacherCount the number of revokes removed and update the counters outside of the revokes loop.
Use the revokes count to eliminate 'n'.
--- fs/gfs2/trans.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
fs/gfs2/trans.c +6 -5
@@ -330,22 +330,23 @@ void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)void gfs2_trans_remove_revoke (struct gfs2_sbd *sdp,u64 blkno,unsigned int len) {struct gfs2_bufdata *bd, *tmp; -unsigned int n = len; +unsigned int revokes =0 ;spin_lock (&sdp->sd_log_lock);list_for_each_entry_safe (bd, tmp, &sdp->sd_log_revokes, bd_list) {if ((bd->bd_blkno >= blkno) && (bd->bd_blkno < (blkno + len))) {list_del_init (&bd->bd_list); -gfs2_assert_withdraw (sdp, sdp->sd_log_num_revoke); - sdp->sd_log_num_revoke--;if (bd->bd_gl)gfs2_glock_remove_revoke (bd->bd_gl);kmem_cache_free (gfs2_bufdata_cachep, bd); -gfs2_log_release_revokes (sdp,1 ); -if (--n ==0 ) + revokes++; +if (revokes == len)break ; } } +gfs2_assert_withdraw (sdp, sdp->sd_log_num_revoke >= revokes); + sdp->sd_log_num_revoke -= revokes; +gfs2_log_release_revokes (sdp, revokes);spin_unlock (&sdp->sd_log_lock); }
Signature · 1 line
2.56.1
Andreas Gruenbacher
maintainerPATCH 4/4 gfs2: gfs2_glock_remove_revoke cleanup
In reply to Andreas GruenbacherPass a bufdata pointer to gfs2_glock_remove_revoke() instead of a glock. Unlink and free the bufdata object inside of gfs2_glock_remove_revoke().
In gfs2_trans_remove_revoke(), bd->bd_gl is guaranteed to be properly initialized and there is no need for double checking.
--- fs/gfs2/log.c | 6 +++++- fs/gfs2/log.h | 2 +- fs/gfs2/lops.c | 9 ++------- fs/gfs2/trans.c | 5 +---- 4 files changed, 9 insertions(+), 13 deletions(-)
fs/gfs2/log.c +5 -1
@@ -775,12 +775,16 @@ void gfs2_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)list_add (&bd->bd_list, &sdp->sd_log_revokes); } -void gfs2_glock_remove_revoke (struct gfs2_glock *gl) +void gfs2_glock_remove_revoke (struct gfs2_bufdata *bd) { +struct gfs2_glock *gl = bd->bd_gl; + +list_del_init (&bd->bd_list);if (atomic_dec_and_test (&gl->gl_revokes)) {clear_bit (GLF_LFLUSH , &gl->gl_flags);gfs2_glock_put_async (gl); } +kmem_cache_free (gfs2_bufdata_cachep, bd); }/**
fs/gfs2/log.h +1 -1
@@ -56,7 +56,7 @@ void log_flush_wait(struct gfs2_sbd *sdp);int gfs2_logd (void *data);void gfs2_add_revoke (struct gfs2_sbd *sdp,struct gfs2_bufdata *bd); -void gfs2_glock_remove_revoke (struct gfs2_glock *gl); +void gfs2_glock_remove_revoke (struct gfs2_bufdata *bd);void gfs2_flush_revokes (struct gfs2_sbd *sdp);void gfs2_ail_drain (struct gfs2_sbd *sdp);
fs/gfs2/lops.c +2 -7
@@ -886,14 +886,9 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)void gfs2_drain_revokes (struct gfs2_sbd *sdp) {struct gfs2_bufdata *bd, *tmp; -struct gfs2_glock *gl; -list_for_each_entry_safe (bd, tmp, &sdp->sd_log_revokes, bd_list) { -list_del_init (&bd->bd_list); - gl = bd->bd_gl; -gfs2_glock_remove_revoke (gl); -kmem_cache_free (gfs2_bufdata_cachep, bd); - } +list_for_each_entry_safe (bd, tmp, &sdp->sd_log_revokes, bd_list) +gfs2_glock_remove_revoke (bd); }static void revoke_lo_after_commit (struct gfs2_sbd *sdp,struct gfs2_trans *tr)
fs/gfs2/trans.c +1 -4
@@ -335,10 +335,7 @@ void gfs2_trans_remove_revoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len)spin_lock (&sdp->sd_log_lock);list_for_each_entry_safe (bd, tmp, &sdp->sd_log_revokes, bd_list) {if ((bd->bd_blkno >= blkno) && (bd->bd_blkno < (blkno + len))) { -list_del_init (&bd->bd_list); -if (bd->bd_gl) -gfs2_glock_remove_revoke (bd->bd_gl); -kmem_cache_free (gfs2_bufdata_cachep, bd); +gfs2_glock_remove_revoke (bd); revokes++;if (revokes == len)break ;
Signature · 1 line
2.56.1