Преглед изворни кода

plugin: propagate errors

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>
Paolo Bonzini пре 4 година
родитељ
комит
0572f558cb
4 измењених фајлова са 21 додато и 25 уклоњено
  1. 2 2
      include/qemu/plugin.h
  2. 1 3
      linux-user/main.c
  3. 17 17
      plugins/loader.c
  4. 1 3
      softmmu/vl.c

+ 2 - 2
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);
 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 {
 union qemu_plugin_cb_sig {
     qemu_plugin_simple_cb_t          simple;
     qemu_plugin_simple_cb_t          simple;
@@ -199,7 +199,7 @@ static inline void qemu_plugin_opt_parse(const char *optarg,
     exit(1);
     exit(1);
 }
 }
 
 
-static inline int qemu_plugin_load_list(QemuPluginList *head)
+static inline int qemu_plugin_load_list(QemuPluginList *head, Error **errp)
 {
 {
     return 0;
     return 0;
 }
 }

+ 1 - 3
linux-user/main.c

@@ -671,9 +671,7 @@ int main(int argc, char **argv, char **envp)
         exit(1);
         exit(1);
     }
     }
     trace_init_file();
     trace_init_file();
-    if (qemu_plugin_load_list(&plugins)) {
-        exit(1);
-    }
+    qemu_plugin_load_list(&plugins, &error_fatal);
 
 
     /* Zero out regs */
     /* Zero out regs */
     memset(regs, 0, sizeof(struct target_pt_regs));
     memset(regs, 0, sizeof(struct target_pt_regs));

+ 17 - 17
plugins/loader.c

@@ -150,7 +150,7 @@ static uint64_t xorshift64star(uint64_t x)
     return x * UINT64_C(2685821657736338717);
     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;
     qemu_plugin_install_func_t install;
     struct qemu_plugin_ctx *ctx;
     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);
     ctx->handle = g_module_open(desc->path, G_MODULE_BIND_LOCAL);
     if (ctx->handle == NULL) {
     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;
         goto err_dlopen;
     }
     }
 
 
     if (!g_module_symbol(ctx->handle, "qemu_plugin_install", &sym)) {
     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;
         goto err_symbol;
     }
     }
     install = (qemu_plugin_install_func_t) sym;
     install = (qemu_plugin_install_func_t) sym;
     /* symbol was found; it could be NULL though */
     /* symbol was found; it could be NULL though */
     if (install == NULL) {
     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;
         goto err_symbol;
     }
     }
 
 
     if (!g_module_symbol(ctx->handle, "qemu_plugin_version", &sym)) {
     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;
         goto err_symbol;
     } else {
     } else {
         int version = *(int *)sym;
         int version = *(int *)sym;
         if (version < QEMU_PLUGIN_MIN_VERSION) {
         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;
             goto err_symbol;
         } else if (version > QEMU_PLUGIN_VERSION) {
         } 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;
             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);
     rc = install(ctx->id, info, desc->argc, desc->argv);
     ctx->installing = false;
     ctx->installing = false;
     if (rc) {
     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
          * we cannot rely on the plugin doing its own cleanup, so
          * call a full uninstall if the plugin did not yet call it.
          * 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
  * Note: the descriptor of each successfully installed plugin is removed
  * from the list given by @head.
  * 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;
     struct qemu_plugin_desc *desc, *next;
     g_autofree qemu_info_t *info = g_new0(qemu_info_t, 1);
     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) {
     QTAILQ_FOREACH_SAFE(desc, head, entry, next) {
         int err;
         int err;
 
 
-        err = plugin_load(desc, info);
+        err = plugin_load(desc, info, errp);
         if (err) {
         if (err) {
             return err;
             return err;
         }
         }

+ 1 - 3
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 */
     /* 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.  */
     /* From here on we enter MACHINE_PHASE_INITIALIZED.  */
     machine_run_board_init(current_machine);
     machine_run_board_init(current_machine);