All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 20/25] link the main loop and its dependencies into the tools
Date: Tue,  6 Dec 2011 16:27:47 +0100	[thread overview]
Message-ID: <1323185272-2610-21-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1323185272-2610-1-git-send-email-pbonzini@redhat.com>

Using the main loop code from QEMU enables tools to operate fully
asynchronously.  Advantages include better Windows portability (for some
definition of portability) over glib's.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 Makefile      |    5 +++--
 main-loop.h   |    6 ++++++
 os-posix.c    |   42 ------------------------------------------
 os-win32.c    |    5 -----
 oslib-posix.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 oslib-win32.c |    5 +++++
 qemu-tool.c   |   42 +++++++++++++++++++++++-------------------
 7 files changed, 80 insertions(+), 68 deletions(-)

diff --git a/Makefile b/Makefile
index 301c75e..988287e 100644
--- a/Makefile
+++ b/Makefile
@@ -147,8 +147,9 @@ endif
 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 $(oslib-obj-y) $(trace-obj-y) \
-	qemu-timer-common.o cutils.o
+tools-obj-y = $(oslib-obj-y) $(trace-obj-y) qemu-tool.o qemu-timer.o \
+	qemu-timer-common.o main-loop.o notify.o iohandler.o cutils.o async.o
+tools-obj-$(CONFIG_POSIX) += compatfd.o
 
 qemu-img$(EXESUF): qemu-img.o $(tools-obj-y) $(block-obj-y)
 qemu-nbd$(EXESUF): qemu-nbd.o $(tools-obj-y) $(block-obj-y)
diff --git a/main-loop.h b/main-loop.h
index 8a716b1..636e712 100644
--- a/main-loop.h
+++ b/main-loop.h
@@ -324,6 +324,9 @@ int qemu_add_child_watch(pid_t pid);
  * by threads other than the main loop thread when calling
  * qemu_bh_new(), qemu_set_fd_handler() and basically all other
  * functions documented in this file.
+ *
+ * NOTE: tools currently are single-threaded and qemu_mutex_lock_iothread
+ * is a no-op there.
  */
 void qemu_mutex_lock_iothread(void);
 
@@ -336,6 +339,9 @@ void qemu_mutex_lock_iothread(void);
  * as soon as possible by threads other than the main loop thread,
  * because it prevents the main loop from processing callbacks,
  * including timers and bottom halves.
+ *
+ * NOTE: tools currently are single-threaded and qemu_mutex_unlock_iothread
+ * is a no-op there.
  */
 void qemu_mutex_unlock_iothread(void);
 
diff --git a/os-posix.c b/os-posix.c
index dc4a6bb..5c437ca 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -42,11 +42,6 @@
 
 #ifdef CONFIG_LINUX
 #include <sys/prctl.h>
-#include <sys/syscall.h>
-#endif
-
-#ifdef CONFIG_EVENTFD
-#include <sys/eventfd.h>
 #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];
@@ -384,12 +351,3 @@ int qemu_create_pidfile(const char *filename)
     close(fd);
     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 8ad5fa1..d012b0c 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -144,8 +144,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 ce75549..b6a3c7f 100644
--- a/oslib-posix.c
+++ b/oslib-posix.c
@@ -55,6 +55,21 @@ static int running_on_valgrind = -1;
 #else
 #  define running_on_valgrind 0
 #endif
+#ifdef CONFIG_LINUX
+#include <sys/syscall.h>
+#endif
+#ifdef CONFIG_EVENTFD
+#include <sys/eventfd.h>
+#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)
 {
@@ -162,6 +177,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_utimens(const char *path, const struct timespec *times)
 {
     struct timeval tv[2], tv_now;
diff --git a/oslib-win32.c b/oslib-win32.c
index 5e3de7d..ce3021e 100644
--- a/oslib-win32.c
+++ b/oslib-win32.c
@@ -118,3 +118,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 5df7279..226b6e8 100644
--- a/qemu-tool.c
+++ b/qemu-tool.c
@@ -16,12 +16,12 @@
 #include "qemu-timer.h"
 #include "qemu-log.h"
 #include "migration.h"
+#include "main-loop.h"
+#include "qemu_socket.h"
+#include "slirp/libslirp.h"
 
 #include <sys/time.h>
 
-QEMUClock *rt_clock;
-QEMUClock *vm_clock;
-
 FILE *logfile;
 
 struct QEMUBH
@@ -57,41 +57,45 @@ 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)
+static void __attribute__((constructor)) init_main_loop(void)
 {
+    init_clocks();
+    init_timer_alarm();
+    qemu_clock_enable(vm_clock, false);
 }
 
-int64_t qemu_get_clock_ns(QEMUClock *clock)
+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;
 }
 
 void migrate_add_blocker(Error *reason)
-- 
1.7.7.1

  parent reply	other threads:[~2011-12-06 15:29 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-06 15:27 [Qemu-devel] [PATCH 00/25] nbd asynchronous operation Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 01/25] add qemu_send_full and qemu_recv_full Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 02/25] sheepdog: move coroutine send/recv function to generic code Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 03/25] nbd: switch to asynchronous operation Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 04/25] nbd: split requests Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 05/25] nbd: allow multiple in-flight requests Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 06/25] nbd: fix error handling in the server Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 07/25] nbd: add support for NBD_CMD_FLAG_FUA Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 08/25] nbd: add support for NBD_CMD_FLUSH Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 09/25] nbd: add support for NBD_CMD_TRIM Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 10/25] Update ioctl order in nbd_init() to detect EBUSY Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 11/25] qemu-nbd: remove offset argument to nbd_trip Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 12/25] qemu-nbd: remove data_size " Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 13/25] move corking functions to osdep.c Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 14/25] qemu-nbd: simplify nbd_trip Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 15/25] qemu-nbd: introduce nbd_do_send_reply Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 16/25] qemu-nbd: more robust handling of invalid requests Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 17/25] qemu-nbd: introduce nbd_do_receive_request Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 18/25] qemu-nbd: introduce NBDExport Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 19/25] qemu-nbd: introduce NBDRequest Paolo Bonzini
2011-12-06 15:27 ` Paolo Bonzini [this message]
2011-12-06 15:27 ` [Qemu-devel] [PATCH 21/25] qemu-nbd: use common main loop Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 22/25] qemu-nbd: move client handling to nbd.c Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 23/25] qemu-nbd: add client pointer to NBDRequest Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 24/25] qemu-nbd: asynchronous operation Paolo Bonzini
2011-12-06 15:27 ` [Qemu-devel] [PATCH 25/25] qemu-nbd: throttle requests Paolo Bonzini
2011-12-15 10:21 ` [Qemu-devel] [PATCH 00/25] nbd asynchronous operation Paolo Bonzini
2011-12-15 11:09   ` Kevin Wolf
2011-12-21 18:11     ` Paolo Bonzini
2011-12-21 19:37       ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1323185272-2610-21-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.