Skip to content

Commit 7f67152

Browse files
committed
Merge branch 'misc-4.6' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux into for-linus-4.6
2 parents 232cad8 + 7ccefb9 commit 7f67152

File tree

8 files changed

+166
-33
lines changed

8 files changed

+166
-33
lines changed

fs/btrfs/ctree.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/sched.h>
2020
#include <linux/slab.h>
2121
#include <linux/rbtree.h>
22+
#include <linux/vmalloc.h>
2223
#include "ctree.h"
2324
#include "disk-io.h"
2425
#include "transaction.h"
@@ -5361,10 +5362,13 @@ int btrfs_compare_trees(struct btrfs_root *left_root,
53615362
goto out;
53625363
}
53635364

5364-
tmp_buf = kmalloc(left_root->nodesize, GFP_KERNEL);
5365+
tmp_buf = kmalloc(left_root->nodesize, GFP_KERNEL | __GFP_NOWARN);
53655366
if (!tmp_buf) {
5366-
ret = -ENOMEM;
5367-
goto out;
5367+
tmp_buf = vmalloc(left_root->nodesize);
5368+
if (!tmp_buf) {
5369+
ret = -ENOMEM;
5370+
goto out;
5371+
}
53685372
}
53695373

53705374
left_path->search_commit_root = 1;
@@ -5565,7 +5569,7 @@ int btrfs_compare_trees(struct btrfs_root *left_root,
55655569
out:
55665570
btrfs_free_path(left_path);
55675571
btrfs_free_path(right_path);
5568-
kfree(tmp_buf);
5572+
kvfree(tmp_buf);
55695573
return ret;
55705574
}
55715575

fs/btrfs/dev-replace.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
394394
dev_replace->cursor_right = 0;
395395
dev_replace->is_valid = 1;
396396
dev_replace->item_needs_writeback = 1;
397+
atomic64_set(&dev_replace->num_write_errors, 0);
398+
atomic64_set(&dev_replace->num_uncorrectable_read_errors, 0);
397399
args->result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;
398400
btrfs_dev_replace_unlock(dev_replace, 1);
399401

fs/btrfs/extent-tree.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9386,15 +9386,23 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
93869386
u64 dev_min = 1;
93879387
u64 dev_nr = 0;
93889388
u64 target;
9389+
int debug;
93899390
int index;
93909391
int full = 0;
93919392
int ret = 0;
93929393

9394+
debug = btrfs_test_opt(root, ENOSPC_DEBUG);
9395+
93939396
block_group = btrfs_lookup_block_group(root->fs_info, bytenr);
93949397

93959398
/* odd, couldn't find the block group, leave it alone */
9396-
if (!block_group)
9399+
if (!block_group) {
9400+
if (debug)
9401+
btrfs_warn(root->fs_info,
9402+
"can't find block group for bytenr %llu",
9403+
bytenr);
93979404
return -1;
9405+
}
93989406

93999407
min_free = btrfs_block_group_used(&block_group->item);
94009408

@@ -9448,8 +9456,13 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
94489456
* this is just a balance, so if we were marked as full
94499457
* we know there is no space for a new chunk
94509458
*/
9451-
if (full)
9459+
if (full) {
9460+
if (debug)
9461+
btrfs_warn(root->fs_info,
9462+
"no space to alloc new chunk for block group %llu",
9463+
block_group->key.objectid);
94529464
goto out;
9465+
}
94539466

94549467
index = get_block_group_index(block_group);
94559468
}
@@ -9496,6 +9509,10 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
94969509
ret = -1;
94979510
}
94989511
}
9512+
if (debug && ret == -1)
9513+
btrfs_warn(root->fs_info,
9514+
"no space to allocate a new chunk for block group %llu",
9515+
block_group->key.objectid);
94999516
mutex_unlock(&root->fs_info->chunk_mutex);
95009517
btrfs_end_transaction(trans, root);
95019518
out:

