Skip to contentSkip to conversation

gfs2: some cleanups

PATCH New Andreas Gruenbacher 1 participant 5 messages Nov 17 GFS2 file system

lore
Share & tools
lore

Andreas Gruenbacher

author maintainer
#0 lore raw

cover 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
author maintainer
#1 lore raw

PATCH 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
index 264170f91c5d..4916bcfa1f30 100644
@@ -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
index aa11168255e9..21b71fe286b7 100644
@@ -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
index 7a391b50d13b..146f5c8da72b 100644
@@ -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
index 13d8aa1dfea1..abf5afbce77d 100644
@@ -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
index b2984fb7b35c..88bf87db1d27 100644
@@ -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
index 84db5bb7dc5c..908e7f1253d2 100644
@@ -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
index bcb90ffe1816..c7777b8565a2 100644
@@ -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
author maintainer
#2 lore raw

PATCH 2/4 gfs2: Remove unnecessary list heads

In reply to Andreas Gruenbacher

Remove 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
index 2597e1cf2315..2073bbf5c8cf 100644
@@ -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
index 146f5c8da72b..3161c728b60b 100644
@@ -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
index abf5afbce77d..849cdcc1baa6 100644
@@ -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
index 908e7f1253d2..f950eb95f435 100644
@@ -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
author maintainer
#3 lore raw

PATCH 3/4 gfs2: gfs2_trans_remove_revoke cleanup

In reply to Andreas Gruenbacher

Count 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
index 65cbe06e301a..a6e6dca8d431 100644
@@ -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
author maintainer
#4 lore raw

PATCH 4/4 gfs2: gfs2_glock_remove_revoke cleanup

In reply to Andreas Gruenbacher

Pass 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
index 3161c728b60b..a89346c93f16 100644
@@ -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
index 10beda62427c..b4eeb04d2f2a 100644
@@ -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
index 849cdcc1baa6..204b2fb76575 100644
@@ -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
index a6e6dca8d431..9cb167ac6ef8 100644
@@ -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