hw/nvme: Support for Namespaces Management from guest OS - delete-ns
Subsystems (2)
PATCH v2 1/1 hw/nvme: Support for Namespaces Management from guest OS - delete-ns
Added support for NVMEe NameSpaces Mangement allowing the guest OS to create, delete namespaces by issuing create-ns and delet-ns commands. It is an extension to currently implemented Qemu nvme virtual device. Virtual devices representing namespaces will be created and/or deleted during Qemu's running session, at anytime.
First create-ns (sent previously)
Second delete-ns (this patch)
Description:
Currently namespaces could be defined as follows:
1. Legacy Namespace - just one namespace within Nvme controller's where the back-end was specified for nvme device by -drive parameter pointing directly to the image file.
2. Additional Namespaces - specified by nvme-ns devices each having its own back-end. To have multiple namespaces each needed to be specified at Qemu's command line being associated with the most recently defined nvme-bus from nvme device.
If a such additional namespace should be attached and/or detached by the guest OS, nvme controller has to be linked with another device nvme-subsys.
All that has a static behavior, all need to be specified at the Qemu's command line, all specified virtual nvme entities will be processed during Qemu's start-up created and provided to the guest OS.
To have a support for nvme create-ns and delete-ns commands with specified parameters, as the NVMe specification defines, a different approach is needed. Virtual devices representing namespaces need to be created and/or deleted during Qemu's running session, at anytime. The back-end image sizes for a namespace must accommodate the payload size and size of metadata resulted from specified parameters. And the total capacity of the nvme controller together with un-allocated capacity needs to be taken into account and updated following the commands nvme create-ns and delete-ns respectively.
Here is the approach:
The nvme device will get new parameters:
- auto-ns-path, specifies the path to to image and necessary configuration files.
- auto-ns-purge, controls behavior when delete-ns command is issued. If set to 'on' the associated back-end images will be deleted, otherwise such will be preserved as backup files (not Qemu backup files)
- auto-ns-tnvmcap, specifies total controller's space pool in bytes that can be allocated for namespaces, usually when nvme device is created first time. When Qemu restarted this parameter could be omitted.
The virtual devices representing namespace will be created during the Qemu running session dynamically. QOM classes and instances will be created utilizing existing configuration scheme already used for Qemu's start-up. Back-end images will be created and associated with QOM namespaces (virtual instances) or disassociated deleted or renamed. Also it is assured that all settings will remain persistent over Qemu start-ups and shutdowns. The implementation makes it possible to combine the existing "Additional Namespace" implementation with the new "Managed Namespaces", those will coexist with obvious restrictions, like both will share the same NsIds space, "static" namespaces will not be deleted etc..
--- docs/system/devices/nvme.rst | 30 ++++- hw/nvme/ctrl-cfg.c | 238 +++++++++++++++++++++++++++++++++++ hw/nvme/ctrl.c | 114 ++++++++++++++++- hw/nvme/meson.build | 2 +- hw/nvme/ns-backend.c | 77 +++++++++++- hw/nvme/ns.c | 66 ++++++++++ hw/nvme/nvme.h | 13 ++ hw/nvme/trace-events | 1 + include/block/nvme.h | 1 + 9 files changed, 537 insertions(+), 5 deletions(-) create mode 100644 hw/nvme/ctrl-cfg.c
docs/system/devices/nvme.rst +29 -1
@@ -92,7 +92,7 @@ There are a number of parameters available: attach the namespace to a specific ``nvme`` device (identified by an ``id`` parameter on the controller device). -Additional Namespaces managed by guest OS Namespaces management +Additional Namespaces managed by guest OS Namespaces Management --------------------------------------------------------------------- .. code-block:: console
@@ -114,6 +114,34 @@ Parameters: contain namespace parameters and state of attachment allowing QEMU to configure namespaces accordingly during its start up. +``auto-ns-purge=on`` (default: ``off``) + If set to ``on`` will cause immediate deletion of backend image files after + issuing of nvme delete-ns. Default value is ``off``, preserving backend + image files by renaming them. (adding _bak_### suffix) + +``auto-tnvmcap=<size>`` (default: ``0``) + if specified sets the total NVM capacity (TNVMCAP) in bytes that is + accessible by the controller. + It is required if the nvme device is specified first time. + The tnvmcap will be stored in the "nvme_<ctrl SN>_ctrl.cfg" file. If QEMU + will be started afterwards and parameter ``auto-tnvmcap`` is specified, + tnvmcap will be checked against the already stored value and the check will + fail in a case if there is no match. + Omitting of ``auto-tnvmcap`` requires that the "nvme_<ctrl SN>_ctrl.cfg" + file already exists and no check will follow. The "nvme_<ctrl SN>_ctrl.cfg" + contains also UNVMCAP which will be automatically updated accordingly + following create-ns or delete-ns commands respectively. + +Please note that ``nvme-ns`` device is not required to support of dynamic +namespaces management feature. It is not prohibited to assign a such device to +``nvme`` device specified to support dynamic namespace management if ones has +an use case to do so, however, it will only coexist and be out of the scope of +Namespaces Management. Deletion (delete-ns) will render an error for this +namespace. NsIds will be consistently managed, creation (create-ns) of +a namespace will not allocate the NsId already being taken or if conflicts +with previously created one by create-ns, it will break QEMU's start up. + + NVM Subsystems --------------
hw/nvme/ctrl-cfg.c new file +238 -0
238 lines not on this page · raw message
hw/nvme/ctrl.c +112 -2
157 lines not on this page · raw message
hw/nvme/meson.build +1 -1
@@ -1 +1 @@ -softmmu_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('ctrl.c', 'dif.c', 'ns.c', 'subsys.c', 'ns-backend.c', 'cfg_key_checker.c')) +softmmu_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('ctrl.c', 'dif.c', 'ns.c', 'subsys.c', 'ns-backend.c', 'cfg_key_checker.c', 'ctrl-cfg.c'))
hw/nvme/ns-backend.c +76 -1
89 lines not on this page · raw message
hw/nvme/ns.c +66 -0
78 lines not on this page · raw message
hw/nvme/nvme.h +13 -0
@@ -281,6 +281,8 @@ void nvme_ns_shutdown(NvmeNamespace *ns);void nvme_ns_cleanup (NvmeNamespace *ns);void nvme_validate_flbas (uint8_t flbas,Error **errp);NvmeNamespace *nvme_ns_create (NvmeCtrl *n,uint32_t nsid,NvmeIdNsMgmt *id_ns,Error **errp); +void nvme_ns_delete (NvmeCtrl *n,uint32_t nsid,Error **errp); +void ns_blockdev_release (NvmeCtrl *n,NvmeNamespace *ns,uint32_t nsid,Error **errp); typedef struct NvmeAsyncEvent { QTAILQ_ENTRY(NvmeAsyncEvent) entry;
@@ -432,6 +434,7 @@ typedef struct NvmeParams {uint8_t sriov_max_vi_per_vf;char *ns_directory;/* if empty (default) one legacy ns will be created */ bool ns_purge;/* allowing purging of auto ns images if ns deleted */ +uint64_t tnvmcap; } NvmeParams; typedef struct NvmeCtrl {
@@ -592,10 +595,20 @@ void nvme_rw_complete_cb(void *opaque, int ret);uint16_t nvme_map_dptr (NvmeCtrl *n,NvmeSg *sg,size_t len,NvmeCmd *cmd);char *ns_create_image_name (NvmeCtrl *n,uint32_t nsid,Error **errp); +int ns_storage_path_check (NvmeCtrl *n,Error **errp);int ns_auto_check (NvmeCtrl *n,NvmeNamespace *ns,uint32_t nsid);int ns_cfg_save (NvmeCtrl *n,NvmeNamespace *ns,uint32_t nsid);int ns_cfg_load (NvmeCtrl *n,NvmeNamespace *ns,uint32_t nsid);int64_t qdict_get_int_chkd (const QDict *qdict,const char *key,Error **errp);bool qdict_get_bool_chkd (const QDict *qdict,const char *key,Error **errp); +int nvme_cfg_save (NvmeCtrl *n); +int nvme_cfg_load (NvmeCtrl *n); + +typedef enum NvmeNsAllocAction { +NVME_NS_ALLOC_CHK , +NVME_NS_ALLOC , +NVME_NS_DEALLOC , +}NvmeNsAllocAction ; +int nvme_cfg_update (NvmeCtrl *n,uint64_t ammount,NvmeNsAllocAction action);#endif /* HW_NVME_NVME_H */
hw/nvme/trace-events +1 -0
@@ -79,6 +79,7 @@ pci_nvme_aer_masked(uint8_t type, uint8_t mask) "type 0x%"PRIx8" mask 0x%"PRIx8" pci_nvme_aer_post_cqe(uint8_t typ, uint8_t info, uint8_t log_page) "type 0x%"PRIx8" info 0x%"PRIx8" lid 0x%"PRIx8"" pci_nvme_ns_mgmt(uint16_t cid, uint32_t nsid, uint8_t sel, uint8_t csi, uint8_t psdt) "cid %"PRIu16", nsid=%"PRIu32", sel=0x%"PRIx8", csi=0x%"PRIx8", psdt=0x%"PRIx8"" pci_nvme_ns_create(uint16_t nsid, uint64_t nsze, uint64_t ncap, uint8_t flbas) "nsid %"PRIu16", nsze=%"PRIu64", ncap=%"PRIu64", flbas=%"PRIu8"" +pci_nvme_ns_delete(uint16_t nsid) "nsid %"PRIu16"" pci_nvme_ns_attachment(uint16_t cid, uint8_t sel) "cid %"PRIu16", sel=0x%"PRIx8"" pci_nvme_ns_attachment_attach(uint16_t cntlid, uint32_t nsid) "cntlid=0x%"PRIx16", nsid=0x%"PRIx32"" pci_nvme_enqueue_event(uint8_t typ, uint8_t info, uint8_t log_page) "type 0x%"PRIx8" info 0x%"PRIx8" lid 0x%"PRIx8""
include/block/nvme.h +1 -0
@@ -898,6 +898,7 @@ enum NvmeStatusCodes {NVME_FEAT_NOT_CHANGEABLE =0x010e ,NVME_FEAT_NOT_NS_SPEC =0x010f ,NVME_FW_REQ_SUSYSTEM_RESET =0x0110 , +NVME_NS_INSUFFICIENT_CAPAC =0x0115 ,NVME_NS_IDNTIFIER_UNAVAIL =0x0116 ,NVME_NS_ALREADY_ATTACHED =0x0118 , NVME_NS_PRIVATE = 0x0119,
Signature · 1 line
2.37.1