diff mbox series

[v2] module: silence errors for module_load_qom_all().

Message ID 20200923091217.22662-1-kraxel@redhat.com (mailing list archive)
State New, archived
Headers show
Series [v2] module: silence errors for module_load_qom_all(). | expand

Commit Message

Gerd Hoffmann Sept. 23, 2020, 9:12 a.m. UTC
Add mayfail bool parameter to module loading functions.  Set it to true
for module_load_qom_all() because device modules might not load into all
system emulation variants.  qemu-system-s390x for example will not load
qxl because it lacks vga support.  Makes "make check" less chatty.

Drop module_loaded_qom_all check in module_load_qom_one to make sure we
see errors for explicit load requests, i.e. module_load_qom_one("qxl")
failing will log an error no matter whenever module_load_qom_all() was
called before or not.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/qemu/module.h |  8 ++++----
 softmmu/qtest.c       |  2 +-
 util/module.c         | 20 ++++++++++----------
 3 files changed, 15 insertions(+), 15 deletions(-)

Comments

Paolo Bonzini Sept. 23, 2020, 9:36 a.m. UTC | #1
On 23/09/20 11:12, Gerd Hoffmann wrote:
> Add mayfail bool parameter to module loading functions.  Set it to true
> for module_load_qom_all() because device modules might not load into all
> system emulation variants.  qemu-system-s390x for example will not load
> qxl because it lacks vga support.  Makes "make check" less chatty.
> 
> Drop module_loaded_qom_all check in module_load_qom_one to make sure we
> see errors for explicit load requests, i.e. module_load_qom_one("qxl")
> failing will log an error no matter whenever module_load_qom_all() was
> called before or not.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  include/qemu/module.h |  8 ++++----
>  softmmu/qtest.c       |  2 +-
>  util/module.c         | 20 ++++++++++----------
>  3 files changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/include/qemu/module.h b/include/qemu/module.h
> index 9121a475c1b6..944d403cbd15 100644
> --- a/include/qemu/module.h
> +++ b/include/qemu/module.h
> @@ -61,15 +61,15 @@ typedef enum {
>  #define fuzz_target_init(function) module_init(function, \
>                                                 MODULE_INIT_FUZZ_TARGET)
>  #define migration_init(function) module_init(function, MODULE_INIT_MIGRATION)
> -#define block_module_load_one(lib) module_load_one("block-", lib)
> -#define ui_module_load_one(lib) module_load_one("ui-", lib)
> -#define audio_module_load_one(lib) module_load_one("audio-", lib)
> +#define block_module_load_one(lib) module_load_one("block-", lib, false)
> +#define ui_module_load_one(lib) module_load_one("ui-", lib, false)
> +#define audio_module_load_one(lib) module_load_one("audio-", lib, false)
>  
>  void register_module_init(void (*fn)(void), module_init_type type);
>  void register_dso_module_init(void (*fn)(void), module_init_type type);
>  
>  void module_call_init(module_init_type type);
> -bool module_load_one(const char *prefix, const char *lib_name);
> +bool module_load_one(const char *prefix, const char *lib_name, bool mayfail);
>  void module_load_qom_one(const char *type);
>  void module_load_qom_all(void);
>  
> diff --git a/softmmu/qtest.c b/softmmu/qtest.c
> index 4e439caec7e9..6f697c8a6987 100644
> --- a/softmmu/qtest.c
> +++ b/softmmu/qtest.c
> @@ -670,7 +670,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
>          g_assert(words[1] && words[2]);
>  
>          qtest_send_prefix(chr);
> -        if (module_load_one(words[1], words[2])) {
> +        if (module_load_one(words[1], words[2], false)) {
>              qtest_sendf(chr, "OK\n");
>          } else {
>              qtest_sendf(chr, "FAIL\n");
> diff --git a/util/module.c b/util/module.c
> index 34772e7d87eb..1535e7da4c06 100644
> --- a/util/module.c
> +++ b/util/module.c
> @@ -109,7 +109,7 @@ void module_call_init(module_init_type type)
>  }
>  
>  #ifdef CONFIG_MODULES
> -static int module_load_file(const char *fname)
> +static int module_load_file(const char *fname, bool mayfail)
>  {
>      GModule *g_module;
>      void (*sym)(void);
> @@ -133,8 +133,10 @@ static int module_load_file(const char *fname)
>  
>      g_module = g_module_open(fname, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
>      if (!g_module) {
> -        fprintf(stderr, "Failed to open module: %s\n",
> -                g_module_error());
> +        if (!mayfail) {
> +            fprintf(stderr, "Failed to open module: %s\n",
> +                    g_module_error());
> +        }
>          ret = -EINVAL;
>          goto out;
>      }
> @@ -166,7 +168,7 @@ out:
>  }
>  #endif
>  
> -bool module_load_one(const char *prefix, const char *lib_name)
> +bool module_load_one(const char *prefix, const char *lib_name, bool mayfail)
>  {
>      bool success = false;
>  
> @@ -222,7 +224,7 @@ bool module_load_one(const char *prefix, const char *lib_name)
>      for (i = 0; i < n_dirs; i++) {
>          fname = g_strdup_printf("%s/%s%s",
>                  dirs[i], module_name, CONFIG_HOST_DSOSUF);
> -        ret = module_load_file(fname);
> +        ret = module_load_file(fname, mayfail);
>          g_free(fname);
>          fname = NULL;
>          /* Try loading until loaded a module file */
> @@ -279,13 +281,11 @@ void module_load_qom_one(const char *type)
>      if (!type) {
>          return;
>      }
> -    if (module_loaded_qom_all) {
> -        return;
> -    }
>      for (i = 0; i < ARRAY_SIZE(qom_modules); i++) {
>          if (strcmp(qom_modules[i].type, type) == 0) {
>              module_load_one(qom_modules[i].prefix,
> -                            qom_modules[i].module);
> +                            qom_modules[i].module,
> +                            false);
>              return;
>          }
>      }
> @@ -306,7 +306,7 @@ void module_load_qom_all(void)
>              /* one module implementing multiple types -> load only once */
>              continue;
>          }
> -        module_load_one(qom_modules[i].prefix, qom_modules[i].module);
> +        module_load_one(qom_modules[i].prefix, qom_modules[i].module, true);
>      }
>      module_loaded_qom_all = true;
>  }
> 

