[libvirt] [PATCH v3 3/5] Add a new function doCoreDump
Hu Tao
hutao at cn.fujitsu.com
Tue Nov 30 07:13:02 UTC 2010
This patch prepares for the next patch.
---
src/qemu/qemu_driver.c | 145 ++++++++++++++++++++++++++----------------------
1 files changed, 78 insertions(+), 67 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ad67e52..80ce9f6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -138,6 +138,7 @@ struct _qemuDomainObjPrivate {
};
static int getCompressionType(struct qemud_driver *driver);
+static int doCoreDump(struct qemud_driver *driver, virDomainObjPtr vm, const char *path, int compress);
static int qemudShutdown(void);
@@ -6057,6 +6058,81 @@ cleanup:
return ret;
}
+static int doCoreDump(struct qemud_driver *driver, virDomainObjPtr vm, const char *path, int compress)
+{
+ int fd = -1;
+ int ret = -1;
+ qemuDomainObjPrivatePtr priv;
+
+ priv = vm->privateData;
+
+ if (!virDomainObjIsActive(vm)) {
+ qemuReportError(VIR_ERR_OPERATION_INVALID,
+ "%s", _("domain is not running"));
+ goto endjob;
+ }
+
+ /* Create an empty file with appropriate ownership. */
+ if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
+ qemuReportError(VIR_ERR_OPERATION_FAILED,
+ _("failed to create '%s'"), path);
+ goto endjob;
+ }
+
+ if (VIR_CLOSE(fd) < 0) {
+ virReportSystemError(errno,
+ _("unable to save file %s"),
+ path);
+ goto endjob;
+ }
+
+ if (driver->securityDriver &&
+ driver->securityDriver->domainSetSavedStateLabel &&
+ driver->securityDriver->domainSetSavedStateLabel(driver->securityDriver,
+ vm, path) == -1)
+ goto endjob;
+
+ qemuDomainObjEnterMonitorWithDriver(driver, vm);
+ 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;
+
+ ret = qemuDomainWaitForMigrationComplete(driver, vm);
+
+ if (ret < 0)
+ goto endjob;
+
+ if (driver->securityDriver &&
+ driver->securityDriver->domainRestoreSavedStateLabel &&
+ driver->securityDriver->domainRestoreSavedStateLabel(driver->securityDriver,
+ vm, path) == -1)
+ goto endjob;
+
+endjob:
+ if (ret != 0)
+ unlink(path);
+ return ret;
+}
+
static int getCompressionType(struct qemud_driver *driver)
{
int compress;
@@ -6090,13 +6166,10 @@ static int qemudDomainCoreDump(virDomainPtr dom,
struct qemud_driver *driver = dom->conn->privateData;
virDomainObjPtr vm;
int resume = 0, paused = 0;
- int ret = -1, fd = -1;
+ int ret = -1;
virDomainEventPtr event = NULL;
- int compress;
qemuDomainObjPrivatePtr priv;
- compress = getCompressionType(driver);
-
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -6109,35 +6182,6 @@ static int qemudDomainCoreDump(virDomainPtr dom,
}
priv = vm->privateData;
- if (qemuDomainObjBeginJobWithDriver(driver, vm) < 0)
- goto cleanup;
-
- if (!virDomainObjIsActive(vm)) {
- qemuReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("domain is not running"));
- goto endjob;
- }
-
- /* Create an empty file with appropriate ownership. */
- if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
- qemuReportError(VIR_ERR_OPERATION_FAILED,
- _("failed to create '%s'"), path);
- goto endjob;
- }
-
- if (VIR_CLOSE(fd) < 0) {
- virReportSystemError(errno,
- _("unable to save file %s"),
- path);
- goto endjob;
- }
-
- if (driver->securityDriver &&
- driver->securityDriver->domainSetSavedStateLabel &&
- driver->securityDriver->domainSetSavedStateLabel(driver->securityDriver,
- vm, path) == -1)
- goto endjob;
-
/* Migrate will always stop the VM, so the resume condition is
independent of whether the stop command is issued. */
resume = (vm->state == VIR_DOMAIN_RUNNING);
@@ -6161,43 +6205,12 @@ static int qemudDomainCoreDump(virDomainPtr dom,
}
}
- qemuDomainObjEnterMonitorWithDriver(driver, vm);
- 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;
-
- ret = qemuDomainWaitForMigrationComplete(driver, vm);
-
+ ret = doCoreDump(driver, vm, path, getCompressionType(driver));
if (ret < 0)
goto endjob;
paused = 1;
- if (driver->securityDriver &&
- driver->securityDriver->domainRestoreSavedStateLabel &&
- driver->securityDriver->domainRestoreSavedStateLabel(driver->securityDriver,
- vm, path) == -1)
- goto endjob;
-
endjob:
if ((ret == 0) && (flags & VIR_DUMP_CRASH)) {
qemudShutdownVMDaemon(driver, vm, 0);
@@ -6230,8 +6243,6 @@ endjob:
}
cleanup:
- if (ret != 0)
- unlink(path);
if (vm)
virDomainObjUnlock(vm);
if (event)
--
1.7.3
--
Thanks,
Hu Tao
More information about the libvir-list
mailing list