Browse code

Enable libvirt coredumps

This adds a flag and basic config for enabling coredumps for libvirt.

Partial-Bug: 1643911
Co-Authored-By: Matthew Booth <mbooth@redhat.com>

Change-Id: If7cd54e804a5a389a0d82a325b58f5b41b8ef0db

Ian Wienand authored on 2017/03/29 09:52:06
Showing 2 changed files
... ...
@@ -20,8 +20,46 @@ set +o xtrace
20 20
 # extremely verbose.)
21 21
 DEBUG_LIBVIRT=$(trueorfalse True DEBUG_LIBVIRT)
22 22
 
23
+# Try to enable coredumps for libvirt
24
+# Currently fairly specific to OpenStackCI hosts
25
+DEBUG_LIBVIRT_COREDUMPS=$(trueorfalse False DEBUG_LIBVIRT_COREDUMPS)
26
+
27
+# Only Xenial is left with libvirt-bin.  Everywhere else is libvirtd
28
+if is_ubuntu && [ ! -f /etc/init.d/libvirtd ]; then
29
+    LIBVIRT_DAEMON=libvirt-bin
30
+else
31
+    LIBVIRT_DAEMON=libvirtd
32
+fi
33
+
34
+# Enable coredumps for libvirt
35
+#  Bug: https://bugs.launchpad.net/nova/+bug/1643911
36
+function _enable_coredump {
37
+    local confdir=/etc/systemd/system/${LIBVIRT_DAEMON}.service.d
38
+    local conffile=${confdir}/coredump.conf
39
+
40
+    # Create a coredump directory, and instruct the kernel to save to
41
+    # here
42
+    sudo mkdir -p /var/core
43
+    sudo chmod a+wrx /var/core
44
+    echo '/var/core/core.%e.%p.%h.%t' | \
45
+        sudo tee /proc/sys/kernel/core_pattern
46
+
47
+    # Drop a config file to up the core ulimit
48
+    sudo mkdir -p ${confdir}
49
+    sudo tee ${conffile} <<EOF
50
+[Service]
51
+LimitCORE=infinity
52
+EOF
53
+
54
+    # Tell systemd to reload the unit (service restarts later after
55
+    # config anyway)
56
+    sudo systemctl daemon-reload
57
+}
58
+
59
+
23 60
 # Installs required distro-specific libvirt packages.
24 61
 function install_libvirt {
62
+
25 63
     if is_ubuntu; then
26 64
         install_package qemu-system
27 65
         install_package libvirt-bin libvirt-dev
... ...
@@ -48,7 +86,10 @@ function install_libvirt {
48 48
 
49 49
         install_package libvirt libvirt-devel
50 50
         pip_install_gr libvirt-python
51
+    fi
51 52
 
53
+    if [[ $DEBUG_LIBVIRT_COREDUMPS == True ]]; then
54
+        _enable_coredump
52 55
     fi
53 56
 }
54 57
 
... ...
@@ -68,14 +109,6 @@ cgroup_device_acl = [
68 68
 EOF
69 69
     fi
70 70
 
71
-    # Since the release of Debian Wheezy the libvirt init script is libvirtd
72
-    # and not libvirtd-bin anymore.
73
-    if is_ubuntu && [ ! -f /etc/init.d/libvirtd ]; then
74
-        LIBVIRT_DAEMON=libvirt-bin
75
-    else
76
-        LIBVIRT_DAEMON=libvirtd
77
-    fi
78
-
79 71
     if is_fedora || is_suse; then
80 72
         # Starting with fedora 18 and opensuse-12.3 enable stack-user to
81 73
         # virsh -c qemu:///system by creating a policy-kit rule for
... ...
@@ -223,6 +223,14 @@ def guru_meditation_reports():
223 223
         print("guru meditation report in %s log" % service)
224 224
 
225 225
 
226
+def var_core():
227
+    if os.path.exists('/var/core'):
228
+        _header("/var/core dumps")
229
+        # NOTE(ianw) : see DEBUG_LIBVIRT_COREDUMPS.  We could think
230
+        # about getting backtraces out of these.  There are other
231
+        # tools out there that can do that sort of thing though.
232
+        _dump_cmd("ls -ltrah /var/core")
233
+
226 234
 def main():
227 235
     opts = get_options()
228 236
     fname = filename(opts.dir, opts.name)
... ...
@@ -238,6 +246,7 @@ def main():
238 238
         ebtables_dump()
239 239
         compute_consoles()
240 240
         guru_meditation_reports()
241
+        var_core()
241 242
 
242 243
 
243 244
 if __name__ == '__main__':