From: Miao Xie <miaox@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 03/12] Btrfs-progs: Don't free the devices when close the ctree
Date: Wed, 3 Jul 2013 21:25:11 +0800 [thread overview]
Message-ID: <1372857920-4678-4-git-send-email-miaox@cn.fujitsu.com> (raw)
In-Reply-To: <1372857920-4678-1-git-send-email-miaox@cn.fujitsu.com>
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>
---
btrfs-find-root.c | 21 +--------------------
disk-io.c | 30 ++----------------------------
volumes.c | 3 +++
3 files changed, 6 insertions(+), 48 deletions(-)
diff --git a/btrfs-find-root.c b/btrfs-find-root.c
index 3e1396d..da22c1d 100644
--- a/btrfs-find-root.c
+++ b/btrfs-find-root.c
@@ -65,25 +65,6 @@ int csum_block(void *buf, u32 len)
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)
{
u32 sectorsize;
@@ -217,7 +198,7 @@ static struct btrfs_root *open_ctree_broken(int fd, const char *device)
out_chunk:
free_extent_buffer(fs_info->chunk_root->node);
out_devices:
- close_all_devices(fs_info);
+ btrfs_close_devices(fs_info->fs_devices);
out_cleanup:
extent_io_tree_cleanup(&fs_info->extent_cache);
extent_io_tree_cleanup(&fs_info->free_space_cache);
diff --git a/disk-io.c b/disk-io.c
index 4003636..a8176a5 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -35,8 +35,6 @@
#include "utils.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)
{
@@ -1028,7 +1026,7 @@ out_chunk:
if (fs_info->chunk_root)
free_extent_buffer(fs_info->chunk_root->node);
out_devices:
- close_all_devices(fs_info);
+ btrfs_close_devices(fs_info->fs_devices);
out_cleanup:
extent_io_tree_cleanup(&fs_info->extent_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;
}
-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)
{
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);
}
- close_all_devices(fs_info);
+ btrfs_close_devices(fs_info->fs_devices);
free_mapping_cache(fs_info);
extent_io_tree_cleanup(&fs_info->extent_cache);
extent_io_tree_cleanup(&fs_info->free_space_cache);
diff --git a/volumes.c b/volumes.c
index b88385b..0f6a35b 100644
--- a/volumes.c
+++ b/volumes.c
@@ -163,6 +163,9 @@ again:
list_for_each(cur, &fs_devices->devices) {
device = list_entry(cur, struct btrfs_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;
}
--
1.8.1.4
next prev parent reply other threads:[~2013-07-03 14:00 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-03 13:25 [RFC PATCH 00/12] Btrfs-progs: introduce chunk recover function Miao Xie
2013-07-03 13:25 ` [PATCH 01/12] Btrfs-progs: fix missing recow roots when making btrfs filesystem Miao Xie
2013-07-03 13:25 ` [PATCH 02/12] Btrfs-progs: don't close the file descriptor 0 when closing a device Miao Xie
2013-07-03 14:17 ` Filipe David Manana
2013-07-04 1:30 ` Miao Xie
2013-07-04 8:30 ` Filipe David Manana
2013-07-03 13:25 ` Miao Xie [this message]
2013-07-08 4:59 ` [PATCH 03/12] Btrfs-progs: Don't free the devices when close the ctree Anand Jain
2013-07-15 4:58 ` Anand Jain
2013-07-03 13:25 ` [PATCH 04/12] Btrfs-progs: cleanup similar code in open_ctree_* and close_ctree Miao Xie
2013-08-04 16:04 ` Eric Sandeen
2013-08-04 23:24 ` Wang Shilong
2013-08-04 23:43 ` Eric Sandeen
2013-07-03 13:25 ` [PATCH 05/12] Btrfs-progs: introduce common insert/search/delete functions for rb-tree Miao Xie
2013-07-03 13:25 ` [PATCH 06/12] Btrfs-progs: use rb-tree instead of extent cache tree for fs/file roots Miao Xie
2013-07-03 13:25 ` [PATCH 07/12] Btrfs-progs: extend the extent cache for the device extent Miao Xie
2013-07-03 13:25 ` [PATCH 08/12] Btrfs-progs: Add block group check funtion Miao Xie
2013-07-03 13:25 ` [PATCH 09/12] Btrfs-progs: Add chunk recover function - using old chunk items Miao Xie
2013-08-01 20:30 ` David Sterba
2013-07-03 13:25 ` [PATCH 10/12] Btrfs-progs: introduce list_{first, next}_entry/list_splice_tail{_init} Miao Xie
2013-07-03 13:25 ` [PATCH 11/12] Btrfs-progs: Add chunk rebuild function for RAID1/SINGLE/DUP Miao Xie
2013-07-03 13:25 ` [PATCH 12/12] Btrfs-progs: recover raid0/raid10/raid5/raid6 metadata chunk Miao Xie
2013-07-03 20:36 ` [RFC PATCH 00/12] Btrfs-progs: introduce chunk recover function Chris Mason
2013-07-04 4:06 ` Liu Bo
2013-07-05 14:00 ` Chris Mason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1372857920-4678-4-git-send-email-miaox@cn.fujitsu.com \
--to=miaox@cn.fujitsu.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).