From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, mjt@tls.msk.ru, famz@redhat.com,
stefanha@redhat.com
Subject: [Qemu-devel] [RFC PATCH 5/6] module: load modules at start
Date: Thu, 5 Sep 2013 18:20:47 +0800 [thread overview]
Message-ID: <1378376448-29036-6-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1378376448-29036-1-git-send-email-famz@redhat.com>
Add module_load_all to load all DSO modules under:
/usr/lib/qemu/block/
/usr/lib/qemu/net/
/usr/lib/qemu/ui/
when starting process.
Requires gmodule-2.0 from glib.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
configure | 20 +++++++++++---------
include/qemu/module.h | 2 ++
qemu-img.c | 2 ++
qemu-io.c | 1 +
qemu-nbd.c | 1 +
scripts/create_config | 3 +++
util/Makefile.objs | 2 ++
util/module.c | 40 ++++++++++++++++++++++++++++++++++++++++
vl.c | 1 +
9 files changed, 63 insertions(+), 9 deletions(-)
diff --git a/configure b/configure
index 8f0a882..975853e 100755
--- a/configure
+++ b/configure
@@ -2238,15 +2238,17 @@ if test "$mingw32" = yes; then
else
glib_req_ver=2.12
fi
-if $pkg_config --atleast-version=$glib_req_ver gthread-2.0 > /dev/null 2>&1
-then
- glib_cflags=`$pkg_config --cflags gthread-2.0 2>/dev/null`
- glib_libs=`$pkg_config --libs gthread-2.0 2>/dev/null`
- 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 > /dev/null 2>&1
+ then
+ glib_cflags=`$pkg_config --cflags $i 2>/dev/null`
+ glib_libs=`$pkg_config --libs $i 2>/dev/null`
+ 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..d3500be 100644
--- a/include/qemu/module.h
+++ b/include/qemu/module.h
@@ -37,4 +37,6 @@ void register_module_init(void (*fn)(void), module_init_type type);
void module_call_init(module_init_type type);
+void module_load_all(void);
+
#endif
diff --git a/qemu-img.c b/qemu-img.c
index b9a848d..e761027 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -34,6 +34,7 @@
#include <getopt.h>
#include <stdio.h>
#include <stdarg.h>
+#include "qemu/module.h"
#ifdef _WIN32
#include <windows.h>
@@ -2328,6 +2329,7 @@ int main(int argc, char **argv)
error_set_progname(argv[0]);
+ module_load_all();
qemu_init_main_loop();
bdrv_init();
if (argc < 2)
diff --git a/qemu-io.c b/qemu-io.c
index d54dc86..d02e8f5 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -398,6 +398,7 @@ int main(int argc, char **argv)
exit(1);
}
+ module_load_all();
qemu_init_main_loop();
bdrv_init();
diff --git a/qemu-nbd.c b/qemu-nbd.c
index f044546..ecea543 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -558,6 +558,7 @@ int main(int argc, char **argv)
snprintf(sockpath, 128, SOCKET_PATH, basename(device));
}
+ module_load_all();
qemu_init_main_loop();
bdrv_init();
atexit(bdrv_close_all);
diff --git a/scripts/create_config b/scripts/create_config
index b1adbf5..3ecb789 100755
--- a/scripts/create_config
+++ b/scripts/create_config
@@ -104,6 +104,9 @@ case $line in
value=${line#*=}
echo "#define $name $value"
;;
+ DSOSUF=*)
+ echo "#define HOST_DSOSUF \"${line#*=}\""
+ ;;
esac
done # read
diff --git a/util/Makefile.objs b/util/Makefile.objs
index dc72ab0..33e56b0 100644
--- a/util/Makefile.objs
+++ b/util/Makefile.objs
@@ -11,3 +11,5 @@ util-obj-y += iov.o aes.o qemu-config.o qemu-sockets.o uri.o notify.o
util-obj-y += qemu-option.o qemu-progress.o
util-obj-y += hexdump.o
util-obj-y += crc32c.o
+
+$(obj)/module.o-libs := -lglib
diff --git a/util/module.c b/util/module.c
index 7acc33d..29d3a4f 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,41 @@ void module_call_init(module_init_type type)
e->init();
}
}
+
+void module_load_all(void)
+{
+ static const char *module_dir_list[] = {
+ "/usr/lib/qemu/block/",
+ "/usr/lib/qemu/net/",
+ "/usr/lib/qemu/ui/",
+ NULL
+ };
+ const char **path;
+ const char *dsosuf = HOST_DSOSUF;
+ char fname[1024];
+ int suf_len = strlen(dsosuf);
+ DIR *dp;
+ struct dirent *ep = NULL;
+ GModule *g_module;
+ for (path = &module_dir_list[0]; *path != NULL; path++) {
+ dp = opendir(*path);
+ if (!dp) {
+ fprintf(stderr, "Failed to open dir %s\n", *path);
+ }
+ 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)) {
+ pstrcpy(fname, sizeof(fname), *path);
+ pstrcat(fname, sizeof(fname), ep->d_name);
+ g_module = g_module_open(fname, G_MODULE_BIND_LAZY);
+ if (!g_module) {
+ fprintf(stderr, "Failed to open module file %s\n",
+ g_module_error());
+ continue;
+ }
+ printf("Loaded module %s\n", fname);
+ }
+ }
+ }
+}
diff --git a/vl.c b/vl.c
index dfbc071..c72e5a8 100644
--- a/vl.c
+++ b/vl.c
@@ -3873,6 +3873,7 @@ int main(int argc, char **argv, char **envp)
}
loc_set_none();
+ module_load_all();
if (qemu_init_main_loop()) {
fprintf(stderr, "qemu_init_main_loop failed\n");
exit(1);
--
1.8.3.1
next prev parent reply other threads:[~2013-09-05 10:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-05 10:20 [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support Fam Zheng
2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 1/6] make.rule: fix $(obj) to a real relative path Fam Zheng
2013-09-06 9:41 ` Paolo Bonzini
2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 2/6] rule.mak: allow per object cflags and libs Fam Zheng
2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 3/6] Makefile: define curl cflags and libs with object Fam Zheng
2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 4/6] Makefile: introduce common-obj-m and block-obj-m for DSO Fam Zheng
2013-09-05 19:24 ` Richard Henderson
2013-09-05 19:41 ` Paolo Bonzini
2013-09-05 21:45 ` Peter Maydell
2013-09-06 8:26 ` Paolo Bonzini
2013-09-06 5:53 ` Fam Zheng
2013-09-06 7:20 ` Richard Henderson
2013-09-06 7:27 ` Fam Zheng
2013-09-05 10:20 ` Fam Zheng [this message]
2013-09-05 11:43 ` [Qemu-devel] [RFC PATCH 5/6] module: load modules at start Lluís Vilanova
2013-09-06 6:33 ` Fam Zheng
2013-09-05 11:49 ` Michael Tokarev
2013-09-05 10:20 ` [Qemu-devel] [RFC PATCH 6/6] curl: build as shared library Fam Zheng
2013-09-05 10:25 ` [Qemu-devel] [RFC PATCH 0/6] Shared Library Module Support 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=1378376448-29036-6-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=pbonzini@redhat.com \
--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).