linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] btrfs-progs: some patches
@ 2012-01-12 15:17 Danny Kukawka
  2012-01-12 15:17 ` [PATCH 1/4] fix segfaults from bnc#710486 Danny Kukawka
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Danny Kukawka @ 2012-01-12 15:17 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Patches to fix some possible segfaults, fix some compiler warnings and
indention.

They are against: 
       git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs.git

@David: I've separated your changes to my patch for the SUSE package
        into an own patch and attached it.
 
Danny Kukawka (3):
  fix segfaults from bnc#710486
  fix some compiler warnings from cgcc
  fix indentation

David Sterba (1):
  return error code from change/get_label_unmounted

 btrfs-image.c        |    5 ++++
 btrfs-select-super.c |    4 ++-
 btrfs.c              |   12 +++++-----
 btrfslabel.c         |   62 ++++++++++++++++++++++++++++---------------------
 btrfslabel.h         |    3 +-
 btrfstune.c          |    5 ++++
 dir-test.c           |   11 +++++++++
 extent-cache.c       |    2 +-
 extent-tree.c        |    2 +-
 extent_io.c          |    2 +-
 find-root.c          |    5 +++-
 mkfs.c               |    6 +++++
 quick-test.c         |   20 ++++++++++++++++
 random-test.c        |    8 ++++++
 14 files changed, 108 insertions(+), 39 deletions(-)

-- 
1.7.8


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] fix segfaults from bnc#710486
  2012-01-12 15:17 [PATCH 0/4] btrfs-progs: some patches Danny Kukawka
@ 2012-01-12 15:17 ` Danny Kukawka
  2012-01-12 15:17 ` [PATCH 2/4] return error code from change/get_label_unmounted Danny Kukawka
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Danny Kukawka @ 2012-01-12 15:17 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Fixed segfaults from bnc#710486 due to unchecked usage of return
value from open_ctree().
---
 btrfs-image.c        |    5 +++++
 btrfs-select-super.c |    4 +++-
 btrfslabel.c         |    8 ++++++++
 btrfstune.c          |    5 +++++
 dir-test.c           |   11 +++++++++++
 find-root.c          |    5 ++++-
 mkfs.c               |    6 ++++++
 quick-test.c         |   20 ++++++++++++++++++++
 random-test.c        |    8 ++++++++
 9 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/btrfs-image.c b/btrfs-image.c
index f2bbcc8..7dc131d 100644
--- a/btrfs-image.c
+++ b/btrfs-image.c
@@ -491,6 +491,11 @@ static int create_metadump(const char *input, FILE *out, int num_threads,
 	int ret;
 
 	root = open_ctree(input, 0, 0);
+	if (!root) {
+		fprintf(stderr, "Open ctree failed\n");
+		exit(1);
+	}
+
 	BUG_ON(root->nodesize != root->leafsize);
 
 	ret = metadump_init(&metadump, root, out, num_threads,
diff --git a/btrfs-select-super.c b/btrfs-select-super.c
index 51eb9c9..0c4f5c0 100644
--- a/btrfs-select-super.c
+++ b/btrfs-select-super.c
@@ -84,8 +84,10 @@ int main(int ac, char **av)
 
 	root = open_ctree(av[optind], bytenr, 1);
 
-	if (root == NULL)
+	if (!root) {
+		fprintf(stderr, "Open ctree failed\n");
 		return 1;
+	}
 
 	/* make the super writing code think we've read the first super */
 	root->fs_info->super_bytenr = BTRFS_SUPER_INFO_OFFSET;
diff --git a/btrfslabel.c b/btrfslabel.c
index c9f4684..2e5d539 100644
--- a/btrfslabel.c
+++ b/btrfslabel.c
@@ -55,6 +55,10 @@ static void change_label_unmounted(char *dev, char *nLabel)
         * and as read-write.
         */
        root = open_ctree(dev, 0, 1);
+       if (!root) {
+		fprintf(stderr, "Open ctree failed\n");
+		return;
+       }
 
        trans = btrfs_start_transaction(root, 1);
        strncpy(root->fs_info->super_copy.label, nLabel, BTRFS_LABEL_SIZE);
@@ -72,6 +76,10 @@ static void get_label_unmounted(char *dev)
         * and as read-only.
         */
        root = open_ctree(dev, 0, 0);
+       if (!root) {
+		fprintf(stderr, "Open ctree failed\n");
+		return;
+       }
 
        fprintf(stdout, "%s\n", root->fs_info->super_copy.label);
 
diff --git a/btrfstune.c b/btrfstune.c
index 47830c5..6950f74 100644
--- a/btrfstune.c
+++ b/btrfstune.c
@@ -108,6 +108,11 @@ int main(int argc, char *argv[])
 
 	root = open_ctree(device, 0, 1);
 
+	if (!root) {
+		fprintf(stderr, "Open ctree failed\n");
+		return 1;
+	}
+
 	if (seeding_flag) {
 		ret = update_seeding_flag(root, seeding_value);
 		if (!ret)
diff --git a/dir-test.c b/dir-test.c
index 3ae9c68..c7644d6 100644
--- a/dir-test.c
+++ b/dir-test.c
@@ -436,6 +436,12 @@ int main(int ac, char **av)
 	radix_tree_init();
 
 	root = open_ctree(av[ac-1], &super, 0);
+
+	if (!root) {
+		fprintf(stderr, "Open ctree failed\n");
+		return 1;
+	}
+
 	trans = btrfs_start_transaction(root, 1);
 
 	dir_oid = btrfs_super_root_dir(&super);
@@ -479,6 +485,11 @@ int main(int ac, char **av)
 				btrfs_header_nritems(&root->node->node.header));
 			close_ctree(root, &super);
 			root = open_ctree("dbfile", &super, 0);
+
+			if (!root) {
+				fprintf(stderr, "Open ctree failed\n");
+				return 1;
+			}
 		}
 		while(count--) {
 			ret = ops[op](trans, root, &radix);
diff --git a/find-root.c b/find-root.c
index c0f38b8..83f1592 100644
--- a/find-root.c
+++ b/find-root.c
@@ -448,8 +448,11 @@ int main(int argc, char **argv)
 
 	root = open_ctree_broken(dev_fd, argv[optind]);
 	close(dev_fd);
-	if (!root)
+
+	if (!root) {
+		fprintf(stderr, "Open ctree failed\n");
 		exit(1);
+	}
 
 	csum_size = btrfs_super_csum_size(&root->fs_info->super_copy);
 	ret = find_root(root);
diff --git a/mkfs.c b/mkfs.c
index e3ced19..4b4930a 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1329,6 +1329,12 @@ int main(int ac, char **av)
 		exit(1);
 	}
 	root = open_ctree(file, 0, O_RDWR);
+	if (!root) {
+		fprintf(stderr, "Open ctree failed\n");
+		close (fd);
+		exit(1);
+	}
+
 	root->fs_info->alloc_start = alloc_start;
 
 	ret = make_root_dir(root, mixed);
diff --git a/quick-test.c b/quick-test.c
index fa6fd83..05d73fd 100644
--- a/quick-test.c
+++ b/quick-test.c
@@ -52,6 +52,10 @@ int main(int ac, char **av) {
 	radix_tree_init();
 
 	root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR);
+	if (!root) {
+		fprintf(stderr, "Open ctree failed\n");
+		exit(1);
+	}
 	trans = btrfs_start_transaction(root, 1);
 	srand(55);
 	btrfs_set_key_type(&ins, BTRFS_STRING_ITEM_KEY);
@@ -75,6 +79,10 @@ int main(int ac, char **av) {
 	close_ctree(root);
 	exit(1);
 	root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR);
+	if (!root) {
+		fprintf(stderr, "Open ctree failed\n");
+		exit(1);
+	}
 	printf("starting search\n");
 	srand(55);
 	for (i = 0; i < run_size; i++) {
@@ -94,6 +102,10 @@ int main(int ac, char **av) {
 	close_ctree(root);
 
 	root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR);
+	if (!root) {
+		fprintf(stderr, "Open ctree failed\n");
+		exit(1);
+	}
 	printf("node %p level %d total ptrs %d free spc %lu\n", root->node,
 	        btrfs_header_level(root->node),
 		btrfs_header_nritems(root->node),
@@ -122,6 +134,10 @@ int main(int ac, char **av) {
 	close_ctree(root);
 
 	root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR);
+	if (!root) {
+		fprintf(stderr, "Open ctree failed\n");
+		exit(1);
+	}
 	trans = btrfs_start_transaction(root, 1);
 	srand(128);
 	for (i = 0; i < run_size; i++) {
@@ -138,6 +154,10 @@ int main(int ac, char **av) {
 	close_ctree(root);
 
 	root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR);
+	if (!root) {
+		fprintf(stderr, "Open ctree failed\n");
+		exit(1);
+	}
 	srand(128);
 	printf("starting search2\n");
 	for (i = 0; i < run_size; i++) {
diff --git a/random-test.c b/random-test.c
index 0003236..3a07e6d 100644
--- a/random-test.c
+++ b/random-test.c
@@ -356,6 +356,10 @@ int main(int ac, char **av)
 	struct btrfs_trans_handle *trans;
 	radix_tree_init();
 	root = open_ctree("dbfile", &super);
+	if (!root) {
+		fprintf(stderr, "Open ctree failed\n");
+		exit(1);
+	}
 	fill_radix(root, &radix);
 
 	signal(SIGTERM, sigstopper);
@@ -398,6 +402,10 @@ int main(int ac, char **av)
 				btrfs_header_nritems(&root->node->node.header));
 			close_ctree(root, &super);
 			root = open_ctree("dbfile", &super);
+			if (!root) {
+				fprintf(stderr, "Open ctree failed\n");
+				goto out;
+			}
 		}
 		while(count--) {
 			ret = ops[op](trans, root, &radix);
-- 
1.7.8


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] return error code from change/get_label_unmounted
  2012-01-12 15:17 [PATCH 0/4] btrfs-progs: some patches Danny Kukawka
  2012-01-12 15:17 ` [PATCH 1/4] fix segfaults from bnc#710486 Danny Kukawka
