nvmf: add a persist through power loss configuration file when constructing NS

For reservation feature in NVMoF, we can't support the persist through
power loss feature, now we will add the configuration file parameter
with Namespace, after users set the configuration file parameter with
one NS, then the PTPL feature can be enabled.

Change-Id: Id72699093f7e68318b9529f7bacc5c9804f7f86b
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/455905
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Changpeng Liu 2019-05-22 01:56:37 -04:00
parent 37bdd0e87f
commit 3ec061800f
6 changed files with 20 additions and 8 deletions

View File

@ -562,11 +562,13 @@ void spdk_nvmf_ns_opts_get_defaults(struct spdk_nvmf_ns_opts *opts, size_t opts_
* \param bdev Block device to add as a namespace.
* \param opts Namespace options, or NULL to use defaults.
* \param opts_size sizeof(*opts)
* \param ptpl_file Persist through power loss file path.
*
* \return newly added NSID on success, or 0 on failure.
*/
uint32_t spdk_nvmf_subsystem_add_ns(struct spdk_nvmf_subsystem *subsystem, struct spdk_bdev *bdev,
const struct spdk_nvmf_ns_opts *opts, size_t opts_size);
const struct spdk_nvmf_ns_opts *opts, size_t opts_size,
const char *ptpl_file);
/**
* Remove a namespace from a subsytem.

View File

@ -338,7 +338,7 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp)
}
}
if (spdk_nvmf_subsystem_add_ns(subsystem, bdev, &ns_opts, sizeof(ns_opts)) == 0) {
if (spdk_nvmf_subsystem_add_ns(subsystem, bdev, &ns_opts, sizeof(ns_opts), NULL) == 0) {
SPDK_ERRLOG("Unable to add namespace\n");
spdk_nvmf_subsystem_destroy(subsystem);
subsystem = NULL;

View File

@ -895,7 +895,7 @@ 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));
ctx->ns_params.nsid = spdk_nvmf_subsystem_add_ns(subsystem, bdev, &ns_opts, sizeof(ns_opts), NULL);
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,

View File

@ -217,6 +217,8 @@ struct spdk_nvmf_ns {
enum spdk_nvme_reservation_type rtype;
/* current reservation holder, only valid if reservation type can only have one holder */
struct spdk_nvmf_registrant *holder;
/* Persist Through Power Loss file which contains the persistent reservation */
char *ptpl_file;
};
struct spdk_nvmf_qpair {

View File

@ -928,6 +928,9 @@ _spdk_nvmf_subsystem_remove_ns(struct spdk_nvmf_subsystem *subsystem, uint32_t n
}
spdk_bdev_module_release_bdev(ns->bdev);
spdk_bdev_close(ns->desc);
if (ns->ptpl_file) {
free(ns->ptpl_file);
}
free(ns);
spdk_nvmf_subsystem_ns_changed(subsystem, nsid);
@ -1007,7 +1010,8 @@ static struct spdk_bdev_module ns_bdev_module = {
uint32_t
spdk_nvmf_subsystem_add_ns(struct spdk_nvmf_subsystem *subsystem, struct spdk_bdev *bdev,
const struct spdk_nvmf_ns_opts *user_opts, size_t opts_size)
const struct spdk_nvmf_ns_opts *user_opts, size_t opts_size,
const char *ptpl_file)
{
struct spdk_nvmf_ns_opts opts;
struct spdk_nvmf_ns *ns;
@ -1104,6 +1108,10 @@ spdk_nvmf_subsystem_add_ns(struct spdk_nvmf_subsystem *subsystem, struct spdk_bd
ns->nsid = opts.nsid;
TAILQ_INIT(&ns->registrants);
if (ptpl_file) {
ns->ptpl_file = strdup(ptpl_file);
}
SPDK_DEBUGLOG(SPDK_LOG_NVMF, "Subsystem %s: bdev %s assigned nsid %" PRIu32 "\n",
spdk_nvmf_subsystem_get_nqn(subsystem),
spdk_bdev_get_name(bdev),

View File

@ -256,7 +256,7 @@ test_spdk_nvmf_subsystem_add_ns(void)
/* Allow NSID to be assigned automatically */
spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
nsid = spdk_nvmf_subsystem_add_ns(&subsystem, &bdev1, &ns_opts, sizeof(ns_opts));
nsid = spdk_nvmf_subsystem_add_ns(&subsystem, &bdev1, &ns_opts, sizeof(ns_opts), NULL);
/* NSID 1 is the first unused ID */
CU_ASSERT(nsid == 1);
CU_ASSERT(subsystem.max_nsid == 1);
@ -267,7 +267,7 @@ test_spdk_nvmf_subsystem_add_ns(void)
/* Request a specific NSID */
spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
ns_opts.nsid = 5;
nsid = spdk_nvmf_subsystem_add_ns(&subsystem, &bdev2, &ns_opts, sizeof(ns_opts));
nsid = spdk_nvmf_subsystem_add_ns(&subsystem, &bdev2, &ns_opts, sizeof(ns_opts), NULL);
CU_ASSERT(nsid == 5);
CU_ASSERT(subsystem.max_nsid == 5);
SPDK_CU_ASSERT_FATAL(subsystem.ns[nsid - 1] != NULL);
@ -276,14 +276,14 @@ test_spdk_nvmf_subsystem_add_ns(void)
/* Request an NSID that is already in use */
spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
ns_opts.nsid = 5;
nsid = spdk_nvmf_subsystem_add_ns(&subsystem, &bdev2, &ns_opts, sizeof(ns_opts));
nsid = spdk_nvmf_subsystem_add_ns(&subsystem, &bdev2, &ns_opts, sizeof(ns_opts), NULL);
CU_ASSERT(nsid == 0);
CU_ASSERT(subsystem.max_nsid == 5);
/* Request 0xFFFFFFFF (invalid NSID, reserved for broadcast) */
spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
ns_opts.nsid = 0xFFFFFFFF;
nsid = spdk_nvmf_subsystem_add_ns(&subsystem, &bdev2, &ns_opts, sizeof(ns_opts));
nsid = spdk_nvmf_subsystem_add_ns(&subsystem, &bdev2, &ns_opts, sizeof(ns_opts), NULL);
CU_ASSERT(nsid == 0);
CU_ASSERT(subsystem.max_nsid == 5);