From nobody Wed Nov 5 14:35:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534873334626808.6346812288175; Tue, 21 Aug 2018 10:42:14 -0700 (PDT) Received: from localhost ([::1]:55146 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsAfV-000582-Fv for importer@patchew.org; Tue, 21 Aug 2018 13:42:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33687) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsA4h-0002C1-Eb for qemu-devel@nongnu.org; Tue, 21 Aug 2018 13:04:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fsA4W-0006pN-Qo for qemu-devel@nongnu.org; Tue, 21 Aug 2018 13:04:05 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:36375) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fsA4V-0006h5-Rd for qemu-devel@nongnu.org; Tue, 21 Aug 2018 13:04:00 -0400 Received: by mail-wr1-x42a.google.com with SMTP id m27-v6so10236161wrf.3 for ; Tue, 21 Aug 2018 10:03:57 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id v6-v6sm2608955wmc.43.2018.08.21.10.03.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Aug 2018 10:03:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e+AVb+CjmVXzZVKiSiFYCADawkt5crQpWTQUtZGCNtg=; b=nrwGxrPEG9pGC56OwBxsZwCr7cWIZPCHCleZCxoeCgJwnZgMSvod46kxGsWeQEQylv FV/hwD5VdJfN2fnHmYYT+1A+rHgXYK+b6ybcx+PiDFuxvCDPLXz1WuFSzVds3oneHcDN 3LRPWXkyPHc194wgT4luW0rK3NDFUe9eV75UfKmiASRskxYHjQ6/kEFTTywW1NmneHjp csGljbppTkQe15pPj7iBWtV8TalcZh3P4TgAjHrwldl4FXJSI95ISKuXrfrb+8pfn/9E whSu+giyaWy7NGSmcg1EM1bxd+vAhwtatxUj9ldpdZ7amnKHScWY+PXaMdfgfOcoPOfQ uufw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=e+AVb+CjmVXzZVKiSiFYCADawkt5crQpWTQUtZGCNtg=; b=Q1ccKyjx5oCZNwZUX6e+W7Z6fCCWJeWL9h00iGYLko5632Siw5JraNQJBwp5rQx9aK ezqEIn975f1aScJFciALwCztQc1nE6u3Jz6kvNvqLj4FAkn+dMlcwJ7wzhFglO2yfII8 gcmETLKpE7uiiRctkfk14XSdcY1b9FtFiQAgFVG55AC8ROOPApQtrH0lFYgfKsNDgosq c+e9D6Xfv0L6TwZsU4zVnTjUSsgaNPs4nE8enEr5vozzbEqrusJbVdzZsYY151MgYsr/ driU3mQUBWaroO+3kIhgJwKQZ0Xh8L6j7LWJ9W2A1N2MspOXcXemo3Wb7PIpBRn/KG2S goYg== X-Gm-Message-State: APzg51A/vqaNg/pgcZuJlqX9w9TTXQMSR42jFUBvELxvmQCW198apxy7 cITyv/FsuGt2/9m/ee5cS1RJrDQB X-Google-Smtp-Source: ANB0VdZfhQd6qVkvG3UB14z9R/We1tF4P1tOuCE3oINrBERkIkkekU68r/43Vsvdv3bmAS7WBzu6qw== X-Received: by 2002:adf:a292:: with SMTP id s18-v6mr8814209wra.100.1534871036356; Tue, 21 Aug 2018 10:03:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 21 Aug 2018 19:02:21 +0200 Message-Id: <1534870966-9287-50-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1534870966-9287-1-git-send-email-pbonzini@redhat.com> References: <1534870966-9287-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42a Subject: [Qemu-devel] [PULL 49/74] module: Use QEMU_MODULE_DIR as a search path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ryang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 From: ryang The current paths for modules are CONFIG_QEMU_MODDIR and paths relative to the executable. Qemu and its modules can be installed and executed in paths that are different from these search paths. This change allows a search path to be specified by environment variable. An example usage for this is postmarketOS[1]. This is a build environment for Alpine Linux. It sets up Alpine Linux in a 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 provides. 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/ Alpine's Qemu is installed at ~/.local/var/pmbootstrap/chroot_native/usr/bin/ The Qemu module search path needs to be: QEMU_MODULE_DIR=3D~/.local/var/pmbootstrap/chroot_native/usr/lib/qemu/ [1] https://postmarketos.org/ Signed-off-by: ryang Message-Id: <20180704181010.GA918@computer> Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Fam Zheng Signed-off-by: Paolo Bonzini --- util/module.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/util/module.c b/util/module.c index c909737..1259dd3 100644 --- a/util/module.c +++ b/util/module.c @@ -162,9 +162,10 @@ void module_load_one(const char *prefix, const char *l= ib_name) #ifdef CONFIG_MODULES char *fname =3D NULL; char *exec_dir; - char *dirs[3]; + const char *search_dir; + char *dirs[4]; char *module_name; - int i =3D 0; + int i =3D 0, n_dirs =3D 0; int ret; static GHashTable *loaded_modules; =20 @@ -186,14 +187,19 @@ void module_load_one(const char *prefix, const char *= lib_name) g_hash_table_insert(loaded_modules, module_name, module_name); =20 exec_dir =3D qemu_get_exec_dir(); - dirs[i++] =3D g_strdup_printf("%s", CONFIG_QEMU_MODDIR); - dirs[i++] =3D g_strdup_printf("%s/..", exec_dir ? : ""); - dirs[i++] =3D g_strdup_printf("%s", exec_dir ? : ""); - assert(i =3D=3D ARRAY_SIZE(dirs)); + search_dir =3D getenv("QEMU_MODULE_DIR"); + if (search_dir !=3D NULL) { + dirs[n_dirs++] =3D g_strdup_printf("%s", search_dir); + } + dirs[n_dirs++] =3D g_strdup_printf("%s", CONFIG_QEMU_MODDIR); + dirs[n_dirs++] =3D g_strdup_printf("%s/..", exec_dir ? : ""); + dirs[n_dirs++] =3D g_strdup_printf("%s", exec_dir ? : ""); + assert(n_dirs <=3D ARRAY_SIZE(dirs)); + g_free(exec_dir); exec_dir =3D NULL; =20 - for (i =3D 0; i < ARRAY_SIZE(dirs); i++) { + for (i =3D 0; i < n_dirs; i++) { fname =3D g_strdup_printf("%s/%s%s", dirs[i], module_name, HOST_DSOSUF); ret =3D module_load_file(fname); @@ -205,7 +211,7 @@ void module_load_one(const char *prefix, const char *li= b_name) } } =20 - for (i =3D 0; i < ARRAY_SIZE(dirs); i++) { + for (i =3D 0; i < n_dirs; i++) { g_free(dirs[i]); } =20 --=20 1.8.3.1