Skip to content

Commit 1176032

Browse files
committed
Merge branch 'for-linus-4.12' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs updates from Chris Mason: "This has fixes and cleanups Dave Sterba collected for the merge window. The biggest functional fixes are between btrfs raid5/6 and scrub, and raid5/6 and device replacement. Some of our pending qgroup fixes are included as well while I bash on the rest in testing. We also have the usual set of cleanups, including one that makes __btrfs_map_block() much more maintainable, and conversions from atomic_t to refcount_t" * 'for-linus-4.12' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (71 commits) btrfs: fix the gfp_mask for the reada_zones radix tree Btrfs: fix reported number of inode blocks Btrfs: send, fix file hole not being preserved due to inline extent Btrfs: fix extent map leak during fallocate error path Btrfs: fix incorrect space accounting after failure to insert inline extent Btrfs: fix invalid attempt to free reserved space on failure to cow range btrfs: Handle delalloc error correctly to avoid ordered extent hang btrfs: Fix metadata underflow caused by btrfs_reloc_clone_csum error btrfs: check if the device is flush capable btrfs: delete unused member nobarriers btrfs: scrub: Fix RAID56 recovery race condition btrfs: scrub: Introduce full stripe lock for RAID56 btrfs: Use ktime_get_real_ts for root ctime Btrfs: handle only applicable errors returned by btrfs_get_extent btrfs: qgroup: Fix qgroup corruption caused by inode_cache mount option btrfs: use q which is already obtained from bdev_get_queue Btrfs: switch to div64_u64 if with a u64 divisor Btrfs: update scrub_parity to use u64 stripe_len Btrfs: enable repair during read for raid56 profile btrfs: use clear_page where appropriate ...
2 parents 56868a4 + 9bcaaea commit 1176032

40 files changed

Lines changed: 1629 additions & 834 deletions

‎MAINTAINERS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,6 +2926,8 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git
29262926
S: Maintained
29272927
F: Documentation/filesystems/btrfs.txt
29282928
F: fs/btrfs/
2929+
F: include/linux/btrfs*
2930+
F: include/uapi/linux/btrfs*
29292931

29302932
BTTV VIDEO4LINUX DRIVER
29312933
M: Mauro Carvalho Chehab <mchehab@s-opensource.com>

‎fs/btrfs/backref.c‎

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
#include "delayed-ref.h"
2727
#include "locking.h"
2828

29+
enum merge_mode {
30+
MERGE_IDENTICAL_KEYS = 1,
31+
MERGE_IDENTICAL_PARENTS,
32+
};
33+
2934
/* Just an arbitrary number so we can be sure this happened */
3035
#define BACKREF_FOUND_SHARED 6
3136

@@ -533,7 +538,7 @@ static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
533538
* slot==nritems. In that case, go to the next leaf before we continue.
534539
*/
535540
if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
536-
if (time_seq == (u64)-1)
541+
if (time_seq == SEQ_LAST)
537542
ret = btrfs_next_leaf(root, path);
538543
else
539544
ret = btrfs_next_old_leaf(root, path, time_seq);
@@ -577,7 +582,7 @@ static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
577582
eie = NULL;
578583
}
579584
next:
580-
if (time_seq == (u64)-1)
585+
if (time_seq == SEQ_LAST)
581586
ret = btrfs_next_item(root, path);
582587
else
583588
ret = btrfs_next_old_item(root, path, time_seq);
@@ -629,7 +634,7 @@ static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
629634

630635
if (path->search_commit_root)
631636
root_level = btrfs_header_level(root->commit_root);
632-
else if (time_seq == (u64)-1)
637+
else if (time_seq == SEQ_LAST)
633638
root_level = btrfs_header_level(root->node);
634639
else
635640
root_level = btrfs_old_root_level(root, time_seq);
@@ -640,7 +645,7 @@ static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
640645
}
641646

