* [PATCH] kvm tools: Add method to stop ipc thread
@ 2011-10-25 10:40 Sasha Levin
2011-10-25 10:42 ` Pekka Enberg
2011-10-25 11:08 ` Osier Yang
0 siblings, 2 replies; 5+ messages in thread
From: Sasha Levin @ 2011-10-25 10:40 UTC (permalink / raw)
To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin
Stop the ipc thread when shutting down the hypervisor.
This solves a bug where the .sock files weren't removed upon shutdown.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/include/kvm/kvm-ipc.h | 1 +
tools/kvm/kvm-ipc.c | 33 +++++++++++++++++++++++++++++----
tools/kvm/kvm.c | 1 +
3 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/tools/kvm/include/kvm/kvm-ipc.h b/tools/kvm/include/kvm/kvm-ipc.h
index c932052..731767f 100644
--- a/tools/kvm/include/kvm/kvm-ipc.h
+++ b/tools/kvm/include/kvm/kvm-ipc.h
@@ -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
diff --git a/tools/kvm/kvm-ipc.c b/tools/kvm/kvm-ipc.c
index f05e926..65209e1 100644
--- a/tools/kvm/kvm-ipc.c
+++ b/tools/kvm/kvm-ipc.c
@@ -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))
{
@@ -109,8 +111,11 @@ static void *kvm_ipc__thread(void *param)
nfds = epoll_wait(epoll_fd, &event, 1, -1);
if (nfds > 0) {
int fd = event.data.fd;
-
- if (fd == server_fd) {
+ printf("bleh\n");
+ if (fd == stop_fd) {
+ printf("Got stop signal\n");
+ break;
+ } else if (fd == server_fd) {
int client;
client = kvm_ipc__new_conn(fd);
@@ -128,7 +133,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 +144,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;
+}
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 40ae6a5..8d6b5e1 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -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);
}
--
1.7.7
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] kvm tools: Add method to stop ipc thread
2011-10-25 10:40 [PATCH] kvm tools: Add method to stop ipc thread Sasha Levin
@ 2011-10-25 10:42 ` Pekka Enberg
2011-10-25 11:27 ` Sasha Levin
2011-10-25 11:08 ` Osier Yang
1 sibling, 1 reply; 5+ messages in thread
From: Pekka Enberg @ 2011-10-25 10:42 UTC (permalink / raw)
To: Sasha Levin; +Cc: kvm, mingo, asias.hejun, gorcunov
On Tue, Oct 25, 2011 at 1:40 PM, Sasha Levin <levinsasha928@gmail.com> wrote:
> Stop the ipc thread when shutting down the hypervisor.
>
> This solves a bug where the .sock files weren't removed upon shutdown.
>
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
> tools/kvm/include/kvm/kvm-ipc.h | 1 +
> tools/kvm/kvm-ipc.c | 33 +++++++++++++++++++++++++++++----
> tools/kvm/kvm.c | 1 +
> 3 files changed, 31 insertions(+), 4 deletions(-)
>
> diff --git a/tools/kvm/include/kvm/kvm-ipc.h b/tools/kvm/include/kvm/kvm-ipc.h
> index c932052..731767f 100644
> --- a/tools/kvm/include/kvm/kvm-ipc.h
> +++ b/tools/kvm/include/kvm/kvm-ipc.h
> @@ -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
> diff --git a/tools/kvm/kvm-ipc.c b/tools/kvm/kvm-ipc.c
> index f05e926..65209e1 100644
> --- a/tools/kvm/kvm-ipc.c
> +++ b/tools/kvm/kvm-ipc.c
> @@ -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))
> {
> @@ -109,8 +111,11 @@ static void *kvm_ipc__thread(void *param)
> nfds = epoll_wait(epoll_fd, &event, 1, -1);
> if (nfds > 0) {
> int fd = event.data.fd;
> -
> - if (fd == server_fd) {
> + printf("bleh\n");
> + if (fd == stop_fd) {
> + printf("Got stop signal\n");
> + break;
LOL. Can I have a version of the patch without those printf calls? :-)
> + } else if (fd == server_fd) {
> int client;
>
> client = kvm_ipc__new_conn(fd);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] kvm tools: Add method to stop ipc thread
2011-10-25 10:40 [PATCH] kvm tools: Add method to stop ipc thread Sasha Levin
2011-10-25 10:42 ` Pekka Enberg
@ 2011-10-25 11:08 ` Osier Yang
2011-10-25 11:38 ` Sasha Levin
1 sibling, 1 reply; 5+ messages in thread
From: Osier Yang @ 2011-10-25 11:08 UTC (permalink / raw)
To: Sasha Levin; +Cc: penberg, kvm, mingo, asias.hejun, gorcunov
于 2011年10月25日 18:40, Sasha Levin 写道:
> Stop the ipc thread when shutting down the hypervisor.
>
> This solves a bug where the .sock files weren't removed upon shutdown.
I tested the patch, the socket is still there. (I'm testing with
"--sdl", and
shutdown the vm window). And the guest starting succeeded even if
a socket with the name same as the specified guest name exists, which
means I can start two guests with same socket, which is not right.
>
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
> tools/kvm/include/kvm/kvm-ipc.h | 1 +
> tools/kvm/kvm-ipc.c | 33 +++++++++++++++++++++++++++++----
> tools/kvm/kvm.c | 1 +
> 3 files changed, 31 insertions(+), 4 deletions(-)
>
> diff --git a/tools/kvm/include/kvm/kvm-ipc.h b/tools/kvm/include/kvm/kvm-ipc.h
> index c932052..731767f 100644
> --- a/tools/kvm/include/kvm/kvm-ipc.h
> +++ b/tools/kvm/include/kvm/kvm-ipc.h
> @@ -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
> diff --git a/tools/kvm/kvm-ipc.c b/tools/kvm/kvm-ipc.c
> index f05e926..65209e1 100644
> --- a/tools/kvm/kvm-ipc.c
> +++ b/tools/kvm/kvm-ipc.c
> @@ -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))
> {
> @@ -109,8 +111,11 @@ static void *kvm_ipc__thread(void *param)
> nfds = epoll_wait(epoll_fd, &event, 1, -1);
> if (nfds > 0) {
> int fd = event.data.fd;
> -
> - if (fd == server_fd) {
> + printf("bleh\n");
> + if (fd == stop_fd) {
> + printf("Got stop signal\n");
> + break;
> + } else if (fd == server_fd) {
> int client;
>
> client = kvm_ipc__new_conn(fd);
> @@ -128,7 +133,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 +144,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;
> +}
> diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
> index 40ae6a5..8d6b5e1 100644
> --- a/tools/kvm/kvm.c
> +++ b/tools/kvm/kvm.c
> @@ -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);
> }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] kvm tools: Add method to stop ipc thread
2011-10-25 10:42 ` Pekka Enberg
@ 2011-10-25 11:27 ` Sasha Levin
0 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2011-10-25 11:27 UTC (permalink / raw)
To: Pekka Enberg; +Cc: kvm, mingo, asias.hejun, gorcunov
On Tue, 2011-10-25 at 13:42 +0300, Pekka Enberg wrote:
> On Tue, Oct 25, 2011 at 1:40 PM, Sasha Levin <levinsasha928@gmail.com> wrote:
> > Stop the ipc thread when shutting down the hypervisor.
> >
> > This solves a bug where the .sock files weren't removed upon shutdown.
> >
> > Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> > ---
> > tools/kvm/include/kvm/kvm-ipc.h | 1 +
> > tools/kvm/kvm-ipc.c | 33 +++++++++++++++++++++++++++++----
> > tools/kvm/kvm.c | 1 +
> > 3 files changed, 31 insertions(+), 4 deletions(-)
> >
> > diff --git a/tools/kvm/include/kvm/kvm-ipc.h b/tools/kvm/include/kvm/kvm-ipc.h
> > index c932052..731767f 100644
> > --- a/tools/kvm/include/kvm/kvm-ipc.h
> > +++ b/tools/kvm/include/kvm/kvm-ipc.h
> > @@ -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
> > diff --git a/tools/kvm/kvm-ipc.c b/tools/kvm/kvm-ipc.c
> > index f05e926..65209e1 100644
> > --- a/tools/kvm/kvm-ipc.c
> > +++ b/tools/kvm/kvm-ipc.c
> > @@ -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))
> > {
> > @@ -109,8 +111,11 @@ static void *kvm_ipc__thread(void *param)
> > nfds = epoll_wait(epoll_fd, &event, 1, -1);
> > if (nfds > 0) {
> > int fd = event.data.fd;
> > -
> > - if (fd == server_fd) {
> > + printf("bleh\n");
> > + if (fd == stop_fd) {
> > + printf("Got stop signal\n");
> > + break;
>
> LOL. Can I have a version of the patch without those printf calls? :-)
Woopsie :)
--
Sasha.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] kvm tools: Add method to stop ipc thread
2011-10-25 11:08 ` Osier Yang
@ 2011-10-25 11:38 ` Sasha Levin
0 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2011-10-25 11:38 UTC (permalink / raw)
To: Osier Yang; +Cc: penberg, kvm, mingo, asias.hejun, gorcunov
On Tue, 2011-10-25 at 19:08 +0800, Osier Yang wrote:
> 于 2011年10月25日 18:40, Sasha Levin 写道:
> > Stop the ipc thread when shutting down the hypervisor.
> >
> > This solves a bug where the .sock files weren't removed upon shutdown.
>
> I tested the patch, the socket is still there. (I'm testing with
> "--sdl", and
> shutdown the vm window). And the guest starting succeeded even if
> a socket with the name same as the specified guest name exists, which
> means I can start two guests with same socket, which is not right.
I've just tested it with --sdl, looks like closing the sdl window uses
the old method of IPC which I forgot to convert.
I'll fix that in a separate patch.
If you test it without --sdl it should work right.
--
Sasha.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-10-25 11:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-25 10:40 [PATCH] kvm tools: Add method to stop ipc thread Sasha Levin
2011-10-25 10:42 ` Pekka Enberg
2011-10-25 11:27 ` Sasha Levin
2011-10-25 11:08 ` Osier Yang
2011-10-25 11:38 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox