From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, famz@redhat.com, mjt@tls.msk.ru,
stefanha@redhat.com, pbonzini@redhat.com, vilanova@ac.upc.edu,
rth@twiddle.net
Subject: [Qemu-devel] [PATCH v6 4/8] module: implement module loading function
Date: Wed, 11 Sep 2013 21:34:04 +0800 [thread overview]
Message-ID: <1378906448-15834-5-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1378906448-15834-1-git-send-email-famz@redhat.com>
Added three types of modules:
typedef enum {
MODULE_LOAD_BLOCK = 0,
MODULE_LOAD_UI,
MODULE_LOAD_NET,
MODULE_LOAD_MAX,
} module_load_type;
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 | 28 ++++++++++++++++++---------
include/qemu/module.h | 9 +++++++++
linux-user/main.c | 3 +++
scripts/create_config | 7 +++++++
util/module.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
vl.c | 2 ++
8 files changed, 97 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..a80f143 100755
--- a/configure
+++ b/configure
@@ -198,6 +198,7 @@ datadir="\${prefix}/share"
qemu_docdir="\${prefix}/share/doc/qemu"
bindir="\${prefix}/bin"
libdir="\${prefix}/lib"
+moddir="\${prefix}/lib/qemu"
libexecdir="\${prefix}/libexec"
includedir="\${prefix}/include"
sysconfdir="\${prefix}/etc"
@@ -673,6 +674,8 @@ for opt do
;;
--libdir=*) libdir="$optarg"
;;
+ --moddir=*) moddir="$optarg"
+ ;;
--libexecdir=*) libexecdir="$optarg"
;;
--includedir=*) includedir="$optarg"
@@ -1049,6 +1052,7 @@ echo " --datadir=PATH install firmware in PATH$confsuffix"
echo " --docdir=PATH install documentation in PATH$confsuffix"
echo " --bindir=PATH install binaries in PATH"
echo " --libdir=PATH install libraries in PATH"
+echo " --moddir=PATH install modules in PATH"
echo " --sysconfdir=PATH install config in PATH$confsuffix"
echo " --localstatedir=PATH install local state in PATH (set at runtime on win32)"
echo " --with-confsuffix=SUFFIX suffix for QEMU data inside datadir and sysconfdir [$confsuffix]"
@@ -2252,15 +2256,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
@@ -3553,6 +3561,7 @@ echo "Install prefix $prefix"
echo "BIOS directory `eval echo $qemu_datadir`"
echo "binary directory `eval echo $bindir`"
echo "library directory `eval echo $libdir`"
+echo "module directory `eval echo $moddir`"
echo "libexec directory `eval echo $libexecdir`"
echo "include directory `eval echo $includedir`"
echo "config directory `eval echo $sysconfdir`"
@@ -3675,6 +3684,7 @@ echo all: >> $config_host_mak
echo "prefix=$prefix" >> $config_host_mak
echo "bindir=$bindir" >> $config_host_mak
echo "libdir=$libdir" >> $config_host_mak
+echo "moddir=$moddir" >> $config_host_mak
echo "libexecdir=$libexecdir" >> $config_host_mak
echo "includedir=$includedir" >> $config_host_mak
echo "mandir=$mandir" >> $config_host_mak
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..381564e 100755
--- a/scripts/create_config
+++ b/scripts/create_config
@@ -26,6 +26,10 @@ case $line in
# save for the next definitions
prefix=${line#*=}
;;
+ moddir=*)
+ eval "moddir=\"${line#*=}\""
+ echo "#define CONFIG_MODDIR \"$moddir\""
+ ;;
CONFIG_AUDIO_DRIVERS=*)
drivers=${line#*=}
echo "#define CONFIG_AUDIO_DRIVERS \\"
@@ -104,6 +108,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..4d0374a 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_MODDIR "/block/";
+ break;
+ case MODULE_LOAD_UI:
+ path = CONFIG_MODDIR "/ui/";
+ break;
+ case MODULE_LOAD_NET:
+ path = CONFIG_MODDIR "/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);
--
1.8.3.1
next prev parent reply other threads:[~2013-09-11 13:34 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-11 13:34 [Qemu-devel] [PATCH v6 0/8] Shared Library Module Support Fam Zheng
2013-09-11 13:34 ` [Qemu-devel] [PATCH v6 1/8] make.rule: fix $(obj) to a real relative path Fam Zheng
2013-09-11 13:41 ` Paolo Bonzini
2013-09-12 2:32 ` Fam Zheng
2013-09-11 14:59 ` Daniel P. Berrange
2013-09-12 1:57 ` Fam Zheng
2013-09-12 2:22 ` Fam Zheng
2013-09-11 16:38 ` Peter Maydell
2013-09-11 16:40 ` Paolo Bonzini
2013-09-11 16:43 ` Peter Maydell
2013-09-11 13:34 ` [Qemu-devel] [PATCH v6 2/8] rule.mak: allow per object cflags and libs Fam Zheng
2013-09-11 13:43 ` Paolo Bonzini
2013-09-12 2:52 ` Fam Zheng
2013-09-12 6:34 ` Paolo Bonzini
2013-09-12 7:12 ` Fam Zheng
2013-09-11 13:34 ` [Qemu-devel] [PATCH v6 3/8] Makefile: introduce common-obj-m and block-obj-m for DSO Fam Zheng
2013-09-11 20:01 ` Peter Maydell
2013-09-12 2:48 ` Fam Zheng
2013-09-12 2:50 ` Fam Zheng
2013-09-11 13:34 ` Fam Zheng [this message]
2013-09-11 15:48 ` [Qemu-devel] [PATCH v6 4/8] module: implement module loading function Daniel P. Berrange
2013-09-11 18:33 ` Alex Bligh
2013-09-11 18:46 ` Richard Henderson
2013-09-12 3:02 ` Fam Zheng
2013-09-12 5:36 ` Michael Tokarev
2013-09-12 9:13 ` Daniel P. Berrange
2013-09-12 11:59 ` Eric Blake
2013-09-12 12:44 ` Daniel P. Berrange
2013-09-11 13:34 ` [Qemu-devel] [PATCH v6 5/8] configure: introduce --enable-modules Fam Zheng
2013-09-11 13:46 ` Paolo Bonzini
2013-09-12 2:06 ` Fam Zheng
2013-09-11 13:34 ` [Qemu-devel] [PATCH v6 6/8] Makefile: install modules with "make install" Fam Zheng
2013-09-11 13:50 ` Paolo Bonzini
2013-09-12 2:00 ` Fam Zheng
2013-09-11 13:34 ` [Qemu-devel] [PATCH v6 7/8] .gitignore: ignore module related files (dll, so, mo) Fam Zheng
2013-09-11 13:34 ` [Qemu-devel] [PATCH v6 8/8] block: convert block drivers linked with libs to modules Fam Zheng
2013-09-11 15:41 ` Daniel P. Berrange
2013-09-12 2:07 ` Fam Zheng
2013-09-11 16:26 ` [Qemu-devel] [PATCH v6 0/8] Shared Library Module Support Peter Maydell
2013-09-12 3:08 ` 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=1378906448-15834-5-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=pbonzini@redhat.com \
--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 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).