Skip to contentSkip to conversation

os_find_datadir: search as in version 4.2

PATCH In review Joe Slater 6 participants 13 messages Jun 15, 2020 – Jan 23, 2021

lore
Share & tools
lore

Joe Slater

author
#0 lore raw

PATCH 1/1 os_find_datadir: search as in version 4.2

Always look for ../share/qemu then ../pc-bios when looking for datadir.

---
 os-posix.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
os-posix.c +8 -1
index 3cd52e1e70..f77da94bf6 100644
@@ -82,8 +82,9 @@ void os_setup_signal_handling(void)
 
 /*
  * Find a likely location for support files using the location of the binary.
+ * Typically, this would be "$bindir/../share/qemu".
  * When running from the build tree this will be "$bindir/../pc-bios".
- * Otherwise, this is CONFIG_QEMU_DATADIR.
+ * Otherwise, this is CONFIG_QEMU_DATADIR as constructed by configure.
  */
 char *os_find_datadir(void)
 {
@@ -93,6 +94,12 @@ char *os_find_datadir(void)
     exec_dir = qemu_get_exec_dir();
     g_return_val_if_fail(exec_dir != NULL, NULL);
 
+    dir = g_build_filename(exec_dir, "..", "share", "qemu", NULL);
+    if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
+        return g_steal_pointer(&dir);
+    }
+    g_free(dir);  /* no autofree this time */
+
     dir = g_build_filename(exec_dir, "..", "pc-bios", NULL);
     if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
         return g_steal_pointer(&dir);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 2 lines · Joe Slater

Always look for ../share/qemu then ../pc-bios when looking for datadir.

Could you provide some more context, please? Why is this change useful; presumably we broke some setup in 5.0, but what exactly ?

I'm guessing this might be a regression introduced by commit 6dd2dacedd83d12328 so I'm ccing the relevant people.

Quoted 35 lines
---
 os-posix.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
os-posix.c +8 -2
index 3cd52e1e70..f77da94bf6 100644
@@ -82,8 +82,9 @@ void os_setup_signal_handling(void)
 
 /*
  * Find a likely location for support files using the location of the binary.
+ * Typically, this would be "$bindir/../share/qemu".
  * When running from the build tree this will be "$bindir/../pc-bios".
- * Otherwise, this is CONFIG_QEMU_DATADIR.
+ * Otherwise, this is CONFIG_QEMU_DATADIR as constructed by configure.
  */
 char *os_find_datadir(void)
 {
@@ -93,6 +94,12 @@ char *os_find_datadir(void)
     exec_dir = qemu_get_exec_dir();
     g_return_val_if_fail(exec_dir != NULL, NULL);
 
+    dir = g_build_filename(exec_dir, "..", "share", "qemu", NULL);
+    if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
+        return g_steal_pointer(&dir);
+    }
+    g_free(dir);  /* no autofree this time */
+
     dir = g_build_filename(exec_dir, "..", "pc-bios", NULL);
     if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
         return g_steal_pointer(&dir);
--

2.17.1

#2 lore raw

Hi Peter,

Specifically, 5.0 breaks the way yocto runqemu starts qemu-system-*. The installation path which is not known at qemu build time, is <arbitrary-prefix>/usr/{bin,share}. In general, though, I think it's a good idea to look in "reasonable" locations relative to the executable, maybe with command line options taking precedence.

Joe

-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Tuesday, June 16, 2020 2:20 AM
To: Slater, Joseph <[email protected]>
Cc: QEMU Developers <[email protected]>; MacLeod, Randy <[email protected]>; Marc-André Lureau <[email protected]>; Paolo Bonzini <[email protected]>
Subject: Re: [PATCH 1/1] os_find_datadir: search as in version 4.2

Quoted 2 lines · Joe Slater

Always look for ../share/qemu then ../pc-bios when looking for datadir.

Could you provide some more context, please? Why is this change useful; presumably we broke some setup in 5.0, but what exactly ?

I'm guessing this might be a regression introduced by commit 6dd2dacedd83d12328 so I'm ccing the relevant people.

