Merge tag 'for-7.4-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux

Pull btrfs fixes from David Sterba:
 "A btrfs fixes. The ones that could have some user noticeable impact
  are enumerated, the rest is one-liners.

   - fix chattr failing on files with nodatasum and compress flags

   - fix inode defrag status with concurrent truncation so it's not
     skipped in defrag in the future

   - fix merging compressed extent in fiemap output

   - fix deleting wrong subvolume by id if it gets renamed during the
     ioctl

   - error handling fixes: sysfs, quotas, fs-verity, scrub, zoned mode"

* tag 'for-7.4-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux:
  btrfs: zoned: fix double free of bitmaps on clone failure
  btrfs: prevent deleting the wrong subvolume by ID
  btrfs: scrub: fix race between scrub and scrub progress ioctl
  btrfs: scrub: fix race leading to use-after-free in the scrub progress ioctl
  btrfs: scrub: fix lost wakeup and hang when cancelling a scrub that is finishing
  btrfs: scrub: fix lost error return value when scrubbing raid56 parity stripe
  btrfs: fix fiemap merging compressed extents
  btrfs: fix the fsverity callback where unexpected range is verified
  btrfs: verity: propagate orphan insertion errors when enabling verity
  btrfs: sysfs: restore NOFS context on early return in btrfs_sysfs_add_block_group_type()
  btrfs: defrag: prevent inode truncated to zero from not being defragged again
  btrfs: cleanup dirty_cowonly_roots during btrfs_free_fs_roots()
  btrfs: cleanup qgroup swapped blocks at root release
  btrfs: always remove quota_root from dirty_cowonly_roots
  btrfs: unwind device add when sysfs registration fails
  btrfs: fix chattr failing on nodatasum files that have the compress flag
