Skip to content

Commit 859862d

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs updates from Chris Mason: "The biggest change here is Josef's rework of the btrfs quota accounting, which improves the in-memory tracking of delayed extent operations. I had been working on Btrfs stack usage for a while, mostly because it had become impossible to do long stress runs with slab, lockdep and pagealloc debugging turned on without blowing the stack. Even though you upgraded us to a nice king sized stack, I kept most of the patches. We also have some very hard to find corruption fixes, an awesome sysfs use after free, and the usual assortment of optimizations, cleanups and other fixes" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (80 commits) Btrfs: convert smp_mb__{before,after}_clear_bit Btrfs: fix scrub_print_warning to handle skinny metadata extents Btrfs: make fsync work after cloning into a file Btrfs: use right type to get real comparison Btrfs: don't check nodes for extent items Btrfs: don't release invalid page in btrfs_page_exists_in_range() Btrfs: make sure we retry if page is a retriable exception Btrfs: make sure we retry if we couldn't get the page btrfs: replace EINVAL with EOPNOTSUPP for dev_replace raid56 trivial: fs/btrfs/ioctl.c: fix typo s/substract/subtract/ Btrfs: fix leaf corruption after __btrfs_drop_extents Btrfs: ensure btrfs_prev_leaf doesn't miss 1 item Btrfs: fix clone to deal with holes when NO_HOLES feature is enabled btrfs: free delayed node outside of root->inode_lock btrfs: replace EINVAL with ERANGE for resize when ULLONG_MAX Btrfs: fix transaction leak during fsync call btrfs: Avoid trucating page or punching hole in a already existed hole. Btrfs: update commit root on snapshot creation after orphan cleanup Btrfs: ioctl, don't re-lock extent range when not necessary Btrfs: avoid visiting all extent items when cloning a range ...
2 parents 412dd3a + c7548af commit 859862d

47 files changed

Lines changed: 3700 additions & 1305 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎fs/btrfs/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
1616

1717
btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o \
1818
tests/extent-buffer-tests.o tests/btrfs-tests.o \
19-
tests/extent-io-tests.o tests/inode-tests.o
19+
tests/extent-io-tests.o tests/inode-tests.o tests/qgroup-tests.o

‎fs/btrfs/acl.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans,
7979
const char *name;
8080
char *value = NULL;
8181

