#include "disk-io.h"
#include "transaction.h"
#include "btrfs_inode.h"
+#include "volumes.h"
#include "print-tree.h"
#if 0
return 0;
}
+static int btree_submit_bio_hook(struct inode *inode, int rw, struct bio *bio)
+{
+ struct btrfs_root *root = BTRFS_I(inode)->root;
+ u64 offset;
+ offset = bio->bi_sector << 9;
+ if (offset == BTRFS_SUPER_INFO_OFFSET) {
+ bio->bi_bdev = root->fs_info->sb->s_bdev;
+ submit_bio(rw, bio);
+ return 0;
+ }
+ return btrfs_map_bio(BTRFS_I(inode)->root, rw, bio);
+}
+
static int btree_writepage(struct page *page, struct writeback_control *wbc)
{
struct extent_io_tree *tree;
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;
+
+ list = &fs_info->fs_devices->devices;
+ list_for_each(next, list) {
+ device = list_entry(next, struct btrfs_device, dev_list);
+ if (device->bdev && device->bdev != fs_info->sb->s_bdev)
+ close_bdev_excl(device->bdev);
+ device->bdev = NULL;
+ }
+ return 0;
+}
+
struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
u32 blocksize)
{
root->leafsize = leafsize;
root->stripesize = stripesize;
root->ref_cows = 0;
+ root->track_dirty = 0;
+
root->fs_info = fs_info;
root->objectid = objectid;
root->last_trans = 0;
root->last_inode_alloc = 0;
root->name = NULL;
root->in_sysfs = 0;
+
+ INIT_LIST_HEAD(&root->dirty_list);
memset(&root->root_key, 0, sizeof(root->root_key));
memset(&root->root_item, 0, sizeof(root->root_item));
memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
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;
GFP_NOFS);
struct btrfs_fs_info *fs_info = kmalloc(sizeof(*fs_info),
GFP_NOFS);
+ struct btrfs_root *chunk_root = kmalloc(sizeof(struct btrfs_root),
+ GFP_NOFS);
+ struct btrfs_root *dev_root = kmalloc(sizeof(struct btrfs_root),
+ GFP_NOFS);
int ret;
int err = -EIO;
struct btrfs_super_block *disk_super;
fs_info->last_trans_committed = 0;
fs_info->tree_root = tree_root;
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->space_info);
+ btrfs_mapping_init(&fs_info->mapping_tree);
fs_info->sb = sb;
fs_info->throttles = 0;
fs_info->mount_opt = 0;
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);
goto fail_iput;
}
#endif
- __setup_root(512, 512, 512, 512, tree_root,
+ __setup_root(4096, 4096, 4096, 4096, tree_root,
fs_info, BTRFS_ROOT_TREE_OBJECTID);
fs_info->sb_buffer = read_tree_block(tree_root,
BTRFS_SUPER_INFO_OFFSET,
- 512);
+ 4096);
if (!fs_info->sb_buffer)
goto fail_iput;
read_extent_buffer(fs_info->sb_buffer, fs_info->fsid,
(unsigned long)btrfs_super_fsid(fs_info->sb_buffer),
BTRFS_FSID_SIZE);
+
disk_super = &fs_info->super_copy;
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);
goto fail_sb_buffer;
}
+ mutex_lock(&fs_info->fs_mutex);
+
+ ret = btrfs_read_sys_array(tree_root);
+ BUG_ON(ret);
+
+ blocksize = btrfs_level_size(tree_root,
+ btrfs_super_chunk_root_level(disk_super));
+
+ __setup_root(nodesize, leafsize, sectorsize, stripesize,
+ chunk_root, fs_info, BTRFS_CHUNK_TREE_OBJECTID);
+
+ chunk_root->node = read_tree_block(chunk_root,
+ btrfs_super_chunk_root(disk_super),
+ blocksize);
+ BUG_ON(!chunk_root->node);
+
+ ret = btrfs_read_chunk_tree(chunk_root);
+ BUG_ON(ret);
+
blocksize = btrfs_level_size(tree_root,
btrfs_super_root_level(disk_super));
+
tree_root->node = read_tree_block(tree_root,
btrfs_super_root(disk_super),
blocksize);
if (!tree_root->node)
goto fail_sb_buffer;
- mutex_lock(&fs_info->fs_mutex);
ret = find_and_setup_root(tree_root, fs_info,
BTRFS_EXTENT_TREE_OBJECTID, extent_root);
- if (ret) {
- mutex_unlock(&fs_info->fs_mutex);
+ if (ret)
goto fail_tree_root;
- }
+ extent_root->track_dirty = 1;
+
+ ret = find_and_setup_root(tree_root, fs_info,
+ BTRFS_DEV_TREE_OBJECTID, dev_root);
+ dev_root->track_dirty = 1;
+
+ if (ret)
+ goto fail_extent_root;
btrfs_read_block_groups(extent_root);
mutex_unlock(&fs_info->fs_mutex);
return tree_root;
+fail_extent_root:
+ free_extent_buffer(extent_root->node);
fail_tree_root:
+ mutex_unlock(&fs_info->fs_mutex);
free_extent_buffer(tree_root->node);
fail_sb_buffer:
free_extent_buffer(fs_info->sb_buffer);
fail_iput:
iput(fs_info->btree_inode);
fail:
+ close_all_devices(fs_info);
kfree(extent_root);
kfree(tree_root);
kfree(fs_info);
if (fs_info->tree_root->node)
free_extent_buffer(fs_info->tree_root->node);
+ if (root->fs_info->chunk_root->node);
+ free_extent_buffer(root->fs_info->chunk_root->node);
+
+ if (root->fs_info->dev_root->node);
+ free_extent_buffer(root->fs_info->dev_root->node);
+
free_extent_buffer(fs_info->sb_buffer);
btrfs_free_block_groups(root->fs_info);
kfree(hasher);
}
#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);
+ kfree(fs_info->chunk_root);
+ kfree(fs_info->dev_root);
return 0;
}
void btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr)
{
balance_dirty_pages_ratelimited_nr(
- root->fs_info->btree_inode->i_mapping, 1);
+ root->fs_info->btree_inode->i_mapping, 1);
}
void btrfs_set_buffer_defrag(struct extent_buffer *buf)
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,
};