Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs

Pull btrfs fixes from Chris Mason:
"This has our collection of bug fixes. I missed the last rc because I
thought our patches were making NFS crash during my xfs test runs.
Turns out it was an NFS client bug fixed by someone else while I tried
to bisect it.

All of these fixes are small, but some are fairly high impact. The
biggest are fixes for our mount -o remount handling, a deadlock due to
GFP_KERNEL allocations in readdir, and a RAID10 error handling bug.

This was tested against both 3.3 and Linus' master as of this morning."

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (26 commits)
Btrfs: reduce lock contention during extent insertion
Btrfs: avoid deadlocks from GFP_KERNEL allocations during btrfs_real_readdir
Btrfs: Fix space checking during fs resize
Btrfs: fix block_rsv and space_info lock ordering
Btrfs: Prevent root_list corruption
Btrfs: fix repair code for RAID10
Btrfs: do not start delalloc inodes during sync
Btrfs: fix that check_int_data mount option was ignored
Btrfs: don't count CRC or header errors twice while scrubbing
Btrfs: fix btrfs_ioctl_dev_info() crash on missing device
btrfs: don't return EINTR
Btrfs: double unlock bug in error handling
Btrfs: always store the mirror we read the eb from
fs/btrfs/volumes.c: add missing free_fs_devices
btrfs: fix early abort in 'remount'
Btrfs: fix max chunk size check in chunk allocator
Btrfs: add missing read locks in backref.c
Btrfs: don't call free_extent_buffer twice in iterate_irefs
Btrfs: Make free_ipath() deal gracefully with NULL pointers
Btrfs: avoid possible use-after-free in clear_extent_bit()
...

