@@ -32,13 +32,18 @@
#define MIN_DISCARD_GRANULARITY (4 * KiB)
-static int nvme_ns_init(NvmeNamespace *ns, Error **errp)
+static int nvme_ns_init(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)
{
BlockDriverInfo bdi;
NvmeIdNs *id_ns = &ns->id_ns;
int lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas);
int npdg;
+ if (!n->params.mpath_ctrl && ns->params.mpath_ns) {
+ error_setg(errp, "mpath.ctrl must be enabled for ns sharing");
+ return -1;
+ }
+
ns->id_ns.dlfeat = 0x9;
id_ns->lbaf[lba_index].ds = 31 - clz32(ns->blkconf.logical_block_size);
@@ -63,6 +68,10 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp)
id_ns->npda = id_ns->npdg = npdg - 1;
+ if (ns->params.mpath_ns) {
+ id_ns->nmic |= NVME_NMIC_NS_SHARED;
+ }
+
return 0;
}
@@ -314,7 +323,7 @@ int nvme_ns_setup(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)
return -1;
}
- if (nvme_ns_init(ns, errp)) {
+ if (nvme_ns_init(n, ns, errp)) {
return -1;
}
if (ns->params.zoned) {
@@ -371,6 +380,7 @@ static Property nvme_ns_props[] = {
DEFINE_BLOCK_PROPERTIES(NvmeNamespace, blkconf),
DEFINE_PROP_UINT32("nsid", NvmeNamespace, params.nsid, 0),
DEFINE_PROP_UUID("uuid", NvmeNamespace, params.uuid),
+ DEFINE_PROP_BOOL("mpath.ns", NvmeNamespace, params.mpath_ns, false),
DEFINE_PROP_BOOL("zoned", NvmeNamespace, params.zoned, false),
DEFINE_PROP_SIZE("zoned.zone_size", NvmeNamespace, params.zone_size_bs,
NVME_DEFAULT_ZONE_SIZE),
@@ -29,6 +29,8 @@ typedef struct NvmeNamespaceParams {
uint32_t nsid;
QemuUUID uuid;
+ bool mpath_ns;
+
bool zoned;
bool cross_zone_read;
uint64_t zone_size_bs;
@@ -62,6 +62,12 @@
* can hold two or more controllers. This will be reflected to Identify
* Controller data structure CMIC[76] field.
*
+ * Setting `mpath.ctrl` to true enables the following properties to configure
+ * multi-path for a namespace:
+ * mpath.ns=<true|false, default: false>
+ * If set to true, namespace sharing in a NVM subsystem is enabled.
+ * This will be reflected to Identify Namespace data structure.
+ *
* - `zoned.append_size_limit`
* The maximum I/O size in bytes that is allowed in Zone Append command.
* The default is 128KiB. Since internally this this value is maintained as
Added mpath.ns parameter to set multi-namespace bit[0] in NMIC field in Identify Namespace data structure. It will indicate that the namespace can be shared by two or more controllers. Example: To share the namespace between two controllers in a NVM subsystem, first multi-controllers should be prepared with the same serial: -device nvme,id=nvme0,ctrlid=0,serial=foo,... -device nvme,id=nvme1,ctrlid=1,serial=foo,... Then, we can prepare namespace device with mpath.ns enabled. Also, we must give the same UUID for those two devices with the same Namespace ID. -device nvme-ns,uuid=<uuid>,bus=nvme0,nsid=1,... -device nvme-ns,uuid=<uuid>,bus=nvme1,nsid=1,... Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com> --- hw/block/nvme-ns.c | 14 ++++++++++++-- hw/block/nvme-ns.h | 2 ++ hw/block/nvme.c | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-)