Blame SOURCES/btrfs-progs-valgrind.patch

b97c1b
Not-upstream changes from Josef.  Some bits have made it usptream
b97c1b
and have been removed; the rest needs some reverse-engineering.
b97c1b
b97c1b
diff -up btrfs-progs-0.19/btrfsck.c.orig btrfs-progs-0.19/btrfsck.c
b97c1b
diff -up btrfs-progs-0.19/disk-io.c.orig btrfs-progs-0.19/disk-io.c
b97c1b
--- btrfs-progs-0.19/disk-io.c.orig	2012-04-11 10:42:36.213042556 -0400
b97c1b
+++ btrfs-progs-0.19/disk-io.c	2012-04-11 10:42:58.790867701 -0400
b97c1b
@@ -622,7 +624,7 @@ static struct btrfs_fs_info *__open_ctre
b97c1b
 	struct btrfs_root *chunk_root = malloc(sizeof(struct btrfs_root));
b97c1b
 	struct btrfs_root *dev_root = malloc(sizeof(struct btrfs_root));
b97c1b
 	struct btrfs_root *csum_root = malloc(sizeof(struct btrfs_root));
b97c1b
-	struct btrfs_fs_info *fs_info = malloc(sizeof(*fs_info));
b97c1b
+	struct btrfs_fs_info *fs_info = malloc(sizeof(struct btrfs_fs_info));
b97c1b
 	int ret;
b97c1b
 	struct btrfs_super_block *disk_super;
b97c1b
 	struct btrfs_fs_devices *fs_devices = NULL;
b97c1b
@@ -646,7 +648,7 @@ static struct btrfs_fs_info *__open_ctre
b97c1b
 			goto out;
b97c1b
 	}
b97c1b
 
b97c1b
-	memset(fs_info, 0, sizeof(*fs_info));
b97c1b
+	memset(fs_info, 0, sizeof(struct btrfs_fs_info));
b97c1b
 	fs_info->tree_root = tree_root;
b97c1b
 	fs_info->extent_root = extent_root;
b97c1b
 	fs_info->chunk_root = chunk_root;
