All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v8 0/4] cutils: Introduce bundle mechanism
@ 2022-06-24 14:50 Akihiko Odaki
  2022-06-24 14:50 ` [PATCH v8 1/4] tests/vm: do not specify -bios option Akihiko Odaki
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Akihiko Odaki @ 2022-06-24 14:50 UTC (permalink / raw)
  Cc: Peter Maydell, Jason Wang, qemu-devel, Programmingkid,
	Philippe Mathieu-Daudé,
	Gerd Hoffmann, Daniel P . Berrangé,
	Paolo Bonzini, Alex Bennée, Thomas Huth, John Snow,
	Cleber Rosa, Stefan Weil, Akihiko Odaki

Developers often run QEMU without installing. The bundle mechanism
allows to look up files which should be present in installation even in
such a situation.

It is a general mechanism and can find any files located relative
to the installation tree. The build tree must have a new directory,
qemu-bundle, to represent what files the installation tree would
have for reference by the executables.

Note that this abandons compatibility with Windows older than 8 to use
PathCchSkipRoot(). The extended support for the prior version, 7 ended
more than 2 years ago, and it is unlikely that anyone would like to run
the latest QEMU on such an old system.

v8:
* Pass absolute paths to get_relocated_path() (Paolo Bonzini)
* Use meson introspection (Paolo Bonzini)
* Drop "qga: Relocate a path emitted in the help text" as it is no longer
  relevant for the bundle mechanism.

v7: Properly fix --firmwarepath (Daniel P. Berrangé)

v6: Reuse get_relocated_path() in find_bundle() (Paolo Bonzini)

v5:
* Prefer qemu-bundle if it exists. (Daniel P. Berrangé)
* Check install_blobs option before installing BIOSes (Paolo Bonzini)
* Add common code to set up qemu-bundle to the top level meson.build
  (Paolo Bonzini)

v4:
* Add Daniel P. Berrangé to CC. Hopefully this helps merging his patch:
  https://mail.gnu.org/archive/html/qemu-devel/2022-06/msg02276.html
* Rebased to the latest QEMU.

v3:
* Note that the bundle mechanism is for any files located relative to the
  installation tree including but not limited to datadir. (Peter Maydell)
* Fix "bridge" typo (Philippe Mathieu-Daudé)

v2: Rebased to the latest QEMU.

Akihiko Odaki (3):
  cutils: Introduce bundle mechanism
  datadir: Use bundle mechanism
  module: Use bundle mechanism

Paolo Bonzini (1):
  tests/vm: do not specify -bios option

 .travis.yml                     |  2 +-
 docs/about/build-platforms.rst  |  2 +-
 include/qemu/cutils.h           | 18 +++++++--
 meson.build                     |  4 ++
 pc-bios/keymaps/meson.build     | 21 +++-------
 pc-bios/meson.build             | 13 ++-----
 scripts/oss-fuzz/build.sh       |  2 +-
 scripts/symlink-install-tree.py | 37 ++++++++++++++++++
 softmmu/datadir.c               | 22 +----------
 tests/qtest/fuzz/fuzz.c         | 15 --------
 tests/vm/fedora                 |  1 -
 tests/vm/freebsd                |  1 -
 tests/vm/netbsd                 |  1 -
 tests/vm/openbsd                |  1 -
 util/cutils.c                   | 68 +++++++++++++++++++++++----------
 util/meson.build                |  1 +
 util/module.c                   |  1 -
 17 files changed, 117 insertions(+), 93 deletions(-)
 create mode 100755 scripts/symlink-install-tree.py

-- 
2.32.1 (Apple Git-133)



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v8 1/4] tests/vm: do not specify -bios option
  2022-06-24 14:50 [PATCH v8 0/4] cutils: Introduce bundle mechanism Akihiko Odaki
@ 2022-06-24 14:50 ` Akihiko Odaki
  2022-06-24 14:50 ` [PATCH v8 2/4] cutils: Introduce bundle mechanism Akihiko Odaki
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Akihiko Odaki @ 2022-06-24 14:50 UTC (permalink / raw)
  Cc: Peter Maydell, Jason Wang, qemu-devel, Programmingkid,
	Philippe Mathieu-Daudé,
	Gerd Hoffmann, Daniel P . Berrangé,
	Paolo Bonzini, Alex Bennée, Thomas Huth, John Snow,
	Cleber Rosa, Stefan Weil, Akihiko Odaki

From: Paolo Bonzini <pbonzini@redhat.com>

When running from the build tree, the executable is able to find
the BIOS on its own; when running from the source tree, a firmware
blob should already be installed and there is no guarantee that
the one in the source tree works with the QEMU that is being used for
the installation.

Just remove the -bios option, since it is unnecessary and in fact
there are other x86 VM tests that do not bother specifying it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Message-Id: <20220616083025.116902-1-pbonzini@redhat.com>
---
 tests/vm/fedora  | 1 -
 tests/vm/freebsd | 1 -
 tests/vm/netbsd  | 1 -
 tests/vm/openbsd | 1 -
 4 files changed, 4 deletions(-)

diff --git a/tests/vm/fedora b/tests/vm/fedora
index 92b78d6e2c9..12eca919a08 100755
--- a/tests/vm/fedora
+++ b/tests/vm/fedora
@@ -79,7 +79,6 @@ class FedoraVM(basevm.BaseVM):
         self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size)
         self.print_step("Booting installer")
         self.boot(img_tmp, extra_args = [
-            "-bios", "pc-bios/bios-256k.bin",
             "-machine", "graphics=off",
             "-device", "VGA",
             "-cdrom", iso
diff --git a/tests/vm/freebsd b/tests/vm/freebsd
index 805db759d67..cd1fabde523 100755
--- a/tests/vm/freebsd
+++ b/tests/vm/freebsd
@@ -95,7 +95,6 @@ class FreeBSDVM(basevm.BaseVM):
 
         self.print_step("Booting installer")
         self.boot(img_tmp, extra_args = [
-            "-bios", "pc-bios/bios-256k.bin",
             "-machine", "graphics=off",
             "-device", "VGA",
             "-cdrom", iso
diff --git a/tests/vm/netbsd b/tests/vm/netbsd
index 45aa9a7fda7..aa883ec23c9 100755
--- a/tests/vm/netbsd
+++ b/tests/vm/netbsd
@@ -86,7 +86,6 @@ class NetBSDVM(basevm.BaseVM):
 
         self.print_step("Booting installer")
         self.boot(img_tmp, extra_args = [
-            "-bios", "pc-bios/bios-256k.bin",
             "-machine", "graphics=off",
             "-cdrom", iso
         ])
diff --git a/tests/vm/openbsd b/tests/vm/openbsd
index 13c82542140..6f1b6f5b98a 100755
--- a/tests/vm/openbsd
+++ b/tests/vm/openbsd
@@ -82,7 +82,6 @@ class OpenBSDVM(basevm.BaseVM):
 
         self.print_step("Booting installer")
         self.boot(img_tmp, extra_args = [
-            "-bios", "pc-bios/bios-256k.bin",
             "-machine", "graphics=off",
             "-device", "VGA",
             "-cdrom", iso
-- 
2.32.1 (Apple Git-133)



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v8 2/4] cutils: Introduce bundle mechanism
  2022-06-24 14:50 [PATCH v8 0/4] cutils: Introduce bundle mechanism Akihiko Odaki
  2022-06-24 14:50 ` [PATCH v8 1/4] tests/vm: do not specify -bios option Akihiko Odaki
