[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH] gfs2_utils: More error handling improvements



Remove a call to die() from dir_e_add() and return an error code
instead. Check the error code up the call tree and add more
context-specific error reporting in the applications.

Signed-off-by: Andrew Price <anprice redhat com>
---
 gfs2/convert/gfs2_convert.c |   47 ++++++++++++--
 gfs2/fsck/initialize.c      |  143 +++++++++++++++++++++++++++++++++++--------
 gfs2/fsck/lost_n_found.c    |   22 ++++++-
 gfs2/fsck/pass1.c           |    7 ++-
 gfs2/fsck/pass2.c           |   14 ++++-
 gfs2/fsck/pass3.c           |    9 ++-
 gfs2/libgfs2/fs_ops.c       |   33 +++++++---
 gfs2/libgfs2/libgfs2.h      |    2 +-
 gfs2/libgfs2/structures.c   |   49 ++++++++++++++-
 gfs2/mkfs/main_mkfs.c       |   36 +++++++++--
 10 files changed, 299 insertions(+), 63 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 64dfe32..77103f3 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -1888,12 +1888,15 @@ static void remove_obsolete_gfs1(struct gfs2_sbd *sbp)
 /* ------------------------------------------------------------------------- */
 /* lifted from libgfs2/structures.c                                          */
 /* ------------------------------------------------------------------------- */
-static void conv_build_jindex(struct gfs2_sbd *sdp)
+static int conv_build_jindex(struct gfs2_sbd *sdp)
 {
 	unsigned int j;
 
 	sdp->md.jiinode = createi(sdp->master_dir, "jindex", S_IFDIR | 0700,
 				  GFS2_DIF_SYSTEM);
+	if (sdp->md.jiinode == NULL) {
+		return errno;
+	}
 
 	sdp->md.journal = malloc(sdp->md.journals *
 				 sizeof(struct gfs2_inode *));
@@ -1919,6 +1922,7 @@ static void conv_build_jindex(struct gfs2_sbd *sdp)
 	}
 
 	inode_put(&sdp->md.jiinode);