Quoted 35 lines
---
 os-posix.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
os-posix.c +8 -2
index 3cd52e1e70..f77da94bf6 100644
@@ -82,8 +82,9 @@ void os_setup_signal_handling(void)
 
 /*
  * Find a likely location for support files using the location of the binary.
+ * Typically, this would be "$bindir/../share/qemu".
  * When running from the build tree this will be "$bindir/../pc-bios".
- * Otherwise, this is CONFIG_QEMU_DATADIR.
+ * Otherwise, this is CONFIG_QEMU_DATADIR as constructed by configure.
  */
 char *os_find_datadir(void)
 {
@@ -93,6 +94,12 @@ char *os_find_datadir(void)
     exec_dir = qemu_get_exec_dir();
     g_return_val_if_fail(exec_dir != NULL, NULL);
 
+    dir = g_build_filename(exec_dir, "..", "share", "qemu", NULL);
+    if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
+        return g_steal_pointer(&dir);
+    }
+    g_free(dir);  /* no autofree this time */
+
     dir = g_build_filename(exec_dir, "..", "pc-bios", NULL);
     if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
         return g_steal_pointer(&dir);
--

2.17.1

#3 lore raw
In reply to Peter Maydell
Quoted 11 lines · Peter Maydell
Quoted 2 lines · Joe Slater

Always look for ../share/qemu then ../pc-bios when looking for datadir.

Could you provide some more context, please? Why is this change useful; presumably we broke some setup in 5.0, but what exactly ?

I'm guessing this might be a regression introduced by commit 6dd2dacedd83d12328 so I'm ccing the relevant people.

Marco, Paolo: ping? Another user has just asked me the status of this as they also ran into this regression in what directories we search...

thanks
-- PMM

Quoted 35 lines
Quoted 35 lines
---
 os-posix.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
os-posix.c +8 -2
index 3cd52e1e70..f77da94bf6 100644
@@ -82,8 +82,9 @@ void os_setup_signal_handling(void)
 
 /*
  * Find a likely location for support files using the location of the binary.
+ * Typically, this would be "$bindir/../share/qemu".
  * When running from the build tree this will be "$bindir/../pc-bios".
- * Otherwise, this is CONFIG_QEMU_DATADIR.
+ * Otherwise, this is CONFIG_QEMU_DATADIR as constructed by configure.
  */
 char *os_find_datadir(void)
 {
@@ -93,6 +94,12 @@ char *os_find_datadir(void)
     exec_dir = qemu_get_exec_dir();
     g_return_val_if_fail(exec_dir != NULL, NULL);
 
+    dir = g_build_filename(exec_dir, "..", "share", "qemu", NULL);
+    if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
+        return g_steal_pointer(&dir);
+    }
+    g_free(dir);  /* no autofree this time */
+
     dir = g_build_filename(exec_dir, "..", "pc-bios", NULL);
     if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
         return g_steal_pointer(&dir);
--

2.17.1

#4 lore raw

Hi

Quoted 11 lines · Peter Maydell
Quoted 9 lines · Peter Maydell
Quoted 2 lines · Joe Slater

Always look for ../share/qemu then ../pc-bios when looking for datadir.

Could you provide some more context, please? Why is this change useful; presumably we broke some setup in 5.0, but what exactly ?

Quoted 6 lines
Quoted 2 lines

I'm guessing this might be a regression introduced by commit 6dd2dacedd83d12328 so I'm ccing the relevant people.

Marco, Paolo: ping? Another user has just asked me the status of this as they also ran into this regression in what directories we search...

Thanks for the heads-up, I didn't see that bug/mail. Indeed, that commit assumed that either we run from a build directory or from an installed qemu. It seems this is hybrid approach, which I didn't know we supported. I'll check it.

cheers

Quoted 41 lines

thanks
-- PMM

Quoted 35 lines
Quoted 35 lines
---
 os-posix.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
