Commit bdcb0d70 authored by Cunyin Chang's avatar Cunyin Chang Committed by Jim Harris
Browse files

nvmf: add support of hotplug for nvmf.



Change-Id: Iebd5b75e3525e77bf256f5b7f52aa2504d7a68c3
Signed-off-by: default avatarCunyin Chang <cunyin.chang@intel.com>
Reviewed-on: https://review.gerrithub.io/390549


Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
parent 7f5864be
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -813,7 +813,7 @@ spdk_nvmf_ctrlr_identify_ns(struct spdk_nvmf_subsystem *subsystem,
	struct spdk_nvmf_ns *ns;

	ns = _spdk_nvmf_subsystem_get_ns(subsystem, cmd->nsid);
	if (ns == NULL || ns->bdev == NULL) {
	if (ns == NULL || ns->bdev == NULL || ns->is_removed) {
		SPDK_ERRLOG("Identify Namespace for invalid NSID %u\n", cmd->nsid);
		rsp->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
		return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
@@ -913,7 +913,7 @@ spdk_nvmf_ctrlr_identify_active_ns_list(struct spdk_nvmf_subsystem *subsystem,

	for (ns = spdk_nvmf_subsystem_get_first_ns(subsystem); ns != NULL;
	     ns = spdk_nvmf_subsystem_get_next_ns(subsystem, ns)) {
		if (ns->id <= cmd->nsid) {
		if (ns->id <= cmd->nsid || ns->is_removed) {
			continue;
		}

+2 −1
Original line number Diff line number Diff line
@@ -390,9 +390,10 @@ spdk_nvmf_ctrlr_process_io_cmd(struct spdk_nvmf_request *req)
	nsid = cmd->nsid;

	ns = _spdk_nvmf_subsystem_get_ns(subsystem, nsid);
	if (ns == NULL || ns->bdev == NULL) {
	if (ns == NULL || ns->bdev == NULL || ns->is_removed) {
		SPDK_ERRLOG("Unsuccessful query for nsid %u\n", cmd->nsid);
		response->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
		response->status.dnr = 1;
		return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
	}

+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
#include "nvmf_internal.h"
#include "transport.h"

#include "spdk/event.h"
#include "spdk/string.h"
#include "spdk/trace.h"
#include "spdk/nvmf_spec.h"
+1 −0
Original line number Diff line number Diff line
@@ -130,6 +130,7 @@ struct spdk_nvmf_ns {
	struct spdk_bdev_desc *desc;
	uint32_t id;
	bool allocated;
	bool is_removed;
};

enum spdk_nvmf_qpair_type {
+21 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include "nvmf_internal.h"
#include "transport.h"

#include "spdk/event.h"
#include "spdk/likely.h"
#include "spdk/string.h"
#include "spdk/trace.h"
@@ -488,6 +489,25 @@ spdk_nvmf_subsystem_ns_update_poll_group(struct spdk_io_channel_iter *i)
	spdk_for_each_channel_continue(i, rc);
}

static void
_spdk_nvmf_ns_hot_remove(void *ctx)
{
	struct spdk_nvmf_ns *ns = ctx;

	spdk_nvmf_subsystem_remove_ns(ns->subsystem, ns->id);
}

static void
spdk_nvmf_ns_hot_remove(void *remove_ctx)
{
	struct spdk_nvmf_ns *ns = remove_ctx;

	ns->is_removed = true;
	spdk_thread_send_msg(ns->subsystem->tgt->master_thread,
			     _spdk_nvmf_ns_hot_remove,
			     ns);
}

uint32_t
spdk_nvmf_subsystem_add_ns(struct spdk_nvmf_subsystem *subsystem, struct spdk_bdev *bdev,
			   uint32_t nsid)
@@ -554,7 +574,7 @@ spdk_nvmf_subsystem_add_ns(struct spdk_nvmf_subsystem *subsystem, struct spdk_bd
	ns->bdev = bdev;
	ns->id = nsid;
	ns->subsystem = subsystem;
	rc = spdk_bdev_open(bdev, true, NULL, NULL, &ns->desc);
	rc = spdk_bdev_open(bdev, true, spdk_nvmf_ns_hot_remove, ns, &ns->desc);
	if (rc != 0) {
		SPDK_ERRLOG("Subsystem %s: bdev %s cannot be opened, error=%d\n",
			    subsystem->subnqn, spdk_bdev_get_name(bdev), rc);
Loading