b97c1b
@@ -1063,15 +1065,19 @@ static int close_all_devices(struct btrf
b97c1b
 {
b97c1b
 	struct list_head *list;
b97c1b
 	struct list_head *next;
b97c1b
+	struct list_head *tmp;
b97c1b
 	struct btrfs_device *device;
b97c1b
 
b97c1b
-	return 0;
b97c1b
-
b97c1b
 	list = &fs_info->fs_devices->devices;
b97c1b
-	list_for_each(next, list) {
b97c1b
+	list_for_each_safe(next, tmp, list) {
b97c1b
 		device = list_entry(next, struct btrfs_device, dev_list);
b97c1b
 		close(device->fd);
b97c1b
+		list_del(&device->dev_list);
b97c1b
+		free(device->name);
b97c1b
+		free(device->label);
b97c1b
+		free(device);
b97c1b
 	}
b97c1b
+	free(fs_info->fs_devices);
b97c1b
 	return 0;
b97c1b
 }
b97c1b
 
b97c1b
@@ -1121,12 +1127,14 @@ int close_ctree(struct btrfs_root *root)
b97c1b
 	extent_io_tree_cleanup(&fs_info->pinned_extents);
b97c1b
 	extent_io_tree_cleanup(&fs_info->pending_del);
b97c1b
 	extent_io_tree_cleanup(&fs_info->extent_ins);
b97c1b
+	btrfs_mapping_tree_free(&fs_info->mapping_tree);
b97c1b
 
b97c1b
 	free(fs_info->tree_root);
b97c1b
 	free(fs_info->extent_root);
b97c1b
 	free(fs_info->chunk_root);
b97c1b
 	free(fs_info->dev_root);
b97c1b
 	free(fs_info->csum_root);
b97c1b
+	free(fs_info->log_root_tree);
b97c1b
 	free(fs_info);
b97c1b
 
b97c1b
 	return 0;
b97c1b
diff -up btrfs-progs-0.19/extent-cache.c.orig btrfs-progs-0.19/extent-cache.c
b97c1b
--- btrfs-progs-0.19/extent-cache.c.orig	2012-04-11 10:42:36.214042548 -0400
b97c1b
+++ btrfs-progs-0.19/extent-cache.c	2012-04-11 10:42:58.833867368 -0400
b97c1b
@@ -168,3 +168,14 @@ void remove_cache_extent(struct cache_tr
b97c1b
 	rb_erase(&pe->rb_node, &tree->root);
b97c1b
 }
b97c1b
 
b97c1b
+void free_cache_tree(struct cache_tree *tree)
b97c1b
+{
b97c1b
+	struct rb_node *node;
b97c1b
+	struct cache_extent *cache;
b97c1b
+
b97c1b
+	while ((node = rb_last(&tree->root)) != NULL) {
b97c1b
+		cache = rb_entry(node, struct cache_extent, rb_node);
b97c1b
+		remove_cache_extent(tree, cache);
b97c1b
+		free(cache);
b97c1b
+	}
b97c1b
+}
b97c1b
diff -up btrfs-progs-0.19/extent-cache.h.orig btrfs-progs-0.19/extent-cache.h
b97c1b
--- btrfs-progs-0.19/extent-cache.h.orig	2009-06-11 12:56:15.000000000 -0400
b97c1b
+++ btrfs-progs-0.19/extent-cache.h	2012-04-11 10:42:58.850867237 -0400
b97c1b
@@ -43,6 +43,7 @@ struct cache_extent *find_cache_extent(s
b97c1b
 int insert_cache_extent(struct cache_tree *tree, u64 start, u64 size);
b97c1b
 int insert_existing_cache_extent(struct cache_tree *tree,
b97c1b
 				 struct cache_extent *pe);
b97c1b
+void free_cache_tree(struct cache_tree *tree);
b97c1b
 
b97c1b
 static inline int cache_tree_empty(struct cache_tree *tree)
b97c1b
 {
b97c1b
diff -up btrfs-progs-0.19/extent-tree.c.orig btrfs-progs-0.19/extent-tree.c
b97c1b
--- btrfs-progs-0.19/extent-tree.c.orig	2012-04-11 10:42:36.216042532 -0400
b97c1b
+++ btrfs-progs-0.19/extent-tree.c	2012-04-11 10:42:58.851867229 -0400
b97c1b
@@ -2999,6 +2999,7 @@ out:
b97c1b
 
b97c1b
 int btrfs_free_block_groups(struct btrfs_fs_info *info)
b97c1b
 {
b97c1b
+	struct btrfs_space_info *space_info;
b97c1b
 	u64 start;
b97c1b
 	u64 end;
b97c1b
 	u64 ptr;
b97c1b
@@ -3022,6 +3023,15 @@ int btrfs_free_block_groups(struct btrfs
b97c1b
 		clear_extent_dirty(&info->free_space_cache, start,
b97c1b
 				   end, GFP_NOFS);
b97c1b
 	}
b97c1b
+
b97c1b
+	while (!list_empty(&info->space_info)) {
b97c1b
+		space_info = list_entry(info->space_info.next,
b97c1b
+					struct btrfs_space_info,
b97c1b
+					list);
b97c1b
+		list_del(&space_info->list);
b97c1b
+		kfree(space_info);
b97c1b
+	}
b97c1b
+
b97c1b
 	return 0;
b97c1b
 }
b97c1b
 
b97c1b
diff -up btrfs-progs-0.19/volumes.c.orig btrfs-progs-0.19/volumes.c
b97c1b
--- btrfs-progs-0.19/volumes.c.orig	2012-04-11 10:42:36.228042439 -0400
b97c1b
+++ btrfs-progs-0.19/volumes.c	2012-04-11 10:43:03.313832673 -0400
b97c1b
@@ -957,6 +957,20 @@ void btrfs_mapping_init(struct btrfs_map
b97c1b
 	cache_tree_init(&tree->cache_tree);
b97c1b
 }
b97c1b
 
b97c1b
+void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree)
b97c1b
+{
b97c1b
+	struct cache_extent *cache;
b97c1b
+	struct rb_node *node;
b97c1b
+	struct map_lookup *map;
b97c1b
+
b97c1b
+	while ((node = rb_last(&tree->cache_tree.root)) != NULL) {
b97c1b
+		cache = rb_entry(node, struct cache_extent, rb_node);
b97c1b
+		map = container_of(cache, struct map_lookup, ce);
b97c1b
+		remove_cache_extent(&tree->cache_tree, cache);
b97c1b
+		free(map);
b97c1b
+	}
b97c1b
+}
b97c1b
+
b97c1b
 int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len)
b97c1b
 {
b97c1b
 	struct cache_extent *ce;
b97c1b
diff -up btrfs-progs-0.19/volumes.h.orig btrfs-progs-0.19/volumes.h
b97c1b
--- btrfs-progs-0.19/volumes.h.orig	2012-04-11 10:42:36.228042439 -0400
b97c1b
+++ btrfs-progs-0.19/volumes.h	2012-04-11 10:43:03.314832666 -0400
b97c1b
@@ -182,4 +182,5 @@ int btrfs_add_system_chunk(struct btrfs_
b97c1b
 			   struct btrfs_root *root, struct btrfs_key *key,
b97c1b
 			   struct btrfs_chunk *chunk, int item_size);
b97c1b
 int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset);
b97c1b
+void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree);
b97c1b
 #endif