82-
if (acl) {
83-
ret = posix_acl_valid(acl);
84-
if (ret < 0)
85-
return ret;
86-
ret = 0;
87-
}
88-
8982
switch (type) {
9083
case ACL_TYPE_ACCESS:
9184
name = POSIX_ACL_XATTR_ACCESS;

‎fs/btrfs/backref.c‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,11 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
900900
goto out;
901901
BUG_ON(ret == 0);
902902

903+
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
904+
if (trans && likely(trans->type != __TRANS_DUMMY)) {
905+
#else
903906
if (trans) {
907+
#endif
904908
/*
905909
* look if there are updates for this ref queued and lock the
906910
* head
@@ -984,11 +988,12 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
984988
goto out;
985989
}
986990
if (ref->count && ref->parent) {
987-
if (extent_item_pos && !ref->inode_list) {
991+
if (extent_item_pos && !ref->inode_list &&
992+
ref->level == 0) {
988993
u32 bsz;
989994
struct extent_buffer *eb;
990995
bsz = btrfs_level_size(fs_info->extent_root,
991-
info_level);
996+
ref->level);
992997
eb = read_tree_block(fs_info->extent_root,
993998
ref->parent, bsz, 0);
994999
if (!eb || !extent_buffer_uptodate(eb)) {
@@ -1404,9 +1409,10 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
14041409
* returns <0 on error
14051410
*/
14061411
static int __get_extent_inline_ref(unsigned long *ptr, struct extent_buffer *eb,
1407-
struct btrfs_extent_item *ei, u32 item_size,
1408-
struct btrfs_extent_inline_ref **out_eiref,
1409-
int *out_type)
1412+
struct btrfs_key *key,
1413+
struct btrfs_extent_item *ei, u32 item_size,
1414+
struct btrfs_extent_inline_ref **out_eiref,
1415+
int *out_type)
14101416
{
14111417
unsigned long end;
14121418
u64 flags;
@@ -1416,19 +1422,26 @@ static int __get_extent_inline_ref(unsigned long *ptr, struct extent_buffer *eb,
14161422
/* first call */
14171423
flags = btrfs_extent_flags(eb, ei);
14181424
if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
1419-
info = (struct btrfs_tree_block_info *)(ei + 1);
1420-
*out_eiref =
1421-
(struct btrfs_extent_inline_ref *)(info + 1);
1425+
if (key->type == BTRFS_METADATA_ITEM_KEY) {
1426+
/* a skinny metadata extent */
1427+
*out_eiref =
1428+
(struct btrfs_extent_inline_ref *)(ei + 1);
1429+
} else {
1430+
WARN_ON(key->type != BTRFS_EXTENT_ITEM_KEY);
1431+
info = (struct btrfs_tree_block_info *)(ei + 1);
1432+
*out_eiref =
1433+
(struct btrfs_extent_inline_ref *)(info + 1);
1434+
}
14221435
} else {
14231436
*out_eiref = (struct btrfs_extent_inline_ref *)(ei + 1);
14241437
}
14251438
*ptr = (unsigned long)*out_eiref;
1426-
if ((void *)*ptr >= (void *)ei + item_size)
1439+
if ((unsigned long)(*ptr) >= (unsigned long)ei + item_size)
14271440
return -ENOENT;
14281441
}
14291442

14301443
end = (unsigned long)ei + item_size;
1431-
*out_eiref = (struct btrfs_extent_inline_ref *)*ptr;
1444+
*out_eiref = (struct btrfs_extent_inline_ref *)(*ptr);
14321445
*out_type = btrfs_extent_inline_ref_type(eb, *out_eiref);
14331446

14341447
*ptr += btrfs_extent_inline_ref_size(*out_type);
@@ -1447,8 +1460,8 @@ static int __get_extent_inline_ref(unsigned long *ptr, struct extent_buffer *eb,
14471460
* <0 on error.
14481461
*/
14491462
int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
1450-
struct btrfs_extent_item *ei, u32 item_size,
1451-
u64 *out_root, u8 *out_level)
1463+
struct btrfs_key *key, struct btrfs_extent_item *ei,
1464+
u32 item_size, u64 *out_root, u8 *out_level)
14521465
{
14531466
int ret;
14541467
int type;
@@ -1459,8 +1472,8 @@ int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
14591472
return 1;
14601473

14611474
while (1) {
1462-
ret = __get_extent_inline_ref(ptr, eb, ei, item_size,
1463-
&eiref, &type);
1475+
ret = __get_extent_inline_ref(ptr, eb, key, ei, item_size,
1476+
&eiref, &type);
14641477
if (ret < 0)
14651478
return ret;
14661479

‎fs/btrfs/backref.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
4040
u64 *flags);
4141

4242
int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
43-
struct btrfs_extent_item *ei, u32 item_size,
44-
u64 *out_root, u8 *out_level);
43+
struct btrfs_key *key, struct btrfs_extent_item *ei,
44+
u32 item_size, u64 *out_root, u8 *out_level);
4545

4646
int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
4747
u64 extent_item_objectid,
@@ -55,8 +55,8 @@ int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
5555
int paths_from_inode(u64 inum, struct inode_fs_paths *ipath);
5656

5757
int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
58-
struct btrfs_fs_info *fs_info, u64 bytenr,
59-
u64 time_seq, struct ulist **roots);
58+
struct btrfs_fs_info *fs_info, u64 bytenr,
59+
u64 time_seq, struct ulist **roots);
6060
char *btrfs_ref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path,
6161
u32 name_len, unsigned long name_off,
6262
struct extent_buffer *eb_in, u64 parent,

