From: Paolo Bonzini <pbonzini@redhat.com>
To: Fam Zheng <famz@redhat.com>
Cc: peter.maydell@linaro.org, mjt@tls.msk.ru, qemu-devel@nongnu.org,
stefanha@redhat.com, vilanova@ac.upc.edu, rth@twiddle.net
Subject: Re: [Qemu-devel] [RFC PATCH v5 4/6] module: implement module loading function
Date: Wed, 11 Sep 2013 09:36:34 +0200 [thread overview]
Message-ID: <52301D82.7000404@redhat.com> (raw)
In-Reply-To: <1378877909-28518-5-git-send-email-famz@redhat.com>
Il 11/09/2013 07:38, Fam Zheng ha scritto:
> Added three types of modules:
>
> typedef enum {
> MODULE_LOAD_BLOCK = 0,
> MODULE_LOAD_UI,
> MODULE_LOAD_NET,
> MODULE_LOAD_MAX,
> } module_load_type;
If you want to make spice into a module, you probably need also audio,
char and hw modules.
Paolo
> and their loading function:
>
> void module_load(module_load_type).
>
> which loads all ".so" files in a subdir under "${PREFIX}/qemu/", e.g.
> "/usr/lib/qemu/block". Modules of each type should be loaded before
> respective subsystem initialization code.
>
> Requires gmodule-2.0 from glib.
>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> block.c | 1 +
> bsd-user/main.c | 3 +++
> configure | 22 ++++++++++++---------
> include/qemu/module.h | 9 +++++++++
> linux-user/main.c | 3 +++
> scripts/create_config | 4 ++++
> util/module.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
> vl.c | 2 ++
> 8 files changed, 88 insertions(+), 9 deletions(-)
>
> diff --git a/block.c b/block.c
> index 26639e8..16ceaaf 100644
> --- a/block.c
> +++ b/block.c
> @@ -4008,6 +4008,7 @@ BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs,
>
> void bdrv_init(void)
> {
> + module_load(MODULE_LOAD_BLOCK);
> module_call_init(MODULE_INIT_BLOCK);
> }
>
> diff --git a/bsd-user/main.c b/bsd-user/main.c
> index f9246aa..6cb9e35 100644
> --- a/bsd-user/main.c
> +++ b/bsd-user/main.c
> @@ -33,6 +33,7 @@
> #include "tcg.h"
> #include "qemu/timer.h"
> #include "qemu/envlist.h"
> +#include "qemu/module.h"
>
> int singlestep;
> #if defined(CONFIG_USE_GUEST_BASE)
> @@ -749,6 +750,8 @@ int main(int argc, char **argv)
> if (argc <= 1)
> usage();
>
> + module_load(MODULE_LOAD_UI);
> + module_load(MODULE_LOAD_NET);
> module_call_init(MODULE_INIT_QOM);
>
> if ((envlist = envlist_create()) == NULL) {
> diff --git a/configure b/configure
> index c6d4a62..a2858c2 100755
> --- a/configure
> +++ b/configure
> @@ -2252,15 +2252,19 @@ if test "$mingw32" = yes; then
> else
> glib_req_ver=2.12
> fi
> -if $pkg_config --atleast-version=$glib_req_ver gthread-2.0; then
> - glib_cflags=`$pkg_config --cflags gthread-2.0`
> - glib_libs=`$pkg_config --libs gthread-2.0`
> - CFLAGS="$glib_cflags $CFLAGS"
> - LIBS="$glib_libs $LIBS"
> - libs_qga="$glib_libs $libs_qga"
> -else
> - error_exit "glib-$glib_req_ver required to compile QEMU"
> -fi
> +
> +for i in gthread-2.0 gmodule-2.0; do
> + if $pkg_config --atleast-version=$glib_req_ver $i; then
> + glib_cflags=`$pkg_config --cflags $i`
> + glib_libs=`$pkg_config --libs $i`
> + CFLAGS="$glib_cflags $CFLAGS"
> + LIBS="$glib_libs $LIBS"
> + libs_qga="$glib_libs $libs_qga"
> + else
> + error_exit "glib-$glib_req_ver required to compile QEMU"
> + fi
> +done
> +
>
> ##########################################
> # pixman support probe
> diff --git a/include/qemu/module.h b/include/qemu/module.h
> index c4ccd57..f00bc25 100644
> --- a/include/qemu/module.h
> +++ b/include/qemu/module.h
> @@ -37,4 +37,13 @@ void register_module_init(void (*fn)(void), module_init_type type);
>
> void module_call_init(module_init_type type);
>
> +typedef enum {
> + MODULE_LOAD_BLOCK = 0,
> + MODULE_LOAD_UI,
> + MODULE_LOAD_NET,
> + MODULE_LOAD_MAX,
> +} module_load_type;
> +
> +void module_load(module_load_type type);
> +
> #endif
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 5c2f7b2..db08c23 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -34,6 +34,7 @@
> #include "qemu/timer.h"
> #include "qemu/envlist.h"
> #include "elf.h"
> +#include <qemu/module.h>
>
> char *exec_path;
>
> @@ -3551,6 +3552,8 @@ int main(int argc, char **argv, char **envp)
> int i;
> int ret;
>
> + module_load(MODULE_LOAD_UI);
> + module_load(MODULE_LOAD_NET);
> module_call_init(MODULE_INIT_QOM);
>
> qemu_cache_utils_init(envp);
> diff --git a/scripts/create_config b/scripts/create_config
> index b1adbf5..7a54f2d 100755
> --- a/scripts/create_config
> +++ b/scripts/create_config
> @@ -25,6 +25,7 @@ case $line in
> prefix=*)
> # save for the next definitions
> prefix=${line#*=}
> + echo "#define CONFIG_PREFIX \"$prefix\""
> ;;
> CONFIG_AUDIO_DRIVERS=*)
> drivers=${line#*=}
> @@ -104,6 +105,9 @@ case $line in
> value=${line#*=}
> echo "#define $name $value"
> ;;
> + DSOSUF=*)
> + echo "#define HOST_DSOSUF \"${line#*=}\""
> + ;;
> esac
>
> done # read
> diff --git a/util/module.c b/util/module.c
> index 7acc33d..ef75f8e 100644
> --- a/util/module.c
> +++ b/util/module.c
> @@ -13,6 +13,8 @@
> * GNU GPL, version 2 or (at your option) any later version.
> */
>
> +#include <gmodule.h>
> +#include <dirent.h>
> #include "qemu-common.h"
> #include "qemu/queue.h"
> #include "qemu/module.h"
> @@ -79,3 +81,54 @@ void module_call_init(module_init_type type)
> e->init();
> }
> }
> +
> +void module_load(module_load_type type)
> +{
> + const char *path;
> + const char *dsosuf = HOST_DSOSUF;
> + char *fname;
> + int suf_len = strlen(dsosuf);
> + DIR *dp;
> + struct dirent *ep = NULL;
> + GModule *g_module;
> +
> + if (!g_module_supported()) {
> + return;
> + }
> +
> + switch (type) {
> + case MODULE_LOAD_BLOCK:
> + path = CONFIG_PREFIX "/qemu/block/";
> + break;
> + case MODULE_LOAD_UI:
> + path = CONFIG_PREFIX "/qemu/ui/";
> + break;
> + case MODULE_LOAD_NET:
> + path = CONFIG_PREFIX "/qemu/net/";
> + break;
> + default:
> + return;
> + }
> +
> + dp = opendir(path);
> + if (!dp) {
> + fprintf(stderr, "Failed to open dir %s\n", path);
> + return;
> + }
> + for (ep = readdir(dp); ep; ep = readdir(dp)) {
> + int len = strlen(ep->d_name);
> + if (len > suf_len &&
> + !strcmp(&ep->d_name[len - suf_len], dsosuf)) {
> + fname = g_strdup_printf("%s%s", path, ep->d_name);
> + g_module = g_module_open(fname,
> + G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
> + if (!g_module) {
> + fprintf(stderr, "Failed to open module file %s\n",
> + g_module_error());
> + g_free(fname);
> + continue;
> + }
> + g_free(fname);
> + }
> + }
> +}
> diff --git a/vl.c b/vl.c
> index b4b119a..659e53a 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2940,6 +2940,8 @@ int main(int argc, char **argv, char **envp)
> #endif
> }
>
> + module_load(MODULE_LOAD_UI);
> + module_load(MODULE_LOAD_NET);
> module_call_init(MODULE_INIT_QOM);
>
> qemu_add_opts(&qemu_drive_opts);
>
next prev parent reply other threads:[~2013-09-11 7:36 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-11 5:38 [Qemu-devel] [RFC PATCH v5 0/6] Shared Library Module Support Fam Zheng
2013-09-11 5:38 ` [Qemu-devel] [RFC PATCH v5 1/6] make.rule: fix $(obj) to a real relative path Fam Zheng
2013-09-11 6:30 ` Paolo Bonzini
2013-09-11 7:05 ` Fam Zheng
2013-09-11 5:38 ` [Qemu-devel] [RFC PATCH v5 2/6] rule.mak: allow per object cflags and libs Fam Zheng
2013-09-11 5:38 ` [Qemu-devel] [RFC PATCH v5 3/6] Makefile: introduce common-obj-m and block-obj-m for DSO Fam Zheng
2013-09-11 5:38 ` [Qemu-devel] [RFC PATCH v5 4/6] module: implement module loading function Fam Zheng
2013-09-11 7:36 ` Paolo Bonzini [this message]
2013-09-11 14:10 ` Alex Bligh
2013-09-11 14:32 ` Paolo Bonzini
2013-09-11 15:06 ` Richard Henderson
2013-09-11 15:23 ` Alex Bligh
2013-09-11 15:43 ` Richard Henderson
2013-09-11 14:24 ` Peter Maydell
2013-09-12 3:12 ` Fam Zheng
2013-09-11 5:38 ` [Qemu-devel] [RFC PATCH v5 5/6] configure: introduce --enable-modules Fam Zheng
2013-09-11 7:27 ` Paolo Bonzini
2013-09-11 7:41 ` Paolo Bonzini
2013-09-11 8:01 ` Gerd Hoffmann
2013-09-11 8:17 ` Fam Zheng
2013-09-11 8:20 ` Peter Maydell
2013-09-11 8:56 ` Gerd Hoffmann
2013-09-11 10:03 ` Peter Maydell
2013-09-11 10:37 ` Gerd Hoffmann
2013-09-11 10:58 ` Peter Maydell
2013-09-11 8:35 ` Fam Zheng
2013-09-11 8:47 ` Paolo Bonzini
2013-09-11 5:38 ` [Qemu-devel] [RFC PATCH v5 6/6] block: build qed and curl as shared library Fam Zheng
2013-09-11 7:28 ` Paolo Bonzini
2013-09-11 7:36 ` Fam Zheng
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=52301D82.7000404@redhat.com \
--to=pbonzini@redhat.com \
--cc=famz@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--cc=stefanha@redhat.com \
--cc=vilanova@ac.upc.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.