+	return 0;
 }
 
 static unsigned int total_file_blocks(struct gfs2_sbd *sdp, 
@@ -2210,19 +2214,48 @@ int main(int argc, char **argv)
 		build_master(&sb2); /* Does not do inode_put */
 		sb2.sd_sb.sb_master_dir = sb2.master_dir->i_di.di_num;
 		/* Build empty journal index file. */
-		conv_build_jindex(&sb2);
+		error = conv_build_jindex(&sb2);
+		if (error) {
+			log_crit("Error: could not build jindex: %s\n", strerror(error));
+			exit(-1);
+		}
 		log_notice("Building GFS2 file system structures.\n");
 		/* Build the per-node directories */
-		build_per_node(&sb2);
+		error = build_per_node(&sb2);
+		if (error) {
+			log_crit("Error building per-node directories: %s\n",
+			         strerror(error));
+			exit(-1);
+		}
 		/* Create the empty inode number file */
-		build_inum(&sb2); /* Does not do inode_put */
+		error = build_inum(&sb2); /* Does not do inode_put */
+		if (error) {
+			log_crit("Error building inum inode: %s\n",
+			         strerror(error));
+			exit(-1);
+		}
 		/* Create the statfs file */
-		build_statfs(&sb2); /* Does not do inode_put */
+		error = build_statfs(&sb2); /* Does not do inode_put */
+		if (error) {
+			log_crit("Error building statfs inode: %s\n",
+			         strerror(error));
+			exit(-1);
+		}
 
 		/* Create the resource group index file */
-		build_rindex(&sb2);
+		error = build_rindex(&sb2);
+		if (error) {
+			log_crit("Error building rindex inode: %s\n",
+			         strerror(error));
+			exit(-1);
+		}
 		/* Create the quota file */
-		build_quota(&sb2);
+		error = build_quota(&sb2);
+		if (error) {
+			log_crit("Error building quota inode: %s\n",
+			         strerror(error));
+			exit(-1);
+		}
 
 		/* Copy out the master dinode */
 		{
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index 9fe7776..c5dc7ef 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -320,6 +320,7 @@ static int rebuild_master(struct gfs2_sbd *sdp)
 {
 	struct gfs2_inum inum;
 	struct gfs2_buffer_head *bh;
+	int err = 0;
 
 	log_err(_("The system master directory seems to be destroyed.\n"));
 	if (!query(_("Okay to rebuild it? (y/n)"))) {
@@ -336,57 +337,110 @@ static int rebuild_master(struct gfs2_sbd *sdp)
 	if (fix_md.jiinode) {
 		inum.no_formal_ino = sdp->md.next_inum++;
 		inum.no_addr = fix_md.jiinode->i_di.di_num.no_addr;
-		dir_add(sdp->master_dir, "jindex", 6, &inum,
-			IF2DT(S_IFDIR | 0700));
+		err = dir_add(sdp->master_dir, "jindex", 6, &inum,
+		              IF2DT(S_IFDIR | 0700));
+		if (err) {
+			log_crit(_("Error adding jindex directory: %s\n"), strerror(err));
+			exit(-1);
+		}
 		sdp->master_dir->i_di.di_nlink++;
 	} else {
-		build_jindex(sdp);
+		err = build_jindex(sdp);
+		if (err) {
+			log_crit(_("Error building jindex: %s\n"), strerror(err));
+			exit(-1);
+		}
 	}
 
 	if (fix_md.pinode) {
 		inum.no_formal_ino = sdp->md.next_inum++;
 		inum.no_addr = fix_md.pinode->i_di.di_num.no_addr;
-		dir_add(sdp->master_dir, "per_node", 8, &inum,
+		err = dir_add(sdp->master_dir, "per_node", 8, &inum,
 			IF2DT(S_IFDIR | 0700));
+		if (err) {
+			log_crit(_("Error adding per_node directory: %s\n"), strerror(err));
+			exit(-1);
+		}
 		sdp->master_dir->i_di.di_nlink++;
 	} else {
-		build_per_node(sdp);
+		err = build_per_node(sdp);
+		if (err) {
+			log_crit(_("Error building per_node directory: %s\n"),
+			         strerror(err));
+			exit(-1);
+		}
 	}
 
 	if (fix_md.inum) {
 		inum.no_formal_ino = sdp->md.next_inum++;
 		inum.no_addr = fix_md.inum->i_di.di_num.no_addr;
-		dir_add(sdp->master_dir, "inum", 4, &inum,
+		err = dir_add(sdp->master_dir, "inum", 4, &inum,
 			IF2DT(S_IFREG | 0600));
+		if (err) {
+			log_crit(_("Error adding inum inode: %s\n"), strerror(err));
+			exit(-1);
+		}
 	} else {
-		build_inum(sdp);
+		err = build_inum(sdp);
+		if (err) {
+			log_crit(_("Error building inum inode: %s\n"),
+			         strerror(err));
+			exit(-1);
+		}
 	}
 
 	if (fix_md.statfs) {
 		inum.no_formal_ino = sdp->md.next_inum++;
 		inum.no_addr = fix_md.statfs->i_di.di_num.no_addr;
-		dir_add(sdp->master_dir, "statfs", 6, &inum,
+		err = dir_add(sdp->master_dir, "statfs", 6, &inum,
 			IF2DT(S_IFREG | 0600));
+		if (err) {
+			log_crit(_("Error adding statfs inode: %s\n"), strerror(err));
+			exit(-1);
+		}
 	} else {
-		build_statfs(sdp);
+		err = build_statfs(sdp);
+		if (err) {
+			log_crit(_("Error building statfs inode: %s\n"),
+			         strerror(err));
+			exit(-1);
+		}
 	}
 
 	if (fix_md.riinode) {
 		inum.no_formal_ino = sdp->md.next_inum++;
 		inum.no_addr = fix_md.riinode->i_di.di_num.no_addr;
-		dir_add(sdp->master_dir, "rindex", 6, &inum,
+		err = dir_add(sdp->master_dir, "rindex", 6, &inum,
 			IF2DT(S_IFREG | 0600));
+		if (err) {
+			log_crit(_("Error adding rindex inode: %s\n"), strerror(err));
+			exit(-1);
+		}
 	} else {
-		build_rindex(sdp);
+		err = build_rindex(sdp);
+		if (err) {
+			log_crit(_("Error building rindex inode: %s\n"),
+			         strerror(err));
+			exit(-1);
+		}
 	}
 
 	if (fix_md.qinode) {
 		inum.no_formal_ino = sdp->md.next_inum++;
 		inum.no_addr = fix_md.qinode->i_di.di_num.no_addr;
-		dir_add(sdp->master_dir, "quota", 5, &inum,
+		err = dir_add(sdp->master_dir, "quota", 5, &inum,
 			IF2DT(S_IFREG | 0600));
+		if (err) {
+			log_crit(_("Error adding quota inode: %s\n"), strerror(err));
+			exit(-1);
+		}
 	} else {
-		build_quota(sdp);
+		err = build_quota(sdp);
+		if (err) {
+			log_crit(_("Error building quota inode: %s\n"),
+			         strerror(err));
+			exit(-1);
+		}
 	}
 
 	log_err(_("Master directory rebuilt.\n"));
@@ -404,7 +458,7 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 	uint64_t inumbuf;
 	char *buf;
 	struct gfs2_statfs_change sc;
-	int rgcount, sane = 1;
+	int rgcount, sane = 1, err = 0;
 	enum rgindex_trust_level trust_lvl;
 	uint64_t addl_mem_needed;
 	const char *level_desc[] = {
@@ -434,8 +488,14 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 	gfs2_lookupi(sdp->master_dir, "rindex", 6, &sdp->md.riinode);
 	if (!sdp->md.riinode) {
 		if (query( _("The gfs2 system rindex inode is missing. "
-			     "Okay to rebuild it? (y/n) ")))
-			build_rindex(sdp);
+			     "Okay to rebuild it? (y/n) "))) {
+			err = build_rindex(sdp);
+			if (err) {
+				log_crit(_("Error rebuilding rindex: %s\n"),
+				         strerror(err));
+				exit(-1);
+			}
+		}
 	}
 
 	/*******************************************************************
@@ -447,8 +507,14 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 	gfs2_lookupi(sdp->master_dir, "jindex", 6, &sdp->md.jiinode);
 	if (!sdp->md.jiinode) {
 		if (query( _("The gfs2 system jindex inode is missing. "
-			     "Okay to rebuild it? (y/n) ")))
-			build_jindex(sdp);
+			     "Okay to rebuild it? (y/n) "))) {
+			err = build_jindex(sdp);
+			if (err) {
+				log_crit(_("Error rebuilding jindex: %s\n"),
+				         strerror(err));
+				exit(-1);
+			}
+		}
 	}
 
 	/* read in the ji data */
@@ -491,8 +557,14 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 	gfs2_lookupi(sdp->master_dir, "inum", 4, &sdp->md.inum);
 	if (!sdp->md.inum) {
 		if (query( _("The gfs2 system inum inode is missing. "
-			     "Okay to rebuild it? (y/n) ")))
-			build_inum(sdp);
+			     "Okay to rebuild it? (y/n) "))) {
+			err = build_inum(sdp);
+			if (err) {
+				log_crit(_("Error rebuilding inum inode: %s\n"),
+				         strerror(err));
+				exit(-1);
+			}
+		}
 	}
 	/* Read inum entry into buffer */
 	gfs2_readi(sdp->md.inum, &inumbuf, 0, sdp->md.inum->i_di.di_size);
@@ -502,9 +574,14 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 	gfs2_lookupi(sdp->master_dir, "statfs", 6, &sdp->md.statfs);
 	if (!sdp->md.statfs) {
 		if (query( _("The gfs2 system statfs inode is missing. "
-			     "Okay to rebuild it? (y/n) ")))
-			build_statfs(sdp);
-		else {
+			     "Okay to rebuild it? (y/n) "))) {
+			err = build_statfs(sdp);
+			if (err) {
+				log_crit(_("Error rebuilding statfs inode: %s\n"),
+				         strerror(err));
+				exit(-1);
+			}
+		} else {
 			log_err( _("fsck.gfs2 cannot continue without a "
 				   "valid statfs file; aborting.\n"));
 			return FSCK_ERROR;
@@ -520,15 +597,27 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 	gfs2_lookupi(sdp->master_dir, "quota", 5, &sdp->md.qinode);
 	if (!sdp->md.qinode) {
 		if (query( _("The gfs2 system quota inode is missing. "
-			     "Okay to rebuild it? (y/n) ")))
-			build_quota(sdp);
+			     "Okay to rebuild it? (y/n) "))) {
+			err = build_quota(sdp);
+			if (err) {
+				log_crit(_("Error rebuilding quota inode: %s\n"),
+				         strerror(err));
+				exit(-1);
+			}
+		}
 	}
 
 	gfs2_lookupi(sdp->master_dir, "per_node", 8, &sdp->md.pinode);
 	if (!sdp->md.pinode) {
 		if (query( _("The gfs2 system per_node directory inode is "
-			     "missing. Okay to rebuild it? (y/n) ")))
-			build_per_node(sdp);
+			     "missing. Okay to rebuild it? (y/n) "))) {
+			err = build_per_node(sdp);
+			if (err) {
+				log_crit(_("Error rebuilding per_node directory: %s\n"),
+				         strerror(err));
+				exit(-1);
+			}
+		}
 	}
 
 	/* FIXME fill in per_node structure */
