Re: [RFC PATCH 09/18] qemu-storage-daemon: Add main loop

2019-11-08 Thread Markus Armbruster
Kevin Wolf  writes:

> 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 
> ---
>  qemu-storage-daemon.c | 13 +
>  Makefile.objs |  2 ++
>  2 files changed, 15 insertions(+)
>
> diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
> index 9e5f474fd0..099388f645 100644
> --- a/qemu-storage-daemon.c
> +++ b/qemu-storage-daemon.c
> @@ -45,10 +45,18 @@
>  #include "qemu/option.h"
>  #include "qom/object_interfaces.h"
>  
> +#include "sysemu/runstate.h"
>  #include "trace/control.h"
>  
>  #include 
>  
> +static bool exit_requested = false;
> +
> +void qemu_system_killed(int signal, pid_t pid)
> +{
> +exit_requested = true;
> +}
> +

This runs within a signal handler, so better make @exit_requested
volatile.  Hmm, vl.c gets it wrong, too.

>  static void help(void)
>  {
>  printf(
> @@ -238,6 +246,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[])
>  return EXIT_FAILURE;
>  }
>  
> +while (!exit_requested) {
> +main_loop_wait(false);
> +}
> +
>  return EXIT_SUCCESS;
>  }
> diff --git a/Makefile.objs b/Makefile.objs
> index cc262e445f..b667d3f07b 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -43,6 +43,8 @@ io-obj-y = io/
>  
>  storage-daemon-obj-y = block/
>  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




[RFC PATCH 09/18] qemu-storage-daemon: Add main loop

2019-10-17 Thread Kevin Wolf
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 
---
 qemu-storage-daemon.c | 13 +
 Makefile.objs |  2 ++
 2 files changed, 15 insertions(+)

diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
index 9e5f474fd0..099388f645 100644
--- a/qemu-storage-daemon.c
+++ b/qemu-storage-daemon.c
@@ -45,10 +45,18 @@
 #include "qemu/option.h"
 #include "qom/object_interfaces.h"
 
+#include "sysemu/runstate.h"
 #include "trace/control.h"
 
 #include 
 
+static bool exit_requested = false;
+
+void qemu_system_killed(int signal, pid_t pid)
+{
+exit_requested = true;
+}
+
 static void help(void)
 {
 printf(
@@ -238,6 +246,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[])
 return EXIT_FAILURE;
 }
 
+while (!exit_requested) {
+main_loop_wait(false);
+}
+
 return EXIT_SUCCESS;
 }
diff --git a/Makefile.objs b/Makefile.objs
index cc262e445f..b667d3f07b 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -43,6 +43,8 @@ io-obj-y = io/
 
 storage-daemon-obj-y = block/
 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
-- 
2.20.1