qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Igor Mammedov <imammedo@redhat.com>
Subject: [PULL 11/45] plugin: propagate errors
Date: Tue, 15 Dec 2020 12:54:11 -0500	[thread overview]
Message-ID: <20201215175445.1272776-12-pbonzini@redhat.com> (raw)
In-Reply-To: <20201215175445.1272776-1-pbonzini@redhat.com>

qemu_finish_machine_init currently can only exit QEMU if it fails.
Prepare for giving it proper error propagation, and possibly for
adding a plugin_add monitor command that calls an accelerator
method.

While at it, make all errors from plugin_load look the same.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/qemu/plugin.h |  4 ++--
 linux-user/main.c     |  4 +---
 plugins/loader.c      | 34 +++++++++++++++++-----------------
 softmmu/vl.c          |  4 +---
 4 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h
index ab790ad105..841deed79c 100644
--- a/include/qemu/plugin.h
+++ b/include/qemu/plugin.h
@@ -45,7 +45,7 @@ static inline void qemu_plugin_add_opts(void)
 }
 
 void qemu_plugin_opt_parse(const char *optarg, QemuPluginList *head);
-int qemu_plugin_load_list(QemuPluginList *head);
+int qemu_plugin_load_list(QemuPluginList *head, Error **errp);
 
 union qemu_plugin_cb_sig {
     qemu_plugin_simple_cb_t          simple;
@@ -199,7 +199,7 @@ static inline void qemu_plugin_opt_parse(const char *optarg,
     exit(1);
 }
 
-static inline int qemu_plugin_load_list(QemuPluginList *head)
+static inline int qemu_plugin_load_list(QemuPluginList *head, Error **errp)
 {
     return 0;
 }
diff --git a/linux-user/main.c b/linux-user/main.c
index 24d1eb73ad..750a01118f 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -671,9 +671,7 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
     trace_init_file();
-    if (qemu_plugin_load_list(&plugins)) {
-        exit(1);
-    }
+    qemu_plugin_load_list(&plugins, &error_fatal);
 
     /* Zero out regs */
     memset(regs, 0, sizeof(struct target_pt_regs));
diff --git a/plugins/loader.c b/plugins/loader.c
index 8ac5dbc20f..5cb9794fda 100644
--- a/plugins/loader.c
+++ b/plugins/loader.c
@@ -150,7 +150,7 @@ static uint64_t xorshift64star(uint64_t x)
     return x * UINT64_C(2685821657736338717);
 }
 
-static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info)
+static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info, Error **errp)
 {
     qemu_plugin_install_func_t install;
     struct qemu_plugin_ctx *ctx;
@@ -163,37 +163,37 @@ static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info)
 
     ctx->handle = g_module_open(desc->path, G_MODULE_BIND_LOCAL);
     if (ctx->handle == NULL) {
-        error_report("%s: %s", __func__, g_module_error());
+        error_setg(errp, "Could not load plugin %s: %s", desc->path, g_module_error());
         goto err_dlopen;
     }
 
     if (!g_module_symbol(ctx->handle, "qemu_plugin_install", &sym)) {
-        error_report("%s: %s", __func__, g_module_error());
+        error_setg(errp, "Could not load plugin %s: %s", desc->path, g_module_error());
         goto err_symbol;
     }
     install = (qemu_plugin_install_func_t) sym;
     /* symbol was found; it could be NULL though */
     if (install == NULL) {
-        error_report("%s: %s: qemu_plugin_install is NULL",
-                     __func__, desc->path);
+        error_setg(errp, "Could not load plugin %s: qemu_plugin_install is NULL",
+                   desc->path);
         goto err_symbol;
     }
 
     if (!g_module_symbol(ctx->handle, "qemu_plugin_version", &sym)) {
-        error_report("TCG plugin %s does not declare API version %s",
-                     desc->path, g_module_error());
+        error_setg(errp, "Could not load plugin %s: plugin does not declare API version %s",
+                   desc->path, g_module_error());
         goto err_symbol;
     } else {
         int version = *(int *)sym;
         if (version < QEMU_PLUGIN_MIN_VERSION) {
-            error_report("TCG plugin %s requires API version %d, but "
-                         "this QEMU supports only a minimum version of %d",
-                         desc->path, version, QEMU_PLUGIN_MIN_VERSION);
+            error_setg(errp, "Could not load plugin %s: plugin requires API version %d, but "
+                       "this QEMU supports only a minimum version of %d",
+                       desc->path, version, QEMU_PLUGIN_MIN_VERSION);
             goto err_symbol;
         } else if (version > QEMU_PLUGIN_VERSION) {
-            error_report("TCG plugin %s requires API version %d, but "
-                         "this QEMU supports only up to version %d",
-                         desc->path, version, QEMU_PLUGIN_VERSION);
+            error_setg(errp, "Could not load plugin %s: plugin requires API version %d, but "
+                       "this QEMU supports only up to version %d",
+                       desc->path, version, QEMU_PLUGIN_VERSION);
             goto err_symbol;
         }
     }
