diff --git a/doc/jsonrpc.md b/doc/jsonrpc.md index b1250d1f4..e6b0ecfe9 100644 --- a/doc/jsonrpc.md +++ b/doc/jsonrpc.md @@ -345,6 +345,7 @@ nsid | Optional | number | Namespace ID between 1 and 42 bdev_name | Required | string | Name of bdev to expose as a namespace. nguid | Optional | string | 16-byte namespace globally unique identifier in hexadecimal (e.g. "ABCDEF0123456789ABCDEF0123456789") eui64 | Optional | string | 8-byte namespace EUI-64 in hexadecimal (e.g. "ABCDEF0123456789") +uuid | Optional | string | RFC 4122 UUID (e.g. "ceccf520-691e-4b46-9546-34af789907c5") ### Example diff --git a/lib/event/subsystems/nvmf/nvmf_rpc.c b/lib/event/subsystems/nvmf/nvmf_rpc.c index 916de041e..b2a4b2844 100644 --- a/lib/event/subsystems/nvmf/nvmf_rpc.c +++ b/lib/event/subsystems/nvmf/nvmf_rpc.c @@ -166,6 +166,21 @@ decode_ns_eui64(const struct spdk_json_val *val, void *out) return rc; } +static int +decode_ns_uuid(const struct spdk_json_val *val, void *out) +{ + char *str = NULL; + int rc; + + rc = spdk_json_decode_string(val, &str); + if (rc == 0) { + rc = spdk_uuid_parse(out, str); + } + + free(str); + return rc; +} + static void dump_nvmf_subsystem(struct spdk_json_write_ctx *w, struct spdk_nvmf_subsystem *subsystem) { @@ -424,6 +439,7 @@ struct spdk_nvmf_ns_params { uint32_t nsid; char nguid[16]; char eui64[8]; + struct spdk_uuid uuid; }; struct rpc_namespaces { @@ -437,6 +453,7 @@ static const struct spdk_json_object_decoder rpc_ns_params_decoders[] = { {"bdev_name", offsetof(struct spdk_nvmf_ns_params, bdev_name), spdk_json_decode_string}, {"nguid", offsetof(struct spdk_nvmf_ns_params, nguid), decode_ns_nguid, true}, {"eui64", offsetof(struct spdk_nvmf_ns_params, eui64), decode_ns_eui64, true}, + {"uuid", offsetof(struct spdk_nvmf_ns_params, uuid), decode_ns_uuid, true}, }; static void @@ -717,6 +734,10 @@ spdk_rpc_construct_nvmf_subsystem(struct spdk_jsonrpc_request *request, SPDK_STATIC_ASSERT(sizeof(ns_opts.eui64) == sizeof(ns_params->eui64), "size mismatch"); memcpy(ns_opts.eui64, ns_params->eui64, sizeof(ns_opts.eui64)); + if (!spdk_mem_all_zero(&ns_params->uuid, sizeof(ns_params->uuid))) { + ns_opts.uuid = ns_params->uuid; + } + if (spdk_nvmf_subsystem_add_ns(subsystem, bdev, &ns_opts, sizeof(ns_opts)) == 0) { SPDK_ERRLOG("Unable to add namespace\n"); spdk_nvmf_subsystem_destroy(subsystem); @@ -1126,6 +1147,10 @@ nvmf_rpc_ns_paused(struct spdk_nvmf_subsystem *subsystem, SPDK_STATIC_ASSERT(sizeof(ns_opts.eui64) == sizeof(ctx->ns_params.eui64), "size mismatch"); memcpy(ns_opts.eui64, ctx->ns_params.eui64, sizeof(ns_opts.eui64)); + if (!spdk_mem_all_zero(&ctx->ns_params.uuid, sizeof(ctx->ns_params.uuid))) { + ns_opts.uuid = ctx->ns_params.uuid; + } + ctx->ns_params.nsid = spdk_nvmf_subsystem_add_ns(subsystem, bdev, &ns_opts, sizeof(ns_opts)); if (ctx->ns_params.nsid == 0) { SPDK_ERRLOG("Unable to add namespace\n"); diff --git a/scripts/rpc.py b/scripts/rpc.py index f264cf1e6..25690053b 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -895,6 +895,7 @@ if __name__ == "__main__": p.add_argument('-n', '--nsid', help='The requested NSID (optional)', type=int) p.add_argument('-g', '--nguid', help='Namespace globally unique identifier (optional)') p.add_argument('-e', '--eui64', help='Namespace EUI-64 identifier (optional)') + p.add_argument('-u', '--uuid', help='Namespace UUID (optional)') p.set_defaults(func=nvmf_subsystem_add_ns) @call_cmd diff --git a/scripts/rpc/nvmf.py b/scripts/rpc/nvmf.py index 3e17413ab..fdfb0881c 100755 --- a/scripts/rpc/nvmf.py +++ b/scripts/rpc/nvmf.py @@ -84,6 +84,9 @@ def nvmf_subsystem_add_ns(client, args): if args.eui64: ns['eui64'] = args.eui64 + if args.uuid: + ns['uuid'] = args.uuid + params = {'nqn': args.nqn, 'namespace': ns}