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 tag 'for-4.15-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux

Pull btrfs fixes from David Sterba:
"We've collected some fixes in since the pre-merge window freeze.

There's technically only one regression fix for 4.15, but the rest
seems important and candidates for stable.

- fix missing flush bio puts in error cases (is serious, but rarely
happens)

- fix reporting stat::st_blocks for buffered append writes

- fix space cache invalidation

- fix out of bound memory access when setting zlib level

- fix potential memory corruption when fsync fails in the middle

- fix crash in integrity checker

- incremetnal send fix, path mixup for certain unlink/rename
combination

- pass flags to writeback so compressed writes can be throttled
properly

- error handling fixes"

* tag 'for-4.15-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux:
Btrfs: incremental send, fix wrong unlink path after renaming file
btrfs: tree-checker: Fix false panic for sanity test
Btrfs: fix list_add corruption and soft lockups in fsync
btrfs: Fix wild memory access in compression level parser
btrfs: fix deadlock when writing out space cache
btrfs: clear space cache inode generation always
Btrfs: fix reported number of inode blocks after buffered append writes
Btrfs: move definition of the function btrfs_find_new_delalloc_bytes
Btrfs: bail out gracefully rather than BUG_ON
btrfs: dev_alloc_list is not protected by RCU, use normal list_del
btrfs: add missing device::flush_bio puts
btrfs: Fix transaction abort during failure in btrfs_rm_dev_item
Btrfs: add write_flags for compression bio