@ 2022-06-24 14:50 ` Akihiko Odaki
  2022-06-24 15:26   ` Thomas Huth
  2022-06-24 14:50 ` [PATCH v8 3/4] datadir: Use " Akihiko Odaki
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Akihiko Odaki @ 2022-06-24 14:50 UTC (permalink / raw)
  Cc: Peter Maydell, Jason Wang, qemu-devel, Programmingkid,
	Philippe Mathieu-Daudé,
	Gerd Hoffmann, Daniel P . Berrangé,
	Paolo Bonzini, Alex Bennée, Thomas Huth, John Snow,
	Cleber Rosa, Stefan Weil, Akihiko Odaki

Developers often run QEMU without installing. The bundle mechanism
allows to look up files which should be present in installation even in
such a situation.

It is a general mechanism and can find any files in the installation
tree. The build tree will have a new directory, qemu-bundle, to
represent what files the installation tree would have for reference by
the executables.

Note that it abandons compatibility with Windows older than 8. The
extended support for the prior version, 7 ended more than 2 years ago,
and it is unlikely that someone would like to run the latest QEMU on
such an old system.

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
---
 docs/about/build-platforms.rst  |  2 +-
 include/qemu/cutils.h           | 18 +++++++--
 meson.build                     |  4 ++
 scripts/symlink-install-tree.py | 37 ++++++++++++++++++
 util/cutils.c                   | 68 +++++++++++++++++++++++----------
 util/meson.build                |  1 +
 6 files changed, 105 insertions(+), 25 deletions(-)
 create mode 100755 scripts/symlink-install-tree.py

diff --git a/docs/about/build-platforms.rst b/docs/about/build-platforms.rst
index 1958edb4305..ebde20f9815 100644
--- a/docs/about/build-platforms.rst
+++ b/docs/about/build-platforms.rst
@@ -88,7 +88,7 @@ Windows
 
 The project aims to support the two most recent versions of Windows that are
 still supported by the vendor. The minimum Windows API that is currently
-targeted is "Windows 7", so theoretically the QEMU binaries can still be run
+targeted is "Windows 8", so theoretically the QEMU binaries can still be run
 on older versions of Windows, too. However, such old versions of Windows are
 not tested anymore, so it is recommended to use one of the latest versions of
 Windows instead.
diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index d3e532b64c8..92c436d8c70 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -224,9 +224,21 @@ const char *qemu_get_exec_dir(void);
  * @dir: the directory (typically a `CONFIG_*DIR` variable) to be relocated.
  *
  * Returns a path for @dir that uses the directory of the running executable
- * as the prefix.  For example, if `bindir` is `/usr/bin` and @dir is
- * `/usr/share/qemu`, the function will append `../share/qemu` to the
- * directory that contains the running executable and return the result.
+ * as the prefix.
+ *
+ * When a directory named `qemu-bundle` exists in the directory of the running
+ * executable, the path to the directory will be prepended to @dir. For
+ * example, if the directory of the running executable is `/qemu/build` @dir
+ * is `/usr/share/qemu`, the result will be
+ * `/qemu/build/qemu-bundle/usr/share/qemu`. The directory is expected to exist
+ * in the build tree.
+ *
+ * Otherwise, the directory of the running executable will be used as the
+ * prefix and it appends the relative path from `bindir` to @dir. For example,
+ * if the directory of the running executable is `/opt/qemu/bin`, `bindir` is
+ * `/usr/bin` and @dir is `/usr/share/qemu`, the result will be
+ * `/opt/qemu/bin/../share/qemu`.
+ *
  * The returned string should be freed by the caller.
  */
 char *get_relocated_path(const char *dir);
diff --git a/meson.build b/meson.build
index 9efcb175d16..c49f5ebfc37 100644
--- a/meson.build
+++ b/meson.build
@@ -7,6 +7,8 @@ add_test_setup('quick', exclude_suites: ['slow', 'thorough'], is_default: true)
 add_test_setup('slow', exclude_suites: ['thorough'], env: ['G_TEST_SLOW=1', 'SPEED=slow'])
 add_test_setup('thorough', env: ['G_TEST_SLOW=1', 'SPEED=thorough'])
 
+meson.add_postconf_script('scripts/symlink-install-tree.py')
+
 not_found = dependency('', required: false)
 keyval = import('keyval')
 ss = import('sourceset')
@@ -356,10 +358,12 @@ nvmm =not_found
 hvf = not_found
 midl = not_found
 widl = not_found
+pathcch = not_found
 host_dsosuf = '.so'
 if targetos == 'windows'
   midl = find_program('midl', required: false)
   widl = find_program('widl', required: false)
+  pathcch = cc.find_library('pathcch')
   socket = cc.find_library('ws2_32')
   winmm = cc.find_library('winmm')
 
diff --git a/scripts/symlink-install-tree.py b/scripts/symlink-install-tree.py
new file mode 100755
index 00000000000..f35aa176404
--- /dev/null
+++ b/scripts/symlink-install-tree.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+
+from pathlib import Path
+import errno
+import json
+import os
+import subprocess
+import sys
+
+def destdir_join(d1: str, d2: str) -> str:
+    if not d1:
+        return d2
+    d2_path = Path(d2)
+    d2_parts = d2_path.parts
+    # c:\destdir + c:\prefix must produce c:\destdir\prefix
+    if d2_path.drive or d2_path.root:
+        d2_parts = d2_parts[1:]
+    return str(Path(d1, *d2_parts))
+
+introspect = os.environ.get('MESONINTROSPECT')
+out = subprocess.run([*introspect.split(' '), '--installed'],
+                     stdout=subprocess.PIPE, check=True).stdout
+for source, dest in json.loads(out).items():
+    assert os.path.isabs(source)
+    bundle_dest = destdir_join('qemu-bundle', dest)
+    path = os.path.dirname(bundle_dest)
+    try:
+        os.makedirs(path, exist_ok=True)
+    except BaseException as e:
+        print(f'error making directory {path}', file=sys.stderr)
+        raise e
+    try:
+        os.symlink(source, bundle_dest)
+    except BaseException as e:
+        if not isinstance(e, OSError) or e.errno != errno.EEXIST:
+            print(f'error making symbolic link {dest}', file=sys.stderr)
+            raise e
diff --git a/util/cutils.c b/util/cutils.c
index 6d04e52907b..8199dac5988 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -35,6 +35,11 @@
 #include <sys/sysctl.h>
 #endif
 
+#ifdef G_OS_WIN32
+#include <pathcch.h>
+#include <wchar.h>
+#endif
+
 #include "qemu/ctype.h"
 #include "qemu/cutils.h"
 #include "qemu/error-report.h"
@@ -1074,31 +1079,52 @@ char *get_relocated_path(const char *dir)
 
     /* Fail if qemu_init_exec_dir was not called.  */
     assert(exec_dir[0]);
-    if (!starts_with_prefix(dir) || !starts_with_prefix(bindir)) {
-        return g_strdup(dir);
-    }
 
     result = g_string_new(exec_dir);
+    g_string_append(result, "/qemu-bundle");
+    if (access(result->str, R_OK) == 0) {
+#ifdef G_OS_WIN32
+        size_t size = mbsrtowcs(NULL, &dir, 0, &(mbstate_t){0}) + 1;
+        PWSTR wdir = g_new(WCHAR, size);
+        mbsrtowcs(wdir, &dir, size, &(mbstate_t){0});
+
+        PCWSTR wdir_skipped_root;
+        PathCchSkipRoot(wdir, &wdir_skipped_root);
+
+        size = wcsrtombs(NULL, &wdir_skipped_root, 0, &(mbstate_t){0});
+        char *cursor = result->str + result->len;
+        g_string_set_size(result, result->len + size);
+        wcsrtombs(cursor, &wdir_skipped_root, size + 1, &(mbstate_t){0});
+        g_free(wdir);
+#else
+        g_string_append(result, dir);
+#endif
+    } else if (!starts_with_prefix(dir) || !starts_with_prefix(bindir)) {
+        g_string_assign(result, dir);
+    } else {
+        g_string_assign(result, exec_dir);
+
+        /* Advance over common components.  */
+        len_dir = len_bindir = prefix_len;
+        do {
+            dir += len_dir;
+            bindir += len_bindir;
+            dir = next_component(dir, &len_dir);
+            bindir = next_component(bindir, &len_bindir);
+        } while (len_dir && len_dir == len_bindir && !memcmp(dir, bindir, len_dir));
+
+        /* Ascend from bindir to the common prefix with dir.  */
+        while (len_bindir) {
+            bindir += len_bindir;
+            g_string_append(result, "/..");
+            bindir = next_component(bindir, &len_bindir);
+        }
 
-    /* Advance over common components.  */
-    len_dir = len_bindir = prefix_len;
-    do {
-        dir += len_dir;
-        bindir += len_bindir;
-        dir = next_component(dir, &len_dir);
-        bindir = next_component(bindir, &len_bindir);
-    } while (len_dir && len_dir == len_bindir && !memcmp(dir, bindir, len_dir));
-
-    /* Ascend from bindir to the common prefix with dir.  */
-    while (len_bindir) {
-        bindir += len_bindir;
-        g_string_append(result, "/..");
-        bindir = next_component(bindir, &len_bindir);
+        if (*dir) {
+            assert(G_IS_DIR_SEPARATOR(dir[-1]));
+            g_string_append(result, dir - 1);
+        }
     }
 
-    if (*dir) {
-        assert(G_IS_DIR_SEPARATOR(dir[-1]));
-        g_string_append(result, dir - 1);
-    }
     return g_string_free(result, false);
 }
diff --git a/util/meson.build b/util/meson.build
index 8f16018cd43..6cacb8689f1 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -23,6 +23,7 @@ util_ss.add(when: 'CONFIG_WIN32', if_true: files('event_notifier-win32.c'))
 util_ss.add(when: 'CONFIG_WIN32', if_true: files('oslib-win32.c'))
 util_ss.add(when: 'CONFIG_WIN32', if_true: files('qemu-thread-win32.c'))
 util_ss.add(when: 'CONFIG_WIN32', if_true: winmm)
+util_ss.add(when: 'CONFIG_WIN32', if_true: pathcch)
 util_ss.add(files('envlist.c', 'path.c', 'module.c'))
 util_ss.add(files('host-utils.c'))
 util_ss.add(files('bitmap.c', 'bitops.c'))
-- 
2.32.1 (Apple Git-133)



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v8 3/4] datadir: Use bundle mechanism
  2022-06-24 14:50 [PATCH v8 0/4] cutils: Introduce bundle mechanism Akihiko Odaki
  2022-06-24 14:50 ` [PATCH v8 1/4] tests/vm: do not specify -bios option Akihiko Odaki
  2022-06-24 14:50 ` [PATCH v8 2/4] cutils: Introduce bundle mechanism Akihiko Odaki
@ 2022-06-24 14:50 ` Akihiko Odaki
  2022-06-24 14:50 ` [PATCH v8 4/4] module: " Akihiko Odaki
  2022-06-24 15:26 ` [PATCH v8 0/4] cutils: Introduce " Paolo Bonzini
  4 siblings, 0 replies; 8+ messages in thread
