Skip to contentSkip to conversation

introduce QMP-only binaries

RFC PATCH In review Paolo Bonzini 2 participants 5 messages Feb 8, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover introduce QMP-only binaries

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
Signature · 1 line
2.31.1
#1 lore raw

RFC PATCH 1/3 migration: allow calling migration_shutdown without a prior initialization

This can happen with the qemu-qmp binaries.

---
 migration/migration.c | 4 ++++
 1 file changed, 4 insertions(+)
migration/migration.c +4 -0
index bcc385b94b..075b21d9b5 100644
@@ -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
Signature · 1 line
2.31.1
#2 lore raw

RFC PATCH 2/3 net: initialize global variables early

In reply to Paolo Bonzini

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

---
 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(-)
hw/net/xen_nic.c +10 -10
index 5c815b4f0c..cd8f1edb29 100644
@@ -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,
 };
include/net/net.h +1 -0
index 523136c7ac..463a2c6de5 100644
@@ -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);
net/net.c +4 -1
index f0d14dbfc1..82406a1851 100644
@@ -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;
softmmu/runstate.c +1 -0
index 10d9b7365a..0ba7828155 100644
@@ -776,6 +776,7 @@ void qemu_init_subsystems(void)
 
     bdrv_init_with_whitelist();
     socket_init();
+    net_init();
 }
 
 
Signature · 1 line
2.31.1
Reviewed-by Philippe Mathieu-Daudé on v1 2/3
#3 lore raw

Re: [RFC PATCH 2/3] net: initialize global variables early

Quoted 10 lines · Paolo Bonzini

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

---
  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(-)
#4 lore raw

RFC PATCH 3/3 introduce qemu-qmp-*

In reply to Paolo Bonzini
---
 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
meson.build +12 -4
index 5f43355071..eed85d3d1a 100644
@@ -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,
softmmu/climain.c renamed from softmmu/vl.c +1 -1
similarity index 99%
rename from softmmu/vl.c
rename to softmmu/climain.c
index 5e1b35ba48..0489850415 100644
@@ -1,5 +1,5 @@
 /*
- * QEMU System Emulator
+ * QEMU System Emulator command-line interface
  *
  * Copyright (c) 2003-2008 Fabrice Bellard
  *
softmmu/meson.build +0 -1
index d8e03018ab..d53673f8d2 100644
@@ -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',
 )])
softmmu/qmpmain.c new file +120 -0

120 lines not on this page · raw message

Signature · 1 line
2.31.1