Skip to content

Commit 07eebd9

Browse files
committed
Merge tag 'for-6.19-rc6-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: - protect reading super block vs setting block size externally (found by syzbot) - make sure no transaction is started in read-only mode even with some rescue mount option combinations - fix checksum calculation of backup super blocks when block-group-tree is enabled - more extensive mount-time checks of device items that could be left after device replace and attempting degraded mount - fix build warning with -Wmaybe-uninitialized on loongarch64-gcc 12 * tag 'for-6.19-rc6-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: add extra device item checks at mount btrfs: fix missing fields in superblock backup with BLOCK_GROUP_TREE btrfs: reject new transactions if the fs is fully read-only btrfs: sync read disk super and set block size btrfs: fix Wmaybe-uninitialized warning in replay_one_buffer()
2 parents 6c79021 + 3430818 commit 07eebd9

5 files changed

Lines changed: 73 additions & 2 deletions

File tree

fs/btrfs/disk-io.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ static void backup_super_roots(struct btrfs_fs_info *info)
16611661
btrfs_set_backup_chunk_root_level(root_backup,
16621662
btrfs_header_level(info->chunk_root->node));
16631663

1664-
if (!btrfs_fs_compat_ro(info, BLOCK_GROUP_TREE)) {
1664+
if (!btrfs_fs_incompat(info, EXTENT_TREE_V2)) {
16651665
struct btrfs_root *extent_root = btrfs_extent_root(info, 0);
16661666
struct btrfs_root *csum_root = btrfs_csum_root(info, 0);
16671667

@@ -3255,6 +3255,15 @@ int btrfs_check_features(struct btrfs_fs_info *fs_info, bool is_rw_mount)
32553255
return 0;
32563256
}
32573257

3258+
static bool fs_is_full_ro(const struct btrfs_fs_info *fs_info)
3259+
{
3260+
if (!sb_rdonly(fs_info->sb))
3261+
return false;
3262+
if (unlikely(fs_info->mount_opt & BTRFS_MOUNT_FULL_RO_MASK))
3263+
return true;
3264+
return false;
3265+
}
3266+
32583267
int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_devices)
32593268
{
32603269
u32 sectorsize;
@@ -3363,6 +3372,10 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
33633372
if (btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_ERROR)
33643373
WRITE_ONCE(fs_info->fs_error, -EUCLEAN);
33653374

3375+
/* If the fs has any rescue options, no transaction is allowed. */
3376+
if (fs_is_full_ro(fs_info))
3377+
WRITE_ONCE(fs_info->fs_error, -EROFS);
3378+
33663379
/* Set up fs_info before parsing mount options */
33673380
nodesize = btrfs_super_nodesize(disk_super);
33683381
sectorsize = btrfs_super_sectorsize(disk_super);
@@ -3489,6 +3502,10 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
34893502
fs_info->generation == btrfs_super_uuid_tree_generation(disk_super))
34903503
set_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags);
34913504

