From: Max Reitz <mreitz@redhat.com>
To: Fam Zheng <famz@redhat.com>, qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, Stefan Hajnoczi <stefanha@redhat.com>,
Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH for-2.8 v3 2/3] module: Don't load the same module if requested multiple times
Date: Mon, 29 Aug 2016 15:30:55 +0200 [thread overview]
Message-ID: <5a41b27e-6a76-d87e-5ff2-4528f132aa42@redhat.com> (raw)
In-Reply-To: <1471418433-20061-3-git-send-email-famz@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2618 bytes --]
On 17.08.2016 09:20, Fam Zheng wrote:
> Use a hash table to keep record of all loaded modules, and return early
> if the requested module is already loaded.
>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> util/module.c | 19 +++++++++++++++++--
> 1 file changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/util/module.c b/util/module.c
> index a5f7fbd..63efad6 100644
> --- a/util/module.c
> +++ b/util/module.c
> @@ -163,14 +163,29 @@ void module_load_one(const char *prefix, const char *lib_name)
> char *fname = NULL;
> char *exec_dir;
> char *dirs[3];
> + char *module_name;
> int i = 0;
> int ret;
> + static GHashTable *loaded_modules;
>
> if (!g_module_supported()) {
> fprintf(stderr, "Module is not supported by system.\n");
> return;
> }
>
> + if (!loaded_modules) {
> + loaded_modules = g_hash_table_new(g_str_hash, g_str_equal);
> + }
> +
> + module_name = g_strdup_printf("%s%s", prefix, lib_name);
> +
> + if (g_hash_table_lookup(loaded_modules, module_name)) {
> + fprintf(stderr, "module is already loaded: %s\n", module_name);
I'm not quite happy with this warning message. Loading a module is
automatically initiated by internal code in qemu, i.e. never done by the
user. Therefore, printing a message for the user does not make much
sense to me since the user cannot do anything about this.
If it is truly wrong to attempt to load a module more than once, this
should be an assertion.
However, I think it's perfectly fine to just allow qemu code to try to
load a module more than once and just ignore the request if we've
already loaded the module (as the commit message implies). In this case,
we don't need an error message or warning, though.
Max
> + g_free(module_name);
> + return;
> + }
> + g_hash_table_insert(loaded_modules, module_name, module_name);
> +
> exec_dir = qemu_get_exec_dir();
> dirs[i++] = g_strdup_printf("%s", CONFIG_QEMU_MODDIR);
> dirs[i++] = g_strdup_printf("%s/..", exec_dir ? : "");
> @@ -180,8 +195,8 @@ void module_load_one(const char *prefix, const char *lib_name)
> exec_dir = NULL;
>
> for (i = 0; i < ARRAY_SIZE(dirs); i++) {
> - fname = g_strdup_printf("%s/%s%s%s",
> - dirs[i], prefix, lib_name, HOST_DSOSUF);
> + fname = g_strdup_printf("%s/%s%s",
> + dirs[i], module_name, HOST_DSOSUF);
> ret = module_load_file(fname);
> g_free(fname);
> fname = NULL;
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 498 bytes --]
next prev parent reply other threads:[~2016-08-29 13:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-17 7:20 [Qemu-devel] [PATCH for-2.8 v3 0/3] block: Fix libbz2 library dependency regresssion Fam Zheng
2016-08-17 7:20 ` [Qemu-devel] [PATCH for-2.8 v3 1/3] scripts: Allow block module to not define BlockDriver Fam Zheng
2016-08-29 13:11 ` Max Reitz
2016-08-17 7:20 ` [Qemu-devel] [PATCH for-2.8 v3 2/3] module: Don't load the same module if requested multiple times Fam Zheng
2016-08-29 13:30 ` Max Reitz [this message]
2016-09-05 2:27 ` Fam Zheng
2016-08-17 7:20 ` [Qemu-devel] [PATCH for-2.8 v3 3/3] dmg: Move libbz2 code to dmg-bz2.so Fam Zheng
2016-08-17 8:35 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2016-08-17 8:43 ` [Qemu-devel] [Qemu-block] [PATCH for-2.8 v3 0/3] block: Fix libbz2 library dependency regresssion Stefan Hajnoczi
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=5a41b27e-6a76-d87e-5ff2-4528f132aa42@redhat.com \
--to=mreitz@redhat.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).