Skip to content

Commit 5cea764

Browse files
committed
Merge branch 'for-4.15' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs updates from David Sterba: "There are some new user features and the usual load of invisible enhancements or cleanups. New features: - extend mount options to specify zlib compression level, -o compress=zlib:9 - v2 of ioctl "extent to inode mapping", addressing a usecase where we want to retrieve more but inaccurate results and do the postprocessing in userspace, aiding defragmentation or deduplication tools - populate compression heuristics logic, do data sampling and try to guess compressibility by: looking for repeated patterns, counting unique byte values and distribution, calculating Shannon entropy; this will need more benchmarking and possibly fine tuning, but the base should be good enough - enable indexing for btrfs as lower filesystem in overlayfs - speedup page cache readahead during send on large files Internal enhancements: - more sanity checks of b-tree items when reading them from disk - more EINVAL/EUCLEAN fixups, missing BLK_STS_* conversion, other errno or error handling fixes - remove some homegrown IO-related logic, that's been obsoleted by core block layer changes (batching, plug/unplug, own counters) - add ref-verify, optional debugging feature to verify extent reference accounting - simplify code handling outstanding extents, make it more clear where and how the accounting is done - make delalloc reservations per-inode, simplify the code and make the logic more straightforward - extensive cleanup of delayed refs code Notable fixes: - fix send ioctl on 32bit with 64bit kernel" * 'for-4.15' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: (102 commits) btrfs: Fix bug for misused dev_t when lookup in dev state hash table. Btrfs: heuristic: add Shannon entropy calculation Btrfs: heuristic: add byte core set calculation Btrfs: heuristic: add byte set calculation Btrfs: heuristic: add detection of repeated data patterns Btrfs: heuristic: implement sampling logic Btrfs: heuristic: add bucket and sample counters and other defines Btrfs: compression: separate heuristic/compression workspaces btrfs: move btrfs_truncate_block out of trans handle btrfs: don't call btrfs_start_delalloc_roots in flushoncommit btrfs: track refs in a rb_tree instead of a list btrfs: add a comp_refs() helper btrfs: switch args for comp_*_refs btrfs: make the delalloc block rsv per inode btrfs: add tracepoints for outstanding extents mods Btrfs: rework outstanding_extents btrfs: increase output size for LOGICAL_INO_V2 ioctl btrfs: add a flags argument to LOGICAL_INO and call it LOGICAL_INO_V2 btrfs: add a flag to iterate_inodes_from_logical to find all extent refs for uncompressed extents btrfs: send: remove unused code ...
2 parents 808eb24 + d28e649 commit 5cea764

51 files changed

Lines changed: 3356 additions & 1556 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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,14 @@ config BTRFS_ASSERT
9191
any of the assertions trip. This is meant for btrfs developers only.
9292

9393
If unsure, say N.
94+
95+
config BTRFS_FS_REF_VERIFY
96+
bool "Btrfs with the ref verify tool compiled in"
97+
depends on BTRFS_FS
98+
default n
99+
help
100+
Enable run-time extent reference verification instrumentation. This
101+
is meant to be used by btrfs developers for tracking down extent
102+
reference problems or verifying they didn't break something.
103+
104+
If unsure, say N.

‎fs/btrfs/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
1010
export.o tree-log.o free-space-cache.o zlib.o lzo.o zstd.o \
1111
compression.o delayed-ref.o relocation.o delayed-inode.o scrub.o \
1212
reada.o backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o \
13-
uuid-tree.o props.o hash.o free-space-tree.o
13+
uuid-tree.o props.o hash.o free-space-tree.o tree-checker.o
1414

1515
btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o
1616
btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
17+
btrfs-$(CONFIG_BTRFS_FS_REF_VERIFY) += ref-verify.o
1718

1819
btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o \
1920
tests/extent-buffer-tests.o tests/btrfs-tests.o \

‎fs/btrfs/async-thread.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct btrfs_workqueue {
6767
static void normal_work_helper(struct btrfs_work *work);
6868

6969
#define BTRFS_WORK_HELPER(name) \
70-
void btrfs_##name(struct work_struct *arg) \
70+
noinline_for_stack void btrfs_##name(struct work_struct *arg) \
7171
{ \
7272
struct btrfs_work *work = container_of(arg, struct btrfs_work, \
7373
normal_work); \

‎fs/btrfs/backref.c‎

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ static int check_extent_in_eb(const struct btrfs_key *key,
4040
const struct extent_buffer *eb,
4141
const struct btrfs_file_extent_item *fi,
4242
u64 extent_item_pos,
43-
struct extent_inode_elem **eie)
43+
struct extent_inode_elem **eie,
44+
bool ignore_offset)
4445
{
4546
u64 offset = 0;
4647
struct extent_inode_elem *e;
4748

48-
if (!btrfs_file_extent_compression(eb, fi) &&
49+
if (!ignore_offset &&
50+
!btrfs_file_extent_compression(eb, fi) &&
4951
!btrfs_file_extent_encryption(eb, fi) &&
5052
!btrfs_file_extent_other_encoding(eb, fi)) {
5153
u64 data_offset;
@@ -84,7 +86,8 @@ static void free_inode_elem_list(struct extent_inode_elem *eie)
8486

8587
static int find_extent_in_eb(const struct extent_buffer *eb,
8688
u64 wanted_disk_byte, u64 extent_item_pos,
87-
struct extent_inode_elem **eie)
89+
struct extent_inode_elem **eie,
90+
bool ignore_offset)
8891
{
8992
u64 disk_byte;
9093
struct btrfs_key key;
@@ -113,7 +116,7 @@ static int find_extent_in_eb(const struct extent_buffer *eb,
113116
if (disk_byte != wanted_disk_byte)
114117
continue;
115118

116-
ret = check_extent_in_eb(&key, eb, fi, extent_item_pos, eie);
119+
ret = check_extent_in_eb(&key, eb, fi, extent_item_pos, eie, ignore_offset);
117120
if (ret < 0)
118121
return ret;
119122
}
@@ -419,7 +422,7 @@ static int add_indirect_ref(const struct btrfs_fs_info *fs_info,
419422
static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
420423
struct ulist *parents, struct prelim_ref *ref,
421424
int level, u64 time_seq, const u64 *extent_item_pos,
422-
u64 total_refs)
425+
u64 total_refs, bool ignore_offset)
423426
{
424427
int ret = 0;
425428
int slot;
@@ -472,7 +475,7 @@ static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
472475
if (extent_item_pos) {
473476
ret = check_extent_in_eb(&key, eb, fi,
474477
*extent_item_pos,
475-
&eie);
478+
&eie, ignore_offset);
476479
if (ret < 0)
477480
break;
478481
}
@@ -510,7 +513,8 @@ static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
510513
static int resolve_indirect_ref(struct btrfs_fs_info *fs_info,
511514
struct btrfs_path *path, u64 time_seq,
512515
struct prelim_ref *ref, struct ulist *parents,
513-
const u64 *extent_item_pos, u64 total_refs)
516+
const u64 *extent_item_pos, u64 total_refs,
517+
bool ignore_offset)
514518
{
515519
struct btrfs_root *root;
516520
struct btrfs_key root_key;
@@ -581,7 +585,7 @@ static int resolve_indirect_ref(struct btrfs_fs_info *fs_info,
581585
}
582586

583587
ret = add_all_parents(root, path, parents, ref, level, time_seq,
584-
extent_item_pos, total_refs);
588+
extent_item_pos, total_refs, ignore_offset);
585589
out:
586590
path->lowest_level = 0;
587591
btrfs_release_path(path);
@@ -616,7 +620,7 @@ static int resolve_indirect_refs(struct btrfs_fs_info *fs_info,
616620
struct btrfs_path *path, u64 time_seq,
617621
struct preftrees *preftrees,
618622
const u64 *extent_item_pos, u64 total_refs,
619-
struct share_check *sc)
623+
struct share_check *sc, bool ignore_offset)
620624
{
621625
int err;
622626
int ret = 0;
@@ -661,7 +665,7 @@ static int resolve_indirect_refs(struct btrfs_fs_info *fs_info,
661665
}
662666
err = resolve_indirect_ref(fs_info, path, time_seq, ref,
663667
parents, extent_item_pos,
664-
total_refs);
668+
total_refs, ignore_offset);
665669
/*
666670
* we can only tolerate ENOENT,otherwise,we should catch error
667671
* and return directly.
@@ -769,6 +773,7 @@ static int add_delayed_refs(const struct btrfs_fs_info *fs_info,
769773
struct btrfs_key key;
770774
struct btrfs_key tmp_op_key;
771775
struct btrfs_key *op_key = NULL;
776+
struct rb_node *n;
772777
int count;
773778
int ret = 0;
774779

@@ -778,7 +783,9 @@ static int add_delayed_refs(const struct btrfs_fs_info *fs_info,
778783
}
779784

780785
spin_lock(&head->lock);
781-
list_for_each_entry(node, &head->ref_list, list) {
786+
for (n = rb_first(&head->ref_tree); n; n = rb_next(n)) {
787+
node = rb_entry(n, struct btrfs_delayed_ref_node,
788+
ref_node);
782789
if (node->seq > seq)
783790
continue;
784791

@@ -1107,13 +1114,17 @@ static int add_keyed_refs(struct btrfs_fs_info *fs_info,
11071114
*
11081115
* Otherwise this returns 0 for success and <0 for an error.
11091116
*
1117+
* If ignore_offset is set to false, only extent refs whose offsets match
1118+
* extent_item_pos are returned. If true, every extent ref is returned
1119+
* and extent_item_pos is ignored.
1120+
*
11101121
* FIXME some caching might speed things up
11111122
*/
11121123
static int find_parent_nodes(struct btrfs_trans_handle *trans,
11131124
struct btrfs_fs_info *fs_info, u64 bytenr,
11141125
u64 time_seq, struct ulist *refs,
11151126
struct ulist *roots, const u64 *extent_item_pos,
1116-
struct share_check *sc)
1127+
struct share_check *sc, bool ignore_offset)
11171128
{
11181129
struct btrfs_key key;
11191130
struct btrfs_path *path;
@@ -1178,7 +1189,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
11781189
head = btrfs_find_delayed_ref_head(delayed_refs, bytenr);
11791190
if (head) {
11801191
if (!mutex_trylock(&head->mutex)) {
1181-
refcount_inc(&head->node.refs);
1192+
refcount_inc(&head->refs);
11821193
spin_unlock(&delayed_refs->lock);
11831194

11841195
btrfs_release_path(path);
@@ -1189,7 +1200,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
11891200
*/
11901201
mutex_lock(&head->mutex);
11911202
mutex_unlock(&head->mutex);
1192-
btrfs_put_delayed_ref(&head->node);
1203+
btrfs_put_delayed_ref_head(head);
11931204
goto again;
11941205
}
11951206
spin_unlock(&delayed_refs->lock);
@@ -1235,7 +1246,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
12351246
WARN_ON(!RB_EMPTY_ROOT(&preftrees.indirect_missing_keys.root));
12361247

12371248
ret = resolve_indirect_refs(fs_info, path, time_seq, &preftrees,
1238-
extent_item_pos, total_refs, sc);
1249+
extent_item_pos, total_refs, sc, ignore_offset);
12391250
if (ret)
12401251
goto out;
12411252

@@ -1282,7 +1293,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
12821293
btrfs_tree_read_lock(eb);
12831294
btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK);
12841295
ret = find_extent_in_eb(eb, bytenr,
1285-
*extent_item_pos, &eie);
1296+
*extent_item_pos, &eie, ignore_offset);
12861297
btrfs_tree_read_unlock_blocking(eb);
12871298
free_extent_buffer(eb);
12881299
if (ret < 0)
@@ -1350,7 +1361,7 @@ static void free_leaf_list(struct ulist *blocks)
13501361
static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans,
13511362
struct btrfs_fs_info *fs_info, u64 bytenr,
13521363
u64 time_seq, struct ulist **leafs,
1353-
const u64 *extent_item_pos)
1364+
const u64 *extent_item_pos, bool ignore_offset)
13541365
{
13551366
int ret;
13561367

@@ -1359,7 +1370,7 @@ static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans,
13591370
return -ENOMEM;
13601371

13611372
ret = find_parent_nodes(trans, fs_info, bytenr, time_seq,
1362-
*leafs, NULL, extent_item_pos, NULL);
1373+
*leafs, NULL, extent_item_pos, NULL, ignore_offset);
13631374
if (ret < 0 && ret != -ENOENT) {
13641375
free_leaf_list(*leafs);
13651376
return ret;
@@ -1383,7 +1394,8 @@ static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans,
13831394
*/
13841395
static int btrfs_find_all_roots_safe(struct btrfs_trans_handle *trans,
13851396
struct btrfs_fs_info *fs_info, u64 bytenr,
1386-
u64 time_seq, struct ulist **roots)
1397+
u64 time_seq, struct ulist **roots,
1398+
bool ignore_offset)
13871399
{
13881400
struct ulist *tmp;
13891401
struct ulist_node *node = NULL;
@@ -1402,7 +1414,7 @@ static int btrfs_find_all_roots_safe(struct btrfs_trans_handle *trans,
14021414
ULIST_ITER_INIT(&uiter);
14031415
while (1) {
14041416
ret = find_parent_nodes(trans, fs_info, bytenr, time_seq,
1405-
tmp, *roots, NULL, NULL);
1417+
tmp, *roots, NULL, NULL, ignore_offset);
14061418
if (ret < 0 && ret != -ENOENT) {
14071419
ulist_free(tmp);
14081420
ulist_free(*roots);
@@ -1421,14 +1433,15 @@ static int btrfs_find_all_roots_safe(struct btrfs_trans_handle *trans,
14211433

14221434
int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
14231435
struct btrfs_fs_info *fs_info, u64 bytenr,
1424-
u64 time_seq, struct ulist **roots)
1436+
u64 time_seq, struct ulist **roots,
1437+
bool ignore_offset)
14251438
{
14261439
int ret;
14271440

14281441
if (!trans)
14291442
down_read(&fs_info->commit_root_sem);
14301443
ret = btrfs_find_all_roots_safe(trans, fs_info, bytenr,
1431-
time_seq, roots);
1444+
time_seq, roots, ignore_offset);
14321445
if (!trans)
14331446
up_read(&fs_info->commit_root_sem);
14341447
return ret;
@@ -1483,7 +1496,7 @@ int btrfs_check_shared(struct btrfs_root *root, u64 inum, u64 bytenr)
14831496
ULIST_ITER_INIT(&uiter);
14841497
while (1) {
14851498
ret = find_parent_nodes(trans, fs_info, bytenr, elem.seq, tmp,
1486-
roots, NULL, &shared);
1499+
roots, NULL, &shared, false);
14871500
if (ret == BACKREF_FOUND_SHARED) {
14881501
/* this is the only condition under which we return 1 */
14891502
ret = 1;
@@ -1877,7 +1890,8 @@ static int iterate_leaf_refs(struct btrfs_fs_info *fs_info,
18771890
int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
18781891
u64 extent_item_objectid, u64 extent_item_pos,
18791892
int search_commit_root,
1880-
iterate_extent_inodes_t *iterate, void *ctx)
1893+
iterate_extent_inodes_t *iterate, void *ctx,
1894+
bool ignore_offset)
18811895
{
18821896
int ret;
18831897
struct btrfs_trans_handle *trans = NULL;
@@ -1903,14 +1917,15 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
19031917

19041918
ret = btrfs_find_all_leafs(trans, fs_info, extent_item_objectid,
19051919
tree_mod_seq_elem.seq, &refs,
1906-
&extent_item_pos);
1920+
&extent_item_pos, ignore_offset);
19071921
if (ret)
19081922
goto out;
19091923

19101924
ULIST_ITER_INIT(&ref_uiter);
19111925
while (!ret && (ref_node = ulist_next(refs, &ref_uiter))) {
19121926
ret = btrfs_find_all_roots_safe(trans, fs_info, ref_node->val,
1913-
tree_mod_seq_elem.seq, &roots);
1927+
tree_mod_seq_elem.seq, &roots,
1928+
ignore_offset);
19141929
if (ret)
19151930
break;
19161931
ULIST_ITER_INIT(&root_uiter);
@@ -1943,7 +1958,8 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
19431958

19441959
int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
19451960
struct btrfs_path *path,
1946-
iterate_extent_inodes_t *iterate, void *ctx)
1961+
iterate_extent_inodes_t *iterate, void *ctx,
1962+
bool ignore_offset)
19471963
{
19481964
int ret;
19491965
u64 extent_item_pos;
@@ -1961,7 +1977,7 @@ int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
19611977
extent_item_pos = logical - found_key.objectid;
19621978
ret = iterate_extent_inodes(fs_info, found_key.objectid,
19631979
extent_item_pos, search_commit_root,
1964-
iterate, ctx);
1980+
iterate, ctx, ignore_offset);
19651981