‎fs/btrfs/btrfs_inode.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,6 @@ static inline void btrfs_inode_resume_unlocked_dio(struct inode *inode)
284284
&BTRFS_I(inode)->runtime_flags);
285285
}
286286

287+
bool btrfs_page_exists_in_range(struct inode *inode, loff_t start, loff_t end);
288+
287289
#endif

‎fs/btrfs/check-integrity.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,7 @@ static int btrfsic_process_metablock(
10931093
next_stack =
10941094
btrfsic_stack_frame_alloc();
10951095
if (NULL == next_stack) {
1096+
sf->error = -1;
10961097
btrfsic_release_block_ctx(
10971098
&sf->
10981099
next_block_ctx);
@@ -1190,8 +1191,10 @@ static int btrfsic_process_metablock(
11901191
sf->next_block_ctx.datav[0];
11911192

11921193
next_stack = btrfsic_stack_frame_alloc();
1193-
if (NULL == next_stack)
1194+
if (NULL == next_stack) {
1195+
sf->error = -1;
11941196
goto one_stack_frame_backwards;
1197+
}
11951198

11961199
next_stack->i = -1;
11971200
next_stack->block = sf->next_block;

‎fs/btrfs/compression.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ int btrfs_compress_pages(int type, struct address_space *mapping,
887887

888888
workspace = find_workspace(type);
889889
if (IS_ERR(workspace))
890-
return -1;
890+
return PTR_ERR(workspace);
891891

892892
ret = btrfs_compress_op[type-1]->compress_pages(workspace, mapping,
893893
start, len, pages,
@@ -923,7 +923,7 @@ static int btrfs_decompress_biovec(int type, struct page **pages_in,
923923

924924
workspace = find_workspace(type);
925925
if (IS_ERR(workspace))
926-
return -ENOMEM;
926+
return PTR_ERR(workspace);
927927

928928
ret = btrfs_compress_op[type-1]->decompress_biovec(workspace, pages_in,
929929
disk_start,
@@ -945,7 +945,7 @@ int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page,
945945

946946
workspace = find_workspace(type);
947947
if (IS_ERR(workspace))
948-
return -ENOMEM;
948+
return PTR_ERR(workspace);
949949

950950
ret = btrfs_compress_op[type-1]->decompress(workspace, data_in,
951951
dest_page, start_byte,

‎fs/btrfs/ctree.c‎

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ static struct extent_buffer *btrfs_read_lock_root_node(struct btrfs_root *root)
224224
static void add_root_to_dirty_list(struct btrfs_root *root)
225225
{
226226
spin_lock(&root->fs_info->trans_lock);
227-
if (root->track_dirty && list_empty(&root->dirty_list)) {
227+
if (test_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state) &&
228+
list_empty(&root->dirty_list)) {
228229
list_add(&root->dirty_list,
229230
&root->fs_info->dirty_cowonly_roots);
230231
}
@@ -246,9 +247,10 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
246247
int level;
247248
struct btrfs_disk_key disk_key;
248249

249-
WARN_ON(root->ref_cows && trans->transid !=
250-
root->fs_info->running_transaction->transid);
251-
WARN_ON(root->ref_cows && trans->transid != root->last_trans);
250+
WARN_ON(test_bit(BTRFS_ROOT_REF_COWS, &root->state) &&
251+
trans->transid != root->fs_info->running_transaction->transid);
252+
WARN_ON(test_bit(BTRFS_ROOT_REF_COWS, &root->state) &&
253+
trans->transid != root->last_trans);
252254

253255
level = btrfs_header_level(buf);
254256
if (level == 0)
@@ -354,43 +356,13 @@ static inline void tree_mod_log_write_unlock(struct btrfs_fs_info *fs_info)
354356
}
355357

356358
/*
357-
* Increment the upper half of tree_mod_seq, set lower half zero.
358-
*
359-
* Must be called with fs_info->tree_mod_seq_lock held.
360-
*/
361-
static inline u64 btrfs_inc_tree_mod_seq_major(struct btrfs_fs_info *fs_info)
362-
{
363-
u64 seq = atomic64_read(&fs_info->tree_mod_seq);
364-
seq &= 0xffffffff00000000ull;
365-
seq += 1ull << 32;
366-
atomic64_set(&fs_info->tree_mod_seq, seq);
367-
return seq;
368-
}
369-
370-
/*
371-
* Increment the lower half of tree_mod_seq.
372-
*
373-
* Must be called with fs_info->tree_mod_seq_lock held. The way major numbers
374-
* are generated should not technically require a spin lock here. (Rationale:
375-
* incrementing the minor while incrementing the major seq number is between its
376-
* atomic64_read and atomic64_set calls doesn't duplicate sequence numbers, it
377-
* just returns a unique sequence number as usual.) We have decided to leave
378-
* that requirement in here and rethink it once we notice it really imposes a
379-
* problem on some workload.
359+
* Pull a new tree mod seq number for our operation.
380360
*/
381-
static inline u64 btrfs_inc_tree_mod_seq_minor(struct btrfs_fs_info *fs_info)
361+
static inline u64 btrfs_inc_tree_mod_seq(struct btrfs_fs_info *fs_info)
382362
{
383363
return atomic64_inc_return(&fs_info->tree_mod_seq);
384364
}
385365

386-
/*
387-
* return the last minor in the previous major tree_mod_seq number
388-
*/
389-
u64 btrfs_tree_mod_seq_prev(u64 seq)
390-
{
391-
return (seq & 0xffffffff00000000ull) - 1ull;
392-
}
393-
394366
/*
395367
* This adds a new blocker to the tree mod log's blocker list if the @elem
396368
* passed does not already have a sequence number set. So when a caller expects
@@ -402,19 +374,16 @@ u64 btrfs_tree_mod_seq_prev(u64 seq)
402374
u64 btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info,
403375
struct seq_list *elem)
404376
{
405-
u64 seq;
406-
407377
tree_mod_log_write_lock(fs_info);
408378
spin_lock(&fs_info->tree_mod_seq_lock);
409379
if (!elem->seq) {
410-
elem->seq = btrfs_inc_tree_mod_seq_major(fs_info);
380+
elem->seq = btrfs_inc_tree_mod_seq(fs_info);
411381
list_add_tail(&elem->list, &fs_info->tree_mod_seq_list);
412382
}
413-
seq = btrfs_inc_tree_mod_seq_minor(fs_info);
414383
spin_unlock(&fs_info->tree_mod_seq_lock);
415384
tree_mod_log_write_unlock(fs_info);
416385

417-
return seq;
386+
return elem->seq;
418387
}
419388

420389
void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
@@ -487,9 +456,7 @@ __tree_mod_log_insert(struct btrfs_fs_info *fs_info, struct tree_mod_elem *tm)
487456

488457
BUG_ON(!tm);
489458

490-
spin_lock(&fs_info->tree_mod_seq_lock);
491-
tm->seq = btrfs_inc_tree_mod_seq_minor(fs_info);
492-
spin_unlock(&fs_info->tree_mod_seq_lock);
459+
tm->seq = btrfs_inc_tree_mod_seq(fs_info);
493460

494461
tm_root = &fs_info->tree_mod_log;
495462
new = &tm_root->rb_node;
@@ -997,14 +964,14 @@ int btrfs_block_can_be_shared(struct btrfs_root *root,
997964
* snapshot and the block was not allocated by tree relocation,
998965
* we know the block is not shared.
999966
*/
1000-
if (root->ref_cows &&
967+
if (test_bit(BTRFS_ROOT_REF_COWS, &root->state) &&
1001968
buf != root->node && buf != root->commit_root &&
1002969
(btrfs_header_generation(buf) <=
1003970
btrfs_root_last_snapshot(&root->root_item) ||
1004971
btrfs_header_flag(buf, BTRFS_HEADER_FLAG_RELOC)))
1005972
return 1;
1006973
#ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1007-
if (root->ref_cows &&
974+
if (test_bit(BTRFS_ROOT_REF_COWS, &root->state) &&
1008975
btrfs_header_backref_rev(buf) < BTRFS_MIXED_BACKREF_REV)
1009976
return 1;
1010977
#endif
@@ -1146,9 +1113,10 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
11461113

11471114
btrfs_assert_tree_locked(buf);
11481115

1149-
WARN_ON(root->ref_cows && trans->transid !=
1150-
root->fs_info->running_transaction->transid);
1151-
WARN_ON(root->ref_cows && trans->transid != root->last_trans);
1116+
WARN_ON(test_bit(BTRFS_ROOT_REF_COWS, &root->state) &&
1117+
trans->transid != root->fs_info->running_transaction->transid);
1118+
WARN_ON(test_bit(BTRFS_ROOT_REF_COWS, &root->state) &&
1119+
trans->transid != root->last_trans);
11521120

11531121
level = btrfs_header_level(buf);
11541122

@@ -1193,7 +1161,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
11931161
return ret;
11941162
}
11951163

1196-
if (root->ref_cows) {
1164+
if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) {
11971165
ret = btrfs_reloc_cow_block(trans, root, buf, cow);
11981166
if (ret)
11991167
return ret;
@@ -1538,6 +1506,10 @@ static inline int should_cow_block(struct btrfs_trans_handle *trans,
15381506
struct btrfs_root *root,
15391507
struct extent_buffer *buf)
15401508
{
1509+
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
1510+
if (unlikely(test_bit(BTRFS_ROOT_DUMMY_ROOT, &root->state)))
1511+
return 0;
1512+
#endif
15411513
/* ensure we can see the force_cow */
15421514
smp_rmb();
15431515

@@ -1556,7 +1528,7 @@ static inline int should_cow_block(struct btrfs_trans_handle *trans,
15561528
!btrfs_header_flag(buf, BTRFS_HEADER_FLAG_WRITTEN) &&
15571529
!(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID &&
15581530
btrfs_header_flag(buf, BTRFS_HEADER_FLAG_RELOC)) &&
1559-
!root->force_cow)
1531+
!test_bit(BTRFS_ROOT_FORCE_COW, &root->state))
15601532
return 0;
15611533
return 1;
15621534
}
@@ -5125,7 +5097,17 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)
51255097
return ret;
51265098
btrfs_item_key(path->nodes[0], &found_key, 0);
51275099
ret = comp_keys(&found_key, &key);
5128-
if (ret < 0)
5100+
/*
5101+
* We might have had an item with the previous key in the tree right
5102+
* before we released our path. And after we released our path, that
5103+
* item might have been pushed to the first slot (0) of the leaf we
5104+
* were holding due to a tree balance. Alternatively, an item with the
5105+
* previous key can exist as the only element of a leaf (big fat item).
5106+
* Therefore account for these 2 cases, so that our callers (like
5107+
* btrfs_previous_item) don't miss an existing item with a key matching
5108+
* the previous key we computed above.
5109+
*/
5110+
if (ret <= 0)
51295111
return 0;
51305112
return 1;
51315113
}
@@ -5736,6 +5718,24 @@ int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path,
57365718
ret = 0;
57375719
goto done;
57385720
}
5721+
/*
5722+
* So the above check misses one case:
5723+
* - after releasing the path above, someone has removed the item that
5724+
* used to be at the very end of the block, and balance between leafs
5725+
* gets another one with bigger key.offset to replace it.
5726+
*
5727+
* This one should be returned as well, or we can get leaf corruption
5728+
* later(esp. in __btrfs_drop_extents()).
5729+
*
5730+
* And a bit more explanation about this check,
5731+
* with ret > 0, the key isn't found, the path points to the slot
5732+
* where it should be inserted, so the path->slots[0] item must be the
5733+
* bigger one.
5734+
*/
5735+
if (nritems > 0 && ret > 0 && path->slots[0] == nritems - 1) {
5736+
ret = 0;
5737+
goto done;
5738+
}
57395739

57405740
while (level < BTRFS_MAX_LEVEL) {
57415741
if (!path->nodes[level]) {

0 commit comments

Comments
 (0)