All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] introduce QMP-only binaries
@ 2022-02-08 14:44 Paolo Bonzini
  2022-02-08 14:44 ` [RFC PATCH 1/3] migration: allow calling migration_shutdown without a prior initialization Paolo Bonzini
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Paolo Bonzini @ 2022-02-08 14:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: damien.hedde, berrange, mark.burton, armbru, f4bug, mirela.grujic

These three patches introduce a new system emulation binary qemu-qmp-*
that does nothing but start a QMP monitor (via systemd activation
protocol if possible, otherwise on stdio).  The idea is that the
creation of the machine would happen through new commands such as
machine-set, accel-set, etc.

Patches 1 and 2 simply avoid that {'execute':'quit'} crashes; that's
more or less the extent of my testing.

Paolo

Paolo Bonzini (3):
  migration: allow calling migration_shutdown without a prior
    initialization
  net: initialize global variables early
  introduce qemu-qmp-*

 hw/net/xen_nic.c            |  20 +++---
 include/net/net.h           |   1 +
 meson.build                 |  16 +++--
 migration/migration.c       |   4 ++
 net/net.c                   |   5 +-
 softmmu/{vl.c => climain.c} |   2 +-
 softmmu/meson.build         |   1 -
 softmmu/qmpmain.c           | 120 ++++++++++++++++++++++++++++++++++++
 softmmu/runstate.c          |   1 +
 9 files changed, 153 insertions(+), 17 deletions(-)
 rename softmmu/{vl.c => climain.c} (99%)
 create mode 100644 softmmu/qmpmain.c

-- 
2.31.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFC PATCH 1/3] migration: allow calling migration_shutdown without a prior initialization
  2022-02-08 14:44 [RFC PATCH 0/3] introduce QMP-only binaries Paolo Bonzini
@ 2022-02-08 14:44 ` Paolo Bonzini
  2022-02-08 14:44 ` [RFC PATCH 2/3] net: initialize global variables early Paolo Bonzini
  2022-02-08 14:44 ` [RFC PATCH 3/3] introduce qemu-qmp-* Paolo Bonzini
  2 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2022-02-08 14:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: damien.hedde, berrange, mark.burton, armbru, f4bug, mirela.grujic

