qemu-storage-daemon: Add main loop
authorKevin Wolf <kwolf@redhat.com>
Mon, 24 Feb 2020 14:30:00 +0000 (15:30 +0100)
committerKevin Wolf <kwolf@redhat.com>
Fri, 6 Mar 2020 16:21:28 +0000 (17:21 +0100)
Instead of exiting after processing all command line options, start a
main loop and keep processing events until exit is requested with a
signal (e.g. SIGINT).

Now qemu-storage-daemon can be used as an alternative for qemu-nbd that
provides a few features that were previously only available from QMP,
such as access to options only available with -blockdev and the socket
types 'vsock' and 'fd'.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200224143008.13362-13-kwolf@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Makefile.objs
qemu-storage-daemon.c

index bacbdb55bc41b9d1794c15ce0fa2ba636d6296b6..2554e331d562a555b9b2ddcd45a96f5653594e52 100644 (file)
@@ -33,6 +33,8 @@ endif # CONFIG_SOFTMMU or CONFIG_TOOLS
 
 storage-daemon-obj-y = block/ qom/
 storage-daemon-obj-y += blockdev.o blockdev-nbd.o iothread.o
+storage-daemon-obj-$(CONFIG_WIN32) += os-win32.o
+storage-daemon-obj-$(CONFIG_POSIX) += os-posix.o
 
 ######################################################################
 # Target independent part of system emulation. The long term path is to
index 5904d3c5b4df0d2c0d035fc97236ac4cad3b3233..14093ac3a0240df9168701190e0ac4dff394bd34 100644 (file)
 #include "qemu/option.h"
 #include "qom/object_interfaces.h"
 
+#include "sysemu/runstate.h"
 #include "trace/control.h"
 
+static volatile bool exit_requested = false;
+
+void qemu_system_killed(int signal, pid_t pid)
+{
+    exit_requested = true;
+}
+
 static void help(void)
 {
     printf(
@@ -241,6 +249,7 @@ int main(int argc, char *argv[])
 
     error_init(argv[0]);
     qemu_init_exec_dir(argv[0]);
+    os_setup_signal_handling();
 
     module_call_init(MODULE_INIT_QOM);
     module_call_init(MODULE_INIT_TRACE);
@@ -256,5 +265,9 @@ int main(int argc, char *argv[])
     qemu_init_main_loop(&error_fatal);
     process_options(argc, argv);
 
+    while (!exit_requested) {
+        main_loop_wait(false);
+    }
+
     return EXIT_SUCCESS;
 }