Skip to content

Commit b7c09ad

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: "This is against 3.11-rc7, but was pulled and tested against your tree as of yesterday. We do have two small incrementals queued up, but I wanted to get this bunch out the door before I hop on an airplane. This is a fairly large batch of fixes, performance improvements, and cleanups from the usual Btrfs suspects. We've included Stefan Behren's work to index subvolume UUIDs, which is targeted at speeding up send/receive with many subvolumes or snapshots in place. It closes a long standing performance issue that was built in to the disk format. Mark Fasheh's offline dedup work is also here. In this case offline means the FS is mounted and active, but the dedup work is not done inline during file IO. This is a building block where utilities are able to ask the FS to dedup a series of extents. The kernel takes care of verifying the data involved really is the same. Today this involves reading both extents, but we'll continue to evolve the patches" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (118 commits) Btrfs: optimize key searches in btrfs_search_slot Btrfs: don't use an async starter for most of our workers Btrfs: only update disk_i_size as we remove extents Btrfs: fix deadlock in uuid scan kthread Btrfs: stop refusing the relocation of chunk 0 Btrfs: fix memory leak of uuid_root in free_fs_info btrfs: reuse kbasename helper btrfs: return btrfs error code for dev excl ops err Btrfs: allow partial ordered extent completion Btrfs: convert all bug_ons in free-space-cache.c Btrfs: add support for asserts Btrfs: adjust the fs_devices->missing count on unmount Btrf: cleanup: don't check for root_refs == 0 twice Btrfs: fix for patch "cleanup: don't check the same thing twice" Btrfs: get rid of one BUG() in write_all_supers() Btrfs: allocate prelim_ref with a slab allocater Btrfs: pass gfp_t to __add_prelim_ref() to avoid always using GFP_ATOMIC Btrfs: fix race conditions in BTRFS_IOC_FS_INFO ioctl Btrfs: fix race between removing a dev and writing sbs Btrfs: remove ourselves from the cluster list under lock ...
2 parents 1812997 + d7396f0 commit b7c09ad

43 files changed

Lines changed: 4045 additions & 2352 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/Kconfig‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,12 @@ config BTRFS_DEBUG
7272
performance, or export extra information via sysfs.
7373

7474
If unsure, say N.
75+
76+
config BTRFS_ASSERT
77+
bool "Btrfs assert support"
78+
depends on BTRFS_FS
79+
help
80+
Enable run-time assertion checking. This will result in panics if
81+
any of the assertions trip. This is meant for btrfs developers only.
82+
83+
If unsure, say N.

‎fs/btrfs/Makefile‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
88
extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \
99
export.o tree-log.o free-space-cache.o zlib.o lzo.o \
1010
compression.o delayed-ref.o relocation.o delayed-inode.o scrub.o \
11-
reada.o backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o
11+
reada.o backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o \
12+
uuid-tree.o
1213

1314
btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o
1415
btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
16+
17+
btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o

‎fs/btrfs/backref.c‎

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,26 @@ struct __prelim_ref {
119119
u64 wanted_disk_byte;
120120
};
121121

122+
static struct kmem_cache *btrfs_prelim_ref_cache;
123+
124+
int __init btrfs_prelim_ref_init(void)
125+
{
126+
btrfs_prelim_ref_cache = kmem_cache_create("btrfs_prelim_ref",
127+
sizeof(struct __prelim_ref),
128+
0,
129+
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
130+
NULL);
131+
if (!btrfs_prelim_ref_cache)
132+
return -ENOMEM;
133+
return 0;
134+
}
135+
136+
void btrfs_prelim_ref_exit(void)
137+
{
138+
if (btrfs_prelim_ref_cache)
139+
kmem_cache_destroy(btrfs_prelim_ref_cache);
140+
}
141+
122142
/*
123143
* the rules for all callers of this function are:
124144
* - obtaining the parent is the goal
@@ -160,12 +180,12 @@ struct __prelim_ref {
160180

161181
static int __add_prelim_ref(struct list_head *head, u64 root_id,
162182
struct btrfs_key *key, int level,
163-
u64 parent, u64 wanted_disk_byte, int count)
183+
u64 parent, u64 wanted_disk_byte, int count,
184+
gfp_t gfp_mask)
164185
{
165186
struct __prelim_ref *ref;
166187

167-
/* in case we're adding delayed refs, we're holding the refs spinlock */
168-
ref = kmalloc(sizeof(*ref), GFP_ATOMIC);
188+
ref = kmem_cache_alloc(btrfs_prelim_ref_cache, gfp_mask);
169189
if (!ref)
170190
return -ENOMEM;
171191

