nvme: change global g_nvme_driver object to a pointer

This is a step towards enabling sharing SPDK NVMe
device access from multiple processes using DPDK's
multi-process framework.

Change-Id: I57d5eec158b42addc1036bd2583596471a467a95
Signed-off-by: GangCao <gang.cao@intel.com>
This commit is contained in:
GangCao 2016-08-01 21:55:23 -04:00 committed by Daniel Verkamp
parent ac7151b161
commit b724e2e5a6
4 changed files with 25 additions and 25 deletions

View File

@ -33,12 +33,14 @@
#include "nvme_internal.h"
struct nvme_driver g_nvme_driver = {
struct nvme_driver _g_nvme_driver = {
.lock = NVME_MUTEX_INITIALIZER,
.init_ctrlrs = TAILQ_HEAD_INITIALIZER(g_nvme_driver.init_ctrlrs),
.attached_ctrlrs = TAILQ_HEAD_INITIALIZER(g_nvme_driver.attached_ctrlrs),
.init_ctrlrs = TAILQ_HEAD_INITIALIZER(_g_nvme_driver.init_ctrlrs),
.attached_ctrlrs = TAILQ_HEAD_INITIALIZER(_g_nvme_driver.attached_ctrlrs),
};
struct nvme_driver *g_nvme_driver = &_g_nvme_driver;
int32_t spdk_nvme_retry_count;
static struct spdk_nvme_ctrlr *
@ -67,15 +69,13 @@ nvme_attach(void *devhandle)
int
spdk_nvme_detach(struct spdk_nvme_ctrlr *ctrlr)
{
struct nvme_driver *driver = &g_nvme_driver;
nvme_mutex_lock(&driver->lock);
nvme_mutex_lock(&g_nvme_driver->lock);
nvme_ctrlr_destruct(ctrlr);
TAILQ_REMOVE(&g_nvme_driver.attached_ctrlrs, ctrlr, tailq);
TAILQ_REMOVE(&g_nvme_driver->attached_ctrlrs, ctrlr, tailq);
nvme_free(ctrlr);
nvme_mutex_unlock(&driver->lock);
nvme_mutex_unlock(&g_nvme_driver->lock);
return 0;
}
@ -161,7 +161,7 @@ struct nvme_enum_ctx {
void *cb_ctx;
};
/* This function must only be called while holding g_nvme_driver.lock */
/* This function must only be called while holding g_nvme_driver->lock */
static int
nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
{
@ -170,7 +170,7 @@ nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
struct spdk_nvme_ctrlr_opts opts;
/* Verify that this controller is not already attached */
TAILQ_FOREACH(ctrlr, &g_nvme_driver.attached_ctrlrs, tailq) {
TAILQ_FOREACH(ctrlr, &g_nvme_driver->attached_ctrlrs, tailq) {
/* NOTE: This assumes that the PCI abstraction layer will use the same device handle
* across enumerations; we could compare by BDF instead if this is not true.
*/
@ -190,7 +190,7 @@ nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
ctrlr->opts = opts;
TAILQ_INSERT_TAIL(&g_nvme_driver.init_ctrlrs, ctrlr, tailq);
TAILQ_INSERT_TAIL(&g_nvme_driver->init_ctrlrs, ctrlr, tailq);
}
return 0;
@ -204,7 +204,7 @@ spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb a
struct nvme_enum_ctx enum_ctx;
struct spdk_nvme_ctrlr *ctrlr, *ctrlr_tmp;
nvme_mutex_lock(&g_nvme_driver.lock);
nvme_mutex_lock(&g_nvme_driver->lock);
enum_ctx.probe_cb = probe_cb;
enum_ctx.cb_ctx = cb_ctx;
@ -216,8 +216,8 @@ spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb a
*/
/* Initialize all new controllers in the init_ctrlrs list in parallel. */
while (!TAILQ_EMPTY(&g_nvme_driver.init_ctrlrs)) {
TAILQ_FOREACH_SAFE(ctrlr, &g_nvme_driver.init_ctrlrs, tailq, ctrlr_tmp) {
while (!TAILQ_EMPTY(&g_nvme_driver->init_ctrlrs)) {
TAILQ_FOREACH_SAFE(ctrlr, &g_nvme_driver->init_ctrlrs, tailq, ctrlr_tmp) {
/* Drop the driver lock while calling nvme_ctrlr_process_init()
* since it needs to acquire the driver lock internally when calling
* nvme_ctrlr_start().
@ -226,13 +226,13 @@ spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb a
* the functions it calls (in particular nvme_ctrlr_set_num_qpairs())
* can assume it is held.
*/
nvme_mutex_unlock(&g_nvme_driver.lock);
nvme_mutex_unlock(&g_nvme_driver->lock);
start_rc = nvme_ctrlr_process_init(ctrlr);
nvme_mutex_lock(&g_nvme_driver.lock);
nvme_mutex_lock(&g_nvme_driver->lock);
if (start_rc) {
/* Controller failed to initialize. */
TAILQ_REMOVE(&g_nvme_driver.init_ctrlrs, ctrlr, tailq);
TAILQ_REMOVE(&g_nvme_driver->init_ctrlrs, ctrlr, tailq);
nvme_ctrlr_destruct(ctrlr);
nvme_free(ctrlr);
rc = -1;
@ -244,22 +244,22 @@ spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb a
* Controller has been initialized.
* Move it to the attached_ctrlrs list.
*/
TAILQ_REMOVE(&g_nvme_driver.init_ctrlrs, ctrlr, tailq);
TAILQ_INSERT_TAIL(&g_nvme_driver.attached_ctrlrs, ctrlr, tailq);
TAILQ_REMOVE(&g_nvme_driver->init_ctrlrs, ctrlr, tailq);
TAILQ_INSERT_TAIL(&g_nvme_driver->attached_ctrlrs, ctrlr, tailq);
/*
* Unlock while calling attach_cb() so the user can call other functions
* that may take the driver lock, like nvme_detach().
*/
nvme_mutex_unlock(&g_nvme_driver.lock);
nvme_mutex_unlock(&g_nvme_driver->lock);
attach_cb(cb_ctx, ctrlr->devhandle, ctrlr, &ctrlr->opts);
nvme_mutex_lock(&g_nvme_driver.lock);
nvme_mutex_lock(&g_nvme_driver->lock);
break;
}
}
}
nvme_mutex_unlock(&g_nvme_driver.lock);
nvme_mutex_unlock(&g_nvme_driver->lock);
return rc;
}

View File

@ -464,7 +464,7 @@ struct pci_id {
uint16_t sub_dev_id;
};
extern struct nvme_driver g_nvme_driver;
extern struct nvme_driver *g_nvme_driver;
#define nvme_min(a,b) (((a)<(b))?(a):(b))

View File

@ -35,7 +35,7 @@
#include "nvme/nvme_ctrlr.c"
struct nvme_driver g_nvme_driver = {
struct nvme_driver _g_nvme_driver = {
.lock = NVME_MUTEX_INITIALIZER,
};

View File

@ -38,7 +38,7 @@
#include "nvme/nvme_qpair.c"
struct nvme_driver g_nvme_driver = {
struct nvme_driver _g_nvme_driver = {
.lock = NVME_MUTEX_INITIALIZER,
};