3505+
if (unlikely(btrfs_verify_dev_items(fs_info))) {
3506+
ret = -EUCLEAN;
3507+
goto fail_block_groups;
3508+
}
34923509
ret = btrfs_verify_dev_extents(fs_info);
34933510
if (ret) {
34943511
btrfs_err(fs_info,

fs/btrfs/fs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@ enum {
264264
BTRFS_MOUNT_REF_TRACKER = (1ULL << 33),
265265
};
266266

267+
/* These mount options require a full read-only fs, no new transaction is allowed. */
268+
#define BTRFS_MOUNT_FULL_RO_MASK \
269+
(BTRFS_MOUNT_NOLOGREPLAY | \
270+
BTRFS_MOUNT_IGNOREBADROOTS | \
271+
BTRFS_MOUNT_IGNOREDATACSUMS | \
272+
BTRFS_MOUNT_IGNOREMETACSUMS | \
273+
BTRFS_MOUNT_IGNORESUPERFLAGS)
274+
267275
/*
268276
* Compat flags that we support. If any incompat flags are set other than the
269277
* ones specified below then we will fail to mount

fs/btrfs/tree-log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2798,7 +2798,7 @@ static int replay_one_buffer(struct extent_buffer *eb,
27982798

27992799
nritems = btrfs_header_nritems(eb);
28002800
for (wc->log_slot = 0; wc->log_slot < nritems; wc->log_slot++) {
2801-
struct btrfs_inode_item *inode_item;
2801+
struct btrfs_inode_item *inode_item = NULL;
28022802

28032803
btrfs_item_key_to_cpu(eb, &wc->log_key, wc->log_slot);
28042804

fs/btrfs/volumes.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,9 @@ struct btrfs_super_block *btrfs_read_disk_super(struct block_device *bdev,
13641364
(bytenr + BTRFS_SUPER_INFO_SIZE) >> PAGE_SHIFT);
13651365
}
13661366

1367+
filemap_invalidate_lock(mapping);
13671368
page = read_cache_page_gfp(mapping, bytenr >> PAGE_SHIFT, GFP_NOFS);
1369+
filemap_invalidate_unlock(mapping);
13681370
if (IS_ERR(page))
13691371
return ERR_CAST(page);
13701372

@@ -7257,6 +7259,7 @@ static int read_one_dev(struct extent_buffer *leaf,
72577259
return -EINVAL;
72587260
}
72597261
}
7262+
set_bit(BTRFS_DEV_STATE_ITEM_FOUND, &device->dev_state);
72607263
set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
72617264
if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) &&
72627265
!test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) {
@@ -8082,6 +8085,45 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)
80828085
return verify_chunk_dev_extent_mapping(fs_info);
80838086
}
80848087

8088+
/*
8089+
* Ensure that all devices registered in the fs have their device items in the
8090+
* chunk tree.
8091+
*
8092+
* Return true if unexpected device is found.
8093+
* Return false otherwise.
8094+
*/
8095+
bool btrfs_verify_dev_items(const struct btrfs_fs_info *fs_info)
8096+
{
8097+
struct btrfs_fs_devices *seed_devs;
8098+
struct btrfs_device *dev;
8099+
bool ret = false;
8100+
8101+
mutex_lock(&uuid_mutex);
8102+
list_for_each_entry(dev, &fs_info->fs_devices->devices, dev_list) {
8103+
if (!test_bit(BTRFS_DEV_STATE_ITEM_FOUND, &dev->dev_state)) {
8104+
btrfs_err(fs_info,
8105+
"devid %llu path %s is registered but not found in chunk tree",
8106+
dev->devid, btrfs_dev_name(dev));
8107+
ret = true;
8108+
}
8109+
}
8110+
list_for_each_entry(seed_devs, &fs_info->fs_devices->seed_list, seed_list) {
8111+
list_for_each_entry(dev, &seed_devs->devices, dev_list) {
8112+
if (!test_bit(BTRFS_DEV_STATE_ITEM_FOUND, &dev->dev_state)) {
8113+
btrfs_err(fs_info,
8114+
"devid %llu path %s is registered but not found in chunk tree",
8115+
dev->devid, btrfs_dev_name(dev));
8116+
ret = true;
8117+
}
8118+
}
8119+
}
8120+
mutex_unlock(&uuid_mutex);
8121+
if (ret)
8122+
btrfs_err(fs_info,
8123+
"remove the above devices or use 'btrfs device scan --forget <dev>' to unregister them before mount");
8124+
return ret;
8125+
}
8126+
80858127
/*
80868128
* Check whether the given block group or device is pinned by any inode being
80878129
* used as a swapfile.

fs/btrfs/volumes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ enum btrfs_raid_types {
100100
#define BTRFS_DEV_STATE_FLUSH_SENT (4)
101101
#define BTRFS_DEV_STATE_NO_READA (5)
102102

103+
/* Set when the device item is found in chunk tree, used to catch unexpected registered device. */
104+
#define BTRFS_DEV_STATE_ITEM_FOUND (7)
105+
103106
/* Special value encoding failure to write primary super block. */
104107
#define BTRFS_SUPER_PRIMARY_WRITE_ERROR (INT_MAX / 2)
105108

@@ -893,6 +896,7 @@ enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags
893896
int btrfs_bg_type_to_factor(u64 flags);
894897
const char *btrfs_bg_type_to_raid_name(u64 flags);
895898
int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
899+
bool btrfs_verify_dev_items(const struct btrfs_fs_info *fs_info);
896900
bool btrfs_repair_one_zone(struct btrfs_fs_info *fs_info, u64 logical);
897901

898902
bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr);

0 commit comments

Comments
 (0)