cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Steven Whitehouse <swhiteho@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 11/24] GFS2: Remove duplicate log code
Date: Thu, 17 May 2012 13:23:18 +0100	[thread overview]
Message-ID: <1337257411-3173-12-git-send-email-swhiteho@redhat.com> (raw)
In-Reply-To: <1337257411-3173-1-git-send-email-swhiteho@redhat.com>

The main part of this patch merges the two functions used to
write metadata and data buffers to the log. Most of the code
is common between the two functions, so this provides a nice
clean up, and makes the code more readable.

The gfs2_get_log_desc() function is also extended to take two more
arguments, and thus avoid having to set the length and data1
fields of this strucuture as a separate operation.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>

diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 872d3e6..7882671 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -372,7 +372,8 @@ void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page)
 	gfs2_log_write(sdp, page, sb->s_blocksize, 0);
 }
 
-static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type)
+static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type,
+				      u32 ld_length, u32 ld_data1)
 {
 	void *page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
 	struct gfs2_log_descriptor *ld = page_address(page);
@@ -381,8 +382,8 @@ static struct page *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type)
 	ld->ld_header.mh_type = cpu_to_be32(GFS2_METATYPE_LD);
 	ld->ld_header.mh_format = cpu_to_be32(GFS2_FORMAT_LD);
 	ld->ld_type = cpu_to_be32(ld_type);
-	ld->ld_length = 0;
-	ld->ld_data1 = 0;
+	ld->ld_length = cpu_to_be32(ld_length);
+	ld->ld_data1 = cpu_to_be32(ld_data1);
 	ld->ld_data2 = 0;
 	return page;
 }
@@ -418,39 +419,49 @@ out:
 	unlock_buffer(bd->bd_bh);
 }
 