os-posix.c +8 -2
index 3cd52e1e70..f77da94bf6 100644
@@ -82,8 +82,9 @@ void os_setup_signal_handling(void)
 
 /*
  * Find a likely location for support files using the location of the binary.
+ * Typically, this would be "$bindir/../share/qemu".
  * When running from the build tree this will be "$bindir/../pc-bios".
- * Otherwise, this is CONFIG_QEMU_DATADIR.
+ * Otherwise, this is CONFIG_QEMU_DATADIR as constructed by configure.
  */
 char *os_find_datadir(void)
 {
@@ -93,6 +94,12 @@ char *os_find_datadir(void)
     exec_dir = qemu_get_exec_dir();
     g_return_val_if_fail(exec_dir != NULL, NULL);
 
+    dir = g_build_filename(exec_dir, "..", "share", "qemu", NULL);
+    if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
+        return g_steal_pointer(&dir);
+    }
+    g_free(dir);  /* no autofree this time */
+
     dir = g_build_filename(exec_dir, "..", "pc-bios", NULL);
     if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
         return g_steal_pointer(&dir);
--

2.17.1

Tested-by Reviewed-by
#5 lore raw

Hello!

Quoted 17 lines · Marc-André Lureau

Hi

Quoted 14 lines · Peter Maydell
Quoted 11 lines · Peter Maydell
Quoted 2 lines · Joe Slater

Always look for ../share/qemu then ../pc-bios when looking for datadir.

Could you provide some more context, please? Why is this change useful; presumably we broke some setup in 5.0, but what exactly ?

I'm guessing this might be a regression introduced by commit 6dd2dacedd83d12328 so I'm ccing the relevant people.

Quoted 8 lines
Quoted 3 lines

Marco, Paolo: ping? Another user has just asked me the status of this as they also ran into this regression in what directories we search...

Thanks for the heads-up, I didn't see that bug/mail. Indeed, that commit assumed that either we run from a build directory or from an installed qemu. It seems this is hybrid approach, which I didn't know we supported. I'll check it.

Add one more to the pile! Chrome OS noticed this when upgrading to 5.0.0:

https://bugs.chromium.org/p/chromium/issues/detail?id=1114204#c8

I'd love to see this applied to a release.

I actually wrote basically this exact same patch and was about to submit it, when I saw that this was already here. I've tested Joe's variant:

The Chromium bug report is public, so you can see details there, but it's basically the same -- we sometimes run qemu from a path that's not the same absolute path noted in ./configure. This is because we build qemu to run within our SDK (a semi-containerized chroot), but we also support running that same QEMU binary from outside the container, which then may be at some arbitrary hierarchy on a developer's machine.

It might be wise to include a tiny bit more verbose of a code comment, to prevent oversights like this in the future. I'm sure that could be spliced in when the patch is applied though.

Regards,
Brian

#6 lore raw
Quoted 30 lines · Brian Norris

Hello!

Quoted 17 lines · Marc-André Lureau

Hi

Quoted 14 lines · Peter Maydell
Quoted 11 lines · Peter Maydell
Quoted 2 lines · Joe Slater

Always look for ../share/qemu then ../pc-bios when looking for datadir.

Could you provide some more context, please? Why is this change useful; presumably we broke some setup in 5.0, but what exactly ?

I'm guessing this might be a regression introduced by commit 6dd2dacedd83d12328 so I'm ccing the relevant people.

Quoted 8 lines
Quoted 3 lines

Marco, Paolo: ping? Another user has just asked me the status of this as they also ran into this regression in what directories we search...

Thanks for the heads-up, I didn't see that bug/mail. Indeed, that commit assumed that either we run from a build directory or from an installed qemu. It seems this is hybrid approach, which I didn't know we supported. I'll check it.

Quoted 6 lines

Add one more to the pile! Chrome OS noticed this when upgrading to 5.0.0:

https://bugs.chromium.org/p/chromium/issues/detail?id=1114204#c8

I'd love to see this applied to a release.

It's just missed 5.1, unfortunately :-(

Marc-André, did you want to review it ?

thanks
-- PMM

#7 lore raw

Hi

Quoted 35 lines · Peter Maydell
Quoted 33 lines · Brian Norris

Hello!

Quoted 17 lines · Marc-André Lureau

Hi

