Skip to content

Commit e3a0dd9

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs update from Chris Mason: "These are the usual mixture of bugs, cleanups and performance fixes. Miao has some really nice tuning of our crc code as well as our transaction commits. Josef is peeling off more and more problems related to early enospc, and has a number of important bug fixes in here too" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (81 commits) Btrfs: wait ordered range before doing direct io Btrfs: only do the tree_mod_log_free_eb if this is our last ref Btrfs: hold the tree mod lock in __tree_mod_log_rewind Btrfs: make backref walking code handle skinny metadata Btrfs: fix crash regarding to ulist_add_merge Btrfs: fix several potential problems in copy_nocow_pages_for_inode Btrfs: cleanup the code of copy_nocow_pages_for_inode() Btrfs: fix oops when recovering the file data by scrub function Btrfs: make the chunk allocator completely tree lockless Btrfs: cleanup orphaned root orphan item Btrfs: fix wrong mirror number tuning Btrfs: cleanup redundant code in btrfs_submit_direct() Btrfs: remove btrfs_sector_sum structure Btrfs: check if we can nocow if we don't have data space Btrfs: stop using try_to_writeback_inodes_sb_nr to flush delalloc Btrfs: use a percpu to keep track of possibly pinned bytes Btrfs: check for actual acls rather than just xattrs when caching no acl Btrfs: move btrfs_truncate_page to btrfs_cont_expand instead of btrfs_truncate Btrfs: optimize reada_for_balance Btrfs: optimize read_block_for_search ...
2 parents da89bd2 + 0e267c4 commit e3a0dd9

36 files changed

Lines changed: 2391 additions & 1739 deletions

‎fs/btrfs/backref.c‎

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -255,25 +255,18 @@ static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
255255
* to a logical address
256256
*/
257257
static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
258-
int search_commit_root,
259-
u64 time_seq,
260-
struct __prelim_ref *ref,
261-
struct ulist *parents,
262-
const u64 *extent_item_pos)
258+
struct btrfs_path *path, u64 time_seq,
259+
struct __prelim_ref *ref,
260+
struct ulist *parents,
261+
const u64 *extent_item_pos)
263262
{
264-
struct btrfs_path *path;
265263
struct btrfs_root *root;
266264
struct btrfs_key root_key;
267265
struct extent_buffer *eb;
268266
int ret = 0;
269267
int root_level;
270268
int level = ref->level;
271269

272-
path = btrfs_alloc_path();
273-
if (!path)
274-
return -ENOMEM;
275-
path->search_commit_root = !!search_commit_root;
276-
277270
root_key.objectid = ref->root_id;
278271
root_key.type = BTRFS_ROOT_ITEM_KEY;
279272
root_key.offset = (u64)-1;
@@ -314,15 +307,16 @@ static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
314307
time_seq, ref->wanted_disk_byte,
315308
extent_item_pos);
316309
out:
317-
btrfs_free_path(path);
310+
path->lowest_level = 0;
311+
btrfs_release_path(path);
318312
return ret;
319313
}
320314

