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

[Cluster-devel] [PATCH 1/7] libgfs2: Remove another exit() call



gfs2_get_leaf_nr was another one of those libgfs2 functions which called
exit instead of returning an error value. This updates it with a new
function which does so.

Signed-off-by: Andrew Price <anprice redhat com>
---
 gfs2/edit/savemeta.c   |  6 +++++-
 gfs2/fsck/pass2.c      |  5 ++++-
 gfs2/libgfs2/fs_ops.c  | 35 ++++++++++++++++++-----------------
 gfs2/libgfs2/libgfs2.h |  3 +--
 4 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index b4c85d6..c38c5ac 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -543,7 +543,11 @@ static void save_inode_data(struct metafd *mfd)
 		int li;
 
 		for (li = 0; li < (1 << inode->i_di.di_depth); li++) {
-			gfs2_get_leaf_nr(inode, li, &leaf_no);
+			if (!lgfs2_get_leaf_ptr(inode, li, &leaf_no)) {
+				fprintf(stderr, "Could not read leaf index %d in dinode %"PRIu64"\n", li,
+				        (uint64_t)inode->i_di.di_num.no_addr);
+				exit(-1);
+			}
 			if (leaf_no == old_leaf ||
 			    gfs2_check_range(&sbd, leaf_no) != 0)
 				continue;
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index d3b56fc..9fd5be2 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -369,7 +369,10 @@ static int wrong_leaf(struct gfs2_inode *ip, struct gfs2_inum *entry,
 		    de->de_type) == 0) {
 		log_err(_("The misplaced directory entry was moved to a "
 			  "valid leaf block.\n"));
-		gfs2_get_leaf_nr(ip, hash_index, &real_leaf);
+		if (!lgfs2_get_leaf_ptr(ip, hash_index, &real_leaf)) {
+			log_err(_("Could not read leaf %d in dinode %"PRIu64": %s\n"), hash_index,
+			        (uint64_t)ip->i_di.di_num.no_addr, strerror(errno));
+		}
 		if (real_leaf != planned_leaf) {
 			log_err(_("The planned leaf was split. The new leaf "
 				  "is: %llu (0x%llx). di_blocks=%llu\n"),
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index f59f014..198f6eb 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -25,7 +25,7 @@ static __inline__ uint64_t *metapointer(struct gfs2_buffer_head *bh,
 }
 
 /* Detect directory is a stuffed inode */
-static int inode_is_stuffed(struct gfs2_inode *ip)
+static int inode_is_stuffed(const struct gfs2_inode *ip)
 {
 	return !ip->i_di.di_height;
 }
@@ -819,20 +819,15 @@ void dirent2_del(struct gfs2_inode *dip, struct gfs2_buffer_head *bh,
 	prev->de_rec_len = cpu_to_be16(prev_rec_len);
 }
 
-void gfs2_get_leaf_nr(struct gfs2_inode *dip, uint32_t lindex,
-		      uint64_t *leaf_out)
+int lgfs2_get_leaf_ptr(struct gfs2_inode *dip, const uint32_t lindex, uint64_t *ptr)
 {
 	uint64_t leaf_no;
-	int count;
-
-	count = gfs2_readi(dip, (char *)&leaf_no, lindex * sizeof(uint64_t),
-			   sizeof(uint64_t));
-	if (count != sizeof(uint64_t)) {
-		fprintf(stderr, "gfs2_get_leaf_nr:  Bad internal read.\n");
-		exit(1);
-	}
+	int count = gfs2_readi(dip, (char *)&leaf_no, lindex * sizeof(uint64_t), sizeof(uint64_t));
+	if (count != sizeof(uint64_t))
+		return -1;
 
-	*leaf_out = be64_to_cpu(leaf_no);
+	*ptr = be64_to_cpu(leaf_no);
+	return 0;
 }
 
 void dir_split_leaf(struct gfs2_inode *dip, uint32_t start, uint64_t leaf_no,
@@ -1034,13 +1029,15 @@ int gfs2_get_leaf(struct gfs2_inode *dip, uint64_t leaf_no,
  * Returns: 0 on success, error code otherwise
  */
 
-static int get_first_leaf(struct gfs2_inode *dip, uint32_t lindex,
-			  struct gfs2_buffer_head **bh_out)
+static int get_first_leaf(struct gfs2_inode *dip, uint32_t lindex, struct gfs2_buffer_head **bh_out)
 {
 	uint64_t leaf_no;
 
-	gfs2_get_leaf_nr(dip, lindex, &leaf_no);
+	if (lgfs2_get_leaf_ptr(dip, lindex, &leaf_no) != 0)
+		return -1;
 	*bh_out = bread(dip->i_sbd, leaf_no);
+	if (*bh_out == NULL)
+		return -1;
 	return 0;
 }
 
@@ -1085,7 +1082,9 @@ restart:
 	else
 		lindex = 0;
 
-	gfs2_get_leaf_nr(dip, lindex, &leaf_no);
+	err = lgfs2_get_leaf_ptr(dip, lindex, &leaf_no);
+	if (err)
+		return err;
 
 	for (;;) {
 		bh = bread(dip->i_sbd, leaf_no);
@@ -1630,7 +1629,9 @@ static int dir_e_del(struct gfs2_inode *dip, const char *filename, int len)
 	lindex = (1 << (dip->i_di.di_depth))-1;
 
 	for(; (lindex >= 0) && !found; lindex--){
-		gfs2_get_leaf_nr(dip, lindex, &leaf_no);
+		error = lgfs2_get_leaf_ptr(dip, lindex, &leaf_no);
+		if (error)
+			return error;
 
 		while(leaf_no && !found){
 			bh = bread(dip->i_sbd, leaf_no);
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 6372128..6248e4b 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -479,8 +479,7 @@ extern int gfs2_dirent_del(struct gfs2_inode *dip, const char *filename,
 			   int filename_len);
 extern void block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
 		      uint64_t *dblock, uint32_t *extlen, int prealloc);
-extern void gfs2_get_leaf_nr(struct gfs2_inode *dip, uint32_t index,
-			     uint64_t *leaf_out);
+extern int lgfs2_get_leaf_ptr(struct gfs2_inode *dip, uint32_t index, uint64_t *ptr) __attribute__((warn_unused_result));
 extern void dir_split_leaf(struct gfs2_inode *dip, uint32_t start,
 			   uint64_t leaf_no, struct gfs2_buffer_head *obh);
 extern void gfs2_free_block(struct gfs2_sbd *sdp, uint64_t block);
-- 
1.8.5.3


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