From: Akihiko Odaki @ 2022-06-24 14:50 UTC (permalink / raw)
  Cc: Peter Maydell, Jason Wang, qemu-devel, Programmingkid,
	Philippe Mathieu-Daudé,
	Gerd Hoffmann, Daniel P . Berrangé,
	Paolo Bonzini, Alex Bennée, Thomas Huth, John Snow,
	Cleber Rosa, Stefan Weil, Akihiko Odaki

softmmu/datadir.c had its own implementation to find files in the
build tree, but now bundle mechanism provides the unified
implementation which works for datadir and the other files.

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
---
 .travis.yml                 |  2 +-
 pc-bios/keymaps/meson.build | 21 ++++++---------------
 pc-bios/meson.build         | 13 +++----------
 scripts/oss-fuzz/build.sh   |  2 +-
 softmmu/datadir.c           | 22 +---------------------
 tests/qtest/fuzz/fuzz.c     | 15 ---------------
 6 files changed, 12 insertions(+), 63 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 9afc4a54b8f..4fdc9a67855 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -223,7 +223,7 @@ jobs:
         - BUILD_RC=0 && make -j${JOBS} || BUILD_RC=$?
         - |
           if [ "$BUILD_RC" -eq 0 ] ; then
-              mv pc-bios/s390-ccw/*.img pc-bios/ ;
+              mv pc-bios/s390-ccw/*.img qemu-bundle/usr/local/share/qemu ;
               ${TEST_CMD} ;
           else
               $(exit $BUILD_RC);
diff --git a/pc-bios/keymaps/meson.build b/pc-bios/keymaps/meson.build
index 44247a12b54..2837eb34f4e 100644
--- a/pc-bios/keymaps/meson.build
+++ b/pc-bios/keymaps/meson.build
@@ -40,9 +40,9 @@ else
 endif
 cp = find_program('cp')
 
-t = []
-foreach km, args: keymaps
-  if native_qemu_keymap.found()
+if native_qemu_keymap.found()
+  t = []
+  foreach km, args: keymaps
     # generate with qemu-kvm
     t += custom_target(km,
                        build_by_default: true,
@@ -50,20 +50,11 @@ foreach km, args: keymaps
                        command: [native_qemu_keymap, '-f', '@OUTPUT@', args.split()],
                        install: true,
                        install_dir: qemu_datadir / 'keymaps')
-  else
-    # copy from source tree
-    t += custom_target(km,
-                       build_by_default: true,
-                       input: km,
-                       output: km,
-                       command: [cp, '@INPUT@', '@OUTPUT@'],
-                       install: true,
-                       install_dir: qemu_datadir / 'keymaps')
-  endif
-endforeach
+  endforeach
 
-if native_qemu_keymap.found()
   alias_target('update-keymaps', t)
+else
+  install_data(keymaps.keys(), install_dir: qemu_datadir / 'keymaps')
 endif
 
 install_data(['sl', 'sv'], install_dir: qemu_datadir / 'keymaps')
diff --git a/pc-bios/meson.build b/pc-bios/meson.build
index 41ba1c0ec7b..388e0db6e40 100644
--- a/pc-bios/meson.build
+++ b/pc-bios/meson.build
@@ -85,16 +85,9 @@ blobs = [
   'vof-nvram.bin',
 ]
 
-ln_s = [find_program('ln', required: true), '-sf']
-foreach f : blobs
-  roms += custom_target(f,
-                build_by_default: have_system,
-                output: f,
-                input: files('meson.build'),            # dummy input
-                install: get_option('install_blobs'),
-                install_dir: qemu_datadir,
-                command: [ ln_s, meson.project_source_root() / 'pc-bios' / f, '@OUTPUT@' ])
-endforeach
+if get_option('install_blobs')
+  install_data(blobs, install_dir: qemu_datadir)
+endif
 
 subdir('descriptors')
 subdir('keymaps')
diff --git a/scripts/oss-fuzz/build.sh b/scripts/oss-fuzz/build.sh
index 98b56e05210..16316b25662 100755
--- a/scripts/oss-fuzz/build.sh
+++ b/scripts/oss-fuzz/build.sh
@@ -88,7 +88,7 @@ if [ "$GITLAB_CI" != "true" ]; then
 fi
 
 # Copy over the datadir
-cp  -r ../pc-bios/ "$DEST_DIR/pc-bios"
+cp  -r ../pc-bios/ "$DEST_DIR/data"
 
 targets=$(./qemu-fuzz-i386 | awk '$1 ~ /\*/  {print $2}')
 base_copy="$DEST_DIR/qemu-fuzz-i386-target-$(echo "$targets" | head -n 1)"
