Skip to contentSkip to conversation

modules: load modules from versioned /var/run dir

PATCH Superseded Christian Ehrhardt 6 participants 11 messages Mar 6, 2020 – Mar 16, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 modules: load modules from versioned /var/run dir

On upgrades the old .so files usually are replaced. But on the other hand since a qemu process represents a guest instance it is usually kept around.

That makes late addition of dynamic features e.g. 'hot-attach of a ceph disk' fail by trying to load a new version of e.f. block-rbd.so into an old still running qemu binary.

This adds a fallback to also load modules from a versioned directory in the temporary /var/run path. That way qemu is providing a way for packaging to store modules of an upgraded qemu package as needed until the next reboot.

An example how that can then be used in packaging can be seen in:
https://git.launchpad.net/~paelzer/ubuntu/+source/qemu/log/?h=bug-1847361-miss-old-so-on-upgrade-UBUNTU

---
 util/module.c | 7 +++++++
 1 file changed, 7 insertions(+)
util/module.c +7 -0
index 236a7bb52a..d2446104be 100644
@@ -19,6 +19,7 @@
 #endif
 #include "qemu/queue.h"
 #include "qemu/module.h"
+#include "qemu-version.h"
 
 typedef struct ModuleEntry
 {
@@ -170,6 +171,7 @@ bool module_load_one(const char *prefix, const char *lib_name)
 #ifdef CONFIG_MODULES
     char *fname = NULL;
     char *exec_dir;
+    char *version_dir;
     const char *search_dir;
     char *dirs[4];
     char *module_name;
@@ -201,6 +203,11 @@ bool module_load_one(const char *prefix, const char *lib_name)
     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 ? : "");
+    version_dir = g_strcanon(g_strdup(QEMU_PKGVERSION),
+                             G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "+-.~",
+                             '_');
+    dirs[n_dirs++] = g_strdup_printf("/var/run/qemu/%s", version_dir);
+
     assert(n_dirs <= ARRAY_SIZE(dirs));
 
     g_free(exec_dir);
Signature · 1 line
2.25.1
#1 lore raw
Patchew URL: https://patchew.org/QEMU/[email protected]/

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

Hi,

This series failed the docker-mingw@fedora build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#! /bin/bash
export ARCH=x86_64
make docker-image-fedora V=1 NETWORK=1
time make docker-test-mingw@fedora J=14 NETWORK=1
=== TEST SCRIPT END ===

File: "/tmp/qemu-nsis\qemu-doc.html" -> no files found.
Usage: File [/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |
/oname=outfile one_file_only)
Error in script "/tmp/qemu-test/src/qemu.nsi" on line 180 -- aborting creation process
make: *** [Makefile:1162: qemu-setup-4.2.50.exe] Error 1
Traceback (most recent call last):
File "./tests/docker/docker.py", line 664, in <module>

    sys.exit(main())

---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=d78ae1bf94024f7c8a0255eb0d63c8f1', '-u', '1003', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-zbg82xrb/src/docker-src.2020-03-06-09.38.41.1852:/var/tmp/qemu:z,ro', 'qemu:fedora', '/var/tmp/qemu/run', 'test-mingw']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=d78ae1bf94024f7c8a0255eb0d63c8f1
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-zbg82xrb/src'
make: *** [docker-run-test-mingw@fedora] Error 2

real 3m8.711s
user 0m7.969s

The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#2 lore raw
Quoted 46 lines · On Fri, Mar 6, 2020 at 3:42 PM <[email protected]> wrote:

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

Hi,

This series failed the docker-mingw@fedora build test. Please find the testing commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.

=== TEST SCRIPT BEGIN ===
#! /bin/bash
export ARCH=x86_64
make docker-image-fedora V=1 NETWORK=1
time make docker-test-mingw@fedora J=14 NETWORK=1
=== TEST SCRIPT END ===

File: "/tmp/qemu-nsis\qemu-doc.html" -> no files found.
Usage: File [/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |
/oname=outfile one_file_only)
Error in script "/tmp/qemu-test/src/qemu.nsi" on line 180 -- aborting creation process
make: *** [Makefile:1162: qemu-setup-4.2.50.exe] Error 1 Traceback (most recent call last):
File "./tests/docker/docker.py", line 664, in <module>

    sys.exit(main())