+317 -138
+5 -4
fs/btrfs/compression.c
··· 295 295 unsigned long len, u64 disk_start, 296 296 unsigned long compressed_len, 297 297 struct page **compressed_pages, 298 - unsigned long nr_pages) 298 + unsigned long nr_pages, 299 + unsigned int write_flags) 299 300 { 300 301 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 301 302 struct bio *bio = NULL; ··· 328 327 bdev = fs_info->fs_devices->latest_bdev; 329 328 330 329 bio = btrfs_bio_alloc(bdev, first_byte); 331 - bio_set_op_attrs(bio, REQ_OP_WRITE, 0); 330 + bio->bi_opf = REQ_OP_WRITE | write_flags; 332 331 bio->bi_private = cb; 333 332 bio->bi_end_io = end_compressed_bio_write; 334 333 refcount_set(&cb->pending_bios, 1); ··· 375 374 bio_put(bio); 376 375 377 376 bio = btrfs_bio_alloc(bdev, first_byte); 378 - bio_set_op_attrs(bio, REQ_OP_WRITE, 0); 377 + bio->bi_opf = REQ_OP_WRITE | write_flags; 379 378 bio->bi_private = cb; 380 379 bio->bi_end_io = end_compressed_bio_write; 381 380 bio_add_page(bio, page, PAGE_SIZE, 0); ··· 1529 1528 if (str[4] == ':' && '1' <= str[5] && str[5] <= '9' && str[6] == 0) 1530 1529 return str[5] - '0'; 1531 1530 1532 - return 0; 1531 + return BTRFS_ZLIB_DEFAULT_LEVEL; 1533 1532 }
+4 -1
fs/btrfs/compression.h
··· 34 34 /* Maximum size of data before compression */ 35 35 #define BTRFS_MAX_UNCOMPRESSED (SZ_128K) 36 36 37 + #define BTRFS_ZLIB_DEFAULT_LEVEL 3 38 + 37 39 struct compressed_bio { 38 40 /* number of bios pending for this compressed extent */ 39 41 refcount_t pending_bios; ··· 93 91 unsigned long len, u64 disk_start, 94 92 unsigned long compressed_len, 95 93 struct page **compressed_pages, 96 - unsigned long nr_pages); 94 + unsigned long nr_pages, 95 + unsigned int write_flags); 97 96 blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, 98 97 int mirror_num, unsigned long bio_flags); 99 98
+1
fs/btrfs/ctree.h
··· 3180 3180 int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int delay_iput, 3181 3181 int nr); 3182 3182 int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, 3183 + unsigned int extra_bits, 3183 3184 struct extent_state **cached_state, int dedupe); 3184 3185 int btrfs_create_subvol_root(struct btrfs_trans_handle *trans, 3185 3186 struct btrfs_root *new_root,
+8 -2
fs/btrfs/disk-io.c
··· 610 610 * that we don't try and read the other copies of this block, just 611 611 * return -EIO. 612 612 */ 613 - if (found_level == 0 && btrfs_check_leaf(root, eb)) { 613 + if (found_level == 0 && btrfs_check_leaf_full(root, eb)) { 614 614 set_bit(EXTENT_BUFFER_CORRUPT, &eb->bflags); 615 615 ret = -EIO; 616 616 } ··· 3848 3848 buf->len, 3849 3849 fs_info->dirty_metadata_batch); 3850 3850 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY 3851 - if (btrfs_header_level(buf) == 0 && btrfs_check_leaf(root, buf)) { 3851 + /* 3852 + * Since btrfs_mark_buffer_dirty() can be called with item pointer set 3853 + * but item data not updated. 3854 + * So here we should only check item pointers, not item data. 3855 + */ 3856 + if (btrfs_header_level(buf) == 0 && 3857 + btrfs_check_leaf_relaxed(root, buf)) { 3852 3858 btrfs_print_leaf(buf); 3853 3859 ASSERT(0); 3854 3860 }
+7 -7
fs/btrfs/extent-tree.c
··· 3502 3502 goto again; 3503 3503 } 3504 3504 3505 - /* We've already setup this transaction, go ahead and exit */ 3506 - if (block_group->cache_generation == trans->transid && 3507 - i_size_read(inode)) { 3508 - dcs = BTRFS_DC_SETUP; 3509 - goto out_put; 3510 - } 3511 - 3512 3505 /* 3513 3506 * We want to set the generation to 0, that way if anything goes wrong 3514 3507 * from here on out we know not to trust this cache when we load up next ··· 3524 3531 goto out_put; 3525 3532 } 3526 3533 WARN_ON(ret); 3534 + 3535 + /* We've already setup this transaction, go ahead and exit */ 3536 + if (block_group->cache_generation == trans->transid && 3537 + i_size_read(inode)) { 3538 + dcs = BTRFS_DC_SETUP; 3539 + goto out_put; 3540 + } 3527 3541 3528 3542 if (i_size_read(inode) > 0) { 3529 3543 ret = btrfs_check_trunc_cache_free_space(fs_info,
+1 -1
fs/btrfs/extent_io.c
··· 3253 3253 delalloc_start, 3254 3254 delalloc_end, 3255 3255 &page_started, 3256 - nr_written); 3256 + nr_written, wbc); 3257 3257 /* File system has been set read-only */ 3258 3258 if (ret) { 3259 3259 SetPageError(page);
+5 -3
fs/btrfs/extent_io.h
··· 116 116 */ 117 117 int (*fill_delalloc)(void *private_data, struct page *locked_page, 118 118 u64 start, u64 end, int *page_started, 119 - unsigned long *nr_written); 119 + unsigned long *nr_written, 120 + struct writeback_control *wbc); 120 121 121 122 int (*writepage_start_hook)(struct page *page, u64 start, u64 end); 122 123 void (*writepage_end_io_hook)(struct page *page, u64 start, u64 end, ··· 366 365 struct extent_state **cached_state); 367 366 368 367 static inline int set_extent_delalloc(struct extent_io_tree *tree, u64 start, 369 - u64 end, struct extent_state **cached_state) 368 + u64 end, unsigned int extra_bits, 369 + struct extent_state **cached_state) 370 370 { 371 371 return set_extent_bit(tree, start, end, 372 - EXTENT_DELALLOC | EXTENT_UPTODATE, 372 + EXTENT_DELALLOC | EXTENT_UPTODATE | extra_bits, 373 373 NULL, cached_state, GFP_NOFS); 374 374 } 375 375
+70 -60
fs/btrfs/file.c
··· 477 477 } 478 478 } 479 479 480 + static int btrfs_find_new_delalloc_bytes(struct btrfs_inode *inode, 481 + const u64 start, 482 + const u64 len, 483 + struct extent_state **cached_state) 484 + { 485 + u64 search_start = start; 486 + const u64 end = start + len - 1; 487 + 488 + while (search_start < end) { 489 + const u64 search_len = end - search_start + 1; 490 + struct extent_map *em; 491 + u64 em_len; 492 + int ret = 0; 493 + 494 + em = btrfs_get_extent(inode, NULL, 0, search_start, 495 + search_len, 0); 496 + if (IS_ERR(em)) 497 + return PTR_ERR(em); 498 + 499 + if (em->block_start != EXTENT_MAP_HOLE) 500 + goto next; 501 + 502 + em_len = em->len; 503 + if (em->start < search_start) 504 + em_len -= search_start - em->start; 505 + if (em_len > search_len) 506 + em_len = search_len; 507 + 508 + ret = set_extent_bit(&inode->io_tree, search_start, 509 + search_start + em_len - 1, 510 + EXTENT_DELALLOC_NEW, 511 + NULL, cached_state, GFP_NOFS); 512 + next: 513 + search_start = extent_map_end(em); 514 + free_extent_map(em); 515 + if (ret) 516 + return ret; 517 + } 518 + return 0; 519 + } 520 + 480 521 /* 481 522 * after copy_from_user, pages need to be dirtied and we need to make 482 523 * sure holes are created between the current EOF and the start of ··· 538 497 u64 end_of_last_block; 539 498 u64 end_pos = pos + write_bytes; 540 499 loff_t isize = i_size_read(inode); 500 + unsigned int extra_bits = 0; 541 501 542 502 start_pos = pos & ~((u64) fs_info->sectorsize - 1); 543 503 num_bytes = round_up(write_bytes + pos - start_pos, 544 504 fs_info->sectorsize); 545 505 546 506 end_of_last_block = start_pos + num_bytes - 1; 507 + 508 + if (!btrfs_is_free_space_inode(BTRFS_I(inode))) { 509 + if (start_pos >= isize && 510 + !(BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC)) { 511 + /* 512 + * There can't be any extents following eof in this case 513 + * so just set the delalloc new bit for the range 514 + * directly. 515 + */ 516 + extra_bits |= EXTENT_DELALLOC_NEW; 517 + } else { 518 + err = btrfs_find_new_delalloc_bytes(BTRFS_I(inode), 519 + start_pos, 520 + num_bytes, cached); 521 + if (err) 522 + return err; 523 + } 524 + } 525 + 547 526 err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block, 548 - cached, 0); 527 + extra_bits, cached, 0); 549 528 if (err) 550 529 return err; 551 530 ··· 1465 1404 1466 1405 } 1467 1406 1468 - static int btrfs_find_new_delalloc_bytes(struct btrfs_inode *inode, 1469 - const u64 start, 1470 - const u64 len, 1471 - struct extent_state **cached_state) 1472 - { 1473 - u64 search_start = start; 1474 - const u64 end = start + len - 1; 1475 - 1476 - while (search_start < end) { 1477 - const u64 search_len = end - search_start + 1; 1478 - struct extent_map *em; 1479 - u64 em_len; 1480 - int ret = 0; 1481 - 1482 - em = btrfs_get_extent(inode, NULL, 0, search_start, 1483 - search_len, 0); 1484 - if (IS_ERR(em)) 1485 - return PTR_ERR(em); 1486 - 1487 - if (em->block_start != EXTENT_MAP_HOLE) 1488 - goto next; 1489 - 1490 - em_len = em->len; 1491 - if (em->start < search_start) 1492 - em_len -= search_start - em->start; 1493 - if (em_len > search_len) 1494 - em_len = search_len; 1495 - 1496 - ret = set_extent_bit(&inode->io_tree, search_start, 1497 - search_start + em_len - 1, 1498 - EXTENT_DELALLOC_NEW, 1499 - NULL, cached_state, GFP_NOFS); 1500 - next: 1501 - search_start = extent_map_end(em); 1502 - free_extent_map(em); 1503 - if (ret) 1504 - return ret; 1505 - } 1506 - return 0; 1507 - } 1508 - 1509 1407 /* 1510 1408 * This function locks the extent and properly waits for data=ordered extents 1511 1409 * to finish before allowing the pages to be modified if need. ··· 1493 1473 + round_up(pos + write_bytes - start_pos, 1494 1474 fs_info->sectorsize) - 1; 1495 1475 1496 - if (start_pos < inode->vfs_inode.i_size || 1497 - (inode->flags & BTRFS_INODE_PREALLOC)) { 1476 + if (start_pos < inode->vfs_inode.i_size) { 1498 1477 struct btrfs_ordered_extent *ordered; 1499 - unsigned int clear_bits; 1500 1478 1501 1479 lock_extent_bits(&inode->io_tree, start_pos, last_pos, 1502 1480 cached_state); ··· 1516 1498 } 1517 1499 if (ordered) 1518 1500 btrfs_put_ordered_extent(ordered); 1519 - ret = btrfs_find_new_delalloc_bytes(inode, start_pos, 1520 - last_pos - start_pos + 1, 1521 - cached_state); 1522 - clear_bits = EXTENT_DIRTY | EXTENT_DELALLOC | 1523 - EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG; 1524 - if (ret) 1525 - clear_bits |= EXTENT_DELALLOC_NEW | EXTENT_LOCKED; 1526 - clear_extent_bit(&inode->io_tree, start_pos, 1527 - last_pos, clear_bits, 1528 - (clear_bits & EXTENT_LOCKED) ? 1 : 0, 1529 - 0, cached_state, GFP_NOFS); 1530 - if (ret) 1531 - return ret; 1501 + clear_extent_bit(&inode->io_tree, start_pos, last_pos, 1502 + EXTENT_DIRTY | EXTENT_DELALLOC | 1503 + EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, 1504 + 0, 0, cached_state, GFP_NOFS); 1532 1505 *lockstart = start_pos; 1533 1506 *lockend = last_pos; 1534 1507 ret = 1; ··· 2057 2048 len = (u64)end - (u64)start + 1; 2058 2049 trace_btrfs_sync_file(file, datasync); 2059 2050 2051 + btrfs_init_log_ctx(&ctx, inode); 2052 + 2060 2053 /* 2061 2054 * We write the dirty pages in the range and wait until they complete 2062 2055 * out of the ->i_mutex. If so, we can flush the dirty pages by ··· 2205 2194 } 2206 2195 trans->sync = true; 2207 2196 2208 - btrfs_init_log_ctx(&ctx, inode); 2209 - 2210 2197 ret = btrfs_log_dentry_safe(trans, root, dentry, start, end, &ctx); 2211 2198 if (ret < 0) { 2212 2199 /* Fallthrough and commit/free transaction. */ ··· 2262 2253 ret = btrfs_end_transaction(trans); 2263 2254 } 2264 2255 out: 2256 + ASSERT(list_empty(&ctx.list)); 2265 2257 err = file_check_and_advance_wb_err(file); 2266 2258 if (!ret) 2267 2259 ret = err;
+2 -1
fs/btrfs/free-space-cache.c
··· 1264 1264 /* Lock all pages first so we can lock the extent safely. */ 1265 1265 ret = io_ctl_prepare_pages(io_ctl, inode, 0); 1266 1266 if (ret) 1267 - goto out; 1267 + goto out_unlock; 1268 1268 1269 1269 lock_extent_bits(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1, 1270 1270 &cached_state); ··· 1358 1358 out_nospc: 1359 1359 cleanup_write_cache_enospc(inode, io_ctl, &cached_state); 1360 1360 1361 + out_unlock: 1361 1362 if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA)) 1362 1363 up_write(&block_group->data_rwsem); 1363 1364
+24 -10
fs/btrfs/inode.c
··· 378 378 struct page *locked_page; 379 379 u64 start; 380 380 u64 end; 381 + unsigned int write_flags; 381 382 struct list_head extents; 382 383 struct btrfs_work work; 383 384 }; ··· 858 857 async_extent->ram_size, 859 858 ins.objectid, 860 859 ins.offset, async_extent->pages, 861 - async_extent->nr_pages)) { 860 + async_extent->nr_pages, 861 + async_cow->write_flags)) { 862 862 struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree; 863 863 struct page *p = async_extent->pages[0]; 864 864 const u64 start = async_extent->start; ··· 1193 1191 1194 1192 static int cow_file_range_async(struct inode *inode, struct page *locked_page, 1195 1193 u64 start, u64 end, int *page_started, 1196 - unsigned long *nr_written) 1194 + unsigned long *nr_written, 1195 + unsigned int write_flags) 1197 1196 { 1198 1197 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 1199 1198 struct async_cow *async_cow; ··· 1211 1208 async_cow->root = root; 1212 1209 async_cow->locked_page = locked_page; 1213 1210 async_cow->start = start; 1211 + async_cow->write_flags = write_flags; 1214 1212 1215 1213 if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS && 1216 1214 !btrfs_test_opt(fs_info, FORCE_COMPRESS)) ··· 1581 1577 */ 1582 1578 static int run_delalloc_range(void *private_data, struct page *locked_page, 1583 1579 u64 start, u64 end, int *page_started, 1584 - unsigned long *nr_written) 1580 + unsigned long *nr_written, 1581 + struct writeback_control *wbc) 1585 1582 { 1586 1583 struct inode *inode = private_data; 1587 1584 int ret; 1588 1585 int force_cow = need_force_cow(inode, start, end); 1586 + unsigned int write_flags = wbc_to_write_flags(wbc); 1589 1587 1590 1588 if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW && !force_cow) { 1591 1589 ret = run_delalloc_nocow(inode, locked_page, start, end, ··· 1602 1596 set_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, 1603 1597 &BTRFS_I(inode)->runtime_flags); 1604 1598 ret = cow_file_range_async(inode, locked_page, start, end, 1605 - page_started, nr_written); 1599 + page_started, nr_written, 1600 + write_flags); 1606 1601 } 1607 1602 if (ret) 1608 1603 btrfs_cleanup_ordered_extents(inode, start, end - start + 1); ··· 2032 2025 } 2033 2026 2034 2027 int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, 2028 + unsigned int extra_bits, 2035 2029 struct extent_state **cached_state, int dedupe) 2036 2030 { 2037 2031 WARN_ON((end & (PAGE_SIZE - 1)) == 0); 2038 2032 return set_extent_delalloc(&BTRFS_I(inode)->io_tree, start, end, 2039 - cached_state); 2033 + extra_bits, cached_state); 2040 2034 } 2041 2035 2042 2036 /* see btrfs_writepage_start_hook for details on why this is required */ ··· 2098 2090 goto out; 2099 2091 } 2100 2092 2101 - btrfs_set_extent_delalloc(inode, page_start, page_end, &cached_state, 2093 + btrfs_set_extent_delalloc(inode, page_start, page_end, 0, &cached_state, 2102 2094 0); 2103 2095 ClearPageChecked(page); 2104 2096 set_page_dirty(page); ··· 4798 4790 EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, 4799 4791 0, 0, &cached_state, GFP_NOFS); 4800 4792 4801 - ret = btrfs_set_extent_delalloc(inode, block_start, block_end, 4793 + ret = btrfs_set_extent_delalloc(inode, block_start, block_end, 0, 4802 4794 &cached_state, 0); 4803 4795 if (ret) { 4804 4796 unlock_extent_cached(io_tree, block_start, block_end, ··· 5446 5438 goto out_err; 5447 5439 5448 5440 btrfs_dir_item_key_to_cpu(path->nodes[0], di, location); 5441 + if (location->type != BTRFS_INODE_ITEM_KEY && 5442 + location->type != BTRFS_ROOT_ITEM_KEY) { 5443 + btrfs_warn(root->fs_info, 5444 + "%s gets something invalid in DIR_ITEM (name %s, directory ino %llu, location(%llu %u %llu))", 5445 + __func__, name, btrfs_ino(BTRFS_I(dir)), 5446 + location->objectid, location->type, location->offset); 5447 + goto out_err; 5448 + } 5449 5449 out: 5450 5450 btrfs_free_path(path); 5451 5451 return ret; ··· 5769 5753 inode = btrfs_iget(dir->i_sb, &location, root, NULL); 5770 5754 return inode; 5771 5755 } 5772 - 5773 - BUG_ON(location.type != BTRFS_ROOT_ITEM_KEY); 5774 5756 5775 5757 index = srcu_read_lock(&fs_info->subvol_srcu); 5776 5758 ret = fixup_tree_root_location(fs_info, dir, dentry, ··· 9164 9150 EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, 9165 9151 0, 0, &cached_state, GFP_NOFS); 9166 9152 9167 - ret = btrfs_set_extent_delalloc(inode, page_start, end, 9153 + ret = btrfs_set_extent_delalloc(inode, page_start, end, 0, 9168 9154 &cached_state, 0); 9169 9155 if (ret) { 9170 9156 unlock_extent_cached(io_tree, page_start, page_end,
+2 -1
fs/btrfs/relocation.c
··· 3268 3268 nr++; 3269 3269 } 3270 3270 3271 - btrfs_set_extent_delalloc(inode, page_start, page_end, NULL, 0); 3271 + btrfs_set_extent_delalloc(inode, page_start, page_end, 0, NULL, 3272 + 0); 3272 3273 set_page_dirty(page); 3273 3274 3274 3275 unlock_extent(&BTRFS_I(inode)->io_tree,
+109 -21
fs/btrfs/send.c
··· 3521 3521 } 3522 3522 3523 3523 /* 3524 - * Check if ino ino1 is an ancestor of inode ino2 in the given root. 3524 + * Check if inode ino2, or any of its ancestors, is inode ino1. 3525 + * Return 1 if true, 0 if false and < 0 on error. 3526 + */ 3527 + static int check_ino_in_path(struct btrfs_root *root, 3528 + const u64 ino1, 3529 + const u64 ino1_gen, 3530 + const u64 ino2, 3531 + const u64 ino2_gen, 3532 + struct fs_path *fs_path) 3533 + { 3534 + u64 ino = ino2; 3535 + 3536 + if (ino1 == ino2) 3537 + return ino1_gen == ino2_gen; 3538 + 3539 + while (ino > BTRFS_FIRST_FREE_OBJECTID) { 3540 + u64 parent; 3541 + u64 parent_gen; 3542 + int ret; 3543 + 3544 + fs_path_reset(fs_path); 3545 + ret = get_first_ref(root, ino, &parent, &parent_gen, fs_path); 3546 + if (ret < 0) 3547 + return ret; 3548 + if (parent == ino1) 3549 + return parent_gen == ino1_gen; 3550 + ino = parent; 3551 + } 3552 + return 0; 3553 + } 3554 + 3555 + /* 3556 + * Check if ino ino1 is an ancestor of inode ino2 in the given root for any 3557 + * possible path (in case ino2 is not a directory and has multiple hard links). 3525 3558 * Return 1 if true, 0 if false and < 0 on error. 3526 3559 */ 3527 3560 static int is_ancestor(struct btrfs_root *root, ··· 3563 3530 const u64 ino2, 3564 3531 struct fs_path *fs_path) 3565 3532 { 3566 - u64 ino = ino2; 3567 - bool free_path = false; 3533 + bool free_fs_path = false; 3568 3534 int ret = 0; 3535 + struct btrfs_path *path = NULL; 3536 + struct btrfs_key key; 3569 3537 3570 3538 if (!fs_path) { 3571 3539 fs_path = fs_path_alloc(); 3572 3540 if (!fs_path) 3573 3541 return -ENOMEM; 3574 - free_path = true; 3542 + free_fs_path = true; 3575 3543 } 3576 3544 3577 - while (ino > BTRFS_FIRST_FREE_OBJECTID) { 3578 - u64 parent; 3579 - u64 parent_gen; 3580 - 3581 - fs_path_reset(fs_path); 3582 - ret = get_first_ref(root, ino, &parent, &parent_gen, fs_path); 3583 - if (ret < 0) { 3584 - if (ret == -ENOENT && ino == ino2) 3585 - ret = 0; 3586 - goto out; 3587 - } 3588 - if (parent == ino1) { 3589 - ret = parent_gen == ino1_gen ? 1 : 0; 3590 - goto out; 3591 - } 3592 - ino = parent; 3545 + path = alloc_path_for_send(); 3546 + if (!path) { 3547 + ret = -ENOMEM; 3548 + goto out; 3593 3549 } 3550 + 3551 + key.objectid = ino2; 3552 + key.type = BTRFS_INODE_REF_KEY; 3553 + key.offset = 0; 3554 + 3555 + ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 3556 + if (ret < 0) 3557 + goto out; 3558 + 3559 + while (true) { 3560 + struct extent_buffer *leaf = path->nodes[0]; 3561 + int slot = path->slots[0]; 3562 + u32 cur_offset = 0; 3563 + u32 item_size; 3564 + 3565 + if (slot >= btrfs_header_nritems(leaf)) { 3566 + ret = btrfs_next_leaf(root, path); 3567 + if (ret < 0) 3568 + goto out; 3569 + if (ret > 0) 3570 + break; 3571 + continue; 3572 + } 3573 + 3574 + btrfs_item_key_to_cpu(leaf, &key, slot); 3575 + if (key.objectid != ino2) 3576 + break; 3577 + if (key.type != BTRFS_INODE_REF_KEY && 3578 + key.type != BTRFS_INODE_EXTREF_KEY) 3579 + break; 3580 + 3581 + item_size = btrfs_item_size_nr(leaf, slot); 3582 + while (cur_offset < item_size) { 3583 + u64 parent; 3584 + u64 parent_gen; 3585 + 3586 + if (key.type == BTRFS_INODE_EXTREF_KEY) { 3587 + unsigned long ptr; 3588 + struct btrfs_inode_extref *extref; 3589 + 3590 + ptr = btrfs_item_ptr_offset(leaf, slot); 3591 + extref = (struct btrfs_inode_extref *) 3592 + (ptr + cur_offset); 3593 + parent = btrfs_inode_extref_parent(leaf, 3594 + extref); 3595 + cur_offset += sizeof(*extref); 3596 + cur_offset += btrfs_inode_extref_name_len(leaf, 3597 + extref); 3598 + } else { 3599 + parent = key.offset; 3600 + cur_offset = item_size; 3601 + } 3602 + 3603 + ret = get_inode_info(root, parent, NULL, &parent_gen, 3604 + NULL, NULL, NULL, NULL); 3605 + if (ret < 0) 3606 + goto out; 3607 + ret = check_ino_in_path(root, ino1, ino1_gen, 3608 + parent, parent_gen, fs_path); 3609 + if (ret) 3610 + goto out; 3611 + } 3612 + path->slots[0]++; 3613 + } 3614 + ret = 0; 3594 3615 out: 3595 - if (free_path) 3616 + btrfs_free_path(path); 3617 + if (free_fs_path) 3596 3618 fs_path_free(fs_path); 3597 3619 return ret; 3598 3620 }
+11 -2
fs/btrfs/super.c
··· 507 507 token == Opt_compress_force || 508 508 strncmp(args[0].from, "zlib", 4) == 0) { 509 509 compress_type = "zlib"; 510 + 510 511 info->compress_type = BTRFS_COMPRESS_ZLIB; 511 - info->compress_level = 512 - btrfs_compress_str2level(args[0].from); 512 + info->compress_level = BTRFS_ZLIB_DEFAULT_LEVEL; 513 + /* 514 + * args[0] contains uninitialized data since 515 + * for these tokens we don't expect any 516 + * parameter. 517 + */ 518 + if (token != Opt_compress && 519 + token != Opt_compress_force) 520 + info->compress_level = 521 + btrfs_compress_str2level(args[0].from); 513 522 btrfs_set_opt(info->mount_opt, COMPRESS); 514 523 btrfs_clear_opt(info->mount_opt, NODATACOW); 515 524 btrfs_clear_opt(info->mount_opt, NODATASUM);
+3 -3
fs/btrfs/tests/extent-io-tests.c
··· 114 114 * |--- delalloc ---| 115 115 * |--- search ---| 116 116 */ 117 - set_extent_delalloc(&tmp, 0, sectorsize - 1, NULL); 117 + set_extent_delalloc(&tmp, 0, sectorsize - 1, 0, NULL); 118 118 start = 0; 119 119 end = 0; 120 120 found = find_lock_delalloc_range(inode, &tmp, locked_page, &start, ··· 145 145 test_msg("Couldn't find the locked page\n"); 146 146 goto out_bits; 147 147 } 148 - set_extent_delalloc(&tmp, sectorsize, max_bytes - 1, NULL); 148 + set_extent_delalloc(&tmp, sectorsize, max_bytes - 1, 0, NULL); 149 149 start = test_start; 150 150 end = 0; 151 151 found = find_lock_delalloc_range(inode, &tmp, locked_page, &start, ··· 200 200 * 201 201 * We are re-using our test_start from above since it works out well. 202 202 */ 203 - set_extent_delalloc(&tmp, max_bytes, total_dirty - 1, NULL); 203 + set_extent_delalloc(&tmp, max_bytes, total_dirty - 1, 0, NULL); 204 204 start = test_start; 205 205 end = 0; 206 206 found = find_lock_delalloc_range(inode, &tmp, locked_page, &start,
+6 -6
fs/btrfs/tests/inode-tests.c
··· 968 968 btrfs_test_inode_set_ops(inode); 969 969 970 970 /* [BTRFS_MAX_EXTENT_SIZE] */ 971 - ret = btrfs_set_extent_delalloc(inode, 0, BTRFS_MAX_EXTENT_SIZE - 1, 971 + ret = btrfs_set_extent_delalloc(inode, 0, BTRFS_MAX_EXTENT_SIZE - 1, 0, 972 972 NULL, 0); 973 973 if (ret) { 974 974 test_msg("btrfs_set_extent_delalloc returned %d\n", ret); ··· 984 984 /* [BTRFS_MAX_EXTENT_SIZE][sectorsize] */ 985 985 ret = btrfs_set_extent_delalloc(inode, BTRFS_MAX_EXTENT_SIZE, 986 986 BTRFS_MAX_EXTENT_SIZE + sectorsize - 1, 987 - NULL, 0); 987 + 0, NULL, 0); 988 988 if (ret) { 989 989 test_msg("btrfs_set_extent_delalloc returned %d\n", ret); 990 990 goto out; ··· 1018 1018 ret = btrfs_set_extent_delalloc(inode, BTRFS_MAX_EXTENT_SIZE >> 1, 1019 1019 (BTRFS_MAX_EXTENT_SIZE >> 1) 1020 1020 + sectorsize - 1, 1021 - NULL, 0); 1021 + 0, NULL, 0); 1022 1022 if (ret) { 1023 1023 test_msg("btrfs_set_extent_delalloc returned %d\n", ret); 1024 1024 goto out; ··· 1036 1036 ret = btrfs_set_extent_delalloc(inode, 1037 1037 BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize, 1038 1038 (BTRFS_MAX_EXTENT_SIZE << 1) + 3 * sectorsize - 1, 1039 - NULL, 0); 1039 + 0, NULL, 0); 1040 1040 if (ret) { 1041 1041 test_msg("btrfs_set_extent_delalloc returned %d\n", ret); 1042 1042 goto out; ··· 1053 1053 */ 1054 1054 ret = btrfs_set_extent_delalloc(inode, 1055 1055 BTRFS_MAX_EXTENT_SIZE + sectorsize, 1056 - BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize - 1, NULL, 0); 1056 + BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize - 1, 0, NULL, 0); 1057 1057 if (ret) { 1058 1058 test_msg("btrfs_set_extent_delalloc returned %d\n", ret); 1059 1059 goto out; ··· 1089 1089 */ 1090 1090 ret = btrfs_set_extent_delalloc(inode, 1091 1091 BTRFS_MAX_EXTENT_SIZE + sectorsize, 1092 - BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize - 1, NULL, 0); 1092 + BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize - 1, 0, NULL, 0); 1093 1093 if (ret) { 1094 1094 test_msg("btrfs_set_extent_delalloc returned %d\n", ret); 1095 1095 goto out;
+22 -5
fs/btrfs/tree-checker.c
··· 242 242 return ret; 243 243 } 244 244 245 - int btrfs_check_leaf(struct btrfs_root *root, struct extent_buffer *leaf) 245 + static int check_leaf(struct btrfs_root *root, struct extent_buffer *leaf, 246 + bool check_item_data) 246 247 { 247 248 struct btrfs_fs_info *fs_info = root->fs_info; 248 249 /* No valid key type is 0, so all key should be larger than this key */ ··· 362 361 return -EUCLEAN; 363 362 } 364 363 365 - /* Check if the item size and content meet other criteria */ 366 - ret = check_leaf_item(root, leaf, &key, slot); 367 - if (ret < 0) 368 - return ret; 364 + if (check_item_data) { 365 + /* 366 + * Check if the item size and content meet other 367 + * criteria 368 + */ 369 + ret = check_leaf_item(root, leaf, &key, slot); 370 + if (ret < 0) 371 + return ret; 372 + } 369 373 370 374 prev_key.objectid = key.objectid; 371 375 prev_key.type = key.type; ··· 378 372 } 379 373 380 374 return 0; 375 + } 376 + 377 + int btrfs_check_leaf_full(struct btrfs_root *root, struct extent_buffer *leaf) 378 + { 379 + return check_leaf(root, leaf, true); 380 + } 381 + 382 + int btrfs_check_leaf_relaxed(struct btrfs_root *root, 383 + struct extent_buffer *leaf) 384 + { 385 + return check_leaf(root, leaf, false); 381 386 } 382 387 383 388 int btrfs_check_node(struct btrfs_root *root, struct extent_buffer *node)
+13 -1
fs/btrfs/tree-checker.h
··· 20 20 #include "ctree.h" 21 21 #include "extent_io.h" 22 22 23 - int btrfs_check_leaf(struct btrfs_root *root, struct extent_buffer *leaf); 23 + /* 24 + * Comprehensive leaf checker. 25 + * Will check not only the item pointers, but also every possible member 26 + * in item data. 27 + */ 28 + int btrfs_check_leaf_full(struct btrfs_root *root, struct extent_buffer *leaf); 29 + 30 + /* 31 + * Less strict leaf checker. 32 + * Will only check item pointers, not reading item data. 33 + */ 34 + int btrfs_check_leaf_relaxed(struct btrfs_root *root, 35 + struct extent_buffer *leaf); 24 36 int btrfs_check_node(struct btrfs_root *root, struct extent_buffer *node); 25 37 26 38 #endif
+1 -1
fs/btrfs/tree-log.c
··· 4102 4102 4103 4103 if (ordered_io_err) { 4104 4104 ctx->io_err = -EIO; 4105 - return 0; 4105 + return ctx->io_err; 4106 4106 } 4107 4107 4108 4108 btrfs_init_map_token(&token);
+23 -9
fs/btrfs/volumes.c
··· 189 189 struct btrfs_device, dev_list); 190 190 list_del(&device->dev_list); 191 191 rcu_string_free(device->name); 192 + bio_put(device->flush_bio); 192 193 kfree(device); 193 194 } 194 195 kfree(fs_devices); ··· 579 578 fs_devs->num_devices--; 580 579 list_del(&dev->dev_list); 581 580 rcu_string_free(dev->name); 581 + bio_put(dev->flush_bio); 582 582 kfree(dev); 583 583 } 584 584 break; ··· 632 630 633 631 name = rcu_string_strdup(path, GFP_NOFS); 634 632 if (!name) { 633 + bio_put(device->flush_bio); 635 634 kfree(device); 636 635 return -ENOMEM; 637 636 } ··· 745 742 name = rcu_string_strdup(orig_dev->name->str, 746 743 GFP_KERNEL); 747 744 if (!name) { 745 + bio_put(device->flush_bio); 748 746 kfree(device); 749 747 goto error; 750 748 } ··· 811 807 list_del_init(&device->dev_list); 812 808 fs_devices->num_devices--; 813 809 rcu_string_free(device->name); 810 + bio_put(device->flush_bio); 814 811 kfree(device); 815 812 } 816 813 ··· 1755 1750 key.offset = device->devid; 1756 1751 1757 1752 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); 1758 - if (ret < 0) 1759 - goto out; 1760 - 1761 - if (ret > 0) { 1762 - ret = -ENOENT; 1753 + if (ret) { 1754 + if (ret > 0) 1755 + ret = -ENOENT; 1756 + btrfs_abort_transaction(trans, ret); 1757 + btrfs_end_transaction(trans); 1763 1758 goto out; 1764 1759 } 1765 1760 1766 1761 ret = btrfs_del_item(trans, root, path); 1767 - if (ret) 1768 - goto out; 1762 + if (ret) { 1763 + btrfs_abort_transaction(trans, ret); 1764 + btrfs_end_transaction(trans); 1765 + } 1766 + 1769 1767 out: 1770 1768 btrfs_free_path(path); 1771 - btrfs_commit_transaction(trans); 1769 + if (!ret) 1770 + ret = btrfs_commit_transaction(trans); 1772 1771 return ret; 1773 1772 } 1774 1773 ··· 2002 1993 fs_devices = srcdev->fs_devices; 2003 1994 2004 1995 list_del_rcu(&srcdev->dev_list); 2005 - list_del_rcu(&srcdev->dev_alloc_list); 1996 + list_del(&srcdev->dev_alloc_list); 2006 1997 fs_devices->num_devices--; 2007 1998 if (srcdev->missing) 2008 1999 fs_devices->missing_devices--; ··· 2358 2349 2359 2350 name = rcu_string_strdup(device_path, GFP_KERNEL); 2360 2351 if (!name) { 2352 + bio_put(device->flush_bio); 2361 2353 kfree(device); 2362 2354 ret = -ENOMEM; 2363 2355 goto error; ··· 2368 2358 trans = btrfs_start_transaction(root, 0); 2369 2359 if (IS_ERR(trans)) { 2370 2360 rcu_string_free(device->name); 2361 + bio_put(device->flush_bio); 2371 2362 kfree(device); 2372 2363 ret = PTR_ERR(trans); 2373 2364 goto error; ··· 2512 2501 if (trans) 2513 2502 btrfs_end_transaction(trans); 2514 2503 rcu_string_free(device->name); 2504 + bio_put(device->flush_bio); 2515 2505 kfree(device); 2516 2506 error: 2517 2507 blkdev_put(bdev, FMODE_EXCL); ··· 2579 2567 2580 2568 name = rcu_string_strdup(device_path, GFP_KERNEL); 2581 2569 if (!name) { 2570 + bio_put(device->flush_bio); 2582 2571 kfree(device); 2583 2572 ret = -ENOMEM; 2584 2573 goto error; ··· 6297 6284 6298 6285 ret = find_next_devid(fs_info, &tmp); 6299 6286 if (ret) { 6287 + bio_put(dev->flush_bio); 6300 6288 kfree(dev); 6301 6289 return ERR_PTR(ret); 6302 6290 }