diff --git a/softmmu/datadir.c b/softmmu/datadir.c
index 160cac999a6..697cffea932 100644
--- a/softmmu/datadir.c
+++ b/softmmu/datadir.c
@@ -83,26 +83,6 @@ void qemu_add_data_dir(char *path)
     data_dir[data_dir_idx++] = path;
 }
 
-/*
- * Find a likely location for support files using the location of the binary.
- * When running from the build tree this will be "$bindir/pc-bios".
- * Otherwise, this is CONFIG_QEMU_DATADIR (possibly relocated).
- *
- * The caller must use g_free() to free the returned data when it is
- * no longer required.
- */
-static char *find_datadir(void)
-{
-    g_autofree char *dir = NULL;
-
-    dir = g_build_filename(qemu_get_exec_dir(), "pc-bios", NULL);
-    if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
-        return g_steal_pointer(&dir);
-    }
-
-    return get_relocated_path(CONFIG_QEMU_DATADIR);
-}
-
 void qemu_add_default_firmwarepath(void)
 {
     char **dirs;
@@ -116,7 +96,7 @@ void qemu_add_default_firmwarepath(void)
     g_strfreev(dirs);
 
     /* try to find datadir relative to the executable path */
-    qemu_add_data_dir(find_datadir());
+    qemu_add_data_dir(get_relocated_path(CONFIG_QEMU_DATADIR));
 }
 
 void qemu_list_data_dirs(void)
diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c
index 0ad4ba9e94d..2062b40d82b 100644
--- a/tests/qtest/fuzz/fuzz.c
+++ b/tests/qtest/fuzz/fuzz.c
@@ -174,21 +174,6 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)
     target_name = strstr(**argv, "-target-");
     if (target_name) {        /* The binary name specifies the target */
         target_name += strlen("-target-");
-        /*
-         * With oss-fuzz, the executable is kept in the root of a directory (we
-         * cannot assume the path). All data (including bios binaries) must be
-         * in the same dir, or a subdir. Thus, we cannot place the pc-bios so
-         * that it would be in exec_dir/../pc-bios.
-         * As a workaround, oss-fuzz allows us to use argv[0] to get the
-         * location of the executable. Using this we add exec_dir/pc-bios to
-         * the datadirs.
-         */
-        bindir = qemu_get_exec_dir();
-        datadir = g_build_filename(bindir, "pc-bios", NULL);
-        if (g_file_test(datadir, G_FILE_TEST_IS_DIR)) {
-            qemu_add_data_dir(datadir);
-        } else {
-            g_free(datadir);
 	}
     } else if (*argc > 1) {  /* The target is specified as an argument */
         target_name = (*argv)[1];
-- 
2.32.1 (Apple Git-133)



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v8 4/4] module: Use bundle mechanism
  2022-06-24 14:50 [PATCH v8 0/4] cutils: Introduce bundle mechanism Akihiko Odaki
                   ` (2 preceding siblings ...)
  2022-06-24 14:50 ` [PATCH v8 3/4] datadir: Use " Akihiko Odaki
