From 4f74c4a69785432258ad5ea5e695d1b94aaa5b30 Mon Sep 17 00:00:00 2001
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu(a)jp.fujitsu.com>
Date: Thu, 28 Oct 2010 16:31:46 +0900
Subject: [PATCH 1/2] add compression support for "virsh dump"
Add dump_image_format[] to qemu.conf and support compressed dump
at virsh dump. coredump compression is important for saving disk space
in an environment where multiple guests run.
In general, "disk space for dump" is specially allocated and will be
a dead space in the system. It's used only at emergency. So, it's better
to have both of save_image_format and dump_image_format. "save" is done
in scheduled manner with enough calculated disk space for it.
This code reuses some of save_image_format[] and supports the same format.
Changelog:
- modified libvirtd_qemu.aug
- modified test_libvirtd_qemu.aug
- fixed error handling of qemudSaveCompressionTypeFromString()
---
src/qemu/libvirtd_qemu.aug | 1 +
src/qemu/qemu.conf | 4 +++
src/qemu/qemu_conf.c | 11 ++++++++++
src/qemu/qemu_conf.h | 1 +
src/qemu/qemu_driver.c | 41 ++++++++++++++++++++++++++++++++------
src/qemu/test_libvirtd_qemu.aug | 2 +
6 files changed, 53 insertions(+), 7 deletions(-)
diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index b9ace3e..66994fd 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -36,6 +36,7 @@ module Libvirtd_qemu =
| str_array_entry "cgroup_controllers"
| str_array_entry "cgroup_device_acl"
| str_entry "save_image_format"
+ | str_entry "dump_image_format"
| str_entry "hugetlbfs_mount"
| bool_entry "relaxed_acs_check"
| bool_entry "vnc_allow_host_audio"
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index 53b76e7..e2c581e 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -145,7 +145,11 @@
# saving a domain in order to save disk space; the list above is in descending
# order by performance and ascending order by compression ratio.
#
+# save_image_format is used when you use 'virsh save' at scheduled saving.
+# dump_image_format is used when you use 'virsh dump' at emergency crashdump.
+#
# save_image_format = "raw"
+# dump_image_format = "raw"
# If provided by the host and a hugetlbfs mount point is configured,
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 5bd3d4c..b5c17b5 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -325,6 +325,17 @@ int qemudLoadDriverConfig(struct qemud_driver *driver,
}
}
+ p = virConfGetValue (conf, "dump_image_format");
+ CHECK_TYPE ("dump_image_format", VIR_CONF_STRING);
+ if (p && p->str) {
+ VIR_FREE(driver->dumpImageFormat);
+ if (!(driver->dumpImageFormat = strdup(p->str))) {
+ virReportOOMError();
+ virConfFree(conf);
+ return -1;
+ }
+ }
+
p = virConfGetValue (conf, "hugetlbfs_mount");
CHECK_TYPE ("hugetlbfs_mount", VIR_CONF_STRING);
if (p && p->str) {
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 530dcdb..bbe6887 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -164,6 +164,7 @@ struct qemud_driver {
virSecurityDriverPtr securitySecondaryDriver;
char *saveImageFormat;
+ char *dumpImageFormat;
pciDeviceList *activePciHostdevs;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b119ca1..51ad50b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5907,11 +5907,22 @@ static int qemudDomainCoreDump(virDomainPtr dom,
int resume = 0, paused = 0;
int ret = -1, fd = -1;
virDomainEventPtr event = NULL;
- const char *args[] = {
- "cat",
- NULL,
- };
+ int compress;
qemuDomainObjPrivatePtr priv;
+ /*
+ * We reuse "save" flag for "dump" here. Then, we can support the
same
+ * format in "save" and "dump".
+ */
+ compress = QEMUD_SAVE_FORMAT_RAW;
+ if (driver->dumpImageFormat) {
+ compress = qemudSaveCompressionTypeFromString(driver->dumpImageFormat);
+ if (compress < 0) {
+ qemuReportError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("Invalid dump image format specified in "
+ "configuration file"));
+ return -1;
+ }
+ }
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -5978,9 +5989,25 @@ static int qemudDomainCoreDump(virDomainPtr dom,
}
qemuDomainObjEnterMonitorWithDriver(driver, vm);
- ret = qemuMonitorMigrateToFile(priv->mon,
- QEMU_MONITOR_MIGRATE_BACKGROUND,
- args, path, 0);
+ if (compress == QEMUD_SAVE_FORMAT_RAW) {
+ const char *args[] = {
+ "cat",
+ NULL,
+ };
+ ret = qemuMonitorMigrateToFile(priv->mon,
+ QEMU_MONITOR_MIGRATE_BACKGROUND,
+ args, path, 0);
+ } else {
+ const char *prog = qemudSaveCompressionTypeToString(compress);
+ const char *args[] = {
+ prog,
+ "-c",
+ NULL,
+ };
+ ret = qemuMonitorMigrateToFile(priv->mon,
+ QEMU_MONITOR_MIGRATE_BACKGROUND,
+ args, path, 0);
+ }
qemuDomainObjExitMonitorWithDriver(driver, vm);
if (ret < 0)
goto endjob;
diff --git a/src/qemu/test_libvirtd_qemu.aug b/src/qemu/test_libvirtd_qemu.aug
index 6788346..efbf642 100644
--- a/src/qemu/test_libvirtd_qemu.aug
+++ b/src/qemu/test_libvirtd_qemu.aug
@@ -94,6 +94,8 @@ cgroup_device_acl = [ \"/dev/null\", \"/dev/full\",
\"/dev/zero\" ]
save_image_format = \"gzip\"
+dump_image_format = \"gzip\"
+
hugetlbfs_mount = \"/dev/hugepages\"
set_process_name = 1
--
1.7.2.3