@@ -220,8 +220,8 @@ static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info)
     rc = install(ctx->id, info, desc->argc, desc->argv);
     ctx->installing = false;
     if (rc) {
-        error_report("%s: qemu_plugin_install returned error code %d",
-                     __func__, rc);
+        error_setg(errp, "Could not load plugin %s: qemu_plugin_install returned error code %d",
+                   desc->path, rc);
         /*
          * we cannot rely on the plugin doing its own cleanup, so
          * call a full uninstall if the plugin did not yet call it.
@@ -263,7 +263,7 @@ static void plugin_desc_free(struct qemu_plugin_desc *desc)
  * Note: the descriptor of each successfully installed plugin is removed
  * from the list given by @head.
  */
-int qemu_plugin_load_list(QemuPluginList *head)
+int qemu_plugin_load_list(QemuPluginList *head, Error **errp)
 {
     struct qemu_plugin_desc *desc, *next;
     g_autofree qemu_info_t *info = g_new0(qemu_info_t, 1);
@@ -283,7 +283,7 @@ int qemu_plugin_load_list(QemuPluginList *head)
     QTAILQ_FOREACH_SAFE(desc, head, entry, next) {
         int err;
 
-        err = plugin_load(desc, info);
+        err = plugin_load(desc, info, errp);
         if (err) {
             return err;
         }
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 0f7222af31..553482ec02 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2416,9 +2416,7 @@ static void qemu_init_board(void)
     }
 
     /* process plugin before CPUs are created, but once -smp has been parsed */
-    if (qemu_plugin_load_list(&plugin_list)) {
-        exit(1);
-    }
+    qemu_plugin_load_list(&plugin_list, &error_fatal);
 
     /* From here on we enter MACHINE_PHASE_INITIALIZED.  */
     machine_run_board_init(current_machine);
-- 
2.26.2




  parent reply	other threads:[~2020-12-15 18:02 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-15 17:54 [PULL 00/45] Misc patches for 2020-12-15 Paolo Bonzini
2020-12-15 17:54 ` [PULL 01/45] remove preconfig state Paolo Bonzini
2020-12-15 17:54 ` [PULL 02/45] vl: remove separate preconfig main_loop Paolo Bonzini
2020-12-19 21:30   ` Laurent Vivier
2020-12-20  8:52     ` Paolo Bonzini
2020-12-15 17:54 ` [PULL 03/45] vl: allow -incoming defer with -preconfig Paolo Bonzini
2020-12-15 17:54 ` [PULL 04/45] vl: extract softmmu/runstate.c Paolo Bonzini
2020-12-15 17:54 ` [PULL 05/45] vl: extract softmmu/globals.c Paolo Bonzini
2020-12-15 17:54 ` [PULL 06/45] vl: move all generic initialization out of vl.c Paolo Bonzini
2020-12-15 17:54 ` [PULL 07/45] chardev: do not use machine_init_done Paolo Bonzini
2020-12-15 17:54 ` [PULL 08/45] machine: introduce MachineInitPhase Paolo Bonzini
2020-12-15 17:54 ` [PULL 09/45] ppc/spapr: cleanup -machine pseries,nvdimm=X handling Paolo Bonzini
2020-12-15 17:54 ` [PULL 10/45] vl: make qemu_get_machine_opts static Paolo Bonzini
2020-12-15 17:54 ` Paolo Bonzini [this message]
2020-12-15 17:54 ` [PULL 12/45] memory: allow creating MemoryRegions before accelerators Paolo Bonzini
2020-12-15 17:54 ` [PULL 13/45] monitor: allow quitting while in preconfig state Paolo Bonzini
2020-12-15 17:54 ` [PULL 14/45] qmp: generalize watchdog-set-action to -no-reboot/-no-shutdown Paolo Bonzini
2020-12-15 17:54 ` [PULL 15/45] vl: Add an -action option specifying response to guest events Paolo Bonzini
2020-12-15 17:54 ` [PULL 16/45] vl: Add option to avoid stopping VM upon guest panic Paolo Bonzini
2021-01-19 21:34   ` Peter Maydell
2021-01-20  5:28     ` Alejandro Jimenez
2021-01-20 13:47       ` Peter Maydell
2021-01-20 13:54       ` Daniel P. Berrangé
2021-01-20 14:47         ` Paolo Bonzini
2021-01-20 13:58     ` Paolo Bonzini
2020-12-15 17:54 ` [PULL 17/45] qtest/pvpanic: Test panic option that allows VM to continue Paolo Bonzini
2020-12-15 17:54 ` [PULL 18/45] msix: assert that accesses are within bounds Paolo Bonzini
2020-12-15 17:54 ` [PULL 19/45] memory: clamp cached translation in case it points to an MMIO region Paolo Bonzini
2021-01-13 13:27   ` Michael S. Tsirkin
2020-12-15 17:54 ` [PULL 20/45] accel/tcg: Remove deprecated '-tb-size' option Paolo Bonzini
2020-12-15 17:54 ` [PULL 21/45] docs/system: Move the list of removed features to a separate file Paolo Bonzini
2020-12-15 17:54 ` [PULL 22/45] Remove the deprecated -realtime option Paolo Bonzini
2020-12-15 17:54 ` [PULL 23/45] Remove the deprecated -show-cursor option Paolo Bonzini
2020-12-15 17:54 ` [PULL 24/45] icount: improve exec nocache usage Paolo Bonzini
2020-12-15 17:54 ` [PULL 25/45] scsi: fix device removal race vs IO restart callback on resume Paolo Bonzini
2020-12-15 17:54 ` [PULL 26/45] kvm: Take into account the unaligned section size when preparing bitmap Paolo Bonzini
2020-12-15 17:54 ` [PULL 27/45] qemu-option: simplify search for end of key Paolo Bonzini
2020-12-15 17:54 ` [PULL 28/45] qemu-option: pass QemuOptsList to opts_accepts_any Paolo Bonzini
2020-12-15 17:54 ` [PULL 29/45] vl: rename local variable in configure_accelerators Paolo Bonzini
2020-12-15 17:54 ` [PULL 30/45] docs: set CONFDIR when running sphinx Paolo Bonzini
2020-12-15 17:54 ` [PULL 31/45] hw/core: Restrict 'fw-path-provider.c' to system mode emulation Paolo Bonzini
2020-12-15 17:54 ` [PULL 32/45] qemu/atomic: Drop special case for unsupported compiler Paolo Bonzini
2020-12-15 17:54 ` [PULL 33/45] accel/tcg: Remove special case for GCC < 4.6 Paolo Bonzini
2020-12-15 17:54 ` [PULL 34/45] compiler.h: remove GCC < 3 __builtin_expect fallback Paolo Bonzini
2020-12-15 17:54 ` [PULL 35/45] qemu-plugin.h: remove GCC < 4 Paolo Bonzini
2020-12-15 17:54 ` [PULL 36/45] tests: remove GCC < 4 fallbacks Paolo Bonzini
2020-12-15 17:54 ` [PULL 37/45] virtiofsd: replace _Static_assert with QEMU_BUILD_BUG_ON Paolo Bonzini
2020-12-15 17:54 ` [PULL 38/45] compiler.h: explicit case for Clang printf attribute Paolo Bonzini
2020-12-15 17:54 ` [PULL 39/45] poison: remove GNUC check Paolo Bonzini
2020-12-15 17:54 ` [PULL 40/45] xen: " Paolo Bonzini
2020-12-15 17:54 ` [PULL 41/45] compiler: " Paolo Bonzini
2020-12-15 17:54 ` [PULL 42/45] linux-user: " Paolo Bonzini
2020-12-15 17:54 ` [PULL 43/45] compiler.h: remove QEMU_GNUC_PREREQ Paolo Bonzini
2020-12-15 17:54 ` [PULL 44/45] scripts/git.orderfile: Keep files with .inc extension sorted Paolo Bonzini
2020-12-15 17:54 ` [PULL 45/45] build: -no-pie is no functional linker flag Paolo Bonzini
2020-12-16 10:55 ` [PULL 00/45] Misc patches for 2020-12-15 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201215175445.1272776-12-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).