@ 2022-06-24 14:50 ` Akihiko Odaki
  2022-06-24 15:26 ` [PATCH v8 0/4] cutils: Introduce " Paolo Bonzini
  4 siblings, 0 replies; 8+ messages in thread
From: Akihiko Odaki @ 2022-06-24 14:50 UTC (permalink / raw)
  Cc: Peter Maydell, Jason Wang, qemu-devel, Programmingkid,
	Philippe Mathieu-Daudé,
	Gerd Hoffmann, Daniel P . Berrangé,
	Paolo Bonzini, Alex Bennée, Thomas Huth, John Snow,
	Cleber Rosa, Stefan Weil, Akihiko Odaki

Before this change, the directory of the executable was being added to
resolve modules in the build tree. However, get_relocated_path() can now
resolve them with the new bundle mechanism.

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
---
 util/module.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/util/module.c b/util/module.c
index 6bb4ad915a1..8ddb0e18f51 100644
--- a/util/module.c
+++ b/util/module.c
@@ -274,7 +274,6 @@ bool module_load_one(const char *prefix, const char *lib_name, bool mayfail)
         dirs[n_dirs++] = g_strdup_printf("%s", search_dir);
     }
     dirs[n_dirs++] = get_relocated_path(CONFIG_QEMU_MODDIR);
