Skip to content

Commit

Permalink
rpc/nvmf: add RPC support to add the persistent configuration file fo…
Browse files Browse the repository at this point in the history
…r one NS

Change-Id: Ic4963d3e55cffceca35d18ba8d406658e51a189a
Signed-off-by: Changpeng Liu <[email protected]>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/455913
Tested-by: SPDK CI Jenkins <[email protected]>
Reviewed-by: Ben Walker <[email protected]>
Reviewed-by: Shuhei Matsumoto <[email protected]>
  • Loading branch information
Changpeng Liu committed Jul 10, 2019
1 parent 7b74274 commit 5317a9f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ A new file API `spdk_posix_file_load` was added to load file content into a data

### NVMe-oF Target

Persistent reservation emulation has been added to the NVMe-oF target. Persistent reservation
state is stored in a JSON file on the local filesystem between target restart. To support this,
an optional parameter to the RPC method `nvmf_subsystem_add_ns` called `--ptpl-file` was added.
This allows the user to specify which file to store the persistent reservation state in. Note
that this is done per namespace.

The c2h success optimization under which a command capsule response is not sent
for reads is turned on. A config knob was added to allow for enable/disable.

Expand Down
4 changes: 3 additions & 1 deletion doc/jsonrpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -3808,6 +3808,7 @@ bdev_name | Required | string | Name of bdev to expose as a n
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")
ptpl_file | Optional | string | File path to save/restore persistent reservation information

### Example

Expand All @@ -3822,7 +3823,8 @@ Example request:
"nqn": "nqn.2016-06.io.spdk:cnode1",
"namespace": {
"nsid": 3,
"bdev_name": "Nvme0n1"
"bdev_name": "Nvme0n1",
"ptpl_file": "/opt/Nvme0n1PR.json"
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion lib/event/subsystems/nvmf/nvmf_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ SPDK_RPC_REGISTER("nvmf_subsystem_remove_listener", spdk_rpc_nvmf_subsystem_remo

struct spdk_nvmf_ns_params {
char *bdev_name;
char *ptpl_file;
uint32_t nsid;
char nguid[16];
char eui64[8];
Expand All @@ -804,6 +805,7 @@ struct rpc_namespaces {
static const struct spdk_json_object_decoder rpc_ns_params_decoders[] = {
{"nsid", offsetof(struct spdk_nvmf_ns_params, nsid), spdk_json_decode_uint32, true},
{"bdev_name", offsetof(struct spdk_nvmf_ns_params, bdev_name), spdk_json_decode_string},
{"ptpl_file", offsetof(struct spdk_nvmf_ns_params, ptpl_file), spdk_json_decode_string, true},
{"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},
Expand Down Expand Up @@ -837,6 +839,7 @@ nvmf_rpc_ns_ctx_free(struct nvmf_rpc_ns_ctx *ctx)
{
free(ctx->nqn);
free(ctx->ns_params.bdev_name);
free(ctx->ns_params.ptpl_file);
free(ctx);
}

Expand Down Expand Up @@ -895,7 +898,8 @@ nvmf_rpc_ns_paused(struct spdk_nvmf_subsystem *subsystem,
ns_opts.uuid = ctx->ns_params.uuid;
}

ctx->ns_params.nsid = spdk_nvmf_subsystem_add_ns(subsystem, bdev, &ns_opts, sizeof(ns_opts), NULL);
ctx->ns_params.nsid = spdk_nvmf_subsystem_add_ns(subsystem, bdev, &ns_opts, sizeof(ns_opts),
ctx->ns_params.ptpl_file);
if (ctx->ns_params.nsid == 0) {
SPDK_ERRLOG("Unable to add namespace\n");
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
Expand Down
2 changes: 2 additions & 0 deletions scripts/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,7 @@ def nvmf_subsystem_add_ns(args):
rpc.nvmf.nvmf_subsystem_add_ns(args.client,
nqn=args.nqn,
bdev_name=args.bdev_name,
ptpl_file=args.ptpl_file,
nsid=args.nsid,
nguid=args.nguid,
eui64=args.eui64,
Expand All @@ -1526,6 +1527,7 @@ def nvmf_subsystem_add_ns(args):
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')
p.add_argument('bdev_name', help='The name of the bdev that will back this namespace')
p.add_argument('-p', '--ptpl-file', help='The persistent reservation storage location (optional)', type=str)
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)')
Expand Down
5 changes: 4 additions & 1 deletion scripts/rpc/nvmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def nvmf_subsystem_remove_listener(
return client.call('nvmf_subsystem_remove_listener', params)


def nvmf_subsystem_add_ns(client, nqn, bdev_name, nsid=None, nguid=None, eui64=None, uuid=None):
def nvmf_subsystem_add_ns(client, nqn, bdev_name, ptpl_file=None, nsid=None, nguid=None, eui64=None, uuid=None):
"""Add a namespace to a subsystem.
Args:
Expand All @@ -228,6 +228,9 @@ def nvmf_subsystem_add_ns(client, nqn, bdev_name, nsid=None, nguid=None, eui64=N
"""
ns = {'bdev_name': bdev_name}

if ptpl_file:
ns['ptpl_file'] = ptpl_file

if nsid:
ns['nsid'] = nsid

Expand Down

0 comments on commit 5317a9f

Please sign in to comment.