Skip to contentSkip to conversation

gfs2_edit: Initialize metafds fully in savemetaopen

PATCH New Andrew Price 3 participants 7 messages Sep 6, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 gfs2_edit: Initialize metafds fully in savemetaopen

Coverity showed that savemetaopen() can return a metafd without initializing the gzfd member. This isn't currently a problem as we only use gzfd when it is set but this patch initializes the metafd fully to avoid future problems.

---
 gfs2/edit/savemeta.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
gfs2/edit/savemeta.c +1 -2
index 3a0e45e..9e5d111 100644
@@ -211,7 +211,7 @@ static void warm_fuzzy_stuff(uint64_t wfsblock, int force)
  */
 static struct metafd savemetaopen(char *out_fn, int gziplevel)
 {
-	struct metafd mfd;
+	struct metafd mfd = {-1, NULL, NULL, gziplevel};
 	char gzmode[3] = "w9";
 	char dft_fn[] = DFT_SAVE_FILE;
 
@@ -233,7 +233,6 @@ static struct metafd savemetaopen(char *out_fn, int gziplevel)
 		exit(1);
 	}
 
-	mfd.gziplevel = gziplevel;
 	if (gziplevel > 0) {
 		gzmode[1] = '0' + gziplevel;
 		mfd.gzfd = gzdopen(mfd.fd, gzmode);
Signature · 1 line
1.7.6
#1 lore raw

PATCH 2/5 libgfs2: clean up some dead code in gfs2_writei

This patch cleans up an error variable which was initialized to 0 and then never changed, and a 'fail' section which could be replaced by a return. It also removes the 'out' label which was only referenced from the dead if-statement in the 'fail' section.

---
 gfs2/libgfs2/gfs1.c |   11 +----------
 1 files changed, 1 insertions(+), 10 deletions(-)
gfs2/libgfs2/gfs1.c +1 -10
index 2bd5282..4549959 100644
@@ -181,11 +181,9 @@ int gfs1_writei(struct gfs2_inode *ip, char *buf, uint64_t offset,
 	int journaled = fs_is_jdata(ip);
 	const uint64_t start = offset;
 	int copied = 0;
-	int error = 0;
 
 	if (!size)
-		goto fail;  /*  Not really an error  */
-
+		return 0;
 
 	if (!ip->i_di.di_height && /* stuffed */
 	    ((start + size) > (sdp->bsize - sizeof(struct gfs_dinode))))
@@ -243,7 +241,6 @@ int gfs1_writei(struct gfs2_inode *ip, char *buf, uint64_t offset,
 		offset = (journaled) ? sizeof(struct gfs2_meta_header) : 0;
 	}
 
- out:
 	if (ip->i_di.di_size < start + copied) {
 		bmodified(ip->i_bh);
 		ip->i_di.di_size = start + copied;
@@ -253,12 +250,6 @@ int gfs1_writei(struct gfs2_inode *ip, char *buf, uint64_t offset,
 	gfs2_dinode_out(&ip->i_di, ip->i_bh);
 
 	return copied;
-
- fail:
-	if (copied)
-		goto out;
-
-	return error;
 }
 
 /* ------------------------------------------------------------------------ */
Signature · 1 line
1.7.6
#2 lore raw

PATCH 3/5 libgfs2: Remove dead code from gfs2_get_leaf

In reply to Andrew Price

The value of error is always 0 when this if statement is reached. This patch removes it.

---
 gfs2/libgfs2/fs_ops.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
gfs2/libgfs2/fs_ops.c +0 -2
index c778564..d344bc4 100644
@@ -1032,8 +1032,6 @@ int gfs2_get_leaf(struct gfs2_inode *dip, uint64_t leaf_no,
 	int error = 0;
 
 	*bhp = bread(dip->i_sbd, leaf_no);
-	if (error)
-		return error;
 	error = gfs2_check_meta(*bhp, GFS2_METATYPE_LF);
 	if(error)
 		brelse(*bhp);
Signature · 1 line
1.7.6
#3 lore raw

PATCH 4/5 gfs_controld: Remove dead code from loop()

In reply to Andrew Price

This patch removes an if statement where the true branch is never taken. At this point in the code, poll_timeout could only be 500 or -1.

---
 group/gfs_controld/main.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
group/gfs_controld/main.c +0 -3
index 252965a..aa38839 100644
@@ -1286,9 +1286,6 @@ static void loop(void)
 			if (dmsetup_wait) {
 				if (poll_timeout == -1)
 					poll_timeout = 1000;
-			} else {
-				if (poll_timeout == 1000)
-					poll_timeout = -1;
 			}
 		}
 		query_unlock();
Signature · 1 line
1.7.6
#4 lore raw

PATCH 4/5 gfs_controld: Remove dead code from loop()

Hi,

Those all look good to me,

Steve.

Quoted 22 lines · Andrew Price

This patch removes an if statement where the true branch is never taken. At this point in the code, poll_timeout could only be 500 or -1.

---
 group/gfs_controld/main.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
group/gfs_controld/main.c +0 -3
index 252965a..aa38839 100644
@@ -1286,9 +1286,6 @@ static void loop(void)
 			if (dmsetup_wait) {
 				if (poll_timeout == -1)
 					poll_timeout = 1000;
-			} else {
-				if (poll_timeout == 1000)
-					poll_timeout = -1;
 			}
 		}
 		query_unlock();
#5 lore raw

PATCH 4/5 gfs_controld: Remove dead code from loop()

In reply to Andrew Price
Quoted 13 lines · Andrew Price

This patch removes an if statement where the true branch is never taken. At this point in the code, poll_timeout could only be 500 or -1.

---
 group/gfs_controld/main.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
group/gfs_controld/main.c +0 -0
index 252965a..aa38839 100644

group/gfs_controld/main.c static void loop(void) · line 1291

Quoted 6 lines
group/gfs_controld/main.c +0 -3
@@ -1286,9 +1286,6 @@ static void loop(void)
 			if (dmsetup_wait) {
 				if (poll_timeout == -1)
 					poll_timeout = 1000;
-			} else {
-				if (poll_timeout == 1000)
-					poll_timeout = -1;

ok

Quoted 5 lines
group/gfs_controld/main.c +0 -0
 			}
 		}
 		query_unlock();
Signature · 1 line
1.7.6
#6 lore raw

PATCH 5/5 gfs2_edit: Fix segfault in find by resource group

In reply to Andrew Price

When using 'find' on block types which require searching by resource group, a segfault occurs in __gfs2_next_rg_meta due to rgd->bh being empty. This patch fixes the segfault by reading in the resource group data, thus populating rgd->bh, prior to the search.

---
 gfs2/edit/hexedit.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
gfs2/edit/hexedit.c +5 -1
index 2182704..dd0cf60 100644
@@ -2056,7 +2056,7 @@ static uint64_t find_metablockoftype_slow(uint64_t startblk, int metatype, int p
 static uint64_t find_metablockoftype_rg(uint64_t startblk, int metatype, int print)
 {
 	struct osi_node *n, *next = NULL;
-	uint64_t blk;
+	uint64_t blk, errblk;
 	int first = 1, found = 0;
 	struct rgrp_tree *rgd;
 	struct gfs2_rindex *ri;
@@ -2087,6 +2087,9 @@ static uint64_t find_metablockoftype_rg(uint64_t startblk, int metatype, int pri
 	for (; !found && n; n = next){
 		next = osi_next(n);
 		rgd = (struct rgrp_tree *)n;
+		errblk = gfs2_rgrp_read(&sbd, rgd);
+		if (errblk)
+			continue;
 		first = 1;
 		do {
 			if (gfs2_next_rg_metatype(&sbd, rgd, &blk, metatype,
@@ -2098,6 +2101,7 @@ static uint64_t find_metablockoftype_rg(uint64_t startblk, int metatype, int pri
 			}
 			first = 0;
 		} while (blk <= startblk);
+		gfs2_rgrp_relse(rgd);
 	}
 	if (!found)
 		blk = 0;
Signature · 1 line
1.7.6