Skip to content

Commit 0fbf2cc

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs fixes from Chris Mason: "These are mostly bug fixes and a two small performance fixes. The most important of the bunch are Josef's fix for a snapshotting regression and Mark's update to fix compile problems on arm" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (25 commits) Btrfs: create the uuid tree on remount rw btrfs: change extent-same to copy entire argument struct Btrfs: dir_inode_operations should use btrfs_update_time also btrfs: Add btrfs: prefix to kernel log output btrfs: refuse to remount read-write after abort Btrfs: btrfs_ioctl_default_subvol: Revert back to toplevel subvolume when arg is 0 Btrfs: don't leak transaction in btrfs_sync_file() Btrfs: add the missing mutex unlock in write_all_supers() Btrfs: iput inode on allocation failure Btrfs: remove space_info->reservation_progress Btrfs: kill delay_iput arg to the wait_ordered functions Btrfs: fix worst case calculator for space usage Revert "Btrfs: rework the overcommit logic to be based on the total size" Btrfs: improve replacing nocow extents Btrfs: drop dir i_size when adding new names on replay Btrfs: replay dir_index items before other items Btrfs: check roots last log commit when checking if an inode has been logged Btrfs: actually log directory we are fsync()'ing Btrfs: actually limit the size of delalloc range Btrfs: allocate the free space by the existed max extent size when ENOSPC ...
2 parents c43a385 + 94aebfb commit 0fbf2cc

21 files changed

+364
-175
lines changed

fs/btrfs/btrfs_inode.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ static inline bool btrfs_is_free_space_inode(struct inode *inode)
213213
static inline int btrfs_inode_in_log(struct inode *inode, u64 generation)
214214
{
215215
if (BTRFS_I(inode)->logged_trans == generation &&
216-
BTRFS_I(inode)->last_sub_trans <= BTRFS_I(inode)->last_log_commit)
216+
BTRFS_I(inode)->last_sub_trans <=
217+
BTRFS_I(inode)->last_log_commit &&
218+
BTRFS_I(inode)->last_sub_trans <=
219+
BTRFS_I(inode)->root->last_log_commit)
217220
return 1;
218221
return 0;
219222
}

fs/btrfs/ctree.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,11 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
10051005
return ret;
10061006
}
10071007

1008-
if (root->ref_cows)
1009-
btrfs_reloc_cow_block(trans, root, buf, cow);
1008+
if (root->ref_cows) {
1009+
ret = btrfs_reloc_cow_block(trans, root, buf, cow);
1010+
if (ret)
1011+
return ret;
1012+
}
10101013

10111014
if (buf == root->node) {
10121015
WARN_ON(parent && parent != buf);

fs/btrfs/ctree.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,15 +1118,6 @@ struct btrfs_space_info {
11181118
*/
11191119
struct percpu_counter total_bytes_pinned;
11201120

1121-
/*
1122-
* we bump reservation progress every time we decrement
1123-
* bytes_reserved. This way people waiting for reservations
1124-
* know something good has happened and they can check
1125-
* for progress. The number here isn't to be trusted, it
1126-
* just shows reclaim activity
1127-
*/
1128-
unsigned long reservation_progress;
1129-
11301121
unsigned int full:1; /* indicates that we cannot allocate any more
11311122
chunks for this space */
11321123
unsigned int chunk_alloc:1; /* set if we are allocating a chunk */
@@ -3135,7 +3126,7 @@ static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root,
31353126
unsigned num_items)
31363127
{
31373128
return (root->leafsize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) *
3138-
3 * num_items;
3129+
2 * num_items;
31393130
}
31403131

31413132
/*
@@ -3939,9 +3930,9 @@ int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
39393930
struct btrfs_root *root);
39403931
int btrfs_recover_relocation(struct btrfs_root *root);
39413932
int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len);
3942-
void btrfs_reloc_cow_block(struct btrfs_trans_handle *trans,
3943-
struct btrfs_root *root, struct extent_buffer *buf,
3944-
struct extent_buffer *cow);
3933+
int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans,
3934+
struct btrfs_root *root, struct extent_buffer *buf,
3935+
struct extent_buffer *cow);
39453936
void btrfs_reloc_pre_snapshot(struct btrfs_trans_handle *trans,
39463937
struct btrfs_pending_snapshot *pending,
39473938
u64 *bytes_to_reserve);

fs/btrfs/dev-replace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
400400
args->result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;
401401
btrfs_dev_replace_unlock(dev_replace);
402402

403-
btrfs_wait_all_ordered_extents(root->fs_info, 0);
403+
btrfs_wait_all_ordered_extents(root->fs_info);
404404

405405
/* force writing the updated state information to disk */
406406
trans = btrfs_start_transaction(root, 0);
@@ -475,7 +475,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
475475
mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);
476476
return ret;
477477
}
478-
btrfs_wait_all_ordered_extents(root->fs_info, 0);
478+
btrfs_wait_all_ordered_extents(root->fs_info);
479479

