borisb / rpms / btrfs-progs

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