bdev/nvme: Move bdev NVMe controller to common layer
Bdev NVMe controller will be used in future by other NVMe based bdevs, so let's move it to common layer. Signed-off-by: Maciej Szwed <maciej.szwed@intel.com> Change-Id: Ic485b556d622011b9e36fec1ce13394fc436bbd8 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/446434 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
47532e9955
commit
b91f8c88d4
@ -34,6 +34,7 @@
|
|||||||
#include "spdk/stdinc.h"
|
#include "spdk/stdinc.h"
|
||||||
|
|
||||||
#include "bdev_nvme.h"
|
#include "bdev_nvme.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#include "spdk/config.h"
|
#include "spdk/config.h"
|
||||||
#include "spdk/conf.h"
|
#include "spdk/conf.h"
|
||||||
@ -117,9 +118,6 @@ static struct spdk_poller *g_hotplug_poller;
|
|||||||
static char *g_nvme_hostnqn = NULL;
|
static char *g_nvme_hostnqn = NULL;
|
||||||
static pthread_mutex_t g_bdev_nvme_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t g_bdev_nvme_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
static TAILQ_HEAD(, nvme_bdev_ctrlr) g_nvme_bdev_ctrlrs = TAILQ_HEAD_INITIALIZER(
|
|
||||||
g_nvme_bdev_ctrlrs);
|
|
||||||
|
|
||||||
static void nvme_ctrlr_create_bdevs(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr);
|
static void nvme_ctrlr_create_bdevs(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr);
|
||||||
static int bdev_nvme_library_init(void);
|
static int bdev_nvme_library_init(void);
|
||||||
static void bdev_nvme_library_fini(void);
|
static void bdev_nvme_library_fini(void);
|
||||||
@ -829,38 +827,6 @@ hotplug_probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct nvme_bdev_ctrlr *
|
|
||||||
nvme_ctrlr_get(const struct spdk_nvme_transport_id *trid)
|
|
||||||
{
|
|
||||||
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
|
|
||||||
|
|
||||||
TAILQ_FOREACH(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq) {
|
|
||||||
if (spdk_nvme_transport_id_compare(trid, &nvme_bdev_ctrlr->trid) == 0) {
|
|
||||||
return nvme_bdev_ctrlr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct nvme_bdev_ctrlr *
|
|
||||||
nvme_ctrlr_get_by_name(const char *name)
|
|
||||||
{
|
|
||||||
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
|
|
||||||
|
|
||||||
if (name == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
TAILQ_FOREACH(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq) {
|
|
||||||
if (strcmp(name, nvme_bdev_ctrlr->name) == 0) {
|
|
||||||
return nvme_bdev_ctrlr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
||||||
struct spdk_nvme_ctrlr_opts *opts)
|
struct spdk_nvme_ctrlr_opts *opts)
|
||||||
@ -869,7 +835,7 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
|||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_BDEV_NVME, "Probing device %s\n", trid->traddr);
|
SPDK_DEBUGLOG(SPDK_LOG_BDEV_NVME, "Probing device %s\n", trid->traddr);
|
||||||
|
|
||||||
if (nvme_ctrlr_get(trid)) {
|
if (nvme_bdev_ctrlr_get(trid)) {
|
||||||
SPDK_ERRLOG("A controller with the provided trid (traddr: %s) already exists.\n",
|
SPDK_ERRLOG("A controller with the provided trid (traddr: %s) already exists.\n",
|
||||||
trid->traddr);
|
trid->traddr);
|
||||||
return false;
|
return false;
|
||||||
@ -1229,12 +1195,12 @@ spdk_bdev_nvme_create(struct spdk_nvme_transport_id *trid,
|
|||||||
size_t j;
|
size_t j;
|
||||||
struct nvme_probe_skip_entry *entry, *tmp;
|
struct nvme_probe_skip_entry *entry, *tmp;
|
||||||
|
|
||||||
if (nvme_ctrlr_get(trid) != NULL) {
|
if (nvme_bdev_ctrlr_get(trid) != NULL) {
|
||||||
SPDK_ERRLOG("A controller with the provided trid (traddr: %s) already exists.\n", trid->traddr);
|
SPDK_ERRLOG("A controller with the provided trid (traddr: %s) already exists.\n", trid->traddr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nvme_ctrlr_get_by_name(base_name)) {
|
if (nvme_bdev_ctrlr_get_by_name(base_name)) {
|
||||||
SPDK_ERRLOG("A controller with the provided name (%s) already exists.\n", base_name);
|
SPDK_ERRLOG("A controller with the provided name (%s) already exists.\n", base_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1274,7 +1240,7 @@ spdk_bdev_nvme_create(struct spdk_nvme_transport_id *trid,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
nvme_bdev_ctrlr = nvme_ctrlr_get(trid);
|
nvme_bdev_ctrlr = nvme_bdev_ctrlr_get(trid);
|
||||||
if (!nvme_bdev_ctrlr) {
|
if (!nvme_bdev_ctrlr) {
|
||||||
SPDK_ERRLOG("Failed to find new NVMe controller\n");
|
SPDK_ERRLOG("Failed to find new NVMe controller\n");
|
||||||
return -1;
|
return -1;
|
||||||
@ -1317,7 +1283,7 @@ spdk_bdev_nvme_delete(const char *name)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
nvme_bdev_ctrlr = nvme_ctrlr_get_by_name(name);
|
nvme_bdev_ctrlr = nvme_bdev_ctrlr_get_by_name(name);
|
||||||
if (nvme_bdev_ctrlr == NULL) {
|
if (nvme_bdev_ctrlr == NULL) {
|
||||||
SPDK_ERRLOG("Failed to find NVMe controller\n");
|
SPDK_ERRLOG("Failed to find NVMe controller\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
@ -1471,7 +1437,7 @@ bdev_nvme_library_init(void)
|
|||||||
struct spdk_nvme_ctrlr *ctrlr;
|
struct spdk_nvme_ctrlr *ctrlr;
|
||||||
struct spdk_nvme_ctrlr_opts opts;
|
struct spdk_nvme_ctrlr_opts opts;
|
||||||
|
|
||||||
if (nvme_ctrlr_get(&probe_ctx->trids[i])) {
|
if (nvme_bdev_ctrlr_get(&probe_ctx->trids[i])) {
|
||||||
SPDK_ERRLOG("A controller with the provided trid (traddr: %s) already exists.\n",
|
SPDK_ERRLOG("A controller with the provided trid (traddr: %s) already exists.\n",
|
||||||
probe_ctx->trids[i].traddr);
|
probe_ctx->trids[i].traddr);
|
||||||
rc = -1;
|
rc = -1;
|
||||||
@ -1527,7 +1493,7 @@ bdev_nvme_library_init(void)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nvme_ctrlr_get(&probe_ctx->trids[i])) {
|
if (!nvme_bdev_ctrlr_get(&probe_ctx->trids[i])) {
|
||||||
SPDK_ERRLOG("NVMe SSD \"%s\" could not be found.\n", probe_ctx->trids[i].traddr);
|
SPDK_ERRLOG("NVMe SSD \"%s\" could not be found.\n", probe_ctx->trids[i].traddr);
|
||||||
SPDK_ERRLOG("Check PCIe BDF and that it is attached to UIO/VFIO driver.\n");
|
SPDK_ERRLOG("Check PCIe BDF and that it is attached to UIO/VFIO driver.\n");
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,6 @@
|
|||||||
#include "spdk/nvme.h"
|
#include "spdk/nvme.h"
|
||||||
#include "spdk/bdev_module.h"
|
#include "spdk/bdev_module.h"
|
||||||
|
|
||||||
#define NVME_MAX_CONTROLLERS 1024
|
|
||||||
|
|
||||||
enum spdk_bdev_timeout_action {
|
enum spdk_bdev_timeout_action {
|
||||||
SPDK_BDEV_NVME_TIMEOUT_ACTION_NONE = 0,
|
SPDK_BDEV_NVME_TIMEOUT_ACTION_NONE = 0,
|
||||||
SPDK_BDEV_NVME_TIMEOUT_ACTION_RESET,
|
SPDK_BDEV_NVME_TIMEOUT_ACTION_RESET,
|
||||||
@ -55,41 +53,6 @@ struct spdk_bdev_nvme_opts {
|
|||||||
uint64_t nvme_adminq_poll_period_us;
|
uint64_t nvme_adminq_poll_period_us;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct nvme_bdev_ctrlr {
|
|
||||||
/**
|
|
||||||
* points to pinned, physically contiguous memory region;
|
|
||||||
* contains 4KB IDENTIFY structure for controller which is
|
|
||||||
* target for CONTROLLER IDENTIFY command during initialization
|
|
||||||
*/
|
|
||||||
struct spdk_nvme_ctrlr *ctrlr;
|
|
||||||
struct spdk_nvme_transport_id trid;
|
|
||||||
char *name;
|
|
||||||
int ref;
|
|
||||||
bool destruct;
|
|
||||||
/**
|
|
||||||
* PI check flags. This flags is set to NVMe controllers created only
|
|
||||||
* through construct_nvme_bdev RPC or .INI config file. Hot added
|
|
||||||
* NVMe controllers are not included.
|
|
||||||
*/
|
|
||||||
uint32_t prchk_flags;
|
|
||||||
uint32_t num_ns;
|
|
||||||
/** Array of bdevs indexed by nsid - 1 */
|
|
||||||
struct nvme_bdev *bdevs;
|
|
||||||
|
|
||||||
struct spdk_poller *adminq_timer_poller;
|
|
||||||
|
|
||||||
/** linked list pointer for device list */
|
|
||||||
TAILQ_ENTRY(nvme_bdev_ctrlr) tailq;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct nvme_bdev {
|
|
||||||
struct spdk_bdev disk;
|
|
||||||
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
|
|
||||||
uint32_t id;
|
|
||||||
bool active;
|
|
||||||
struct spdk_nvme_ns *ns;
|
|
||||||
};
|
|
||||||
|
|
||||||
void spdk_bdev_nvme_dump_trid_json(struct spdk_nvme_transport_id *trid,
|
void spdk_bdev_nvme_dump_trid_json(struct spdk_nvme_transport_id *trid,
|
||||||
struct spdk_json_write_ctx *w);
|
struct spdk_json_write_ctx *w);
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "spdk/stdinc.h"
|
#include "spdk/stdinc.h"
|
||||||
|
|
||||||
#include "bdev_nvme.h"
|
#include "bdev_nvme.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#include "spdk/string.h"
|
#include "spdk/string.h"
|
||||||
#include "spdk/rpc.h"
|
#include "spdk/rpc.h"
|
||||||
|
@ -30,3 +30,40 @@
|
|||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "spdk/env.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
struct nvme_bdev_ctrlrs g_nvme_bdev_ctrlrs = TAILQ_HEAD_INITIALIZER(g_nvme_bdev_ctrlrs);
|
||||||
|
|
||||||
|
struct nvme_bdev_ctrlr *
|
||||||
|
nvme_bdev_ctrlr_get(const struct spdk_nvme_transport_id *trid)
|
||||||
|
{
|
||||||
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
|
||||||
|
|
||||||
|
TAILQ_FOREACH(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq) {
|
||||||
|
if (spdk_nvme_transport_id_compare(trid, &nvme_bdev_ctrlr->trid) == 0) {
|
||||||
|
return nvme_bdev_ctrlr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct nvme_bdev_ctrlr *
|
||||||
|
nvme_bdev_ctrlr_get_by_name(const char *name)
|
||||||
|
{
|
||||||
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
|
||||||
|
|
||||||
|
if (name == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAILQ_FOREACH(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq) {
|
||||||
|
if (strcmp(name, nvme_bdev_ctrlr->name) == 0) {
|
||||||
|
return nvme_bdev_ctrlr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
@ -34,4 +34,50 @@
|
|||||||
#ifndef SPDK_COMMON_BDEV_NVME_H
|
#ifndef SPDK_COMMON_BDEV_NVME_H
|
||||||
#define SPDK_COMMON_BDEV_NVME_H
|
#define SPDK_COMMON_BDEV_NVME_H
|
||||||
|
|
||||||
|
#include "spdk/nvme.h"
|
||||||
|
#include "spdk/bdev_module.h"
|
||||||
|
|
||||||
|
TAILQ_HEAD(nvme_bdev_ctrlrs, nvme_bdev_ctrlr);
|
||||||
|
extern struct nvme_bdev_ctrlrs g_nvme_bdev_ctrlrs;
|
||||||
|
|
||||||
|
#define NVME_MAX_CONTROLLERS 1024
|
||||||
|
|
||||||
|
struct nvme_bdev_ctrlr {
|
||||||
|
/**
|
||||||
|
* points to pinned, physically contiguous memory region;
|
||||||
|
* contains 4KB IDENTIFY structure for controller which is
|
||||||
|
* target for CONTROLLER IDENTIFY command during initialization
|
||||||
|
*/
|
||||||
|
struct spdk_nvme_ctrlr *ctrlr;
|
||||||
|
struct spdk_nvme_transport_id trid;
|
||||||
|
char *name;
|
||||||
|
int ref;
|
||||||
|
bool destruct;
|
||||||
|
/**
|
||||||
|
* PI check flags. This flags is set to NVMe controllers created only
|
||||||
|
* through construct_nvme_bdev RPC or .INI config file. Hot added
|
||||||
|
* NVMe controllers are not included.
|
||||||
|
*/
|
||||||
|
uint32_t prchk_flags;
|
||||||
|
uint32_t num_ns;
|
||||||
|
/** Array of bdevs indexed by nsid - 1 */
|
||||||
|
struct nvme_bdev *bdevs;
|
||||||
|
|
||||||
|
struct spdk_poller *adminq_timer_poller;
|
||||||
|
|
||||||
|
/** linked list pointer for device list */
|
||||||
|
TAILQ_ENTRY(nvme_bdev_ctrlr) tailq;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nvme_bdev {
|
||||||
|
struct spdk_bdev disk;
|
||||||
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
|
||||||
|
uint32_t id;
|
||||||
|
bool active;
|
||||||
|
struct spdk_nvme_ns *ns;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr_get(const struct spdk_nvme_transport_id *trid);
|
||||||
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr_get_by_name(const char *name);
|
||||||
|
|
||||||
#endif /* SPDK_COMMON_BDEV_NVME_H */
|
#endif /* SPDK_COMMON_BDEV_NVME_H */
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "spdk_internal/log.h"
|
#include "spdk_internal/log.h"
|
||||||
|
|
||||||
#include "bdev_nvme.h"
|
#include "bdev_nvme.h"
|
||||||
|
#include "common.h"
|
||||||
#include "spdk/base64.h"
|
#include "spdk/base64.h"
|
||||||
|
|
||||||
enum spdk_nvme_rpc_type {
|
enum spdk_nvme_rpc_type {
|
||||||
|
Loading…
Reference in New Issue
Block a user