On Thu, Jan 05, 2017 at 02:41:02PM +0100, Michal Privoznik wrote:
With my namespace patches, we are spawning qemu in its own
namespace so that we can manage /dev entries ourselves. However,
some filesystems mounted under /dev needs to be preserved in
order to be shared with the parent namespace (e.g. /dev/pts).
Currently, the list of mount points to preserve is hardcoded
which ain't right - on some systems there might be less or more
items under real /dev that on our list. The solution is to parse
/proc/mounts and fetch the list from there.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_domain.c | 126 +++++++++++++++++++++++++++++++------------------
1 file changed, 81 insertions(+), 45 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 67e8836f3b..e0631bf55a 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -200,33 +194,73 @@ qemuDomainEnableNamespace(virDomainObjPtr vm,
}
+/**
+ * qemuDomainGetPreservedMounts:
+ *
+ * Process list of mounted filesystems and:
+ * a) save all FSs mounted under /dev to @devPath
+ * b) generate backup path for all the entries in a)
+ *
+ * Any of the return pointers can be NULL.
+ *
+ * Returns 0 on success, -1 otherwise (with error reported)
+ */
static int
qemuDomainGetPreservedMounts(virQEMUDriverPtr driver,
virDomainObjPtr vm,
- char ***devMountsPath,
- size_t *ndevMountsPath)
+ char ***devPath,
+ char ***devSavePath,
+ size_t *ndevPath)
{
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
- char **paths;
- size_t i;
+ char **paths = NULL, **mounts = NULL;
+ size_t i, nmounts;
- if (VIR_ALLOC_N(paths, ARRAY_CARDINALITY(devPreserveMounts)) < 0)
+ if (virFileGetMountSubtree(PROC_MOUNTS, "/dev",
+ &mounts, &nmounts) < 0)
goto error;
- for (i = 0; i < ARRAY_CARDINALITY(devPreserveMounts); i++) {
+ if (!nmounts) {
+ if (ndevPath)
+ *ndevPath = 0;
+ return 0;
+ }
+
+ /* Okay, this is crazy. But virFileGetMountSubtree() fetched us all the
+ * mount points under /dev including /dev itself. Fortunately, the paths
+ * are sorted based in their length so we skip the first one (/dev) as it
"based on", abut it's not sorted by length, just sorted. But it will
work alright for this case.