480480
trans = btrfs_start_transaction(root, 0);
481481
if (IS_ERR(trans)) {

fs/btrfs/disk-io.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ static struct btrfs_lockdep_keyset {
157157
{ .id = BTRFS_TREE_LOG_OBJECTID, .name_stem = "log" },
158158
{ .id = BTRFS_TREE_RELOC_OBJECTID, .name_stem = "treloc" },
159159
{ .id = BTRFS_DATA_RELOC_TREE_OBJECTID, .name_stem = "dreloc" },
160+
{ .id = BTRFS_UUID_TREE_OBJECTID, .name_stem = "uuid" },
160161
{ .id = 0, .name_stem = "tree" },
161162
};
162163

@@ -3415,6 +3416,7 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors)
34153416
if (total_errors > max_errors) {
34163417
printk(KERN_ERR "btrfs: %d errors while writing supers\n",
34173418
total_errors);
3419+
mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);
34183420

34193421
/* FUA is masked off if unsupported and can't be the reason */
34203422
btrfs_error(root->fs_info, -EIO,

fs/btrfs/extent-tree.c

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3925,7 +3925,6 @@ static int can_overcommit(struct btrfs_root *root,
39253925
u64 space_size;
39263926
u64 avail;
39273927
u64 used;
3928-
u64 to_add;
39293928

39303929
used = space_info->bytes_used + space_info->bytes_reserved +
39313930
space_info->bytes_pinned + space_info->bytes_readonly;
@@ -3959,25 +3958,17 @@ static int can_overcommit(struct btrfs_root *root,
39593958
BTRFS_BLOCK_GROUP_RAID10))
39603959
avail >>= 1;
39613960

3962-
to_add = space_info->total_bytes;
3963-
39643961
/*
39653962
* If we aren't flushing all things, let us overcommit up to
39663963
* 1/2th of the space. If we can flush, don't let us overcommit
39673964
* too much, let it overcommit up to 1/8 of the space.
39683965
*/
39693966
if (flush == BTRFS_RESERVE_FLUSH_ALL)
3970-
to_add >>= 3;
3967+
avail >>= 3;
39713968
else
3972-
to_add >>= 1;
3973-
3974-
/*
3975-
* Limit the overcommit to the amount of free space we could possibly
3976-
* allocate for chunks.
3977-
*/
3978-
to_add = min(avail, to_add);
3969+
avail >>= 1;
39793970

3980-
if (used + bytes < space_info->total_bytes + to_add)
3971+
if (used + bytes < space_info->total_bytes + avail)
39813972
return 1;
39823973
return 0;
39833974
}
@@ -4000,7 +3991,7 @@ static void btrfs_writeback_inodes_sb_nr(struct btrfs_root *root,
40003991
*/
40013992
btrfs_start_all_delalloc_inodes(root->fs_info, 0);
40023993
if (!current->journal_info)
4003-
btrfs_wait_all_ordered_extents(root->fs_info, 0);
3994+
btrfs_wait_all_ordered_extents(root->fs_info);
40043995
}
40053996
}
40063997

