Skip to contentSkip to conversation

os-posix: fix regression for install-less datadir location

RFC PATCH In review Marc-André Lureau 4 participants 5 messages Jul 16, 2020 – Aug 18, 2020

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 os-posix: fix regression for install-less datadir location

os_find_datadir() used to check the ../share/qemu location (regardless of CONFIG_QEMU_DATADIR). It turns out that people rely on that location for running qemu in an arbitrary "install-less/portable" fashion. Change the logic to return that directory as a last resort.

(this is an alternative to the patch "[PATCH 1/1] os_find_datadir: search as in version 4.2" from Joe Slater)

Fixes 6dd2dacedd83d12328 ("os-posix: simplify os_find_datadir")
Cc Paolo Bonzini <[email protected]>
---
 os-posix.c            | 15 ++++++++++++---
 scripts/create_config |  2 +-
 2 files changed, 13 insertions(+), 4 deletions(-)
os-posix.c +12 -3
index b674b20b1b1..bd0ed0c14d1 100644
@@ -82,8 +82,13 @@ void os_setup_signal_handling(void)
 
 /*
  * 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.
+ *
+ * If running from the install location (CONFIG_BINDIR), this will be
+ * CONFIG_QEMU_DATADIR.
+ *
+ * Otherwise, fallback on "$execdir/../pc-bios" if it exists (the build tree
+ * location), else on "$execdir/../share/qemu" (for the install-less/"portable"
+ * version).
  */
 char *os_find_datadir(void)
 {
@@ -93,12 +98,16 @@ char *os_find_datadir(void)
     exec_dir = qemu_get_exec_dir();
     g_return_val_if_fail(exec_dir != NULL, NULL);
 
+    if (g_str_has_prefix(exec_dir, CONFIG_BINDIR)) {
+        return g_strdup(CONFIG_QEMU_DATADIR);
+    }
+
     dir = g_build_filename(exec_dir, "..", "pc-bios", NULL);
     if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
         return g_steal_pointer(&dir);
     }
 
-    return g_strdup(CONFIG_QEMU_DATADIR);
+    return g_build_filename(exec_dir, "..", "share", "qemu", NULL);
 }
 
 void os_set_proc_name(const char *s)
scripts/create_config +1 -1
index 6d8f08b39da..03f8cb1dc10 100755
@@ -15,7 +15,7 @@ case $line in
     echo "#define QEMU_VERSION_MINOR $minor"
     echo "#define QEMU_VERSION_MICRO $micro"
     ;;
- qemu_*dir=* | qemu_*path=*) # qemu-specific directory configuration
+ bindir=* | qemu_*dir=* | qemu_*path=*) # qemu-specific directory configuration
     name=${line%=*}
     value=${line#*=}
     define_name=$(echo $name | LC_ALL=C tr '[a-z]' '[A-Z]')
Signature · 1 line
2.27.0.221.ga08a83db2b
#1 lore raw

Hi

Quoted 40 lines · Marc-André Lureau

os_find_datadir() used to check the ../share/qemu location (regardless of CONFIG_QEMU_DATADIR). It turns out that people rely on that location for running qemu in an arbitrary "install-less/portable" fashion. Change the logic to return that directory as a last resort.

(this is an alternative to the patch "[PATCH 1/1] os_find_datadir: search as in version 4.2" from Joe Slater)

Fixes 6dd2dacedd83d12328 ("os-posix: simplify os_find_datadir")
Cc Paolo Bonzini <[email protected]>
---
 os-posix.c            | 15 ++++++++++++---
 scripts/create_config |  2 +-
 2 files changed, 13 insertions(+), 4 deletions(-)
os-posix.c +0 -0
index b674b20b1b1..bd0ed0c14d1 100644
@@ -82,8 +82,13 @@ void os_setup_signal_handling(void)
 
 /*
  * 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.
+ *
+ * If running from the install location (CONFIG_BINDIR), this will be
+ * CONFIG_QEMU_DATADIR.
+ *
+ * Otherwise, fallback on "$execdir/../pc-bios" if it exists (the build tree
+ * location), else on "$execdir/../share/qemu" (for the install-less/"portable"
+ * version).
*/
char *os_find_datadir(void)
{

os-posix.c char *os_find_datadir(void) · line 102

Quoted 5 lines
os-posix.c +1 -0
@@ -93,12 +98,16 @@ char *os_find_datadir(void)
     exec_dir = qemu_get_exec_dir();
     g_return_val_if_fail(exec_dir != NULL, NULL);
 
+    if (g_str_has_prefix(exec_dir, CONFIG_BINDIR)) {
 

I realize g_str_has_prefix() may not be good enough (it was meant to ignore the / suffix..). I guess we can just go with the version from Joe instead.

+ return g_strdup(CONFIG_QEMU_DATADIR);

Quoted 31 lines
os-posix.c +3 -1
+    }
+
     dir = g_build_filename(exec_dir, "..", "pc-bios", NULL);
     if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
         return g_steal_pointer(&dir);
     }
 
-    return g_strdup(CONFIG_QEMU_DATADIR);
+    return g_build_filename(exec_dir, "..", "share", "qemu", NULL);
 }
 
 void os_set_proc_name(const char *s)
scripts/create_config +1 -1
index 6d8f08b39da..03f8cb1dc10 100755
@@ -15,7 +15,7 @@ case $line in
     echo "#define QEMU_VERSION_MINOR $minor"
     echo "#define QEMU_VERSION_MICRO $micro"
     ;;
- qemu_*dir=* | qemu_*path=*) # qemu-specific directory configuration
+ bindir=* | qemu_*dir=* | qemu_*path=*) # qemu-specific directory

configuration

     name=${line%=*}
     value=${line#*=}
     define_name=$(echo $name | LC_ALL=C tr '[a-z]' '[A-Z]')

--
2.27.0.221.ga08a83db2b

Signature · 1 line
Marc-André Lureau
#2 lore raw
In reply to Marc-André Lureau
Quoted 11 lines · Marc-André Lureau

os_find_datadir() used to check the ../share/qemu location (regardless of CONFIG_QEMU_DATADIR). It turns out that people rely on that location for running qemu in an arbitrary "install-less/portable" fashion. Change the logic to return that directory as a last resort.

(this is an alternative to the patch "[PATCH 1/1] os_find_datadir: search as in version 4.2" from Joe Slater)

Fixes 6dd2dacedd83d12328 ("os-posix: simplify os_find_datadir")
Cc Paolo Bonzini <[email protected]>

For 5.2 I plan to support fully relocatable installs, so I think this will not be needed.

The idea is to write a function like

char *get_relocatable_path(const char *dir);

That takes CONFIG_QEMU_*DIR as the argument, turns it into a path relative to bindir, and tacks it to the end of qemu_get_exec_dir().

So for example all references to CONFIG_QEMU_DATADIR would invoke get_relocatable_path(CONFIG_QEMU_DATADIR), which would return something like "/usr/bin/../share/qemu".

Paolo

#3 lore raw
Quoted 19 lines · Paolo Bonzini
Quoted 11 lines · Marc-André Lureau

os_find_datadir() used to check the ../share/qemu location (regardless of CONFIG_QEMU_DATADIR). It turns out that people rely on that location for running qemu in an arbitrary "install-less/portable" fashion. Change the logic to return that directory as a last resort.

(this is an alternative to the patch "[PATCH 1/1] os_find_datadir: search as in version 4.2" from Joe Slater)

Fixes 6dd2dacedd83d12328 ("os-posix: simplify os_find_datadir")
Cc Paolo Bonzini <[email protected]>

For 5.2 I plan to support fully relocatable installs, so I think this will not be needed.

The idea is to write a function like

Quoted 8 lines

char *get_relocatable_path(const char *dir);

That takes CONFIG_QEMU_*DIR as the argument, turns it into a path relative to bindir, and tacks it to the end of qemu_get_exec_dir().

So for example all references to CONFIG_QEMU_DATADIR would invoke get_relocatable_path(CONFIG_QEMU_DATADIR), which would return something like "/usr/bin/../share/qemu".

Unless you have that series ready-to-roll, I think it would be useful to just fix the regression (and cc qemu-stable on it so it gets backported to 5.1.1) for the moment.

thanks
-- PMM

#4 lore raw
Quoted 6 lines · Peter Maydell
Quoted 3 lines

So for example all references to CONFIG_QEMU_DATADIR would invoke get_relocatable_path(CONFIG_QEMU_DATADIR), which would return something like "/usr/bin/../share/qemu".

Unless you have that series ready-to-roll, I think it would be useful to just fix the regression (and cc qemu-stable on it so it gets backported to 5.1.1) for the moment.

I have it ready but I agree it's not suitable for backporting (among other things, I've never tested it on the non-meson build system). I can rebase it on top of this patch with no issue.

Paolo