From patchwork Tue Sep 10 01:02:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 273741 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EF6BD2C00EF for ; Tue, 10 Sep 2013 11:05:13 +1000 (EST) Received: from localhost ([::1]:54282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJCOF-0001O1-Gn for incoming@patchwork.ozlabs.org; Mon, 09 Sep 2013 21:05:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33062) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJCMa-0007Jr-59 for qemu-devel@nongnu.org; Mon, 09 Sep 2013 21:03:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJCMU-0006Bl-3c for qemu-devel@nongnu.org; Mon, 09 Sep 2013 21:03:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8292) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJCMT-0006BM-L3 for qemu-devel@nongnu.org; Mon, 09 Sep 2013 21:03:22 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8A13Iat024773 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 9 Sep 2013 21:03:18 -0400 Received: from T430s.nay.redhat.com ([10.66.5.155]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r8A12xP5015290; Mon, 9 Sep 2013 21:03:15 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 10 Sep 2013 09:02:57 +0800 Message-Id: <1378774978-22602-5-git-send-email-famz@redhat.com> In-Reply-To: <1378774978-22602-1-git-send-email-famz@redhat.com> References: <1378774978-22602-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 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] [RFC PATCH v3 4/5] module: implement module loading function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 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 +#include #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);