-    dirs[n_dirs++] = g_strdup(qemu_get_exec_dir());
 
 #ifdef CONFIG_MODULE_UPGRADES
     version_dir = g_strcanon(g_strdup(QEMU_PKGVERSION),
-- 
2.32.1 (Apple Git-133)



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v8 2/4] cutils: Introduce bundle mechanism
  2022-06-24 14:50 ` [PATCH v8 2/4] cutils: Introduce bundle mechanism Akihiko Odaki
@ 2022-06-24 15:26   ` Thomas Huth
  0 siblings, 0 replies; 8+ messages in thread
From: Thomas Huth @ 2022-06-24 15:26 UTC (permalink / raw)
  To: Akihiko Odaki
  Cc: Peter Maydell, Jason Wang, qemu-devel, Programmingkid,
	Philippe Mathieu-Daudé,
	Gerd Hoffmann, Daniel P . Berrangé,
	Paolo Bonzini, Alex Bennée, John Snow, Cleber Rosa,
	Stefan Weil

On 24/06/2022 16.50, Akihiko Odaki wrote:
> Developers often run QEMU without installing. The bundle mechanism
> allows to look up files which should be present in installation even in
> such a situation.
> 
> It is a general mechanism and can find any files in the installation
> tree. The build tree will have a new directory, qemu-bundle, to
> represent what files the installation tree would have for reference by
> the executables.
> 
> Note that it abandons compatibility with Windows older than 8. The
> extended support for the prior version, 7 ended more than 2 years ago,
> and it is unlikely that someone would like to run the latest QEMU on
> such an old system.
> 
> Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   docs/about/build-platforms.rst  |  2 +-
>   include/qemu/cutils.h           | 18 +++++++--
>   meson.build                     |  4 ++
>   scripts/symlink-install-tree.py | 37 ++++++++++++++++++
>   util/cutils.c                   | 68 +++++++++++++++++++++++----------
>   util/meson.build                |  1 +
>   6 files changed, 105 insertions(+), 25 deletions(-)
>   create mode 100755 scripts/symlink-install-tree.py
> 
> diff --git a/docs/about/build-platforms.rst b/docs/about/build-platforms.rst
> index 1958edb4305..ebde20f9815 100644
> --- a/docs/about/build-platforms.rst
> +++ b/docs/about/build-platforms.rst
> @@ -88,7 +88,7 @@ Windows
>   
>   The project aims to support the two most recent versions of Windows that are
>   still supported by the vendor. The minimum Windows API that is currently
> -targeted is "Windows 7", so theoretically the QEMU binaries can still be run
> +targeted is "Windows 8", so theoretically the QEMU binaries can still be run
>   on older versions of Windows, too. However, such old versions of Windows are
>   not tested anymore, so it is recommended to use one of the latest versions of
>   Windows instead.

Please update _WIN32_WINNT in include/qemu/osdep.h accordingly.

Thanks,
  Thomas



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v8 0/4] cutils: Introduce bundle mechanism
  2022-06-24 14:50 [PATCH v8 0/4] cutils: Introduce bundle mechanism Akihiko Odaki
                   ` (3 preceding siblings ...)
  2022-06-24 14:50 ` [PATCH v8 4/4] module: " Akihiko Odaki
@ 2022-06-24 15:26 ` Paolo Bonzini
  2022-06-24 15:31   ` Akihiko Odaki
  4 siblings, 1 reply; 8+ messages in thread
From: Paolo Bonzini @ 2022-06-24 15:26 UTC (permalink / raw)
  To: Akihiko Odaki
  Cc: Peter Maydell, Jason Wang, qemu-devel, Programmingkid,
	Philippe Mathieu-Daudé,
	Gerd Hoffmann, Daniel P . Berrangé,
	Alex Bennée, Thomas Huth, John Snow, Cleber Rosa,
	Stefan Weil

On 6/24/22 16:50, Akihiko Odaki wrote:
> Developers often run QEMU without installing. The bundle mechanism
> allows to look up files which should be present in installation even in
> such a situation.
> 
> It is a general mechanism and can find any files located relative
> to the installation tree. The build tree must have a new directory,
> qemu-bundle, to represent what files the installation tree would
> have for reference by the executables.
> 
> Note that this abandons compatibility with Windows older than 8 to use
> PathCchSkipRoot(). The extended support for the prior version, 7 ended
> more than 2 years ago, and it is unlikely that anyone would like to run
> the latest QEMU on such an old system.

Thanks, this looks good.  Even though technically it adds more lines 
than it removes (thanks Windows...), it replaces lots of special cases 
with a single general mechanism, which is nice and future proof.

