If migratioin fails because of whatever reason and we've
pre-created any disks, we should remove them instead of letting
them lying around. Moreover, we need to save the disks sources
into domain status file in case libvirtd gets restarted.
---
src/qemu/qemu_domain.c | 30 ++++++++++++++++++++++++++++--
src/qemu/qemu_domain.h | 2 ++
src/qemu/qemu_migration.c | 13 +++++++++++++
src/qemu/qemu_process.c | 8 ++++++++
4 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 8df2739..66e0d82 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -231,10 +231,15 @@ error:
static void qemuDomainObjPrivateFree(void *data)
{
+ size_t i;
qemuDomainObjPrivatePtr priv = data;
virObjectUnref(priv->qemuCaps);
+ for (i = 0; i < priv->nnbdDisk; i++)
+ VIR_FREE(priv->nbdDisk[i]);
+ VIR_FREE(priv->nbdDisk);
+
qemuDomainPCIAddressSetFree(priv->pciaddrs);
virDomainChrSourceDefFree(priv->monConfig);
qemuDomainObjFreeJob(priv);
@@ -263,6 +268,7 @@ static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void
*data)
qemuDomainObjPrivatePtr priv = data;
const char *monitorpath;
enum qemuDomainJob job;
+ size_t i;
/* priv->monitor_chr is set only for qemu */
if (priv->monConfig) {
@@ -285,7 +291,6 @@ static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void
*data)
if (priv->nvcpupids) {
- int i;
virBufferAddLit(buf, " <vcpus>\n");
for (i = 0 ; i < priv->nvcpupids ; i++) {
virBufferAsprintf(buf, " <vcpu pid='%d'/>\n",
priv->vcpupids[i]);
@@ -294,7 +299,6 @@ static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void
*data)
}
if (priv->qemuCaps) {
- int i;
virBufferAddLit(buf, " <qemuCaps>\n");
for (i = 0 ; i < QEMU_CAPS_LAST ; i++) {
if (virQEMUCapsGet(priv->qemuCaps, i)) {
@@ -328,6 +332,13 @@ static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void
*data)
if (priv->fakeReboot)
virBufferAsprintf(buf, " <fakereboot/>\n");
+ if (priv->nnbdDisk) {
+ virBufferAddLit(buf, " <nbdDisk>\n");
+ for (i = 0; i < priv->nnbdDisk; i++)
+ virBufferAsprintf(buf, " <disk src='%s'/>\n",
priv->nbdDisk[i]);
+ virBufferAddLit(buf, " </nbdDisk>\n");
+ }
+
return 0;
}
@@ -473,6 +484,21 @@ static int qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void
*data)
priv->fakeReboot = virXPathBoolean("boolean(./fakereboot)", ctxt) == 1;
+ n = virXPathNodeSet("./nbdDisk/disk", ctxt, &nodes);
+ if (n < 0)
+ goto error;
+ if (n) {
+ if (VIR_REALLOC_N(priv->nbdDisk, n) < 0) {
+ virReportOOMError();
+ goto error;
+ }
+ priv->nnbdDisk = n;
+
+ for (i = 0; i < n; i++)
+ if (!(priv->nbdDisk[i] = virXMLPropString(nodes[i], "src")))
+ goto error;
+ }
+
return 0;
error:
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 4e20a49..83a2c1f 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -155,6 +155,8 @@ struct _qemuDomainObjPrivate {
unsigned long migMaxBandwidth;
char *origname;
int nbdPort; /* Port used for migration with NBD */
+ size_t nnbdDisk;
+ char **nbdDisk; /* src of disks we want to transfer via NBD */
virChrdevsPtr devs;
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 95b6102..fb4b7ac 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1565,6 +1565,7 @@ qemuMigrationPreCreateStorage(virQEMUDriverPtr driver,
virDomainObjPtr vm,
qemuMigrationCookiePtr mig)
{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
int ret = -1;
size_t i = 0;
@@ -1611,6 +1612,11 @@ qemuMigrationPreCreateStorage(virQEMUDriverPtr driver,
goto cleanup;
}
+ if ((VIR_REALLOC_N(priv->nbdDisk, priv->nnbdDisk + 1) < 0) ||
+ !(priv->nbdDisk[priv->nnbdDisk++] = strdup(disk->src))) {
+ virReportOOMError();
+ goto cleanup;
+ }
}
ret = 0;
@@ -4055,6 +4061,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
qemuDomainObjPrivatePtr priv = vm->privateData;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virCapsPtr caps = NULL;
+ size_t i;
VIR_DEBUG("driver=%p, dconn=%p, vm=%p, cookiein=%s, cookieinlen=%d, "
"cookieout=%p, cookieoutlen=%p, flags=%lx, retcode=%d",
@@ -4208,6 +4215,12 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
VIR_DOMAIN_EVENT_SUSPENDED,
VIR_DOMAIN_EVENT_SUSPENDED_PAUSED);
}
+
+ /* Free disks transferred via NBD so they don't get deleted */
+ for (i = 0; i < priv->nnbdDisk; i++)
+ VIR_FREE(priv->nbdDisk[i]);
+ VIR_FREE(priv->nbdDisk);
+ priv->nnbdDisk = 0;
}
if (virDomainObjIsActive(vm) &&
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index e6874e2..9fa7004 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4242,6 +4242,14 @@ void qemuProcessStop(virQEMUDriverPtr driver,
priv->nbdPort = 0;
}
+ for (i = 0; i < priv->nnbdDisk; i++) {
+ VIR_DEBUG("Unlinking %s due to unsuccessful NBD transfer",
+ priv->nbdDisk[i]);
+ if (unlink(priv->nbdDisk[i]) < 0)
+ virReportSystemError(errno, _("Unable to unlink %s"),
+ priv->nbdDisk[i]);
+ }
+
if (priv->agent) {
qemuAgentClose(priv->agent);
priv->agent = NULL;
--
1.8.0.2