Btrfs: remove device tree
Signed-off-by: Chris Mason <chris.mason@oracle.com>
This commit is contained in:
parent
ad693af684
commit
0cf6c62017
105
fs/btrfs/ctree.h
105
fs/btrfs/ctree.h
|
@ -16,11 +16,10 @@ extern struct kmem_cache *btrfs_path_cachep;
|
|||
#define BTRFS_MAGIC "_BtRfS_M"
|
||||
|
||||
#define BTRFS_ROOT_TREE_OBJECTID 1ULL
|
||||
#define BTRFS_DEV_TREE_OBJECTID 2ULL
|
||||
#define BTRFS_EXTENT_TREE_OBJECTID 3ULL
|
||||
#define BTRFS_FS_TREE_OBJECTID 4ULL
|
||||
#define BTRFS_ROOT_TREE_DIR_OBJECTID 5ULL
|
||||
#define BTRFS_FIRST_FREE_OBJECTID 6ULL
|
||||
#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
|
||||
#define BTRFS_FS_TREE_OBJECTID 3ULL
|
||||
#define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL
|
||||
#define BTRFS_FIRST_FREE_OBJECTID 5ULL
|
||||
|
||||
/*
|
||||
* we can actually store much bigger names, but lets not confuse the rest
|
||||
|
@ -111,12 +110,6 @@ struct btrfs_super_block {
|
|||
__le64 total_blocks;
|
||||
__le64 blocks_used;
|
||||
__le64 root_dir_objectid;
|
||||
__le64 last_device_id;
|
||||
/* fields below here vary with the underlying disk */
|
||||
__le64 device_block_start;
|
||||
__le64 device_num_blocks;
|
||||
__le64 device_root;
|
||||
__le64 device_id;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
/*
|
||||
|
@ -251,11 +244,6 @@ struct btrfs_csum_item {
|
|||
u8 csum;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct btrfs_device_item {
|
||||
__le16 pathlen;
|
||||
__le64 device_id;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
/* tag for the radix tree of block groups in ram */
|
||||
#define BTRFS_BLOCK_GROUP_DIRTY 0
|
||||
#define BTRFS_BLOCK_GROUP_AVAIL 1
|
||||
|
@ -286,11 +274,9 @@ struct btrfs_fs_info {
|
|||
spinlock_t hash_lock;
|
||||
struct btrfs_root *extent_root;
|
||||
struct btrfs_root *tree_root;
|
||||
struct btrfs_root *dev_root;
|
||||
struct radix_tree_root fs_roots_radix;
|
||||
struct radix_tree_root pending_del_radix;
|
||||
struct radix_tree_root pinned_radix;
|
||||
struct radix_tree_root dev_radix;
|
||||
struct radix_tree_root block_group_radix;
|
||||
struct radix_tree_root block_group_data_radix;
|
||||
struct radix_tree_root extent_map_radix;
|
||||
|
@ -385,11 +371,6 @@ struct btrfs_root {
|
|||
*/
|
||||
#define BTRFS_BLOCK_GROUP_ITEM_KEY 34
|
||||
|
||||
/*
|
||||
* dev items list the devices that make up the FS
|
||||
*/
|
||||
#define BTRFS_DEV_ITEM_KEY 35
|
||||
|
||||
/*
|
||||
* string items are for debugging. They just store a short string of
|
||||
* data in the FS
|
||||
|
@ -880,62 +861,6 @@ static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
|
|||
s->root_dir_objectid = cpu_to_le64(val);
|
||||
}
|
||||
|
||||
static inline u64 btrfs_super_last_device_id(struct btrfs_super_block *s)
|
||||
{
|
||||
return le64_to_cpu(s->last_device_id);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_super_last_device_id(struct btrfs_super_block *s,
|
||||
u64 val)
|
||||
{
|
||||
s->last_device_id = cpu_to_le64(val);
|
||||
}
|
||||
|
||||
static inline u64 btrfs_super_device_id(struct btrfs_super_block *s)
|
||||
{
|
||||
return le64_to_cpu(s->device_id);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_super_device_id(struct btrfs_super_block *s,
|
||||
u64 val)
|
||||
{
|
||||
s->device_id = cpu_to_le64(val);
|
||||
}
|
||||
|
||||
static inline u64 btrfs_super_device_block_start(struct btrfs_super_block *s)
|
||||
{
|
||||
return le64_to_cpu(s->device_block_start);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_super_device_block_start(struct btrfs_super_block
|
||||
*s, u64 val)
|
||||
{
|
||||
s->device_block_start = cpu_to_le64(val);
|
||||
}
|
||||
|
||||
static inline u64 btrfs_super_device_num_blocks(struct btrfs_super_block *s)
|
||||
{
|
||||
return le64_to_cpu(s->device_num_blocks);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_super_device_num_blocks(struct btrfs_super_block
|
||||
*s, u64 val)
|
||||
{
|
||||
s->device_num_blocks = cpu_to_le64(val);
|
||||
}
|
||||
|
||||
static inline u64 btrfs_super_device_root(struct btrfs_super_block *s)
|
||||
{
|
||||
return le64_to_cpu(s->device_root);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_super_device_root(struct btrfs_super_block
|
||||
*s, u64 val)
|
||||
{
|
||||
s->device_root = cpu_to_le64(val);
|
||||
}
|
||||
|
||||
|
||||
static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
|
||||
{
|
||||
return (u8 *)l->items;
|
||||
|
@ -1031,28 +956,6 @@ static inline void btrfs_set_file_extent_num_blocks(struct
|
|||
e->num_blocks = cpu_to_le64(val);
|
||||
}
|
||||
|
||||
static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d)
|
||||
{
|
||||
return le16_to_cpu(d->pathlen);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d,
|
||||
u16 val)
|
||||
{
|
||||
d->pathlen = cpu_to_le16(val);
|
||||
}
|
||||
|
||||
static inline u64 btrfs_device_id(struct btrfs_device_item *d)
|
||||
{
|
||||
return le64_to_cpu(d->device_id);
|
||||
}
|
||||
|
||||
static inline void btrfs_set_device_id(struct btrfs_device_item *d,
|
||||
u64 val)
|
||||
{
|
||||
d->device_id = cpu_to_le64(val);
|
||||
}
|
||||
|
||||
static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
|
||||
{
|
||||
return sb->s_fs_info;
|
||||
|
|
|
@ -11,47 +11,9 @@
|
|||
#include "transaction.h"
|
||||
#include "btrfs_inode.h"
|
||||
|
||||
struct dev_lookup {
|
||||
u64 block_start;
|
||||
u64 num_blocks;
|
||||
u64 device_id;
|
||||
struct block_device *bdev;
|
||||
};
|
||||
|
||||
int btrfs_insert_dev_radix(struct btrfs_root *root,
|
||||
struct block_device *bdev,
|
||||
u64 device_id,
|
||||
u64 block_start,
|
||||
u64 num_blocks)
|
||||
{
|
||||
struct dev_lookup *lookup;
|
||||
int ret;
|
||||
|
||||
lookup = kmalloc(sizeof(*lookup), GFP_NOFS);
|
||||
if (!lookup)
|
||||
return -ENOMEM;
|
||||
lookup->block_start = block_start;
|
||||
lookup->num_blocks = num_blocks;
|
||||
lookup->bdev = bdev;
|
||||
lookup->device_id = device_id;
|
||||
|
||||
ret = radix_tree_insert(&root->fs_info->dev_radix, block_start +
|
||||
num_blocks - 1, lookup);
|
||||
return ret;
|
||||
}
|
||||
|
||||
u64 bh_blocknr(struct buffer_head *bh)
|
||||
{
|
||||
int blkbits = bh->b_page->mapping->host->i_blkbits;
|
||||
u64 blocknr = bh->b_page->index << (PAGE_CACHE_SHIFT - blkbits);
|
||||
unsigned long offset;
|
||||
|
||||
if (PageHighMem(bh->b_page))
|
||||
offset = (unsigned long)bh->b_data;
|
||||
else
|
||||
offset = bh->b_data - (char *)page_address(bh->b_page);
|
||||
blocknr += offset >> (PAGE_CACHE_SHIFT - blkbits);
|
||||
return blocknr;
|
||||
return bh->b_blocknr;
|
||||
}
|
||||
|
||||
static int check_tree_block(struct btrfs_root *root, struct buffer_head *buf)
|
||||
|
@ -102,32 +64,14 @@ out_unlock:
|
|||
int btrfs_map_bh_to_logical(struct btrfs_root *root, struct buffer_head *bh,
|
||||
u64 logical)
|
||||
{
|
||||
struct dev_lookup *lookup[2];
|
||||
|
||||
int ret;
|
||||
|
||||
if (logical == 0) {
|
||||
bh->b_bdev = NULL;
|
||||
bh->b_blocknr = 0;
|
||||
set_buffer_mapped(bh);
|
||||
return 0;
|
||||
} else {
|
||||
map_bh(bh, root->fs_info->sb, logical);
|
||||
}
|
||||
root = root->fs_info->dev_root;
|
||||
ret = radix_tree_gang_lookup(&root->fs_info->dev_radix,
|
||||
(void **)lookup,
|
||||
(unsigned long)logical,
|
||||
ARRAY_SIZE(lookup));
|
||||
if (ret == 0 || lookup[0]->block_start > logical ||
|
||||
lookup[0]->block_start + lookup[0]->num_blocks <= logical) {
|
||||
ret = -ENOENT;
|
||||
goto out;
|
||||
}
|
||||
bh->b_bdev = lookup[0]->bdev;
|
||||
bh->b_blocknr = logical - lookup[0]->block_start;
|
||||
set_buffer_mapped(bh);
|
||||
ret = 0;
|
||||
out:
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct buffer_head *btrfs_find_create_tree_block(struct btrfs_root *root,
|
||||
|
@ -382,24 +326,18 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
|
|||
u64 highest_inode;
|
||||
int ret = 0;
|
||||
|
||||
printk("read_fs_root looking for %Lu %Lu %u\n", location->objectid, location->offset, location->flags);
|
||||
root = radix_tree_lookup(&fs_info->fs_roots_radix,
|
||||
(unsigned long)location->objectid);
|
||||
if (root) {
|
||||
printk("found %p in cache\n", root);
|
||||
if (root)
|
||||
return root;
|
||||
}
|
||||
root = kmalloc(sizeof(*root), GFP_NOFS);
|
||||
if (!root) {
|
||||
printk("failed1\n");
|
||||
if (!root)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
}
|
||||
if (location->offset == (u64)-1) {
|
||||
ret = find_and_setup_root(fs_info->sb->s_blocksize,
|
||||
fs_info->tree_root, fs_info,
|
||||
location->objectid, root);
|
||||
if (ret) {
|
||||
printk("failed2\n");
|
||||
kfree(root);
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
|
@ -413,7 +351,6 @@ printk("failed2\n");
|
|||
BUG_ON(!path);
|
||||
ret = btrfs_search_slot(NULL, tree_root, location, path, 0, 0);
|
||||
if (ret != 0) {
|
||||
printk("internal search_slot gives us %d\n", ret);
|
||||
if (ret > 0)
|
||||
ret = -ENOENT;
|
||||
goto out;
|
||||
|
@ -435,13 +372,11 @@ out:
|
|||
btrfs_root_blocknr(&root->root_item));
|
||||
BUG_ON(!root->node);
|
||||
insert:
|
||||
printk("inserting %p\n", root);
|
||||
root->ref_cows = 1;
|
||||
ret = radix_tree_insert(&fs_info->fs_roots_radix,
|
||||
(unsigned long)root->root_key.objectid,
|
||||
root);
|
||||
if (ret) {
|
||||
printk("radix_tree_insert gives us %d\n", ret);
|
||||
brelse(root->node);
|
||||
kfree(root);
|
||||
return ERR_PTR(ret);
|
||||
|
@ -450,116 +385,25 @@ printk("radix_tree_insert gives us %d\n", ret);
|
|||
if (ret == 0) {
|
||||
root->highest_inode = highest_inode;
|
||||
root->last_inode_alloc = highest_inode;
|
||||
printk("highest inode is %Lu\n", highest_inode);
|
||||
}
|
||||
printk("all worked\n");
|
||||
return root;
|
||||
}
|
||||
|
||||
static int btrfs_open_disk(struct btrfs_root *root, u64 device_id,
|
||||
u64 block_start, u64 num_blocks,
|
||||
char *filename, int name_len)
|
||||
{
|
||||
char *null_filename;
|
||||
struct block_device *bdev;
|
||||
int ret;
|
||||
|
||||
null_filename = kmalloc(name_len + 1, GFP_NOFS);
|
||||
if (!null_filename)
|
||||
return -ENOMEM;
|
||||
memcpy(null_filename, filename, name_len);
|
||||
null_filename[name_len] = '\0';
|
||||
|
||||
bdev = open_bdev_excl(null_filename, O_RDWR, root->fs_info->sb);
|
||||
if (IS_ERR(bdev)) {
|
||||
ret = PTR_ERR(bdev);
|
||||
goto out;
|
||||
}
|
||||
set_blocksize(bdev, root->fs_info->sb->s_blocksize);
|
||||
ret = btrfs_insert_dev_radix(root, bdev, device_id,
|
||||
block_start, num_blocks);
|
||||
BUG_ON(ret);
|
||||
ret = 0;
|
||||
out:
|
||||
kfree(null_filename);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int read_device_info(struct btrfs_root *root)
|
||||
{
|
||||
struct btrfs_path *path;
|
||||
int ret;
|
||||
struct btrfs_key key;
|
||||
struct btrfs_leaf *leaf;
|
||||
struct btrfs_device_item *dev_item;
|
||||
int nritems;
|
||||
int slot;
|
||||
|
||||
root = root->fs_info->dev_root;
|
||||
|
||||
path = btrfs_alloc_path();
|
||||
if (!path)
|
||||
return -ENOMEM;
|
||||
key.objectid = 0;
|
||||
key.offset = 0;
|
||||
key.flags = 0;
|
||||
btrfs_set_key_type(&key, BTRFS_DEV_ITEM_KEY);
|
||||
|
||||
mutex_lock(&root->fs_info->fs_mutex);
|
||||
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
|
||||
leaf = btrfs_buffer_leaf(path->nodes[0]);
|
||||
nritems = btrfs_header_nritems(&leaf->header);
|
||||
while(1) {
|
||||
slot = path->slots[0];
|
||||
if (slot >= nritems) {
|
||||
ret = btrfs_next_leaf(root, path);
|
||||
if (ret)
|
||||
break;
|
||||
leaf = btrfs_buffer_leaf(path->nodes[0]);
|
||||
nritems = btrfs_header_nritems(&leaf->header);
|
||||
slot = path->slots[0];
|
||||
}
|
||||
btrfs_disk_key_to_cpu(&key, &leaf->items[slot].key);
|
||||
if (btrfs_key_type(&key) != BTRFS_DEV_ITEM_KEY) {
|
||||
path->slots[0]++;
|
||||
continue;
|
||||
}
|
||||
dev_item = btrfs_item_ptr(leaf, slot, struct btrfs_device_item);
|
||||
printk("found key %Lu %Lu\n", key.objectid, key.offset);
|
||||
if (btrfs_device_id(dev_item) !=
|
||||
btrfs_super_device_id(root->fs_info->disk_super)) {
|
||||
ret = btrfs_open_disk(root, btrfs_device_id(dev_item),
|
||||
key.objectid, key.offset,
|
||||
(char *)(dev_item + 1),
|
||||
btrfs_device_pathlen(dev_item));
|
||||
BUG_ON(ret);
|
||||
}
|
||||
path->slots[0]++;
|
||||
}
|
||||
btrfs_free_path(path);
|
||||
mutex_unlock(&root->fs_info->fs_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct btrfs_root *open_ctree(struct super_block *sb)
|
||||
{
|
||||
struct btrfs_root *extent_root = kmalloc(sizeof(struct btrfs_root),
|
||||
GFP_NOFS);
|
||||
struct btrfs_root *dev_root = kmalloc(sizeof(struct btrfs_root),
|
||||
GFP_NOFS);
|
||||
struct btrfs_root *tree_root = kmalloc(sizeof(struct btrfs_root),
|
||||
GFP_NOFS);
|
||||
struct btrfs_fs_info *fs_info = kmalloc(sizeof(*fs_info),
|
||||
GFP_NOFS);
|
||||
int ret;
|
||||
struct btrfs_super_block *disk_super;
|
||||
struct dev_lookup *dev_lookup;
|
||||
|
||||
init_bit_radix(&fs_info->pinned_radix);
|
||||
init_bit_radix(&fs_info->pending_del_radix);
|
||||
init_bit_radix(&fs_info->extent_map_radix);
|
||||
INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_NOFS);
|
||||
INIT_RADIX_TREE(&fs_info->dev_radix, GFP_NOFS);
|
||||
INIT_RADIX_TREE(&fs_info->block_group_radix, GFP_KERNEL);
|
||||
INIT_RADIX_TREE(&fs_info->block_group_data_radix, GFP_KERNEL);
|
||||
INIT_LIST_HEAD(&fs_info->trans_list);
|
||||
|
@ -568,7 +412,6 @@ struct btrfs_root *open_ctree(struct super_block *sb)
|
|||
fs_info->running_transaction = NULL;
|
||||
fs_info->tree_root = tree_root;
|
||||
fs_info->extent_root = extent_root;
|
||||
fs_info->dev_root = dev_root;
|
||||
fs_info->sb = sb;
|
||||
fs_info->btree_inode = new_inode(sb);
|
||||
fs_info->btree_inode->i_ino = 1;
|
||||
|
@ -595,19 +438,9 @@ struct btrfs_root *open_ctree(struct super_block *sb)
|
|||
mutex_init(&fs_info->trans_mutex);
|
||||
mutex_init(&fs_info->fs_mutex);
|
||||
|
||||
__setup_root(sb->s_blocksize, dev_root,
|
||||
fs_info, BTRFS_DEV_TREE_OBJECTID);
|
||||
|
||||
__setup_root(sb->s_blocksize, tree_root,
|
||||
fs_info, BTRFS_ROOT_TREE_OBJECTID);
|
||||
|
||||
dev_lookup = kmalloc(sizeof(*dev_lookup), GFP_NOFS);
|
||||
dev_lookup->block_start = 0;
|
||||
dev_lookup->num_blocks = (u32)-2;
|
||||
dev_lookup->bdev = sb->s_bdev;
|
||||
dev_lookup->device_id = 0;
|
||||
ret = radix_tree_insert(&fs_info->dev_radix, (u32)-2, dev_lookup);
|
||||
BUG_ON(ret);
|
||||
fs_info->sb_buffer = read_tree_block(tree_root,
|
||||
BTRFS_SUPER_INFO_OFFSET /
|
||||
sb->s_blocksize);
|
||||
|
@ -622,24 +455,7 @@ struct btrfs_root *open_ctree(struct super_block *sb)
|
|||
btrfs_super_total_blocks(disk_super) <<
|
||||
fs_info->btree_inode->i_blkbits);
|
||||
|
||||
radix_tree_delete(&fs_info->dev_radix, (u32)-2);
|
||||
dev_lookup->block_start = btrfs_super_device_block_start(disk_super);
|
||||
dev_lookup->num_blocks = btrfs_super_device_num_blocks(disk_super);
|
||||
dev_lookup->device_id = btrfs_super_device_id(disk_super);
|
||||
|
||||
ret = radix_tree_insert(&fs_info->dev_radix,
|
||||
dev_lookup->block_start +
|
||||
dev_lookup->num_blocks - 1, dev_lookup);
|
||||
BUG_ON(ret);
|
||||
|
||||
fs_info->disk_super = disk_super;
|
||||
|
||||
dev_root->node = read_tree_block(tree_root,
|
||||
btrfs_super_device_root(disk_super));
|
||||
|
||||
ret = read_device_info(dev_root);
|
||||
BUG_ON(ret);
|
||||
|
||||
tree_root->node = read_tree_block(tree_root,
|
||||
btrfs_super_root(disk_super));
|
||||
BUG_ON(!tree_root->node);
|
||||
|
@ -719,30 +535,6 @@ static int del_fs_roots(struct btrfs_fs_info *fs_info)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int free_dev_radix(struct btrfs_fs_info *fs_info)
|
||||
{
|
||||
struct dev_lookup *lookup[8];
|
||||
struct block_device *super_bdev = fs_info->sb->s_bdev;
|
||||
int ret;
|
||||
int i;
|
||||
while(1) {
|
||||
ret = radix_tree_gang_lookup(&fs_info->dev_radix,
|
||||
(void **)lookup, 0,
|
||||
ARRAY_SIZE(lookup));
|
||||
if (!ret)
|
||||
break;
|
||||
for (i = 0; i < ret; i++) {
|
||||
if (lookup[i]->bdev != super_bdev)
|
||||
close_bdev_excl(lookup[i]->bdev);
|
||||
radix_tree_delete(&fs_info->dev_radix,
|
||||
lookup[i]->block_start +
|
||||
lookup[i]->num_blocks - 1);
|
||||
kfree(lookup[i]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int close_ctree(struct btrfs_root *root)
|
||||
{
|
||||
int ret;
|
||||
|
@ -765,9 +557,6 @@ int close_ctree(struct btrfs_root *root)
|
|||
if (fs_info->extent_root->node)
|
||||
btrfs_block_release(fs_info->extent_root,
|
||||
fs_info->extent_root->node);
|
||||
if (fs_info->dev_root->node)
|
||||
btrfs_block_release(fs_info->dev_root,
|
||||
fs_info->dev_root->node);
|
||||
if (fs_info->tree_root->node)
|
||||
btrfs_block_release(fs_info->tree_root,
|
||||
fs_info->tree_root->node);
|
||||
|
@ -776,7 +565,6 @@ int close_ctree(struct btrfs_root *root)
|
|||
truncate_inode_pages(fs_info->btree_inode->i_mapping, 0);
|
||||
iput(fs_info->btree_inode);
|
||||
|
||||
free_dev_radix(fs_info);
|
||||
btrfs_free_block_groups(root->fs_info);
|
||||
del_fs_roots(fs_info);
|
||||
kfree(fs_info->extent_root);
|
||||
|
|
|
@ -2566,83 +2566,6 @@ static int create_snapshot(struct btrfs_root *root, char *name, int namelen)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int add_disk(struct btrfs_root *root, char *name, int namelen)
|
||||
{
|
||||
struct block_device *bdev;
|
||||
struct btrfs_path *path;
|
||||
struct super_block *sb = root->fs_info->sb;
|
||||
struct btrfs_root *dev_root = root->fs_info->dev_root;
|
||||
struct btrfs_trans_handle *trans;
|
||||
struct btrfs_device_item *dev_item;
|
||||
struct btrfs_key key;
|
||||
u16 item_size;
|
||||
u64 num_blocks;
|
||||
u64 new_blocks;
|
||||
u64 device_id;
|
||||
int ret;
|
||||
|
||||
printk("adding disk %s\n", name);
|
||||
path = btrfs_alloc_path();
|
||||
if (!path)
|
||||
return -ENOMEM;
|
||||
num_blocks = btrfs_super_total_blocks(root->fs_info->disk_super);
|
||||
bdev = open_bdev_excl(name, O_RDWR, sb);
|
||||
if (IS_ERR(bdev)) {
|
||||
ret = PTR_ERR(bdev);
|
||||
printk("open bdev excl failed ret %d\n", ret);
|
||||
goto out_nolock;
|
||||
}
|
||||
set_blocksize(bdev, sb->s_blocksize);
|
||||
new_blocks = bdev->bd_inode->i_size >> sb->s_blocksize_bits;
|
||||
key.objectid = num_blocks;
|
||||
key.offset = new_blocks;
|
||||
key.flags = 0;
|
||||
btrfs_set_key_type(&key, BTRFS_DEV_ITEM_KEY);
|
||||
|
||||
mutex_lock(&dev_root->fs_info->fs_mutex);
|
||||
trans = btrfs_start_transaction(dev_root, 1);
|
||||
item_size = sizeof(*dev_item) + namelen;
|
||||
printk("insert empty on %Lu %Lu %u size %d\n", num_blocks, new_blocks, key.flags, item_size);
|
||||
ret = btrfs_insert_empty_item(trans, dev_root, path, &key, item_size);
|
||||
if (ret) {
|
||||
printk("insert failed %d\n", ret);
|
||||
close_bdev_excl(bdev);
|
||||
if (ret > 0)
|
||||
ret = -EEXIST;
|
||||
goto out;
|
||||
}
|
||||
dev_item = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
|
||||
path->slots[0], struct btrfs_device_item);
|
||||
btrfs_set_device_pathlen(dev_item, namelen);
|
||||
memcpy(dev_item + 1, name, namelen);
|
||||
|
||||
device_id = btrfs_super_last_device_id(root->fs_info->disk_super) + 1;
|
||||
btrfs_set_super_last_device_id(root->fs_info->disk_super, device_id);
|
||||
btrfs_set_device_id(dev_item, device_id);
|
||||
mark_buffer_dirty(path->nodes[0]);
|
||||
|
||||
ret = btrfs_insert_dev_radix(root, bdev, device_id, num_blocks,
|
||||
new_blocks);
|
||||
|
||||
if (!ret) {
|
||||
btrfs_set_super_total_blocks(root->fs_info->disk_super,
|
||||
num_blocks + new_blocks);
|
||||
i_size_write(root->fs_info->btree_inode,
|
||||
(num_blocks + new_blocks) <<
|
||||
root->fs_info->btree_inode->i_blkbits);
|
||||
}
|
||||
|
||||
out:
|
||||
ret = btrfs_commit_transaction(trans, dev_root);
|
||||
BUG_ON(ret);
|
||||
mutex_unlock(&root->fs_info->fs_mutex);
|
||||
out_nolock:
|
||||
btrfs_free_path(path);
|
||||
btrfs_btree_balance_dirty(root);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int btrfs_ioctl(struct inode *inode, struct file *filp, unsigned int
|
||||
cmd, unsigned long arg)
|
||||
{
|
||||
|
@ -2682,17 +2605,6 @@ static int btrfs_ioctl(struct inode *inode, struct file *filp, unsigned int
|
|||
ret = create_snapshot(root, vol_args.name, namelen);
|
||||
WARN_ON(ret);
|
||||
break;
|
||||
case BTRFS_IOC_ADD_DISK:
|
||||
if (copy_from_user(&vol_args,
|
||||
(struct btrfs_ioctl_vol_args __user *)arg,
|
||||
sizeof(vol_args)))
|
||||
return -EFAULT;
|
||||
namelen = strlen(vol_args.name);
|
||||
if (namelen > BTRFS_VOL_NAME_MAX)
|
||||
return -EINVAL;
|
||||
vol_args.name[namelen] = '\0';
|
||||
ret = add_disk(root, vol_args.name, namelen);
|
||||
break;
|
||||
default:
|
||||
return -ENOTTY;
|
||||
}
|
||||
|
|
|
@ -150,13 +150,7 @@ int btrfs_commit_tree_roots(struct btrfs_trans_handle *trans,
|
|||
struct btrfs_fs_info *fs_info = root->fs_info;
|
||||
struct btrfs_root *tree_root = fs_info->tree_root;
|
||||
struct btrfs_root *extent_root = fs_info->extent_root;
|
||||
struct btrfs_root *dev_root = fs_info->dev_root;
|
||||
|
||||
if (btrfs_super_device_root(fs_info->disk_super) !=
|
||||
bh_blocknr(dev_root->node)) {
|
||||
btrfs_set_super_device_root(fs_info->disk_super,
|
||||
bh_blocknr(dev_root->node));
|
||||
}
|
||||
btrfs_write_dirty_block_groups(trans, extent_root);
|
||||
while(1) {
|
||||
old_extent_block = btrfs_root_blocknr(&extent_root->root_item);
|
||||
|
|
Loading…
Reference in a new issue