The only change I'd make (which I can do when queueing the patch) is to 
change the directory name to something "strange" like "=install", so 
that it's unlikely to have a directory named like that in the $bindir.

Any opinions?

Paolo

> v8:
> * Pass absolute paths to get_relocated_path() (Paolo Bonzini)
> * Use meson introspection (Paolo Bonzini)
> * Drop "qga: Relocate a path emitted in the help text" as it is no longer
>    relevant for the bundle mechanism.
> 
> v7: Properly fix --firmwarepath (Daniel P. Berrangé)
> 
> v6: Reuse get_relocated_path() in find_bundle() (Paolo Bonzini)
> 
> v5:
> * Prefer qemu-bundle if it exists. (Daniel P. Berrangé)
> * Check install_blobs option before installing BIOSes (Paolo Bonzini)
> * Add common code to set up qemu-bundle to the top level meson.build
>    (Paolo Bonzini)
> 
> v4:
> * Add Daniel P. Berrangé to CC. Hopefully this helps merging his patch:
>    https://mail.gnu.org/archive/html/qemu-devel/2022-06/msg02276.html
> * Rebased to the latest QEMU.
> 
> v3:
> * Note that the bundle mechanism is for any files located relative to the
>    installation tree including but not limited to datadir. (Peter Maydell)
> * Fix "bridge" typo (Philippe Mathieu-Daudé)
> 
> v2: Rebased to the latest QEMU.
> 
> Akihiko Odaki (3):
>    cutils: Introduce bundle mechanism
>    datadir: Use bundle mechanism
>    module: Use bundle mechanism
> 
> Paolo Bonzini (1):
>    tests/vm: do not specify -bios option
> 
>   .travis.yml                     |  2 +-
>   docs/about/build-platforms.rst  |  2 +-
>   include/qemu/cutils.h           | 18 +++++++--
>   meson.build                     |  4 ++
>   pc-bios/keymaps/meson.build     | 21 +++-------
>   pc-bios/meson.build             | 13 ++-----
>   scripts/oss-fuzz/build.sh       |  2 +-
>   scripts/symlink-install-tree.py | 37 ++++++++++++++++++
>   softmmu/datadir.c               | 22 +----------
>   tests/qtest/fuzz/fuzz.c         | 15 --------
>   tests/vm/fedora                 |  1 -
>   tests/vm/freebsd                |  1 -
>   tests/vm/netbsd                 |  1 -
>   tests/vm/openbsd                |  1 -
>   util/cutils.c                   | 68 +++++++++++++++++++++++----------
>   util/meson.build                |  1 +
>   util/module.c                   |  1 -
>   17 files changed, 117 insertions(+), 93 deletions(-)
>   create mode 100755 scripts/symlink-install-tree.py
> 



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v8 0/4] cutils: Introduce bundle mechanism
  2022-06-24 15:26 ` [PATCH v8 0/4] cutils: Introduce " Paolo Bonzini
@ 2022-06-24 15:31   ` Akihiko Odaki
  0 siblings, 0 replies; 8+ messages in thread
From: Akihiko Odaki @ 2022-06-24 15:31 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Peter Maydell, Jason Wang, qemu-devel, Programmingkid,
	Philippe Mathieu-Daudé,
	Gerd Hoffmann, Daniel P . Berrangé,
	Alex Bennée, Thomas Huth, John Snow, Cleber Rosa,
	Stefan Weil

On 2022/06/25 0:26, Paolo Bonzini wrote:
> The only change I'd make (which I can do when queueing the patch) is to 
> change the directory name to something "strange" like "=install", so 
> that it's unlikely to have a directory named like that in the $bindir.
> 
> Any opinions?

Actually I prepended qemu- to the directory because all executables of 
QEMU has the prefix. We can safely say QEMU installation will never 
collide if no file prefixed with qemu- exists in the bindir.

If anyone has an idea what should follow "qemu-", please tell us.

Regards,
Akihiko Odaki


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-06-24 15:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-24 14:50 [PATCH v8 0/4] cutils: Introduce bundle mechanism Akihiko Odaki
2022-06-24 14:50 ` [PATCH v8 1/4] tests/vm: do not specify -bios option Akihiko Odaki
2022-06-24 14:50 ` [PATCH v8 2/4] cutils: Introduce bundle mechanism Akihiko Odaki
2022-06-24 15:26   ` Thomas Huth
2022-06-24 14:50 ` [PATCH v8 3/4] datadir: Use " Akihiko Odaki
2022-06-24 14:50 ` [PATCH v8 4/4] module: " Akihiko Odaki
2022-06-24 15:26 ` [PATCH v8 0/4] cutils: Introduce " Paolo Bonzini
2022-06-24 15:31   ` Akihiko Odaki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.