]> git.ipfire.org Git - thirdparty/libvirt.git/commit
qemu_namespace: Fix a corner case in qemuDomainGetPreservedMounts()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 6 Sep 2022 11:43:22 +0000 (13:43 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 23 Sep 2022 14:32:51 +0000 (16:32 +0200)
commit46b03819ae8d833b11c2aaccb2c2a0361727f51b
tree75167f0d7570e025babe0b0ddb2a19f51a3dfa1e
parent687374959e160dc566bd4b6d43c7bf1beb470c59
qemu_namespace: Fix a corner case in qemuDomainGetPreservedMounts()

When setting up namespace for QEMU we look at mount points under
/dev (like /dev/pts, /dev/mqueue/, etc.) because we want to
preserve those (which is done by moving them to a temp location,
unshare(), and then moving them back). We have a convenience
helper - qemuDomainGetPreservedMounts() - that processes the
mount table and (optionally) moves the other filesystems too.
This helper is also used when attempting to create a path in NS,
because the path, while starting with "/dev/" prefix, may
actually lead to one of those filesystems that we preserved.

And here comes the corner case: while we require the parent mount
table to be in shared mode (equivalent of `mount --make-rshared /'),
these mount events propagate iff the target path exist inside the
slave mount table (= QEMU's private namespace). And since we
create only a subset of /dev nodes, well, that assumption is not
always the case.

For instance, assume that a domain is already running, no
hugepages were configured for it nor any hugetlbfs is mounted.
Now, when a hugetlbfs is mounted into '/dev/hugepages', this is
propagated into the QEMU's namespace, but since the target dir
does not exist in the private /dev, the FS is not mounted in the
namespace.

Fortunately, this difference between namespaces is visible when
comparing /proc/mounts and /proc/$PID/mounts (where PID is the
QEMU's PID). Therefore, if possible we should look at the latter.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/qemu/qemu_namespace.c