fs/btrfs/file.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,9 +2682,12 @@ static long btrfs_fallocate(struct file *file, int mode,
26822682
return ret;
26832683

26842684
inode_lock(inode);
2685-
ret = inode_newsize_ok(inode, alloc_end);
2686-
if (ret)
2687-
goto out;
2685+
2686+
if (!(mode & FALLOC_FL_KEEP_SIZE) && offset + len > inode->i_size) {
2687+
ret = inode_newsize_ok(inode, offset + len);
2688+
if (ret)
2689+
goto out;
2690+
}
26882691

26892692
/*
26902693
* TODO: Move these two operations after we have checked

fs/btrfs/ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,7 @@ static noinline int btrfs_ioctl_snap_create_transid(struct file *file,
16541654

16551655
src_inode = file_inode(src.file);
16561656
if (src_inode->i_sb != file_inode(file)->i_sb) {
1657-
btrfs_info(BTRFS_I(src_inode)->root->fs_info,
1657+
btrfs_info(BTRFS_I(file_inode(file))->root->fs_info,
16581658
"Snapshot src from another FS");
16591659
ret = -EXDEV;
16601660
} else if (!inode_owner_or_capable(src_inode)) {

fs/btrfs/qgroup.c

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@ struct btrfs_qgroup_extent_record
14631463
u64 bytenr = record->bytenr;
14641464

14651465
assert_spin_locked(&delayed_refs->lock);
1466+
trace_btrfs_qgroup_insert_dirty_extent(record);
14661467

14671468
while (*p) {
14681469
parent_node = *p;
@@ -1594,6 +1595,9 @@ static int qgroup_update_counters(struct btrfs_fs_info *fs_info,
15941595
cur_old_count = btrfs_qgroup_get_old_refcnt(qg, seq);
15951596
cur_new_count = btrfs_qgroup_get_new_refcnt(qg, seq);
15961597

1598+
trace_qgroup_update_counters(qg->qgroupid, cur_old_count,
1599+
cur_new_count);
1600+
15971601
/* Rfer update part */
15981602
if (cur_old_count == 0 && cur_new_count > 0) {
15991603
qg->rfer += num_bytes;
@@ -1683,6 +1687,9 @@ btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans,
16831687
goto out_free;
16841688
BUG_ON(!fs_info->quota_root);
16851689

1690+
trace_btrfs_qgroup_account_extent(bytenr, num_bytes, nr_old_roots,
1691+
nr_new_roots);
1692+
16861693
qgroups = ulist_alloc(GFP_NOFS);
16871694
if (!qgroups) {
16881695
ret = -ENOMEM;
@@ -1752,6 +1759,8 @@ int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans,
17521759
record = rb_entry(node, struct btrfs_qgroup_extent_record,
17531760
node);
17541761

1762+
trace_btrfs_qgroup_account_extents(record);
1763+
17551764
if (!ret) {
17561765
/*
17571766
* Use (u64)-1 as time_seq to do special search, which
@@ -1842,8 +1851,10 @@ int btrfs_run_qgroups(struct btrfs_trans_handle *trans,
18421851
}
18431852

18441853
/*
1845-
* copy the acounting information between qgroups. This is necessary when a
1846-
* snapshot or a subvolume is created
1854+
* Copy the acounting information between qgroups. This is necessary
1855+
* when a snapshot or a subvolume is created. Throwing an error will
1856+
* cause a transaction abort so we take extra care here to only error
1857+
* when a readonly fs is a reasonable outcome.
18471858
*/
18481859
int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
18491860
struct btrfs_fs_info *fs_info, u64 srcid, u64 objectid,
@@ -1873,15 +1884,15 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
18731884
2 * inherit->num_excl_copies;
18741885
for (i = 0; i < nums; ++i) {
18751886
srcgroup = find_qgroup_rb(fs_info, *i_qgroups);
1876-
if (!srcgroup) {
1877-
ret = -EINVAL;
1878-
goto out;
1879-
}
18801887

1881-
if ((srcgroup->qgroupid >> 48) <= (objectid >> 48)) {
1882-
ret = -EINVAL;
1883-
goto out;
1884-
}
1888+
/*
1889+
* Zero out invalid groups so we can ignore
1890+
* them later.
1891+
*/
1892+
if (!srcgroup ||
1893+
((srcgroup->qgroupid >> 48) <= (objectid >> 48)))
1894+
*i_qgroups = 0ULL;
1895+
18851896
++i_qgroups;
18861897
}
18871898
}
@@ -1916,17 +1927,19 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
19161927
*/
19171928
if (inherit) {
19181929
i_qgroups = (u64 *)(inherit + 1);
1919-
for (i = 0; i < inherit->num_qgroups; ++i) {
1930+
for (i = 0; i < inherit->num_qgroups; ++i, ++i_qgroups) {
1931+
if (*i_qgroups == 0)
1932+
continue;
19201933
ret = add_qgroup_relation_item(trans, quota_root,
19211934
objectid, *i_qgroups);
1922-
if (ret)
1935+
if (ret && ret != -EEXIST)
19231936
goto out;
19241937
ret = add_qgroup_relation_item(trans, quota_root,
19251938
*i_qgroups, objectid);
1926-
if (ret)
1939+
if (ret && ret != -EEXIST)
19271940
goto out;
1928-
++i_qgroups;
19291941
}
1942+
ret = 0;
19301943
}
19311944

19321945

@@ -1987,17 +2000,22 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
19872000

19882001
i_qgroups = (u64 *)(inherit + 1);
19892002
for (i = 0; i < inherit->num_qgroups; ++i) {
1990-
ret = add_relation_rb(quota_root->fs_info, objectid,
1991-
*i_qgroups);
1992-
if (ret)
1993-
goto unlock;
2003+
if (*i_qgroups) {
2004+
ret = add_relation_rb(quota_root->fs_info, objectid,
2005+
*i_qgroups);
2006+
if (ret)
2007+
goto unlock;
2008+
}
19942009
++i_qgroups;
19952010
}
19962011

1997-
for (i = 0; i < inherit->num_ref_copies; ++i) {
2012+
for (i = 0; i < inherit->num_ref_copies; ++i, i_qgroups += 2) {
19982013
struct btrfs_qgroup *src;
19992014
struct btrfs_qgroup *dst;
20002015

2016+
if (!i_qgroups[0] || !i_qgroups[1])
2017+
continue;
2018+
20012019
src = find_qgroup_rb(fs_info, i_qgroups[0]);
20022020
dst = find_qgroup_rb(fs_info, i_qgroups[1]);
20032021

@@ -2008,12 +2026,14 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
20082026

20092027
dst->rfer = src->rfer - level_size;
20102028
dst->rfer_cmpr = src->rfer_cmpr - level_size;
2011-
i_qgroups += 2;
20122029
}
2013-
for (i = 0; i < inherit->num_excl_copies; ++i) {
2030+
for (i = 0; i < inherit->num_excl_copies; ++i, i_qgroups += 2) {
20142031
struct btrfs_qgroup *src;
20152032
struct btrfs_qgroup *dst;
20162033

2034+
if (!i_qgroups[0] || !i_qgroups[1])
2035+
continue;
2036+
20172037
src = find_qgroup_rb(fs_info, i_qgroups[0]);
20182038
dst = find_qgroup_rb(fs_info, i_qgroups[1]);
20192039

@@ -2024,7 +2044,6 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
20242044

20252045
dst->excl = src->excl + level_size;
20262046
dst->excl_cmpr = src->excl_cmpr + level_size;
2027-
i_qgroups += 2;
20282047
}
20292048

20302049
unlock:

fs/btrfs/relocation.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,7 @@ int replace_path(struct btrfs_trans_handle *trans,
18501850
eb = read_tree_block(dest, old_bytenr, old_ptr_gen);
18511851
if (IS_ERR(eb)) {
18521852
ret = PTR_ERR(eb);
1853+
break;
18531854
} else if (!extent_buffer_uptodate(eb)) {
18541855
ret = -EIO;
18551856
free_extent_buffer(eb);

include/trace/events/btrfs.h

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct map_lookup;
2323
struct extent_buffer;
2424
struct btrfs_work;
2525
struct __btrfs_workqueue;
26-
struct btrfs_qgroup_operation;
26+
struct btrfs_qgroup_extent_record;
2727

2828
#define show_ref_type(type) \
2929
__print_symbolic(type, \
@@ -1231,6 +1231,93 @@ DEFINE_EVENT(btrfs__qgroup_delayed_ref, btrfs_qgroup_free_delayed_ref,
12311231

12321232
TP_ARGS(ref_root, reserved)
12331233
);
1234+
1235+
DECLARE_EVENT_CLASS(btrfs_qgroup_extent,
1236+
TP_PROTO(struct btrfs_qgroup_extent_record *rec),
1237+
1238+
TP_ARGS(rec),
1239+
1240+
TP_STRUCT__entry(
1241+
__field( u64, bytenr )
1242+
__field( u64, num_bytes )
1243+
),
1244+
1245+
TP_fast_assign(
1246+
__entry->bytenr = rec->bytenr,
1247+
__entry->num_bytes = rec->num_bytes;
1248+
),
1249+
1250+
TP_printk("bytenr = %llu, num_bytes = %llu",
1251+
(unsigned long long)__entry->bytenr,
1252+
(unsigned long long)__entry->num_bytes)
1253+
);
1254+
1255+
DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_account_extents,
1256+
1257+
TP_PROTO(struct btrfs_qgroup_extent_record *rec),
1258+
1259+
TP_ARGS(rec)
1260+
);
1261+
1262+
DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_insert_dirty_extent,
1263+
1264+
TP_PROTO(struct btrfs_qgroup_extent_record *rec),
1265+
1266+
TP_ARGS(rec)
1267+
);
1268+
1269+
TRACE_EVENT(btrfs_qgroup_account_extent,
1270+
1271+
TP_PROTO(u64 bytenr, u64 num_bytes, u64 nr_old_roots, u64 nr_new_roots),
1272+
1273+
TP_ARGS(bytenr, num_bytes, nr_old_roots, nr_new_roots),
1274+
1275+
TP_STRUCT__entry(
1276+
__field( u64, bytenr )
1277+
__field( u64, num_bytes )
1278+
__field( u64, nr_old_roots )
1279+
__field( u64, nr_new_roots )
1280+
),
1281+
1282+
TP_fast_assign(
1283+
__entry->bytenr = bytenr;
1284+
__entry->num_bytes = num_bytes;
1285+
__entry->nr_old_roots = nr_old_roots;
1286+
__entry->nr_new_roots = nr_new_roots;
1287+
),
1288+
1289+
TP_printk("bytenr = %llu, num_bytes = %llu, nr_old_roots = %llu, "
1290+
"nr_new_roots = %llu",
1291+
__entry->bytenr,
1292+
__entry->num_bytes,
1293+
__entry->nr_old_roots,
1294+
__entry->nr_new_roots)
1295+
);
1296+
1297+
TRACE_EVENT(qgroup_update_counters,
1298+
1299+
TP_PROTO(u64 qgid, u64 cur_old_count, u64 cur_new_count),
1300+
1301+
TP_ARGS(qgid, cur_old_count, cur_new_count),
1302+
1303+
TP_STRUCT__entry(
1304+
__field( u64, qgid )
1305+
__field( u64, cur_old_count )
1306+
__field( u64, cur_new_count )
1307+
),
1308+
1309+
TP_fast_assign(
1310+
__entry->qgid = qgid;
1311+
__entry->cur_old_count = cur_old_count;
1312+
__entry->cur_new_count = cur_new_count;
1313+
),
1314+
1315+
TP_printk("qgid = %llu, cur_old_count = %llu, cur_new_count = %llu",
1316+
__entry->qgid,
1317+
__entry->cur_old_count,
1318+
__entry->cur_new_count)
1319+
);
1320+
12341321
#endif /* _TRACE_BTRFS_H */
12351322

12361323
/* This part must be outside protection */

0 commit comments

Comments
 (0)