Skip to contentSkip to conversation

GFS2: Combine func meta_prep_new with its only caller

PATCH Superseded Bob Peterson 2 participants 2 messages May 22, 2017 1 message not in the archive GFS2 file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 GFS2: Combine func meta_prep_new with its only caller

In reply to a message not in the archive

Hi,

Before this patch function meta_prep_new was only called in one place, function gfs2_meta_new which is only a couple lines long. This patch combines them for readability.

---

fs/gfs2/meta_io.c +9 -15
index 663ffc1..bbd9411 100644
@@ -158,18 +158,6 @@ struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create)
 	return bh;
 }
 
-static void meta_prep_new(struct buffer_head *bh)
-{
-	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
-
-	lock_buffer(bh);
-	clear_buffer_dirty(bh);
-	set_buffer_uptodate(bh);
-	unlock_buffer(bh);
-
-	mh->mh_magic = cpu_to_be32(GFS2_MAGIC);
-}
-
 /**
  * gfs2_meta_new - Get a block
  * @gl: The glock associated with this block
@@ -180,9 +168,15 @@ static void meta_prep_new(struct buffer_head *bh)
 
 struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno)
 {
-	struct buffer_head *bh;
-	bh = gfs2_getbuf(gl, blkno, CREATE);
-	meta_prep_new(bh);
+	struct buffer_head *bh = gfs2_getbuf(gl, blkno, CREATE);
+	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
+
+	lock_buffer(bh);
+	clear_buffer_dirty(bh);
+	set_buffer_uptodate(bh);
+	unlock_buffer(bh);
+
+	mh->mh_magic = cpu_to_be32(GFS2_MAGIC);
 	return bh;
 }
 
#2 lore raw

PATCH 1/1 GFS2: Combine func meta_prep_new with its only caller

Hi,

Quoted 7 lines · Bob Peterson

Hi,

Before this patch function meta_prep_new was only called in one place, function gfs2_meta_new which is only a couple lines long. This patch combines them for readability.

That is a good plan. If you look at the callers of gfs2_meta_new then you'll see that there is a common pattern there too (aside from the two callers from log.c) and it would be good to merge back some of that into this function too, to reduce duplication of code.

It is a bit odd that we unlock the buffer before setting the magic number, and also that we do that before adding the buffer to a transaction. Worth a quick check there just to see if there is something not quite right,

Steve.

Quoted 44 lines

---

fs/gfs2/meta_io.c +9 -15
index 663ffc1..bbd9411 100644
@@ -158,18 +158,6 @@ struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create)
  	return bh;
  }
 
-static void meta_prep_new(struct buffer_head *bh)
-{
-	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
-
-	lock_buffer(bh);
-	clear_buffer_dirty(bh);
-	set_buffer_uptodate(bh);
-	unlock_buffer(bh);
-
-	mh->mh_magic = cpu_to_be32(GFS2_MAGIC);
-}
-
  /**
   * gfs2_meta_new - Get a block
   * @gl: The glock associated with this block
@@ -180,9 +168,15 @@ static void meta_prep_new(struct buffer_head *bh)
 
  struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno)
  {
-	struct buffer_head *bh;
-	bh = gfs2_getbuf(gl, blkno, CREATE);
-	meta_prep_new(bh);
+	struct buffer_head *bh = gfs2_getbuf(gl, blkno, CREATE);
+	struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data;
+
+	lock_buffer(bh);
+	clear_buffer_dirty(bh);
+	set_buffer_uptodate(bh);
+	unlock_buffer(bh);
+
+	mh->mh_magic = cpu_to_be32(GFS2_MAGIC);
  	return bh;
  }