[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 09/18] nvme: factor out property/constraint checks
From: |
Klaus Jensen |
Subject: |
[PATCH v5 09/18] nvme: factor out property/constraint checks |
Date: |
Tue, 5 May 2020 07:48:31 +0200 |
From: Klaus Jensen <address@hidden>
Signed-off-by: Klaus Jensen <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Reviewed-by: Maxim Levitsky <address@hidden>
Reviewed-by: Keith Busch <address@hidden>
---
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 cc6d3059ff7f..13fb90c77e90 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -1352,24 +1352,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;
+ NvmeParams *params = &n->params;
- int i;
- int64_t bs_size;
- uint8_t *pci_conf;
-
- 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;
@@ -1380,13 +1375,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;
}
@@ -1406,6 +1395,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.26.2
- Re: [PATCH v5 06/18] nvme: refactor nvme_addr_read, (continued)
- [PATCH v5 04/18] nvme: move device parameters to separate struct, Klaus Jensen, 2020/05/05
- [PATCH v5 05/18] nvme: use constants in identify, Klaus Jensen, 2020/05/05
- [PATCH v5 08/18] nvme: remove redundant cmbloc/cmbsz members, Klaus Jensen, 2020/05/05
- [PATCH v5 02/18] nvme: rename trace events to pci_nvme, Klaus Jensen, 2020/05/05
- [PATCH v5 10/18] nvme: factor out device state setup, Klaus Jensen, 2020/05/05
- [PATCH v5 07/18] nvme: add max_ioqpairs device parameter, Klaus Jensen, 2020/05/05
- [PATCH v5 15/18] nvme: factor out cmb setup, Klaus Jensen, 2020/05/05
- [PATCH v5 14/18] nvme: factor out pci setup, Klaus Jensen, 2020/05/05
- [PATCH v5 09/18] nvme: factor out property/constraint checks,
Klaus Jensen <=
- [PATCH v5 11/18] nvme: factor out block backend setup, Klaus Jensen, 2020/05/05
- [PATCH v5 12/18] nvme: add namespace helpers, Klaus Jensen, 2020/05/05
- [PATCH v5 17/18] nvme: do cmb/pmr init as part of pci init, Klaus Jensen, 2020/05/05
- [PATCH v5 13/18] nvme: factor out namespace setup, Klaus Jensen, 2020/05/05
- [PATCH v5 16/18] nvme: factor out pmr setup, Klaus Jensen, 2020/05/05
- [PATCH v5 18/18] nvme: factor out controller identify setup, Klaus Jensen, 2020/05/05
- Re: [PATCH v5 00/18] nvme: refactoring and cleanups, Philippe Mathieu-Daudé, 2020/05/05
- Re: [PATCH v5 00/18] nvme: refactoring and cleanups, Klaus Jensen, 2020/05/11