---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run',
'--label', 'com.qemu.instance.uuid=d78ae1bf94024f7c8a0255eb0d63c8f1', '-u', '1003', '--security-opt', 'seccomp=unconfined', '--rm', '-e',
'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14',
'-e', 'DEBUG=', '-e', 'SHOW_ENV=', '-e', 'CCACHE_DIR=/var/tmp/ccache',
'-v', '/home/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-zbg82xrb/src/docker-src.2020-03-06-09.38.41.1852:/var/tmp/qemu:z,ro', 'qemu:fedora', '/var/tmp/qemu/run', 'test-mingw']' returned non-zero exit
status 2.

filter=--filter=label=com.qemu.instance.uuid=d78ae1bf94024f7c8a0255eb0d63c8f1 make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-zbg82xrb/src'
make: *** [docker-run-test-mingw@fedora] Error 2

Quoted 9 lines

real 3m8.711s
user 0m7.969s

The full log is available at

http://patchew.org/logs/[email protected]/testing.docker-mingw@fedora/?type=message
.

This is a false-positive - at least not due to my proposed patch. I've not even remotely touched qemu-doc.

The test build even runs with config:
module support no
Which even means all my changes except the include are removed by the preprocessor.

Do I need to do anything to reset the state of this patch to not be marked as failed?

Quoted 3 lines

---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

Signature · 3 lines
Christian Ehrhardt
Staff Engineer, Ubuntu Server
Canonical Ltd
#3 lore raw
In reply to Christian Ehrhardt
Quoted 12 lines · Christian Ehrhardt

On upgrades the old .so files usually are replaced. But on the other hand since a qemu process represents a guest instance it is usually kept around.

That makes late addition of dynamic features e.g. 'hot-attach of a ceph disk' fail by trying to load a new version of e.f. block-rbd.so into an old still running qemu binary.

This adds a fallback to also load modules from a versioned directory in the temporary /var/run path. That way qemu is providing a way for packaging to store modules of an upgraded qemu package as needed until the next reboot.

Quoted 8 lines

An example how that can then be used in packaging can be seen in:
https://git.launchpad.net/~paelzer/ubuntu/+source/qemu/log/?h=bug-1847361-miss-old-so-on-upgrade-UBUNTU

---
 util/module.c | 7 +++++++
 1 file changed, 7 insertions(+)

CCing Debian, Fedora, and Red Hat package maintainers in case they have comments.

The use of /var/run makes me a little uneasy. I guess it's related to wanting to uninstall the old package so the .so in their original location cannot be used (even if they had a versioned path)?

I'm not a package maintainer though so I hope the others will make suggestions if there are other solutions :).

Quoted 37 lines
util/module.c +7 -0
index 236a7bb52a..d2446104be 100644
@@ -19,6 +19,7 @@
 #endif
 #include "qemu/queue.h"
 #include "qemu/module.h"
+#include "qemu-version.h"
 
 typedef struct ModuleEntry
 {
@@ -170,6 +171,7 @@ bool module_load_one(const char *prefix, const char *lib_name)
 #ifdef CONFIG_MODULES
     char *fname = NULL;
     char *exec_dir;
+    char *version_dir;
     const char *search_dir;
     char *dirs[4];
     char *module_name;
@@ -201,6 +203,11 @@ bool module_load_one(const char *prefix, const char *lib_name)
     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 ? : "");
+    version_dir = g_strcanon(g_strdup(QEMU_PKGVERSION),
+                             G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "+-.~",
+                             '_');
+    dirs[n_dirs++] = g_strdup_printf("/var/run/qemu/%s", version_dir);
+
     assert(n_dirs <= ARRAY_SIZE(dirs));
 
     g_free(exec_dir);
Signature · 1 line
2.25.1
#4 lore raw
Quoted 19 lines · Stefan Hajnoczi
Quoted 9 lines · Christian Ehrhardt

On upgrades the old .so files usually are replaced. But on the other hand since a qemu process represents a guest instance it is usually kept around.

That makes late addition of dynamic features e.g. 'hot-attach of a ceph disk' fail by trying to load a new version of e.f. block-rbd.so into an old still running qemu binary.

This adds a fallback to also load modules from a versioned directory in

the

Quoted 2 lines

temporary /var/run path. That way qemu is providing a way for packaging to store modules of an upgraded qemu package as needed until the next

