qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Klaus Jensen <its@irrelevant.dk>
To: qemu-devel@nongnu.org
Cc: Fam Zheng <fam@euphon.net>, Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org, Klaus Jensen <k.jensen@samsung.com>,
	Gollu Appalanaidu <anaidu.gollu@samsung.com>,
	Max Reitz <mreitz@redhat.com>, Keith Busch <kbusch@kernel.org>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Klaus Jensen <its@irrelevant.dk>
Subject: [PATCH v5 08/13] hw/block/nvme: pull lba format initialization
Date: Wed, 10 Mar 2021 10:53:42 +0100	[thread overview]
Message-ID: <20210310095347.682395-9-its@irrelevant.dk> (raw)
In-Reply-To: <20210310095347.682395-1-its@irrelevant.dk>

From: Klaus Jensen <k.jensen@samsung.com>

Pull lba format initialization code into separate function in
preparation for Format NVM support.

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

diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c
index 7e3cba55e4db..1e8ef36ba5ae 100644
--- a/hw/block/nvme-ns.c
+++ b/hw/block/nvme-ns.c
@@ -32,17 +32,55 @@
 
 #define MIN_DISCARD_GRANULARITY (4 * KiB)
 
+static void nvme_ns_init_format(NvmeNamespace *ns)
+{
+    NvmeIdNs *id_ns = &ns->id_ns;
+    BlockDriverInfo bdi;
+    int npdg, nlbas, ret;
+
+    nlbas = nvme_ns_nlbas(ns);
+
+    id_ns->nsze = cpu_to_le64(nlbas);
+
+    /* no thin provisioning */
+    id_ns->ncap = id_ns->nsze;
+    id_ns->nuse = id_ns->ncap;
+
+    ns->mdata_offset = nvme_l2b(ns, nlbas);
+
+    npdg = ns->blkconf.discard_granularity / nvme_lsize(ns);
+
+    ret = bdrv_get_info(blk_bs(ns->blkconf.blk), &bdi);
+    if (ret >= 0 && bdi.cluster_size > ns->blkconf.discard_granularity) {
+        npdg = bdi.cluster_size / nvme_lsize(ns);
+    }
+
+    id_ns->npda = id_ns->npdg = npdg - 1;
+}
+
 static int nvme_ns_init(NvmeNamespace *ns, Error **errp)
 {
-    BlockDriverInfo bdi;
     NvmeIdNs *id_ns = &ns->id_ns;
-    int npdg, nlbas;
     uint8_t ds;
     uint16_t ms;
     int i;
 
+    ns->csi = NVME_CSI_NVM;
+
     ns->id_ns.dlfeat = 0x1;
 
+    /* support DULBE and I/O optimization fields */
+    id_ns->nsfeat |= (0x4 | 0x10);
+
+    if (nvme_ns_shared(ns)) {
+        id_ns->nmic |= NVME_NMIC_NS_SHARED;
+    }
+
+    /* simple copy */
+    id_ns->mssrl = cpu_to_le16(ns->params.mssrl);
+    id_ns->mcl = cpu_to_le32(ns->params.mcl);
+    id_ns->msrc = ns->params.msrc;
+
     ds = 31 - clz32(ns->blkconf.logical_block_size);
     ms = ns->params.ms;
 
@@ -96,37 +134,7 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp)
     id_ns->flbas |= id_ns->nlbaf;
 
 lbaf_found:
-    nlbas = nvme_ns_nlbas(ns);
-
-    id_ns->nsze = cpu_to_le64(nlbas);
-    ns->mdata_offset = nvme_l2b(ns, nlbas);
-
-    ns->csi = NVME_CSI_NVM;
-
-    /* no thin provisioning */
-    id_ns->ncap = id_ns->nsze;
-    id_ns->nuse = id_ns->ncap;
-
-    /* support DULBE and I/O optimization fields */
-    id_ns->nsfeat |= (0x4 | 0x10);
-
-    npdg = ns->blkconf.discard_granularity / nvme_lsize(ns);
-
-    if (bdrv_get_info(blk_bs(ns->blkconf.blk), &bdi) >= 0 &&
-        bdi.cluster_size > ns->blkconf.discard_granularity) {
-        npdg = bdi.cluster_size / nvme_lsize(ns);
-    }
-
-    id_ns->npda = id_ns->npdg = npdg - 1;
-
-    if (nvme_ns_shared(ns)) {
-        id_ns->nmic |= NVME_NMIC_NS_SHARED;
-    }
-
-    /* simple copy */
-    id_ns->mssrl = cpu_to_le16(ns->params.mssrl);
-    id_ns->mcl = cpu_to_le32(ns->params.mcl);
-    id_ns->msrc = ns->params.msrc;
+    nvme_ns_init_format(ns);
 
     return 0;
 }
-- 
2.30.1



  parent reply	other threads:[~2021-03-10  9:59 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-10  9:53 [PATCH v5 00/13] hw/block/nvme: metadata and end-to-end data protection support Klaus Jensen
2021-03-10  9:53 ` [PATCH v5 01/13] hw/block/nvme: fix zone management receive reporting too many zones Klaus Jensen
2021-03-14 19:31   ` Dmitry Fomichev
2021-03-15 18:59     ` Klaus Jensen
2021-03-10  9:53 ` [PATCH v5 02/13] hw/block/nvme: add metadata support Klaus Jensen
2021-03-10  9:53 ` [PATCH v5 03/13] hw/block/nvme: end-to-end data protection Klaus Jensen
2021-03-10  9:53 ` [PATCH v5 04/13] hw/block/nvme: add verify command Klaus Jensen
2021-03-10  9:53 ` [PATCH v5 05/13] hw/block/nvme: add non-mdts command size limit for verify Klaus Jensen
2021-03-10  9:53 ` [PATCH v5 06/13] hw/block/nvme: support multiple lba formats Klaus Jensen
2021-03-10  9:53 ` [PATCH v5 07/13] hw/block/nvme: prefer runtime helpers instead of device parameters Klaus Jensen
2021-03-16  6:47   ` Minwoo Im
2021-03-10  9:53 ` Klaus Jensen [this message]
2021-03-16  6:49   ` [PATCH v5 08/13] hw/block/nvme: pull lba format initialization Minwoo Im
2021-03-10  9:53 ` [PATCH v5 09/13] hw/block/nvme: parameterize nvme_ns_nlbas Klaus Jensen
2021-03-16  6:53   ` Minwoo Im
2021-03-16  7:19     ` Klaus Jensen
2021-03-16  7:34       ` Minwoo Im
2021-03-10  9:53 ` [PATCH v5 10/13] hw/block/nvme: remove invalid zone resource checks Klaus Jensen
2021-03-10  9:53 ` [PATCH v5 11/13] hw/block/nvme: move zoned constraints checks Klaus Jensen
2021-03-10  9:53 ` [PATCH v5 12/13] hw/block/nvme: split zone check/set geometry Klaus Jensen
2021-03-10  9:53 ` [PATCH v5 13/13] hw/block/nvme: add support for the format nvm command Klaus Jensen
2021-03-15 22:23 ` [PATCH v5 00/13] hw/block/nvme: metadata and end-to-end data protection support Klaus Jensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210310095347.682395-9-its@irrelevant.dk \
    --to=its@irrelevant.dk \
    --cc=anaidu.gollu@samsung.com \
    --cc=fam@euphon.net \
    --cc=k.jensen@samsung.com \
    --cc=kbusch@kernel.org \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).