Similar to write_zeroes, let the generic code receive a ENOTSUP for discard operations. Since bdrv_discard has advisory semantics, we can just swallow the error.
Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> --- block.c | 2 +- block/raw-posix.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index f5428f4..4897649 100644 --- a/block.c +++ b/block.c @@ -4357,7 +4357,7 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, ret = co.ret; } } - if (ret) { + if (ret && ret != -ENOTSUP) { return ret; } diff --git a/block/raw-posix.c b/block/raw-posix.c index ace5d96..f719b69 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -324,10 +324,10 @@ static int raw_open_common(BlockDriverState *bs, QDict *options, } #endif - s->has_discard = 1; + s->has_discard = true; #ifdef CONFIG_XFS if (platform_test_xfs_fd(s->fd)) { - s->is_xfs = 1; + s->is_xfs = true; } #endif @@ -699,8 +699,8 @@ static ssize_t handle_aiocb_discard(RawPosixAIOData *aiocb) int ret = -EOPNOTSUPP; BDRVRawState *s = aiocb->bs->opaque; - if (s->has_discard == 0) { - return 0; + if (!s->has_discard) { + return -ENOTSUP; } if (aiocb->aio_type & QEMU_AIO_BLKDEV) { @@ -735,8 +735,8 @@ static ssize_t handle_aiocb_discard(RawPosixAIOData *aiocb) if (ret == -ENODEV || ret == -ENOSYS || ret == -EOPNOTSUPP || ret == -ENOTTY) { - s->has_discard = 0; - ret = 0; + s->has_discard = false; + ret = -ENOTSUP; } return ret; } -- 1.8.4.2