-static void buf_lo_before_commit(struct gfs2_sbd *sdp)
+static void gfs2_check_magic(struct buffer_head *bh)
+{
+	void *kaddr;
+	__be32 *ptr;
+
+	clear_buffer_escaped(bh);
+	kaddr = kmap_atomic(bh->b_page);
+	ptr = kaddr + bh_offset(bh);
+	if (*ptr == cpu_to_be32(GFS2_MAGIC))
+		set_buffer_escaped(bh);
+	kunmap_atomic(kaddr);
+}
+
+static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
+				unsigned int total, struct list_head *blist,
+				bool is_databuf)
 {
 	struct gfs2_log_descriptor *ld;
 	struct gfs2_bufdata *bd1 = NULL, *bd2;
 	struct page *page;
-	unsigned int total;
-	unsigned int limit;
 	unsigned int num;
 	unsigned n;
 	__be64 *ptr;
 
-	limit = buf_limit(sdp);
-	/* for 4k blocks, limit = 503 */
-
 	gfs2_log_lock(sdp);
-	total = sdp->sd_log_num_buf;
-	bd1 = bd2 = list_prepare_entry(bd1, &sdp->sd_log_le_buf, bd_le.le_list);
+	bd1 = bd2 = list_prepare_entry(bd1, blist, bd_le.le_list);
 	while(total) {
 		num = total;
 		if (total > limit)
 			num = limit;
 		gfs2_log_unlock(sdp);
-		page = gfs2_get_log_desc(sdp, GFS2_LOG_DESC_METADATA);
+		page = gfs2_get_log_desc(sdp, GFS2_LOG_DESC_METADATA, num + 1, num);
 		ld = page_address(page);
 		gfs2_log_lock(sdp);
 		ptr = (__be64 *)(ld + 1);
-		ld->ld_length = cpu_to_be32(num + 1);
-		ld->ld_data1 = cpu_to_be32(num);
 
 		n = 0;
-		list_for_each_entry_continue(bd1, &sdp->sd_log_le_buf,
-					     bd_le.le_list) {
+		list_for_each_entry_continue(bd1, blist, bd_le.le_list) {
 			*ptr++ = cpu_to_be64(bd1->bd_bh->b_blocknr);
+			if (is_databuf) {
+				gfs2_check_magic(bd1->bd_bh);
+				*ptr++ = cpu_to_be64(buffer_escaped(bd1->bd_bh) ? 1 : 0);
+			}
 			if (++n >= num)
 				break;
 		}
@@ -460,12 +471,27 @@ static void buf_lo_before_commit(struct gfs2_sbd *sdp)
 		gfs2_log_lock(sdp);
 
 		n = 0;
-		list_for_each_entry_continue(bd2, &sdp->sd_log_le_buf,
-					     bd_le.le_list) {
+		list_for_each_entry_continue(bd2, blist, bd_le.le_list) {
 			get_bh(bd2->bd_bh);
 			gfs2_log_unlock(sdp);
 			lock_buffer(bd2->bd_bh);
-			gfs2_log_write_bh(sdp, bd2->bd_bh);
+
+			if (buffer_escaped(bd2->bd_bh)) {
+				void *kaddr;
+				page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
+				ptr = page_address(page);
+				kaddr = kmap_atomic(bd2->bd_bh->b_page);
+				memcpy(ptr, kaddr + bh_offset(bd2->bd_bh),
+				       bd2->bd_bh->b_size);
+				kunmap_atomic(kaddr);
+				*(__be32 *)ptr = 0;
+				clear_buffer_escaped(bd2->bd_bh);
+				unlock_buffer(bd2->bd_bh);
+				brelse(bd2->bd_bh);
+				gfs2_log_write_page(sdp, page);
+			} else {
+				gfs2_log_write_bh(sdp, bd2->bd_bh);
+			}
 			gfs2_log_lock(sdp);
 			if (++n >= num)
 				break;
@@ -477,6 +503,14 @@ static void buf_lo_before_commit(struct gfs2_sbd *sdp)
 	gfs2_log_unlock(sdp);
 }
 
+static void buf_lo_before_commit(struct gfs2_sbd *sdp)
+{
+	unsigned int limit = buf_limit(sdp); /* 503 for 4k blocks */
+
+	gfs2_before_commit(sdp, limit, sdp->sd_log_num_buf,
+			   &sdp->sd_log_le_buf, 0);
+}
+
 static void buf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
 {
 	struct list_head *head = &sdp->sd_log_le_buf;
@@ -594,15 +628,14 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp)
 	struct list_head *head = &sdp->sd_log_le_revoke;
 	struct gfs2_bufdata *bd;
 	struct page *page;
+	unsigned int length;
 
 	if (!sdp->sd_log_num_revoke)
 		return;
 
-	page = gfs2_get_log_desc(sdp, GFS2_LOG_DESC_REVOKE);
+	length = gfs2_struct2blk(sdp, sdp->sd_log_num_revoke, sizeof(u64));
+	page = gfs2_get_log_desc(sdp, GFS2_LOG_DESC_REVOKE, length, sdp->sd_log_num_revoke);
 	ld = page_address(page);
-	ld->ld_length = cpu_to_be32(gfs2_struct2blk(sdp, sdp->sd_log_num_revoke,
-						    sizeof(u64)));
-	ld->ld_data1 = cpu_to_be32(sdp->sd_log_num_revoke);
 	offset = sizeof(struct gfs2_log_descriptor);
 
 	list_for_each_entry(bd, head, bd_le.le_list) {
@@ -775,66 +808,6 @@ out:
 	unlock_buffer(bd->bd_bh);
 }
 
-static void gfs2_check_magic(struct buffer_head *bh)
-{
-	void *kaddr;
-	__be32 *ptr;
-
-	clear_buffer_escaped(bh);
-	kaddr = kmap_atomic(bh->b_page);
-	ptr = kaddr + bh_offset(bh);
-	if (*ptr == cpu_to_be32(GFS2_MAGIC))
-		set_buffer_escaped(bh);
-	kunmap_atomic(kaddr);
-}
-
-static void gfs2_write_blocks(struct gfs2_sbd *sdp,
-			      struct gfs2_log_descriptor *ld,
-			      struct page *page,
-			      struct list_head *list, struct list_head *done,
-			      unsigned int n)
-{
-	struct gfs2_bufdata *bd;
-	__be64 *ptr;
-
-	if (!ld)
-		return;
-
-	ld->ld_length = cpu_to_be32(n + 1);
-	ld->ld_data1 = cpu_to_be32(n);
-	ptr = (__force __be64 *)(ld + 1);
-	
-	gfs2_log_write_page(sdp, page);
-	gfs2_log_lock(sdp);
-	while (!list_empty(list)) {
-		bd = list_entry(list->next, struct gfs2_bufdata, bd_le.le_list);
-		list_move_tail(&bd->bd_le.le_list, done);
-		get_bh(bd->bd_bh);
-		gfs2_log_unlock(sdp);
-		lock_buffer(bd->bd_bh);
-		if (buffer_escaped(bd->bd_bh)) {
-			void *kaddr;
-			page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
-			ptr = page_address(page);
-			kaddr = kmap_atomic(bd->bd_bh->b_page);
-			memcpy(ptr, kaddr + bh_offset(bd->bd_bh),
-			       bd->bd_bh->b_size);
-			kunmap_atomic(kaddr);
-			*(__be32 *)ptr = 0;
-			clear_buffer_escaped(bd->bd_bh);
-			unlock_buffer(bd->bd_bh);
-			brelse(bd->bd_bh);
-			gfs2_log_write_page(sdp, page);
-		} else {
-			gfs2_log_write_bh(sdp, bd->bd_bh);
-		}
-		n--;
-		gfs2_log_lock(sdp);
-	}
-	gfs2_log_unlock(sdp);
-	BUG_ON(n != 0);
-}
-
 /**
  * databuf_lo_before_commit - Scan the data buffers, writing as we go
  *
@@ -842,40 +815,10 @@ static void gfs2_write_blocks(struct gfs2_sbd *sdp,
 
 static void databuf_lo_before_commit(struct gfs2_sbd *sdp)
 {
-	struct gfs2_bufdata *bd = NULL;
-	struct gfs2_log_descriptor *ld = NULL;
-	struct page *page = NULL;
-	unsigned int n = 0;
-	__be64 *ptr = NULL, *end = NULL;
-	LIST_HEAD(processed);
-	LIST_HEAD(in_progress);
+	unsigned int limit = buf_limit(sdp) / 2;
 
-	gfs2_log_lock(sdp);
-	while (!list_empty(&sdp->sd_log_le_databuf)) {
-		if (ptr == end) {
-			gfs2_log_unlock(sdp);
-			gfs2_write_blocks(sdp, ld, page, &in_progress, &processed, n);
-			n = 0;
-			page = gfs2_get_log_desc(sdp, GFS2_LOG_DESC_JDATA);
-			ld = page_address(page);
-			ptr = (__force __be64 *)(ld + 1);
-			end = (__force __be64 *)(page_address(page) + sdp->sd_vfs->s_blocksize);
-			end--;
-			gfs2_log_lock(sdp);
-			continue;
-		}
-		bd = list_entry(sdp->sd_log_le_databuf.next, struct gfs2_bufdata, bd_le.le_list);
-		list_move_tail(&bd->bd_le.le_list, &in_progress);
-		gfs2_check_magic(bd->bd_bh);
-		*ptr++ = cpu_to_be64(bd->bd_bh->b_blocknr);
-		*ptr++ = cpu_to_be64(buffer_escaped(bd->bd_bh) ? 1 : 0);
-		n++;
-	}
-	gfs2_log_unlock(sdp);
-	gfs2_write_blocks(sdp, ld, page, &in_progress, &processed, n);
-	gfs2_log_lock(sdp);
-	list_splice(&processed, &sdp->sd_log_le_databuf);
-	gfs2_log_unlock(sdp);
+	gfs2_before_commit(sdp, limit, sdp->sd_log_num_databuf,
+			   &sdp->sd_log_le_databuf, 1);
 }
 
 static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start,
-- 
1.7.4



  parent reply	other threads:[~2012-05-17 12:23 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-17 12:23 [Cluster-devel] GFS2: Pre-pull patch posting (merge window) Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 01/24] GFS2: Drop "pull" argument from log_write_header() Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 02/24] GFS2: Make gfs2_log_fake_buf() write the buffer too Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 03/24] GFS2: Rename function gfs2_close to gfs2_release Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 04/24] GFS2: make function gfs2_page_add_databufs static Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 05/24] GFS2: Use slab for block reservation memory Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 06/24] GFS2: Eliminate offset parameter to gfs2_setbit Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 07/24] GFS2: Fix function parameter comments in rgrp.c Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 08/24] GFS2: Change variable blk to biblk Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 09/24] GFS2: Use variable rather than qa to determine if unstuff necessary Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 10/24] GFS2: Clean up log write code path Steven Whitehouse
2012-05-17 12:23 ` Steven Whitehouse [this message]
2012-05-17 12:23 ` [Cluster-devel] [PATCH 12/24] GFS2: Remove bd_list_tr Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 13/24] GFS2: Remove unused argument from gfs2_internal_read Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 14/24] GFS2: Log code fixes Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 15/24] GFS2: Eliminate needless parameter from function gfs2_setbit Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 16/24] GFS2: Eliminate vestigial sd_log_le_rg Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 17/24] GFS2: eliminate log elements and simplify Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 18/24] GFS2: Fix sgid propagation when using ACLs Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 19/24] GFS2: Remove redundant metadata block type check Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 20/24] GFS2: Update main gfs2 doc Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 21/24] GFS2: Update glock doc to add new stats info Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 22/24] GFS2: Eliminate unused "new" parameter to gfs2_meta_indirect_buffer Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 23/24] GFS2: Add rgrp information to block_alloc trace point Steven Whitehouse
2012-05-17 12:23 ` [Cluster-devel] [PATCH 24/24] GFS2: Fix quota adjustment return code Steven Whitehouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1337257411-3173-12-git-send-email-swhiteho@redhat.com \
    --to=swhiteho@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).