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> Change-Id: I528cedc3ff44de6ea8ecaf6d2389226502ba408e Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2681 Community-CI: Broadcom CI Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
18f79f2449
commit
89e47f6014
@ -35,6 +35,7 @@
|
|||||||
#include "spdk/string.h"
|
#include "spdk/string.h"
|
||||||
#include "nvme_internal.h"
|
#include "nvme_internal.h"
|
||||||
#include "nvme_io_msg.h"
|
#include "nvme_io_msg.h"
|
||||||
|
#include "nvme_uevent.h"
|
||||||
|
|
||||||
#define SPDK_NVME_DRIVER_NAME "spdk_nvme_driver"
|
#define SPDK_NVME_DRIVER_NAME "spdk_nvme_driver"
|
||||||
|
|
||||||
@ -438,6 +439,10 @@ nvme_driver_init(void)
|
|||||||
nvme_robust_mutex_lock(&g_spdk_nvme_driver->lock);
|
nvme_robust_mutex_lock(&g_spdk_nvme_driver->lock);
|
||||||
|
|
||||||
g_spdk_nvme_driver->initialized = false;
|
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);
|
TAILQ_INIT(&g_spdk_nvme_driver->shared_attached_ctrlrs);
|
||||||
|
|
||||||
|
@ -798,6 +798,9 @@ struct nvme_driver {
|
|||||||
|
|
||||||
bool initialized;
|
bool initialized;
|
||||||
struct spdk_uuid default_extended_host_id;
|
struct spdk_uuid default_extended_host_id;
|
||||||
|
|
||||||
|
/** netlink socket fd for hotplug messages */
|
||||||
|
int hotplug_fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct nvme_driver *g_spdk_nvme_driver;
|
extern struct nvme_driver *g_spdk_nvme_driver;
|
||||||
|
@ -214,7 +214,6 @@ static int nvme_pcie_qpair_destroy(struct spdk_nvme_qpair *qpair);
|
|||||||
__thread struct nvme_pcie_ctrlr *g_thread_mmio_ctrlr = NULL;
|
__thread struct nvme_pcie_ctrlr *g_thread_mmio_ctrlr = NULL;
|
||||||
static uint16_t g_signal_lock;
|
static uint16_t g_signal_lock;
|
||||||
static bool g_sigset = false;
|
static bool g_sigset = false;
|
||||||
static int g_hotplug_fd = -1;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nvme_sigbus_fault_sighandler(int signum, siginfo_t *info, void *ctx)
|
nvme_sigbus_fault_sighandler(int signum, siginfo_t *info, void *ctx)
|
||||||
@ -273,7 +272,11 @@ _nvme_pcie_hotplug_monitor(struct spdk_nvme_probe_ctx *probe_ctx)
|
|||||||
union spdk_nvme_csts_register csts;
|
union spdk_nvme_csts_register csts;
|
||||||
struct spdk_nvme_ctrlr_process *proc;
|
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 ||
|
if (event.subsystem == SPDK_NVME_UEVENT_SUBSYSTEM_UIO ||
|
||||||
event.subsystem == SPDK_NVME_UEVENT_SUBSYSTEM_VFIO) {
|
event.subsystem == SPDK_NVME_UEVENT_SUBSYSTEM_VFIO) {
|
||||||
if (event.action == SPDK_NVME_UEVENT_ADD) {
|
if (event.action == SPDK_NVME_UEVENT_ADD) {
|
||||||
@ -778,14 +781,7 @@ nvme_pcie_ctrlr_scan(struct spdk_nvme_probe_ctx *probe_ctx,
|
|||||||
|
|
||||||
/* Only the primary process can monitor hotplug. */
|
/* Only the primary process can monitor hotplug. */
|
||||||
if (spdk_process_is_primary()) {
|
if (spdk_process_is_primary()) {
|
||||||
if (g_hotplug_fd < 0) {
|
_nvme_pcie_hotplug_monitor(probe_ctx);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enum_ctx.has_pci_addr == false) {
|
if (enum_ctx.has_pci_addr == false) {
|
||||||
|
@ -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_V(nvme_io_msg_ctrlr_detach, (struct spdk_nvme_ctrlr *ctrlr));
|
||||||
DEFINE_STUB(spdk_nvme_transport_available, bool,
|
DEFINE_STUB(spdk_nvme_transport_available, bool,
|
||||||
(enum spdk_nvme_transport_type trtype), true);
|
(enum spdk_nvme_transport_type trtype), true);
|
||||||
|
DEFINE_STUB(spdk_uevent_connect, int, (void), 1);
|
||||||
|
|
||||||
|
|
||||||
static bool ut_destruct_called = false;
|
static bool ut_destruct_called = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user