Skip to content

Commit 13d6d86

Browse files
committed
btrfs: on unknown chunk allocation policy fallback to regular
We have only two chunk allocation policies right now and the switch/cases don't handle an unknown one properly. The error is in the impossible category (the policy is stored only in memory), we don't have to BUG(), falling back to regular policy should be safe. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 3329d3d commit 13d6d86

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

fs/btrfs/volumes.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,9 @@ static bool contains_pending_extent(struct btrfs_device *device, u64 *start,
15281528
static u64 dev_extent_search_start(struct btrfs_device *device)
15291529
{
15301530
switch (device->fs_devices->chunk_alloc_policy) {
1531+
default:
1532+
btrfs_warn_unknown_chunk_allocation(device->fs_devices->chunk_alloc_policy);
1533+
fallthrough;
15311534
case BTRFS_CHUNK_ALLOC_REGULAR:
15321535
return BTRFS_DEVICE_RANGE_RESERVED;
15331536
case BTRFS_CHUNK_ALLOC_ZONED:
@@ -1537,8 +1540,6 @@ static u64 dev_extent_search_start(struct btrfs_device *device)
15371540
* for superblock logging.
15381541
*/
15391542
return 0;
1540-
default:
1541-
BUG();
15421543
}
15431544
}
15441545

@@ -1618,6 +1619,9 @@ static bool dev_extent_hole_check(struct btrfs_device *device, u64 *hole_start,
16181619
}
16191620

16201621
switch (device->fs_devices->chunk_alloc_policy) {
1622+
default:
1623+
btrfs_warn_unknown_chunk_allocation(device->fs_devices->chunk_alloc_policy);
1624+
fallthrough;
16211625
case BTRFS_CHUNK_ALLOC_REGULAR:
16221626
/* No extra check */
16231627
break;
@@ -1632,8 +1636,6 @@ static bool dev_extent_hole_check(struct btrfs_device *device, u64 *hole_start,
16321636
continue;
16331637
}
16341638
break;
1635-
default:
1636-
BUG();
16371639
}
16381640

16391641
break;
@@ -5199,14 +5201,15 @@ static void init_alloc_chunk_ctl(struct btrfs_fs_devices *fs_devices,
51995201
ctl->ndevs = 0;
52005202

52015203
switch (fs_devices->chunk_alloc_policy) {
5204+
default:
5205+
btrfs_warn_unknown_chunk_allocation(fs_devices->chunk_alloc_policy);
5206+
fallthrough;
52025207
case BTRFS_CHUNK_ALLOC_REGULAR:
52035208
init_alloc_chunk_ctl_policy_regular(fs_devices, ctl);
52045209
break;
52055210
case BTRFS_CHUNK_ALLOC_ZONED:
52065211
init_alloc_chunk_ctl_policy_zoned(fs_devices, ctl);
52075212
break;
5208-
default:
5209-
BUG();
52105213
}
52115214
}
52125215

@@ -5395,12 +5398,13 @@ static int decide_stripe_size(struct btrfs_fs_devices *fs_devices,
53955398
ctl->ndevs = min(ctl->ndevs, ctl->devs_max);
53965399

53975400
switch (fs_devices->chunk_alloc_policy) {
5401+
default:
5402+
btrfs_warn_unknown_chunk_allocation(fs_devices->chunk_alloc_policy);
5403+
fallthrough;
53985404
case BTRFS_CHUNK_ALLOC_REGULAR:
53995405
return decide_stripe_size_regular(ctl, devices_info);
54005406
case BTRFS_CHUNK_ALLOC_ZONED:
54015407
return decide_stripe_size_zoned(ctl, devices_info);
5402-
default:
5403-
BUG();
54045408
}
54055409
}
54065410

fs/btrfs/volumes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,11 @@ static inline const char *btrfs_dev_name(const struct btrfs_device *device)
846846
return rcu_str_deref(device->name);
847847
}
848848

849+
static inline void btrfs_warn_unknown_chunk_allocation(enum btrfs_chunk_allocation_policy pol)
850+
{
851+
WARN_ONCE(1, "unknown allocation policy %d, fallback to regular", pol);
852+
}
853+
849854
void btrfs_commit_device_sizes(struct btrfs_transaction *trans);
850855

851856
struct list_head * __attribute_const__ btrfs_get_fs_uuids(void);

0 commit comments

Comments
 (0)