From 694fa34d65c5361a2639e75199212172c7822761 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Fri, 6 Aug 2021 15:05:52 +0900 Subject: [PATCH] nvmf: Make anagrpid configurable when adding ns to subsystem by RPC Signed-off-by: Shuhei Matsumoto Change-Id: I77e2e79889edb87374d81638380887ccc711818a Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9114 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris --- CHANGELOG.md | 2 ++ doc/jsonrpc.md | 1 + lib/nvmf/nvmf.c | 4 ++++ lib/nvmf/nvmf_rpc.c | 8 ++++++++ scripts/rpc.py | 4 +++- scripts/rpc/nvmf.py | 15 ++++++++++++++- 6 files changed, 32 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d1da49ef..3695cb900 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ An `opts_size` element was added in the `spdk_nvmf_ns_opts` structure to solve t ABI compatibility issue between different SPDK version. An new option `anagrpid` was added in the `spdk_nvmf_ns_opts` structure. +An new parameter `anagrpid` was added to the RPC `nvmf_subsystem_add_ns`. + ### bdev New API `spdk_bdev_get_memory_domains` has been added, it allows to get SPDK memory domains used by bdev. diff --git a/doc/jsonrpc.md b/doc/jsonrpc.md index d41812dc6..f0210b502 100644 --- a/doc/jsonrpc.md +++ b/doc/jsonrpc.md @@ -6343,6 +6343,7 @@ nguid | Optional | string | 16-byte namespace globally un 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") ptpl_file | Optional | string | File path to save/restore persistent reservation information +anagrpid | Optional | number | ANA group ID. Default: Namespace ID. #### Example diff --git a/lib/nvmf/nvmf.c b/lib/nvmf/nvmf.c index d3a63c81a..a9aeaa47c 100644 --- a/lib/nvmf/nvmf.c +++ b/lib/nvmf/nvmf.c @@ -562,6 +562,10 @@ nvmf_write_subsystem_config_json(struct spdk_json_write_ctx *w, spdk_json_write_named_string(w, "uuid", uuid_str); } + if (nvmf_subsystem_get_ana_reporting(subsystem)) { + spdk_json_write_named_uint32(w, "anagrpid", ns_opts.anagrpid); + } + /* "namespace" */ spdk_json_write_object_end(w); diff --git a/lib/nvmf/nvmf_rpc.c b/lib/nvmf/nvmf_rpc.c index e0636f6db..2d244c5a8 100644 --- a/lib/nvmf/nvmf_rpc.c +++ b/lib/nvmf/nvmf_rpc.c @@ -291,6 +291,10 @@ dump_nvmf_subsystem(struct spdk_json_write_ctx *w, struct spdk_nvmf_subsystem *s spdk_json_write_named_string(w, "uuid", uuid_str); } + if (nvmf_subsystem_get_ana_reporting(subsystem)) { + spdk_json_write_named_uint32(w, "anagrpid", ns_opts.anagrpid); + } + spdk_json_write_object_end(w); } spdk_json_write_array_end(w); @@ -1078,6 +1082,7 @@ struct spdk_nvmf_ns_params { char nguid[16]; char eui64[8]; struct spdk_uuid uuid; + uint32_t anagrpid; }; static const struct spdk_json_object_decoder rpc_ns_params_decoders[] = { @@ -1087,6 +1092,7 @@ static const struct spdk_json_object_decoder rpc_ns_params_decoders[] = { {"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}, + {"anagrpid", offsetof(struct spdk_nvmf_ns_params, anagrpid), spdk_json_decode_uint32, true}, }; static int @@ -1204,6 +1210,8 @@ nvmf_rpc_ns_paused(struct spdk_nvmf_subsystem *subsystem, ns_opts.uuid = ctx->ns_params.uuid; } + ns_opts.anagrpid = ctx->ns_params.anagrpid; + ctx->ns_params.nsid = spdk_nvmf_subsystem_add_ns_ext(subsystem, ctx->ns_params.bdev_name, &ns_opts, sizeof(ns_opts), ctx->ns_params.ptpl_file); diff --git a/scripts/rpc.py b/scripts/rpc.py index 308e31bc5..b83156b60 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -2056,7 +2056,8 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse nsid=args.nsid, nguid=args.nguid, eui64=args.eui64, - uuid=args.uuid) + uuid=args.uuid, + anagrpid=args.anagrpid) p = subparsers.add_parser('nvmf_subsystem_add_ns', help='Add a namespace to an NVMe-oF subsystem') p.add_argument('nqn', help='NVMe-oF subsystem NQN') @@ -2067,6 +2068,7 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse 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.add_argument('-a', '--anagrpid', help='ANA group ID (optional)', type=int) p.set_defaults(func=nvmf_subsystem_add_ns) def nvmf_subsystem_remove_ns(args): diff --git a/scripts/rpc/nvmf.py b/scripts/rpc/nvmf.py index 1a93e04ce..1b0bd8099 100644 --- a/scripts/rpc/nvmf.py +++ b/scripts/rpc/nvmf.py @@ -332,7 +332,16 @@ def nvmf_subsystem_listener_set_ana_state( return client.call('nvmf_subsystem_listener_set_ana_state', params) -def nvmf_subsystem_add_ns(client, nqn, bdev_name, tgt_name=None, ptpl_file=None, nsid=None, nguid=None, eui64=None, uuid=None): +def nvmf_subsystem_add_ns(client, + nqn, + bdev_name, + tgt_name=None, + ptpl_file=None, + nsid=None, + nguid=None, + eui64=None, + uuid=None, + anagrpid=None): """Add a namespace to a subsystem. Args: @@ -343,6 +352,7 @@ def nvmf_subsystem_add_ns(client, nqn, bdev_name, tgt_name=None, ptpl_file=None, nguid: 16-byte namespace globally unique identifier in hexadecimal (optional). eui64: 8-byte namespace EUI-64 in hexadecimal (e.g. "ABCDEF0123456789") (optional). uuid: Namespace UUID (optional). + anagrpid: ANA group ID (optional). Returns: The namespace ID @@ -364,6 +374,9 @@ def nvmf_subsystem_add_ns(client, nqn, bdev_name, tgt_name=None, ptpl_file=None, if uuid: ns['uuid'] = uuid + if anagrpid: + ns['anagrpid'] = anagrpid + params = {'nqn': nqn, 'namespace': ns}