diff --git a/gfs2/fsck/lost_n_found.c b/gfs2/fsck/lost_n_found.c
index 2fcae00..aea48c5 100644
--- a/gfs2/fsck/lost_n_found.c
+++ b/gfs2/fsck/lost_n_found.c
@@ -32,6 +32,7 @@ int add_inode_to_lf(struct gfs2_inode *ip){
 	uint64_t lf_blocks;
 	struct gfs2_sbd *sdp = ip->i_sbd;
 	struct dir_info *di;
+	int err = 0;
 
 	if(!lf_dip) {
 		uint8_t q;
@@ -40,6 +41,12 @@ int add_inode_to_lf(struct gfs2_inode *ip){
 
 		lf_dip = createi(sdp->md.rooti, "lost+found",
 				 S_IFDIR | 0700, 0);
+		if (lf_dip == NULL) {
+			log_crit(_("Error creating lost+found: %s\n"),
+			         strerror(errno));
+			exit(-1);
+		}
+
 		/* createi will have incremented the di_nlink link count for
 		   the root directory.  We must increment the nlink value
 		   in the hash table to keep them in sync so that pass4 can
@@ -135,7 +142,13 @@ int add_inode_to_lf(struct gfs2_inode *ip){
 			log_warn( _("add_inode_to_lf:  Unable to remove "
 				    "\"..\" directory entry.\n"));
 
-		dir_add(ip, "..", 2, &(lf_dip->i_di.di_num), DT_DIR);
+		err = dir_add(ip, "..", 2, &(lf_dip->i_di.di_num), DT_DIR);
+		if (err) {
+			log_crit(_("Error adding .. directory: %s\n"),
+			         strerror(errno));
+			exit(-1);
+		}
+
 		sprintf(tmp_name, "lost_dir_%llu",
 			(unsigned long long)ip->i_di.di_num.no_addr);
 		inode_type = DT_DIR;
@@ -177,8 +190,13 @@ int add_inode_to_lf(struct gfs2_inode *ip){
 		break;
 	}
 
-	dir_add(lf_dip, tmp_name, strlen(tmp_name), &(ip->i_di.di_num),
+	err = dir_add(lf_dip, tmp_name, strlen(tmp_name), &(ip->i_di.di_num),
 		inode_type);
+	if (err) {
+		log_crit(_("Error adding directory %s: %s\n"),
+			 tmp_name, strerror(errno));
+		exit(-1);
+	}
 	/* If the lf directory had new blocks added we have to mark them
 	   properly in the bitmap so they're not freed. */
 	if (lf_dip->i_di.di_blocks != lf_blocks)
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 0134941..002a781 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1280,12 +1280,17 @@ static int check_system_inode(struct gfs2_sbd *sdp,
 static int build_a_journal(struct gfs2_sbd *sdp)
 {
 	char name[256];
+	int err = 0;
 
 	/* First, try to delete the journal if it's in jindex */
 	sprintf(name, "journal%u", sdp->md.journals);
 	gfs2_dirent_del(sdp->md.jiinode, name, strlen(name));
 	/* Now rebuild it */
-	build_journal(sdp, sdp->md.journals, sdp->md.jiinode);
+	err = build_journal(sdp, sdp->md.journals, sdp->md.jiinode);
+	if (err) {
+		log_crit(_("Error building journal: %s\n"), strerror(err));
+		exit(-1);
+	}
 	return 0;
 }
 
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 5379ec7..d0d67ed 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -591,8 +591,13 @@ static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,
 			}
 			memcpy(filename, tmp_name, filename_len);
 			log_warn( _("Adding '.' entry\n"));
-			dir_add(sysinode, filename, filename_len,
+			error = dir_add(sysinode, filename, filename_len,
 				&(sysinode->i_di.di_num), DT_DIR);
+			if (error) {
+				log_err(_("Error adding directory %s: %s\n"),
+				        filename, strerror(error));
+				return -error;
+			}
 			if (cur_blks != sysinode->i_di.di_blocks)
 				reprocess_inode(sysinode, dirname);
 			/* This system inode is linked to itself via '.' */
@@ -798,8 +803,13 @@ int pass2(struct gfs2_sbd *sbp)
 				memcpy(filename, tmp_name, filename_len);
 
 				cur_blks = ip->i_di.di_blocks;
-				dir_add(ip, filename, filename_len,
+				error = dir_add(ip, filename, filename_len,
 					&(ip->i_di.di_num), DT_DIR);
+				if (error) {
+					log_err(_("Error adding directory %s: %s\n"),
+					        filename, strerror(error));
+					return -error;
+				}
 				if (cur_blks != ip->i_di.di_blocks) {
 					char dirname[80];
 
diff --git a/gfs2/fsck/pass3.c b/gfs2/fsck/pass3.c
index 6c6099c..93514be 100644
--- a/gfs2/fsck/pass3.c
+++ b/gfs2/fsck/pass3.c
@@ -20,7 +20,7 @@ static int attach_dotdot_to(struct gfs2_sbd *sbp, uint64_t newdotdot,
 			    uint64_t olddotdot, uint64_t block)
 {
 	char *filename;
-	int filename_len;
+	int filename_len, err;
 	struct gfs2_inode *ip, *pip;
 	uint64_t cur_blks;
 
@@ -54,7 +54,12 @@ static int attach_dotdot_to(struct gfs2_sbd *sbp, uint64_t newdotdot,
 	else
 		decrement_link(olddotdot, block, _("old \"..\""));
 	cur_blks = ip->i_di.di_blocks;
-	dir_add(ip, filename, filename_len, &pip->i_di.di_num, DT_DIR);
+	err = dir_add(ip, filename, filename_len, &pip->i_di.di_num, DT_DIR);
+	if (err) {
+		log_err(_("Error adding directory %s: %s\n"),
+		        filename, strerror(err));
+		exit(-1);
+	}
 	if (cur_blks != ip->i_di.di_blocks) {
 		char dirname[80];
 
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 047fcca..60ee467 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -1053,7 +1053,7 @@ static int get_next_leaf(struct gfs2_inode *dip,struct gfs2_buffer_head *bh_in,
 	return 0;
 }
 
-static void dir_e_add(struct gfs2_inode *dip, const char *filename, int len,
+static int dir_e_add(struct gfs2_inode *dip, const char *filename, int len,
 		      struct gfs2_inum *inum, unsigned int type)
 {
 	struct gfs2_buffer_head *bh, *nbh;
@@ -1062,6 +1062,7 @@ static void dir_e_add(struct gfs2_inode *dip, const char *filename, int len,
 	uint32_t lindex;
 	uint32_t hash;
 	uint64_t leaf_no, bn;
+	int err = 0;
 
 	hash = gfs2_disk_hash(filename, len);
 restart:
@@ -1110,8 +1111,9 @@ restart:
 				nleaf->lf_depth = leaf->lf_depth;
 				nleaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE);
 
-				if (dirent_alloc(dip, nbh, len, &dent))
-					die("dir_split_leaf (3)\n");
+				err = dirent_alloc(dip, nbh, len, &dent);
+				if (err)
+					return err;
 				dip->i_di.di_blocks++;
 				bmodified(dip->i_bh);
 				bmodified(bh);
@@ -1131,7 +1133,7 @@ restart:
 
 		bmodified(bh);
 		brelse(bh);
-		return;
+		return err;
 	}
 }
 
@@ -1199,15 +1201,16 @@ static void dir_make_exhash(struct gfs2_inode *dip)
 	bwrite(dip->i_bh);
 }
 
-static void dir_l_add(struct gfs2_inode *dip, const char *filename, int len,
+static int dir_l_add(struct gfs2_inode *dip, const char *filename, int len,
 		      struct gfs2_inum *inum, unsigned int type)
 {
 	struct gfs2_dirent *dent;
+	int err = 0;
 
 	if (dirent_alloc(dip, dip->i_bh, len, &dent)) {
 		dir_make_exhash(dip);
-		dir_e_add(dip, filename, len, inum, type);
-		return;
+		err = dir_e_add(dip, filename, len, inum, type);
+		return err;
 	}
 
 	gfs2_inum_out(inum, (char *)&dent->de_inum);
@@ -1215,15 +1218,18 @@ static void 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);
+	return err;
 }
 
-void dir_add(struct gfs2_inode *dip, const char *filename, int len,
+int dir_add(struct gfs2_inode *dip, const char *filename, int len,
 	     struct gfs2_inum *inum, unsigned int type)
 {
+	int err = 0;
 	if (dip->i_di.di_flags & GFS2_DIF_EXHASH)
-		dir_e_add(dip, filename, len, inum, type);
+		err = dir_e_add(dip, filename, len, inum, type);
 	else
-		dir_l_add(dip, filename, len, inum, type);
+		err = dir_l_add(dip, filename, len, inum, type);
+	return err;
 }
 
 struct gfs2_buffer_head *init_dinode(struct gfs2_sbd *sdp,
@@ -1296,6 +1302,7 @@ struct gfs2_inode *createi(struct gfs2_inode *dip, const char *filename,
 	struct gfs2_inum inum;
 	struct gfs2_buffer_head *bh;
 	struct gfs2_inode *ip;
+	int err = 0;
 
 	gfs2_lookupi(dip, filename, strlen(filename), &ip);
 	if (!ip) {
@@ -1304,7 +1311,11 @@ struct gfs2_inode *createi(struct gfs2_inode *dip, const char *filename,
 		inum.no_formal_ino = sdp->md.next_inum++;
 		inum.no_addr = bn;
 
-		dir_add(dip, filename, strlen(filename), &inum, IF2DT(mode));
+		err = dir_add(dip, filename, strlen(filename), &inum, IF2DT(mode));
+		if (err) {
+			errno = -err;
+			return NULL;
+		}
 
 		if(S_ISDIR(mode)) {
 			bmodified(dip->i_bh);
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 387e8a7..099ba48 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -455,7 +455,7 @@ extern int dir_search(struct gfs2_inode *dip, const char *filename, int len,
 		      unsigned int *type, struct gfs2_inum *inum);
 extern int gfs2_lookupi(struct gfs2_inode *dip, const char *filename, int len,
 			struct gfs2_inode **ipp);
-extern void dir_add(struct gfs2_inode *dip, const char *filename, int len,
+extern int dir_add(struct gfs2_inode *dip, const char *filename, int len,
 		    struct gfs2_inum *inum, unsigned int type);
 extern int gfs2_dirent_del(struct gfs2_inode *dip, const char *filename,
 			   int filename_len);
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index c8a2f50..8b2c9d9 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -138,6 +138,9 @@ int build_journal(struct gfs2_sbd *sdp, int j, struct gfs2_inode *jindex)
 	sprintf(name, "journal%u", j);
 	sdp->md.journal[j] = createi(jindex, name, S_IFREG | 0600,
 				     GFS2_DIF_SYSTEM);
+	if (sdp->md.journal[j] == NULL) {
+		return errno;
+	}
 	ret = write_journal(sdp, j,
 			    sdp->jsize << 20 >> sdp->sd_sb.sb_bsize_shift);
 	return ret;
@@ -151,6 +154,9 @@ int build_jindex(struct gfs2_sbd *sdp)
 
 	jindex = createi(sdp->master_dir, "jindex", S_IFDIR | 0700,
 			 GFS2_DIF_SYSTEM);
+	if (jindex == NULL) {
+		return errno;
+	}
 	sdp->md.journal = malloc(sdp->md.journals *
 				 sizeof(struct gfs2_inode *));
 	for (j = 0; j < sdp->md.journals; j++) {
@@ -178,6 +184,9 @@ static int build_inum_range(struct gfs2_inode *per_node, unsigned int j)
 	sprintf(name, "inum_range%u", j);
 	ip = createi(per_node, name, S_IFREG | 0600,
 		     GFS2_DIF_SYSTEM | GFS2_DIF_JDATA);
+	if (ip == NULL) {
+		return errno;
+	}
 	ip->i_di.di_size = sizeof(struct gfs2_inum_range);
 	gfs2_dinode_out(&ip->i_di, ip->i_bh);
 
@@ -190,7 +199,7 @@ static int build_inum_range(struct gfs2_inode *per_node, unsigned int j)
 	return 0;
 }
 
-static void build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
+static int build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
 {
 	struct gfs2_sbd *sdp = per_node->i_sbd;
 	char name[256];
@@ -199,6 +208,9 @@ static void build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
 	sprintf(name, "statfs_change%u", j);
 	ip = createi(per_node, name, S_IFREG | 0600,
 		     GFS2_DIF_SYSTEM | GFS2_DIF_JDATA);
+	if (ip == NULL) {
+		return errno;
+	}
 	ip->i_di.di_size = sizeof(struct gfs2_statfs_change);
 	gfs2_dinode_out(&ip->i_di, ip->i_bh);
 
@@ -208,6 +220,7 @@ static void build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
 	}
 
 	inode_put(&ip);
+	return 0;
 }
 
 static int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
@@ -228,6 +241,9 @@ static int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
 
 	sprintf(name, "quota_change%u", j);
 	ip = createi(per_node, name, S_IFREG | 0600, GFS2_DIF_SYSTEM);
+	if (ip == NULL) {
+		return errno;
+	}
 
 	hgt = calc_tree_height(ip, (blocks + 1) * sdp->bsize);
 	build_height(ip, hgt);
@@ -255,14 +271,27 @@ int build_per_node(struct gfs2_sbd *sdp)
 {
 	struct gfs2_inode *per_node;
 	unsigned int j;
+	int err;
 
 	per_node = createi(sdp->master_dir, "per_node", S_IFDIR | 0700,
 			   GFS2_DIF_SYSTEM);
+	if (per_node == NULL) {
+		return errno;
+	}
 
 	for (j = 0; j < sdp->md.journals; j++) {
-		build_inum_range(per_node, j);
-		build_statfs_change(per_node, j);
-		build_quota_change(per_node, j);
+		err = build_inum_range(per_node, j);
+		if (err) {
+			return err;
+		}
+		err = build_statfs_change(per_node, j);
+		if (err) {
+			return err;
+		}
+		err = build_quota_change(per_node, j);
+		if (err) {
+			return err;
+		}
 	}
 
 	if (sdp->debug) {
@@ -280,6 +309,9 @@ int build_inum(struct gfs2_sbd *sdp)
 
 	ip = createi(sdp->master_dir, "inum", S_IFREG | 0600,
 		     GFS2_DIF_SYSTEM | GFS2_DIF_JDATA);
+	if (ip == NULL) {
+		return errno;
+	}
 
 	if (sdp->debug) {
 		printf("\nInum Inode:\n");
@@ -296,6 +328,9 @@ int build_statfs(struct gfs2_sbd *sdp)
 
 	ip = createi(sdp->master_dir, "statfs", S_IFREG | 0600,
 		     GFS2_DIF_SYSTEM | GFS2_DIF_JDATA);
+	if (ip == NULL) {
+		return errno;
+	}
 
 	if (sdp->debug) {
 		printf("\nStatFS Inode:\n");
@@ -316,6 +351,9 @@ int build_rindex(struct gfs2_sbd *sdp)
 
 	ip = createi(sdp->master_dir, "rindex", S_IFREG | 0600,
 		     GFS2_DIF_SYSTEM | GFS2_DIF_JDATA);
+	if (ip == NULL) {
+		return errno;
+	}
 	ip->i_di.di_payload_format = GFS2_FORMAT_RI;
 	bmodified(ip->i_bh);
 
@@ -354,6 +392,9 @@ int build_quota(struct gfs2_sbd *sdp)
 
 	ip = createi(sdp->master_dir, "quota", S_IFREG | 0600,
 		     GFS2_DIF_SYSTEM | GFS2_DIF_JDATA);
+	if (ip == NULL) {
+		return errno;
+	}
 	ip->i_di.di_payload_format = GFS2_FORMAT_QU;
 	bmodified(ip->i_bh);
 
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 3cec996..d33a424 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -668,12 +668,36 @@ void main_mkfs(int argc, char *argv[])
 	build_root(sdp);
 	build_master(sdp);
 	build_sb(sdp, uuid);
-	build_jindex(sdp);
-	build_per_node(sdp);
-	build_inum(sdp);
-	build_statfs(sdp);
-	build_rindex(sdp);
-	build_quota(sdp);
+	error = build_jindex(sdp);
+	if (error) {
+		fprintf(stderr, _("Error building jindex: %s\n"), strerror(error));
+		exit(-1);
+	}
+	error = build_per_node(sdp);
+	if (error) {
+		fprintf(stderr, _("Error building per-node directory: %s\n"), strerror(error));
+		exit(-1);
+	}
+	error = build_inum(sdp);
+	if (error) {
+		fprintf(stderr, _("Error building inum inode: %s\n"), strerror(error));
+		exit(-1);
+	}
+	error = build_statfs(sdp);
+	if (error) {
+		fprintf(stderr, _("Error building statfs inode: %s\n"), strerror(error));
+		exit(-1);
+	}
+	error = build_rindex(sdp);
+	if (error) {
+		fprintf(stderr, _("Error building rindex inode: %s\n"), strerror(error));
+		exit(-1);
+	}
+	error = build_quota(sdp);
+	if (error) {
+		fprintf(stderr, _("Error building quota inode: %s\n"), strerror(error));
+		exit(-1);
+	}
 
 	do_init_inum(sdp);
 	do_init_statfs(sdp);
-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]