summaryrefslogtreecommitdiff
path: root/volumes.c
diff options
context:
space:
mode:
Diffstat (limited to 'volumes.c')
-rw-r--r--volumes.c69
1 files changed, 34 insertions, 35 deletions
diff --git a/volumes.c b/volumes.c
index 01127e79..437e219a 100644
--- a/volumes.c
+++ b/volumes.c
@@ -52,9 +52,6 @@ static inline int nr_data_stripes(struct map_lookup *map)
#define is_parity_stripe(x) ( ((x) == BTRFS_RAID5_P_STRIPE) || ((x) == BTRFS_RAID6_Q_STRIPE) )
-#define map_lookup_size(n) (sizeof(struct map_lookup) + \
- (sizeof(struct btrfs_bio_stripe) * (n)))
-
static LIST_HEAD(fs_uuids);
static struct btrfs_device *__find_device(struct list_head *head, u64 devid,
@@ -116,6 +113,7 @@ static int device_list_add(const char *path,
/* we can safely leave the fs_devices entry around */
return -ENOMEM;
}
+ device->fd = -1;
device->devid = devid;
memcpy(device->uuid, disk_super->dev_item.uuid,
BTRFS_UUID_SIZE);
@@ -161,8 +159,13 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
again:
list_for_each(cur, &fs_devices->devices) {
device = list_entry(cur, struct btrfs_device, dev_list);
- close(device->fd);
- 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);
+ device->fd = -1;
+ }
device->writeable = 0;
}
@@ -663,12 +666,12 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
{
u64 dev_offset;
struct btrfs_fs_info *info = extent_root->fs_info;
- struct btrfs_root *chunk_root = extent_root->fs_info->chunk_root;
+ struct btrfs_root *chunk_root = info->chunk_root;
struct btrfs_stripe *stripes;
struct btrfs_device *device = NULL;
struct btrfs_chunk *chunk;
struct list_head private_devs;
- struct list_head *dev_list = &extent_root->fs_info->fs_devices->devices;
+ struct list_head *dev_list = &info->fs_devices->devices;
struct list_head *cur;
struct map_lookup *map;
int min_stripe_size = 1 * 1024 * 1024;
@@ -821,7 +824,7 @@ again:
if (!chunk)
return -ENOMEM;
- map = kmalloc(map_lookup_size(num_stripes), GFP_NOFS);
+ map = kmalloc(btrfs_map_lookup_size(num_stripes), GFP_NOFS);
if (!map) {
kfree(chunk);
return -ENOMEM;
@@ -888,9 +891,7 @@ again:
map->ce.start = key.offset;
map->ce.size = *num_bytes;
- ret = insert_existing_cache_extent(
- &extent_root->fs_info->mapping_tree.cache_tree,
- &map->ce);
+ ret = insert_cache_extent(&info->mapping_tree.cache_tree, &map->ce);
BUG_ON(ret);
if (type & BTRFS_BLOCK_GROUP_SYSTEM) {
@@ -909,11 +910,11 @@ int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans,
{
u64 dev_offset;
struct btrfs_fs_info *info = extent_root->fs_info;
- struct btrfs_root *chunk_root = extent_root->fs_info->chunk_root;
+ struct btrfs_root *chunk_root = info->chunk_root;
struct btrfs_stripe *stripes;
struct btrfs_device *device = NULL;
struct btrfs_chunk *chunk;
- struct list_head *dev_list = &extent_root->fs_info->fs_devices->devices;
+ struct list_head *dev_list = &info->fs_devices->devices;
struct list_head *cur;
struct map_lookup *map;
u64 calc_size = 8 * 1024 * 1024;
@@ -935,7 +936,7 @@ int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans,
if (!chunk)
return -ENOMEM;
- map = kmalloc(map_lookup_size(num_stripes), GFP_NOFS);
+ map = kmalloc(btrfs_map_lookup_size(num_stripes), GFP_NOFS);
if (!map) {
kfree(chunk);
return -ENOMEM;
@@ -996,9 +997,7 @@ int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans,
map->ce.start = key.offset;
map->ce.size = num_bytes;
- ret = insert_existing_cache_extent(
- &extent_root->fs_info->mapping_tree.cache_tree,
- &map->ce);
+ ret = insert_cache_extent(&info->mapping_tree.cache_tree, &map->ce);
BUG_ON(ret);
kfree(chunk);
@@ -1016,7 +1015,7 @@ int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len)
struct map_lookup *map;
int ret;
- ce = find_first_cache_extent(&map_tree->cache_tree, logical);
+ ce = search_cache_extent(&map_tree->cache_tree, logical);
BUG_ON(!ce);
BUG_ON(ce->start > logical || ce->start + ce->size < logical);
map = container_of(ce, struct map_lookup, ce);
@@ -1040,7 +1039,7 @@ int btrfs_next_metadata(struct btrfs_mapping_tree *map_tree, u64 *logical,
struct cache_extent *ce;
struct map_lookup *map;
- ce = find_first_cache_extent(&map_tree->cache_tree, *logical);
+ ce = search_cache_extent(&map_tree->cache_tree, *logical);
while (ce) {
ce = next_cache_extent(ce);
@@ -1071,7 +1070,7 @@ int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,
u64 rmap_len;
int i, j, nr = 0;
- ce = find_first_cache_extent(&map_tree->cache_tree, chunk_start);
+ ce = search_cache_extent(&map_tree->cache_tree, chunk_start);
BUG_ON(!ce);
map = container_of(ce, struct map_lookup, ce);
@@ -1183,7 +1182,7 @@ int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
stripes_allocated = 1;
}
again:
- ce = find_first_cache_extent(&map_tree->cache_tree, logical);
+ ce = search_cache_extent(&map_tree->cache_tree, logical);
if (!ce) {
if (multi)
kfree(multi);
@@ -1391,16 +1390,15 @@ struct btrfs_device *btrfs_find_device(struct btrfs_root *root, u64 devid,
return NULL;
}
-struct btrfs_device *btrfs_find_device_by_devid(struct btrfs_root *root,
- u64 devid, int instance)
+struct btrfs_device *
+btrfs_find_device_by_devid(struct btrfs_fs_devices *fs_devices,
+ u64 devid, int instance)
{
- struct list_head *head = &root->fs_info->fs_devices->devices;
+ struct list_head *head = &fs_devices->devices;
struct btrfs_device *dev;
- struct list_head *cur;
int num_found = 0;
- list_for_each(cur, head) {
- dev = list_entry(cur, struct btrfs_device, dev_list);
+ list_for_each_entry(dev, head, dev_list) {
if (dev->devid == devid && num_found++ == instance)
return dev;
}
@@ -1422,7 +1420,7 @@ int btrfs_bootstrap_super_map(struct btrfs_mapping_tree *map_tree,
list_for_each(cur, &fs_devices->devices) {
num_stripes++;
}
- map = kmalloc(map_lookup_size(num_stripes), GFP_NOFS);
+ map = kmalloc(btrfs_map_lookup_size(num_stripes), GFP_NOFS);
if (!map)
return -ENOMEM;
@@ -1445,15 +1443,16 @@ int btrfs_bootstrap_super_map(struct btrfs_mapping_tree *map_tree,
map->stripes[i].dev = device;
i++;
}
- ret = insert_existing_cache_extent(&map_tree->cache_tree, &map->ce);
+ ret = insert_cache_extent(&map_tree->cache_tree, &map->ce);
if (ret == -EEXIST) {
struct cache_extent *old;
struct map_lookup *old_map;
- old = find_cache_extent(&map_tree->cache_tree, logical, length);
+ old = lookup_cache_extent(&map_tree->cache_tree,
+ logical, length);
old_map = container_of(old, struct map_lookup, ce);
remove_cache_extent(&map_tree->cache_tree, old);
kfree(old_map);
- ret = insert_existing_cache_extent(&map_tree->cache_tree,
+ ret = insert_cache_extent(&map_tree->cache_tree,
&map->ce);
}
BUG_ON(ret);
@@ -1468,7 +1467,7 @@ int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset)
int readonly = 0;
int i;
- ce = find_first_cache_extent(&map_tree->cache_tree, chunk_offset);
+ ce = search_cache_extent(&map_tree->cache_tree, chunk_offset);
BUG_ON(!ce);
map = container_of(ce, struct map_lookup, ce);
@@ -1510,7 +1509,7 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
logical = key->offset;
length = btrfs_chunk_length(leaf, chunk);
- ce = find_first_cache_extent(&map_tree->cache_tree, logical);
+ ce = search_cache_extent(&map_tree->cache_tree, logical);
/* already mapped? */
if (ce && ce->start <= logical && ce->start + ce->size > logical) {
@@ -1518,7 +1517,7 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
}
num_stripes = btrfs_chunk_num_stripes(leaf, chunk);
- map = kmalloc(map_lookup_size(num_stripes), GFP_NOFS);
+ map = kmalloc(btrfs_map_lookup_size(num_stripes), GFP_NOFS);
if (!map)
return -ENOMEM;
@@ -1548,7 +1547,7 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
}
}
- ret = insert_existing_cache_extent(&map_tree->cache_tree, &map->ce);
+ ret = insert_cache_extent(&map_tree->cache_tree, &map->ce);
BUG_ON(ret);
return 0;