main/qemu: Load modules from QEMU_MODULE_PATH env variable

This commit is contained in:
ryang 2018-06-30 10:28:14 -04:00
parent 1be6257820
commit a1c77ff5f9
2 changed files with 88 additions and 1 deletions

View File

@ -0,0 +1,85 @@
From 5bf8d0efa7e02f26dfa08ac68b2d62021bfc3fda Mon Sep 17 00:00:00 2001
From: ryang <decatf@gmail.com>
Date: Thu, 28 Jun 2018 13:22:50 -0400
Subject: [PATCH] module: Use QEMU_MODULE_PATH as a search path
The current paths for modules are CONFIG_QEMU_MODDIR and paths relative
to the executable. Qemu and its modules can be installed / executed in
paths that are different from the current search paths. This change allows
a search path to be specified by environment variable.
An example usage for this is postmarketOS. This is a build environment for
Alpine Linux. It sets up an Alpine Linux chroot environment. Alpine's Qemu
packages are installed in the chroot. The Alpine Linux Qemu package is used
to test compiled Alpine Linux system images. This way there isn't a
reliance on the which ever version of Qemu the host system / distro
might provide.
postmarketOS executes Qemu on host system outside of the chroot
The Qemu module search path needs to point to the location of the
chroot relative to the host system.
e.g.
The root of the Alpine Linux chroot is:
~/.local/var/pmbootstrap/chroot_native/
The Qemu module search path needs to be:
QEMU_MODULE_PATH=~/.local/var/pmbootstrap/chroot_native/usr/lib/qemu/
Signed-off-by: ryang <decatf@gmail.com>
---
util/module.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/util/module.c b/util/module.c
index c909737..f9088a5 100644
--- a/util/module.c
+++ b/util/module.c
@@ -162,9 +162,10 @@ void module_load_one(const char *prefix, const char *lib_name)
#ifdef CONFIG_MODULES
char *fname = NULL;
char *exec_dir;
- char *dirs[3];
+ char *search_path;
+ char *dirs[4];
char *module_name;
- int i = 0;
+ int i = 0, n_dirs;
int ret;
static GHashTable *loaded_modules;
@@ -186,14 +187,18 @@ void module_load_one(const char *prefix, const char *lib_name)
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 ? : "");
- dirs[i++] = g_strdup_printf("%s", exec_dir ? : "");
- assert(i == ARRAY_SIZE(dirs));
+ search_path = getenv("QEMU_MODULE_PATH");
+ if (search_path != NULL)
+ dirs[n_dirs++] = g_strdup_printf("%s", search_path);
+ dirs[n_dirs++] = g_strdup_printf("%s", CONFIG_QEMU_MODDIR);
+ dirs[n_dirs++] = g_strdup_printf("%s/..", exec_dir ? : "");
+ dirs[n_dirs++] = g_strdup_printf("%s", exec_dir ? : "");
+ assert(n_dirs <= ARRAY_SIZE(dirs));
+
g_free(exec_dir);
exec_dir = NULL;
- for (i = 0; i < ARRAY_SIZE(dirs); i++) {
+ for (i = 0; i < n_dirs; i++) {
fname = g_strdup_printf("%s/%s%s",
dirs[i], module_name, HOST_DSOSUF);
ret = module_load_file(fname);
@@ -205,7 +210,7 @@ void module_load_one(const char *prefix, const char *lib_name)
}
}
- for (i = 0; i < ARRAY_SIZE(dirs); i++) {
+ for (i = 0; i < n_dirs; i++) {
g_free(dirs[i]);
}
--
2.7.4

View File

@ -1,6 +1,6 @@
pkgname=qemu pkgname=qemu
pkgver=2.12.0 pkgver=2.12.0
pkgrel=4 pkgrel=5
pkgdesc="QEMU is a generic machine emulator and virtualizer" pkgdesc="QEMU is a generic machine emulator and virtualizer"
url="http://qemu.org/" url="http://qemu.org/"
arch="all" arch="all"
@ -156,6 +156,7 @@ source="http://wiki.qemu-project.org/download/$pkgname-$pkgver.tar.xz
fix-sockios-header.patch fix-sockios-header.patch
test-crypto-ivgen-skip-essiv.patch test-crypto-ivgen-skip-essiv.patch
0001-ui-add-x_keymap.o-to-modules.patch 0001-ui-add-x_keymap.o-to-modules.patch
0001-module-Use-QEMU_MODULE_PATH-as-a-search-path.patch
$pkgname-guest-agent.confd $pkgname-guest-agent.confd
$pkgname-guest-agent.initd $pkgname-guest-agent.initd
@ -396,6 +397,7 @@ d8933df9484158c2b4888254e62117d78f8ed7c18527b249419f39c2b2ab1afa148010884b40661f
39590476a4ebd7c1e79a4f0451b24c75b1817a2a83abaa1f71bb60b225d772152f0af8f3e51ff65645e378c536ffa6ff551dade52884d03a14b7c6a19c5c97d4 fix-sockios-header.patch 39590476a4ebd7c1e79a4f0451b24c75b1817a2a83abaa1f71bb60b225d772152f0af8f3e51ff65645e378c536ffa6ff551dade52884d03a14b7c6a19c5c97d4 fix-sockios-header.patch
8b8db136f78bd26b5da171effa9e11016ec2bc3e2fc8107228b5543b47aa370978ed883794aa4f917f334e284a5b49e82070e1da2d31d49301195b6713a48eff test-crypto-ivgen-skip-essiv.patch 8b8db136f78bd26b5da171effa9e11016ec2bc3e2fc8107228b5543b47aa370978ed883794aa4f917f334e284a5b49e82070e1da2d31d49301195b6713a48eff test-crypto-ivgen-skip-essiv.patch
e052ece28af1e7a81828322999b6f1ff5c030c717a897fe80ea04d5ba7f9d477786d91cfbf2eb3444c46b1bc8d3b72a771c26c819bc3ecfd216dd02b6567796e 0001-ui-add-x_keymap.o-to-modules.patch e052ece28af1e7a81828322999b6f1ff5c030c717a897fe80ea04d5ba7f9d477786d91cfbf2eb3444c46b1bc8d3b72a771c26c819bc3ecfd216dd02b6567796e 0001-ui-add-x_keymap.o-to-modules.patch
320ecf95274ed42402fd0e6e1779906abea36891945888649ae4df80a7021cf4c7a6f96a3bb525103ecbf3193300a11484f523c2acb6ddbf2504374171853de2 0001-module-Use-QEMU_MODULE_PATH-as-a-search-path.patch
d90c034cae3f9097466854ed1a9f32ab4b02089fcdf7320e8f4da13b2b1ff65067233f48809911485e4431d7ec1a22448b934121bc9522a2dc489009e87e2b1f qemu-guest-agent.confd d90c034cae3f9097466854ed1a9f32ab4b02089fcdf7320e8f4da13b2b1ff65067233f48809911485e4431d7ec1a22448b934121bc9522a2dc489009e87e2b1f qemu-guest-agent.confd
1cd24c2444c5935a763c501af2b0da31635aad9cf62e55416d6477fcec153cddbe7de205d99616def11b085e0dd366ba22463d2270f831d884edbc307c7864a6 qemu-guest-agent.initd 1cd24c2444c5935a763c501af2b0da31635aad9cf62e55416d6477fcec153cddbe7de205d99616def11b085e0dd366ba22463d2270f831d884edbc307c7864a6 qemu-guest-agent.initd
9b7a89b20fcf737832cb7b4d5dc7d8301dd88169cbe5339eda69fbb51c2e537d8cb9ec7cf37600899e734209e63410d50d0821bce97e401421db39c294d97be2 80-kvm.rules 9b7a89b20fcf737832cb7b4d5dc7d8301dd88169cbe5339eda69fbb51c2e537d8cb9ec7cf37600899e734209e63410d50d0821bce97e401421db39c294d97be2 80-kvm.rules