[Cluster-devel] [PATCH 48/56] libgfs2: Make rebuild functions not re-read ip

Bob Peterson rpeterso at redhat.com
Thu Aug 25 16:58:22 UTC 2011


>From c93beb4367027f52979297dafae5728093f6a5d6 Mon Sep 17 00:00:00 2001
From: Bob Peterson <rpeterso at redhat.com>
Date: Fri, 19 Aug 2011 15:57:03 -0500
Subject: [PATCH 48/56] libgfs2: Make rebuild functions not re-read ip

Before this patch, the libgfs2 rebuild functions in structures.c
were not consistent about reading in the gfs2_inode in-core struct.
Some of the functions did and some didn't.  The previous patch to
make fsck.gfs2 operate on gfs1 introduced a problem because the code
was changed to re-read the inum and statfs files if they were rebuilt.
But since the functions already did the read, it was a double-read.
A double-read is a bad thing because inode writes are now done on
the last inode put, and the double-read messed up the counter.
(Number of inode gets should match puts).  This patch makes all the
build functions consistent: they all put the inode after building,
except for root and master which have no parent inodes.

There was also a minor problem whereby leaf searches were getting
the number of entries from the directory buffer rather than from
the dinode itself.  (The buffer may be out of date, but the dinode
should always be current).  So there were circumstances where you
could add a new dirent to "master" but the count of entries was not
correct in the buffer, which caused the search to stop prematurely.

rhbz#675723
---
 gfs2/convert/gfs2_convert.c |    3 +++
 gfs2/fsck/initialize.c      |    7 ++++++-
 gfs2/libgfs2/fs_ops.c       |   10 +++++-----
 gfs2/libgfs2/structures.c   |    4 ++--
 gfs2/mkfs/main_mkfs.c       |    2 ++
 5 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index c255874..bef2ccd 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2246,6 +2246,7 @@ int main(int argc, char **argv)
 			         strerror(error));
 			exit(-1);
 		}
+		gfs2_lookupi(sb2.master_dir, "inum", 4, &sb2.md.inum);
 		/* Create the statfs file */
 		error = build_statfs(&sb2); /* Does not do inode_put */
 		if (error) {
@@ -2253,6 +2254,8 @@ int main(int argc, char **argv)
 			         strerror(error));
 			exit(-1);
 		}
+		gfs2_lookupi(sb2.master_dir, "statfs", 6, &sb2.md.statfs);
+		do_init_statfs(&sb2);
 
 		/* Create the resource group index file */
 		error = build_rindex(&sb2);
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index e2b1e63..8910103 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -422,13 +422,14 @@ static int rebuild_master(struct gfs2_sbd *sdp)
 			         strerror(err));
 			exit(-1);
 		}
+		gfs2_lookupi(sdp->master_dir, "inum", 4, &sdp->md.inum);
 	}
 
 	if (fix_md.statfs) {
 		inum.no_formal_ino = sdp->md.next_inum++;
 		inum.no_addr = fix_md.statfs->i_di.di_num.no_addr;
 		err = dir_add(sdp->master_dir, "statfs", 6, &inum,
-			IF2DT(S_IFREG | 0600));
+			      IF2DT(S_IFREG | 0600));
 		if (err) {
 			log_crit(_("Error adding statfs inode: %s\n"), strerror(err));
 			exit(-1);
@@ -440,6 +441,7 @@ static int rebuild_master(struct gfs2_sbd *sdp)
 			         strerror(err));
 			exit(-1);
 		}
+		gfs2_lookupi(sdp->master_dir, "statfs", 6, &sdp->md.statfs);
 	}
 
 	if (fix_md.riinode) {
@@ -479,6 +481,8 @@ static int rebuild_master(struct gfs2_sbd *sdp)
 	}
 
 	log_err(_("Master directory rebuilt.\n"));
+	inode_put(&sdp->md.inum);
+	inode_put(&sdp->md.statfs);
 	inode_put(&sdp->master_dir);
 	return 0;
 }
@@ -704,6 +708,7 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 				   "a valid statfs file; aborting.\n"));
 			goto fail;
 		}
+		do_init_statfs(sdp);
 	}
 	buf = malloc(sdp->md.statfs->i_di.di_size);
 	// FIXME: handle failed malloc
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 629729d..84cd895 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -1246,6 +1246,7 @@ static int dir_l_add(struct gfs2_inode *dip, const char *filename, int len,
 	dent->de_hash = cpu_to_be32(dent->de_hash);
 	dent->de_type = cpu_to_be16(type);
 	memcpy((char *)(dent + 1), filename, len);
+	bmodified(dip->i_bh);
 	return err;
 }
 
@@ -1448,10 +1449,9 @@ static int leaf_search(struct gfs2_inode *dip, struct gfs2_buffer_head *bh,
 	if (type == IS_LEAF){
 		struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data;
 		entries = be16_to_cpu(leaf->lf_entries);
-	} else if (type == IS_DINODE) {
-		struct gfs2_dinode *dinode = (struct gfs2_dinode *)bh->b_data;
-		entries = be32_to_cpu(dinode->di_entries);
-	} else
+	} else if (type == IS_DINODE)
+		entries = dip->i_di.di_entries;
+	else
 		return -1;
 
 	hash = gfs2_disk_hash(filename, len);
@@ -1464,7 +1464,7 @@ static int leaf_search(struct gfs2_inode *dip, struct gfs2_buffer_head *bh,
 		
 		if (be32_to_cpu(dent->de_hash) == hash &&
 			gfs2_filecmp(filename, (char *)(dent + 1),
-						 be16_to_cpu(dent->de_name_len))){
+				     be16_to_cpu(dent->de_name_len))) {
 			*dent_out = dent;
 			if (dent_prev)
 				*dent_prev = prev;
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index e8a8c65..7f21ad6 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -318,7 +318,7 @@ int build_inum(struct gfs2_sbd *sdp)
 		gfs2_dinode_print(&ip->i_di);
 	}
 
-	sdp->md.inum = ip;
+	inode_put(&ip);
 	return 0;
 }
 
@@ -337,7 +337,7 @@ int build_statfs(struct gfs2_sbd *sdp)
 		gfs2_dinode_print(&ip->i_di);
 	}
 
-	sdp->md.statfs = ip;
+	inode_put(&ip);
 	return 0;
 }
 
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 0da3bc5..d841daa 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -652,11 +652,13 @@ void main_mkfs(int argc, char *argv[])
 		fprintf(stderr, _("Error building inum inode: %s\n"), strerror(error));
 		exit(-1);
 	}
+	gfs2_lookupi(sdp->master_dir, "inum", 4, &sdp->md.inum);
 	error = build_statfs(sdp);
 	if (error) {
 		fprintf(stderr, _("Error building statfs inode: %s\n"), strerror(error));
 		exit(-1);
 	}
+	gfs2_lookupi(sdp->master_dir, "statfs", 6, &sdp->md.statfs);
 	error = build_rindex(sdp);
 	if (error) {
 		fprintf(stderr, _("Error building rindex inode: %s\n"), strerror(error));
-- 
1.7.4.4




More information about the Cluster-devel mailing list