642647
path->lowest_level = level;
643-
if (time_seq == (u64)-1)
648+
if (time_seq == SEQ_LAST)
644649
ret = btrfs_search_slot(NULL, root, &ref->key_for_search, path,
645650
0, 0);
646651
else
@@ -809,14 +814,12 @@ static int __add_missing_keys(struct btrfs_fs_info *fs_info,
809814
/*
810815
* merge backrefs and adjust counts accordingly
811816
*
812-
* mode = 1: merge identical keys, if key is set
813-
* FIXME: if we add more keys in __add_prelim_ref, we can merge more here.
814-
* additionally, we could even add a key range for the blocks we
815-
* looked into to merge even more (-> replace unresolved refs by those
816-
* having a parent).
817-
* mode = 2: merge identical parents
817+
* FIXME: For MERGE_IDENTICAL_KEYS, if we add more keys in __add_prelim_ref
818+
* then we can merge more here. Additionally, we could even add a key
819+
* range for the blocks we looked into to merge even more (-> replace
820+
* unresolved refs by those having a parent).
818821
*/
819-
static void __merge_refs(struct list_head *head, int mode)
822+
static void __merge_refs(struct list_head *head, enum merge_mode mode)
820823
{
821824
struct __prelim_ref *pos1;
822825

@@ -829,7 +832,7 @@ static void __merge_refs(struct list_head *head, int mode)
829832

830833
if (!ref_for_same_block(ref1, ref2))
831834
continue;
832-
if (mode == 1) {
835+
if (mode == MERGE_IDENTICAL_KEYS) {
833836
if (!ref1->parent && ref2->parent)
834837
swap(ref1, ref2);
835838
} else {
@@ -1196,7 +1199,7 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
11961199
*
11971200
* NOTE: This can return values > 0
11981201
*
1199-
* If time_seq is set to (u64)-1, it will not search delayed_refs, and behave
1202+
* If time_seq is set to SEQ_LAST, it will not search delayed_refs, and behave
12001203
* much like trans == NULL case, the difference only lies in it will not
12011204
* commit root.
12021205
* The special case is for qgroup to search roots in commit_transaction().
@@ -1243,7 +1246,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
12431246
path->skip_locking = 1;
12441247
}
12451248

1246-
if (time_seq == (u64)-1)
1249+
if (time_seq == SEQ_LAST)
12471250
path->skip_locking = 1;
12481251

12491252
/*
@@ -1273,9 +1276,9 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
12731276

12741277
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
12751278
if (trans && likely(trans->type != __TRANS_DUMMY) &&
1276-
time_seq != (u64)-1) {
1279+
time_seq != SEQ_LAST) {
12771280
#else
1278-
if (trans && time_seq != (u64)-1) {
1281+
if (trans && time_seq != SEQ_LAST) {
12791282
#endif
12801283
/*
12811284
* look if there are updates for this ref queued and lock the
@@ -1286,7 +1289,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
12861289
head = btrfs_find_delayed_ref_head(delayed_refs, bytenr);
12871290
if (head) {
12881291
if (!mutex_trylock(&head->mutex)) {
1289-
atomic_inc(&head->node.refs);
1292+
refcount_inc(&head->node.refs);
12901293
spin_unlock(&delayed_refs->lock);
12911294

12921295
btrfs_release_path(path);
@@ -1374,15 +1377,15 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
13741377
if (ret)
13751378
goto out;
13761379

1377-
__merge_refs(&prefs, 1);
1380+
__merge_refs(&prefs, MERGE_IDENTICAL_KEYS);
13781381

13791382
ret = __resolve_indirect_refs(fs_info, path, time_seq, &prefs,
13801383
extent_item_pos, total_refs,
13811384
root_objectid);
13821385
if (ret)
13831386
goto out;
13841387

1385-
__merge_refs(&prefs, 2);
1388+
__merge_refs(&prefs, MERGE_IDENTICAL_PARENTS);
13861389

13871390
while (!list_empty(&prefs)) {
13881391
ref = list_first_entry(&prefs, struct __prelim_ref, list);

‎fs/btrfs/btrfs_inode.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ struct btrfs_inode {
124124
*/
125125
u64 delalloc_bytes;
126126

127+
/*
128+
* Total number of bytes pending delalloc that fall within a file
129+
* range that is either a hole or beyond EOF (and no prealloc extent
130+
* exists in the range). This is always <= delalloc_bytes.
131+
*/
132+
u64 new_delalloc_bytes;
133+
127134
/*
128135
* total number of bytes pending defrag, used by stat to check whether
129136
* it needs COW.

‎fs/btrfs/compression.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
struct compressed_bio {
4646
/* number of bios pending for this compressed extent */
47-
atomic_t pending_bios;
47+
refcount_t pending_bios;
4848

4949
/* the pages with the compressed data on them */
5050
struct page **compressed_pages;
@@ -161,7 +161,7 @@ static void end_compressed_bio_read(struct bio *bio)
161161
/* if there are more bios still pending for this compressed
162162
* extent, just exit
163163
*/
164-
if (!atomic_dec_and_test(&cb->pending_bios))
164+
if (!refcount_dec_and_test(&cb->pending_bios))
165165
goto out;
166166

167167
inode = cb->inode;
@@ -274,7 +274,7 @@ static void end_compressed_bio_write(struct bio *bio)
274274
/* if there are more bios still pending for this compressed
275275
* extent, just exit
276276
*/
277-
if (!atomic_dec_and_test(&cb->pending_bios))
277+
if (!refcount_dec_and_test(&cb->pending_bios))
278278
goto out;
279279

280280
/* ok, we're the last bio for this extent, step one is to
@@ -342,7 +342,7 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start,
342342
cb = kmalloc(compressed_bio_size(fs_info, compressed_len), GFP_NOFS);
343343
if (!cb)
344344
return -ENOMEM;
345-
atomic_set(&cb->pending_bios, 0);
345+
refcount_set(&cb->pending_bios, 0);
346346
cb->errors = 0;
347347
cb->inode = inode;
348348
cb->start = start;
@@ -363,7 +363,7 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start,
363363
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
364364
bio->bi_private = cb;
365365
bio->bi_end_io = end_compressed_bio_write;
366-
atomic_inc(&cb->pending_bios);
366+
refcount_set(&cb->pending_bios, 1);
367367

368368
/* create and submit bios for the compressed pages */
369369
bytes_left = compressed_len;
@@ -388,7 +388,7 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start,
388388
* we inc the count. Otherwise, the cb might get
389389
* freed before we're done setting it up
390390
*/
391-
atomic_inc(&cb->pending_bios);
391+
refcount_inc(&cb->pending_bios);
392392
ret = btrfs_bio_wq_end_io(fs_info, bio,
393393
BTRFS_WQ_ENDIO_DATA);
394394
BUG_ON(ret); /* -ENOMEM */
@@ -607,7 +607,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
607607
if (!cb)
608608
goto out;
609609

610-
atomic_set(&cb->pending_bios, 0);
610+
refcount_set(&cb->pending_bios, 0);
611611
cb->errors = 0;
612612
cb->inode = inode;
613613
cb->mirror_num = mirror_num;
@@ -656,7 +656,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
656656
bio_set_op_attrs (comp_bio, REQ_OP_READ, 0);
657657
comp_bio->bi_private = cb;
658658
comp_bio->bi_end_io = end_compressed_bio_read;
659-
atomic_inc(&cb->pending_bios);
659+
refcount_set(&cb->pending_bios, 1);
660660

661661
for (pg_index = 0; pg_index < nr_pages; pg_index++) {
662662
page = cb->compressed_pages[pg_index];
@@ -685,7 +685,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
685685
* we inc the count. Otherwise, the cb might get
686686
* freed before we're done setting it up
687687
*/
688-
atomic_inc(&cb->pending_bios);
688+
refcount_inc(&cb->pending_bios);
689689

690690
if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) {
691691
ret = btrfs_lookup_bio_sums(inode, comp_bio,

‎fs/btrfs/ctree.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ tree_mod_log_insert_key(struct btrfs_fs_info *fs_info,
567567
static noinline int
568568
tree_mod_log_insert_move(struct btrfs_fs_info *fs_info,
569569
struct extent_buffer *eb, int dst_slot, int src_slot,
570-
int nr_items, gfp_t flags)
570+
int nr_items)
571571
{
572572
struct tree_mod_elem *tm = NULL;
573573
struct tree_mod_elem **tm_list = NULL;
@@ -578,11 +578,11 @@ tree_mod_log_insert_move(struct btrfs_fs_info *fs_info,
578578
if (!tree_mod_need_log(fs_info, eb))
579579
return 0;
580580

581-
tm_list = kcalloc(nr_items, sizeof(struct tree_mod_elem *), flags);
581+
tm_list = kcalloc(nr_items, sizeof(struct tree_mod_elem *), GFP_NOFS);
582582
if (!tm_list)
583583
return -ENOMEM;
584584

585-
tm = kzalloc(sizeof(*tm), flags);
585+
tm = kzalloc(sizeof(*tm), GFP_NOFS);
586586
if (!tm) {
587587
ret = -ENOMEM;
588588
goto free_tms;
@@ -596,7 +596,7 @@ tree_mod_log_insert_move(struct btrfs_fs_info *fs_info,
596596

597597
for (i = 0; i + dst_slot < src_slot && i < nr_items; i++) {
598598
tm_list[i] = alloc_tree_mod_elem(eb, i + dst_slot,
599-
MOD_LOG_KEY_REMOVE_WHILE_MOVING, flags);
599+
MOD_LOG_KEY_REMOVE_WHILE_MOVING, GFP_NOFS);
600600
if (!tm_list[i]) {
601601
ret = -ENOMEM;
602602
goto free_tms;
@@ -663,7 +663,7 @@ __tree_mod_log_free_eb(struct btrfs_fs_info *fs_info,
663663
static noinline int
664664
tree_mod_log_insert_root(struct btrfs_fs_info *fs_info,
665665
struct extent_buffer *old_root,
666-
struct extent_buffer *new_root, gfp_t flags,
666+
struct extent_buffer *new_root,
667667
int log_removal)
668668
{
669669
struct tree_mod_elem *tm = NULL;
@@ -678,22 +678,22 @@ tree_mod_log_insert_root(struct btrfs_fs_info *fs_info,
678678
if (log_removal && btrfs_header_level(old_root) > 0) {
679679
nritems = btrfs_header_nritems(old_root);
680680
tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *),
681-
flags);
681+
GFP_NOFS);
682682
if (!tm_list) {
683683
ret = -ENOMEM;
684684
goto free_tms;
685685
}
686686
for (i = 0; i < nritems; i++) {
687687
tm_list[i] = alloc_tree_mod_elem(old_root, i,
688-
MOD_LOG_KEY_REMOVE_WHILE_FREEING, flags);
688+
MOD_LOG_KEY_REMOVE_WHILE_FREEING, GFP_NOFS);
689689
if (!tm_list[i]) {
690690
ret = -ENOMEM;
691691
goto free_tms;
692692
}
693693
}
694694
}
695695

696-
tm = kzalloc(sizeof(*tm), flags);
696+
tm = kzalloc(sizeof(*tm), GFP_NOFS);
697697
if (!tm) {
698698
ret = -ENOMEM;
699699
goto free_tms;
@@ -873,7 +873,7 @@ tree_mod_log_eb_move(struct btrfs_fs_info *fs_info, struct extent_buffer *dst,
873873
{
874874
int ret;
875875
ret = tree_mod_log_insert_move(fs_info, dst, dst_offset, src_offset,
876-
nr_items, GFP_NOFS);
876+
nr_items);
877877
BUG_ON(ret < 0);
878878
}
879879

@@ -943,7 +943,7 @@ tree_mod_log_set_root_pointer(struct btrfs_root *root,
943943
{
944944
int ret;
945945
ret = tree_mod_log_insert_root(root->fs_info, root->node,
946-
new_root_node, GFP_NOFS, log_removal);
946+
new_root_node, log_removal);
947947
BUG_ON(ret < 0);
948948
}
949949

0 commit comments

Comments
 (0)