[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 20/43] hw/block/nvme: factor out namespace setup
From: |
Kevin Wolf |
Subject: |
[PULL 20/43] hw/block/nvme: factor out namespace setup |
Date: |
Wed, 17 Jun 2020 16:48:46 +0200 |
From: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Message-Id: <20200609190333.59390-15-its@irrelevant.dk>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/block/nvme.c | 46 ++++++++++++++++++++++++++--------------------
1 file changed, 26 insertions(+), 20 deletions(-)
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 3f3db17231..c98af03f44 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -1417,6 +1417,27 @@ static void nvme_init_blk(NvmeCtrl *n, Error **errp)
false, errp);
}
+static void nvme_init_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)
+{
+ int64_t bs_size;
+ NvmeIdNs *id_ns = &ns->id_ns;
+
+ bs_size = blk_getlength(n->conf.blk);
+ if (bs_size < 0) {
+ error_setg_errno(errp, -bs_size, "could not get backing file size");
+ return;
+ }
+
+ n->ns_size = bs_size;
+
+ id_ns->lbaf[0].ds = BDRV_SECTOR_BITS;
+ id_ns->nsze = cpu_to_le64(nvme_ns_nlbas(n, ns));
+
+ /* no thin provisioning */
+ id_ns->ncap = id_ns->nsze;
+ id_ns->nuse = id_ns->ncap;
+}
+
static void nvme_realize(PCIDevice *pci_dev, Error **errp)
{
NvmeCtrl *n = NVME(pci_dev);
@@ -1424,7 +1445,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
Error *local_err = NULL;
int i;
- int64_t bs_size;
uint8_t *pci_conf;
nvme_check_constraints(n, &local_err);
@@ -1435,12 +1455,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error
**errp)
nvme_init_state(n);
- bs_size = blk_getlength(n->conf.blk);
- if (bs_size < 0) {
- error_setg(errp, "could not get backing file size");
- return;
- }
-
nvme_init_blk(n, &local_err);
if (local_err) {
error_propagate(errp, local_err);
@@ -1453,8 +1467,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
pci_config_set_class(pci_dev->config, PCI_CLASS_STORAGE_EXPRESS);
pcie_endpoint_cap_init(pci_dev, 0x80);
- n->ns_size = bs_size / (uint64_t)n->num_namespaces;
-
memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n,
"nvme", n->reg_size);
pci_register_bar(pci_dev, 0,
@@ -1563,17 +1575,11 @@ static void nvme_realize(PCIDevice *pci_dev, Error
**errp)
}
for (i = 0; i < n->num_namespaces; i++) {
- NvmeNamespace *ns = &n->namespaces[i];
- NvmeIdNs *id_ns = &ns->id_ns;
- id_ns->nsfeat = 0;
- id_ns->nlbaf = 0;
- id_ns->flbas = 0;
- id_ns->mc = 0;
- id_ns->dpc = 0;
- id_ns->dps = 0;
- id_ns->lbaf[0].ds = BDRV_SECTOR_BITS;
- id_ns->ncap = id_ns->nuse = id_ns->nsze =
- cpu_to_le64(nvme_ns_nlbas(n, ns));
+ nvme_init_namespace(n, &n->namespaces[i], &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
}
}
--
2.25.4
- [PULL 12/43] hw/block/nvme: refactor nvme_addr_read, (continued)
- [PULL 12/43] hw/block/nvme: refactor nvme_addr_read, Kevin Wolf, 2020/06/17
- [PULL 13/43] hw/block/nvme: fix pin-based interrupt behavior, Kevin Wolf, 2020/06/17
- [PULL 08/43] hw/block/nvme: rename trace events to pci_nvme, Kevin Wolf, 2020/06/17
- [PULL 16/43] hw/block/nvme: factor out property/constraint checks, Kevin Wolf, 2020/06/17
- [PULL 15/43] hw/block/nvme: remove redundant cmbloc/cmbsz members, Kevin Wolf, 2020/06/17
- [PULL 11/43] hw/block/nvme: use constants in identify, Kevin Wolf, 2020/06/17
- [PULL 17/43] hw/block/nvme: factor out device state setup, Kevin Wolf, 2020/06/17
- [PULL 14/43] hw/block/nvme: add max_ioqpairs device parameter, Kevin Wolf, 2020/06/17
- [PULL 18/43] hw/block/nvme: factor out block backend setup, Kevin Wolf, 2020/06/17
- [PULL 19/43] hw/block/nvme: add namespace helpers, Kevin Wolf, 2020/06/17
- [PULL 20/43] hw/block/nvme: factor out namespace setup,
Kevin Wolf <=
- [PULL 22/43] hw/block/nvme: factor out cmb setup, Kevin Wolf, 2020/06/17
- [PULL 25/43] hw/block/nvme: factor out controller identify setup, Kevin Wolf, 2020/06/17
- [PULL 21/43] hw/block/nvme: factor out pci setup, Kevin Wolf, 2020/06/17
- [PULL 23/43] hw/block/nvme: factor out pmr setup, Kevin Wolf, 2020/06/17
- [PULL 24/43] hw/block/nvme: do cmb/pmr init as part of pci init, Kevin Wolf, 2020/06/17
- [PULL 26/43] hw/block/nvme: Verify msix_vector_use() returned value, Kevin Wolf, 2020/06/17
- [PULL 28/43] hw/block/nvme: verify msix_init_exclusive_bar() return value, Kevin Wolf, 2020/06/17
- [PULL 30/43] virtio-blk: store opt_io_size with correct size, Kevin Wolf, 2020/06/17
- [PULL 32/43] qdev-properties: blocksize: use same limits in code and description, Kevin Wolf, 2020/06/17
- [PULL 27/43] hw/block/nvme: add msix_qsize parameter, Kevin Wolf, 2020/06/17