Commit 04160088 authored by Chris Mason's avatar Chris Mason

Create a btrfs backing dev info

This allows intelligent versions of unplug and congestion functions
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 593060d7
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/backing-dev.h>
#include <asm/kmap_types.h> #include <asm/kmap_types.h>
#include "bit-radix.h" #include "bit-radix.h"
#include "extent_io.h" #include "extent_io.h"
...@@ -472,6 +473,7 @@ struct btrfs_fs_info { ...@@ -472,6 +473,7 @@ struct btrfs_fs_info {
struct block_device *__bdev; struct block_device *__bdev;
struct super_block *sb; struct super_block *sb;
struct inode *btree_inode; struct inode *btree_inode;
struct backing_dev_info bdi;
spinlock_t hash_lock; spinlock_t hash_lock;
struct mutex trans_mutex; struct mutex trans_mutex;
struct mutex fs_mutex; struct mutex fs_mutex;
......
...@@ -655,6 +655,55 @@ static int add_hasher(struct btrfs_fs_info *info, char *type) { ...@@ -655,6 +655,55 @@ static int add_hasher(struct btrfs_fs_info *info, char *type) {
return 0; return 0;
} }
#endif #endif
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_root *open_ctree(struct super_block *sb,
struct btrfs_fs_devices *fs_devices) struct btrfs_fs_devices *fs_devices)
{ {
...@@ -708,11 +757,14 @@ struct btrfs_root *open_ctree(struct super_block *sb, ...@@ -708,11 +757,14 @@ struct btrfs_root *open_ctree(struct super_block *sb,
fs_info->max_extent = (u64)-1; fs_info->max_extent = (u64)-1;
fs_info->max_inline = 8192 * 1024; fs_info->max_inline = 8192 * 1024;
fs_info->delalloc_bytes = 0; fs_info->delalloc_bytes = 0;
setup_bdi(fs_info, &fs_info->bdi);
fs_info->btree_inode = new_inode(sb); fs_info->btree_inode = new_inode(sb);
fs_info->btree_inode->i_ino = 1; fs_info->btree_inode->i_ino = 1;
fs_info->btree_inode->i_nlink = 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_size = sb->s_bdev->bd_inode->i_size;
fs_info->btree_inode->i_mapping->a_ops = &btree_aops; 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, extent_io_tree_init(&BTRFS_I(fs_info->btree_inode)->io_tree,
fs_info->btree_inode->i_mapping, fs_info->btree_inode->i_mapping,
GFP_NOFS); GFP_NOFS);
...@@ -992,6 +1044,7 @@ int close_ctree(struct btrfs_root *root) ...@@ -992,6 +1044,7 @@ int close_ctree(struct btrfs_root *root)
#endif #endif
close_all_devices(fs_info); close_all_devices(fs_info);
btrfs_mapping_tree_free(&fs_info->mapping_tree); btrfs_mapping_tree_free(&fs_info->mapping_tree);
bdi_destroy(&fs_info->bdi);
kfree(fs_info->extent_root); kfree(fs_info->extent_root);
kfree(fs_info->tree_root); kfree(fs_info->tree_root);
......
...@@ -494,6 +494,7 @@ void btrfs_read_locked_inode(struct inode *inode) ...@@ -494,6 +494,7 @@ void btrfs_read_locked_inode(struct inode *inode)
switch (inode->i_mode & S_IFMT) { switch (inode->i_mode & S_IFMT) {
case S_IFREG: case S_IFREG:
inode->i_mapping->a_ops = &btrfs_aops; inode->i_mapping->a_ops = &btrfs_aops;
inode->i_mapping->backing_dev_info = &root->fs_info->bdi;
BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
inode->i_fop = &btrfs_file_operations; inode->i_fop = &btrfs_file_operations;
inode->i_op = &btrfs_file_inode_operations; inode->i_op = &btrfs_file_inode_operations;
...@@ -508,6 +509,7 @@ void btrfs_read_locked_inode(struct inode *inode) ...@@ -508,6 +509,7 @@ void btrfs_read_locked_inode(struct inode *inode)
case S_IFLNK: case S_IFLNK:
inode->i_op = &btrfs_symlink_inode_operations; inode->i_op = &btrfs_symlink_inode_operations;
inode->i_mapping->a_ops = &btrfs_symlink_aops; inode->i_mapping->a_ops = &btrfs_symlink_aops;
inode->i_mapping->backing_dev_info = &root->fs_info->bdi;
break; break;
default: default:
init_special_inode(inode, inode->i_mode, rdev); init_special_inode(inode, inode->i_mode, rdev);
...@@ -1792,6 +1794,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, ...@@ -1792,6 +1794,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
drop_inode = 1; drop_inode = 1;
else { else {
inode->i_mapping->a_ops = &btrfs_aops; inode->i_mapping->a_ops = &btrfs_aops;
inode->i_mapping->backing_dev_info = &root->fs_info->bdi;
inode->i_fop = &btrfs_file_operations; inode->i_fop = &btrfs_file_operations;
inode->i_op = &btrfs_file_inode_operations; inode->i_op = &btrfs_file_inode_operations;
extent_map_tree_init(&BTRFS_I(inode)->extent_tree, GFP_NOFS); extent_map_tree_init(&BTRFS_I(inode)->extent_tree, GFP_NOFS);
...@@ -2960,6 +2963,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, ...@@ -2960,6 +2963,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
drop_inode = 1; drop_inode = 1;
else { else {
inode->i_mapping->a_ops = &btrfs_aops; inode->i_mapping->a_ops = &btrfs_aops;
inode->i_mapping->backing_dev_info = &root->fs_info->bdi;
inode->i_fop = &btrfs_file_operations; inode->i_fop = &btrfs_file_operations;
inode->i_op = &btrfs_file_inode_operations; inode->i_op = &btrfs_file_inode_operations;
extent_map_tree_init(&BTRFS_I(inode)->extent_tree, GFP_NOFS); extent_map_tree_init(&BTRFS_I(inode)->extent_tree, GFP_NOFS);
...@@ -2999,6 +3003,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, ...@@ -2999,6 +3003,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
inode->i_op = &btrfs_symlink_inode_operations; inode->i_op = &btrfs_symlink_inode_operations;
inode->i_mapping->a_ops = &btrfs_symlink_aops; inode->i_mapping->a_ops = &btrfs_symlink_aops;
inode->i_mapping->backing_dev_info = &root->fs_info->bdi;
inode->i_size = name_len - 1; inode->i_size = name_len - 1;
err = btrfs_update_inode(trans, root, inode); err = btrfs_update_inode(trans, root, inode);
if (err) if (err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment