[Btrfs-devel][PATCH] check return value in extent map allocation

Wyatt Banks wyatt at banksresearch.com
Tue Nov 6 17:06:08 PST 2007


Hello,

I just began digging through the source last night.  I hope nobody minds if I just
jump in and start sending some patches.  The return of extent_map_init is not
checked at module startup.  The net effect of this function is checked at inode
space allocation time though, so my patch decides to quit early on if the alloc
fails.

Thanks,
Wyatt Banks

diff -r 29b8cc7794ac extent_map.c
--- a/extent_map.c	Thu Sep 20 14:14:42 2007 -0400
+++ b/extent_map.c	Tue Nov 06 19:06:04 2007 -0500
@@ -36,16 +36,23 @@ struct tree_entry {

 #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)

-void __init extent_map_init(void)
+int __init extent_map_init(void)
 {
	extent_map_cache = btrfs_cache_create("extent_map",
 					    sizeof(struct extent_map),
 					    SLAB_DESTROY_BY_RCU,
 					    NULL);
+	if (!extent_map_cache)
+		return -ENOMEM;
+
	extent_state_cache = btrfs_cache_create("extent_state",
 					    sizeof(struct extent_state),
 					    SLAB_DESTROY_BY_RCU,
 					    NULL);
+	if (!extent_state_cache)
+		return -ENOMEM;
+
+	return 0;
 }

 void __exit extent_map_exit(void)
diff -r 29b8cc7794ac extent_map.h
--- a/extent_map.h	Thu Sep 20 14:14:42 2007 -0400
+++ b/extent_map.h	Tue Nov 06 19:06:04 2007 -0500
@@ -78,7 +78,7 @@ void free_extent_map(struct extent_map *
 void free_extent_map(struct extent_map *em);
 int extent_read_full_page(struct extent_map_tree *tree, struct page *page,
 			  get_extent_t *get_extent);
-void __init extent_map_init(void);
+int __init extent_map_init(void);
 void __exit extent_map_exit(void);
 int extent_clean_all_trees(struct extent_map_tree *tree);
 int set_extent_uptodate(struct extent_map_tree *tree, u64 start, u64 end,
diff -r 29b8cc7794ac super.c
--- a/super.c	Thu Sep 20 14:14:42 2007 -0400
+++ b/super.c	Tue Nov 06 19:06:04 2007 -0500
@@ -345,7 +345,9 @@ static int __init init_btrfs_fs(void)
	err = btrfs_init_cachep();
	if (err)
		return err;
-	extent_map_init();
+	err = extent_map_init();
+	if (err)
+		return err;
	return register_filesystem(&btrfs_fs_type);
 }



More information about the Btrfs-devel mailing list