nvmf: add ptpl activated flag to Namespace

If users set the persist through power loss configuation file,
that means the Namespace has the capability to support ptpl
feature, here we added a ptpl_activated flag to indicate that
the users enable the feature or not.  Users can use Set features
or Reservation Register commands to change the value.

Change-Id: Iae3fd44085c5be5bf9574e49efa567e8212dee20
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/455906
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Changpeng Liu 2019-06-11 02:21:01 -04:00
parent d2c169d51c
commit cf5c4a8a2e
4 changed files with 20 additions and 8 deletions

View File

@ -1116,8 +1116,7 @@ spdk_nvmf_ctrlr_get_features_reservation_persistence(struct spdk_nvmf_request *r
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
}
/* TODO: Persistence feature can't support for now */
response->cdw0 = 0;
response->cdw0 = ns->ptpl_activated;
response->status.sct = SPDK_NVME_SCT_GENERIC;
response->status.sc = SPDK_NVME_SC_SUCCESS;
@ -1131,12 +1130,22 @@ spdk_nvmf_ctrlr_set_features_reservation_persistence(struct spdk_nvmf_request *r
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
struct spdk_nvmf_ns *ns;
bool ptpl;
SPDK_DEBUGLOG(SPDK_LOG_NVMF, "Set Features - Reservation Persistence\n");
ns = _spdk_nvmf_subsystem_get_ns(ctrlr->subsys, cmd->nsid);
if (cmd->nsid != 0xffffffffu && ns == NULL) {
SPDK_ERRLOG("Set Features - Invalid Namespace ID\n");
ptpl = cmd->cdw11 & 0x1u;
if (cmd->nsid != 0xffffffffu && ns && ns->ptpl_file) {
ns->ptpl_activated = ptpl;
} else if (cmd->nsid == 0xffffffffu) {
for (ns = spdk_nvmf_subsystem_get_first_ns(ctrlr->subsys); ns && ns->ptpl_file;
ns = spdk_nvmf_subsystem_get_next_ns(ctrlr->subsys, ns)) {
ns->ptpl_activated = ptpl;
}
} else {
SPDK_ERRLOG("Set Features - Invalid Namespace ID or Reservation Configuration\n");
response->status.sct = SPDK_NVME_SCT_GENERIC;
response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
@ -1144,7 +1153,7 @@ spdk_nvmf_ctrlr_set_features_reservation_persistence(struct spdk_nvmf_request *r
/* TODO: Feature not changeable for now */
response->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
response->status.sc = SPDK_NVME_SC_FEATURE_NOT_CHANGEABLE;
response->status.sc = SPDK_NVME_SC_FEATURE_ID_NOT_SAVEABLE;
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
}

View File

@ -144,7 +144,9 @@ spdk_nvmf_bdev_ctrlr_identify_ns(struct spdk_nvmf_ns *ns, struct spdk_nvme_ns_da
}
nsdata->noiob = spdk_bdev_get_optimal_io_boundary(bdev);
nsdata->nmic.can_share = 1;
nsdata->nsrescap.rescap.persist = 0; /* TODO: don't support for now */
if (ns->ptpl_file != NULL) {
nsdata->nsrescap.rescap.persist = 1;
}
nsdata->nsrescap.rescap.write_exclusive = 1;
nsdata->nsrescap.rescap.exclusive_access = 1;
nsdata->nsrescap.rescap.write_exclusive_reg_only = 1;

View File

@ -219,6 +219,8 @@ struct spdk_nvmf_ns {
struct spdk_nvmf_registrant *holder;
/* Persist Through Power Loss file which contains the persistent reservation */
char *ptpl_file;
/* Persist Through Power Loss feature is enabled */
bool ptpl_activated;
};
struct spdk_nvmf_qpair {

View File

@ -2009,8 +2009,7 @@ nvmf_ns_reservation_report(struct spdk_nvmf_ns *ns,
status_data->data.gen = ns->gen;
status_data->data.rtype = ns->rtype;
status_data->data.regctl = regctl;
/* TODO: Don't support Persist Through Power Loss State for now */
status_data->data.ptpls = 0;
status_data->data.ptpls = ns->ptpl_activated;
TAILQ_FOREACH_SAFE(reg, &ns->registrants, link, tmp) {
assert(count <= regctl);