]> www.infradead.org Git - qemu-nvme.git/commitdiff
hw/block/nvme: report actual LBA data shift in LBAF
authorDmitry Fomichev <dmitry.fomichev@wdc.com>
Mon, 28 Sep 2020 02:35:15 +0000 (11:35 +0900)
committerKeith Busch <kbusch@kernel.org>
Wed, 30 Sep 2020 21:28:27 +0000 (14:28 -0700)
Calculate the data shift value to report based on the set value of
logical_block_size device property.

In the process, use a local variable to calculate the LBA format
index instead of the hardcoded value 0. This makes the code more
readable and it will make it easier to add support for multiple LBA
formats in the future.

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

index 2ba0263ddaca49325d000960f268c2f09af749b5..a85e5fdb4228f8827ceb79ef4672041de45c712b 100644 (file)
@@ -47,6 +47,8 @@ static void nvme_ns_init(NvmeNamespace *ns)
 
 static int nvme_ns_init_blk(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)
 {
+    int lba_index;
+
     if (!blkconf_blocksizes(&ns->blkconf, errp)) {
         return -1;
     }
@@ -67,6 +69,9 @@ static int nvme_ns_init_blk(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)
         n->features.vwc = 0x1;
     }
 
+    lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas);
+    ns->id_ns.lbaf[lba_index].ds = 31 - clz32(ns->blkconf.logical_block_size);
+
     return 0;
 }