mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-26 21:17:56 +00:00
Btrfs-progs: Don't free the devices when close the ctree
Some commands(such as btrfs-convert) access the devices again after we close the ctree, so it is better that we don't free the devices objects when the ctree is closed, or we need re-allocate the memory for the devices. We needn't worry the memory leak problem, because all the memory will be freed after the taskes die. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
This commit is contained in:
parent
0daa219ee1
commit
d25aa23b02
@ -65,25 +65,6 @@ int csum_block(void *buf, u32 len)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
if (device->fd != -1) {
|
|
||||||
close(device->fd);
|
|
||||||
device->fd = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct btrfs_root *open_ctree_broken(int fd, const char *device)
|
static struct btrfs_root *open_ctree_broken(int fd, const char *device)
|
||||||
{
|
{
|
||||||
u32 sectorsize;
|
u32 sectorsize;
|
||||||
@ -217,7 +198,7 @@ static struct btrfs_root *open_ctree_broken(int fd, const char *device)
|
|||||||
out_chunk:
|
out_chunk:
|
||||||
free_extent_buffer(fs_info->chunk_root->node);
|
free_extent_buffer(fs_info->chunk_root->node);
|
||||||
out_devices:
|
out_devices:
|
||||||
close_all_devices(fs_info);
|
btrfs_close_devices(fs_info->fs_devices);
|
||||||
out_cleanup:
|
out_cleanup:
|
||||||
extent_io_tree_cleanup(&fs_info->extent_cache);
|
extent_io_tree_cleanup(&fs_info->extent_cache);
|
||||||
extent_io_tree_cleanup(&fs_info->free_space_cache);
|
extent_io_tree_cleanup(&fs_info->free_space_cache);
|
||||||
|
30
disk-io.c
30
disk-io.c
@ -35,8 +35,6 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "print-tree.h"
|
#include "print-tree.h"
|
||||||
|
|
||||||
static int close_all_devices(struct btrfs_fs_info *fs_info);
|
|
||||||
|
|
||||||
static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf)
|
static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -1028,7 +1026,7 @@ out_chunk:
|
|||||||
if (fs_info->chunk_root)
|
if (fs_info->chunk_root)
|
||||||
free_extent_buffer(fs_info->chunk_root->node);
|
free_extent_buffer(fs_info->chunk_root->node);
|
||||||
out_devices:
|
out_devices:
|
||||||
close_all_devices(fs_info);
|
btrfs_close_devices(fs_info->fs_devices);
|
||||||
out_cleanup:
|
out_cleanup:
|
||||||
extent_io_tree_cleanup(&fs_info->extent_cache);
|
extent_io_tree_cleanup(&fs_info->extent_cache);
|
||||||
extent_io_tree_cleanup(&fs_info->free_space_cache);
|
extent_io_tree_cleanup(&fs_info->free_space_cache);
|
||||||
@ -1261,30 +1259,6 @@ int write_ctree_super(struct btrfs_trans_handle *trans,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int close_all_devices(struct btrfs_fs_info *fs_info)
|
|
||||||
{
|
|
||||||
struct list_head *list;
|
|
||||||
struct btrfs_device *device;
|
|
||||||
|
|
||||||
list = &fs_info->fs_devices->devices;
|
|
||||||
while (!list_empty(list)) {
|
|
||||||
device = list_entry(list->next, struct btrfs_device, dev_list);
|
|
||||||
list_del_init(&device->dev_list);
|
|
||||||
if (device->fd != -1) {
|
|
||||||
fsync(device->fd);
|
|
||||||
if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
|
|
||||||
fprintf(stderr, "Warning, could not drop caches\n");
|
|
||||||
close(device->fd);
|
|
||||||
device->fd = -1;
|
|
||||||
}
|
|
||||||
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)
|
static void free_mapping_cache(struct btrfs_fs_info *fs_info)
|
||||||
{
|
{
|
||||||
struct cache_tree *cache_tree = &fs_info->mapping_tree.cache_tree;
|
struct cache_tree *cache_tree = &fs_info->mapping_tree.cache_tree;
|
||||||
@ -1337,7 +1311,7 @@ int close_ctree(struct btrfs_root *root)
|
|||||||
free(fs_info->log_root_tree);
|
free(fs_info->log_root_tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
close_all_devices(fs_info);
|
btrfs_close_devices(fs_info->fs_devices);
|
||||||
free_mapping_cache(fs_info);
|
free_mapping_cache(fs_info);
|
||||||
extent_io_tree_cleanup(&fs_info->extent_cache);
|
extent_io_tree_cleanup(&fs_info->extent_cache);
|
||||||
extent_io_tree_cleanup(&fs_info->free_space_cache);
|
extent_io_tree_cleanup(&fs_info->free_space_cache);
|
||||||
|
@ -163,6 +163,9 @@ again:
|
|||||||
list_for_each(cur, &fs_devices->devices) {
|
list_for_each(cur, &fs_devices->devices) {
|
||||||
device = list_entry(cur, struct btrfs_device, dev_list);
|
device = list_entry(cur, struct btrfs_device, dev_list);
|
||||||
if (device->fd != -1) {
|
if (device->fd != -1) {
|
||||||
|
fsync(device->fd);
|
||||||
|
if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
|
||||||
|
fprintf(stderr, "Warning, could not drop caches\n");
|
||||||
close(device->fd);
|
close(device->fd);
|
||||||
device->fd = -1;
|
device->fd = -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user