@ 2012-01-12 15:17 ` Danny Kukawka
  2012-01-12 15:17 ` [PATCH 3/4] fix some compiler warnings from cgcc Danny Kukawka
  2012-01-12 15:17 ` [PATCH 4/4] fix indentation Danny Kukawka
  3 siblings, 0 replies; 5+ messages in thread
From: Danny Kukawka @ 2012-01-12 15:17 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

From: David Sterba <dsterba@suse.cz>

Return error code from change/get_label_unmounted caused by
caused by open_ctree()
---
 btrfslabel.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/btrfslabel.c b/btrfslabel.c
index 2e5d539..29b00bf 100644
--- a/btrfslabel.c
+++ b/btrfslabel.c
@@ -46,7 +46,7 @@
 #define GET_LABEL                      3
 #define SET_LABEL                      4
 
-static void change_label_unmounted(char *dev, char *nLabel)
+static int change_label_unmounted(char *dev, char *nLabel)
 {
        struct btrfs_root *root;
        struct btrfs_trans_handle *trans;
@@ -57,7 +57,7 @@ static void change_label_unmounted(char *dev, char *nLabel)
        root = open_ctree(dev, 0, 1);
        if (!root) {
 		fprintf(stderr, "Open ctree failed\n");
-		return;
+		return -1;
        }
 
        trans = btrfs_start_transaction(root, 1);
@@ -66,9 +66,10 @@ static void change_label_unmounted(char *dev, char *nLabel)
 
        /* Now we close it since we are done. */
        close_ctree(root);
+       return 0;
 }
 
-static void get_label_unmounted(char *dev)
+static int get_label_unmounted(char *dev)
 {
        struct btrfs_root *root;
 
@@ -78,13 +79,14 @@ static void get_label_unmounted(char *dev)
        root = open_ctree(dev, 0, 0);
        if (!root) {
 		fprintf(stderr, "Open ctree failed\n");
-		return;
+		return -1;
        }
 
        fprintf(stdout, "%s\n", root->fs_info->super_copy.label);
 
        /* Now we close it since we are done. */
        close_ctree(root);
+       return 0;
 }
 
 int get_label(char *btrfs_dev)
@@ -103,8 +105,7 @@ int get_label(char *btrfs_dev)
 	       fprintf(stderr, "FATAL: the filesystem has to be unmounted\n");
 	       return -2;
 	}
-	get_label_unmounted(btrfs_dev);
-	return 0;
+	return get_label_unmounted(btrfs_dev);
 }
 
 
@@ -124,6 +125,5 @@ int set_label(char *btrfs_dev, char *nLabel)
 	       fprintf(stderr, "FATAL: the filesystem has to be unmounted\n");
 	       return -2;
 	}
-	change_label_unmounted(btrfs_dev, nLabel);
-	return 0;
+	return change_label_unmounted(btrfs_dev, nLabel);
 }
-- 
1.7.8


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] fix some compiler warnings from cgcc
  2012-01-12 15:17 [PATCH 0/4] btrfs-progs: some patches Danny Kukawka
  2012-01-12 15:17 ` [PATCH 1/4] fix segfaults from bnc#710486 Danny Kukawka
  2012-01-12 15:17 ` [PATCH 2/4] return error code from change/get_label_unmounted Danny Kukawka
@ 2012-01-12 15:17 ` Danny Kukawka
  2012-01-12 15:17 ` [PATCH 4/4] fix indentation Danny Kukawka
  3 siblings, 0 replies; 5+ messages in thread
From: Danny Kukawka @ 2012-01-12 15:17 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Fixed some compiler warnings from cgcc.
---
 btrfs.c        |   12 ++++++------
 btrfslabel.h   |    3 ++-
 extent-cache.c |    2 +-
 extent-tree.c  |    2 +-
 extent_io.c    |    2 +-
 5 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/btrfs.c b/btrfs.c
index 1def354..0f4b8b7 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -179,7 +179,7 @@ static struct Command commands[] = {
 		"get file system paths for the given logical address.",
 	  NULL
 	},
-	{ 0, 0, 0, 0 }
+	{ NULL, 0, NULL, NULL }
 };
 
 static char *get_prgname(char *programname)
@@ -235,7 +235,7 @@ static int split_command(char *cmd, char ***commands)
 	int	c, l;
 	char	*p, *s;
 
-	for( *commands = 0, l = c = 0, p = s = cmd ; ; p++, l++ ){
+	for( *commands = NULL, l = c = 0, p = s = cmd ; ; p++, l++ ){
 		if ( *p && *p != ' ' )
 			continue;
 
@@ -248,7 +248,7 @@ static int split_command(char *cmd, char ***commands)
 		if( !*p ) break;
 	}
 
-	(*commands)[c] = 0;
+	(*commands)[c] = NULL;
 	return c;
 }
 
@@ -354,7 +354,7 @@ static int parse_args(int argc, char **argv,
 		      int *nargs_, char **cmd_, char ***args_ )
 {
 	struct Command	*cp;
-	struct Command	*matchcmd=0;
+	struct Command	*matchcmd=NULL;
 	char		*prgname = get_prgname(argv[0]);
 	int		i=0, helprequested=0;
 
@@ -446,9 +446,9 @@ static int parse_args(int argc, char **argv,
 int main(int ac, char **av )
 {
 
-	char		*cmd=0, **args=0;
+	char		*cmd=NULL, **args=NULL;
 	int		nargs=0, r;
-	CommandFunction func=0;
+	CommandFunction func=NULL;
 
 	r = parse_args(ac, av, &func, &nargs, &cmd, &args);
 	if( r <= 0 ){
diff --git a/btrfslabel.h b/btrfslabel.h
index abf43ad..62da332 100644
--- a/btrfslabel.h
+++ b/btrfslabel.h
@@ -2,4 +2,5 @@
 
 
 int get_label(char *btrfs_dev);
-int set_label(char *btrfs_dev, char *nLabel);
\ No newline at end of file
+int set_label(char *btrfs_dev, char *nLabel);
+
diff --git a/extent-cache.c b/extent-cache.c
index 3dd6434..673947d 100644
--- a/extent-cache.c
+++ b/extent-cache.c
@@ -81,7 +81,7 @@ static struct rb_node *__tree_search(struct rb_root *root, u64 offset,
 	return NULL;
 }
 
-struct cache_extent *alloc_cache_extent(u64 start, u64 size)
+static struct cache_extent *alloc_cache_extent(u64 start, u64 size)
 {
 	struct cache_extent *pe = malloc(sizeof(*pe));
 
diff --git a/extent-tree.c b/extent-tree.c
index 5bed3c2..c1f68bd 100644
--- a/extent-tree.c
+++ b/extent-tree.c
@@ -1067,7 +1067,7 @@ static int lookup_inline_extent_backref(struct btrfs_trans_handle *trans,
 	}
 #endif
 	if (item_size < sizeof(*ei)) {
-		printf("Size is %u, needs to be %u, slot %d\n", item_size,
+		printf("Size is %u, needs to be %lu, slot %d\n", item_size,
 		       sizeof(*ei), path->slots[0]);
 		btrfs_print_leaf(root, leaf);
 		return -EINVAL;
diff --git a/extent_io.c b/extent_io.c
index 973e918..e3eca86 100644
--- a/extent_io.c
+++ b/extent_io.c
@@ -28,7 +28,7 @@
 #include "extent_io.h"
 #include "list.h"
 
-u64 cache_max = 1024 * 1024 * 32;
+static u64 cache_max = 1024 * 1024 * 32;
 
 void extent_io_tree_init(struct extent_io_tree *tree)
 {
-- 
1.7.8


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] fix indentation
  2012-01-12 15:17 [PATCH 0/4] btrfs-progs: some patches Danny Kukawka
                   ` (2 preceding siblings ...)
  2012-01-12 15:17 ` [PATCH 3/4] fix some compiler warnings from cgcc Danny Kukawka
@ 2012-01-12 15:17 ` Danny Kukawka
  3 siblings, 0 replies; 5+ messages in thread