321315
/*
322316
* resolve all indirect backrefs from the list
323317
*/
324318
static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
325-
int search_commit_root, u64 time_seq,
319+
struct btrfs_path *path, u64 time_seq,
326320
struct list_head *head,
327321
const u64 *extent_item_pos)
328322
{
@@ -349,9 +343,8 @@ static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
349343
continue;
350344
if (ref->count == 0)
351345
continue;
352-
err = __resolve_indirect_ref(fs_info, search_commit_root,
353-
time_seq, ref, parents,
354-
extent_item_pos);
346+
err = __resolve_indirect_ref(fs_info, path, time_seq, ref,
347+
parents, extent_item_pos);
355348
if (err == -ENOMEM)
356349
goto out;
357350
if (err)
@@ -604,6 +597,7 @@ static int __add_inline_refs(struct btrfs_fs_info *fs_info,
604597
int slot;
605598
struct extent_buffer *leaf;
606599
struct btrfs_key key;
600+
struct btrfs_key found_key;
607601
unsigned long ptr;
608602
unsigned long end;
609603
struct btrfs_extent_item *ei;
@@ -621,17 +615,21 @@ static int __add_inline_refs(struct btrfs_fs_info *fs_info,
621615

622616
ei = btrfs_item_ptr(leaf, slot, struct btrfs_extent_item);
623617
flags = btrfs_extent_flags(leaf, ei);
618+
btrfs_item_key_to_cpu(leaf, &found_key, slot);
624619

625620
ptr = (unsigned long)(ei + 1);
626621
end = (unsigned long)ei + item_size;
627622

628-
if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
623+
if (found_key.type == BTRFS_EXTENT_ITEM_KEY &&
624+
flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
629625
struct btrfs_tree_block_info *info;
630626

631627
info = (struct btrfs_tree_block_info *)ptr;
632628
*info_level = btrfs_tree_block_level(leaf, info);
633629
ptr += sizeof(struct btrfs_tree_block_info);
634630
BUG_ON(ptr > end);
631+
} else if (found_key.type == BTRFS_METADATA_ITEM_KEY) {
632+
*info_level = found_key.offset;
635633
} else {
636634
BUG_ON(!(flags & BTRFS_EXTENT_FLAG_DATA));
637635
}
@@ -795,7 +793,6 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
795793
struct btrfs_delayed_ref_head *head;
796794
int info_level = 0;
797795
int ret;
798-
int search_commit_root = (trans == BTRFS_BACKREF_SEARCH_COMMIT_ROOT);
799796
struct list_head prefs_delayed;
800797
struct list_head prefs;
801798
struct __prelim_ref *ref;
@@ -804,13 +801,17 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
804801
INIT_LIST_HEAD(&prefs_delayed);
805802

806803
key.objectid = bytenr;
807-
key.type = BTRFS_EXTENT_ITEM_KEY;
808804
key.offset = (u64)-1;
805+
if (btrfs_fs_incompat(fs_info, SKINNY_METADATA))
806+
key.type = BTRFS_METADATA_ITEM_KEY;
807+
else
808+
key.type = BTRFS_EXTENT_ITEM_KEY;
809809

810810
path = btrfs_alloc_path();
811811
if (!path)
812812
return -ENOMEM;
813-
path->search_commit_root = !!search_commit_root;
813+
if (!trans)
814+
path->search_commit_root = 1;
814815

815816
/*
816817
* grab both a lock on the path and a lock on the delayed ref head.
@@ -825,7 +826,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
825826
goto out;
826827
BUG_ON(ret == 0);
827828

828-
if (trans != BTRFS_BACKREF_SEARCH_COMMIT_ROOT) {
829+
if (trans) {
829830
/*
830831
* look if there are updates for this ref queued and lock the
831832
* head
@@ -869,7 +870,8 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
869870
slot = path->slots[0];
870871
btrfs_item_key_to_cpu(leaf, &key, slot);
871872
if (key.objectid == bytenr &&
872-
key.type == BTRFS_EXTENT_ITEM_KEY) {
873+
(key.type == BTRFS_EXTENT_ITEM_KEY ||
874+
key.type == BTRFS_METADATA_ITEM_KEY)) {
873875
ret = __add_inline_refs(fs_info, path, bytenr,
874876
&info_level, &prefs);
875877
if (ret)
@@ -890,8 +892,8 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
890892

891893
__merge_refs(&prefs, 1);
892894

893-
ret = __resolve_indirect_refs(fs_info, search_commit_root, time_seq,
894-
&prefs, extent_item_pos);
895+
ret = __resolve_indirect_refs(fs_info, path, time_seq, &prefs,
896+
extent_item_pos);
895897
if (ret)
896898
goto out;
897899

@@ -1283,12 +1285,16 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
12831285
{
12841286
int ret;
12851287
u64 flags;
1288+
u64 size = 0;
12861289
u32 item_size;
12871290
struct extent_buffer *eb;
12881291
struct btrfs_extent_item *ei;
12891292
struct btrfs_key key;
12901293

1291-
key.type = BTRFS_EXTENT_ITEM_KEY;
1294+
if (btrfs_fs_incompat(fs_info, SKINNY_METADATA))
1295+
key.type = BTRFS_METADATA_ITEM_KEY;
1296+
else
1297+
key.type = BTRFS_EXTENT_ITEM_KEY;
12921298
key.objectid = logical;
12931299
key.offset = (u64)-1;
12941300

@@ -1301,9 +1307,15 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
13011307
return ret;
13021308

13031309
btrfs_item_key_to_cpu(path->nodes[0], found_key, path->slots[0]);
1304-
if (found_key->type != BTRFS_EXTENT_ITEM_KEY ||
1310+
if (found_key->type == BTRFS_METADATA_ITEM_KEY)
1311+
size = fs_info->extent_root->leafsize;
1312+
else if (found_key->type == BTRFS_EXTENT_ITEM_KEY)
1313+
size = found_key->offset;
1314+
1315+
if ((found_key->type != BTRFS_EXTENT_ITEM_KEY &&
1316+
found_key->type != BTRFS_METADATA_ITEM_KEY) ||
13051317
found_key->objectid > logical ||
1306-
found_key->objectid + found_key->offset <= logical) {
1318+
found_key->objectid + size <= logical) {
13071319
pr_debug("logical %llu is not within any extent\n",
13081320
(unsigned long long)logical);
13091321
return -ENOENT;
@@ -1459,7 +1471,7 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
14591471
iterate_extent_inodes_t *iterate, void *ctx)
14601472
{
14611473
int ret;
1462-
struct btrfs_trans_handle *trans;
1474+
struct btrfs_trans_handle *trans = NULL;
14631475
struct ulist *refs = NULL;
14641476
struct ulist *roots = NULL;
14651477
struct ulist_node *ref_node = NULL;
@@ -1471,9 +1483,7 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
14711483
pr_debug("resolving all inodes for extent %llu\n",
14721484
extent_item_objectid);
14731485

1474-
if (search_commit_root) {
1475-
trans = BTRFS_BACKREF_SEARCH_COMMIT_ROOT;
1476-
} else {
1486+
if (!search_commit_root) {
14771487
trans = btrfs_join_transaction(fs_info->extent_root);
14781488
if (IS_ERR(trans))
14791489
return PTR_ERR(trans);

‎fs/btrfs/backref.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include "ulist.h"
2424
#include "extent_io.h"
2525

26-
#define BTRFS_BACKREF_SEARCH_COMMIT_ROOT ((struct btrfs_trans_handle *)0)
27-
2826
struct inode_fs_paths {
2927
struct btrfs_path *btrfs_path;
3028
struct btrfs_root *fs_root;

0 commit comments

Comments
 (0)