@@ -4030,7 +4021,7 @@ static void shrink_delalloc(struct btrfs_root *root, u64 to_reclaim, u64 orig,
40304021
if (delalloc_bytes == 0) {
40314022
if (trans)
40324023
return;
4033-
btrfs_wait_all_ordered_extents(root->fs_info, 0);
4024+
btrfs_wait_all_ordered_extents(root->fs_info);
40344025
return;
40354026
}
40364027

@@ -4058,7 +4049,7 @@ static void shrink_delalloc(struct btrfs_root *root, u64 to_reclaim, u64 orig,
40584049

40594050
loops++;
40604051
if (wait_ordered && !trans) {
4061-
btrfs_wait_all_ordered_extents(root->fs_info, 0);
4052+
btrfs_wait_all_ordered_extents(root->fs_info);
40624053
} else {
40634054
time_left = schedule_timeout_killable(1);
40644055
if (time_left)
@@ -4465,7 +4456,6 @@ static void block_rsv_release_bytes(struct btrfs_fs_info *fs_info,
44654456
space_info->bytes_may_use -= num_bytes;
44664457
trace_btrfs_space_reservation(fs_info, "space_info",
44674458
space_info->flags, num_bytes, 0);
4468-
space_info->reservation_progress++;
44694459
spin_unlock(&space_info->lock);
44704460
}
44714461
}
@@ -4666,7 +4656,6 @@ static void update_global_block_rsv(struct btrfs_fs_info *fs_info)
46664656
sinfo->bytes_may_use -= num_bytes;
46674657
trace_btrfs_space_reservation(fs_info, "space_info",
46684658
sinfo->flags, num_bytes, 0);
4669-
sinfo->reservation_progress++;
46704659
block_rsv->reserved = block_rsv->size;
46714660
block_rsv->full = 1;
46724661
}
@@ -5446,7 +5435,6 @@ static int btrfs_update_reserved_bytes(struct btrfs_block_group_cache *cache,
54465435
space_info->bytes_readonly += num_bytes;
54475436
cache->reserved -= num_bytes;
54485437
space_info->bytes_reserved -= num_bytes;
5449-
space_info->reservation_progress++;
54505438
}
54515439
spin_unlock(&cache->lock);
54525440
spin_unlock(&space_info->lock);
@@ -6117,10 +6105,13 @@ enum btrfs_loop_type {
61176105
/*
61186106
* walks the btree of allocated extents and find a hole of a given size.
61196107
* The key ins is changed to record the hole:
6120-
* ins->objectid == block start
6108+
* ins->objectid == start position
61216109
* ins->flags = BTRFS_EXTENT_ITEM_KEY
6122-
* ins->offset == number of blocks
6110+
* ins->offset == the size of the hole.
61236111
* Any available blocks before search_start are skipped.
6112+
*
6113+
* If there is no suitable free space, we will record the max size of
6114+
* the free space extent currently.
61246115
*/
61256116
static noinline int find_free_extent(struct btrfs_root *orig_root,
61266117
u64 num_bytes, u64 empty_size,
@@ -6133,6 +6124,7 @@ static noinline int find_free_extent(struct btrfs_root *orig_root,
61336124
struct btrfs_block_group_cache *block_group = NULL;
61346125
struct btrfs_block_group_cache *used_block_group;
61356126
u64 search_start = 0;
6127+
u64 max_extent_size = 0;
61366128
int empty_cluster = 2 * 1024 * 1024;
61376129
struct btrfs_space_info *space_info;
61386130
int loop = 0;
@@ -6292,7 +6284,10 @@ static noinline int find_free_extent(struct btrfs_root *orig_root,
62926284
btrfs_get_block_group(used_block_group);
62936285

62946286
offset = btrfs_alloc_from_cluster(used_block_group,
6295-
last_ptr, num_bytes, used_block_group->key.objectid);
6287+
last_ptr,
6288+
num_bytes,
6289+
used_block_group->key.objectid,
6290+
&max_extent_size);
62966291
if (offset) {
62976292
/* we have a block, we're done */
62986293
spin_unlock(&last_ptr->refill_lock);
@@ -6355,8 +6350,10 @@ static noinline int find_free_extent(struct btrfs_root *orig_root,
63556350
* cluster
63566351
*/
63576352
offset = btrfs_alloc_from_cluster(block_group,
6358-
last_ptr, num_bytes,
6359-
search_start);
6353+
last_ptr,
6354+
num_bytes,
6355+
search_start,
6356+
&max_extent_size);
63606357
if (offset) {
63616358
/* we found one, proceed */
63626359
spin_unlock(&last_ptr->refill_lock);
@@ -6391,13 +6388,18 @@ static noinline int find_free_extent(struct btrfs_root *orig_root,
63916388
if (cached &&
63926389
block_group->free_space_ctl->free_space <
63936390
num_bytes + empty_cluster + empty_size) {
6391+
if (block_group->free_space_ctl->free_space >
6392+
max_extent_size)
6393+
max_extent_size =
6394+
block_group->free_space_ctl->free_space;
63946395
spin_unlock(&block_group->free_space_ctl->tree_lock);
63956396
goto loop;
63966397
}
63976398
spin_unlock(&block_group->free_space_ctl->tree_lock);
63986399

63996400
offset = btrfs_find_space_for_alloc(block_group, search_start,
6400-
num_bytes, empty_size);
6401+
num_bytes, empty_size,
6402+
&max_extent_size);
64016403
/*
64026404
* If we didn't find a chunk, and we haven't failed on this
64036405
* block group before, and this block group is in the middle of
@@ -6515,7 +6517,8 @@ static noinline int find_free_extent(struct btrfs_root *orig_root,
65156517
ret = 0;
65166518
}
65176519
out:
6518-
6520+
if (ret == -ENOSPC)
6521+
ins->offset = max_extent_size;
65196522
return ret;
65206523
}
65216524

@@ -6573,8 +6576,8 @@ int btrfs_reserve_extent(struct btrfs_root *root,
65736576
flags);
65746577

65756578
if (ret == -ENOSPC) {
6576-
if (!final_tried) {
6577-
num_bytes = num_bytes >> 1;
6579+
if (!final_tried && ins->offset) {
6580+
num_bytes = min(num_bytes >> 1, ins->offset);
65786581
num_bytes = round_down(num_bytes, root->sectorsize);
65796582
num_bytes = max(num_bytes, min_alloc_size);
65806583
if (num_bytes == min_alloc_size)

fs/btrfs/extent_io.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,10 +1481,12 @@ static noinline u64 find_delalloc_range(struct extent_io_tree *tree,
14811481
*end = state->end;
14821482
cur_start = state->end + 1;
14831483
node = rb_next(node);
1484-
if (!node)
1485-
break;
14861484
total_bytes += state->end - state->start + 1;
1487-
if (total_bytes >= max_bytes)
1485+
if (total_bytes >= max_bytes) {
1486+
*end = *start + max_bytes - 1;
1487+
break;
1488+
}
1489+
if (!node)
14881490
break;
14891491
}
14901492
out:

fs/btrfs/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,8 +1859,8 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
18591859

18601860
ret = btrfs_log_dentry_safe(trans, root, dentry);
18611861
if (ret < 0) {
1862-
mutex_unlock(&inode->i_mutex);
1863-
goto out;
1862+
/* Fallthrough and commit/free transaction. */
1863+
ret = 1;
18641864
}
18651865

18661866
/* we've logged all the items and now have a consistent

0 commit comments

Comments
 (0)