eal: set name when creating a control thread
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_vfio_mp_sync.c
index 00cf919..a20fb86 100644 (file)
 #endif
 
 #include <rte_log.h>
-#include <rte_pci.h>
 #include <rte_eal_memconfig.h>
 #include <rte_malloc.h>
+#include <rte_vfio.h>
 
 #include "eal_filesystem.h"
-#include "eal_pci_init.h"
+#include "eal_vfio.h"
 #include "eal_thread.h"
 
 /**
@@ -267,7 +267,7 @@ vfio_mp_sync_connect_to_primary(void)
 static __attribute__((noreturn)) void *
 vfio_mp_sync_thread(void __rte_unused * arg)
 {
-       int ret, fd, vfio_group_no;
+       int ret, fd, vfio_data;
 
        /* wait for requests on the socket */
        for (;;) {
@@ -301,16 +301,18 @@ vfio_mp_sync_thread(void __rte_unused * arg)
                                vfio_mp_sync_send_request(conn_sock, SOCKET_ERR);
                        else
                                vfio_mp_sync_send_fd(conn_sock, fd);
+                       if (fd >= 0)
+                               close(fd);
                        break;
                case SOCKET_REQ_GROUP:
                        /* wait for group number */
-                       vfio_group_no = vfio_mp_sync_receive_request(conn_sock);
-                       if (vfio_group_no < 0) {
+                       vfio_data = vfio_mp_sync_receive_request(conn_sock);
+                       if (vfio_data < 0) {
                                close(conn_sock);
                                continue;
                        }
 
-                       fd = vfio_get_group_fd(vfio_group_no);
+                       fd = vfio_get_group_fd(vfio_data);
 
                        if (fd < 0)
                                vfio_mp_sync_send_request(conn_sock, SOCKET_ERR);
@@ -323,6 +325,21 @@ vfio_mp_sync_thread(void __rte_unused * arg)
                                vfio_mp_sync_send_fd(conn_sock, fd);
                        }
                        break;
+               case SOCKET_CLR_GROUP:
+                       /* wait for group fd */
+                       vfio_data = vfio_mp_sync_receive_request(conn_sock);
+                       if (vfio_data < 0) {
+                               close(conn_sock);
+                               continue;
+                       }
+
+                       ret = clear_group(vfio_data);
+
+                       if (ret < 0)
+                               vfio_mp_sync_send_request(conn_sock, SOCKET_NO_FD);
+                       else
+                               vfio_mp_sync_send_request(conn_sock, SOCKET_OK);
+                       break;
                default:
                        vfio_mp_sync_send_request(conn_sock, SOCKET_ERR);
                        break;
@@ -386,7 +403,8 @@ vfio_mp_sync_setup(void)
                return -1;
        }
 
-       ret = pthread_create(&socket_thread, NULL,
+       snprintf(thread_name, sizeof(thread_name), "vfio-sync");
+       ret = rte_ctrl_thread_create(&socket_thread, thread_name, NULL,
                        vfio_mp_sync_thread, NULL);
        if (ret) {
                RTE_LOG(ERR, EAL,
@@ -395,13 +413,6 @@ vfio_mp_sync_setup(void)
                return -1;
        }
 
-       /* Set thread_name for aid in debugging. */
-       snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "vfio-sync");
-       ret = rte_thread_setname(socket_thread, thread_name);
-       if (ret)
-               RTE_LOG(DEBUG, EAL,
-                       "Failed to set thread name for secondary processes!\n");
-
        return 0;
 }