reboot.

Quoted 3 lines

An example how that can then be used in packaging can be seen in:

https://git.launchpad.net/~paelzer/ubuntu/+source/qemu/log/?h=bug-1847361-miss-old-so-on-upgrade-UBUNTU

Quoted 1 line
Quoted 9 lines
Quoted 5 lines
---
 util/module.c | 7 +++++++
 1 file changed, 7 insertions(+)

CCing Debian, Fedora, and Red Hat package maintainers in case they have comments.

Yeah that seems worth, thanks Stefan.

The use of /var/run makes me a little uneasy. I guess it's related to

Quoted 3 lines

wanting to uninstall the old package so the .so in their original location cannot be used (even if they had a versioned path)?

Yes you'd want to uninstall the old bits from disk - even if there would be a versioned path.
/var/run was considered a nice place as it is auto-cleaned on a reboot avoiding a massive
and most likely broken logic trying to detect which qemu versions still have running binaries.

And no distro will have so many qemu updates that N*~<100k for the .so files will really grow too big.

Also if the path would end up to be the major concern and we can't agree on a single one we can consider making this:
1. not checking an extra path if not configured
2. on configure packaging can set a path of their choice

I have not done so yet as I was hoping for a simpler patch and everyone knowing what to expect across e.g. distros.
It also will make isolation easier for example I also have apparmor changes for libvirt allowing that path which is more complex if it ends up configurable.

And finally this has to be considered an "offer" by qemu to the packagers to fix a real field issue.
The packaging does not "have to" exploit this, every Distro is free to just ignore it.

I'm not a package maintainer though so I hope the others will make

Quoted 43 lines

suggestions if there are other solutions :).