This commit is contained in:
Linus Torvalds
2026-11-07 13:52:02 -08:00
11 changed files with 97 additions and 15 deletions
+10 -1
View File
@@ -242,13 +242,22 @@ again:
goto cleanup;
}
/*
* Clear the flag right away. On the first iteration (cur == 0) if the
* inode happened to have been truncated to 0 after it was added to
* autodefrag and before we were called, then we need to clear the flag,
* otherwise if writes are done to the inode we won't be able to add it
* to autodefrag again (unless the inode is evicted, loaded again, and
* small writes to it happen again).
*/
clear_bit(BTRFS_INODE_IN_DEFRAG, &inode->runtime_flags);
if (cur >= i_size_read(&inode->vfs_inode)) {
iput(&inode->vfs_inode);
goto cleanup;
}
/* Do a chunk of defrag */
clear_bit(BTRFS_INODE_IN_DEFRAG, &inode->runtime_flags);
memset(&range, 0, sizeof(range));
range.len = (u64)-1;
range.start = cur;
+20
View File
@@ -1847,6 +1847,7 @@ void btrfs_put_root(struct btrfs_root *root)
if (root->anon_dev)
free_anon_bdev(root->anon_dev);
free_root_extent_buffers(root);
btrfs_qgroup_clean_swapped_blocks(root);
#ifdef CONFIG_BTRFS_DEBUG
spin_lock(&root->fs_info->fs_roots_radix_lock);
list_del_init(&root->leak_list);
@@ -1862,6 +1863,25 @@ void btrfs_free_fs_roots(struct btrfs_fs_info *fs_info)
struct btrfs_root *gang[8];
int i;
/*
* Some dirty roots may still be linked to dirty_cowonly_roots after
* the transaction is aborted. Cleanup them here.
*/
while (!list_empty(&fs_info->dirty_cowonly_roots)) {
struct btrfs_root *root;
root = list_first_entry(&fs_info->dirty_cowonly_roots,
struct btrfs_root, dirty_list);
list_del_init(&root->dirty_list);
/*
* The dirty_log_pages should never be populated for
* cowonly trees.
*/
spin_lock(&root->dirty_log_pages.lock);
ASSERT(RB_EMPTY_ROOT(&root->dirty_log_pages.state));
spin_unlock(&root->dirty_log_pages.lock);
}
while (!list_empty(&fs_info->dead_roots)) {
gang[0] = list_first_entry(&fs_info->dead_roots,
struct btrfs_root, root_list);
+1 -1
View File
@@ -504,7 +504,7 @@ static bool btrfs_verify_folio(struct fsverity_info *vi, struct folio *folio,
if (!vi || btrfs_folio_test_uptodate(fs_info, folio, start, len))
return true;
return fsverity_verify_folio(vi, folio);
return fsverity_verify_blocks(vi, folio, len, offset_in_folio(folio, start));
}
static void end_folio_read(struct fsverity_info *vi, struct folio *folio,
+2 -1
View File
@@ -228,7 +228,8 @@ static int emit_fiemap_extent(struct fiemap_extent_info *fieinfo,
*
* 3) Share same flags
*/
if (cache->offset + cache->len == offset &&
if (!(flags & FIEMAP_EXTENT_ENCODED) &&
cache->offset + cache->len == offset &&
cache->phys + cache->len == phys &&
cache->flags == flags) {
cache->len += len;
+24
View File
@@ -375,6 +375,19 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap,
}
}
/*
* Callers write back the whole flag set, so only touch the compression
* flags and the compression property if FS_COMPR_FL or FS_NOCOMP_FL
* changes.
*/
if (!((fsflags ^ old_fsflags) & (FS_COMPR_FL | FS_NOCOMP_FL))) {
/* 1 item for the inode */
trans = btrfs_start_transaction(root, 1);
if (IS_ERR(trans))
return PTR_ERR(trans);
goto update_flags;
}
/*
* The COMPRESS flag can only be changed by users, while the NOCOMPRESS
* flag may be changed automatically if compression code won't make
@@ -2380,6 +2393,17 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
inode = d_inode(dentry);
dest = BTRFS_I(inode)->root;
/*
* A concurrent rename may have changed which subvolume the name
* refers to. Verify that the resolved ID still matches the requested ID.
*/
if (destroy_v2 && (vol_args2->flags & BTRFS_SUBVOL_SPEC_BY_ID) &&
btrfs_root_id(dest) != vol_args2->subvolid) {
ret = -EAGAIN;
goto out_end_removing;
}
if (!capable(CAP_SYS_ADMIN)) {
/*
* Regular user. Only allow this with a special mount
+7 -5
View File
@@ -1440,10 +1440,6 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
goto out;
}
spin_lock(&fs_info->trans_lock);
list_del(&quota_root->dirty_list);
spin_unlock(&fs_info->trans_lock);
btrfs_tree_lock(quota_root->node);
btrfs_clear_buffer_dirty(trans, quota_root->node);
btrfs_tree_unlock(quota_root->node);
@@ -1454,7 +1450,13 @@ int btrfs_quota_disable(struct btrfs_fs_info *fs_info)
btrfs_abort_transaction(trans, ret);
out:
btrfs_put_root(quota_root);
if (quota_root) {
spin_lock(&fs_info->trans_lock);
list_del(&quota_root->dirty_list);
spin_unlock(&fs_info->trans_lock);
btrfs_put_root(quota_root);
}
mutex_unlock(&fs_info->qgroup_ioctl_lock);
if (ret && trans)
btrfs_end_transaction(trans);
+17 -5
View File
@@ -2250,7 +2250,7 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
"scrub: unrepaired sectors detected, full stripe %llu data stripe %u errors %*pbl",
full_stripe_start, i, stripe->nr_sectors,
&error);
return ret;
return -EIO;
}
bitmap_or(&extent_bitmap, &extent_bitmap, &has_extent,
stripe->nr_sectors);
@@ -3171,7 +3171,6 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
memalloc_nofs_restore(nofs_flag);
atomic_dec(&fs_info->scrubs_running);
wake_up(&fs_info->scrub_pause_wait);
if (progress)
memcpy(progress, &sctx->stat, sizeof(*progress));
@@ -3184,6 +3183,13 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
dev->scrub_ctx = NULL;
mutex_unlock(&fs_info->scrub_lock);
/*
* We have set dev->scrub_ctx to NULL, now do the wakeup as a concurrent
* scrub cancel (btrfs_scrub_cancel_dev()) waits for dev->scrub_ctx to
* be set to NULL.
*/
wake_up(&fs_info->scrub_pause_wait);
scrub_workers_put(fs_info);
scrub_put_ctx(sctx);
@@ -3289,10 +3295,16 @@ int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid,
mutex_lock(&fs_info->fs_devices->device_list_mutex);
dev = btrfs_find_device(fs_info->fs_devices, &args);
if (dev)
if (dev) {
mutex_lock(&fs_info->scrub_lock);
sctx = dev->scrub_ctx;
if (sctx)
memcpy(progress, &sctx->stat, sizeof(*progress));
if (sctx) {
spin_lock(&sctx->stat_lock);
memcpy(progress, &sctx->stat, sizeof(*progress));
spin_unlock(&sctx->stat_lock);
}
mutex_unlock(&fs_info->scrub_lock);
}
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
return dev ? (sctx ? 0 : -ENOTCONN) : -ENODEV;
+4
View File
@@ -1741,6 +1741,7 @@ void btrfs_sysfs_add_block_group_type(struct btrfs_block_group *cache)
if (space_info->block_group_kobjs[index]) {
spin_unlock(&space_info->lock);
kobject_put(&rkobj->kobj);
memalloc_nofs_restore(nofs_flag);
return;
} else {
space_info->block_group_kobjs[index] = &rkobj->kobj;
@@ -2049,6 +2050,9 @@ int btrfs_sysfs_add_device(struct btrfs_device *device)
ret = kobject_init_and_add(&device->devid_kobj, &devid_ktype,
devinfo_kobj, "%llu", device->devid);
if (ret) {
if (device->bdev)
sysfs_remove_link(devices_kobj,
bdev_kobj(device->bdev)->name);
kobject_put(&device->devid_kobj);
btrfs_warn(device->fs_info,
"devinfo init for devid %llu failed: %d",
+1 -1
View File
@@ -610,7 +610,7 @@ static int btrfs_begin_enable_verity(struct file *filp)
set_bit(BTRFS_INODE_VERITY_IN_PROGRESS, &inode->runtime_flags);
btrfs_end_transaction(trans);
return 0;
return ret;
}
/*
+6 -1
View File
@@ -3097,7 +3097,11 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
mutex_unlock(&fs_info->chunk_mutex);
/* Add sysfs device entry */
btrfs_sysfs_add_device(device);
ret = btrfs_sysfs_add_device(device);
if (ret) {
mutex_unlock(&fs_devices->device_list_mutex);
goto error_unwind_device;
}
mutex_unlock(&fs_devices->device_list_mutex);
@@ -3178,6 +3182,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
error_sysfs:
btrfs_sysfs_remove_device(device);
error_unwind_device:
mutex_lock(&fs_info->fs_devices->device_list_mutex);
if (seeding_dev)
btrfs_assign_next_active_device(device, seed_devices->latest_dev);
+5
View File
@@ -645,6 +645,11 @@ struct btrfs_zoned_device_info *btrfs_clone_dev_zone_info(struct btrfs_device *o
if (!zone_info)
return NULL;
/* Don't let the error path free the bitmaps still owned by @orig_dev. */
zone_info->seq_zones = NULL;
zone_info->empty_zones = NULL;
zone_info->active_zones = NULL;
zone_info->seq_zones = bitmap_zalloc(zone_info->nr_zones, GFP_KERNEL);
if (!zone_info->seq_zones)
goto out;