osandov / rpms / btrfs-progs

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