Skip to content

Commit 9613beb

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs fixes and features from Chris Mason: "We've merged in the error handling patches from SuSE. These are already shipping in the sles kernel, and they give btrfs the ability to abort transactions and go readonly on errors. It involves a lot of churn as they clarify BUG_ONs, and remove the ones we now properly deal with. Josef reworked the way our metadata interacts with the page cache. page->private now points to the btrfs extent_buffer object, which makes everything faster. He changed it so we write an whole extent buffer at a time instead of allowing individual pages to go down,, which will be important for the raid5/6 code (for the 3.5 merge window ;) Josef also made us more aggressive about dropping pages for metadata blocks that were freed due to COW. Overall, our metadata caching is much faster now. We've integrated my patch for metadata bigger than the page size. This allows metadata blocks up to 64KB in size. In practice 16K and 32K seem to work best. For workloads with lots of metadata, this cuts down the size of the extent allocation tree dramatically and fragments much less. Scrub was updated to support the larger block sizes, which ended up being a fairly large change (thanks Stefan Behrens). We also have an assortment of fixes and updates, especially to the balancing code (Ilya Dryomov), the back ref walker (Jan Schmidt) and the defragging code (Liu Bo)." Fixed up trivial conflicts in fs/btrfs/scrub.c that were just due to removal of the second argument to k[un]map_atomic() in commit 7ac687d. * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (75 commits) Btrfs: update the checks for mixed block groups with big metadata blocks Btrfs: update to the right index of defragment Btrfs: do not bother to defrag an extent if it is a big real extent Btrfs: add a check to decide if we should defrag the range Btrfs: fix recursive defragment with autodefrag option Btrfs: fix the mismatch of page->mapping Btrfs: fix race between direct io and autodefrag Btrfs: fix deadlock during allocating chunks Btrfs: show useful info in space reservation tracepoint Btrfs: don't use crc items bigger than 4KB Btrfs: flush out and clean up any block device pages during mount btrfs: disallow unequal data/metadata blocksize for mixed block groups Btrfs: enhance superblock sanity checks Btrfs: change scrub to support big blocks Btrfs: minor cleanup in scrub Btrfs: introduce common define for max number of mirrors Btrfs: fix infinite loop in btrfs_shrink_device() Btrfs: fix memory leak in resolver code Btrfs: allow dup for data chunks in mixed mode Btrfs: validate target profiles only if we are going to use them ...
2 parents 40380f1 + bc3f116 commit 9613beb

42 files changed

Lines changed: 4406 additions & 2225 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/async-thread.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ static void check_pending_worker_creates(struct btrfs_worker_thread *worker)
171171
spin_unlock_irqrestore(&workers->lock, flags);
172172
}
173173

174-
static noinline int run_ordered_completions(struct btrfs_workers *workers,
174+
static noinline void run_ordered_completions(struct btrfs_workers *workers,
175175
struct btrfs_work *work)
176176
{
177177
if (!workers->ordered)
178-
return 0;
178+
return;
179179

180180
set_bit(WORK_DONE_BIT, &work->flags);
181181

@@ -213,7 +213,6 @@ static noinline int run_ordered_completions(struct btrfs_workers *workers,
213213
}
214214

215215
spin_unlock(&workers->order_lock);
216-
return 0;
217216
}
218217

219218
static void put_worker(struct btrfs_worker_thread *worker)
@@ -399,7 +398,7 @@ static int worker_loop(void *arg)
399398
/*
400399
* this will wait for all the worker threads to shutdown
401400
*/
402-
int btrfs_stop_workers(struct btrfs_workers *workers)
401+
void btrfs_stop_workers(struct btrfs_workers *workers)
403402
{
404403
struct list_head *cur;
405404
struct btrfs_worker_thread *worker;
@@ -427,7 +426,6 @@ int btrfs_stop_workers(struct btrfs_workers *workers)
427426
put_worker(worker);
428427
}
429428
spin_unlock_irq(&workers->lock);
430-
return 0;
431429
}
432430

