Skip to content

Commit 06873db

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: refactor zone reset handling
Include the actual bio submission in the common zone reset handler to share more code and prepare for adding error injection for zone reset. Note the I plan to refactor the block layer submit_bio_wait and bio_await_chain code in the next merge window to remove some of the code duplication added here. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com> Reviewed-by: Hans Holmberg <hans.holmberg@wdc.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent 32ae9b8 commit 06873db

1 file changed

Lines changed: 28 additions & 21 deletions

File tree

fs/xfs/xfs_zone_gc.c

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -893,40 +893,55 @@ xfs_zone_gc_finish_reset(
893893
bio_put(&chunk->bio);
894894
}
895895

896-
static bool
897-
xfs_zone_gc_prepare_reset(
898-
struct bio *bio,
899-
struct xfs_rtgroup *rtg)
896+
static void
897+
xfs_submit_zone_reset_bio(
898+
struct xfs_rtgroup *rtg,
899+
struct bio *bio)
900900
{
901901
trace_xfs_zone_reset(rtg);
902902

903903
ASSERT(rtg_rmap(rtg)->i_used_blocks == 0);
904904
bio->bi_iter.bi_sector = xfs_gbno_to_daddr(&rtg->rtg_group, 0);
905905
if (!bdev_zone_is_seq(bio->bi_bdev, bio->bi_iter.bi_sector)) {
906-
if (!bdev_max_discard_sectors(bio->bi_bdev))
907-
return false;
906+
/*
907+
* Also use the bio to drive the state machine when neither
908+
* zone reset nor discard is supported to keep things simple.
909+
*/
910+
if (!bdev_max_discard_sectors(bio->bi_bdev)) {
911+
bio_endio(bio);
912+
return;
913+
}
908914
bio->bi_opf &= ~REQ_OP_ZONE_RESET;
909915
bio->bi_opf |= REQ_OP_DISCARD;
910916
bio->bi_iter.bi_size =
911917
XFS_FSB_TO_B(rtg_mount(rtg), rtg_blocks(rtg));
912918
}
913919

914-
return true;
920+
submit_bio(bio);
921+
}
922+
923+
static void xfs_bio_wait_endio(struct bio *bio)
924+
{
925+
complete(bio->bi_private);
915926
}
916927

917928
int
918929
xfs_zone_gc_reset_sync(
919930
struct xfs_rtgroup *rtg)
920931
{
921-
int error = 0;
932+
DECLARE_COMPLETION_ONSTACK(done);
922933
struct bio bio;
934+
int error;
923935

924936
bio_init(&bio, rtg_mount(rtg)->m_rtdev_targp->bt_bdev, NULL, 0,
925-
REQ_OP_ZONE_RESET);
926-
if (xfs_zone_gc_prepare_reset(&bio, rtg))
927-
error = submit_bio_wait(&bio);
928-
bio_uninit(&bio);
937+
REQ_OP_ZONE_RESET | REQ_SYNC);
938+
bio.bi_private = &done;
939+
bio.bi_end_io = xfs_bio_wait_endio;
940+
xfs_submit_zone_reset_bio(rtg, &bio);
941+
wait_for_completion_io(&done);
929942

943+
error = blk_status_to_errno(bio.bi_status);
944+
bio_uninit(&bio);
930945
return error;
931946
}
932947

@@ -961,15 +976,7 @@ xfs_zone_gc_reset_zones(
961976
chunk->data = data;
962977
WRITE_ONCE(chunk->state, XFS_GC_BIO_NEW);
963978
list_add_tail(&chunk->entry, &data->resetting);
964-
965-
/*
966-
* Also use the bio to drive the state machine when neither
967-
* zone reset nor discard is supported to keep things simple.
968-
*/
969-
if (xfs_zone_gc_prepare_reset(bio, rtg))
970-
submit_bio(bio);
971-
else
972-
bio_endio(bio);
979+
xfs_submit_zone_reset_bio(rtg, bio);
973980
} while (next);
974981
}
975982

0 commit comments

Comments
 (0)