Blame SOURCES/btrfs-progs-valgrind.patch

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