Commit d756bd2d authored by Chris Mason's avatar Chris Mason

Merge branch 'for-chris' of git://repo.or.cz/linux-btrfs-devel into integration

Conflicts:
	fs/btrfs/volumes.c
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parents 27263e28 b367e47f
...@@ -2278,9 +2278,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, ...@@ -2278,9 +2278,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,
(unsigned long)btrfs_header_chunk_tree_uuid(chunk_root->node), (unsigned long)btrfs_header_chunk_tree_uuid(chunk_root->node),
BTRFS_UUID_SIZE); BTRFS_UUID_SIZE);
mutex_lock(&fs_info->chunk_mutex);
ret = btrfs_read_chunk_tree(chunk_root); ret = btrfs_read_chunk_tree(chunk_root);
mutex_unlock(&fs_info->chunk_mutex);
if (ret) { if (ret) {
printk(KERN_WARNING "btrfs: failed to read chunk tree on %s\n", printk(KERN_WARNING "btrfs: failed to read chunk tree on %s\n",
sb->s_id); sb->s_id);
......
...@@ -7143,7 +7143,7 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr) ...@@ -7143,7 +7143,7 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
* space to fit our block group in. * space to fit our block group in.
*/ */
if (device->total_bytes > device->bytes_used + min_free) { if (device->total_bytes > device->bytes_used + min_free) {
ret = find_free_dev_extent(NULL, device, min_free, ret = find_free_dev_extent(device, min_free,
&dev_offset, NULL); &dev_offset, NULL);
if (!ret) if (!ret)
dev_nr++; dev_nr++;
...@@ -7505,6 +7505,7 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans, ...@@ -7505,6 +7505,7 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
ret = update_space_info(root->fs_info, cache->flags, size, bytes_used, ret = update_space_info(root->fs_info, cache->flags, size, bytes_used,
&cache->space_info); &cache->space_info);
BUG_ON(ret); BUG_ON(ret);
update_global_block_rsv(root->fs_info);
spin_lock(&cache->space_info->lock); spin_lock(&cache->space_info->lock);
cache->space_info->bytes_readonly += cache->bytes_super; cache->space_info->bytes_readonly += cache->bytes_super;
......
This diff is collapsed.
...@@ -176,6 +176,8 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -176,6 +176,8 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
unsigned int flags, oldflags; unsigned int flags, oldflags;
int ret; int ret;
u64 ip_oldflags;
unsigned int i_oldflags;
if (btrfs_root_readonly(root)) if (btrfs_root_readonly(root))
return -EROFS; return -EROFS;
...@@ -192,6 +194,9 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -192,6 +194,9 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
mutex_lock(&inode->i_mutex); mutex_lock(&inode->i_mutex);
ip_oldflags = ip->flags;
i_oldflags = inode->i_flags;
flags = btrfs_mask_flags(inode->i_mode, flags); flags = btrfs_mask_flags(inode->i_mode, flags);
oldflags = btrfs_flags_to_ioctl(ip->flags); oldflags = btrfs_flags_to_ioctl(ip->flags);
if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) { if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
...@@ -249,19 +254,24 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -249,19 +254,24 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
ip->flags &= ~(BTRFS_INODE_COMPRESS | BTRFS_INODE_NOCOMPRESS); ip->flags &= ~(BTRFS_INODE_COMPRESS | BTRFS_INODE_NOCOMPRESS);
} }
trans = btrfs_join_transaction(root); trans = btrfs_start_transaction(root, 1);
BUG_ON(IS_ERR(trans)); if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
goto out_drop;
}
btrfs_update_iflags(inode); btrfs_update_iflags(inode);
inode->i_ctime = CURRENT_TIME; inode->i_ctime = CURRENT_TIME;
ret = btrfs_update_inode(trans, root, inode); ret = btrfs_update_inode(trans, root, inode);
BUG_ON(ret);
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
out_drop:
if (ret) {
ip->flags = ip_oldflags;
inode->i_flags = i_oldflags;
}
mnt_drop_write(file->f_path.mnt); mnt_drop_write(file->f_path.mnt);
ret = 0;
out_unlock: out_unlock:
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
return ret; return ret;
......
...@@ -830,7 +830,6 @@ int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start, ...@@ -830,7 +830,6 @@ int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start,
/* /*
* find_free_dev_extent - find free space in the specified device * find_free_dev_extent - find free space in the specified device
* @trans: transaction handler
* @device: the device which we search the free space in * @device: the device which we search the free space in
* @num_bytes: the size of the free space that we need * @num_bytes: the size of the free space that we need
* @start: store the start of the free space. * @start: store the start of the free space.
...@@ -849,8 +848,7 @@ int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start, ...@@ -849,8 +848,7 @@ int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start,
* But if we don't find suitable free space, it is used to store the size of * But if we don't find suitable free space, it is used to store the size of
* the max free space. * the max free space.
*/ */
int find_free_dev_extent(struct btrfs_trans_handle *trans, int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
struct btrfs_device *device, u64 num_bytes,
u64 *start, u64 *len) u64 *start, u64 *len)
{ {
struct btrfs_key key; struct btrfs_key key;
...@@ -894,7 +892,7 @@ int find_free_dev_extent(struct btrfs_trans_handle *trans, ...@@ -894,7 +892,7 @@ int find_free_dev_extent(struct btrfs_trans_handle *trans,
key.offset = search_start; key.offset = search_start;
key.type = BTRFS_DEV_EXTENT_KEY; key.type = BTRFS_DEV_EXTENT_KEY;
ret = btrfs_search_slot(trans, root, &key, path, 0, 0); ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0) if (ret < 0)
goto out; goto out;
if (ret > 0) { if (ret > 0) {
...@@ -1468,8 +1466,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) ...@@ -1468,8 +1466,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
/* /*
* does all the dirty work required for changing file system's UUID. * does all the dirty work required for changing file system's UUID.
*/ */
static int btrfs_prepare_sprout(struct btrfs_trans_handle *trans, static int btrfs_prepare_sprout(struct btrfs_root *root)
struct btrfs_root *root)
{ {
struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
struct btrfs_fs_devices *old_devices; struct btrfs_fs_devices *old_devices;
...@@ -1693,7 +1690,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) ...@@ -1693,7 +1690,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
if (seeding_dev) { if (seeding_dev) {
sb->s_flags &= ~MS_RDONLY; sb->s_flags &= ~MS_RDONLY;
ret = btrfs_prepare_sprout(trans, root); ret = btrfs_prepare_sprout(root);
BUG_ON(ret); BUG_ON(ret);
} }
...@@ -3044,8 +3041,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) ...@@ -3044,8 +3041,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
return ret; return ret;
} }
static int btrfs_add_system_chunk(struct btrfs_trans_handle *trans, static int btrfs_add_system_chunk(struct btrfs_root *root,
struct btrfs_root *root,
struct btrfs_key *key, struct btrfs_key *key,
struct btrfs_chunk *chunk, int item_size) struct btrfs_chunk *chunk, int item_size)
{ {
...@@ -3221,7 +3217,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, ...@@ -3221,7 +3217,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
if (total_avail == 0) if (total_avail == 0)
continue; continue;
ret = find_free_dev_extent(trans, device, ret = find_free_dev_extent(device,
max_stripe_size * dev_stripes, max_stripe_size * dev_stripes,
&dev_offset, &max_avail); &dev_offset, &max_avail);
if (ret && ret != -ENOSPC) if (ret && ret != -ENOSPC)
...@@ -3412,7 +3408,7 @@ static int __finish_chunk_alloc(struct btrfs_trans_handle *trans, ...@@ -3412,7 +3408,7 @@ static int __finish_chunk_alloc(struct btrfs_trans_handle *trans,
BUG_ON(ret); BUG_ON(ret);
if (map->type & BTRFS_BLOCK_GROUP_SYSTEM) { if (map->type & BTRFS_BLOCK_GROUP_SYSTEM) {
ret = btrfs_add_system_chunk(trans, chunk_root, &key, chunk, ret = btrfs_add_system_chunk(chunk_root, &key, chunk,
item_size); item_size);
BUG_ON(ret); BUG_ON(ret);
} }
...@@ -3624,26 +3620,13 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, ...@@ -3624,26 +3620,13 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
u64 stripe_nr; u64 stripe_nr;
u64 stripe_nr_orig; u64 stripe_nr_orig;
u64 stripe_nr_end; u64 stripe_nr_end;
int stripes_allocated = 8;
int stripes_required = 1;
int stripe_index; int stripe_index;
int i; int i;
int ret = 0;
int num_stripes; int num_stripes;
int max_errors = 0; int max_errors = 0;
struct btrfs_bio *bbio = NULL; struct btrfs_bio *bbio = NULL;
if (bbio_ret && !(rw & (REQ_WRITE | REQ_DISCARD)))
stripes_allocated = 1;
again:
if (bbio_ret) {
bbio = kzalloc(btrfs_bio_size(stripes_allocated),
GFP_NOFS);
if (!bbio)
return -ENOMEM;
atomic_set(&bbio->error, 0);
}
read_lock(&em_tree->lock); read_lock(&em_tree->lock);
em = lookup_extent_mapping(em_tree, logical, *length); em = lookup_extent_mapping(em_tree, logical, *length);
read_unlock(&em_tree->lock); read_unlock(&em_tree->lock);
...@@ -3662,28 +3645,6 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, ...@@ -3662,28 +3645,6 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
if (mirror_num > map->num_stripes) if (mirror_num > map->num_stripes)
mirror_num = 0; mirror_num = 0;
/* if our btrfs_bio struct is too small, back off and try again */
if (rw & REQ_WRITE) {
if (map->type & (BTRFS_BLOCK_GROUP_RAID1 |
BTRFS_BLOCK_GROUP_DUP)) {
stripes_required = map->num_stripes;
max_errors = 1;
} else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
stripes_required = map->sub_stripes;
max_errors = 1;
}
}
if (rw & REQ_DISCARD) {
if (map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK)
stripes_required = map->num_stripes;
}
if (bbio_ret && (rw & (REQ_WRITE | REQ_DISCARD)) &&
stripes_allocated < stripes_required) {
stripes_allocated = map->num_stripes;
free_extent_map(em);
kfree(bbio);
goto again;
}
stripe_nr = offset; stripe_nr = offset;
/* /*
* stripe_nr counts the total number of stripes we have to stride * stripe_nr counts the total number of stripes we have to stride
...@@ -3775,81 +3736,55 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, ...@@ -3775,81 +3736,55 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
} }
BUG_ON(stripe_index >= map->num_stripes); BUG_ON(stripe_index >= map->num_stripes);
bbio = kzalloc(btrfs_bio_size(num_stripes), GFP_NOFS);
if (!bbio) {
ret = -ENOMEM;
goto out;
}
atomic_set(&bbio->error, 0);
if (rw & REQ_DISCARD) { if (rw & REQ_DISCARD) {
int factor = 0;
int sub_stripes = 0;
u64 stripes_per_dev = 0;
u32 remaining_stripes = 0;
if (map->type &
(BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID10)) {
if (map->type & BTRFS_BLOCK_GROUP_RAID0)
sub_stripes = 1;
else
sub_stripes = map->sub_stripes;
factor = map->num_stripes / sub_stripes;
stripes_per_dev = div_u64_rem(stripe_nr_end -
stripe_nr_orig,
factor,
&remaining_stripes);
}
for (i = 0; i < num_stripes; i++) { for (i = 0; i < num_stripes; i++) {
bbio->stripes[i].physical = bbio->stripes[i].physical =
map->stripes[stripe_index].physical + map->stripes[stripe_index].physical +
stripe_offset + stripe_nr * map->stripe_len; stripe_offset + stripe_nr * map->stripe_len;
bbio->stripes[i].dev = map->stripes[stripe_index].dev; bbio->stripes[i].dev = map->stripes[stripe_index].dev;
if (map->type & BTRFS_BLOCK_GROUP_RAID0) { if (map->type & (BTRFS_BLOCK_GROUP_RAID0 |
u64 stripes; BTRFS_BLOCK_GROUP_RAID10)) {
u32 last_stripe = 0; bbio->stripes[i].length = stripes_per_dev *
int j; map->stripe_len;
if (i / sub_stripes < remaining_stripes)
div_u64_rem(stripe_nr_end - 1, bbio->stripes[i].length +=
map->num_stripes, map->stripe_len;
&last_stripe); if (i < sub_stripes)
for (j = 0; j < map->num_stripes; j++) {
u32 test;
div_u64_rem(stripe_nr_end - 1 - j,
map->num_stripes, &test);
if (test == stripe_index)
break;
}
stripes = stripe_nr_end - 1 - j;
do_div(stripes, map->num_stripes);
bbio->stripes[i].length = map->stripe_len *
(stripes - stripe_nr + 1);
if (i == 0) {
bbio->stripes[i].length -=
stripe_offset;
stripe_offset = 0;
}
if (stripe_index == last_stripe)
bbio->stripes[i].length -=
stripe_end_offset;
} else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
u64 stripes;
int j;
int factor = map->num_stripes /
map->sub_stripes;
u32 last_stripe = 0;
div_u64_rem(stripe_nr_end - 1,
factor, &last_stripe);
last_stripe *= map->sub_stripes;
for (j = 0; j < factor; j++) {
u32 test;
div_u64_rem(stripe_nr_end - 1 - j,
factor, &test);
if (test ==
stripe_index / map->sub_stripes)
break;
}
stripes = stripe_nr_end - 1 - j;
do_div(stripes, factor);
bbio->stripes[i].length = map->stripe_len *
(stripes - stripe_nr + 1);
if (i < map->sub_stripes) {
bbio->stripes[i].length -= bbio->stripes[i].length -=
stripe_offset; stripe_offset;
if (i == map->sub_stripes - 1) if ((i / sub_stripes + 1) %
stripe_offset = 0; sub_stripes == remaining_stripes)
}
if (stripe_index >= last_stripe &&
stripe_index <= (last_stripe +
map->sub_stripes - 1)) {
bbio->stripes[i].length -= bbio->stripes[i].length -=
stripe_end_offset; stripe_end_offset;
} if (i == sub_stripes - 1)
stripe_offset = 0;
} else } else
bbio->stripes[i].length = *length; bbio->stripes[i].length = *length;
...@@ -3871,15 +3806,22 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, ...@@ -3871,15 +3806,22 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
stripe_index++; stripe_index++;
} }
} }
if (bbio_ret) {
*bbio_ret = bbio; if (rw & REQ_WRITE) {
bbio->num_stripes = num_stripes; if (map->type & (BTRFS_BLOCK_GROUP_RAID1 |
bbio->max_errors = max_errors; BTRFS_BLOCK_GROUP_RAID10 |
bbio->mirror_num = mirror_num; BTRFS_BLOCK_GROUP_DUP)) {
max_errors = 1;
}
} }
*bbio_ret = bbio;
bbio->num_stripes = num_stripes;
bbio->max_errors = max_errors;
bbio->mirror_num = mirror_num;
out: out:
free_extent_map(em); free_extent_map(em);
return 0; return ret;
} }
int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw,
...@@ -4284,7 +4226,7 @@ static int open_seed_devices(struct btrfs_root *root, u8 *fsid) ...@@ -4284,7 +4226,7 @@ static int open_seed_devices(struct btrfs_root *root, u8 *fsid)
struct btrfs_fs_devices *fs_devices; struct btrfs_fs_devices *fs_devices;
int ret; int ret;
mutex_lock(&uuid_mutex); BUG_ON(!mutex_is_locked(&uuid_mutex));
fs_devices = root->fs_info->fs_devices->seed; fs_devices = root->fs_info->fs_devices->seed;
while (fs_devices) { while (fs_devices) {
...@@ -4322,7 +4264,6 @@ static int open_seed_devices(struct btrfs_root *root, u8 *fsid) ...@@ -4322,7 +4264,6 @@ static int open_seed_devices(struct btrfs_root *root, u8 *fsid)
fs_devices->seed = root->fs_info->fs_devices->seed; fs_devices->seed = root->fs_info->fs_devices->seed;
root->fs_info->fs_devices->seed = fs_devices; root->fs_info->fs_devices->seed = fs_devices;
out: out:
mutex_unlock(&uuid_mutex);
return ret; return ret;
} }
...@@ -4465,6 +4406,9 @@ int btrfs_read_chunk_tree(struct btrfs_root *root) ...@@ -4465,6 +4406,9 @@ int btrfs_read_chunk_tree(struct btrfs_root *root)
if (!path) if (!path)
return -ENOMEM; return -ENOMEM;
mutex_lock(&uuid_mutex);
lock_chunks(root);
/* first we search for all of the device items, and then we /* first we search for all of the device items, and then we
* read in all of the chunk items. This way we can create chunk * read in all of the chunk items. This way we can create chunk
* mappings that reference all of the devices that are afound * mappings that reference all of the devices that are afound
...@@ -4515,6 +4459,9 @@ int btrfs_read_chunk_tree(struct btrfs_root *root) ...@@ -4515,6 +4459,9 @@ int btrfs_read_chunk_tree(struct btrfs_root *root)
} }
ret = 0; ret = 0;
error: error:
unlock_chunks(root);
mutex_unlock(&uuid_mutex);
btrfs_free_path(path); btrfs_free_path(path);
return ret; return ret;
} }
...@@ -279,7 +279,6 @@ int btrfs_recover_balance(struct btrfs_root *tree_root); ...@@ -279,7 +279,6 @@ int btrfs_recover_balance(struct btrfs_root *tree_root);
int btrfs_pause_balance(struct btrfs_fs_info *fs_info); int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
int btrfs_cancel_balance(struct btrfs_fs_info *fs_info); int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset); int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset);
int find_free_dev_extent(struct btrfs_trans_handle *trans, int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
struct btrfs_device *device, u64 num_bytes,
u64 *start, u64 *max_avail); u64 *start, u64 *max_avail);
#endif #endif
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