Acked-by: Paolo Bonzini <pbonzini@redhat.com>
diff mbox series

Patch

diff --git a/include/qemu/module.h b/include/qemu/module.h
index 9121a475c1b6..944d403cbd15 100644
--- a/include/qemu/module.h
+++ b/include/qemu/module.h
@@ -61,15 +61,15 @@  typedef enum {
 #define fuzz_target_init(function) module_init(function, \
                                                MODULE_INIT_FUZZ_TARGET)
 #define migration_init(function) module_init(function, MODULE_INIT_MIGRATION)
-#define block_module_load_one(lib) module_load_one("block-", lib)
-#define ui_module_load_one(lib) module_load_one("ui-", lib)
-#define audio_module_load_one(lib) module_load_one("audio-", lib)
+#define block_module_load_one(lib) module_load_one("block-", lib, false)
+#define ui_module_load_one(lib) module_load_one("ui-", lib, false)
+#define audio_module_load_one(lib) module_load_one("audio-", lib, false)
 
 void register_module_init(void (*fn)(void), module_init_type type);
 void register_dso_module_init(void (*fn)(void), module_init_type type);
 
 void module_call_init(module_init_type type);
-bool module_load_one(const char *prefix, const char *lib_name);
+bool module_load_one(const char *prefix, const char *lib_name, bool mayfail);
 void module_load_qom_one(const char *type);
 void module_load_qom_all(void);
 
diff --git a/softmmu/qtest.c b/softmmu/qtest.c
index 4e439caec7e9..6f697c8a6987 100644
--- a/softmmu/qtest.c
+++ b/softmmu/qtest.c
@@ -670,7 +670,7 @@  static void qtest_process_command(CharBackend *chr, gchar **words)
         g_assert(words[1] && words[2]);
 
         qtest_send_prefix(chr);
-        if (module_load_one(words[1], words[2])) {
+        if (module_load_one(words[1], words[2], false)) {
             qtest_sendf(chr, "OK\n");
         } else {
             qtest_sendf(chr, "FAIL\n");
diff --git a/util/module.c b/util/module.c
index 34772e7d87eb..1535e7da4c06 100644
--- a/util/module.c
+++ b/util/module.c
@@ -109,7 +109,7 @@  void module_call_init(module_init_type type)
 }
 
 #ifdef CONFIG_MODULES
-static int module_load_file(const char *fname)
+static int module_load_file(const char *fname, bool mayfail)
 {
     GModule *g_module;
     void (*sym)(void);
@@ -133,8 +133,10 @@  static int module_load_file(const char *fname)
 
     g_module = g_module_open(fname, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
     if (!g_module) {
-        fprintf(stderr, "Failed to open module: %s\n",
-                g_module_error());
+        if (!mayfail) {
+            fprintf(stderr, "Failed to open module: %s\n",
+                    g_module_error());
+        }
         ret = -EINVAL;
         goto out;
     }
@@ -166,7 +168,7 @@  out:
 }
 #endif
 
-bool module_load_one(const char *prefix, const char *lib_name)
+bool module_load_one(const char *prefix, const char *lib_name, bool mayfail)
 {
     bool success = false;
 
@@ -222,7 +224,7 @@  bool module_load_one(const char *prefix, const char *lib_name)
     for (i = 0; i < n_dirs; i++) {
         fname = g_strdup_printf("%s/%s%s",
                 dirs[i], module_name, CONFIG_HOST_DSOSUF);
-        ret = module_load_file(fname);
+        ret = module_load_file(fname, mayfail);
         g_free(fname);
         fname = NULL;
         /* Try loading until loaded a module file */
@@ -279,13 +281,11 @@  void module_load_qom_one(const char *type)
     if (!type) {
         return;
     }
-    if (module_loaded_qom_all) {
-        return;
-    }
     for (i = 0; i < ARRAY_SIZE(qom_modules); i++) {
         if (strcmp(qom_modules[i].type, type) == 0) {
             module_load_one(qom_modules[i].prefix,
-                            qom_modules[i].module);
+                            qom_modules[i].module,
+                            false);
             return;
         }
     }
@@ -306,7 +306,7 @@  void module_load_qom_all(void)
             /* one module implementing multiple types -> load only once */
             continue;
         }
-        module_load_one(qom_modules[i].prefix, qom_modules[i].module);
+        module_load_one(qom_modules[i].prefix, qom_modules[i].module, true);
     }
     module_loaded_qom_all = true;
 }