Message ID | 20200415102445.564803-11-its@irrelevant.dk (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | nvme: refactoring and cleanups | expand |
On 4/15/20 12:24 PM, Klaus Jensen wrote: > From: Klaus Jensen <k.jensen@samsung.com> > > Signed-off-by: Klaus Jensen <k.jensen@samsung.com> > --- > hw/block/nvme.c | 17 +++++++++++------ > 1 file changed, 11 insertions(+), 6 deletions(-) > > diff --git a/hw/block/nvme.c b/hw/block/nvme.c > index 635292d6fac4..e67f578fbf79 100644 > --- a/hw/block/nvme.c > +++ b/hw/block/nvme.c > @@ -1339,6 +1339,15 @@ static int nvme_check_constraints(NvmeCtrl *n, Error **errp) > return 0; > } > > +static void nvme_init_state(NvmeCtrl *n) > +{ > + n->num_namespaces = 1; > + n->reg_size = pow2ceil(0x1008 + 2 * (n->params.max_ioqpairs) * 4); > + n->namespaces = g_new0(NvmeNamespace, n->num_namespaces); > + n->sq = g_new0(NvmeSQueue *, n->params.max_ioqpairs + 1); > + n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1); > +} > + > static void nvme_realize(PCIDevice *pci_dev, Error **errp) > { > NvmeCtrl *n = NVME(pci_dev); > @@ -1352,6 +1361,8 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) > return; > } > > + nvme_init_state(n); > + > bs_size = blk_getlength(n->conf.blk); > if (bs_size < 0) { > error_setg(errp, "could not get backing file size"); > @@ -1370,14 +1381,8 @@ 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->num_namespaces = 1; > - n->reg_size = pow2ceil(0x1008 + 2 * (n->params.max_ioqpairs) * 4); > n->ns_size = bs_size / (uint64_t)n->num_namespaces; > > - n->namespaces = g_new0(NvmeNamespace, n->num_namespaces); > - n->sq = g_new0(NvmeSQueue *, n->params.max_ioqpairs + 1); > - n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1); > - > memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n, > "nvme", n->reg_size); > pci_register_bar(pci_dev, 0, > Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 635292d6fac4..e67f578fbf79 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1339,6 +1339,15 @@ static int nvme_check_constraints(NvmeCtrl *n, Error **errp) return 0; } +static void nvme_init_state(NvmeCtrl *n) +{ + n->num_namespaces = 1; + n->reg_size = pow2ceil(0x1008 + 2 * (n->params.max_ioqpairs) * 4); + n->namespaces = g_new0(NvmeNamespace, n->num_namespaces); + n->sq = g_new0(NvmeSQueue *, n->params.max_ioqpairs + 1); + n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1); +} + static void nvme_realize(PCIDevice *pci_dev, Error **errp) { NvmeCtrl *n = NVME(pci_dev); @@ -1352,6 +1361,8 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) return; } + nvme_init_state(n); + bs_size = blk_getlength(n->conf.blk); if (bs_size < 0) { error_setg(errp, "could not get backing file size"); @@ -1370,14 +1381,8 @@ 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->num_namespaces = 1; - n->reg_size = pow2ceil(0x1008 + 2 * (n->params.max_ioqpairs) * 4); n->ns_size = bs_size / (uint64_t)n->num_namespaces; - n->namespaces = g_new0(NvmeNamespace, n->num_namespaces); - n->sq = g_new0(NvmeSQueue *, n->params.max_ioqpairs + 1); - n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1); - memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n, "nvme", n->reg_size); pci_register_bar(pci_dev, 0,