From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:41297) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R4a2v-0005ES-B0 for qemu-devel@nongnu.org; Fri, 16 Sep 2011 11:09:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R4a2q-00086g-9b for qemu-devel@nongnu.org; Fri, 16 Sep 2011 11:09:41 -0400 Received: from mail-ww0-f53.google.com ([74.125.82.53]:51127) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R4a2p-000805-Tj for qemu-devel@nongnu.org; Fri, 16 Sep 2011 11:09:36 -0400 Received: by mail-ww0-f53.google.com with SMTP id 14so4687113wwg.10 for ; Fri, 16 Sep 2011 08:09:35 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 16 Sep 2011 17:09:09 +0200 Message-Id: <1316185750-9187-14-git-send-email-pbonzini@redhat.com> In-Reply-To: <1316185750-9187-1-git-send-email-pbonzini@redhat.com> References: <1316185750-9187-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [RFC PATCH 13/14] link the main loop and its dependencies into the tools List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com This completes the refactoring and lets the tools use the main loop code from QEMU. This enables tools to operate fully asynchronously. Advantages include better Windows portability (for some definition of portability) over glib's. Signed-off-by: Paolo Bonzini --- Makefile | 4 +++- os-posix.c | 42 ------------------------------------------ os-win32.c | 5 ----- oslib-posix.c | 42 ++++++++++++++++++++++++++++++++++++++++++ oslib-win32.c | 5 +++++ qemu-tool.c | 45 ++++++++++++++++++++++++++------------------- 6 files changed, 76 insertions(+), 67 deletions(-) diff --git a/Makefile b/Makefile index f00afc2..6644259 100644 --- a/Makefile +++ b/Makefile @@ -143,7 +143,9 @@ qemu-img.o: qemu-img-cmds.h qemu-img.o qemu-tool.o qemu-nbd.o qemu-io.o cmd.o qemu-ga.o: $(GENERATED_HEADERS) tools-obj-y = qemu-tool.o qemu-error.o $(oslib-obj-y) $(trace-obj-y) \ - $(block-obj-y) $(qobject-obj-y) $(version-obj-y) qemu-timer-common.o + $(block-obj-y) $(qobject-obj-y) $(version-obj-y) qemu-timer-common.o \ + qemu-timer.o main-loop.o notify.o iohandler.o +tools-obj-$(CONFIG_POSIX) += compatfd.o qemu-img$(EXESUF): qemu-img.o $(tools-obj-y) qemu-nbd$(EXESUF): qemu-nbd.o $(tools-obj-y) diff --git a/os-posix.c b/os-posix.c index dbf3b24..c0188b3 100644 --- a/os-posix.c +++ b/os-posix.c @@ -42,11 +42,6 @@ #ifdef CONFIG_LINUX #include -#include -#endif - -#ifdef CONFIG_EVENTFD -#include #endif static struct passwd *user_pwd; @@ -333,34 +328,6 @@ void os_set_line_buffering(void) setvbuf(stdout, NULL, _IOLBF, 0); } -/* - * Creates an eventfd that looks like a pipe and has EFD_CLOEXEC set. - */ -int qemu_eventfd(int fds[2]) -{ -#ifdef CONFIG_EVENTFD - int ret; - - ret = eventfd(0, 0); - if (ret >= 0) { - fds[0] = ret; - qemu_set_cloexec(ret); - if ((fds[1] = dup(ret)) == -1) { - close(ret); - return -1; - } - qemu_set_cloexec(fds[1]); - return 0; - } - - if (errno != ENOSYS) { - return -1; - } -#endif - - return qemu_pipe(fds); -} - int qemu_create_pidfile(const char *filename) { char buffer[128]; @@ -381,12 +348,3 @@ int qemu_create_pidfile(const char *filename) return 0; } - -int qemu_get_thread_id(void) -{ -#if defined (__linux__) - return syscall(SYS_gettid); -#else - return getpid(); -#endif -} diff --git a/os-win32.c b/os-win32.c index 7909401..30a96ef 100644 --- a/os-win32.c +++ b/os-win32.c @@ -143,8 +143,3 @@ int qemu_create_pidfile(const char *filename) } return 0; } - -int qemu_get_thread_id(void) -{ - return GetCurrentThreadId(); -} diff --git a/oslib-posix.c b/oslib-posix.c index a304fb0..34b8107 100644 --- a/oslib-posix.c +++ b/oslib-posix.c @@ -47,7 +47,21 @@ extern int daemon(int, int); #include "trace.h" #include "qemu_socket.h" +#ifdef CONFIG_LINUX +#include +#endif +#ifdef CONFIG_EVENTFD +#include +#endif +int qemu_get_thread_id(void) +{ +#if defined(__linux__) + return syscall(SYS_gettid); +#else + return getpid(); +#endif +} int qemu_daemon(int nochdir, int noclose) { @@ -139,6 +153,34 @@ int qemu_pipe(int pipefd[2]) return ret; } +/* + * Creates an eventfd that looks like a pipe and has EFD_CLOEXEC set. + */ +int qemu_eventfd(int fds[2]) +{ +#ifdef CONFIG_EVENTFD + int ret; + + ret = eventfd(0, 0); + if (ret >= 0) { + fds[0] = ret; + fds[1] = dup(ret); + if (fds[1] == -1) { + close(ret); + return -1; + } + qemu_set_cloexec(ret); + qemu_set_cloexec(fds[1]); + return 0; + } + if (errno != ENOSYS) { + return -1; + } +#endif + + return qemu_pipe(fds); +} + int qemu_utimensat(int dirfd, const char *path, const struct timespec *times, int flags) { diff --git a/oslib-win32.c b/oslib-win32.c index 5f0759f..4b5b403 100644 --- a/oslib-win32.c +++ b/oslib-win32.c @@ -112,3 +112,8 @@ int qemu_gettimeofday(qemu_timeval *tp) Do not set errno on error. */ return 0; } + +int qemu_get_thread_id(void) +{ + return GetCurrentThreadId(); +} diff --git a/qemu-tool.c b/qemu-tool.c index eb89fe0..5a54e10 100644 --- a/qemu-tool.c +++ b/qemu-tool.c @@ -15,12 +15,12 @@ #include "monitor.h" #include "qemu-timer.h" #include "qemu-log.h" +#include "main-loop.h" +#include "qemu_socket.h" +#include "slirp/libslirp.h" #include -QEMUClock *rt_clock; -QEMUClock *vm_clock; - FILE *logfile; struct QEMUBH @@ -60,39 +60,46 @@ void monitor_protocol_event(MonitorEvent event, QObject *data) { } -int qemu_set_fd_handler2(int fd, - IOCanReadHandler *fd_read_poll, - IOHandler *fd_read, - IOHandler *fd_write, - void *opaque) +int64 cpu_get_clock(void) { - return 0; + abort(); } -void qemu_notify_event(void) +int64 cpu_get_icount(void) { + abort(); } -QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, - QEMUTimerCB *cb, void *opaque) +void qemu_mutex_lock_iothread(void) { - return g_malloc(1); } -void qemu_free_timer(QEMUTimer *ts) +void qemu_mutex_unlock_iothread(void) { - g_free(ts); } -void qemu_del_timer(QEMUTimer *ts) +int use_icount; + +void qemu_clock_warp(QEMUClock *clock) { } -void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time) +VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, + void *opaque) { + return NULL; } -int64_t qemu_get_clock_ns(QEMUClock *clock) +void qemu_del_vm_change_state_handler(VMChangeStateEntry *e) +{ +} + +void slirp_select_fill(int *pnfds, fd_set *readfds, + fd_set *writefds, fd_set *xfds) +{ +} + +void slirp_select_poll(fd_set *readfds, fd_set *writefds, + fd_set *xfds, int select_error) { - return 0; } -- 1.7.6