19661982
return ret;
19671983
}

‎fs/btrfs/backref.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,19 @@ int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
4343
int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
4444
u64 extent_item_objectid,
4545
u64 extent_offset, int search_commit_root,
46-
iterate_extent_inodes_t *iterate, void *ctx);
46+
iterate_extent_inodes_t *iterate, void *ctx,
47+
bool ignore_offset);
4748

4849
int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
4950
struct btrfs_path *path,
50-
iterate_extent_inodes_t *iterate, void *ctx);
51+
iterate_extent_inodes_t *iterate, void *ctx,
52+
bool ignore_offset);
5153

5254
int paths_from_inode(u64 inum, struct inode_fs_paths *ipath);
5355

5456
int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
5557
struct btrfs_fs_info *fs_info, u64 bytenr,
56-
u64 time_seq, struct ulist **roots);
58+
u64 time_seq, struct ulist **roots, bool ignore_offset);
5759
char *btrfs_ref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path,
5860
u32 name_len, unsigned long name_off,
5961
struct extent_buffer *eb_in, u64 parent,

‎fs/btrfs/btrfs_inode.h‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@
3636
#define BTRFS_INODE_ORPHAN_META_RESERVED 1
3737
#define BTRFS_INODE_DUMMY 2
3838
#define BTRFS_INODE_IN_DEFRAG 3
39-
#define BTRFS_INODE_DELALLOC_META_RESERVED 4
40-
#define BTRFS_INODE_HAS_ORPHAN_ITEM 5
41-
#define BTRFS_INODE_HAS_ASYNC_EXTENT 6
42-
#define BTRFS_INODE_NEEDS_FULL_SYNC 7
43-
#define BTRFS_INODE_COPY_EVERYTHING 8
44-
#define BTRFS_INODE_IN_DELALLOC_LIST 9
45-
#define BTRFS_INODE_READDIO_NEED_LOCK 10
46-
#define BTRFS_INODE_HAS_PROPS 11
39+
#define BTRFS_INODE_HAS_ORPHAN_ITEM 4
40+
#define BTRFS_INODE_HAS_ASYNC_EXTENT 5
41+
#define BTRFS_INODE_NEEDS_FULL_SYNC 6
42+
#define BTRFS_INODE_COPY_EVERYTHING 7
43+
#define BTRFS_INODE_IN_DELALLOC_LIST 8
44+
#define BTRFS_INODE_READDIO_NEED_LOCK 9
45+
#define BTRFS_INODE_HAS_PROPS 10
4746

4847
/* in memory btrfs inode */
4948
struct btrfs_inode {
@@ -176,7 +175,8 @@ struct btrfs_inode {
176175
* of extent items we've reserved metadata for.
177176
*/
178177
unsigned outstanding_extents;
179-
unsigned reserved_extents;
178+
179+
struct btrfs_block_rsv block_rsv;
180180

181181
/*
182182
* Cached values of inode properties
@@ -267,6 +267,17 @@ static inline bool btrfs_is_free_space_inode(struct btrfs_inode *inode)
267267
return false;
268268
}
269269

270+
static inline void btrfs_mod_outstanding_extents(struct btrfs_inode *inode,
271+
int mod)
272+
{
273+
lockdep_assert_held(&inode->lock);
274+
inode->outstanding_extents += mod;
275+
if (btrfs_is_free_space_inode(inode))
276+
return;
277+
trace_btrfs_inode_mod_outstanding_extents(inode->root, btrfs_ino(inode),
278+
mod);
279+
}
280+
270281
static inline int btrfs_inode_in_log(struct btrfs_inode *inode, u64 generation)
271282
{
272283
int ret = 0;

0 commit comments

Comments
 (0)