433431
/*
@@ -615,14 +613,14 @@ static struct btrfs_worker_thread *find_worker(struct btrfs_workers *workers)
615613
* it was taken from. It is intended for use with long running work functions
616614
* that make some progress and want to give the cpu up for others.
617615
*/
618-
int btrfs_requeue_work(struct btrfs_work *work)
616+
void btrfs_requeue_work(struct btrfs_work *work)
619617
{
620618
struct btrfs_worker_thread *worker = work->worker;
621619
unsigned long flags;
622620
int wake = 0;
623621

624622
if (test_and_set_bit(WORK_QUEUED_BIT, &work->flags))
625-
goto out;
623+
return;
626624

627625
spin_lock_irqsave(&worker->lock, flags);
628626
if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags))
@@ -649,9 +647,6 @@ int btrfs_requeue_work(struct btrfs_work *work)
649647
if (wake)
650648
wake_up_process(worker->task);
651649
spin_unlock_irqrestore(&worker->lock, flags);
652-
out:
653-
654-
return 0;
655650
}
656651

657652
void btrfs_set_work_high_prio(struct btrfs_work *work)

‎fs/btrfs/async-thread.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ struct btrfs_workers {
111111

112112
void btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work);
113113
int btrfs_start_workers(struct btrfs_workers *workers);
114-
int btrfs_stop_workers(struct btrfs_workers *workers);
114+
void btrfs_stop_workers(struct btrfs_workers *workers);
115115
void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max,
116116
struct btrfs_workers *async_starter);
117-
int btrfs_requeue_work(struct btrfs_work *work);
117+
void btrfs_requeue_work(struct btrfs_work *work);
118118
void btrfs_set_work_high_prio(struct btrfs_work *work);
119119
#endif

