#include "eal_private.h"
-static struct rte_intr_handle intr_handle = {
- .type = RTE_INTR_HANDLE_DEV_EVENT,
- .fd = -1,
-};
+static struct rte_intr_handle *intr_handle;
static rte_rwlock_t monitor_lock = RTE_RWLOCK_INITIALIZER;
static uint32_t monitor_refcount;
static bool hotplug_handle;
dev_uev_socket_fd_create(void)
{
struct sockaddr_nl addr;
- int ret;
+ int ret, fd;
- intr_handle.fd = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC |
- SOCK_NONBLOCK,
- NETLINK_KOBJECT_UEVENT);
- if (intr_handle.fd < 0) {
+ fd = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK,
+ NETLINK_KOBJECT_UEVENT);
+ if (fd < 0) {
RTE_LOG(ERR, EAL, "create uevent fd failed.\n");
return -1;
}
addr.nl_pid = 0;
addr.nl_groups = 0xffffffff;
- ret = bind(intr_handle.fd, (struct sockaddr *) &addr, sizeof(addr));
+ ret = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
if (ret < 0) {
RTE_LOG(ERR, EAL, "Failed to bind uevent socket.\n");
goto err;
}
+ if (rte_intr_fd_set(intr_handle, fd))
+ goto err;
+
return 0;
err:
- close(intr_handle.fd);
- intr_handle.fd = -1;
+ close(fd);
+ fd = -1;
return ret;
}
break;
buf++;
}
+ if (i >= length)
+ break;
+
/**
* check device uevent from kernel side, no need to check
* uevent from udev.
static void
dev_delayed_unregister(void *param)
{
- rte_intr_callback_unregister(&intr_handle, dev_uev_handler, param);
- close(intr_handle.fd);
- intr_handle.fd = -1;
+ rte_intr_callback_unregister(intr_handle, dev_uev_handler, param);
+ if (rte_intr_fd_get(intr_handle) >= 0) {
+ close(rte_intr_fd_get(intr_handle));
+ rte_intr_fd_set(intr_handle, -1);
+ }
}
static void
memset(&uevent, 0, sizeof(struct rte_dev_event));
memset(buf, 0, EAL_UEV_MSG_LEN);
- ret = recv(intr_handle.fd, buf, EAL_UEV_MSG_LEN, MSG_DONTWAIT);
+ if (rte_intr_fd_get(intr_handle) < 0)
+ return;
+
+ ret = recv(rte_intr_fd_get(intr_handle), buf, EAL_UEV_MSG_LEN,
+ MSG_DONTWAIT);
if (ret < 0 && errno == EAGAIN)
return;
else if (ret <= 0) {
goto exit;
}
+ intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
+ if (intr_handle == NULL) {
+ RTE_LOG(ERR, EAL, "Fail to allocate intr_handle\n");
+ goto exit;
+ }
+
+ ret = rte_intr_type_set(intr_handle, RTE_INTR_HANDLE_DEV_EVENT);
+ if (ret)
+ goto exit;
+
+ ret = rte_intr_fd_set(intr_handle, -1);
+ if (ret)
+ goto exit;
+
ret = dev_uev_socket_fd_create();
if (ret) {
RTE_LOG(ERR, EAL, "error create device event fd.\n");
goto exit;
}
- ret = rte_intr_callback_register(&intr_handle, dev_uev_handler, NULL);
+ ret = rte_intr_callback_register(intr_handle, dev_uev_handler, NULL);
if (ret) {
- RTE_LOG(ERR, EAL, "fail to register uevent callback.\n");
- close(intr_handle.fd);
- intr_handle.fd = -1;
+ close(rte_intr_fd_get(intr_handle));
goto exit;
}
monitor_refcount++;
exit:
+ if (ret) {
+ rte_intr_instance_free(intr_handle);
+ intr_handle = NULL;
+ }
rte_rwlock_write_unlock(&monitor_lock);
return ret;
}
goto exit;
}
- ret = rte_intr_callback_unregister(&intr_handle, dev_uev_handler,
+ ret = rte_intr_callback_unregister(intr_handle, dev_uev_handler,
(void *)-1);
if (ret < 0) {
RTE_LOG(ERR, EAL, "fail to unregister uevent callback.\n");
goto exit;
}
- close(intr_handle.fd);
- intr_handle.fd = -1;
+ close(rte_intr_fd_get(intr_handle));
+ rte_intr_instance_free(intr_handle);
+ intr_handle = NULL;
monitor_refcount--;