]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Add method to stop ipc thread
authorSasha Levin <levinsasha928@gmail.com>
Tue, 25 Oct 2011 11:30:53 +0000 (13:30 +0200)
committerPekka Enberg <penberg@kernel.org>
Tue, 25 Oct 2011 11:42:54 +0000 (14:42 +0300)
Stop the ipc thread when shutting down the hypervisor.

This solves a bug where the .sock files weren't removed upon shutdown.

Reported-by: Osier Yang <jyang@redhat.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/include/kvm/kvm-ipc.h
tools/kvm/kvm-ipc.c
tools/kvm/kvm.c

index c93205277257be57c65e3a18eecb4fd74f81855f..731767fbff68aad16e68d443df3c969ae377d3a1 100644 (file)
@@ -22,5 +22,6 @@ enum {
 int kvm_ipc__register_handler(u32 type, void (*cb)(int fd, u32 type, u32 len, u8 *msg));
 int kvm_ipc__handle(int fd, struct kvm_ipc_msg *msg);
 int kvm_ipc__start(int sock);
+int kvm_ipc__stop(void);
 
 #endif
index f05e92687e2410f18315466a7a479754e7108593..3131fe8375391c828484ef309853606e9344babe 100644 (file)
@@ -7,12 +7,14 @@
 #include <sys/un.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/eventfd.h>
 
 #define KVM_IPC_MAX_MSGS 16
 
 static void (*msgs[KVM_IPC_MAX_MSGS])(int fd, u32 type, u32 len, u8 *msg);
 static DECLARE_RWSEM(msgs_rwlock);
-static int epoll_fd, server_fd;
+static int epoll_fd, server_fd, stop_fd;
+static pthread_t thread;
 
 int kvm_ipc__register_handler(u32 type, void (*cb)(int fd, u32 type, u32 len, u8 *msg))
 {
@@ -110,7 +112,9 @@ static void *kvm_ipc__thread(void *param)
                if (nfds > 0) {
                        int fd = event.data.fd;
 
-                       if (fd == server_fd) {
+                       if (fd == stop_fd) {
+                               break;
+                       } else if (fd == server_fd) {
                                int client;
 
                                client = kvm_ipc__new_conn(fd);
@@ -128,7 +132,6 @@ static void *kvm_ipc__thread(void *param)
 
 int kvm_ipc__start(int sock)
 {
-       pthread_t thread;
        struct epoll_event ev;
 
        server_fd = sock;
@@ -140,8 +143,29 @@ int kvm_ipc__start(int sock)
        if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev) < 0)
                die("Failed starting IPC thread");
 
+       stop_fd = eventfd(0, 0);
+       ev.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET;
+       ev.data.fd = stop_fd;
+       if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_fd, &ev) < 0)
+               die("Failed adding stop event to epoll");
+
        if (pthread_create(&thread, NULL, kvm_ipc__thread, NULL) != 0)
                die("Failed starting IPC thread");
 
        return 0;
 }
+
+int kvm_ipc__stop(void)
+{
+       u64 val = 1;
+       int ret;
+
+       ret = write(stop_fd, &val, sizeof(val));
+       if (ret < 0)
+               return ret;
+
+       close(server_fd);
+       close(epoll_fd);
+
+       return ret;
+}
index 40ae6a5cf5a91caa77797ae2e0e7593f168b5f4a..8d6b5e1f040260092813cf1c2eccac88b1c0116d 100644 (file)
@@ -237,6 +237,7 @@ void kvm__delete(struct kvm *kvm)
        kvm__stop_timer(kvm);
 
        munmap(kvm->ram_start, kvm->ram_size);
+       kvm_ipc__stop();
        kvm__remove_socket(kvm->name);
        free(kvm);
 }