[Cluster-devel] [PATCH 1/3] libgfs2: Remove exit calls from inode_read and inode_get

Andrew Price anprice at redhat.com
Tue Aug 28 15:36:19 UTC 2012


- Remove exit calls from inode_read and inode_get
- Fix error handling for the functions up the call tree
- The two functions are almost identical so define inode_read using
  inode_get
- Update their names with an lgfs2_ prefix
- Move block_is_in_per_node into savemeta.c and make it static

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 gfs2/convert/gfs2_convert.c | 24 ++++++++++++----
 gfs2/edit/extended.c        | 24 ++++++++++++----
 gfs2/edit/hexedit.c         | 47 ++++++++++++-------------------
 gfs2/edit/hexedit.h         |  1 -
 gfs2/edit/savemeta.c        | 56 ++++++++++++++++++++++++++++++++-----
 gfs2/fsck/fs_recovery.c     |  4 ++-
 gfs2/fsck/initialize.c      | 68 +++++++++++++++++++++++++++++++++------------
 gfs2/fsck/metawalk.c        |  4 +--
 gfs2/libgfs2/fs_ops.c       | 34 +++++++++++++----------
 gfs2/libgfs2/libgfs2.h      |  4 +--
 gfs2/libgfs2/structures.c   |  8 ++++--
 gfs2/mkfs/main_grow.c       |  7 +++--
 12 files changed, 192 insertions(+), 89 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 9944d23..51ec256 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -1092,7 +1092,9 @@ static int fetch_inum(struct gfs2_sbd *sbp, uint64_t iblock,
 {
 	struct gfs2_inode *fix_inode;
 
-	fix_inode = inode_read(sbp, iblock);
+	fix_inode = lgfs2_inode_read(sbp, iblock);
+	if (fix_inode == NULL)
+		return 1;
 	inum->no_formal_ino = fix_inode->i_di.di_num.no_formal_ino;
 	inum->no_addr = fix_inode->i_di.di_num.no_addr;
 	if (eablk)
@@ -1289,7 +1291,9 @@ static int process_directory(struct gfs2_sbd *sbp, uint64_t dirblock, uint64_t d
 	struct gfs2_inode *dip;
 	int error = 0;
 	/* read in the directory inode */
-	dip = inode_read(sbp, dirblock);
+	dip = lgfs2_inode_read(sbp, dirblock);
+	if (dip == NULL)
+		return -1;
 	/* fix the directory: either exhash (leaves) or linear (stuffed) */
 	if (dip->i_di.di_flags & GFS2_DIF_EXHASH) {
 		if (fix_one_directory_exhash(sbp, dip, dentmod)) {
@@ -1391,7 +1395,9 @@ static int fix_cdpn_symlinks(struct gfs2_sbd *sbp, osi_list_t *cdpn_to_fix)
 
 		/* initialize the symlink inode to be a directory */
 		bh = init_dinode(sbp, &fix, S_IFDIR | 0755, 0, &dir);
-		fix_inode = inode_get(sbp, bh);
+		fix_inode = lgfs2_inode_get(sbp, bh);
+		if (fix_inode == NULL)
+			return -1;
 		fix_inode->i_di.di_eattr = eablk; /*fix extended attribute */
 		inode_put(&fix_inode);
 		bmodified(bh);
@@ -1588,7 +1594,11 @@ static int init(struct gfs2_sbd *sbp)
 	sbp->md.riinode = gfs_inode_read(sbp, inum.no_addr);
 	/* get gfs1 jindex inode - gfs1's journal index inode ptr became master */
 	gfs2_inum_in(&inum, (char *)&raw_gfs1_ondisk_sb.sb_jindex_di);
-	sbp->md.jiinode = inode_read(sbp, inum.no_addr);
+	sbp->md.jiinode = lgfs2_inode_read(sbp, inum.no_addr);
+	if (sbp->md.jiinode == NULL) {
+		log_crit(_("Could not read journal index: %s\n"), strerror(errno));
+		exit(-1);
+	}
 	/* read in the journal index data */
 	read_gfs1_jiindex(sbp);
 	/* read in the resource group index data: */
@@ -2056,7 +2066,11 @@ static void copy_quotas(struct gfs2_sbd *sdp)
 	}
 
 	gfs2_inum_in(&inum, (char *)&raw_gfs1_ondisk_sb.sb_quota_di);
-	oq_ip = inode_read(sdp, inum.no_addr);
+	oq_ip = lgfs2_inode_read(sdp, inum.no_addr);
+	if (oq_ip == NULL) {
+		fprintf(stderr, _("Couldn't lookup old quota file: %s\n"), strerror(errno));
+		exit(1);
+	}
 
 	nq_ip->i_di.di_height = oq_ip->i_di.di_height;
 	nq_ip->i_di.di_size = oq_ip->i_di.di_size;
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
index 566fb5b..e2567a5 100644
--- a/gfs2/edit/extended.c
+++ b/gfs2/edit/extended.c
@@ -654,7 +654,9 @@ int display_extended(void)
 	/* Display any indirect pointers that we have. */
 	if (block_is_rindex()) {
 		tmp_bh = bread(&sbd, block);
-		tmp_inode = inode_get(&sbd, tmp_bh);
+		tmp_inode = lgfs2_inode_get(&sbd, tmp_bh);
+		if (tmp_inode == NULL)
+			return -1;
 		parse_rindex(tmp_inode, TRUE);
 		inode_put(&tmp_inode);
 		brelse(tmp_bh);
@@ -669,35 +671,45 @@ int display_extended(void)
 			tmp_bh = bread(&sbd, sbd1->sb_rindex_di.no_addr);
 		else
 			tmp_bh = bread(&sbd, masterblock("rindex"));
-		tmp_inode = inode_get(&sbd, tmp_bh);
+		tmp_inode = lgfs2_inode_get(&sbd, tmp_bh);
+		if (tmp_inode == NULL)
+			return -1;
 		parse_rindex(tmp_inode, FALSE);
 		inode_put(&tmp_inode);
 		brelse(tmp_bh);
 	}
 	else if (block_is_jindex()) {
 		tmp_bh = bread(&sbd, block);
-		tmp_inode = inode_get(&sbd, tmp_bh);
+		tmp_inode = lgfs2_inode_get(&sbd, tmp_bh);
+		if (tmp_inode == NULL)
+			return -1;
 		print_jindex(tmp_inode);
 		inode_put(&tmp_inode);
 		brelse(tmp_bh);
 	}
 	else if (block_is_inum_file()) {
 		tmp_bh = bread(&sbd, block);
-		tmp_inode = inode_get(&sbd, tmp_bh);
+		tmp_inode = lgfs2_inode_get(&sbd, tmp_bh);
+		if (tmp_inode == NULL)
+			return -1;
 		print_inum(tmp_inode);
 		inode_put(&tmp_inode);
 		brelse(tmp_bh);
 	}
 	else if (block_is_statfs_file()) {
 		tmp_bh = bread(&sbd, block);
-		tmp_inode = inode_get(&sbd, tmp_bh);
+		tmp_inode = lgfs2_inode_get(&sbd, tmp_bh);
+		if (tmp_inode == NULL)
+			return -1;
 		print_statfs(tmp_inode);
 		inode_put(&tmp_inode);
 		brelse(tmp_bh);
 	}
 	else if (block_is_quota_file()) {
 		tmp_bh = bread(&sbd, block);
-		tmp_inode = inode_get(&sbd, tmp_bh);
+		tmp_inode = lgfs2_inode_get(&sbd, tmp_bh);
+		if (tmp_inode == NULL)
+			return -1;
 		print_quota(tmp_inode);
 		inode_put(&tmp_inode);
 		brelse(tmp_bh);
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 2ff1125..79082b8 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -1063,7 +1063,9 @@ static uint64_t get_rg_addr(int rgnum)
 		gblock = sbd1->sb_rindex_di.no_addr;
 	else
 		gblock = masterblock("rindex");
-	riinode = inode_read(&sbd, gblock);
+	riinode = lgfs2_inode_read(&sbd, gblock);
+	if (riinode == NULL)
+		return 0;
 	if (rgnum < riinode->i_di.di_size / sizeof(struct gfs2_rindex))
 		rgblk = find_rgrp_block(riinode, rgnum);
 	else
@@ -1205,29 +1207,6 @@ int block_is_per_node(void)
 }
 
 /* ------------------------------------------------------------------------ */
-/* block_is_in_per_node                                                     */
-/* ------------------------------------------------------------------------ */
-int block_is_in_per_node(void)
-{
-	int d;
-	struct gfs2_inode *per_node_di;
-
-	if (sbd.gfs1)
-		return FALSE;
-
-	per_node_di = inode_read(&sbd, masterblock("per_node"));
-
-	do_dinode_extended(&per_node_di->i_di, per_node_di->i_bh);
-	inode_put(&per_node_di);
-
-	for (d = 0; d < indirect->ii[0].dirents; d++) {
-		if (block == indirect->ii[0].dirent[d].block)
-			return TRUE;
-	}
-	return FALSE;
-}
-
-/* ------------------------------------------------------------------------ */
 /* block_has_extended_info                                                  */
 /* ------------------------------------------------------------------------ */
 static int block_has_extended_info(void)
@@ -1301,15 +1280,19 @@ static void read_superblock(int fd)
 			sizeof(uint64_t);
 		sbd.sd_diptrs = (sbd.bsize - sizeof(struct gfs_dinode)) /
 			sizeof(uint64_t);
-		sbd.md.riinode = inode_read(&sbd, sbd1->sb_rindex_di.no_addr);
+		sbd.md.riinode = lgfs2_inode_read(&sbd, sbd1->sb_rindex_di.no_addr);
 	} else {
 		sbd.sd_inptrs = (sbd.bsize - sizeof(struct gfs2_meta_header)) /
 			sizeof(uint64_t);
 		sbd.sd_diptrs = (sbd.bsize - sizeof(struct gfs2_dinode)) /
 			sizeof(uint64_t);
-		sbd.master_dir = inode_read(&sbd,
+		sbd.master_dir = lgfs2_inode_read(&sbd,
 					    sbd.sd_sb.sb_master_dir.no_addr);
-		gfs2_lookupi(sbd.master_dir, "rindex", 6, &sbd.md.riinode);
+		if (sbd.master_dir == NULL) {
+			sbd.md.riinode = NULL;
+		} else {
+			gfs2_lookupi(sbd.master_dir, "rindex", 6, &sbd.md.riinode);
+		}
 	}
 	sbd.fssize = sbd.device.length;
 	if (sbd.md.riinode) /* If we found the rindex */
@@ -1521,7 +1504,9 @@ static uint64_t find_journal_block(const char *journal, uint64_t *j_size)
 		struct gfs2_inode *jiinode;
 		struct gfs_jindex ji;
 
-		jiinode = inode_get(&sbd, jindex_bh);
+		jiinode = lgfs2_inode_get(&sbd, jindex_bh);
+		if (jiinode == NULL)
+			return 0;
 		amtread = gfs2_readi(jiinode, (void *)&jbuf,
 				   journal_num * sizeof(struct gfs_jindex),
 				   sizeof(struct gfs_jindex));
@@ -2682,7 +2667,11 @@ static void dump_journal(const char *journal)
 		return;
 	if (!sbd.gfs1) {
 		j_bh = bread(&sbd, jblock);
-		j_inode = inode_get(&sbd, j_bh);
+		j_inode = lgfs2_inode_get(&sbd, j_bh);
+		if (j_inode == NULL) {
+			fprintf(stderr, "Out of memory\n");
+			exit(-1);
+		}
 		jbuf = malloc(sbd.bsize);
 		if (jbuf == NULL) {
 			fprintf(stderr, "Out of memory\n");
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
index dd76810..706909c 100644
--- a/gfs2/edit/hexedit.h
+++ b/gfs2/edit/hexedit.h
@@ -217,7 +217,6 @@ extern int block_is_inum_file(void);
 extern int block_is_statfs_file(void);
 extern int block_is_quota_file(void);
 extern int block_is_per_node(void);
-extern int block_is_in_per_node(void);
 extern int display_block_type(int from_restore);
 extern void gfs_jindex_in(struct gfs_jindex *jindex, char *buf);
 extern void gfs_log_header_in(struct gfs_log_header *head,
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 77cd7fa..77165a7 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -60,6 +60,30 @@ static int block_is_a_journal(void)
 	return FALSE;
 }
 
+static int block_is_in_per_node(void)
+{
+	int d;
+	struct gfs2_inode *per_node_di;
+
+	if (sbd.gfs1)
+		return FALSE;
+
+	per_node_di = lgfs2_inode_read(&sbd, masterblock("per_node"));
+	if (per_node_di == NULL) {
+		fprintf(stderr, "Failed to read per_node: %s\n", strerror(errno));
+		exit(1);
+	}
+
+	do_dinode_extended(&per_node_di->i_di, per_node_di->i_bh);
+	inode_put(&per_node_di);
+
+	for (d = 0; d < indirect->ii[0].dirents; d++) {
+		if (block == indirect->ii[0].dirent[d].block)
+			return TRUE;
+	}
+	return FALSE;
+}
+
 static int block_is_systemfile(void)
 {
 	return block_is_jindex() || block_is_inum_file() ||
@@ -122,10 +146,15 @@ static int get_gfs_struct_info(struct gfs2_buffer_head *lbh, int *block_type,
 		*gstruct_len = sbd.bsize;
 		break;
 	case GFS2_METATYPE_DI:   /* 4 (disk inode) */
-		if (sbd.gfs1)
+		if (sbd.gfs1) {
 			inode = gfs_inode_get(&sbd, lbh);
-		else
-			inode = inode_get(&sbd, lbh);
+		} else {
+			inode = lgfs2_inode_get(&sbd, lbh);
+			if (inode == NULL) {
+				fprintf(stderr, "Out of memory\n");
+				exit(-1);
+			}
+		}
 		if (S_ISDIR(inode->i_di.di_mode) ||
 		     (sbd.gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR))
 			*gstruct_len = sbd.bsize;
@@ -461,8 +490,13 @@ static void save_inode_data(struct metafd *mfd)
 	metabh = bread(&sbd, block);
 	if (sbd.gfs1)
 		inode = gfs_inode_get(&sbd, metabh);
-	else
-		inode = inode_get(&sbd, metabh);
+	else {
+		inode = lgfs2_inode_get(&sbd, metabh);
+		if (inode == NULL) {
+			fprintf(stderr, "Failed to read inode: %s\n", strerror(errno));
+			exit(-1);
+		}
+	}
 	height = inode->i_di.di_height;
 	/* If this is a user inode, we don't follow to the file height.
 	   We stop one level less.  That way we save off the indirect
@@ -678,11 +712,19 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
 	printf("There are %llu blocks of %u bytes in the destination "
 	       "device.\n", (unsigned long long)sbd.fssize, sbd.bsize);
 	if (sbd.gfs1) {
-		sbd.md.riinode = inode_read(&sbd, sbd1->sb_rindex_di.no_addr);
+		sbd.md.riinode = lgfs2_inode_read(&sbd, sbd1->sb_rindex_di.no_addr);
+		if (sbd.md.riinode == NULL) {
+			fprintf(stderr, "Unable to read rindex: %s.\n", strerror(errno));
+			exit(-1);
+		}
 		jindex_block = sbd1->sb_jindex_di.no_addr;
 	} else {
-		sbd.master_dir = inode_read(&sbd,
+		sbd.master_dir = lgfs2_inode_read(&sbd,
 					    sbd.sd_sb.sb_master_dir.no_addr);
+		if (sbd.master_dir == NULL) {
+			fprintf(stderr, "Unable to read master: %s.\n", strerror(errno));
+			exit(-1);
+		}
 
 		gfs2_lookupi(sbd.master_dir, "rindex", 6, &sbd.md.riinode);
 		jindex_block = masterblock("jindex");
diff --git a/gfs2/fsck/fs_recovery.c b/gfs2/fsck/fs_recovery.c
index 1d9f632..6c92d0e 100644
--- a/gfs2/fsck/fs_recovery.c
+++ b/gfs2/fsck/fs_recovery.c
@@ -667,7 +667,9 @@ int ji_update(struct gfs2_sbd *sdp)
 				return -1;
 			}
 			gfs_jindex_in(&ji, buf);
-			sdp->md.journal[i] = inode_read(sdp, ji.ji_addr);
+			sdp->md.journal[i] = lgfs2_inode_read(sdp, ji.ji_addr);
+			if (sdp->md.journal[i] == NULL)
+				return -1;
 		} else {
 			/* FIXME check snprintf return code */
 			snprintf(journal_name, JOURNAL_NAME_SIZE,
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index e56161e..a1047f3 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -366,7 +366,11 @@ static int rebuild_master(struct gfs2_sbd *sdp)
 	inum.no_formal_ino = sdp->md.next_inum++;
 	inum.no_addr = sdp->sd_sb.sb_master_dir.no_addr;
 	bh = init_dinode(sdp, &inum, S_IFDIR | 0755, GFS2_DIF_SYSTEM, &inum);
-	sdp->master_dir = inode_get(sdp, bh);
+	sdp->master_dir = lgfs2_inode_get(sdp, bh);
+	if (sdp->master_dir == NULL) {
+		log_crit(_("Error reading master: %s\n"), strerror(errno));
+		return -1;
+	}
 	sdp->master_dir->bh_owned = 1;
 
 	if (fix_md.jiinode) {
@@ -610,7 +614,9 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 	log_info( _("Initializing special inodes...\n"));
 
 	/* Get root dinode */
-	sdp->md.rooti = inode_read(sdp, sdp->sd_sb.sb_root_dir.no_addr);
+	sdp->md.rooti = lgfs2_inode_read(sdp, sdp->sd_sb.sb_root_dir.no_addr);
+	if (sdp->md.rooti == NULL)
+		return -1;
 
 	err = fetch_rgrps(sdp);
 	if (err)
@@ -655,9 +661,13 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 		sdp->md.next_inum = be64_to_cpu(inumbuf);
 	}
 
-	if (sdp->gfs1)
-		sdp->md.statfs = inode_read(sdp, sbd1->sb_license_di.no_addr);
-	else
+	if (sdp->gfs1) {
+		sdp->md.statfs = lgfs2_inode_read(sdp, sbd1->sb_license_di.no_addr);
+		if (sdp->md.statfs == NULL) {
+			log_crit(_("Error reading statfs inode: %s\n"), strerror(errno));
+			goto fail;
+		}
+	} else
 		gfs2_lookupi(sdp->master_dir, "statfs", 6, &sdp->md.statfs);
 	if (!sdp->gfs1 && !sdp->md.statfs) {
 		if (!query( _("The gfs2 system statfs inode is missing. "
@@ -697,9 +707,13 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 		}
 	}
 
-	if (sdp->gfs1)
-		sdp->md.qinode = inode_read(sdp, sbd1->sb_quota_di.no_addr);
-	else
+	if (sdp->gfs1) {
+		sdp->md.qinode = lgfs2_inode_read(sdp, sbd1->sb_quota_di.no_addr);
+		if (sdp->md.qinode == NULL) {
+			log_crit(_("Error reading quota inode: %s\n"), strerror(errno));
+			goto fail;
+		}
+	} else
 		gfs2_lookupi(sdp->master_dir, "quota", 5, &sdp->md.qinode);
 	if (!sdp->gfs1 && !sdp->md.qinode) {
 		if (!query( _("The gfs2 system quota inode is missing. "
@@ -839,7 +853,11 @@ static void peruse_system_dinode(struct gfs2_sbd *sdp, struct gfs2_dinode *di,
 		sdp->sd_sb.sb_master_dir.no_addr = di->di_num.no_addr;
 		return;
 	}
-	ip = inode_read(sdp, di->di_num.no_addr);
+	ip = lgfs2_inode_read(sdp, di->di_num.no_addr);
+	if (ip == NULL) {
+		log_crit(_("Error reading inode: %s\n"), strerror(errno));
+		return;
+	}
 	if ((!sdp->gfs1 && di->di_num.no_formal_ino == 3) ||
 	    (sdp->gfs1 && (di->di_flags & GFS2_DIF_JDATA) &&
 	     (di->di_size % sizeof(struct gfs_jindex) == 0))) {
@@ -962,7 +980,11 @@ static void peruse_user_dinode(struct gfs2_sbd *sdp, struct gfs2_dinode *di,
 		log_warn(_("Root directory copied from the journal.\n"));
 		return;
 	}
-	ip = inode_read(sdp, di->di_num.no_addr);
+	ip = lgfs2_inode_read(sdp, di->di_num.no_addr);
+	if (ip == NULL) {
+		log_crit(_("Error reading inode: %s\n"), strerror(errno));
+		return;
+	}
 	while (ip) {
 		gfs2_lookupi(ip, "..", 2, &parent_ip);
 		if (parent_ip && parent_ip->i_di.di_num.no_addr ==
@@ -1147,7 +1169,7 @@ static int sb_repair(struct gfs2_sbd *sdp)
 		log_err(_("Found a possible root at: 0x%llx\n"),
 			(unsigned long long)possible_root);
 		sdp->sd_sb.sb_root_dir.no_addr = possible_root;
-		sdp->md.rooti = inode_read(sdp, possible_root);
+		sdp->md.rooti = lgfs2_inode_read(sdp, possible_root);
 		if (!sdp->md.rooti ||
 		    sdp->md.rooti->i_di.di_header.mh_magic != GFS2_MAGIC) {
 			struct gfs2_buffer_head *bh;
@@ -1174,14 +1196,22 @@ static int sb_repair(struct gfs2_sbd *sdp)
 	if (query(_("Okay to fix the GFS2 superblock? (y/n)"))) {
 		log_info(_("Found system master directory at: 0x%llx\n"),
 			 sdp->sd_sb.sb_master_dir.no_addr);
-		sdp->master_dir = inode_read(sdp,
+		sdp->master_dir = lgfs2_inode_read(sdp,
 					     sdp->sd_sb.sb_master_dir.no_addr);
+		if (sdp->master_dir == NULL) {
+			log_crit(_("Error reading master inode: %s\n"), strerror(errno));
+			return -1;
+		}
 		sdp->master_dir->i_di.di_num.no_addr =
 			sdp->sd_sb.sb_master_dir.no_addr;
 		log_info(_("Found the root directory at: 0x%llx\n"),
 			 sdp->sd_sb.sb_root_dir.no_addr);
-		sdp->md.rooti = inode_read(sdp,
+		sdp->md.rooti = lgfs2_inode_read(sdp,
 					   sdp->sd_sb.sb_root_dir.no_addr);
+		if (sdp->md.rooti == NULL) {
+			log_crit(_("Error reading root inode: %s\n"), strerror(errno));
+			return -1;
+		}
 		get_random_bytes(uuid, sizeof(uuid));
 		build_sb(sdp, uuid);
 		inode_put(&sdp->md.rooti);
@@ -1345,7 +1375,7 @@ static int init_rindex(struct gfs2_sbd *sdp)
 	int err;
 
 	if (sdp->gfs1)
-		sdp->md.riinode = inode_read(sdp, sbd1->sb_rindex_di.no_addr);
+		sdp->md.riinode = lgfs2_inode_read(sdp, sbd1->sb_rindex_di.no_addr);
 	else
 		gfs2_lookupi(sdp->master_dir, "rindex", 6, &sdp->md.riinode);
 
@@ -1376,7 +1406,7 @@ static int init_jindex(struct gfs2_sbd *sdp)
 	/* rgrepair requires the journals be read in in order to distinguish
 	   "real" rgrps from rgrps that are just copies left in journals. */
 	if (sdp->gfs1)
-		sdp->md.jiinode = inode_read(sdp, sbd1->sb_jindex_di.no_addr);
+		sdp->md.jiinode = lgfs2_inode_read(sdp, sbd1->sb_jindex_di.no_addr);
 	else
 		gfs2_lookupi(sdp->master_dir, "jindex", 6, &sdp->md.jiinode);
 
@@ -1488,7 +1518,7 @@ int initialize(struct gfs2_sbd *sdp, int force_check, int preen,
 	if (sdp->gfs1)
 		sdp->master_dir = NULL;
 	else
-		sdp->master_dir = inode_read(sdp,
+		sdp->master_dir = lgfs2_inode_read(sdp,
 					     sdp->sd_sb.sb_master_dir.no_addr);
 	if (!sdp->gfs1 &&
 	    (sdp->master_dir->i_di.di_header.mh_magic != GFS2_MAGIC ||
@@ -1496,8 +1526,12 @@ int initialize(struct gfs2_sbd *sdp, int force_check, int preen,
 	     !sdp->master_dir->i_di.di_size)) {
 		inode_put(&sdp->master_dir);
 		rebuild_master(sdp);
-		sdp->master_dir = inode_read(sdp,
+		sdp->master_dir = lgfs2_inode_read(sdp,
 					     sdp->sd_sb.sb_master_dir.no_addr);
+		if (sdp->master_dir == NULL) {
+			log_crit(_("Error reading master directory: %s\n"), strerror(errno));
+			return FSCK_ERROR;
+		}
 	}
 
 	/* Look up the "per_node" inode.  If there are journals missing, we
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index acdd10f..aa4f0b5 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -227,7 +227,7 @@ struct gfs2_inode *fsck_load_inode(struct gfs2_sbd *sdp, uint64_t block)
 		return ip;
 	if (sdp->gfs1)
 		return gfs_inode_read(sdp, block);
-	return inode_read(sdp, block);
+	return lgfs2_inode_read(sdp, block);
 }
 
 /* fsck_inode_get - same as inode_get() in libgfs2 but system inodes
@@ -243,7 +243,7 @@ struct gfs2_inode *fsck_inode_get(struct gfs2_sbd *sdp,
 
 	if (sdp->gfs1)
 		return gfs_inode_get(sdp, bh);
-	return inode_get(sdp, bh);
+	return lgfs2_inode_get(sdp, bh);
 }
 
 /* fsck_inode_put - same as inode_put() in libgfs2 but system inodes
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 9409332..ec150e8 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -34,34 +34,32 @@ static int inode_is_stuffed(struct gfs2_inode *ip)
 	return !ip->i_di.di_height;
 }
 
-struct gfs2_inode *inode_get(struct gfs2_sbd *sdp, struct gfs2_buffer_head *bh)
+struct gfs2_inode *lgfs2_inode_get(struct gfs2_sbd *sdp, struct gfs2_buffer_head *bh)
 {
 	struct gfs2_inode *ip;
 
 	ip = calloc(1, sizeof(struct gfs2_inode));
 	if (ip == NULL) {
-		fprintf(stderr, "Out of memory in %s\n", __FUNCTION__);
-		exit(-1);
+		return NULL;
 	}
 	gfs2_dinode_in(&ip->i_di, bh);
 	ip->i_bh = bh;
 	ip->i_sbd = sdp;
-	ip->bh_owned = 0; /* caller did the bread so we don't own the bh */
 	return ip;
 }
 
-struct gfs2_inode *inode_read(struct gfs2_sbd *sdp, uint64_t di_addr)
+struct gfs2_inode *lgfs2_inode_read(struct gfs2_sbd *sdp, uint64_t di_addr)
 {
 	struct gfs2_inode *ip;
-
-	ip = calloc(1, sizeof(struct gfs2_inode));
+	struct gfs2_buffer_head *bh = bread(sdp, di_addr);
+	if (bh == NULL) {
+		return NULL;
+	}
+	ip = lgfs2_inode_get(sdp, bh);
 	if (ip == NULL) {
-		fprintf(stderr, "Out of memory in %s\n", __FUNCTION__);
-		exit(-1);
+		brelse(bh);
+		return NULL;
 	}
-	ip->i_bh = bread(sdp, di_addr);
-	gfs2_dinode_in(&ip->i_di, ip->i_bh);
-	ip->i_sbd = sdp;
 	ip->bh_owned = 1; /* We did the bread so we own the bh */
 	return ip;
 }
@@ -1405,7 +1403,9 @@ static struct gfs2_inode *__createi(struct gfs2_inode *dip,
 
 		bh = __init_dinode(sdp, &inum, mode, flags, &dip->i_di.di_num,
 				   if_gfs1);
-		ip = inode_get(sdp, bh);
+		ip = lgfs2_inode_get(sdp, bh);
+		if (ip == NULL)
+			return NULL;
 		bmodified(bh);
 	}
 	ip->bh_owned = 1;
@@ -1764,7 +1764,7 @@ int gfs2_lookupi(struct gfs2_inode *dip, const char *filename, int len,
 			return 0;
 	}
 	else
-		*ipp = inode_read(sdp, inum.no_addr);
+		*ipp = lgfs2_inode_read(sdp, inum.no_addr);
 
 	return error;
 }
@@ -1808,7 +1808,11 @@ int gfs2_freedi(struct gfs2_sbd *sdp, uint64_t diblock)
 		osi_list_init(&metalist[h]);
 
 	bh = bread(sdp, diblock);
-	ip = inode_get(sdp, bh);
+	if (bh == NULL)
+		return -1;
+	ip = lgfs2_inode_get(sdp, bh);
+	if (ip == NULL)
+		return -1;
 	height = ip->i_di.di_height;
 	osi_list_add(&bh->b_altlist, &metalist[0]);
 
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 09f0b1d..9b128ff 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -425,9 +425,9 @@ extern struct metapath *find_metapath(struct gfs2_inode *ip, uint64_t block);
 extern void lookup_block(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
 			 unsigned int height, struct metapath *mp,
 			 int create, int *new, uint64_t *block);
-extern struct gfs2_inode *inode_get(struct gfs2_sbd *sdp,
+extern struct gfs2_inode *lgfs2_inode_get(struct gfs2_sbd *sdp,
 				    struct gfs2_buffer_head *bh);
-extern struct gfs2_inode *inode_read(struct gfs2_sbd *sdp, uint64_t di_addr);
+extern struct gfs2_inode *lgfs2_inode_read(struct gfs2_sbd *sdp, uint64_t di_addr);
 extern struct gfs2_inode *is_system_inode(struct gfs2_sbd *sdp,
 					  uint64_t block);
 extern void inode_put(struct gfs2_inode **ip);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 0c22b01..645c45a 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -26,7 +26,9 @@ int build_master(struct gfs2_sbd *sdp)
 
 	bh = init_dinode(sdp, &inum, S_IFDIR | 0755, GFS2_DIF_SYSTEM, &inum);
 	
-	sdp->master_dir = inode_get(sdp, bh);
+	sdp->master_dir = lgfs2_inode_get(sdp, bh);
+	if (sdp->master_dir == NULL)
+		return -1;
 
 	if (sdp->debug) {
 		printf("\nMaster dir:\n");
@@ -429,7 +431,9 @@ int build_root(struct gfs2_sbd *sdp)
 	inum.no_addr = bn;
 
 	bh = init_dinode(sdp, &inum, S_IFDIR | 0755, 0, &inum);
-	sdp->md.rooti = inode_get(sdp, bh);
+	sdp->md.rooti = lgfs2_inode_get(sdp, bh);
+	if (sdp->md.rooti == NULL)
+		return -1;
 
 	if (sdp->debug) {
 		printf("\nRoot directory:\n");
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 3fe08a1..7bcfce2 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -376,8 +376,11 @@ main_grow(int argc, char *argv[])
 			die( _("GFS2 rindex not found.  Please run gfs2_fsck.\n"));
 		}
 		/* Get master dinode */
-		sdp->master_dir =
-			inode_read(sdp, sdp->sd_sb.sb_master_dir.no_addr);
+		sdp->master_dir = lgfs2_inode_read(sdp, sdp->sd_sb.sb_master_dir.no_addr);
+		if (sdp->master_dir == NULL) {
+			perror("Could not read master");
+			exit(EXIT_FAILURE);
+		}
 		gfs2_lookupi(sdp->master_dir, "rindex", 6, &sdp->md.riinode);
 		/* Fetch the rindex from disk.  We aren't using gfs2 here,  */
 		/* which means that the bitmaps will most likely be cached  */
-- 
1.7.11.4




More information about the Cluster-devel mailing list