+148 -139
+20 -7
fs/btrfs/backref.c
··· 22 22 #include "ulist.h" 23 23 #include "transaction.h" 24 24 #include "delayed-ref.h" 25 + #include "locking.h" 25 26 26 27 /* 27 28 * this structure records all encountered refs on the way up to the root ··· 894 893 s64 bytes_left = size - 1; 895 894 struct extent_buffer *eb = eb_in; 896 895 struct btrfs_key found_key; 896 + int leave_spinning = path->leave_spinning; 897 897 898 898 if (bytes_left >= 0) 899 899 dest[bytes_left] = '\0'; 900 900 901 + path->leave_spinning = 1; 901 902 while (1) { 902 903 len = btrfs_inode_ref_name_len(eb, iref); 903 904 bytes_left -= len; 904 905 if (bytes_left >= 0) 905 906 read_extent_buffer(eb, dest + bytes_left, 906 907 (unsigned long)(iref + 1), len); 907 - if (eb != eb_in) 908 + if (eb != eb_in) { 909 + btrfs_tree_read_unlock_blocking(eb); 908 910 free_extent_buffer(eb); 911 + } 909 912 ret = inode_ref_info(parent, 0, fs_root, path, &found_key); 910 913 if (ret > 0) 911 914 ret = -ENOENT; ··· 924 919 slot = path->slots[0]; 925 920 eb = path->nodes[0]; 926 921 /* make sure we can use eb after releasing the path */ 927 - if (eb != eb_in) 922 + if (eb != eb_in) { 928 923 atomic_inc(&eb->refs); 924 + btrfs_tree_read_lock(eb); 925 + btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); 926 + } 929 927 btrfs_release_path(path); 930 928 931 929 iref = btrfs_item_ptr(eb, slot, struct btrfs_inode_ref); ··· 939 931 } 940 932 941 933 btrfs_release_path(path); 934 + path->leave_spinning = leave_spinning; 942 935 943 936 if (ret) 944 937 return ERR_PTR(ret); ··· 1256 1247 struct btrfs_path *path, 1257 1248 iterate_irefs_t *iterate, void *ctx) 1258 1249 { 1259 - int ret; 1250 + int ret = 0; 1260 1251 int slot; 1261 1252 u32 cur; 1262 1253 u32 len; ··· 1268 1259 struct btrfs_inode_ref *iref; 1269 1260 struct btrfs_key found_key; 1270 1261 1271 - while (1) { 1262 + while (!ret) { 1263 + path->leave_spinning = 1; 1272 1264 ret = inode_ref_info(inum, parent ? parent+1 : 0, fs_root, path, 1273 1265 &found_key); 1274 1266 if (ret < 0) ··· 1285 1275 eb = path->nodes[0]; 1286 1276 /* make sure we can use eb after releasing the path */ 1287 1277 atomic_inc(&eb->refs); 1278 + btrfs_tree_read_lock(eb); 1279 + btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); 1288 1280 btrfs_release_path(path); 1289 1281 1290 1282 item = btrfs_item_nr(eb, slot); ··· 1300 1288 (unsigned long long)found_key.objectid, 1301 1289 (unsigned long long)fs_root->objectid); 1302 1290 ret = iterate(parent, iref, eb, ctx); 1303 - if (ret) { 1304 - free_extent_buffer(eb); 1291 + if (ret) 1305 1292 break; 1306 - } 1307 1293 len = sizeof(*iref) + name_len; 1308 1294 iref = (struct btrfs_inode_ref *)((char *)iref + len); 1309 1295 } 1296 + btrfs_tree_read_unlock_blocking(eb); 1310 1297 free_extent_buffer(eb); 1311 1298 } 1312 1299 ··· 1425 1414 1426 1415 void free_ipath(struct inode_fs_paths *ipath) 1427 1416 { 1417 + if (!ipath) 1418 + return; 1428 1419 kfree(ipath->fspath); 1429 1420 kfree(ipath); 1430 1421 }
+1 -1
fs/btrfs/ctree.h
··· 1078 1078 * is required instead of the faster short fsync log commits 1079 1079 */ 1080 1080 u64 last_trans_log_full_commit; 1081 - unsigned long mount_opt:21; 1081 + unsigned long mount_opt; 1082 1082 unsigned long compress_type:4; 1083 1083 u64 max_inline; 1084 1084 u64 alloc_start;
+11 -11
fs/btrfs/disk-io.c
··· 383 383 if (test_bit(EXTENT_BUFFER_CORRUPT, &eb->bflags)) 384 384 break; 385 385 386 - if (!failed_mirror) { 387 - failed = 1; 388 - printk(KERN_ERR "failed mirror was %d\n", eb->failed_mirror); 389 - failed_mirror = eb->failed_mirror; 390 - } 391 - 392 386 num_copies = btrfs_num_copies(&root->fs_info->mapping_tree, 393 387 eb->start, eb->len); 394 388 if (num_copies == 1) 395 389 break; 390 + 391 + if (!failed_mirror) { 392 + failed = 1; 393 + failed_mirror = eb->read_mirror; 394 + } 396 395 397 396 mirror_num++; 398 397 if (mirror_num == failed_mirror) ··· 563 564 } 564 565 565 566 static int btree_readpage_end_io_hook(struct page *page, u64 start, u64 end, 566 - struct extent_state *state) 567 + struct extent_state *state, int mirror) 567 568 { 568 569 struct extent_io_tree *tree; 569 570 u64 found_start; ··· 588 589 if (!reads_done) 589 590 goto err; 590 591 592 + eb->read_mirror = mirror; 591 593 if (test_bit(EXTENT_BUFFER_IOERR, &eb->bflags)) { 592 594 ret = -EIO; 593 595 goto err; ··· 652 652 653 653 eb = (struct extent_buffer *)page->private; 654 654 set_bit(EXTENT_BUFFER_IOERR, &eb->bflags); 655 - eb->failed_mirror = failed_mirror; 655 + eb->read_mirror = failed_mirror; 656 656 if (test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags)) 657 657 btree_readahead_hook(root, eb, eb->start, -EIO); 658 658 return -EIO; /* we fixed nothing */ ··· 2254 2254 goto fail_sb_buffer; 2255 2255 } 2256 2256 2257 - if (sectorsize < PAGE_SIZE) { 2258 - printk(KERN_WARNING "btrfs: Incompatible sector size " 2259 - "found on %s\n", sb->s_id); 2257 + if (sectorsize != PAGE_SIZE) { 2258 + printk(KERN_WARNING "btrfs: Incompatible sector size(%lu) " 2259 + "found on %s\n", (unsigned long)sectorsize, sb->s_id); 2260 2260 goto fail_sb_buffer; 2261 2261 } 2262 2262
+7 -8
fs/btrfs/extent-tree.c
··· 2301 2301 2302 2302 if (ret) { 2303 2303 printk(KERN_DEBUG "btrfs: run_delayed_extent_op returned %d\n", ret); 2304 + spin_lock(&delayed_refs->lock); 2304 2305 return ret; 2305 2306 } 2306 2307 ··· 2332 2331 2333 2332 if (ret) { 2334 2333 printk(KERN_DEBUG "btrfs: run_one_delayed_ref returned %d\n", ret); 2334 + spin_lock(&delayed_refs->lock); 2335 2335 return ret; 2336 2336 } 2337 2337 ··· 3771 3769 */ 3772 3770 if (current->journal_info) 3773 3771 return -EAGAIN; 3774 - ret = wait_event_interruptible(space_info->wait, 3775 - !space_info->flush); 3776 - /* Must have been interrupted, return */ 3777 - if (ret) { 3778 - printk(KERN_DEBUG "btrfs: %s returning -EINTR\n", __func__); 3772 + ret = wait_event_killable(space_info->wait, !space_info->flush); 3773 + /* Must have been killed, return */ 3774 + if (ret) 3779 3775 return -EINTR; 3780 - } 3781 3776 3782 3777 spin_lock(&space_info->lock); 3783 3778 } ··· 4214 4215 4215 4216 num_bytes = calc_global_metadata_size(fs_info); 4216 4217 4217 - spin_lock(&block_rsv->lock); 4218 4218 spin_lock(&sinfo->lock); 4219 + spin_lock(&block_rsv->lock); 4219 4220 4220 4221 block_rsv->size = num_bytes; 4221 4222 ··· 4241 4242 block_rsv->full = 1; 4242 4243 } 4243 4244 4244 - spin_unlock(&sinfo->lock); 4245 4245 spin_unlock(&block_rsv->lock); 4246 + spin_unlock(&sinfo->lock); 4246 4247 } 4247 4248 4248 4249 static void init_global_block_rsv(struct btrfs_fs_info *fs_info)
+28 -28
fs/btrfs/extent_io.c
··· 402 402 return 0; 403 403 } 404 404 405 + static struct extent_state *next_state(struct extent_state *state) 406 + { 407 + struct rb_node *next = rb_next(&state->rb_node); 408 + if (next) 409 + return rb_entry(next, struct extent_state, rb_node); 410 + else 411 + return NULL; 412 + } 413 + 405 414 /* 406 415 * utility function to clear some bits in an extent state struct. 407 - * it will optionally wake up any one waiting on this state (wake == 1), or 408 - * forcibly remove the state from the tree (delete == 1). 416 + * it will optionally wake up any one waiting on this state (wake == 1) 409 417 * 410 418 * If no bits are set on the state struct after clearing things, the 411 419 * struct is freed and removed from the tree 412 420 */ 413 - static int clear_state_bit(struct extent_io_tree *tree, 414 - struct extent_state *state, 415 - int *bits, int wake) 421 + static struct extent_state *clear_state_bit(struct extent_io_tree *tree, 422 + struct extent_state *state, 423 + int *bits, int wake) 416 424 { 425 + struct extent_state *next; 417 426 int bits_to_clear = *bits & ~EXTENT_CTLBITS; 418 - int ret = state->state & bits_to_clear; 419 427 420 428 if ((bits_to_clear & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) { 421 429 u64 range = state->end - state->start + 1; ··· 435 427 if (wake) 436 428 wake_up(&state->wq); 437 429 if (state->state == 0) { 430 + next = next_state(state); 438 431 if (state->tree) { 439 432 rb_erase(&state->rb_node, &tree->state); 440 433 state->tree = NULL; ··· 445 436 } 446 437 } else { 447 438 merge_state(tree, state); 439 + next = next_state(state); 448 440 } 449 - return ret; 441 + return next; 450 442 } 451 443 452 444 static struct extent_state * ··· 486 476 struct extent_state *state; 487 477 struct extent_state *cached; 488 478 struct extent_state *prealloc = NULL; 489 - struct rb_node *next_node; 490 479 struct rb_node *node; 491 480 u64 last_end; 492 481 int err; ··· 537 528 WARN_ON(state->end < start); 538 529 last_end = state->end; 539 530 540 - if (state->end < end && !need_resched()) 541 - next_node = rb_next(&state->rb_node); 542 - else 543 - next_node = NULL; 544 - 545 531 /* the state doesn't have the wanted bits, go ahead */ 546 - if (!(state->state & bits)) 532 + if (!(state->state & bits)) { 533 + state = next_state(state); 547 534 goto next; 535 + } 548 536 549 537 /* 550 538 * | ---- desired range ---- | ··· 599 593 goto out; 600 594 } 601 595 602 - clear_state_bit(tree, state, &bits, wake); 596 + state = clear_state_bit(tree, state, &bits, wake); 603 597 next: 604 598 if (last_end == (u64)-1) 605 599 goto out; 606 600 start = last_end + 1; 607 - if (start <= end && next_node) { 608 - state = rb_entry(next_node, struct extent_state, 609 - rb_node); 601 + if (start <= end && state && !need_resched()) 610 602 goto hit_next; 611 - } 612 603 goto search_again; 613 604 614 605 out: ··· 2304 2301 u64 start; 2305 2302 u64 end; 2306 2303 int whole_page; 2307 - int failed_mirror; 2304 + int mirror; 2308 2305 int ret; 2309 2306 2310 2307 if (err) ··· 2343 2340 } 2344 2341 spin_unlock(&tree->lock); 2345 2342 2343 + mirror = (int)(unsigned long)bio->bi_bdev; 2346 2344 if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) { 2347 2345 ret = tree->ops->readpage_end_io_hook(page, start, end, 2348 - state); 2346 + state, mirror); 2349 2347 if (ret) 2350 2348 uptodate = 0; 2351 2349 else 2352 2350 clean_io_failure(start, page); 2353 2351 } 2354 2352 2355 - if (!uptodate) 2356 - failed_mirror = (int)(unsigned long)bio->bi_bdev; 2357 - 2358 2353 if (!uptodate && tree->ops && tree->ops->readpage_io_failed_hook) { 2359 - ret = tree->ops->readpage_io_failed_hook(page, failed_mirror); 2354 + ret = tree->ops->readpage_io_failed_hook(page, mirror); 2360 2355 if (!ret && !err && 2361 2356 test_bit(BIO_UPTODATE, &bio->bi_flags)) 2362 2357 uptodate = 1; ··· 2369 2368 * can't handle the error it will return -EIO and we 2370 2369 * remain responsible for that page. 2371 2370 */ 2372 - ret = bio_readpage_error(bio, page, start, end, 2373 - failed_mirror, NULL); 2371 + ret = bio_readpage_error(bio, page, start, end, mirror, NULL); 2374 2372 if (ret == 0) { 2375 2373 uptodate = 2376 2374 test_bit(BIO_UPTODATE, &bio->bi_flags); ··· 4462 4462 } 4463 4463 4464 4464 clear_bit(EXTENT_BUFFER_IOERR, &eb->bflags); 4465 - eb->failed_mirror = 0; 4465 + eb->read_mirror = 0; 4466 4466 atomic_set(&eb->io_pages, num_reads); 4467 4467 for (i = start_i; i < num_pages; i++) { 4468 4468 page = extent_buffer_page(eb, i);
+2 -2
fs/btrfs/extent_io.h
··· 79 79 u64 start, u64 end, 80 80 struct extent_state *state); 81 81 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end, 82 - struct extent_state *state); 82 + struct extent_state *state, int mirror); 83 83 int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end, 84 84 struct extent_state *state, int uptodate); 85 85 void (*set_bit_hook)(struct inode *inode, struct extent_state *state, ··· 135 135 spinlock_t refs_lock; 136 136 atomic_t refs; 137 137 atomic_t io_pages; 138 - int failed_mirror; 138 + int read_mirror; 139 139 struct list_head leak_list; 140 140 struct rcu_head rcu_head; 141 141 pid_t lock_owner;
+7 -2
fs/btrfs/file.c
··· 567 567 int extent_type; 568 568 int recow; 569 569 int ret; 570 + int modify_tree = -1; 570 571 571 572 if (drop_cache) 572 573 btrfs_drop_extent_cache(inode, start, end - 1, 0); ··· 576 575 if (!path) 577 576 return -ENOMEM; 578 577 578 + if (start >= BTRFS_I(inode)->disk_i_size) 579 + modify_tree = 0; 580 + 579 581 while (1) { 580 582 recow = 0; 581 583 ret = btrfs_lookup_file_extent(trans, root, path, ino, 582 - search_start, -1); 584 + search_start, modify_tree); 583 585 if (ret < 0) 584 586 break; 585 587 if (ret > 0 && path->slots[0] > 0 && search_start == start) { ··· 638 634 } 639 635 640 636 search_start = max(key.offset, start); 641 - if (recow) { 637 + if (recow || !modify_tree) { 638 + modify_tree = -1; 642 639 btrfs_release_path(path); 643 640 continue; 644 641 }
+17 -35
fs/btrfs/inode.c
··· 1947 1947 * extent_io.c will try to find good copies for us. 1948 1948 */ 1949 1949 static int btrfs_readpage_end_io_hook(struct page *page, u64 start, u64 end, 1950 - struct extent_state *state) 1950 + struct extent_state *state, int mirror) 1951 1951 { 1952 1952 size_t offset = start - ((u64)page->index << PAGE_CACHE_SHIFT); 1953 1953 struct inode *inode = page->mapping->host; ··· 4069 4069 BTRFS_I(inode)->dummy_inode = 1; 4070 4070 4071 4071 inode->i_ino = BTRFS_EMPTY_SUBVOL_DIR_OBJECTID; 4072 - inode->i_op = &simple_dir_inode_operations; 4072 + inode->i_op = &btrfs_dir_ro_inode_operations; 4073 4073 inode->i_fop = &simple_dir_operations; 4074 4074 inode->i_mode = S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO; 4075 4075 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; ··· 4140 4140 static int btrfs_dentry_delete(const struct dentry *dentry) 4141 4141 { 4142 4142 struct btrfs_root *root; 4143 + struct inode *inode = dentry->d_inode; 4143 4144 4144 - if (!dentry->d_inode && !IS_ROOT(dentry)) 4145 - dentry = dentry->d_parent; 4145 + if (!inode && !IS_ROOT(dentry)) 4146 + inode = dentry->d_parent->d_inode; 4146 4147 4147 - if (dentry->d_inode) { 4148 - root = BTRFS_I(dentry->d_inode)->root; 4148 + if (inode) { 4149 + root = BTRFS_I(inode)->root; 4149 4150 if (btrfs_root_refs(&root->root_item) == 0) 4151 + return 1; 4152 + 4153 + if (btrfs_ino(inode) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID) 4150 4154 return 1; 4151 4155 } 4152 4156 return 0; ··· 4192 4188 struct btrfs_path *path; 4193 4189 struct list_head ins_list; 4194 4190 struct list_head del_list; 4195 - struct qstr q; 4196 4191 int ret; 4197 4192 struct extent_buffer *leaf; 4198 4193 int slot; ··· 4282 4279 4283 4280 while (di_cur < di_total) { 4284 4281 struct btrfs_key location; 4285 - struct dentry *tmp; 4286 4282 4287 4283 if (verify_dir_item(root, leaf, di)) 4288 4284 break; ··· 4302 4300 d_type = btrfs_filetype_table[btrfs_dir_type(leaf, di)]; 4303 4301 btrfs_dir_item_key_to_cpu(leaf, di, &location); 4304 4302 4305 - q.name = name_ptr; 4306 - q.len = name_len; 4307 - q.hash = full_name_hash(q.name, q.len); 4308 - tmp = d_lookup(filp->f_dentry, &q); 4309 - if (!tmp) { 4310 - struct btrfs_key *newkey; 4311 4303 4312 - newkey = kzalloc(sizeof(struct btrfs_key), 4313 - GFP_NOFS); 4314 - if (!newkey) 4315 - goto no_dentry; 4316 - tmp = d_alloc(filp->f_dentry, &q); 4317 - if (!tmp) { 4318 - kfree(newkey); 4319 - dput(tmp); 4320 - goto no_dentry; 4321 - } 4322 - memcpy(newkey, &location, 4323 - sizeof(struct btrfs_key)); 4324 - tmp->d_fsdata = newkey; 4325 - tmp->d_flags |= DCACHE_NEED_LOOKUP; 4326 - d_rehash(tmp); 4327 - dput(tmp); 4328 - } else { 4329 - dput(tmp); 4330 - } 4331 - no_dentry: 4332 4304 /* is this a reference to our own snapshot? If so 4333 - * skip it 4305 + * skip it. 4306 + * 4307 + * In contrast to old kernels, we insert the snapshot's 4308 + * dir item and dir index after it has been created, so 4309 + * we won't find a reference to our own snapshot. We 4310 + * still keep the following code for backward 4311 + * compatibility. 4334 4312 */ 4335 4313 if (location.type == BTRFS_ROOT_ITEM_KEY && 4336 4314 location.objectid == root->root_key.objectid) {
+4 -1
fs/btrfs/ioctl.c
··· 2262 2262 di_args->bytes_used = dev->bytes_used; 2263 2263 di_args->total_bytes = dev->total_bytes; 2264 2264 memcpy(di_args->uuid, dev->uuid, sizeof(di_args->uuid)); 2265 - strncpy(di_args->path, dev->name, sizeof(di_args->path)); 2265 + if (dev->name) 2266 + strncpy(di_args->path, dev->name, sizeof(di_args->path)); 2267 + else 2268 + di_args->path[0] = '\0'; 2266 2269 2267 2270 out: 2268 2271 if (ret == 0 && copy_to_user(arg, di_args, sizeof(*di_args)))
+30 -20
fs/btrfs/reada.c
··· 250 250 struct btrfs_bio *bbio) 251 251 { 252 252 int ret; 253 - int looped = 0; 254 253 struct reada_zone *zone; 255 254 struct btrfs_block_group_cache *cache = NULL; 256 255 u64 start; 257 256 u64 end; 258 257 int i; 259 258 260 - again: 261 259 zone = NULL; 262 260 spin_lock(&fs_info->reada_lock); 263 261 ret = radix_tree_gang_lookup(&dev->reada_zones, (void **)&zone, ··· 271 273 kref_put(&zone->refcnt, reada_zone_release); 272 274 spin_unlock(&fs_info->reada_lock); 273 275 } 274 - 275 - if (looped) 276 - return NULL; 277 276 278 277 cache = btrfs_lookup_block_group(fs_info, logical); 279 278 if (!cache) ··· 302 307 ret = radix_tree_insert(&dev->reada_zones, 303 308 (unsigned long)(zone->end >> PAGE_CACHE_SHIFT), 304 309 zone); 305 - spin_unlock(&fs_info->reada_lock); 306 310 307 - if (ret) { 311 + if (ret == -EEXIST) { 308 312 kfree(zone); 309 - looped = 1; 310 - goto again; 313 + ret = radix_tree_gang_lookup(&dev->reada_zones, (void **)&zone, 314 + logical >> PAGE_CACHE_SHIFT, 1); 315 + if (ret == 1) 316 + kref_get(&zone->refcnt); 311 317 } 318 + spin_unlock(&fs_info->reada_lock); 312 319 313 320 return zone; 314 321 } ··· 320 323 struct btrfs_key *top, int level) 321 324 { 322 325 int ret; 323 - int looped = 0; 324 326 struct reada_extent *re = NULL; 327 + struct reada_extent *re_exist = NULL; 325 328 struct btrfs_fs_info *fs_info = root->fs_info; 326 329 struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree; 327 330 struct btrfs_bio *bbio = NULL; 328 331 struct btrfs_device *dev; 332 + struct btrfs_device *prev_dev; 329 333 u32 blocksize; 330 334 u64 length; 331 335 int nzones = 0; 332 336 int i; 333 337 unsigned long index = logical >> PAGE_CACHE_SHIFT; 334 338 335 - again: 336 339 spin_lock(&fs_info->reada_lock); 337 340 re = radix_tree_lookup(&fs_info->reada_tree, index); 338 341 if (re) 339 342 kref_get(&re->refcnt); 340 343 spin_unlock(&fs_info->reada_lock); 341 344 342 - if (re || looped) 345 + if (re) 343 346 return re; 344 347 345 348 re = kzalloc(sizeof(*re), GFP_NOFS); ··· 395 398 /* insert extent in reada_tree + all per-device trees, all or nothing */ 396 399 spin_lock(&fs_info->reada_lock); 397 400 ret = radix_tree_insert(&fs_info->reada_tree, index, re); 398 - if (ret) { 401 + if (ret == -EEXIST) { 402 + re_exist = radix_tree_lookup(&fs_info->reada_tree, index); 403 + BUG_ON(!re_exist); 404 + kref_get(&re_exist->refcnt); 399 405 spin_unlock(&fs_info->reada_lock); 400 - if (ret != -ENOMEM) { 401 - /* someone inserted the extent in the meantime */ 402 - looped = 1; 403 - } 404 406 goto error; 405 407 } 408 + if (ret) { 409 + spin_unlock(&fs_info->reada_lock); 410 + goto error; 411 + } 412 + prev_dev = NULL; 406 413 for (i = 0; i < nzones; ++i) { 407 414 dev = bbio->stripes[i].dev; 415 + if (dev == prev_dev) { 416 + /* 417 + * in case of DUP, just add the first zone. As both 418 + * are on the same device, there's nothing to gain 419 + * from adding both. 420 + * Also, it wouldn't work, as the tree is per device 421 + * and adding would fail with EEXIST 422 + */ 423 + continue; 424 + } 425 + prev_dev = dev; 408 426 ret = radix_tree_insert(&dev->reada_extents, index, re); 409 427 if (ret) { 410 428 while (--i >= 0) { ··· 462 450 } 463 451 kfree(bbio); 464 452 kfree(re); 465 - if (looped) 466 - goto again; 467 - return NULL; 453 + return re_exist; 468 454 } 469 455 470 456 static void reada_kref_dummy(struct kref *kr)
+3 -1
fs/btrfs/relocation.c
··· 1279 1279 if (rb_node) 1280 1280 backref_tree_panic(rb_node, -EEXIST, node->bytenr); 1281 1281 } else { 1282 + spin_lock(&root->fs_info->trans_lock); 1282 1283 list_del_init(&root->root_list); 1284 + spin_unlock(&root->fs_info->trans_lock); 1283 1285 kfree(node); 1284 1286 } 1285 1287 return 0; ··· 3813 3811 3814 3812 ret = btrfs_block_rsv_check(rc->extent_root, rc->block_rsv, 5); 3815 3813 if (ret < 0) { 3816 - if (ret != -EAGAIN) { 3814 + if (ret != -ENOSPC) { 3817 3815 err = ret; 3818 3816 WARN_ON(1); 3819 3817 break;
-15
fs/btrfs/scrub.c
··· 1257 1257 if (memcmp(csum, on_disk_csum, sdev->csum_size)) 1258 1258 fail = 1; 1259 1259 1260 - if (fail) { 1261 - spin_lock(&sdev->stat_lock); 1262 - ++sdev->stat.csum_errors; 1263 - spin_unlock(&sdev->stat_lock); 1264 - } 1265 - 1266 1260 return fail; 1267 1261 } 1268 1262 ··· 1328 1334 btrfs_csum_final(crc, calculated_csum); 1329 1335 if (memcmp(calculated_csum, on_disk_csum, sdev->csum_size)) 1330 1336 ++crc_fail; 1331 - 1332 - if (crc_fail || fail) { 1333 - spin_lock(&sdev->stat_lock); 1334 - if (crc_fail) 1335 - ++sdev->stat.csum_errors; 1336 - if (fail) 1337 - ++sdev->stat.verify_errors; 1338 - spin_unlock(&sdev->stat_lock); 1339 - } 1340 1337 1341 1338 return fail || crc_fail; 1342 1339 }
+4 -3
fs/btrfs/super.c
··· 815 815 return 0; 816 816 } 817 817 818 - btrfs_start_delalloc_inodes(root, 0); 819 818 btrfs_wait_ordered_extents(root, 0, 0); 820 819 821 820 trans = btrfs_start_transaction(root, 0); ··· 1147 1148 if (ret) 1148 1149 goto restore; 1149 1150 } else { 1150 - if (fs_info->fs_devices->rw_devices == 0) 1151 + if (fs_info->fs_devices->rw_devices == 0) { 1151 1152 ret = -EACCES; 1152 1153 goto restore; 1154 + } 1153 1155 1154 - if (btrfs_super_log_root(fs_info->super_copy) != 0) 1156 + if (btrfs_super_log_root(fs_info->super_copy) != 0) { 1155 1157 ret = -EINVAL; 1156 1158 goto restore; 1159 + } 1157 1160 1158 1161 ret = btrfs_cleanup_fs_roots(fs_info); 1159 1162 if (ret)
+5 -1
fs/btrfs/transaction.c
··· 73 73 74 74 cur_trans = root->fs_info->running_transaction; 75 75 if (cur_trans) { 76 - if (cur_trans->aborted) 76 + if (cur_trans->aborted) { 77 + spin_unlock(&root->fs_info->trans_lock); 77 78 return cur_trans->aborted; 79 + } 78 80 atomic_inc(&cur_trans->use_count); 79 81 atomic_inc(&cur_trans->num_writers); 80 82 cur_trans->num_joined++; ··· 1402 1400 ret = commit_fs_roots(trans, root); 1403 1401 if (ret) { 1404 1402 mutex_unlock(&root->fs_info->tree_log_mutex); 1403 + mutex_unlock(&root->fs_info->reloc_mutex); 1405 1404 goto cleanup_transaction; 1406 1405 } 1407 1406 ··· 1414 1411 ret = commit_cowonly_roots(trans, root); 1415 1412 if (ret) { 1416 1413 mutex_unlock(&root->fs_info->tree_log_mutex); 1414 + mutex_unlock(&root->fs_info->reloc_mutex); 1417 1415 goto cleanup_transaction; 1418 1416 } 1419 1417
+9 -4
fs/btrfs/volumes.c
··· 3324 3324 stripe_size = devices_info[ndevs-1].max_avail; 3325 3325 num_stripes = ndevs * dev_stripes; 3326 3326 3327 - if (stripe_size * num_stripes > max_chunk_size * ncopies) { 3327 + if (stripe_size * ndevs > max_chunk_size * ncopies) { 3328 3328 stripe_size = max_chunk_size * ncopies; 3329 - do_div(stripe_size, num_stripes); 3329 + do_div(stripe_size, ndevs); 3330 3330 } 3331 3331 3332 3332 do_div(stripe_size, dev_stripes); 3333 + 3334 + /* align to BTRFS_STRIPE_LEN */ 3333 3335 do_div(stripe_size, BTRFS_STRIPE_LEN); 3334 3336 stripe_size *= BTRFS_STRIPE_LEN; 3335 3337 ··· 3807 3805 else if (mirror_num) 3808 3806 stripe_index += mirror_num - 1; 3809 3807 else { 3808 + int old_stripe_index = stripe_index; 3810 3809 stripe_index = find_live_mirror(map, stripe_index, 3811 3810 map->sub_stripes, stripe_index + 3812 3811 current->pid % map->sub_stripes); 3813 - mirror_num = stripe_index + 1; 3812 + mirror_num = stripe_index - old_stripe_index + 1; 3814 3813 } 3815 3814 } else { 3816 3815 /* ··· 4353 4350 4354 4351 ret = __btrfs_open_devices(fs_devices, FMODE_READ, 4355 4352 root->fs_info->bdev_holder); 4356 - if (ret) 4353 + if (ret) { 4354 + free_fs_devices(fs_devices); 4357 4355 goto out; 4356 + } 4358 4357 4359 4358 if (!fs_devices->seeding) { 4360 4359 __btrfs_close_devices(fs_devices);