提交 78f3666f 编写于 作者: M Martin Kletzander

Add support for limiting guest coredump

Sometimes when guest machine crashes, coredump can get huge due to the
guest memory. This can be limited using madvise(2) system call and is
being used in QEMU hypervisor. This patch adds an option for configuring
that in the domain XML and related documentation.
上级 ec62a602
...@@ -515,9 +515,15 @@ ...@@ -515,9 +515,15 @@
However, the value will be rounded up to the nearest kibibyte However, the value will be rounded up to the nearest kibibyte
by libvirt, and may be further rounded to the granularity by libvirt, and may be further rounded to the granularity
supported by the hypervisor. Some hypervisors also enforce a supported by the hypervisor. Some hypervisors also enforce a
minimum, such as minimum, such as 4000KiB.
4000KiB. <span class='since'><code>unit</code> since
0.9.11</span></dd> In the case of crash, optional attribute <code>dumpCore</code>
can be used to control whether the guest memory should be
included in the generated coredump or not (values "on", "off").
<span class='since'><code>unit</code> since 0.9.11</span>,
<span class='since'><code>dumpCore</code> since 0.10.2
(QEMU only)</span></dd>
<dt><code>currentMemory</code></dt> <dt><code>currentMemory</code></dt>
<dd>The actual allocation of memory for the guest. This value can <dd>The actual allocation of memory for the guest. This value can
be less than the maximum allocation, to allow for ballooning be less than the maximum allocation, to allow for ballooning
......
...@@ -470,6 +470,14 @@ ...@@ -470,6 +470,14 @@
<interleave> <interleave>
<element name="memory"> <element name="memory">
<ref name='scaledInteger'/> <ref name='scaledInteger'/>
<optional>
<attribute name="dumpCore">
<choice>
<value>on</value>
<value>off</value>
</choice>
</attribute>
</optional>
</element> </element>
<optional> <optional>
<element name="currentMemory"> <element name="currentMemory">
......
...@@ -381,6 +381,11 @@ VIR_ENUM_IMPL(virDomainSoundModel, VIR_DOMAIN_SOUND_MODEL_LAST, ...@@ -381,6 +381,11 @@ VIR_ENUM_IMPL(virDomainSoundModel, VIR_DOMAIN_SOUND_MODEL_LAST,
"ac97", "ac97",
"ich6") "ich6")
VIR_ENUM_IMPL(virDomainMemDump, VIR_DOMAIN_MEM_DUMP_LAST,
"default",
"on",
"off")
VIR_ENUM_IMPL(virDomainMemballoonModel, VIR_DOMAIN_MEMBALLOON_MODEL_LAST, VIR_ENUM_IMPL(virDomainMemballoonModel, VIR_DOMAIN_MEMBALLOON_MODEL_LAST,
"virtio", "virtio",
"xen", "xen",
...@@ -8524,6 +8529,18 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, ...@@ -8524,6 +8529,18 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
&def->mem.cur_balloon, false) < 0) &def->mem.cur_balloon, false) < 0)
goto error; goto error;
/* and info about it */
tmp = virXPathString("string(./memory[1]/@dumpCore)", ctxt);
if (tmp) {
def->mem.dump_core = virDomainMemDumpTypeFromString(tmp);
if (def->mem.dump_core <= 0) {
virReportError(VIR_ERR_XML_ERROR, _("Bad value '%s'"), tmp);
goto error;
}
VIR_FREE(tmp);
}
if (def->mem.cur_balloon > def->mem.max_balloon) { if (def->mem.cur_balloon > def->mem.max_balloon) {
/* Older libvirt could get into this situation due to /* Older libvirt could get into this situation due to
* rounding; if the discrepancy is less than 1MiB, we silently * rounding; if the discrepancy is less than 1MiB, we silently
...@@ -13266,8 +13283,13 @@ virDomainDefFormatInternal(virDomainDefPtr def, ...@@ -13266,8 +13283,13 @@ virDomainDefFormatInternal(virDomainDefPtr def,
xmlIndentTreeOutput = oldIndentTreeOutput; xmlIndentTreeOutput = oldIndentTreeOutput;
} }
virBufferAsprintf(buf, " <memory unit='KiB'>%llu</memory>\n", virBufferAddLit(buf, " <memory");
if (def->mem.dump_core)
virBufferAsprintf(buf, " dumpCore='%s'",
virDomainMemDumpTypeToString(def->mem.dump_core));
virBufferAsprintf(buf, " unit='KiB'>%llu</memory>\n",
def->mem.max_balloon); def->mem.max_balloon);
virBufferAsprintf(buf, " <currentMemory unit='KiB'>%llu</currentMemory>\n", virBufferAsprintf(buf, " <currentMemory unit='KiB'>%llu</currentMemory>\n",
def->mem.cur_balloon); def->mem.cur_balloon);
......
...@@ -1320,6 +1320,14 @@ struct _virDomainRedirFilterDef { ...@@ -1320,6 +1320,14 @@ struct _virDomainRedirFilterDef {
virDomainRedirFilterUsbDevDefPtr *usbdevs; virDomainRedirFilterUsbDevDefPtr *usbdevs;
}; };
enum virDomainMemDump {
VIR_DOMAIN_MEM_DUMP_DEFAULT = 0,
VIR_DOMAIN_MEM_DUMP_ON,
VIR_DOMAIN_MEM_DUMP_OFF,
VIR_DOMAIN_MEM_DUMP_LAST,
};
enum { enum {
VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO, VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO,
VIR_DOMAIN_MEMBALLOON_MODEL_XEN, VIR_DOMAIN_MEMBALLOON_MODEL_XEN,
...@@ -1641,6 +1649,7 @@ struct _virDomainDef { ...@@ -1641,6 +1649,7 @@ struct _virDomainDef {
unsigned long long max_balloon; /* in kibibytes */ unsigned long long max_balloon; /* in kibibytes */
unsigned long long cur_balloon; /* in kibibytes */ unsigned long long cur_balloon; /* in kibibytes */
bool hugepage_backed; bool hugepage_backed;
int dump_core; /* enum virDomainMemDump */
unsigned long long hard_limit; /* in kibibytes */ unsigned long long hard_limit; /* in kibibytes */
unsigned long long soft_limit; /* in kibibytes */ unsigned long long soft_limit; /* in kibibytes */
unsigned long long min_guarantee; /* in kibibytes */ unsigned long long min_guarantee; /* in kibibytes */
...@@ -2177,6 +2186,7 @@ VIR_ENUM_DECL(virDomainChrTcpProtocol) ...@@ -2177,6 +2186,7 @@ VIR_ENUM_DECL(virDomainChrTcpProtocol)
VIR_ENUM_DECL(virDomainChrSpicevmc) VIR_ENUM_DECL(virDomainChrSpicevmc)
VIR_ENUM_DECL(virDomainSoundCodec) VIR_ENUM_DECL(virDomainSoundCodec)
VIR_ENUM_DECL(virDomainSoundModel) VIR_ENUM_DECL(virDomainSoundModel)
VIR_ENUM_DECL(virDomainMemDump)
VIR_ENUM_DECL(virDomainMemballoonModel) VIR_ENUM_DECL(virDomainMemballoonModel)
VIR_ENUM_DECL(virDomainSmbiosMode) VIR_ENUM_DECL(virDomainSmbiosMode)
VIR_ENUM_DECL(virDomainWatchdogModel) VIR_ENUM_DECL(virDomainWatchdogModel)
......
...@@ -426,6 +426,8 @@ virDomainLiveConfigHelperMethod; ...@@ -426,6 +426,8 @@ virDomainLiveConfigHelperMethod;
virDomainLoadAllConfigs; virDomainLoadAllConfigs;
virDomainMemballoonModelTypeFromString; virDomainMemballoonModelTypeFromString;
virDomainMemballoonModelTypeToString; virDomainMemballoonModelTypeToString;
virDomainMemDumpTypeFromString;
virDomainMemDumpTypeToString;
virDomainNetDefFree; virDomainNetDefFree;
virDomainNetFind; virDomainNetFind;
virDomainNetGetActualBandwidth; virDomainNetGetActualBandwidth;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册