QEMU uses Linux extensions to madvise() to include/exclue guest
memory from core dump. These are obviously not available
everywhere. Currently, users have two options:
1) configure <memory dumpCore=''/> in domain XML, or
2) configure dump_guest_core in qemu.conf
While these work, they may harm user experience as "things just
don't work" out of the box. Provide sane default in
virQEMUDriverConfigNew() so neither of two options is required.
To have predictable results in tests, explicitly set
cfg->dumpGuestCore to false in qemuTestDriverInit() (which
creates cfg object for tests).
Resolves:
https://gitlab.com/libvirt/libvirt/-/issues/679
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
meson.build | 1 +
src/qemu/qemu_conf.c | 11 +++++++++++
tests/testutilsqemu.c | 2 ++
3 files changed, 14 insertions(+)
diff --git a/meson.build b/meson.build
index 4c6e5a088e..aa6b8ce5aa 100644
--- a/meson.build
+++ b/meson.build
@@ -676,6 +676,7 @@ headers = [
'sched.h',
'sys/auxv.h',
'sys/ioctl.h',
+ 'sys/mman.h',
'sys/mount.h',
'sys/syscall.h',
'sys/ucred.h',
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index b36bede6c3..2c4e6a74cb 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -26,6 +26,10 @@
#include <unistd.h>
#include <fcntl.h>
+#ifdef WITH_SYS_MMAN_H
+# include <sys/mman.h>
+#endif
+
#include "virerror.h"
#include "qemu_conf.h"
#include "qemu_capabilities.h"
@@ -287,6 +291,13 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged,
cfg->deprecationBehavior = g_strdup("none");
cfg->storageUseNbdkit = USE_NBDKIT_DEFAULT;
+#ifndef MADV_DONTDUMP
+ /* QEMU uses Linux extensions to madvise() (MADV_DODUMP/MADV_DONTDUMP) to
+ * include/exclude guest memory from core dump. These might be unavailable
+ * on some systems. Provide sane default. */
+ cfg->dumpGuestCore = true;
+#endif
+
return g_steal_pointer(&cfg);
}
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index ee6cae218a..4daee432e5 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -407,6 +407,8 @@ int qemuTestDriverInit(virQEMUDriver *driver)
cfg->hugetlbfs[0].deflt = true;
cfg->hugetlbfs[1].size = 1048576;
+ cfg->dumpGuestCore = false;
+
driver->privileged = true;
return 0;
--
2.44.2