diff mbox series

hw/block/nvme: conditionally enable DULBE for zoned namespaces

Message ID 20210111180952.112488-1-its@irrelevant.dk (mailing list archive)
State New, archived
Headers show
Series hw/block/nvme: conditionally enable DULBE for zoned namespaces | expand

Commit Message

Klaus Jensen Jan. 11, 2021, 6:09 p.m. UTC
From: Klaus Jensen <k.jensen@samsung.com>

The device uses the BDRV_BLOCK_ZERO flag to determine the "deallocated"
status of logical blocks. Since the zoned namespaces command set
specification defines that logical blocks SHALL be marked as deallocated
when the zone is in the Empty or Offline states, DULBE can only be
supported if the zone size is a multiple of the calculated deallocation
granularity (reported in NPDG) which depends on the underlying block
device cluster size (if applicable) or the configured
discard_granularity.

Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/block/nvme-ns.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Keith Busch Jan. 14, 2021, 11:39 p.m. UTC | #1
On Mon, Jan 11, 2021 at 07:09:52PM +0100, Klaus Jensen wrote:
> From: Klaus Jensen <k.jensen@samsung.com>
> 
> The device uses the BDRV_BLOCK_ZERO flag to determine the "deallocated"
> status of logical blocks. Since the zoned namespaces command set
> specification defines that logical blocks SHALL be marked as deallocated
> when the zone is in the Empty or Offline states, DULBE can only be
> supported if the zone size is a multiple of the calculated deallocation
> granularity (reported in NPDG) which depends on the underlying block
> device cluster size (if applicable) or the configured
> discard_granularity.
> 
> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>

Looks good.

Reviewed-by: Keith Busch <kbusch@kernel.org>
Klaus Jensen Jan. 15, 2021, 7:10 a.m. UTC | #2
On Jan 14 15:39, Keith Busch wrote:
> On Mon, Jan 11, 2021 at 07:09:52PM +0100, Klaus Jensen wrote:
> > From: Klaus Jensen <k.jensen@samsung.com>
> > 
> > The device uses the BDRV_BLOCK_ZERO flag to determine the "deallocated"
> > status of logical blocks. Since the zoned namespaces command set
> > specification defines that logical blocks SHALL be marked as deallocated
> > when the zone is in the Empty or Offline states, DULBE can only be
> > supported if the zone size is a multiple of the calculated deallocation
> > granularity (reported in NPDG) which depends on the underlying block
> > device cluster size (if applicable) or the configured
> > discard_granularity.
> > 
> > Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
> 
> Looks good.
> 
> Reviewed-by: Keith Busch <kbusch@kernel.org>
> 

Thanks! Applied to nvme-next.
diff mbox series

Patch

diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c
index a4972ac23d8f..274eaf61b721 100644
--- a/hw/block/nvme-ns.c
+++ b/hw/block/nvme-ns.c
@@ -16,6 +16,7 @@ 
 #include "qemu/units.h"
 #include "qemu/cutils.h"
 #include "qemu/log.h"
+#include "qemu/error-report.h"
 #include "hw/block/block.h"
 #include "hw/pci/pci.h"
 #include "sysemu/sysemu.h"
@@ -226,6 +227,22 @@  static void nvme_ns_init_zoned(NvmeCtrl *n, NvmeNamespace *ns, int lba_index)
     ns->id_ns.ncap = ns->id_ns.nsze;
     ns->id_ns.nuse = ns->id_ns.ncap;
 
+    /*
+     * The device uses the BDRV_BLOCK_ZERO flag to determine the "deallocated"
+     * status of logical blocks. Since the spec defines that logical blocks
+     * SHALL be deallocated when then zone is in the Empty or Offline states,
+     * we can only support DULBE if the zone size is a multiple of the
+     * calculated NPDG.
+     */
+    if (ns->zone_size % (ns->id_ns.npdg + 1)) {
+        warn_report("the zone size (%"PRIu64" blocks) is not a multiple of "
+                    "the calculated deallocation granularity "
+                    "(%"PRIu16" blocks); DULBE support disabled",
+                    ns->zone_size, ns->id_ns.npdg + 1);
+
+        ns->id_ns.nsfeat &= ~0x4;
+    }
+
     ns->id_ns_zoned = id_ns_z;
 }