From 7331affefd75633a59908c593fe0f83c337521c0 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Mon, 4 Dec 2017 10:40:17 -0700 Subject: [PATCH] blob: blob_bdev no longer converts unmap to write zeroes Unmaps are only used within blobstore to improve device performance, never to zero blocks. Therefore, if the device does not support unmap, just skip it instead of writing zeroes. This is different than devices that elect to implement the write zeroes command as an unmap because they will return 0 for subsequent reads. That optimization is still in effect. Change-Id: Ie1bf98fe86d73b4ac40b41c0d2804db325716500 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/390306 Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki Reviewed-by: Daniel Verkamp --- lib/blob/bdev/blob_bdev.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/blob/bdev/blob_bdev.c b/lib/blob/bdev/blob_bdev.c index 4fa134398..55f860ae4 100644 --- a/lib/blob/bdev/blob_bdev.c +++ b/lib/blob/bdev/blob_bdev.c @@ -140,12 +140,22 @@ static void bdev_blob_unmap(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args) { + struct blob_bdev *blob_bdev = (struct blob_bdev *)dev; int rc; - rc = spdk_bdev_unmap_blocks(__get_desc(dev), channel, lba, lba_count, - bdev_blob_io_complete, cb_args); - if (rc) { - cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, rc); + if (spdk_bdev_io_type_supported(blob_bdev->bdev, SPDK_BDEV_IO_TYPE_UNMAP)) { + rc = spdk_bdev_unmap_blocks(__get_desc(dev), channel, lba, lba_count, + bdev_blob_io_complete, cb_args); + if (rc) { + cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, rc); + } + } else { + /* + * If the device doesn't support unmap, immediately complete + * the request. Blobstore does not rely on unmap zeroing + * data. + */ + cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); } } @@ -226,18 +236,7 @@ spdk_bdev_create_bs_dev(struct spdk_bdev *bdev, spdk_bdev_remove_cb_t remove_cb, b->bs_dev.readv = bdev_blob_readv; b->bs_dev.writev = bdev_blob_writev; b->bs_dev.write_zeroes = bdev_blob_write_zeroes; - if (spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_UNMAP)) { - b->bs_dev.unmap = bdev_blob_unmap; - } else { - /* - * If bdev doesn't support unmap, use write_zeroes as a fallback. - * This will always work, since bdev implements write_zeroes on top of write - * if the device doesn't natively support write_zeroes. - */ - SPDK_NOTICELOG("Bdev %s does not support unmap, write_zeroes will be used instead.\n", - bdev->name); - b->bs_dev.unmap = bdev_blob_write_zeroes; - } + b->bs_dev.unmap = bdev_blob_unmap; return &b->bs_dev; }