util/module.c bool module_load_one(const char *prefix, const char

Quoted 14 lines
util/module.c +1 -0
index 236a7bb52a..d2446104be 100644
@@ -19,6 +19,7 @@
 #endif
 #include "qemu/queue.h"
 #include "qemu/module.h"
+#include "qemu-version.h"
 
 typedef struct ModuleEntry
 {
@@ -170,6 +171,7 @@ bool module_load_one(const char *prefix, const char

*lib_name)

util/module.c bool module_load_one(const char *prefix, const char

Quoted 8 lines
util/module.c +1 -0
 #ifdef CONFIG_MODULES
     char *fname = NULL;
     char *exec_dir;
+    char *version_dir;
     const char *search_dir;
     char *dirs[4];
     char *module_name;
@@ -201,6 +203,11 @@ bool module_load_one(const char *prefix, const char

*lib_name)

util/module.c bool module_load_one(const char *prefix, const char *lib_name)

Quoted 5 lines
util/module.c +2 -0
     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 ? : "");
+    version_dir = g_strcanon(g_strdup(QEMU_PKGVERSION),
+                             G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS

"+-.~",

Quoted 10 lines
util/module.c +3 -1
+                             '_');
+    dirs[n_dirs++] = g_strdup_printf("/var/run/qemu/%s", version_dir);
+
     assert(n_dirs <= ARRAY_SIZE(dirs));
 
     g_free(exec_dir);
--

2.25.1

Signature · 3 lines
Christian Ehrhardt
Staff Engineer, Ubuntu Server
Canonical Ltd
#5 lore raw
Quoted 6 lines · Christian Ehrhardt
Quoted 1 line · Stefan Hajnoczi

On Fri, Mar 06, 2020 at 02:26:48PM +0100, Christian Ehrhardt wrote:

And finally this has to be considered an "offer" by qemu to the packagers to fix a real field issue.
The packaging does not "have to" exploit this, every Distro is free to just ignore it.

I understand. My intention is just to draw the attention of the right people so that other distros are aware of the problem and improvements can be discussed.

From my own perspective it seems fine to merge this or a similar patch into qemu.git.

Stefan

#6 lore raw
In reply to Stefan Hajnoczi
Quoted 25 lines · Stefan Hajnoczi
Quoted 12 lines · Christian Ehrhardt

On upgrades the old .so files usually are replaced. But on the other hand since a qemu process represents a guest instance it is usually kept around.

That makes late addition of dynamic features e.g. 'hot-attach of a ceph disk' fail by trying to load a new version of e.f. block-rbd.so into an old still running qemu binary.

This adds a fallback to also load modules from a versioned directory in the temporary /var/run path. That way qemu is providing a way for packaging to store modules of an upgraded qemu package as needed until the next reboot.

Quoted 8 lines

An example how that can then be used in packaging can be seen in:
https://git.launchpad.net/~paelzer/ubuntu/+source/qemu/log/?h=bug-1847361-miss-old-so-on-upgrade-UBUNTU

---
 util/module.c | 7 +++++++
 1 file changed, 7 insertions(+)

CCing Debian, Fedora, and Red Hat package maintainers in case they have comments.

Quoted 6 lines

The use of /var/run makes me a little uneasy. I guess it's related to wanting to uninstall the old package so the .so in their original location cannot be used (even if they had a versioned path)?

I'm not a package maintainer though so I hope the others will make suggestions if there are other solutions :).

My first concern is that this only partially solves the quoted problem.

Consider the QEMU RBD module which is

/usr/lib64/qemu/block-rbd.so

This links to

/usr/lib64/librbd.so.1

On host OS upgrade, just before uninstalling old QEMU we copy RBD module into:

/var/run/qemu-$VER/block-rbd.so

....but the host OS upgrade also upgrades RBD itself to a new major version which ships

/usr/lib64/librbd.so.2

We've got /var/run/qemu-$VER/block-rbd.so saved, but we didn't transitively save all the things that this linked to, so there's no guarantee it will still be possible to load it.

IOW, this approach of saving QEMU block modules to a scratch dir works, *provided* everything else that this QEMU block module needs still exists in a compatible form.

Some distros may have a policy that no incompatible soname bumps are permitted in updates, but that's not universal.

On the other hand this is not a big amount of new code, so is not a huge maint problem even if only a few people ever use it. I would be a bit more comfortable if this search path addition was perhaps enabled by an opt-in configure argument, rather than being always present.

I'm also uneasy about the idea of using a search path ordering for doing this. This means that an old running QEMU is always going to first try to load the block-rbd.so from the new QEMU, expect to see that fail, and only then fallback to load the block-rbd.so that actually matches its build.

IIRC, we have an embedded build-id in the modules that should guarantee that the first load attempt always fails, but I'm still uneasy about that at a conceptual level.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#7 lore raw
Quoted 50 lines · Daniel P. Berrangé
Quoted 3 lines · Stefan Hajnoczi
Quoted 2 lines · Christian Ehrhardt

On upgrades the old .so files usually are replaced. But on the other hand since a qemu process represents a guest instance it is usually

kept

Quoted 7 lines
Quoted 7 lines

around.

That makes late addition of dynamic features e.g. 'hot-attach of a ceph disk' fail by trying to load a new version of e.f. block-rbd.so into an old still running qemu binary.

This adds a fallback to also load modules from a versioned directory

in the

Quoted 2 lines
Quoted 2 lines

temporary /var/run path. That way qemu is providing a way for packaging to store modules of an upgraded qemu package as needed until the next

reboot.

Quoted 3 lines
Quoted 3 lines

An example how that can then be used in packaging can be seen in:

https://git.launchpad.net/~paelzer/ubuntu/+source/qemu/log/?h=bug-1847361-miss-old-so-on-upgrade-UBUNTU

Quoted 10 lines
Quoted 6 lines
---
 util/module.c | 7 +++++++
 1 file changed, 7 insertions(+)

CCing Debian, Fedora, and Red Hat package maintainers in case they have comments.

Quoted 6 lines

The use of /var/run makes me a little uneasy. I guess it's related to wanting to uninstall the old package so the .so in their original location cannot be used (even if they had a versioned path)?

I'm not a package maintainer though so I hope the others will make suggestions if there are other solutions :).

My first concern is that this only partially solves the quoted problem.

Consider the QEMU RBD module which is

   /usr/lib64/qemu/block-rbd.so

This links to

   /usr/lib64/librbd.so.1

On host OS upgrade, just before uninstalling old QEMU we copy RBD module into:

Quoted 6 lines
   /var/run/qemu-$VER/block-rbd.so

....but the host OS upgrade also upgrades RBD itself to a new major version which ships

   /usr/lib64/librbd.so.2

We've got /var/run/qemu-$VER/block-rbd.so saved, but we didn't

Quoted 10 lines

transitively save all the things that this linked to, so there's no guarantee it will still be possible to load it.

IOW, this approach of saving QEMU block modules to a scratch dir works, *provided* everything else that this QEMU block module needs still exists in a compatible form.

Some distros may have a policy that no incompatible soname bumps are permitted in updates, but that's not universal.

Hi Daniel,
Yeah for "us" being Ubuntu that would certainly be true.
An upgrade of librbd.so.1 to librbd.so.2 would only happen at a major upgrade.
For example in Ubuntu terms e.g. 18.04 to 20.04. Those upgrades usually come with a requirement to reboot anyway - I'm not trying to solve these.

The much more common and frequent small updates to qemu with individual fixes are what triggers this bug and what my proposal would solve.

On the other hand this is not a big amount of new code, so is not

Quoted 5 lines

a huge maint problem even if only a few people ever use it. I would be a bit more comfortable if this search path addition was perhaps enabled by an opt-in configure argument, rather than being always present.

I already suggested opt-in configure before.
I'd keep this just enable/disable unless we really can't agree on a path. That should be no big issue to add this in v2.

I'm also uneasy about the idea of using a search path ordering for

Quoted 7 lines

doing this. This means that an old running QEMU is always going to first try to load the block-rbd.so from the new QEMU, expect to see that fail, and only then fallback to load the block-rbd.so that actually matches its build.

IIRC, we have an embedded build-id in the modules that should guarantee that the first load attempt always fails, but I'm still

uneasy about that at a conceptual level.

Quoted 1 line

Yes that build-id is what prevents it loading the modules of the new package.

The intention was to keep this change small and not a burden for anyone. I'm not yet having an idea for a conceptual change that would avoid to rely on the build-id AND at the same time not make this a huge patch with probably many new issues we'll find out only much later.

Regards,

Quoted 10 lines

Daniel
--
|: https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-
https://fstop138.berrange.com :|
|: https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|

Signature · 3 lines
Christian Ehrhardt
Staff Engineer, Ubuntu Server
Canonical Ltd
#8 lore raw
In reply to Stefan Hajnoczi
Quoted 22 lines · Stefan Hajnoczi
Quoted 12 lines · Christian Ehrhardt

On upgrades the old .so files usually are replaced. But on the other hand since a qemu process represents a guest instance it is usually kept around.

That makes late addition of dynamic features e.g. 'hot-attach of a ceph disk' fail by trying to load a new version of e.f. block-rbd.so into an old still running qemu binary.

This adds a fallback to also load modules from a versioned directory in the temporary /var/run path. That way qemu is providing a way for packaging to store modules of an upgraded qemu package as needed until the next reboot.

Quoted 8 lines

An example how that can then be used in packaging can be seen in:
https://git.launchpad.net/~paelzer/ubuntu/+source/qemu/log/?h=bug-1847361-miss-old-so-on-upgrade-UBUNTU

---
 util/module.c | 7 +++++++
 1 file changed, 7 insertions(+)
Quoted 6 lines

CCing Debian, Fedora, and Red Hat package maintainers in case they have comments.

The use of /var/run makes me a little uneasy. I guess it's related to wanting to uninstall the old package so the .so in their original location cannot be used (even if they had a versioned path)?

BTW, this is /run nowadays, not /var/run, as far as I can see.

/mjt

#9 lore raw
Quoted 5 lines · Michael Tokarev
Quoted 3 lines

The use of /var/run makes me a little uneasy. I guess it's related to wanting to uninstall the old package so the .so in their original location cannot be used (even if they had a versioned path)?

BTW, this is /run nowadays, not /var/run, as far as I can see.

/var/run is still symlinked to /run. QEMU generally uses /var/run, though we could consider switching sooner or later.

Paolo

#10 lore raw
Quoted 9 lines · Paolo Bonzini
Quoted 5 lines · Michael Tokarev
Quoted 3 lines

The use of /var/run makes me a little uneasy. I guess it's related to wanting to uninstall the old package so the .so in their original location cannot be used (even if they had a versioned path)?

BTW, this is /run nowadays, not /var/run, as far as I can see.

/var/run is still symlinked to /run. QEMU generally uses /var/run, though we could consider switching sooner or later.

Only Linux commonly uses /run, others still use /var/run.

We really only need a "configure --rundir=/run" arg to override the default, in the same way distros pick /etc and /var, instead of /usr/etc and /usr/var.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|