‎fs/btrfs/backref.c‎

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
116116
* to a logical address
117117
*/
118118
static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
119+
int search_commit_root,
119120
struct __prelim_ref *ref,
120121
struct ulist *parents)
121122
{
@@ -131,6 +132,7 @@ static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
131132
path = btrfs_alloc_path();
132133
if (!path)
133134
return -ENOMEM;
135+
path->search_commit_root = !!search_commit_root;
134136

135137
root_key.objectid = ref->root_id;
136138
root_key.type = BTRFS_ROOT_ITEM_KEY;
@@ -188,6 +190,7 @@ static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
188190
* resolve all indirect backrefs from the list
189191
*/
190192
static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
193+
int search_commit_root,
191194
struct list_head *head)
192195
{
193196
int err;
@@ -212,7 +215,8 @@ static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
212215
continue;
213216
if (ref->count == 0)
214217
continue;
215-
err = __resolve_indirect_ref(fs_info, ref, parents);
218+
err = __resolve_indirect_ref(fs_info, search_commit_root,
219+
ref, parents);
216220
if (err) {
217221
if (ret == 0)
218222
ret = err;
@@ -586,6 +590,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
586590
struct btrfs_delayed_ref_head *head;
587591
int info_level = 0;
588592
int ret;
593+
int search_commit_root = (trans == BTRFS_BACKREF_SEARCH_COMMIT_ROOT);
589594
struct list_head prefs_delayed;
590595
struct list_head prefs;
591596
struct __prelim_ref *ref;
@@ -600,6 +605,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
600605
path = btrfs_alloc_path();
601606
if (!path)
602607
return -ENOMEM;
608+
path->search_commit_root = !!search_commit_root;
603609

604610
/*
605611
* grab both a lock on the path and a lock on the delayed ref head.
@@ -614,35 +620,39 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
614620
goto out;
615621
BUG_ON(ret == 0);
616622

617-
/*
618-
* look if there are updates for this ref queued and lock the head
619-
*/
620-
delayed_refs = &trans->transaction->delayed_refs;
621-
spin_lock(&delayed_refs->lock);
622-
head = btrfs_find_delayed_ref_head(trans, bytenr);
623-
if (head) {
624-
if (!mutex_trylock(&head->mutex)) {
625-
atomic_inc(&head->node.refs);
626-
spin_unlock(&delayed_refs->lock);
627-
628-
btrfs_release_path(path);
629-
630-
/*
631-
* Mutex was contended, block until it's
632-
* released and try again
633-
*/
634-
mutex_lock(&head->mutex);
635-
mutex_unlock(&head->mutex);
636-
btrfs_put_delayed_ref(&head->node);
637-
goto again;
638-
}
639-
ret = __add_delayed_refs(head, seq, &info_key, &prefs_delayed);
640-
if (ret) {
641-
spin_unlock(&delayed_refs->lock);
642-
goto out;
623+
if (trans != BTRFS_BACKREF_SEARCH_COMMIT_ROOT) {
624+
/*
625+
* look if there are updates for this ref queued and lock the
626+
* head
627+
*/
628+
delayed_refs = &trans->transaction->delayed_refs;
629+
spin_lock(&delayed_refs->lock);
630+
head = btrfs_find_delayed_ref_head(trans, bytenr);
631+
if (head) {
632+
if (!mutex_trylock(&head->mutex)) {
633+
atomic_inc(&head->node.refs);
634+
spin_unlock(&delayed_refs->lock);
635+
636+
btrfs_release_path(path);
637+
638+
/*
639+
* Mutex was contended, block until it's
640+
* released and try again
641+
*/
642+
mutex_lock(&head->mutex);
643+
mutex_unlock(&head->mutex);
644+
btrfs_put_delayed_ref(&head->node);
645+
goto again;
646+
}
647+
ret = __add_delayed_refs(head, seq, &info_key,
648+
&prefs_delayed);
649+
if (ret) {
650+
spin_unlock(&delayed_refs->lock);
651+
goto out;
652+
}
643653
}
654+
spin_unlock(&delayed_refs->lock);
644655
}
645-
spin_unlock(&delayed_refs->lock);
646656

647657
if (path->slots[0]) {
648658
struct extent_buffer *leaf;
@@ -679,7 +689,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
679689
if (ret)
680690
goto out;
681691

682-
ret = __resolve_indirect_refs(fs_info, &prefs);
692+
ret = __resolve_indirect_refs(fs_info, search_commit_root, &prefs);
683693
if (ret)
684694
goto out;
685695

@@ -1074,8 +1084,7 @@ int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
10741084
return 0;
10751085
}
10761086

1077-
static int iterate_leaf_refs(struct btrfs_fs_info *fs_info,
1078-
struct btrfs_path *path, u64 logical,
1087+
static int iterate_leaf_refs(struct btrfs_fs_info *fs_info, u64 logical,
10791088
u64 orig_extent_item_objectid,
10801089
u64 extent_item_pos, u64 root,
10811090
iterate_extent_inodes_t *iterate, void *ctx)
@@ -1143,35 +1152,38 @@ static int iterate_leaf_refs(struct btrfs_fs_info *fs_info,
11431152
* calls iterate() for every inode that references the extent identified by
11441153
* the given parameters.
11451154
* when the iterator function returns a non-zero value, iteration stops.
1146-
* path is guaranteed to be in released state when iterate() is called.
11471155
*/
11481156
int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
1149-
struct btrfs_path *path,
11501157
u64 extent_item_objectid, u64 extent_item_pos,
1158+
int search_commit_root,
11511159
iterate_extent_inodes_t *iterate, void *ctx)
11521160
{
11531161
int ret;
11541162
struct list_head data_refs = LIST_HEAD_INIT(data_refs);
11551163
struct list_head shared_refs = LIST_HEAD_INIT(shared_refs);
11561164
struct btrfs_trans_handle *trans;
1157-
struct ulist *refs;
1158-
struct ulist *roots;
1165+
struct ulist *refs = NULL;
1166+
struct ulist *roots = NULL;
11591167
struct ulist_node *ref_node = NULL;
11601168
struct ulist_node *root_node = NULL;
11611169
struct seq_list seq_elem;
1162-
struct btrfs_delayed_ref_root *delayed_refs;
1163-
1164-
trans = btrfs_join_transaction(fs_info->extent_root);
1165-
if (IS_ERR(trans))
1166-
return PTR_ERR(trans);
1170+
struct btrfs_delayed_ref_root *delayed_refs = NULL;
11671171

11681172
pr_debug("resolving all inodes for extent %llu\n",
11691173
extent_item_objectid);
11701174

1171-
delayed_refs = &trans->transaction->delayed_refs;
1172-
spin_lock(&delayed_refs->lock);
1173-
btrfs_get_delayed_seq(delayed_refs, &seq_elem);
1174-
spin_unlock(&delayed_refs->lock);
1175+
if (search_commit_root) {
1176+
trans = BTRFS_BACKREF_SEARCH_COMMIT_ROOT;
1177+
} else {
1178+
trans = btrfs_join_transaction(fs_info->extent_root);
1179+
if (IS_ERR(trans))
1180+
return PTR_ERR(trans);
1181+
1182+
delayed_refs = &trans->transaction->delayed_refs;
1183+
spin_lock(&delayed_refs->lock);
1184+
btrfs_get_delayed_seq(delayed_refs, &seq_elem);
1185+
spin_unlock(&delayed_refs->lock);
1186+
}
11751187

11761188
ret = btrfs_find_all_leafs(trans, fs_info, extent_item_objectid,
11771189
extent_item_pos, seq_elem.seq,
@@ -1188,7 +1200,7 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
11881200
while (!ret && (root_node = ulist_next(roots, root_node))) {
11891201
pr_debug("root %llu references leaf %llu\n",
11901202
root_node->val, ref_node->val);
1191-
ret = iterate_leaf_refs(fs_info, path, ref_node->val,
1203+
ret = iterate_leaf_refs(fs_info, ref_node->val,
11921204
extent_item_objectid,
11931205
extent_item_pos, root_node->val,
11941206
iterate, ctx);
@@ -1198,8 +1210,11 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
11981210
ulist_free(refs);
11991211
ulist_free(roots);
12001212
out:
1201-
btrfs_put_delayed_seq(delayed_refs, &seq_elem);
1202-
btrfs_end_transaction(trans, fs_info->extent_root);
1213+
if (!search_commit_root) {
1214+
btrfs_put_delayed_seq(delayed_refs, &seq_elem);
1215+
btrfs_end_transaction(trans, fs_info->extent_root);
1216+
}
1217+
12031218
return ret;
12041219
}
12051220

@@ -1210,6 +1225,7 @@ int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
12101225
int ret;
12111226
u64 extent_item_pos;
12121227
struct btrfs_key found_key;
1228+
int search_commit_root = path->search_commit_root;
12131229

12141230
ret = extent_from_logical(fs_info, logical, path,
12151231
&found_key);
@@ -1220,8 +1236,9 @@ int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
12201236
return ret;
12211237

12221238
extent_item_pos = logical - found_key.objectid;
1223-
ret = iterate_extent_inodes(fs_info, path, found_key.objectid,
1224-
extent_item_pos, iterate, ctx);
1239+
ret = iterate_extent_inodes(fs_info, found_key.objectid,
1240+
extent_item_pos, search_commit_root,
1241+
iterate, ctx);
12251242

12261243
return ret;
12271244
}
@@ -1342,12 +1359,6 @@ int paths_from_inode(u64 inum, struct inode_fs_paths *ipath)
13421359
inode_to_path, ipath);
13431360
}
13441361

1345-
/*
1346-
* allocates space to return multiple file system paths for an inode.
1347-
* total_bytes to allocate are passed, note that space usable for actual path
1348-
* information will be total_bytes - sizeof(struct inode_fs_paths).
1349-
* the returned pointer must be freed with free_ipath() in the end.
1350-
*/
13511362
struct btrfs_data_container *init_data_container(u32 total_bytes)
13521363
{
13531364
struct btrfs_data_container *data;
@@ -1403,5 +1414,6 @@ struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root,
14031414

14041415
void free_ipath(struct inode_fs_paths *ipath)
14051416
{
1417+
kfree(ipath->fspath);
14061418
kfree(ipath);
14071419
}

‎fs/btrfs/backref.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "ioctl.h"
2323
#include "ulist.h"
2424

25+
#define BTRFS_BACKREF_SEARCH_COMMIT_ROOT ((struct btrfs_trans_handle *)0)
26+
2527
struct inode_fs_paths {
2628
struct btrfs_path *btrfs_path;
2729
struct btrfs_root *fs_root;
@@ -44,9 +46,8 @@ int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
4446
u64 *out_root, u8 *out_level);
4547

4648
int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
47-
struct btrfs_path *path,
4849
u64 extent_item_objectid,
49-
u64 extent_offset,
50+
u64 extent_offset, int search_commit_root,
5051
iterate_extent_inodes_t *iterate, void *ctx);
5152

5253
int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,

0 commit comments

Comments
 (0)