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

Pull btrfs fixes from David Sterba:
"Fixes:

- check that subvolume is writable when changing xattrs from security
namespace

- fix memory leak in device lookup helper

- update generation of hole file extent item when merging holes

- fix space cache corruption and potential double allocations; this
is a rare bug but can be serious once it happens, stable backports
and analysis tool will be provided

- fix error handling when deleting root references

- fix crash due to assert when attempting to cancel suspended device
replace, add message what to do if mount fails due to missing
replace item

Regressions:

- don't merge pages into bio if their page offset is not contiguous

- don't allow large NOWAIT direct reads, this could lead to short
reads eg. in io_uring"

* tag 'for-6.0-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux:
btrfs: add info when mount fails due to stale replace target
btrfs: replace: drop assert for suspended replace
btrfs: fix silent failure when deleting root reference
btrfs: fix space cache corruption and potential double allocations
btrfs: don't allow large NOWAIT direct reads
btrfs: don't merge pages into bio if their page offset is not contiguous
btrfs: update generation of hole file extent item when merging holes
btrfs: fix possible memory leak in btrfs_get_dev_args_from_path()
btrfs: check if root is readonly while setting security xattr

+79 -70
+15 -32
fs/btrfs/block-group.c
··· 440 440 btrfs_put_caching_control(caching_ctl); 441 441 } 442 442 443 - int btrfs_wait_block_group_cache_done(struct btrfs_block_group *cache) 443 + static int btrfs_caching_ctl_wait_done(struct btrfs_block_group *cache, 444 + struct btrfs_caching_control *caching_ctl) 445 + { 446 + wait_event(caching_ctl->wait, btrfs_block_group_done(cache)); 447 + return cache->cached == BTRFS_CACHE_ERROR ? -EIO : 0; 448 + } 449 + 450 + static int btrfs_wait_block_group_cache_done(struct btrfs_block_group *cache) 444 451 { 445 452 struct btrfs_caching_control *caching_ctl; 446 - int ret = 0; 453 + int ret; 447 454 448 455 caching_ctl = btrfs_get_caching_control(cache); 449 456 if (!caching_ctl) 450 457 return (cache->cached == BTRFS_CACHE_ERROR) ? -EIO : 0; 451 - 452 - wait_event(caching_ctl->wait, btrfs_block_group_done(cache)); 453 - if (cache->cached == BTRFS_CACHE_ERROR) 454 - ret = -EIO; 458 + ret = btrfs_caching_ctl_wait_done(cache, caching_ctl); 455 459 btrfs_put_caching_control(caching_ctl); 456 460 return ret; 457 - } 458 - 459 - static bool space_cache_v1_done(struct btrfs_block_group *cache) 460 - { 461 - bool ret; 462 - 463 - spin_lock(&cache->lock); 464 - ret = cache->cached != BTRFS_CACHE_FAST; 465 - spin_unlock(&cache->lock); 466 - 467 - return ret; 468 - } 469 - 470 - void btrfs_wait_space_cache_v1_finished(struct btrfs_block_group *cache, 471 - struct btrfs_caching_control *caching_ctl) 472 - { 473 - wait_event(caching_ctl->wait, space_cache_v1_done(cache)); 474 461 } 475 462 476 463 #ifdef CONFIG_BTRFS_DEBUG ··· 737 750 btrfs_put_block_group(block_group); 738 751 } 739 752 740 - int btrfs_cache_block_group(struct btrfs_block_group *cache, int load_cache_only) 753 + int btrfs_cache_block_group(struct btrfs_block_group *cache, bool wait) 741 754 { 742 - DEFINE_WAIT(wait); 743 755 struct btrfs_fs_info *fs_info = cache->fs_info; 744 756 struct btrfs_caching_control *caching_ctl = NULL; 745 757 int ret = 0; ··· 771 785 } 772 786 WARN_ON(cache->caching_ctl); 773 787 cache->caching_ctl = caching_ctl; 774 - if (btrfs_test_opt(fs_info, SPACE_CACHE)) 775 - cache->cached = BTRFS_CACHE_FAST; 776 - else 777 - cache->cached = BTRFS_CACHE_STARTED; 788 + cache->cached = BTRFS_CACHE_STARTED; 778 789 cache->has_caching_ctl = 1; 779 790 spin_unlock(&cache->lock); 780 791 ··· 784 801 785 802 btrfs_queue_work(fs_info->caching_workers, &caching_ctl->work); 786 803 out: 787 - if (load_cache_only && caching_ctl) 788 - btrfs_wait_space_cache_v1_finished(cache, caching_ctl); 804 + if (wait && caching_ctl) 805 + ret = btrfs_caching_ctl_wait_done(cache, caching_ctl); 789 806 if (caching_ctl) 790 807 btrfs_put_caching_control(caching_ctl); 791 808 ··· 3295 3312 * space back to the block group, otherwise we will leak space. 3296 3313 */ 3297 3314 if (!alloc && !btrfs_block_group_done(cache)) 3298 - btrfs_cache_block_group(cache, 1); 3315 + btrfs_cache_block_group(cache, true); 3299 3316 3300 3317 byte_in_group = bytenr - cache->start; 3301 3318 WARN_ON(byte_in_group > cache->length);
+1 -3
fs/btrfs/block-group.h
··· 263 263 void btrfs_wait_nocow_writers(struct btrfs_block_group *bg); 264 264 void btrfs_wait_block_group_cache_progress(struct btrfs_block_group *cache, 265 265 u64 num_bytes); 266 - int btrfs_wait_block_group_cache_done(struct btrfs_block_group *cache); 267 - int btrfs_cache_block_group(struct btrfs_block_group *cache, 268 - int load_cache_only); 266 + int btrfs_cache_block_group(struct btrfs_block_group *cache, bool wait); 269 267 void btrfs_put_caching_control(struct btrfs_caching_control *ctl); 270 268 struct btrfs_caching_control *btrfs_get_caching_control( 271 269 struct btrfs_block_group *cache);
-1
fs/btrfs/ctree.h
··· 505 505 enum btrfs_caching_type { 506 506 BTRFS_CACHE_NO, 507 507 BTRFS_CACHE_STARTED, 508 - BTRFS_CACHE_FAST, 509 508 BTRFS_CACHE_FINISHED, 510 509 BTRFS_CACHE_ERROR, 511 510 };
+2 -3
fs/btrfs/dev-replace.c
··· 165 165 */ 166 166 if (btrfs_find_device(fs_info->fs_devices, &args)) { 167 167 btrfs_err(fs_info, 168 - "replace devid present without an active replace item"); 168 + "replace without active item, run 'device scan --forget' on the target device"); 169 169 ret = -EUCLEAN; 170 170 } else { 171 171 dev_replace->srcdev = NULL; ··· 1129 1129 up_write(&dev_replace->rwsem); 1130 1130 1131 1131 /* Scrub for replace must not be running in suspended state */ 1132 - ret = btrfs_scrub_cancel(fs_info); 1133 - ASSERT(ret != -ENOTCONN); 1132 + btrfs_scrub_cancel(fs_info); 1134 1133 1135 1134 trans = btrfs_start_transaction(root, 0); 1136 1135 if (IS_ERR(trans)) {
+6 -24
fs/btrfs/extent-tree.c
··· 2551 2551 return -EINVAL; 2552 2552 2553 2553 /* 2554 - * pull in the free space cache (if any) so that our pin 2555 - * removes the free space from the cache. We have load_only set 2556 - * to one because the slow code to read in the free extents does check 2557 - * the pinned extents. 2554 + * Fully cache the free space first so that our pin removes the free space 2555 + * from the cache. 2558 2556 */ 2559 - btrfs_cache_block_group(cache, 1); 2560 - /* 2561 - * Make sure we wait until the cache is completely built in case it is 2562 - * missing or is invalid and therefore needs to be rebuilt. 2563 - */ 2564 - ret = btrfs_wait_block_group_cache_done(cache); 2557 + ret = btrfs_cache_block_group(cache, true); 2565 2558 if (ret) 2566 2559 goto out; 2567 2560 ··· 2577 2584 if (!block_group) 2578 2585 return -EINVAL; 2579 2586 2580 - btrfs_cache_block_group(block_group, 1); 2581 - /* 2582 - * Make sure we wait until the cache is completely built in case it is 2583 - * missing or is invalid and therefore needs to be rebuilt. 2584 - */ 2585 - ret = btrfs_wait_block_group_cache_done(block_group); 2587 + ret = btrfs_cache_block_group(block_group, true); 2586 2588 if (ret) 2587 2589 goto out; 2588 2590 ··· 4387 4399 ffe_ctl->cached = btrfs_block_group_done(block_group); 4388 4400 if (unlikely(!ffe_ctl->cached)) { 4389 4401 ffe_ctl->have_caching_bg = true; 4390 - ret = btrfs_cache_block_group(block_group, 0); 4402 + ret = btrfs_cache_block_group(block_group, false); 4391 4403 4392 4404 /* 4393 4405 * If we get ENOMEM here or something else we want to ··· 6157 6169 6158 6170 if (end - start >= range->minlen) { 6159 6171 if (!btrfs_block_group_done(cache)) { 6160 - ret = btrfs_cache_block_group(cache, 0); 6161 - if (ret) { 6162 - bg_failed++; 6163 - bg_ret = ret; 6164 - continue; 6165 - } 6166 - ret = btrfs_wait_block_group_cache_done(cache); 6172 + ret = btrfs_cache_block_group(cache, true); 6167 6173 if (ret) { 6168 6174 bg_failed++; 6169 6175 bg_ret = ret;
+29 -4
fs/btrfs/extent_io.c
··· 3233 3233 u32 bio_size = bio->bi_iter.bi_size; 3234 3234 u32 real_size; 3235 3235 const sector_t sector = disk_bytenr >> SECTOR_SHIFT; 3236 - bool contig; 3236 + bool contig = false; 3237 3237 int ret; 3238 3238 3239 3239 ASSERT(bio); ··· 3242 3242 if (bio_ctrl->compress_type != compress_type) 3243 3243 return 0; 3244 3244 3245 - if (bio_ctrl->compress_type != BTRFS_COMPRESS_NONE) 3245 + 3246 + if (bio->bi_iter.bi_size == 0) { 3247 + /* We can always add a page into an empty bio. */ 3248 + contig = true; 3249 + } else if (bio_ctrl->compress_type == BTRFS_COMPRESS_NONE) { 3250 + struct bio_vec *bvec = bio_last_bvec_all(bio); 3251 + 3252 + /* 3253 + * The contig check requires the following conditions to be met: 3254 + * 1) The pages are belonging to the same inode 3255 + * This is implied by the call chain. 3256 + * 3257 + * 2) The range has adjacent logical bytenr 3258 + * 3259 + * 3) The range has adjacent file offset 3260 + * This is required for the usage of btrfs_bio->file_offset. 3261 + */ 3262 + if (bio_end_sector(bio) == sector && 3263 + page_offset(bvec->bv_page) + bvec->bv_offset + 3264 + bvec->bv_len == page_offset(page) + pg_offset) 3265 + contig = true; 3266 + } else { 3267 + /* 3268 + * For compression, all IO should have its logical bytenr 3269 + * set to the starting bytenr of the compressed extent. 3270 + */ 3246 3271 contig = bio->bi_iter.bi_sector == sector; 3247 - else 3248 - contig = bio_end_sector(bio) == sector; 3272 + } 3273 + 3249 3274 if (!contig) 3250 3275 return 0; 3251 3276
+2
fs/btrfs/file.c
··· 2482 2482 btrfs_set_file_extent_num_bytes(leaf, fi, num_bytes); 2483 2483 btrfs_set_file_extent_ram_bytes(leaf, fi, num_bytes); 2484 2484 btrfs_set_file_extent_offset(leaf, fi, 0); 2485 + btrfs_set_file_extent_generation(leaf, fi, trans->transid); 2485 2486 btrfs_mark_buffer_dirty(leaf); 2486 2487 goto out; 2487 2488 } ··· 2499 2498 btrfs_set_file_extent_num_bytes(leaf, fi, num_bytes); 2500 2499 btrfs_set_file_extent_ram_bytes(leaf, fi, num_bytes); 2501 2500 btrfs_set_file_extent_offset(leaf, fi, 0); 2501 + btrfs_set_file_extent_generation(leaf, fi, trans->transid); 2502 2502 btrfs_mark_buffer_dirty(leaf); 2503 2503 goto out; 2504 2504 }
+14
fs/btrfs/inode.c
··· 7694 7694 bool unlock_extents = false; 7695 7695 7696 7696 /* 7697 + * We could potentially fault if we have a buffer > PAGE_SIZE, and if 7698 + * we're NOWAIT we may submit a bio for a partial range and return 7699 + * EIOCBQUEUED, which would result in an errant short read. 7700 + * 7701 + * The best way to handle this would be to allow for partial completions 7702 + * of iocb's, so we could submit the partial bio, return and fault in 7703 + * the rest of the pages, and then submit the io for the rest of the 7704 + * range. However we don't have that currently, so simply return 7705 + * -EAGAIN at this point so that the normal path is used. 7706 + */ 7707 + if (!write && (flags & IOMAP_NOWAIT) && length > PAGE_SIZE) 7708 + return -EAGAIN; 7709 + 7710 + /* 7697 7711 * Cap the size of reads to that usually seen in buffered I/O as we need 7698 7712 * to allocate a contiguous array for the checksums. 7699 7713 */
+3 -2
fs/btrfs/root-tree.c
··· 349 349 key.offset = ref_id; 350 350 again: 351 351 ret = btrfs_search_slot(trans, tree_root, &key, path, -1, 1); 352 - if (ret < 0) 352 + if (ret < 0) { 353 + err = ret; 353 354 goto out; 354 - if (ret == 0) { 355 + } else if (ret == 0) { 355 356 leaf = path->nodes[0]; 356 357 ref = btrfs_item_ptr(leaf, path->slots[0], 357 358 struct btrfs_root_ref);
+4 -1
fs/btrfs/volumes.c
··· 2345 2345 2346 2346 ret = btrfs_get_bdev_and_sb(path, FMODE_READ, fs_info->bdev_holder, 0, 2347 2347 &bdev, &disk_super); 2348 - if (ret) 2348 + if (ret) { 2349 + btrfs_put_dev_args_from_path(args); 2349 2350 return ret; 2351 + } 2352 + 2350 2353 args->devid = btrfs_stack_device_id(&disk_super->dev_item); 2351 2354 memcpy(args->uuid, disk_super->dev_item.uuid, BTRFS_UUID_SIZE); 2352 2355 if (btrfs_fs_incompat(fs_info, METADATA_UUID))
+3
fs/btrfs/xattr.c
··· 371 371 const char *name, const void *buffer, 372 372 size_t size, int flags) 373 373 { 374 + if (btrfs_root_readonly(BTRFS_I(inode)->root)) 375 + return -EROFS; 376 + 374 377 name = xattr_full_name(handler, name); 375 378 return btrfs_setxattr_trans(inode, name, buffer, size, flags); 376 379 }