Skip to content

Commit e0178b5

Browse files
committed
Merge tag 'for-6.4-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fix from David Sterba: "One regression fix. The rewrite of scrub code in 6.4 broke device replace in zoned mode, some of the writes could happen out of order so this had to be adjusted for all cases" * tag 'for-6.4-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: zoned: fix dev-replace after the scrub rework
2 parents 5321d1b + b675df0 commit e0178b5

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

fs/btrfs/bio.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,6 @@ void btrfs_submit_repair_write(struct btrfs_bio *bbio, int mirror_num, bool dev_
811811
goto fail;
812812

813813
if (dev_replace) {
814-
if (btrfs_op(&bbio->bio) == BTRFS_MAP_WRITE && btrfs_is_zoned(fs_info)) {
815-
bbio->bio.bi_opf &= ~REQ_OP_WRITE;
816-
bbio->bio.bi_opf |= REQ_OP_ZONE_APPEND;
817-
}
818814
ASSERT(smap.dev == fs_info->dev_replace.srcdev);
819815
smap.dev = fs_info->dev_replace.tgtdev;
820816
}

fs/btrfs/scrub.c

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,35 @@ static void scrub_write_endio(struct btrfs_bio *bbio)
11371137
wake_up(&stripe->io_wait);
11381138
}
11391139

1140+
static void scrub_submit_write_bio(struct scrub_ctx *sctx,
1141+
struct scrub_stripe *stripe,
1142+
struct btrfs_bio *bbio, bool dev_replace)
1143+
{
1144+
struct btrfs_fs_info *fs_info = sctx->fs_info;
1145+
u32 bio_len = bbio->bio.bi_iter.bi_size;
1146+
u32 bio_off = (bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT) -
1147+
stripe->logical;
1148+
1149+
fill_writer_pointer_gap(sctx, stripe->physical + bio_off);
1150+
atomic_inc(&stripe->pending_io);
1151+
btrfs_submit_repair_write(bbio, stripe->mirror_num, dev_replace);
1152+
if (!btrfs_is_zoned(fs_info))
1153+
return;
1154+
/*
1155+
* For zoned writeback, queue depth must be 1, thus we must wait for
1156+
* the write to finish before the next write.
1157+
*/
1158+
wait_scrub_stripe_io(stripe);
1159+
1160+
/*
1161+
* And also need to update the write pointer if write finished
1162+
* successfully.
1163+
*/
1164+
if (!test_bit(bio_off >> fs_info->sectorsize_bits,
1165+
&stripe->write_error_bitmap))
1166+
sctx->write_pointer += bio_len;
1167+
}
1168+
11401169
/*
11411170
* Submit the write bio(s) for the sectors specified by @write_bitmap.
11421171
*
@@ -1155,7 +1184,6 @@ static void scrub_write_sectors(struct scrub_ctx *sctx, struct scrub_stripe *str
11551184
{
11561185
struct btrfs_fs_info *fs_info = stripe->bg->fs_info;
11571186
struct btrfs_bio *bbio = NULL;
1158-
const bool zoned = btrfs_is_zoned(fs_info);
11591187
int sector_nr;
11601188

11611189
for_each_set_bit(sector_nr, &write_bitmap, stripe->nr_sectors) {
@@ -1168,13 +1196,7 @@ static void scrub_write_sectors(struct scrub_ctx *sctx, struct scrub_stripe *str
11681196

11691197
/* Cannot merge with previous sector, submit the current one. */
11701198
if (bbio && sector_nr && !test_bit(sector_nr - 1, &write_bitmap)) {
1171-
fill_writer_pointer_gap(sctx, stripe->physical +
1172-
(sector_nr << fs_info->sectorsize_bits));
1173-
atomic_inc(&stripe->pending_io);
1174-
btrfs_submit_repair_write(bbio, stripe->mirror_num, dev_replace);
1175-
/* For zoned writeback, queue depth must be 1. */
1176-
if (zoned)
1177-
wait_scrub_stripe_io(stripe);
1199+
scrub_submit_write_bio(sctx, stripe, bbio, dev_replace);
11781200
bbio = NULL;
11791201
}
11801202
if (!bbio) {
@@ -1187,14 +1209,8 @@ static void scrub_write_sectors(struct scrub_ctx *sctx, struct scrub_stripe *str
11871209
ret = bio_add_page(&bbio->bio, page, fs_info->sectorsize, pgoff);
11881210
ASSERT(ret == fs_info->sectorsize);
11891211
}
1190-
if (bbio) {
1191-
fill_writer_pointer_gap(sctx, bbio->bio.bi_iter.bi_sector <<
1192-
SECTOR_SHIFT);
1193-
atomic_inc(&stripe->pending_io);
1194-
btrfs_submit_repair_write(bbio, stripe->mirror_num, dev_replace);
1195-
if (zoned)
1196-
wait_scrub_stripe_io(stripe);
1197-
}
1212+
if (bbio)
1213+
scrub_submit_write_bio(sctx, stripe, bbio, dev_replace);
11981214
}
11991215

12001216
/*

0 commit comments

Comments
 (0)