From e18788d30e7d72aa16713b63a39ea4c6dc665084 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Mon, 14 Dec 2020 00:59:25 -0500 Subject: [PATCH] vhost-blk: process VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP correctly Flag VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP is only used for WRITE ZEROES command, vhost-blk target may tell VM via 'write_zeroes_may_unmap' configuration that the backend can support this flag, however, Linux generic block driver doesn't have such logic, it will enable this flag by default(without REQ_NOUNMAP) with WRITE ZEROES command, so the backend may choose to ignore this flag, because WRITE ZEROES with this flag isn't mandatory. Fix issue #1714. Change-Id: Ic9388f39269720a23c00d41cba585d2a5abc3cfb Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5565 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Reviewed-by: --- lib/vhost/vhost_blk.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/vhost/vhost_blk.c b/lib/vhost/vhost_blk.c index 4fa11d273..b16c7bbc8 100644 --- a/lib/vhost/vhost_blk.c +++ b/lib/vhost/vhost_blk.c @@ -464,6 +464,12 @@ process_blk_request(struct spdk_vhost_blk_task *task, return -1; } + if (desc->flags & VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP) { + SPDK_ERRLOG("UNMAP flag is only used for WRITE ZEROES command\n"); + invalid_blk_request(task, VIRTIO_BLK_S_UNSUPP); + return -1; + } + rc = spdk_bdev_unmap(bvdev->bdev_desc, bvsession->io_channel, desc->sector * 512, desc->num_sectors * 512, blk_request_complete_cb, task); @@ -485,11 +491,13 @@ process_blk_request(struct spdk_vhost_blk_task *task, return -1; } - /* Zeroed and Unmap the range, SPDK doen't support it. */ + /* Unmap this range, SPDK doesn't support it, kernel will enable this flag by default + * without checking unmap feature is negociated or not, the flag isn't mandatory, so + * just print a warning. + */ if (desc->flags & VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP) { - SPDK_NOTICELOG("Can't support Write Zeroes with Unmap flag\n"); - invalid_blk_request(task, VIRTIO_BLK_S_UNSUPP); - return -1; + SPDK_WARNLOG("Ignore the unmap flag for WRITE ZEROES from %"PRIx64", len %"PRIx64"\n", + (uint64_t)desc->sector * 512, (uint64_t)desc->num_sectors * 512); } rc = spdk_bdev_write_zeroes(bvdev->bdev_desc, bvsession->io_channel,