This can happen with the qemu-qmp binaries.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 migration/migration.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/migration/migration.c b/migration/migration.c
index bcc385b94b..075b21d9b5 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -226,6 +226,10 @@ void migration_cancel(const Error *error)
 
 void migration_shutdown(void)
 {
+    if (!current_migration) {
+        return;
+    }
+
     /*
      * When the QEMU main thread exit, the COLO thread
      * may wait a semaphore. So, we should wakeup the
-- 
2.31.1




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC PATCH 2/3] net: initialize global variables early
  2022-02-08 14:44 [RFC PATCH 0/3] introduce QMP-only binaries Paolo Bonzini
  2022-02-08 14:44 ` [RFC PATCH 1/3] migration: allow calling migration_shutdown without a prior initialization Paolo Bonzini
@ 2022-02-08 14:44 ` Paolo Bonzini
  2022-02-08 14:47   ` Philippe Mathieu-Daudé via
  2022-02-08 14:44 ` [RFC PATCH 3/3] introduce qemu-qmp-* Paolo Bonzini
  2 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2022-02-08 14:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: damien.hedde, berrange, mark.burton, armbru, f4bug, mirela.grujic

Initialize global variables separately from net_init_clients, so
that calling net_cleanup does not crash miserably.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/net/xen_nic.c   | 20 ++++++++++----------
 include/net/net.h  |  1 +
 net/net.c          |  5 ++++-
 softmmu/runstate.c |  1 +
 4 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c
index 5c815b4f0c..cd8f1edb29 100644
--- a/hw/net/xen_nic.c
+++ b/hw/net/xen_nic.c
@@ -275,7 +275,7 @@ static NetClientInfo net_xen_info = {
     .receive = net_rx_packet,
 };
 
-static int net_init(struct XenLegacyDevice *xendev)
+static int xen_net_init(struct XenLegacyDevice *xendev)
 {
     struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev);
 
@@ -307,7 +307,7 @@ static int net_init(struct XenLegacyDevice *xendev)
     return 0;
 }
 
-static int net_connect(struct XenLegacyDevice *xendev)
+static int xen_net_connect(struct XenLegacyDevice *xendev)
 {
     struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev);
     int rx_copy;
@@ -362,7 +362,7 @@ static int net_connect(struct XenLegacyDevice *xendev)
     return 0;
 }
 
-static void net_disconnect(struct XenLegacyDevice *xendev)
+static void xen_net_disconnect(struct XenLegacyDevice *xendev)
 {
     struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev);
 
@@ -378,14 +378,14 @@ static void net_disconnect(struct XenLegacyDevice *xendev)
     }
 }
 
-static void net_event(struct XenLegacyDevice *xendev)
+static void xen_net_event(struct XenLegacyDevice *xendev)
 {
     struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev);
     net_tx_packets(netdev);
     qemu_flush_queued_packets(qemu_get_queue(netdev->nic));
 }
 
-static int net_free(struct XenLegacyDevice *xendev)
+static int xen_net_free(struct XenLegacyDevice *xendev)
 {
     struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev);
 
@@ -403,9 +403,9 @@ static int net_free(struct XenLegacyDevice *xendev)
 struct XenDevOps xen_netdev_ops = {
     .size       = sizeof(struct XenNetDev),
     .flags      = DEVOPS_FLAG_NEED_GNTDEV,
-    .init       = net_init,
-    .initialise    = net_connect,
-    .event      = net_event,
-    .disconnect = net_disconnect,
-    .free       = net_free,
+    .init       = xen_net_init,
+    .initialise    = xen_net_connect,
+    .event      = xen_net_event,
+    .disconnect = xen_net_disconnect,
+    .free       = xen_net_free,
 };
diff --git a/include/net/net.h b/include/net/net.h
index 523136c7ac..463a2c6de5 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -216,6 +216,7 @@ extern const char *host_net_devices[];
 /* from net.c */
 int net_client_parse(QemuOptsList *opts_list, const char *str);
 void show_netdevs(void);
+void net_init(void);
 int net_init_clients(Error **errp);
 void net_check_clients(void);
 void net_cleanup(void);
diff --git a/net/net.c b/net/net.c
index f0d14dbfc1..82406a1851 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1551,13 +1551,16 @@ out:
     return ret;
 }
 
-int net_init_clients(Error **errp)
+void net_init(void)
 {
     net_change_state_entry =
         qemu_add_vm_change_state_handler(net_vm_change_state_handler, NULL);
 
     QTAILQ_INIT(&net_clients);
+}
 
+int net_init_clients(Error **errp)
+{
     if (qemu_opts_foreach(qemu_find_opts("netdev"),
                           net_init_netdev, NULL, errp)) {
         return -1;
diff --git a/softmmu/runstate.c b/softmmu/runstate.c
index 10d9b7365a..0ba7828155 100644
--- a/softmmu/runstate.c
+++ b/softmmu/runstate.c
@@ -776,6 +776,7 @@ void qemu_init_subsystems(void)
 
     bdrv_init_with_whitelist();
     socket_init();
+    net_init();
 }
 
 
-- 
2.31.1




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC PATCH 3/3] introduce qemu-qmp-*
  2022-02-08 14:44 [RFC PATCH 0/3] introduce QMP-only binaries Paolo Bonzini
  2022-02-08 14:44 ` [RFC PATCH 1/3] migration: allow calling migration_shutdown without a prior initialization Paolo Bonzini
  2022-02-08 14:44 ` [RFC PATCH 2/3] net: initialize global variables early Paolo Bonzini
