hw/block/nvme: add dulbe support
authorKlaus Jensen <k.jensen@samsung.com>
Wed, 14 Oct 2020 07:55:08 +0000 (09:55 +0200)
committerKlaus Jensen <k.jensen@samsung.com>
Mon, 8 Feb 2021 17:55:48 +0000 (18:55 +0100)
commit54064e51d1e2c85e08ab64f05d12957ff65dfcd3
tree8257f578bd71759f82398cddc066aa8c722e665d
parent54eea8d947869856133a4eba0c0cb0b17cb9a5cd
hw/block/nvme: add dulbe support

Add support for reporting the Deallocated or Unwritten Logical Block
Error (DULBE).

Rely on the block status flags reported by the block layer and consider
any block with the BDRV_BLOCK_ZERO flag to be deallocated.

Multiple factors affect when a Write Zeroes command result in
deallocation of blocks.

  * the underlying file system block size
  * the blockdev format
  * the 'discard' and 'logical_block_size' parameters

     format | discard | wz (512B)  wz (4KiB)  wz (64KiB)
    -----------------------------------------------------
      qcow2    ignore   n          n          y
      qcow2    unmap    n          n          y
      raw      ignore   n          y          y
      raw      unmap    n          y          y

So, this works best with an image in raw format and 4KiB LBAs, since
holes can then be punched on a per-block basis (this assumes a file
system with a 4kb block size, YMMV). A qcow2 image, uses a cluster size
of 64KiB by default and blocks will only be marked deallocated if a full
cluster is zeroed or discarded. However, this *is* consistent with the
spec since Write Zeroes "should" deallocate the block if the Deallocate
attribute is set and "may" deallocate if the Deallocate attribute is not
set. Thus, we always try to deallocate (the BDRV_REQ_MAY_UNMAP flag is
always set).

Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Reviewed-by: Keith Busch <kbusch@kernel.org>
hw/block/nvme-ns.c
hw/block/nvme-ns.h
hw/block/nvme.c
hw/block/trace-events
include/block/nvme.h