[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 16/43] hw/block/nvme: factor out property/constraint checks
From: |
Kevin Wolf |
Subject: |
[PULL 16/43] hw/block/nvme: factor out property/constraint checks |
Date: |
Wed, 17 Jun 2020 16:48:42 +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-11-its@irrelevant.dk>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/block/nvme.c | 48 ++++++++++++++++++++++++++++++------------------
1 file changed, 30 insertions(+), 18 deletions(-)
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 61447220a8..ee669ee8dc 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -1354,24 +1354,19 @@ static const MemoryRegionOps nvme_cmb_ops = {
},
};
-static void nvme_realize(PCIDevice *pci_dev, Error **errp)
+static void nvme_check_constraints(NvmeCtrl *n, Error **errp)
{
- NvmeCtrl *n = NVME(pci_dev);
- NvmeIdCtrl *id = &n->id_ctrl;
-
- int i;
- int64_t bs_size;
- uint8_t *pci_conf;
+ NvmeParams *params = &n->params;
- if (n->params.num_queues) {
+ if (params->num_queues) {
warn_report("num_queues is deprecated; please use max_ioqpairs "
"instead");
- n->params.max_ioqpairs = n->params.num_queues - 1;
+ params->max_ioqpairs = params->num_queues - 1;
}
- if (n->params.max_ioqpairs < 1 ||
- n->params.max_ioqpairs > PCI_MSIX_FLAGS_QSIZE) {
+ if (params->max_ioqpairs < 1 ||
+ params->max_ioqpairs > PCI_MSIX_FLAGS_QSIZE) {
error_setg(errp, "max_ioqpairs must be between 1 and %d",
PCI_MSIX_FLAGS_QSIZE);
return;
@@ -1382,13 +1377,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error
**errp)
return;
}
- bs_size = blk_getlength(n->conf.blk);
- if (bs_size < 0) {
- error_setg(errp, "could not get backing file size");
- return;
- }
-
- if (!n->params.serial) {
+ if (!params->serial) {
error_setg(errp, "serial property not set");
return;
}
@@ -1408,6 +1397,29 @@ static void nvme_realize(PCIDevice *pci_dev, Error
**errp)
host_memory_backend_set_mapped(n->pmrdev, true);
}
+}
+
+static void nvme_realize(PCIDevice *pci_dev, Error **errp)
+{
+ NvmeCtrl *n = NVME(pci_dev);
+ NvmeIdCtrl *id = &n->id_ctrl;
+ Error *local_err = NULL;
+
+ int i;
+ int64_t bs_size;
+ uint8_t *pci_conf;
+
+ nvme_check_constraints(n, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ bs_size = blk_getlength(n->conf.blk);
+ if (bs_size < 0) {
+ error_setg(errp, "could not get backing file size");
+ return;
+ }
blkconf_blocksizes(&n->conf);
if (!blkconf_apply_backend_options(&n->conf, blk_is_read_only(n->conf.blk),
--
2.25.4
- [PULL 04/43] virtio-blk: On restart, process queued requests in the proper context, (continued)
- [PULL 04/43] virtio-blk: On restart, process queued requests in the proper context, Kevin Wolf, 2020/06/17
- [PULL 06/43] qcow2: Tweak comments on qcow2_get_persistent_dirty_bitmap_size, Kevin Wolf, 2020/06/17
- [PULL 05/43] block: Refactor subdirectory recursion during make, Kevin Wolf, 2020/06/17
- [PULL 02/43] icount: make dma reads deterministic, Kevin Wolf, 2020/06/17
- [PULL 10/43] hw/block/nvme: move device parameters to separate struct, Kevin Wolf, 2020/06/17
- [PULL 07/43] hw/block/nvme: fix pci doorbell size calculation, Kevin Wolf, 2020/06/17
- [PULL 09/43] hw/block/nvme: remove superfluous breaks, Kevin Wolf, 2020/06/17
- [PULL 12/43] hw/block/nvme: refactor nvme_addr_read, Kevin Wolf, 2020/06/17
- [PULL 14/43] hw/block/nvme: add max_ioqpairs device parameter, Kevin Wolf, 2020/06/17
- [PULL 15/43] hw/block/nvme: remove redundant cmbloc/cmbsz members, Kevin Wolf, 2020/06/17
- [PULL 16/43] hw/block/nvme: factor out property/constraint checks,
Kevin Wolf <=
- [PULL 13/43] hw/block/nvme: fix pin-based interrupt behavior, Kevin Wolf, 2020/06/17
- [PULL 11/43] hw/block/nvme: use constants in identify, Kevin Wolf, 2020/06/17
- [PULL 18/43] hw/block/nvme: factor out block backend setup, Kevin Wolf, 2020/06/17
- [PULL 17/43] hw/block/nvme: factor out device state setup, Kevin Wolf, 2020/06/17
- [PULL 19/43] hw/block/nvme: add namespace helpers, Kevin Wolf, 2020/06/17
- [PULL 21/43] hw/block/nvme: factor out pci 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 08/43] hw/block/nvme: rename trace events to pci_nvme, Kevin Wolf, 2020/06/17
- [PULL 20/43] hw/block/nvme: factor out namespace setup, Kevin Wolf, 2020/06/17