btrfs: zoned: RAID1 block groups with missing or stale stripes
v2 cover btrfs: zoned: RAID1 block groups with missing or stale stripes
btrfs_load_block_group_raid1() compares the active state and the write pointer of each present stripe with stripe 0's, and takes the zone capacity from stripes 0 and 1. But stripe 0 can be missing, any stripe can be behind the others on a degraded mount, and the full zones of a block group can report different capacities.
- 1/5 compares the active state with the first present stripe. With stripe 0 missing, such block groups were left off the active list, and writes to them could hang.
- 2/5 takes the zone capacity from all present stripes. RAID1C3 and RAID1C4 block groups failed to load with stripes 0 and 1 missing, once they held data, and were written past a smaller third or fourth stripe.
- 3/5 takes a full zone with more capacity than the block group as written up to the block group's capacity, unless an extent ends past it. Before, a regular mount failed on such block groups.
- 4/5 allocates from the highest write pointer on degraded mounts. Stripe 0's can be behind, and new extents then went over committed ones. It also lets a regular mount load a block group whose stripe 0 is on an offline or read-only zone.
- 5/5 adds self-test cases.
v2:
- 2/5: was 3/4, moved before 3/5, which needs the block group's capacity. It takes the capacity from all present stripes now
- 3/5: new. v1 failed a degraded mount with all devices present and full zones of different capacities, which loaded before when stripe 0 had the smallest one (found in an LLM review). Zones with an extent past the capacity are not capped
- 4/5 (was 2/4): mark a metadata block group with a mismatch active if any of its zones is. With an empty first zone, it stayed inactive and warned at its next write (reported by Sashiko)
- 5/5: add cases with an empty first zone, with different zone capacities and with a failed zone report, and a capacity per stripe. Renamed, as 6 of the 14 new cases are on a regular mount
- rebased on for-next 184fa2c40f5c
v1: https://lore.kernel.org/linux-btrfs/[email protected]/
Miroslav Cimerman (5):
btrfs: zoned: take the RAID1 active state from the first present
stripe
btrfs: zoned: take the RAID1 zone capacity from all present stripes
btrfs: zoned: cap full RAID1 zones at the block group's capacity
btrfs: zoned: use the highest RAID1 write pointer on degraded mounts
btrfs: tests: zoned: add RAID1 cases with missing or stale stripes
fs/btrfs/tests/zoned-tests.c | 203 ++++++++++++++++++++++++++++++++++- fs/btrfs/zoned.c | 102 +++++++++++++++--- 2 files changed, 291 insertions(+), 14 deletions(-)
base-commit: 184fa2c40f5c50afb1d8bf900eafadf450db392e
Signature · 1 line
2.53.0
PATCH v2 2/5 btrfs: zoned: take the RAID1 zone capacity from all present stripes
btrfs_load_block_group_raid1() takes the zone capacity of a block group from stripes 0 and 1 only, also when it creates one. RAID1C3 and RAID1C4 have more stripes, and that goes wrong in two ways.
A missing device has a capacity of 0, which min_not_zero() skips, but with stripes 0 and 1 both missing the capacity is 0. Once the block group has been written to, it fails to load, and a degraded mount fails although a copy is left:
BTRFS error (device nb4): zoned: invalid write pointer 98304 (larger than zone capacity 0) in block group 83886080 BTRFS error (device nb4): zoned: failed to load zone info of bg 83886080
BTRFS error (device nb4): failed to read block groups: -EIO
A third or fourth stripe with a smaller capacity is ignored, so the block group is written past the end of that stripe's zone, and those writes fail:
I/O error, dev nb2, sector 122880 op 0x7:(ZONE_APPEND) flags 0xc800 phys_seg 2 prio class 2
Take the smallest capacity of all present stripes.
RAID1C3 and RAID1C4 block groups already written past a smaller third or fourth stripe failed a regular mount before. Now a degraded mount with all devices present refuses them too, where it loaded them with the larger capacity. A degraded mount without the device with the smaller capacity still loads them.
---
v2: was 3/4. Takes the smallest capacity of all present stripes now, not only when stripes 0 and 1 are missing. A smaller third or fourth stripe was ignored too.
Found in an LLM review of this series. The fix and the commit message were prepared with the help of an LLM, which also tested it. I reviewed everything.
The next patch takes care of full zones that report different capacities.
fs/btrfs/zoned.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/zoned.c +3 -1
@@ -1532,7 +1532,9 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg, }/* In case a device is missing we have a cap of 0, so don't use it. */ - bg->zone_capacity =min_not_zero (zone_info[0 ].capacity, zone_info[1 ].capacity); + bg->zone_capacity =0 ; +for (i =0 ; i < map->num_stripes; i++) + bg->zone_capacity =min_not_zero (bg->zone_capacity, zone_info[i].capacity);/* * When the last extent is removed, last_alloc can be smaller than the other write
Signature · 1 line
2.53.0
PATCH v2 1/5 btrfs: zoned: take the RAID1 active state from the first present stripe
In reply to Miroslav Cimermanbtrfs_load_block_group_raid1() compares the active state of each present stripe's zone with stripe 0's. A missing device has no active zones. So with stripe 0 missing, an active zone of a present stripe always mismatches. A degraded mount then neither activates the block group nor marks it active. The block group is not on the list of active block groups, while its zones are active and count against their devices' active zone limits.
If it is a data block group, writing data to it tries to activate it, which fails when the active zones left are reserved for metadata. With no other data block group with room left, the allocation then returns -EAGAIN, and the write waits for a zone finish forever:
task:dd state:D
btrfs_new_extent_direct
btrfs_dio_iomap_next
iomap_iter
__iomap_dio_rw
btrfs_direct_write
btrfs_do_write_iter
vfs_write
If it is a metadata block group, writing tree blocks to it activates it with a warning:
WARNING: fs/btrfs/zoned.c:2451 at btrfs_zone_activate+0x72a/0xa60, CPU#1: btrfs/157 btrfs_check_meta_write_pointer write_meta_extent_buffer btree_writepages
Compare with the first present stripe instead.
---
Found by an LLM while testing this series. The fix and the commit message were prepared with the help of an LLM, which also tested it. I reviewed everything.
A mismatch between present stripes is not changed, apart from metadata block groups with a stripe behind, see 4/5. On a degraded mount, depending on which stripe comes first, the block group is marked active at load without the zone of the other stripe accounted, or activated at its first write if it has room left, which can fail as above when no active zone is left. Both happened before too.
btrfs_load_block_group_raid10() compares the active state with stripe 0's too, but activates the block group on a mismatch instead of skipping it. With stripe 0 missing, that warns at mount for a metadata block group, and can fail the mount for a data block group when no active zone is left. RAID10 also adds a zone capacity of 0 for a missing first stripe of a pair, which fails the degraded mount once a block group holds more than the capacity that is left. Neither is changed in this series. I will send fixes for both.
fs/btrfs/zoned.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/btrfs/zoned.c +6 -2
@@ -1522,6 +1522,7 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg, u64 last_alloc) {struct btrfs_fs_info *fs_info = bg->fs_info; +int first =-1 ;int i;if ((map->type &BTRFS_BLOCK_GROUP_DATA ) && !fs_info->stripe_root) {
@@ -1555,6 +1556,9 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg,if (zone_info[i].alloc_offset ==WP_CONVENTIONAL ) zone_info[i].alloc_offset = last_alloc; +if (first <0 ) + first = i; +if (unlikely ((zone_info[0 ].alloc_offset != zone_info[i].alloc_offset) && !btrfs_test_opt (fs_info,DEGRADED ))) { btrfs_err(fs_info,
@@ -1562,13 +1566,13 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg, btrfs_bg_type_to_raid_name(map->type));return -EIO ; } -if (test_bit (0 , active) !=test_bit (i, active)) { +if (test_bit (first, active) !=test_bit (i, active)) {if (unlikely (!btrfs_test_opt (fs_info,DEGRADED ) && !btrfs_zone_activate (bg))) {return -EIO ; } }else { -if (test_bit (0 , active)) +if (test_bit (first, active))set_bit (BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE , &bg->runtime_flags); } }
Signature · 1 line
2.53.0
PATCH v2 4/5 btrfs: zoned: use the highest RAID1 write pointer on degraded mounts
In reply to Miroslav CimermanThe write pointers of a RAID1 block group's stripes can differ after a crash, or when a device missed committed writes and came back. A regular mount fails then, and commit b0c26f479926 ("btrfs: zoned:
return EIO on RAID1 block group write pointer mismatch") relies on manual intervention: a degraded mount and a full balance. On a degraded mount, btrfs_load_block_group_raid1() ignores the mismatch and takes the allocation offset from stripe 0. If stripe 0 is behind, new extents are allocated over committed ones:
stripe 0 (behind) | a | a | | | stripe 1 | a | a | b | b |
^
allocation offset from stripe 0, new extents go over b
BTRFS error (device nb2): failed to run delayed ref for logical 155189248 num_bytes 1048576 type 178 action 1 ref_mod 1: -17 BTRFS error (device nb2 state A): Transaction 18 aborted (-EEXIST)
or, with CONFIG_BTRFS_ASSERT, an assertion in the free space tree fails:
assertion failed: start >= found_start && end <= found_end, in fs/btrfs/free-space-tree.c:742
A stripe that is not behind has all committed extents below its write pointer, the highest one. If no present stripe is up to date, the highest write pointer can still be below committed extents, as before. On a degraded mount, take the allocation offset from it, and warn about the block group. Until a balance copies the block group to new zones, reads of what the stripes behind miss fail their checksums and go to the other copies. Writes to the stripes behind can fail, as they already could when stripe 0 was ahead. Data without checksums can return what a stripe behind holds there.
Once a block group with a stripe behind is full and finished, all its zones report their capacity, and a later regular mount no longer sees that a stripe was behind. Only the warning of the degraded mount tells that a balance is needed.
The active state still comes from the first present stripe. If that is an empty zone behind a written one, a metadata block group is not marked active although it holds tree blocks. btrfs_zone_activate() then warns at its next write: it expects a block group that is not active to be empty. Tree blocks are written at the highest write pointer, which fails on a stripe behind without opening its zone. So mark a metadata block group with a mismatch active if any of its zones is. Data is written by zone append to each stripe. So a data block group whose first present zone is empty is still activated with all its zones at its first allocation, if it has room and its devices have active zones left.
Compare the write pointers with the first present stripe, and leave missing stripes out of the highest one. With stripe 0 missing, the allocation offset came from the last stripe. In RAID1C3 and RAID1C4 that stripe can be missing as well, and the block group then failed to load.
An offline or read-only zone, or one whose zone report fails with -EIO or -EOPNOTSUPP, has no write pointer, as with a missing stripe. With stripe 0's zone in that state, a regular mount failed on the comparison, while with another stripe's zone in that state it loaded. Now both load.
---
v2 (was 2/4): mark a metadata block group with a mismatch active if any of its zones is. Sashiko found that with an empty first zone, it stayed inactive and warned at its next write.
Found with FuzzyRAID, a fault-injection tester for RAID that is not public at the moment. The analysis, the fix and the commit message were prepared with the help of an LLM, which also tested it. I reviewed everything.
Making such a block group unallocatable instead, as b1934cd60695 did, was replaced by failing the mount in b0c26f479926. With the highest write pointer, the degraded mount and balance that b0c26f479926 describes keep working, and in testing, a regular mount works again after the balance.
A regular mount now loads a block group whose stripe 0 is on an offline or read-only zone. Finishing the block group later fails on that zone, which, for a metadata block group, turns the filesystem read-only. It already did so with such a zone on another stripe.
Scrub on such a degraded mount finds what the stripes behind miss, but does not repair it, as zoned repairs are skipped on degraded mounts. Qu agreed to drop that skip in the thread of "btrfs: scrub: don't count zoned repairs as corrected on a degraded mount", and I will send that as its own patch:
https://lore.kernel.org/linux-btrfs/[email protected]/
In testing, scrub then relocated the block groups where it found errors, and a regular mount worked without a balance.
A degraded mount without the stripe with the smallest zone capacity uses a larger one and can write past the smallest. This is not changed here. With that stripe back, a degraded mount now fails to load such a block group. Before, if that stripe was stripe 0, it took stripe 0's write pointer, below the extents written while it was missing.
fs/btrfs/zoned.c | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-)
fs/btrfs/zoned.c +38 -9
@@ -1522,6 +1522,8 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg, u64 last_alloc) {struct btrfs_fs_info *fs_info = bg->fs_info; +u64 highest =0 ; +bool mismatch = false;int first =-1 ;int i;
@@ -1575,13 +1577,24 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg,if (first <0 ) first = i; -if (unlikely ((zone_info[0 ].alloc_offset != zone_info[i].alloc_offset) && - !btrfs_test_opt (fs_info,DEGRADED ))) { -btrfs_err (fs_info, -"zoned: write pointer offset mismatch of zones in %s profile" , -btrfs_bg_type_to_raid_name (map->type)); -return -EIO ; +if (zone_info[first].alloc_offset != zone_info[i].alloc_offset) { +/* +* A stripe is behind the others after a crash, or when +* its device missed committed writes and came back. +* This fails a regular mount. A degraded one allocates +* from the highest write pointer: committed extents are +* below it, unless all present stripes are behind. +*/ +if (unlikely (!btrfs_test_opt (fs_info,DEGRADED ))) { +btrfs_err (fs_info, +"zoned: write pointer offset mismatch of zones in %s profile" , +btrfs_bg_type_to_raid_name (map->type)); +return -EIO ; + } + mismatch = true; } + highest =max (highest, zone_info[i].alloc_offset); +if (test_bit (first, active) !=test_bit (i, active)) {if (unlikely (!btrfs_test_opt (fs_info,DEGRADED ) && !btrfs_zone_activate (bg))) {
@@ -1593,10 +1606,26 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg, } } -if (zone_info[0 ].alloc_offset !=WP_MISSING_DEV ) - bg->alloc_offset = zone_info[0 ].alloc_offset; +if (mismatch) { +btrfs_warn (fs_info, +"zoned: write pointer mismatch in %s block group %llu, using the highest" , +btrfs_bg_type_to_raid_name (map->type), bg->start); +/* +* Metadata is written at the highest write pointer, which fails +* on a stripe behind and opens no zone there. +* btrfs_zone_activate() expects an inactive block group to be +* empty, but this one holds metadata, so it is active if any of +* its zones is. +*/ +if (!(map->type &BTRFS_BLOCK_GROUP_DATA ) && + !bitmap_empty (active, map->num_stripes)) +set_bit (BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE , &bg->runtime_flags); + } + +if (first >=0 ) + bg->alloc_offset = highest;else - bg->alloc_offset = zone_info[i -1 ].alloc_offset; + bg->alloc_offset =WP_MISSING_DEV ;return 0 ; }
Signature · 1 line
2.53.0
PATCH v2 3/5 btrfs: zoned: cap full RAID1 zones at the block group's capacity
In reply to Miroslav CimermanThe zone capacity of a RAID1 block group is the smallest of its stripes'. Finishing the block group finishes its zones on devices with an active zone limit, and a full zone reports its own capacity as its write pointer. With zone capacities that differ between the devices, the write pointers of a full block group then differ, and the next mount fails:
BTRFS error (device nb2): zoned: write pointer offset mismatch of zones in raid1 profile BTRFS error (device nb2): zoned: failed to load zone info of bg 150994944
A degraded mount with all devices present takes stripe 0's write pointer, and fails too unless stripe 0 has the smallest capacity:
BTRFS error (device nb2): zoned: invalid write pointer 14680064 (larger than zone capacity 12582912) in block group 150994944
Take a full zone with a larger capacity as written up to the block group's capacity, unless an extent of the block group ends past it. Then the block group was written with a larger capacity, e.g. by a degraded mount without the stripe with the smallest capacity, or in RAID1C3 and RAID1C4 before the previous patch. Such a block group still fails a regular mount. Get the end of the last extent from the extent tree when the capacities differ, as for conventional zones.
---
v2: new. An LLM review of v1 found that v1 failed a degraded mount here, where it loaded before. A later review found that capping zones with extents past the capacity let a regular mount accept a stale stripe. The fix and the commit message were prepared with the help of an LLM, which also tested it. I reviewed everything.
btrfs sets an active zone limit for devices that report none, so the zones are finished on almost every device. DUP, RAID0 and RAID10 are not changed here. RAID0 and RAID10 add up the capacities of their stripes. In testing with different zone capacities, writes past the smallest one failed, and so did the next mount. RAID10 also compares the two stripes of a pair as RAID1 did. I will send fixes for RAID0 and RAID10 with the RAID10 fixes mentioned in 1/5.
Blocks of the log tree are never in the extent tree. File data is never only in the log tree here: zoned RAID1 data needs the raid-stripe-tree, and an fsync of new RAID1 data commits the transaction. A tree-log block group written past the capacity only by log tree blocks would still be capped, and log replay would then move the allocation offset past the capacity. I was not able to get that tested: in my tests on null_blk, every fsync on a zoned filesystem committed the transaction, also for changes without new data.
Not changed here, and found only by reading the code: with different capacities, a crash between the last write to a block group and its zone finish leaves the smaller zone FULL and the larger one open, at the same write pointer. A regular mount then activates the block group while loading it, which warns for metadata and fails the mount for data when no active zone is left.
fs/btrfs/zoned.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
fs/btrfs/zoned.c +43 -0
@@ -1536,6 +1536,20 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg,for (i =0 ; i < map->num_stripes; i++) bg->zone_capacity =min_not_zero (bg->zone_capacity, zone_info[i].capacity); +/* +* A full zone reports its own capacity as its write pointer. With more +* capacity than the block group, take it as written up to the block +* group's capacity, unless an extent ends past that capacity: then the +* block group was written with a larger one, and the zone keeps its +* write pointer. +*/ +for (i =0 ; i < map->num_stripes; i++) { +if (zone_info[i].alloc_offset == zone_info[i].capacity && + zone_info[i].alloc_offset > bg->zone_capacity && + last_alloc <= bg->zone_capacity) + zone_info[i].alloc_offset = bg->zone_capacity; + } +/* * When the last extent is removed, last_alloc can be smaller than the other write * pointer. In that case, last_alloc should be moved to the corresponding write
@@ -1920,6 +1934,22 @@ int btrfs_load_block_group_by_raid_type(struct btrfs_block_group *bg,return ret; } +/* Whether the zones of the present stripes have different capacities. */ +static bool zone_capacities_differ (const struct btrfs_chunk_map *map, +const struct zone_info *zone_info) +{ +u64 capacity =0 ; + +for (int i =0 ; i < map->num_stripes; i++) { +if (!zone_info[i].capacity) +continue ; +if (capacity && zone_info[i].capacity != capacity) +return true; + capacity = zone_info[i].capacity; + } +return false; +} +int btrfs_load_block_group_zone_info (struct btrfs_block_group *cache,bool new) {struct btrfs_fs_info *fs_info = cache->fs_info;
@@ -1989,6 +2019,19 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)set_bit (BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE , &cache->runtime_flags); goto out; } + }else if ((map->type &BTRFS_BLOCK_GROUP_RAID1_MASK ) && +zone_capacities_differ (map, zone_info)) { +/* +* The RAID1 loader caps a full zone only if no extent +* ends past the block group's capacity. +*/ + ret =calculate_alloc_pointer (cache, &last_alloc, new); +if (ret) { +btrfs_err (fs_info, +"zoned: failed to determine allocation offset of bg %llu" , + cache->start); + goto out; + } } ret =btrfs_load_block_group_by_raid_type (cache, map, zone_info, active, last_alloc);
Signature · 1 line
2.53.0
PATCH v2 5/5 btrfs: tests: zoned: add RAID1 cases with missing or stale stripes
In reply to Miroslav CimermanAdd cases for the previous patches. On a degraded mount:
- RAID1 with the first device missing, and RAID1 metadata with an empty first zone: both are marked active
- RAID1C3 with the first and the last, and with the first two devices missing
- RAID1 and RAID1C3 with different write pointers: the highest one is taken
- RAID1 with full zones of different capacities
- RAID1 with a full zone that has extents past the smaller capacity: not capped, so the caller then refuses the block group
On a regular mount:
- RAID1 with the first zone offline, with a failed zone report for it, and with full zones of different capacities: now load
- RAID1C3 with a smaller third zone: sets the capacity
- two cases that still fail: a write pointer past the capacity in a zone that is not full, and full zones with extents past the capacity
Let a case set the zone capacity of each stripe. A stripe without a write pointer has a capacity of 0 unless the case sets one:btrfs_load_zone_info() gives 0 for a missing device or a failed zone report, while an offline zone keeps its capacity. Derive the active state from the write pointer and the capacity, and check the zone capacity and the active state where a case asks for it. All new cases fail without the previous patches, except the two that fail either way. Those make sure that only full zones without extents past the capacity are capped.
---
v2 (was 4/4): add the cases with an empty first zone, with different zone capacities and with a failed zone report, and a capacity per stripe. The case with an offline zone gives that zone a capacity now.
The subject was "btrfs: tests: zoned: add degraded RAID1 cases", but 6 of the 14 new cases are on a regular mount.
Prepared with the help of an LLM, which also ran the tests. I reviewed everything.
fs/btrfs/tests/zoned-tests.c | 203 ++++++++++++++++++++++++++++++++++- 1 file changed, 201 insertions(+), 2 deletions(-)
fs/btrfs/tests/zoned-tests.c +201 -2
@@ -21,12 +21,15 @@ struct load_zone_info_test_vector {u64 raid_type;u64 num_stripes;u64 alloc_offsets[8 ]; +u64 capacities[8 ];u64 last_alloc;u64 bg_length;bool degraded;int expected_result;u64 expected_alloc_offset; +u64 expected_zone_capacity; +bool expected_active;const char *description; };
@@ -77,8 +80,16 @@ static int test_load_zone_info(struct btrfs_fs_info *fs_info,for (int i =0 ; i < test->num_stripes; i++) { zone_info[i].physical =0 ; zone_info[i].alloc_offset = test->alloc_offsets[i]; - zone_info[i].capacity =ZONE_SIZE ; -if (zone_info[i].alloc_offset && zone_info[i].alloc_offset <ZONE_SIZE ) +/* +* Without a write pointer, the capacity is 0 for a missing device +* or a failed zone report, while an offline zone keeps its own. +*/ +if (zone_info[i].alloc_offset ==WP_MISSING_DEV ) + zone_info[i].capacity = test->capacities[i]; +else + zone_info[i].capacity = test->capacities[i] ?:ZONE_SIZE ; +if (zone_info[i].alloc_offset && + zone_info[i].alloc_offset < zone_info[i].capacity)__set_bit (i, active); }if (test->degraded)
@@ -101,6 +112,19 @@ static int test_load_zone_info(struct btrfs_fs_info *fs_info,return -EINVAL ; } +if (!ret && test->expected_zone_capacity && + bg->zone_capacity != test->expected_zone_capacity) { +test_err ("unexpected zone_capacity: zone_capacity %llu expected %llu" , + bg->zone_capacity, test->expected_zone_capacity); +return -EINVAL ; + } + +if (!ret && test->expected_active && + !test_bit (BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE , &bg->runtime_flags)) { +test_err ("block group not marked active" ); +return -EINVAL ; + } +return 0 ; }
@@ -244,7 +268,182 @@ static const struct load_zone_info_test_vector load_zone_info_tests[] = { .degraded = true, .expected_alloc_offset = SZ_1M, }, + { + .description = "RAID1: missing first device on DEGRADED", + .raid_type = BTRFS_BLOCK_GROUP_RAID1, + .num_stripes = 2, + .alloc_offsets = { + WP_MISSING_DEV, SZ_1M, + }, + .degraded = true, + .expected_alloc_offset = SZ_1M, + .expected_active = true, + }, + { + .description ="RAID1C3: missing first and last device on DEGRADED" , + .raid_type = BTRFS_BLOCK_GROUP_RAID1C3, + .num_stripes = 3, + .alloc_offsets = { + WP_MISSING_DEV, SZ_1M, WP_MISSING_DEV, + }, + .degraded = true, + .expected_alloc_offset = SZ_1M, + }, + { + .description ="RAID1C3: missing first and second device on DEGRADED" , + .raid_type = BTRFS_BLOCK_GROUP_RAID1C3, + .num_stripes = 3, + .alloc_offsets = { + WP_MISSING_DEV, WP_MISSING_DEV, SZ_1M, + }, + .degraded = true, + .expected_alloc_offset = SZ_1M, + .expected_zone_capacity = ZONE_SIZE, + }, + /* A stripe behind the others: the highest write pointer on DEGRADED. */ + { + .description ="RAID1: metadata, empty first zone on DEGRADED" , + .raid_type = BTRFS_BLOCK_GROUP_RAID1, + .num_stripes = 2, + .alloc_offsets = { + 0, SZ_1M, + }, + .degraded = true, + .expected_alloc_offset = SZ_1M, + .expected_active = true, + }, + { + .description ="RAID1: different write pointers on DEGRADED" , + .raid_type = BTRFS_BLOCK_GROUP_RAID1, + .num_stripes = 2, + .alloc_offsets = { + SZ_1M, SZ_2M, + }, + .degraded = true, + .expected_alloc_offset = SZ_2M, + }, + { + .description ="RAID1C3: first missing, different write pointers on DEGRADED" , + .raid_type = BTRFS_BLOCK_GROUP_RAID1C3, + .num_stripes = 3, + .alloc_offsets = { + WP_MISSING_DEV, SZ_2M, SZ_1M, + }, + .degraded = true, + .expected_alloc_offset = SZ_2M, + }, + /* + * An offline zone or a failed zone report has no write pointer on a + * regular mount either. An offline zone still has its capacity. + */ + { + .description ="RAID1: first zone offline" , + .raid_type = BTRFS_BLOCK_GROUP_RAID1, + .num_stripes = 2, + .alloc_offsets = { + WP_MISSING_DEV, SZ_1M, + }, + .capacities = { + ZONE_SIZE - SZ_1M, + }, + .expected_alloc_offset =SZ_1M , + .expected_zone_capacity = ZONE_SIZE - SZ_1M, + }, + { + .description ="RAID1: failed zone report of the first zone" , + .raid_type = BTRFS_BLOCK_GROUP_RAID1, + .num_stripes = 2, + .alloc_offsets = { + WP_MISSING_DEV, SZ_1M, + }, + .expected_alloc_offset =SZ_1M , + .expected_zone_capacity = ZONE_SIZE, + }, + /* The block group's capacity is the smallest of its stripes'. */ + { + .description ="RAID1C3: smaller third zone capacity" , + .raid_type = BTRFS_BLOCK_GROUP_RAID1C3, + .num_stripes = 3, + .alloc_offsets = { +SZ_1M ,SZ_1M ,SZ_1M , + }, + .capacities = { + ZONE_SIZE, ZONE_SIZE, ZONE_SIZE - SZ_1M, + }, + .expected_alloc_offset =SZ_1M , + .expected_zone_capacity = ZONE_SIZE - SZ_1M, + }, + /* Full zones report their own capacity, which can differ by device. */ + { + .description ="RAID1: full zones with different capacities" , + .raid_type = BTRFS_BLOCK_GROUP_RAID1, + .num_stripes = 2, + .alloc_offsets = { + ZONE_SIZE - SZ_1M, ZONE_SIZE, + }, + .capacities = { + ZONE_SIZE - SZ_1M, ZONE_SIZE, + }, + .last_alloc =ZONE_SIZE -SZ_1M , + .expected_alloc_offset = ZONE_SIZE - SZ_1M, + .expected_zone_capacity = ZONE_SIZE - SZ_1M, + }, + { + .description ="RAID1: full zones with different capacities on DEGRADED" , + .raid_type = BTRFS_BLOCK_GROUP_RAID1, + .num_stripes = 2, + .alloc_offsets = { + ZONE_SIZE, ZONE_SIZE - SZ_1M, + }, + .capacities = { + ZONE_SIZE, ZONE_SIZE - SZ_1M, + }, + .last_alloc =ZONE_SIZE -SZ_1M , + .degraded = true, + .expected_alloc_offset = ZONE_SIZE - SZ_1M, + .expected_zone_capacity = ZONE_SIZE - SZ_1M, + }, + { + .description ="RAID1: full zone with extents past the capacity on DEGRADED" , + .raid_type = BTRFS_BLOCK_GROUP_RAID1, + .num_stripes = 2, + .alloc_offsets = { + SZ_1M, ZONE_SIZE, + }, + .capacities = { + ZONE_SIZE - SZ_1M, ZONE_SIZE, + }, + .last_alloc =ZONE_SIZE , + .degraded = true, + .expected_alloc_offset = ZONE_SIZE, + .expected_zone_capacity = ZONE_SIZE - SZ_1M, + }, /* Error case: having different write pointers. */ + { + .description ="RAID1: fail: write pointer past the capacity" , + .raid_type = BTRFS_BLOCK_GROUP_RAID1, + .num_stripes = 2, + .alloc_offsets = { + ZONE_SIZE - SZ_1M, ZONE_SIZE - SZ_512K, + }, + .capacities = { + ZONE_SIZE - SZ_1M, ZONE_SIZE, + }, + .expected_result = -EIO, + }, + { + .description ="RAID1: fail: full zones with extents past the capacity" , + .raid_type = BTRFS_BLOCK_GROUP_RAID1, + .num_stripes = 2, + .alloc_offsets = { + ZONE_SIZE - SZ_1M, ZONE_SIZE, + }, + .capacities = { + ZONE_SIZE - SZ_1M, ZONE_SIZE, + }, + .last_alloc =ZONE_SIZE , + .expected_result = -EIO, + }, { .description ="RAID1: fail: different write pointers" , .raid_type = BTRFS_BLOCK_GROUP_RAID1,
Signature · 1 line
2.53.0
Re: [PATCH v2 4/5] btrfs: zoned: use the highest RAID1 write pointer on degraded mounts
In reply to Miroslav CimermanSashiko's review of this patch [1] found that on a degraded mount, a RAID1 data block group whose zones differ in their active state can be marked active without all its zones counted, or, if it is full, left inactive with an open zone that is never finished. That is right, but not new in this series: the base compares the active state with stripe 0 the same way and skips the activation on degraded mounts, 1/5 only compares with the first present stripe, and 4/5 changes it for metadata only. The 1/5 note mentions the first case and a block group with room left, but not the full one.
I reproduced both on the base and with this series, and sent a fix that applies on top of this series:
https://lore.kernel.org/linux-btrfs/[email protected]/
[1] https://sashiko.dev/#/patchset/20261121134550.216217-1-mc%40raidlab.org?part=4