summaryrefslogtreecommitdiff
path: root/disk-io.c
diff options
context:
space:
mode:
Diffstat (limited to 'disk-io.c')
-rw-r--r--disk-io.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/disk-io.c b/disk-io.c
index 6ef35bbf..be4abb8b 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1278,24 +1278,39 @@ int write_ctree_super(struct btrfs_trans_handle *trans,
static int close_all_devices(struct btrfs_fs_info *fs_info)
{
struct list_head *list;
- struct list_head *next;
struct btrfs_device *device;
- return 0;
-
list = &fs_info->fs_devices->devices;
- list_for_each(next, list) {
- device = list_entry(next, struct btrfs_device, dev_list);
+ while (!list_empty(list)) {
+ device = list_entry(list->next, struct btrfs_device, dev_list);
+ list_del_init(&device->dev_list);
if (device->fd) {
fsync(device->fd);
if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
fprintf(stderr, "Warning, could not drop caches\n");
}
close(device->fd);
+ kfree(device->name);
+ kfree(device->label);
+ kfree(device);
}
+ kfree(fs_info->fs_devices);
return 0;
}
+static void free_mapping_cache(struct btrfs_fs_info *fs_info)
+{
+ struct cache_tree *cache_tree = &fs_info->mapping_tree.cache_tree;
+ struct cache_extent *ce;
+ struct map_lookup *map;
+
+ while ((ce = find_first_cache_extent(cache_tree, 0))) {
+ map = container_of(ce, struct map_lookup, ce);
+ remove_cache_extent(cache_tree, ce);
+ kfree(map);
+ }
+}
+
int close_ctree(struct btrfs_root *root)
{
int ret;
@@ -1336,6 +1351,7 @@ int close_ctree(struct btrfs_root *root)
}
close_all_devices(fs_info);
+ free_mapping_cache(fs_info);
extent_io_tree_cleanup(&fs_info->extent_cache);
extent_io_tree_cleanup(&fs_info->free_space_cache);
extent_io_tree_cleanup(&fs_info->block_group_cache);