Quoted 14 lines · Peter Maydell
Quoted 11 lines · Peter Maydell
Quoted 2 lines · Joe Slater

Always look for ../share/qemu then ../pc-bios when looking for datadir.

Could you provide some more context, please? Why is this change useful; presumably we broke some setup in 5.0, but what exactly ?

I'm guessing this might be a regression introduced by commit 6dd2dacedd83d12328 so I'm ccing the relevant people.

Quoted 8 lines
Quoted 3 lines

Marco, Paolo: ping? Another user has just asked me the status of this as they also ran into this regression in what directories we search...

Thanks for the heads-up, I didn't see that bug/mail. Indeed, that commit assumed that either we run from a build directory or from an installed qemu. It seems this is hybrid approach, which I didn't know we supported. I'll check it.

Add one more to the pile! Chrome OS noticed this when upgrading to 5.0.0:

Quoted 7 lines
Quoted 3 lines

https://bugs.chromium.org/p/chromium/issues/detail?id=1114204#c8

I'd love to see this applied to a release.

It's just missed 5.1, unfortunately :-(

Marc-André, did you want to review it ?

I tried an alternative approach, and ack his version instead:

https://patchew.org/QEMU/[email protected]/

(I am going to do this in this thread instead)

#8 lore raw
Quoted 11 lines · Marc-André Lureau
Quoted 10 lines · Peter Maydell
Quoted 6 lines · Brian Norris

Add one more to the pile! Chrome OS noticed this when upgrading to 5.0.0:

https://bugs.chromium.org/p/chromium/issues/detail?id=1114204#c8

I'd love to see this applied to a release.

It's just missed 5.1, unfortunately :-(

Quoted 7 lines
Quoted 1 line

Marc-André, did you want to review it ?

I tried an alternative approach, and ack his version instead:

https://patchew.org/QEMU/[email protected]/

(I am going to do this in this thread instead)

FWIW, you already provided your Review a month ago:
https://lore.kernel.org/qemu-devel/CAJ+F1CJmMV6pY6r0P6ukNZA_q+w6yLvAxekGnusgXYuuip6gZA@mail.gmail.com/

But I see you've now repeated it ;)
https://lore.kernel.org/qemu-devel/CAJ+F1CJdHo7R9rnmoD1cLEzsYLFsFVVjcAr5UcsYFgfcW3z2LA@mail.gmail.com/

In any case, thanks! We'll likely carry this patch in Chrome OS, until it gets applied to a proper release.

Regards,
Brian

#9 lore raw

Just to follow-up here, since nobody followed up for months...

Quoted 5 lines · Brian Norris
Quoted 3 lines · Marc-André Lureau
Quoted 2 lines · Peter Maydell

On Sat, 8 Aug 2020 at 02:35, Brian Norris <[email protected]> wrote:
It's just missed 5.1, unfortunately :-(

And it missed 5.2 too :(

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Marc-André, did you want to review it ?

I tried an alternative approach, and ack his version instead:

https://patchew.org/QEMU/[email protected]/

(I am going to do this in this thread instead)

Quoted 8 lines

FWIW, you already provided your Review a month ago:
https://lore.kernel.org/qemu-devel/CAJ+F1CJmMV6pY6r0P6ukNZA_q+w6yLvAxekGnusgXYuuip6gZA@mail.gmail.com/

But I see you've now repeated it ;)
https://lore.kernel.org/qemu-devel/CAJ+F1CJdHo7R9rnmoD1cLEzsYLFsFVVjcAr5UcsYFgfcW3z2LA@mail.gmail.com/

In any case, thanks! We'll likely carry this patch in Chrome OS, until it gets applied to a proper release.

It turns out that Paolo inadvertently (?) fixed this issue by refactoring, in v5.2.0:
ea1edcd7da1a vl: relocate paths to data directories
https://git.qemu.org/?p=qemu.git;a=commitdiff;h=ea1edcd7da1a375ef7ccf8aa93b72827b518ad8e;hp=63c4db4c2e6d221cecb5aafa365934bb05724cb4

I tested that out here, and the new find_datadir() is able to track relocations properly, by looking for a common directory ancestor of the running executable. Thanks Paolo!

Brian

#10 lore raw
Quoted 4 lines · Brian Norris

It turns out that Paolo inadvertently (?) fixed this issue by refactoring, in v5.2.0:
ea1edcd7da1a vl: relocate paths to data directories
https://git.qemu.org/?p=qemu.git;a=commitdiff;h=ea1edcd7da1a375ef7ccf8aa93b72827b518ad8e;hp=63c4db4c2e6d221cecb5aafa365934bb05724cb4

That wasn't entirely inadvertent. It had been on my todo list to fix relocatability for good, I just didn't remember how it got on the list. :)