From: Danny Kukawka @ 2012-01-12 15:17 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Fixed indentation, replace spaces with tabs.
---
 btrfslabel.c |   52 ++++++++++++++++++++++++++--------------------------
 1 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/btrfslabel.c b/btrfslabel.c
index 29b00bf..50050ec 100644
--- a/btrfslabel.c
+++ b/btrfslabel.c
@@ -48,45 +48,45 @@
 
 static int change_label_unmounted(char *dev, char *nLabel)
 {
-       struct btrfs_root *root;
-       struct btrfs_trans_handle *trans;
-
-       /* Open the super_block at the default location
-        * and as read-write.
-        */
-       root = open_ctree(dev, 0, 1);
-       if (!root) {
+	struct btrfs_root *root;
+	struct btrfs_trans_handle *trans;
+
+	/* Open the super_block at the default location
+	 * and as read-write.
+	 */
+	root = open_ctree(dev, 0, 1);
+	if (!root) {
 		fprintf(stderr, "Open ctree failed\n");
 		return -1;
-       }
+	}
 
-       trans = btrfs_start_transaction(root, 1);
-       strncpy(root->fs_info->super_copy.label, nLabel, BTRFS_LABEL_SIZE);
-       btrfs_commit_transaction(trans, root);
+	trans = btrfs_start_transaction(root, 1);
+	strncpy(root->fs_info->super_copy.label, nLabel, BTRFS_LABEL_SIZE);
+	btrfs_commit_transaction(trans, root);
 
-       /* Now we close it since we are done. */
-       close_ctree(root);
-       return 0;
+	/* Now we close it since we are done. */
+	close_ctree(root);
+	return 0;
 }
 
 static int get_label_unmounted(char *dev)
 {
-       struct btrfs_root *root;
+	struct btrfs_root *root;
 
-       /* Open the super_block at the default location
-        * and as read-only.
-        */
-       root = open_ctree(dev, 0, 0);
-       if (!root) {
+	/* Open the super_block at the default location
+	* and as read-only.
+	*/
+	root = open_ctree(dev, 0, 0);
+	if (!root) {
 		fprintf(stderr, "Open ctree failed\n");
 		return -1;
-       }
+	}
 
-       fprintf(stdout, "%s\n", root->fs_info->super_copy.label);
+	fprintf(stdout, "%s\n", root->fs_info->super_copy.label);
 
-       /* Now we close it since we are done. */
-       close_ctree(root);
-       return 0;
+	/* Now we close it since we are done. */
+	close_ctree(root);
+	return 0;
 }
 
 int get_label(char *btrfs_dev)
-- 
1.7.8


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-01-12 15:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-12 15:17 [PATCH 0/4] btrfs-progs: some patches Danny Kukawka
2012-01-12 15:17 ` [PATCH 1/4] fix segfaults from bnc#710486 Danny Kukawka
2012-01-12 15:17 ` [PATCH 2/4] return error code from change/get_label_unmounted Danny Kukawka
2012-01-12 15:17 ` [PATCH 3/4] fix some compiler warnings from cgcc Danny Kukawka
2012-01-12 15:17 ` [PATCH 4/4] fix indentation Danny Kukawka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).