@ 2022-02-08 14:44 ` Paolo Bonzini
  2 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2022-02-08 14:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: damien.hedde, berrange, mark.burton, armbru, f4bug, mirela.grujic

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 meson.build                 |  16 +++--
 softmmu/{vl.c => climain.c} |   2 +-
 softmmu/meson.build         |   1 -
 softmmu/qmpmain.c           | 120 ++++++++++++++++++++++++++++++++++++
 4 files changed, 133 insertions(+), 6 deletions(-)
 rename softmmu/{vl.c => climain.c} (99%)
 create mode 100644 softmmu/qmpmain.c

diff --git a/meson.build b/meson.build
index 5f43355071..eed85d3d1a 100644
--- a/meson.build
+++ b/meson.build
@@ -3003,14 +3003,21 @@ foreach target : target_dirs
     execs = [{
       'name': 'qemu-system-' + target_name,
       'win_subsystem': 'console',
-      'sources': files('softmmu/main.c'),
+      'sources': [files('softmmu/climain.c', 'softmmu/main.c')],
       'dependencies': []
     }]
-    if targetos == 'windows' and (sdl.found() or gtk.found())
+    if targetos != 'windows'
+      execs += [{
+        'name': 'qemu-qmp-' + target_name,
+        'win_subsystem': 'console',
+        'sources': [files('softmmu/qmpmain.c', 'softmmu/main.c')],
+        'dependencies': []
+      }]
+    elif sdl.found() or gtk.found()
       execs += [{
         'name': 'qemu-system-' + target_name + 'w',
         'win_subsystem': 'windows',
-        'sources': files('softmmu/main.c'),
+        'sources': [files('softmmu/climain.c', 'softmmu/main.c')],
         'dependencies': []
       }]
     endif
@@ -3019,7 +3026,7 @@ foreach target : target_dirs
       execs += [{
         'name': 'qemu-fuzz-' + target_name,
         'win_subsystem': 'console',
-        'sources': specific_fuzz.sources(),
+        'sources': [files('softmmu/climain.c'), specific_fuzz.sources()],
         'dependencies': specific_fuzz.dependencies(),
       }]
     endif
@@ -3040,6 +3047,7 @@ foreach target : target_dirs
     emulator = executable(exe_name, exe['sources'],
                install: true,
                c_args: c_args,
+               include_directories: target_inc,
                dependencies: arch_deps + deps + exe['dependencies'],
                objects: lib.extract_all_objects(recursive: true),
                link_language: link_language,
diff --git a/softmmu/vl.c b/softmmu/climain.c
similarity index 99%
rename from softmmu/vl.c
rename to softmmu/climain.c
index 5e1b35ba48..0489850415 100644
--- a/softmmu/vl.c
+++ b/softmmu/climain.c
@@ -1,5 +1,5 @@
 /*
- * QEMU System Emulator
+ * QEMU System Emulator command-line interface
  *
  * Copyright (c) 2003-2008 Fabrice Bellard
  *
diff --git a/softmmu/meson.build b/softmmu/meson.build
index d8e03018ab..d53673f8d2 100644
--- a/softmmu/meson.build
+++ b/softmmu/meson.build
@@ -12,7 +12,6 @@ specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files(
   'memory.c',
   'memory_mapping.c',
   'qtest.c',
-  'vl.c',
   'cpu-timers.c',
   'runstate-action.c',
 )])
diff --git a/softmmu/qmpmain.c b/softmmu/qmpmain.c
new file mode 100644
index 0000000000..d976736ed9
--- /dev/null
+++ b/softmmu/qmpmain.c
@@ -0,0 +1,120 @@
+/*
+ * QEMU System Emulator machine interface
+ *
+ * Copyright (c) 2020 Red Hat, Inc.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/rcu.h"
+#include "qemu-common.h"
+#include "chardev/char.h"
+#include "monitor/monitor.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-misc.h"
+#include "qapi/qapi-commands-ui.h"
+#include "qapi/qapi-types-sockets.h"
+#include "qemu/systemd.h"
+#include "sysemu/cpu-timers.h"
+#include "sysemu/sysemu.h"
+#include "ui/console.h"
+#include "hw/qdev-core.h"
+
+static void open_socket_and_monitor(void)
+{
+    int nfds = check_socket_activation();
+    Chardev *chardev;
+    if (nfds > 1) {
+        error_report("QEMU only supports listening on one socket");
+        exit(1);
+    }
+    if (!nfds) {
+        ChardevBackend backend = {
+            .type = CHARDEV_BACKEND_KIND_STDIO,
+            .u.stdio.data = &(ChardevStdio) {
+                .has_signal = true,
+                .signal = false
+            }
+        };
+        chardev = qemu_chardev_new("#qmp0", TYPE_CHARDEV_STDIO, &backend, NULL, &error_fatal);
+    } else {
+        ChardevBackend backend = {
+           .type = CHARDEV_BACKEND_KIND_SOCKET,
+           .u.socket.data = &(ChardevSocket) {
+               .addr = &(SocketAddressLegacy) {
+                   .type = SOCKET_ADDRESS_TYPE_FD,
+                   .u.fd.data = &(String){
+                       .str = (char *) stringify(FIRST_SOCKET_ACTIVATION_FD)
+                   }
+               }
+           }
+        };
+        chardev = qemu_chardev_new("#qmp0", TYPE_CHARDEV_SOCKET, &backend, NULL, &error_fatal);
+    }
+    monitor_init_qmp(chardev, true, &error_fatal);
+}
+
+bool defaults_enabled(void)
+{
+    return false;
+}
+
+DisplayOptions *qmp_query_display_options(Error **errp)
+{
+    error_setg(errp, "You're running too fast!");
+    return NULL;
+}
+
+Chardev *serial_hd(int i)
+{
+    return NULL;
+}
+
+void qmp_x_exit_preconfig(Error **errp)
+{
+    error_setg(errp, "You're running too fast!");
+}
+
+void qemu_init(int argc, char **argv, char **envp)
+{
+    error_init(argv[0]);
+    qemu_init_exec_dir(argv[0]);
+
+    qemu_init_subsystems();
+
+    /* Missing: parse -name, -sandbox, -trace, -L */
+
+    /*
+     * Clear error location left behind by the loop.
+     * Best done right after the loop.  Do not insert code here!
+     */
+    loc_set_none();
+
+    /* Missing: process -name, -sandbox, -trace, -L */
+
+    rcu_disable_atfork();
+    qemu_init_main_loop(&error_fatal);
+    cpu_timers_init();
+    open_socket_and_monitor();
+
+    /* Missing: replay_configure, configure_rtc */
+
+    /* machine-set:
+     *    qemu_create_machine();
+     *    qemu_apply_machine_options();
+     *    phase_advance(PHASE_MACHINE_CREATED);
+     *
+     * accel-set:
+     *    configure_accelerators(argv[0]);
+     *    phase_advance(PHASE_ACCEL_CREATED);
+     *    machine type deprecation
+     *    migration_object_init();
+     *    cpu_type...
+     *    accel_setup_post(current_machine);
+     *    machine_run_board_init(current_machine, errp);
+     */
+
+    init_displaystate();
+    os_setup_signal_handling();
+}
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [RFC PATCH 2/3] net: initialize global variables early
  2022-02-08 14:44 ` [RFC PATCH 2/3] net: initialize global variables early Paolo Bonzini
@ 2022-02-08 14:47   ` Philippe Mathieu-Daudé via
  0 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-02-08 14:47 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel
  Cc: mirela.grujic, armbru, damien.hedde, berrange, mark.burton

On 8/2/22 15:44, Paolo Bonzini wrote:
> Initialize global variables separately from net_init_clients, so
> that calling net_cleanup does not crash miserably.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   hw/net/xen_nic.c   | 20 ++++++++++----------
>   include/net/net.h  |  1 +
>   net/net.c          |  5 ++++-
>   softmmu/runstate.c |  1 +
>   4 files changed, 16 insertions(+), 11 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-08 17:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-08 14:44 [RFC PATCH 0/3] introduce QMP-only binaries Paolo Bonzini
2022-02-08 14:44 ` [RFC PATCH 1/3] migration: allow calling migration_shutdown without a prior initialization Paolo Bonzini
2022-02-08 14:44 ` [RFC PATCH 2/3] net: initialize global variables early Paolo Bonzini
2022-02-08 14:47   ` Philippe Mathieu-Daudé via
2022-02-08 14:44 ` [RFC PATCH 3/3] introduce qemu-qmp-* Paolo Bonzini

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.