Create libvirt managed saveDir and pass it to CH to save the VM
Signed-off-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi(a)linux.microsoft.com>
---
src/ch/ch_conf.c | 6 ++++++
src/ch/ch_conf.h | 1 +
src/ch/ch_driver.c | 51 +++++++++++++++++++++++++++++++++++++++++++++
src/ch/ch_monitor.c | 7 +++++++
4 files changed, 65 insertions(+)
diff --git a/src/ch/ch_conf.c b/src/ch/ch_conf.c
index a7b2285886..cab97639c4 100644
--- a/src/ch/ch_conf.c
+++ b/src/ch/ch_conf.c
@@ -148,10 +148,12 @@ virCHDriverConfigNew(bool privileged)
if (privileged) {
cfg->logDir = g_strdup_printf("%s/log/libvirt/ch", LOCALSTATEDIR);
cfg->stateDir = g_strdup_printf("%s/libvirt/ch", RUNSTATEDIR);
+ cfg->saveDir = g_strdup_printf("%s/lib/libvirt/ch/save",
LOCALSTATEDIR);
} else {
g_autofree char *rundir = NULL;
g_autofree char *cachedir = NULL;
+ g_autofree char *configbasedir = NULL;
cachedir = virGetUserCacheDirectory();
@@ -159,6 +161,9 @@ virCHDriverConfigNew(bool privileged)
rundir = virGetUserRuntimeDirectory();
cfg->stateDir = g_strdup_printf("%s/ch/run", rundir);
+
+ configbasedir = virGetUserConfigDirectory();
+ cfg->saveDir = g_strdup_printf("%s/ch/save", configbasedir);
}
return cfg;
@@ -175,6 +180,7 @@ virCHDriverConfigDispose(void *obj)
{
virCHDriverConfig *cfg = obj;
+ g_free(cfg->saveDir);
g_free(cfg->stateDir);
g_free(cfg->logDir);
}
diff --git a/src/ch/ch_conf.h b/src/ch/ch_conf.h
index 4b4c3345b6..a77cad7a2a 100644
--- a/src/ch/ch_conf.h
+++ b/src/ch/ch_conf.h
@@ -37,6 +37,7 @@ struct _virCHDriverConfig {
char *stateDir;
char *logDir;
+ char *saveDir;
int cgroupControllers;
diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c
index 24f697d2e1..be6e25c8e2 100644
--- a/src/ch/ch_driver.c
+++ b/src/ch/ch_driver.c
@@ -178,6 +178,14 @@ static char *chConnectGetCapabilities(virConnectPtr conn)
return xml;
}
+static char *
+chDomainManagedSavePath(virCHDriver *driver, virDomainObj *vm)
+{
+ g_autoptr(virCHDriverConfig) cfg = virCHDriverGetConfig(driver);
+ return g_strdup_printf("%s/%s.save", cfg->saveDir,
vm->def->name);
+}
+
+
/**
* chDomainCreateXML:
* @conn: pointer to connection
@@ -763,6 +771,48 @@ chDomainSave(virDomainPtr dom, const char *to)
return chDomainSaveFlags(dom, to, NULL, 0);
}
+static int
+chDomainManagedSave(virDomainPtr dom, unsigned int flags)
+{
+ virCHDriver *driver = dom->conn->privateData;
+ virDomainObj *vm = NULL;
+ g_autofree char *to = NULL;
+ int ret = -1;
+
+ virCheckFlags(0, -1);
+
+ if (!(vm = virCHDomainObjFromDomain(dom)))
+ goto cleanup;
+
+ if (virDomainManagedSaveEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+ if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
+ goto cleanup;
+
+ if (virDomainObjCheckActive(vm) < 0)
+ goto endjob;
+
+ if (!vm->persistent) {
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("cannot do managed save for transient domain"));
+ goto endjob;
+ }
+
+ to = chDomainManagedSavePath(driver, vm);
+ if (chDoDomainSave(driver, vm, to, true) < 0)
+ goto endjob;
+
+ ret = 0;
+
+ endjob:
+ virDomainObjEndJob(vm);
+
+ cleanup:
+ virDomainObjEndAPI(&vm);
+ return ret;
+}
+
static virDomainPtr chDomainLookupByID(virConnectPtr conn,
int id)
{
@@ -1887,6 +1937,7 @@ static virHypervisorDriver chHypervisorDriver = {
.domainGetNumaParameters = chDomainGetNumaParameters, /* 8.1.0 */
.domainSave = chDomainSave, /* 10.2.0 */
.domainSaveFlags = chDomainSaveFlags, /* 10.2.0 */
+ .domainManagedSave = chDomainManagedSave, /* 10.2.0 */
};
static virConnectDriver chConnectDriver = {
diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c
index 939fa13667..7b6b77de1c 100644
--- a/src/ch/ch_monitor.c
+++ b/src/ch/ch_monitor.c
@@ -557,6 +557,13 @@ virCHMonitorNew(virDomainObj *vm, virCHDriverConfig *cfg)
return NULL;
}
+ if (g_mkdir_with_parents(cfg->saveDir, 0777) < 0) {
+ virReportSystemError(errno,
+ _("Cannot create save directory '%1$s'"),
+ cfg->saveDir);
+ return NULL;
+ }
+
cmd = virCommandNew(vm->def->emulator);
virCommandSetUmask(cmd, 0x002);
socket_fd = chMonitorCreateSocket(mon->socketpath);
--
2.34.1