So on one hand I didn't remember it to be a regression, and I only really set out to make QEMU relocatable in order to enable the change of commit d17f305a26 ("configure: use a platform-neutral prefix", 2020-09-30). On the other hand, your report was what had made me aware that relocatable installs were buggy and inconsistent.

Paolo

Reviewed-by on v1 1/1
#11 lore raw
In reply to Joe Slater

Hi

Quoted 4 lines · Joe Slater

Always look for ../share/qemu then ../pc-bios when looking for datadir.

Looks good to me, with:

Fixes 6dd2dacedd83d12328 ("os-posix: simplify os_find_datadir")

Alternatively, we may want to check the binary install location to decide which path to return. I sent a proposal "[RFC PATCH] os-posix: fix regression for install-less datadir location".

---

Quoted 37 lines
 os-posix.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
os-posix.c +0 -0
index 3cd52e1e70..f77da94bf6 100644
@@ -82,8 +82,9 @@ void os_setup_signal_handling(void)
 
 /*
  * Find a likely location for support files using the location of the

binary.
+ * Typically, this would be "$bindir/../share/qemu".
* When running from the build tree this will be "$bindir/../pc-bios".
- * Otherwise, this is CONFIG_QEMU_DATADIR.
+ * Otherwise, this is CONFIG_QEMU_DATADIR as constructed by configure. */
char *os_find_datadir(void)
{

os-posix.c +6 -1
@@ -93,6 +94,12 @@ char *os_find_datadir(void)
     exec_dir = qemu_get_exec_dir();
     g_return_val_if_fail(exec_dir != NULL, NULL);
 
+    dir = g_build_filename(exec_dir, "..", "share", "qemu", NULL);
+    if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
+        return g_steal_pointer(&dir);
+    }
+    g_free(dir);  /* no autofree this time */
+
     dir = g_build_filename(exec_dir, "..", "pc-bios", NULL);
     if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
         return g_steal_pointer(&dir);
--

2.17.1

Signature · 1 line
Marc-André Lureau
Reviewed-by on v1 1/1
#12 lore raw
In reply to Joe Slater
Quoted 4 lines · Joe Slater

Always look for ../share/qemu then ../pc-bios when looking for datadir.

---

Quoted 37 lines
 os-posix.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
os-posix.c +0 -0
index 3cd52e1e70..f77da94bf6 100644
@@ -82,8 +82,9 @@ void os_setup_signal_handling(void)
 
 /*
  * Find a likely location for support files using the location of the

binary.
+ * Typically, this would be "$bindir/../share/qemu".
* When running from the build tree this will be "$bindir/../pc-bios".
- * Otherwise, this is CONFIG_QEMU_DATADIR.
+ * Otherwise, this is CONFIG_QEMU_DATADIR as constructed by configure. */
char *os_find_datadir(void)
{

os-posix.c +6 -1
@@ -93,6 +94,12 @@ char *os_find_datadir(void)
     exec_dir = qemu_get_exec_dir();
     g_return_val_if_fail(exec_dir != NULL, NULL);
 
+    dir = g_build_filename(exec_dir, "..", "share", "qemu", NULL);
+    if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
+        return g_steal_pointer(&dir);
+    }
+    g_free(dir);  /* no autofree this time */
+
     dir = g_build_filename(exec_dir, "..", "pc-bios", NULL);
     if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
         return g_steal_pointer(&dir);
--

2.17.1

Signature · 1 line
Marc-André Lureau