]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Provide sane default for dump_guest_core
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 18 Sep 2024 13:32:45 +0000 (15:32 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 25 Sep 2024 06:38:09 +0000 (08:38 +0200)
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@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
meson.build
src/qemu/qemu.conf.in
src/qemu/qemu_conf.c
tests/testutilsqemu.c

index cfdccd1d05d0f224f0560c7a58c13f5368062b0a..582a178c780da6cbcc51f01ede9daa2b0243e581 100644 (file)
@@ -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',
index e1f304617719fb69d2ae030ca3cccd393056890a..59af58b4d4ca99690564d36a21dfd547ead311c8 100644 (file)
 
 # 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.
index 0d90a87392028d219de884dd7987d9cec272dfdb..a912790c3c21517aad51aad3224991f32e67a50b 100644 (file)
 #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);
 }
 
index ee6cae218adbd3fc6c722d95b927b4b9947359c8..4daee432e5e85e55291e023d86eba6f6beca4c87 100644 (file)
@@ -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;