@@ -295,10 +315,9 @@ static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
295315
ret = btrfs_search_old_slot(root, &ref->key_for_search, path, time_seq);
296316
pr_debug("search slot in root %llu (level %d, ref count %d) returned "
297317
"%d for key (%llu %u %llu)\n",
298-
(unsigned long long)ref->root_id, level, ref->count, ret,
299-
(unsigned long long)ref->key_for_search.objectid,
300-
ref->key_for_search.type,
301-
(unsigned long long)ref->key_for_search.offset);
318+
ref->root_id, level, ref->count, ret,
319+
ref->key_for_search.objectid, ref->key_for_search.type,
320+
ref->key_for_search.offset);
302321
if (ret < 0)
303322
goto out;
304323

@@ -365,11 +384,12 @@ static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
365384
node = ulist_next(parents, &uiter);
366385
ref->parent = node ? node->val : 0;
367386
ref->inode_list = node ?
368-
(struct extent_inode_elem *)(uintptr_t)node->aux : 0;
387+
(struct extent_inode_elem *)(uintptr_t)node->aux : NULL;
369388

370389
/* additional parents require new refs being added here */
371390
while ((node = ulist_next(parents, &uiter))) {
372-
new_ref = kmalloc(sizeof(*new_ref), GFP_NOFS);
391+
new_ref = kmem_cache_alloc(btrfs_prelim_ref_cache,
392+
GFP_NOFS);
373393
if (!new_ref) {
374394
ret = -ENOMEM;
375395
goto out;
@@ -493,7 +513,7 @@ static void __merge_refs(struct list_head *head, int mode)
493513
ref1->count += ref2->count;
494514

495515
list_del(&ref2->list);
496-
kfree(ref2);
516+
kmem_cache_free(btrfs_prelim_ref_cache, ref2);
497517
}
498518

499519
}
@@ -548,7 +568,7 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
548568
ref = btrfs_delayed_node_to_tree_ref(node);
549569
ret = __add_prelim_ref(prefs, ref->root, &op_key,
550570
ref->level + 1, 0, node->bytenr,
551-
node->ref_mod * sgn);
571+
node->ref_mod * sgn, GFP_ATOMIC);
552572
break;
553573
}
554574
case BTRFS_SHARED_BLOCK_REF_KEY: {
@@ -558,7 +578,7 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
558578
ret = __add_prelim_ref(prefs, ref->root, NULL,
559579
ref->level + 1, ref->parent,
560580
node->bytenr,
561-
node->ref_mod * sgn);
581+
node->ref_mod * sgn, GFP_ATOMIC);
562582
break;
563583
}
564584
case BTRFS_EXTENT_DATA_REF_KEY: {
@@ -570,7 +590,7 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
570590
key.offset = ref->offset;
571591
ret = __add_prelim_ref(prefs, ref->root, &key, 0, 0,
572592
node->bytenr,
573-
node->ref_mod * sgn);
593+
node->ref_mod * sgn, GFP_ATOMIC);
574594
break;
575595
}
576596
case BTRFS_SHARED_DATA_REF_KEY: {
@@ -583,7 +603,7 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
583603
key.offset = ref->offset;
584604
ret = __add_prelim_ref(prefs, ref->root, &key, 0,
585605
ref->parent, node->bytenr,
586-
node->ref_mod * sgn);
606+
node->ref_mod * sgn, GFP_ATOMIC);
587607
break;
588608
}
589609
default:
@@ -657,7 +677,7 @@ static int __add_inline_refs(struct btrfs_fs_info *fs_info,
657677
case BTRFS_SHARED_BLOCK_REF_KEY:
658678
ret = __add_prelim_ref(prefs, 0, NULL,
659679
*info_level + 1, offset,
660-
bytenr, 1);
680+
bytenr, 1, GFP_NOFS);
661681
break;
662682
case BTRFS_SHARED_DATA_REF_KEY: {
663683
struct btrfs_shared_data_ref *sdref;
@@ -666,13 +686,13 @@ static int __add_inline_refs(struct btrfs_fs_info *fs_info,
666686
sdref = (struct btrfs_shared_data_ref *)(iref + 1);
667687
count = btrfs_shared_data_ref_count(leaf, sdref);
668688
ret = __add_prelim_ref(prefs, 0, NULL, 0, offset,
669-
bytenr, count);
689+
bytenr, count, GFP_NOFS);
670690
break;
671691
}
672692
case BTRFS_TREE_BLOCK_REF_KEY:
673693
ret = __add_prelim_ref(prefs, offset, NULL,
674694
*info_level + 1, 0,
675-
bytenr, 1);
695+
bytenr, 1, GFP_NOFS);
676696
break;
677697
case BTRFS_EXTENT_DATA_REF_KEY: {
678698
struct btrfs_extent_data_ref *dref;
@@ -687,7 +707,7 @@ static int __add_inline_refs(struct btrfs_fs_info *fs_info,
687707
key.offset = btrfs_extent_data_ref_offset(leaf, dref);
688708
root = btrfs_extent_data_ref_root(leaf, dref);
689709
ret = __add_prelim_ref(prefs, root, &key, 0, 0,
690-
bytenr, count);
710+
bytenr, count, GFP_NOFS);
691711
break;
692712
}
693713
default:
@@ -738,7 +758,7 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
738758
case BTRFS_SHARED_BLOCK_REF_KEY:
739759
ret = __add_prelim_ref(prefs, 0, NULL,
740760
info_level + 1, key.offset,
741-
bytenr, 1);
761+
bytenr, 1, GFP_NOFS);
742762
break;
743763
case BTRFS_SHARED_DATA_REF_KEY: {
744764
struct btrfs_shared_data_ref *sdref;
@@ -748,13 +768,13 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
748768
struct btrfs_shared_data_ref);
749769
count = btrfs_shared_data_ref_count(leaf, sdref);
750770
ret = __add_prelim_ref(prefs, 0, NULL, 0, key.offset,
751-
bytenr, count);
771+
bytenr, count, GFP_NOFS);
752772
break;
753773
}
754774
case BTRFS_TREE_BLOCK_REF_KEY:
755775
ret = __add_prelim_ref(prefs, key.offset, NULL,
756776
info_level + 1, 0,
757-
bytenr, 1);
777+
bytenr, 1, GFP_NOFS);
758778
break;
759779
case BTRFS_EXTENT_DATA_REF_KEY: {
760780
struct btrfs_extent_data_ref *dref;
@@ -770,7 +790,7 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
770790
key.offset = btrfs_extent_data_ref_offset(leaf, dref);
771791
root = btrfs_extent_data_ref_root(leaf, dref);
772792
ret = __add_prelim_ref(prefs, root, &key, 0, 0,
773-
bytenr, count);
793+
bytenr, count, GFP_NOFS);
774794
break;
775795
}
776796
default:
@@ -911,7 +931,6 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
911931

912932
while (!list_empty(&prefs)) {
913933
ref = list_first_entry(&prefs, struct __prelim_ref, list);
914-
list_del(&ref->list);
915934
WARN_ON(ref->count < 0);
916935
if (ref->count && ref->root_id && ref->parent == 0) {
917936
/* no parent == root of tree */
@@ -935,8 +954,10 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
935954
}
936955
ret = find_extent_in_eb(eb, bytenr,
937956
*extent_item_pos, &eie);
938-
ref->inode_list = eie;
939957
free_extent_buffer(eb);
958+
if (ret < 0)
959+
goto out;
960+
ref->inode_list = eie;
940961
}
941962
ret = ulist_add_merge(refs, ref->parent,
942963
(uintptr_t)ref->inode_list,
@@ -954,21 +975,22 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
954975
eie->next = ref->inode_list;
955976
}
956977
}
957-
kfree(ref);
978+
list_del(&ref->list);
979+
kmem_cache_free(btrfs_prelim_ref_cache, ref);
958980
}
959981

960982
out:
961983
btrfs_free_path(path);
962984
while (!list_empty(&prefs)) {
963985
ref = list_first_entry(&prefs, struct __prelim_ref, list);
964986
list_del(&ref->list);
965-
kfree(ref);
987+
kmem_cache_free(btrfs_prelim_ref_cache, ref);
966988
}
967989
while (!list_empty(&prefs_delayed)) {
968990
ref = list_first_entry(&prefs_delayed, struct __prelim_ref,
969991
list);
970992
list_del(&ref->list);
971-
kfree(ref);
993+
kmem_cache_free(btrfs_prelim_ref_cache, ref);
972994
}
973995

974996
return ret;
@@ -1326,8 +1348,7 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
13261348
found_key->type != BTRFS_METADATA_ITEM_KEY) ||
13271349
found_key->objectid > logical ||
13281350
found_key->objectid + size <= logical) {
1329-
pr_debug("logical %llu is not within any extent\n",
1330-
(unsigned long long)logical);
1351+
pr_debug("logical %llu is not within any extent\n", logical);
13311352
return -ENOENT;
13321353
}
13331354

@@ -1340,11 +1361,8 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
13401361

13411362
pr_debug("logical %llu is at position %llu within the extent (%llu "
13421363
"EXTENT_ITEM %llu) flags %#llx size %u\n",
1343-
(unsigned long long)logical,
1344-
(unsigned long long)(logical - found_key->objectid),
1345-
(unsigned long long)found_key->objectid,
1346-
(unsigned long long)found_key->offset,
1347-
(unsigned long long)flags, item_size);
1364+
logical, logical - found_key->objectid, found_key->objectid,
1365+
found_key->offset, flags, item_size);
13481366

13491367
WARN_ON(!flags_ret);
13501368
if (flags_ret) {
@@ -1516,7 +1534,7 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
15161534
while (!ret && (root_node = ulist_next(roots, &root_uiter))) {
15171535
pr_debug("root %llu references leaf %llu, data list "
15181536
"%#llx\n", root_node->val, ref_node->val,
1519-
(long long)ref_node->aux);
1537+
ref_node->aux);
15201538
ret = iterate_leaf_refs((struct extent_inode_elem *)
15211539
(uintptr_t)ref_node->aux,
15221540
root_node->val,
@@ -1608,9 +1626,8 @@ static int iterate_inode_refs(u64 inum, struct btrfs_root *fs_root,
16081626
name_len = btrfs_inode_ref_name_len(eb, iref);
16091627
/* path must be released before calling iterate()! */
16101628
pr_debug("following ref at offset %u for inode %llu in "
1611-
"tree %llu\n", cur,
1612-
(unsigned long long)found_key.objectid,
1613-
(unsigned long long)fs_root->objectid);
1629+
"tree %llu\n", cur, found_key.objectid,
1630+
fs_root->objectid);
16141631
ret = iterate(parent, name_len,
16151632
(unsigned long)(iref + 1), eb, ctx);
16161633
if (ret)

‎fs/btrfs/backref.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,6 @@ int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid,
7272
struct btrfs_inode_extref **ret_extref,
7373
u64 *found_off);
7474

75+
int __init btrfs_prelim_ref_init(void);
76+
void btrfs_prelim_ref_exit(void);
7577
#endif

‎fs/btrfs/btrfs_inode.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,27 @@ static inline int btrfs_inode_in_log(struct inode *inode, u64 generation)
218218
return 0;
219219
}
220220

221+
struct btrfs_dio_private {
222+
struct inode *inode;
223+
u64 logical_offset;
224+
u64 disk_bytenr;
225+
u64 bytes;
226+
void *private;
227+
228+
/* number of bios pending for this dio */
229+
atomic_t pending_bios;
230+
231+
/* IO errors */
232+
int errors;
233+
234+
/* orig_bio is our btrfs_io_bio */
235+
struct bio *orig_bio;
236+
237+
/* dio_bio came from fs/direct-io.c */
238+
struct bio *dio_bio;
239+
u8 csum[0];
240+
};
241+
221242
/*
222243
* Disable DIO read nolock optimization, so new dio readers will be forced
223244
* to grab i_mutex. It is used to avoid the endless truncate due to

0 commit comments

Comments
 (0)