Commit cbcfa041 authored by Paolo Bonzini's avatar Paolo Bonzini
Browse files

link the main loop and its dependencies into the tools



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: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent d9a73806
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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)
+6 −0
Original line number Diff line number Diff line
@@ -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);

+0 −42
Original line number Diff line number Diff line
@@ -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
}
+0 −5
Original line number Diff line number Diff line
@@ -151,8 +151,3 @@ int qemu_create_pidfile(const char *filename)
    }
    return 0;
}

int qemu_get_thread_id(void)
{
    return GetCurrentThreadId();
}
+43 −0
Original line number Diff line number Diff line
@@ -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;
Loading