struct list_head *next;
struct btrfs_device *device;
- list = &fs_info->devices;
- while(!list_empty(list)) {
- next = list->next;
- list_del(next);
+ list = &fs_info->fs_devices->devices;
+ list_for_each(next, list) {
device = list_entry(next, struct btrfs_device, dev_list);
- kfree(device);
+ if (device->bdev && device->bdev != fs_info->sb->s_bdev)
+ close_bdev_excl(device->bdev);
+ device->bdev = NULL;
}
return 0;
}
return 0;
}
#endif
-struct btrfs_root *open_ctree(struct super_block *sb)
+
+static int btrfs_congested_fn(void *congested_data, int bdi_bits)
+{
+ struct btrfs_fs_info *info = (struct btrfs_fs_info *)congested_data;
+ int ret = 0;
+ struct list_head *cur;
+ struct btrfs_device *device;
+ struct backing_dev_info *bdi;
+
+ list_for_each(cur, &info->fs_devices->devices) {
+ device = list_entry(cur, struct btrfs_device, dev_list);
+ bdi = blk_get_backing_dev_info(device->bdev);
+ if (bdi && bdi_congested(bdi, bdi_bits)) {
+ ret = 1;
+ break;
+ }
+ }
+ return ret;
+}
+
+void btrfs_unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
+{
+ struct list_head *cur;
+ struct btrfs_device *device;
+ struct btrfs_fs_info *info;
+
+ info = (struct btrfs_fs_info *)bdi->unplug_io_data;
+ list_for_each(cur, &info->fs_devices->devices) {
+ device = list_entry(cur, struct btrfs_device, dev_list);
+ bdi = blk_get_backing_dev_info(device->bdev);
+ if (bdi->unplug_io_fn) {
+ bdi->unplug_io_fn(bdi, page);
+ }
+ }
+}
+
+static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi)
+{
+ bdi_init(bdi);
+ bdi->ra_pages = default_backing_dev_info.ra_pages;
+ bdi->state = 0;
+ bdi->capabilities = default_backing_dev_info.capabilities;
+ bdi->unplug_io_fn = btrfs_unplug_io_fn;
+ bdi->unplug_io_data = info;
+ bdi->congested_fn = btrfs_congested_fn;
+ bdi->congested_data = info;
+ return 0;
+}
+
+struct btrfs_root *open_ctree(struct super_block *sb,
+ struct btrfs_fs_devices *fs_devices)
{
u32 sectorsize;
u32 nodesize;
fs_info->extent_root = extent_root;
fs_info->chunk_root = chunk_root;
fs_info->dev_root = dev_root;
+ fs_info->fs_devices = fs_devices;
INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots);
- INIT_LIST_HEAD(&fs_info->devices);
INIT_LIST_HEAD(&fs_info->space_info);
btrfs_mapping_init(&fs_info->mapping_tree);
fs_info->sb = sb;
fs_info->max_extent = (u64)-1;
fs_info->max_inline = 8192 * 1024;
fs_info->delalloc_bytes = 0;
+ setup_bdi(fs_info, &fs_info->bdi);
fs_info->btree_inode = new_inode(sb);
fs_info->btree_inode->i_ino = 1;
fs_info->btree_inode->i_nlink = 1;
fs_info->btree_inode->i_size = sb->s_bdev->bd_inode->i_size;
fs_info->btree_inode->i_mapping->a_ops = &btree_aops;
+ fs_info->btree_inode->i_mapping->backing_dev_info = &fs_info->bdi;
+
extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree,
fs_info->btree_inode->i_mapping,
GFP_NOFS);
fs_info->total_pinned = 0;
fs_info->last_alloc = 0;
fs_info->last_data_alloc = 0;
+ fs_info->extra_alloc_bits = 0;
+ fs_info->extra_data_alloc_bits = 0;
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
INIT_WORK(&fs_info->trans_work, btrfs_transaction_cleaner, fs_info);
if (!btrfs_super_root(disk_super))
goto fail_sb_buffer;
+ if (btrfs_super_num_devices(disk_super) != fs_devices->num_devices) {
+ printk("Btrfs: wanted %llu devices, but found %llu\n",
+ (unsigned long long)btrfs_super_num_devices(disk_super),
+ (unsigned long long)fs_devices->num_devices);
+ goto fail_sb_buffer;
+ }
nodesize = btrfs_super_nodesize(disk_super);
leafsize = btrfs_super_leafsize(disk_super);
sectorsize = btrfs_super_sectorsize(disk_super);
}
mutex_lock(&fs_info->fs_mutex);
- ret = btrfs_read_super_device(tree_root, fs_info->sb_buffer);
- BUG_ON(ret);
ret = btrfs_read_sys_array(tree_root);
BUG_ON(ret);
fail_iput:
iput(fs_info->btree_inode);
fail:
+ close_all_devices(fs_info);
kfree(extent_root);
kfree(tree_root);
kfree(fs_info);
#endif
close_all_devices(fs_info);
btrfs_mapping_tree_free(&fs_info->mapping_tree);
+ bdi_destroy(&fs_info->bdi);
kfree(fs_info->extent_root);
kfree(fs_info->tree_root);
static struct extent_io_ops btree_extent_io_ops = {
.writepage_io_hook = btree_writepage_io_hook,
.submit_bio_hook = btree_submit_bio_hook,
+ /* note we're sharing with inode.c for the merge bio hook */
+ .merge_bio_hook = btrfs_merge_bio_hook,
};