diff --git a/block/io.c b/block/io.c index b0435ed6707cef8d35526bdb0b3a5474274773fd..ca2dca30070e4bb4b8f04c10bed1977e18a5df5d 100644 --- a/block/io.c +++ b/block/io.c @@ -3460,3 +3460,14 @@ out: return ret; } + +void bdrv_cancel_in_flight(BlockDriverState *bs) +{ + if (!bs || !bs->drv) { + return; + } + + if (bs->drv->bdrv_cancel_in_flight) { + bs->drv->bdrv_cancel_in_flight(bs); + } +} diff --git a/include/block/block.h b/include/block/block.h index 0a9f2c187cdbbae7968d76d09bdd8d800ab927a0..2f2698074e303df3b8922fef4b0d9b2b3a792569 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -849,4 +849,7 @@ int coroutine_fn bdrv_co_copy_range(BdrvChild *src, int64_t src_offset, BdrvChild *dst, int64_t dst_offset, int64_t bytes, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags); + +void bdrv_cancel_in_flight(BlockDriverState *bs); + #endif diff --git a/include/block/block_int.h b/include/block/block_int.h index 22a2789d3516bbc23ddc9e26e5326695dee794c6..88e41119398144f79f2b2f0db8d5e0ec3beceb0f 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -352,6 +352,15 @@ struct BlockDriver { bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); + /* + * This informs the driver that we are no longer interested in the result + * of in-flight requests, so don't waste the time if possible. + * + * One example usage is to avoid waiting for an nbd target node reconnect + * timeout during job-cancel. + */ + void (*bdrv_cancel_in_flight)(BlockDriverState *bs); + /* * Invalidate any cached meta-data. */