nvme: create netlink socket during nvme_driver_init

This helps ensure thread safety on creation of the
netlink socket, when probe is called from multiple
threads at once.  It is also a lot more clean - we just
create it once, rather than checking every time probe
is called to see if it has to be created.

Signed-off-by: Jim Harris <james.r.harris@intel.com>

Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2681 (master)

(cherry picked from commit 89e47f6014)
Change-Id: I528cedc3ff44de6ea8ecaf6d2389226502ba408e
Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2696
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Jim Harris 2020-05-28 13:10:30 -07:00 committed by Tomasz Zawadzki
parent 239eae6000
commit f8d26843fc
4 changed files with 15 additions and 10 deletions

View File

@ -34,6 +34,7 @@
#include "spdk/nvmf_spec.h"
#include "nvme_internal.h"
#include "nvme_io_msg.h"
#include "nvme_uevent.h"
#define SPDK_NVME_DRIVER_NAME "spdk_nvme_driver"
@ -437,6 +438,10 @@ nvme_driver_init(void)
nvme_robust_mutex_lock(&g_spdk_nvme_driver->lock);
g_spdk_nvme_driver->initialized = false;
g_spdk_nvme_driver->hotplug_fd = spdk_uevent_connect();
if (g_spdk_nvme_driver->hotplug_fd < 0) {
SPDK_DEBUGLOG(SPDK_LOG_NVME, "Failed to open uevent netlink socket\n");
}
TAILQ_INIT(&g_spdk_nvme_driver->shared_attached_ctrlrs);

View File

@ -767,6 +767,9 @@ struct nvme_driver {
bool initialized;
struct spdk_uuid default_extended_host_id;
/** netlink socket fd for hotplug messages */
int hotplug_fd;
};
extern struct nvme_driver *g_spdk_nvme_driver;

View File

@ -212,7 +212,6 @@ static int nvme_pcie_qpair_destroy(struct spdk_nvme_qpair *qpair);
__thread struct nvme_pcie_ctrlr *g_thread_mmio_ctrlr = NULL;
static uint16_t g_signal_lock;
static bool g_sigset = false;
static int g_hotplug_fd = -1;
static void
nvme_sigbus_fault_sighandler(int signum, siginfo_t *info, void *ctx)
@ -271,7 +270,11 @@ _nvme_pcie_hotplug_monitor(struct spdk_nvme_probe_ctx *probe_ctx)
union spdk_nvme_csts_register csts;
struct spdk_nvme_ctrlr_process *proc;
while (spdk_get_uevent(g_hotplug_fd, &event) > 0) {
if (g_spdk_nvme_driver->hotplug_fd < 0) {
return 0;
}
while (spdk_get_uevent(g_spdk_nvme_driver->hotplug_fd, &event) > 0) {
if (event.subsystem == SPDK_NVME_UEVENT_SUBSYSTEM_UIO ||
event.subsystem == SPDK_NVME_UEVENT_SUBSYSTEM_VFIO) {
if (event.action == SPDK_NVME_UEVENT_ADD) {
@ -768,14 +771,7 @@ nvme_pcie_ctrlr_scan(struct spdk_nvme_probe_ctx *probe_ctx,
/* Only the primary process can monitor hotplug. */
if (spdk_process_is_primary()) {
if (g_hotplug_fd < 0) {
g_hotplug_fd = spdk_uevent_connect();
if (g_hotplug_fd < 0) {
SPDK_DEBUGLOG(SPDK_LOG_NVME, "Failed to open uevent netlink socket\n");
}
} else {
_nvme_pcie_hotplug_monitor(probe_ctx);
}
_nvme_pcie_hotplug_monitor(probe_ctx);
}
if (enum_ctx.has_pci_addr == false) {

View File

@ -63,6 +63,7 @@ DEFINE_STUB(nvme_transport_ctrlr_construct, struct spdk_nvme_ctrlr *,
DEFINE_STUB_V(nvme_io_msg_ctrlr_detach, (struct spdk_nvme_ctrlr *ctrlr));
DEFINE_STUB(spdk_nvme_transport_available, bool,
(enum spdk_nvme_transport_type trtype), true);
DEFINE_STUB(spdk_uevent_connect, int, (void), 1);
static bool ut_destruct_called = false;