hw/block/nvme: add the dataset management command
commit2605257a26b873eb8a0917391063df9c7ed7a976
authorKlaus Jensen <k.jensen@samsung.com>
Wed, 21 Oct 2020 12:03:19 +0000 (21 14:03 +0200)
committerKlaus Jensen <k.jensen@samsung.com>
Mon, 8 Feb 2021 17:55:48 +0000 (8 18:55 +0100)
treece87941a5e71a5b02f1792fc2c7f8f3300125664
parent6fd704a59af99056ee6ed1284784b092725a9416
hw/block/nvme: add the dataset management command

Add support for the Dataset Management command and the Deallocate
attribute. Deallocation results in discards being sent to the underlying
block device. Whether of not the blocks are actually deallocated is
affected by the same factors as Write Zeroes (see previous commit).

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

Again, a raw format and 4KiB LBAs are preferable.

In order to set the Namespace Preferred Deallocate Granularity and
Alignment fields (NPDG and NPDA), choose a sane minimum discard
granularity of 4KiB. If we are using a passthru device supporting
discard at a 512B granularity, user should set the discard_granularity
property explicitly. NPDG and NPDA will also account for the
cluster_size of the block driver if required (i.e. for QCOW2).

See NVM Express 1.3d, Section 6.7 ("Dataset Management command").

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