[PATCH v2 2/2] qemu: Provide sane default for dump_guest_core

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



QEMU uses Linux extensions to madvise() to include/exclude 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@xxxxxxxxxx>
---
 meson.build           |  1 +
 src/qemu/qemu.conf.in |  4 ++--
 src/qemu/qemu_conf.c  | 12 ++++++++++++
 tests/testutilsqemu.c |  2 ++
 4 files changed, 17 insertions(+), 2 deletions(-)

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.in b/src/qemu/qemu.conf.in
index e1f3046177..59af58b4d4 100644
--- a/src/qemu/qemu.conf.in
+++ b/src/qemu/qemu.conf.in
@@ -710,8 +710,8 @@
 
 # Determine if guest RAM is included in QEMU core dumps. By
 # default guest RAM will be excluded if a new enough QEMU is
-# present. Setting this to '1' will force guest RAM to always
-# be included in QEMU core dumps.
+# present and host kernel supports it. Setting this to '1' will
+# force guest RAM to always be included in QEMU core dumps.
 #
 # This setting will be ignored if the guest XML has set the
 # dumpCore attribute on the <memory> element.
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index b36bede6c3..0f09e22730 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,14 @@ 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. */
+    VIR_INFO("Host kernel doesn't support MADV_DONTDUMP. Enabling dump_guest_core");
+    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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux