mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
ch_driver: Add domainManagedSave callback
Create libvirt managed saveDir and pass it to CH to save the VM Signed-off-by: Purna Pavan Chandra Aekkaladevi <paekkaladevi@linux.microsoft.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
c22fb87b05
commit
d07cdc0f48
@ -148,10 +148,12 @@ virCHDriverConfigNew(bool privileged)
|
|||||||
if (privileged) {
|
if (privileged) {
|
||||||
cfg->logDir = g_strdup_printf("%s/log/libvirt/ch", LOCALSTATEDIR);
|
cfg->logDir = g_strdup_printf("%s/log/libvirt/ch", LOCALSTATEDIR);
|
||||||
cfg->stateDir = g_strdup_printf("%s/libvirt/ch", RUNSTATEDIR);
|
cfg->stateDir = g_strdup_printf("%s/libvirt/ch", RUNSTATEDIR);
|
||||||
|
cfg->saveDir = g_strdup_printf("%s/lib/libvirt/ch/save", LOCALSTATEDIR);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
g_autofree char *rundir = NULL;
|
g_autofree char *rundir = NULL;
|
||||||
g_autofree char *cachedir = NULL;
|
g_autofree char *cachedir = NULL;
|
||||||
|
g_autofree char *configbasedir = NULL;
|
||||||
|
|
||||||
cachedir = virGetUserCacheDirectory();
|
cachedir = virGetUserCacheDirectory();
|
||||||
|
|
||||||
@ -159,6 +161,9 @@ virCHDriverConfigNew(bool privileged)
|
|||||||
|
|
||||||
rundir = virGetUserRuntimeDirectory();
|
rundir = virGetUserRuntimeDirectory();
|
||||||
cfg->stateDir = g_strdup_printf("%s/ch/run", rundir);
|
cfg->stateDir = g_strdup_printf("%s/ch/run", rundir);
|
||||||
|
|
||||||
|
configbasedir = virGetUserConfigDirectory();
|
||||||
|
cfg->saveDir = g_strdup_printf("%s/ch/save", configbasedir);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cfg;
|
return cfg;
|
||||||
@ -175,6 +180,7 @@ virCHDriverConfigDispose(void *obj)
|
|||||||
{
|
{
|
||||||
virCHDriverConfig *cfg = obj;
|
virCHDriverConfig *cfg = obj;
|
||||||
|
|
||||||
|
g_free(cfg->saveDir);
|
||||||
g_free(cfg->stateDir);
|
g_free(cfg->stateDir);
|
||||||
g_free(cfg->logDir);
|
g_free(cfg->logDir);
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ struct _virCHDriverConfig {
|
|||||||
|
|
||||||
char *stateDir;
|
char *stateDir;
|
||||||
char *logDir;
|
char *logDir;
|
||||||
|
char *saveDir;
|
||||||
|
|
||||||
int cgroupControllers;
|
int cgroupControllers;
|
||||||
|
|
||||||
|
@ -178,6 +178,14 @@ static char *chConnectGetCapabilities(virConnectPtr conn)
|
|||||||
return xml;
|
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:
|
* chDomainCreateXML:
|
||||||
* @conn: pointer to connection
|
* @conn: pointer to connection
|
||||||
@ -763,6 +771,48 @@ chDomainSave(virDomainPtr dom, const char *to)
|
|||||||
return chDomainSaveFlags(dom, to, NULL, 0);
|
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,
|
static virDomainPtr chDomainLookupByID(virConnectPtr conn,
|
||||||
int id)
|
int id)
|
||||||
{
|
{
|
||||||
@ -1886,6 +1936,7 @@ static virHypervisorDriver chHypervisorDriver = {
|
|||||||
.domainGetNumaParameters = chDomainGetNumaParameters, /* 8.1.0 */
|
.domainGetNumaParameters = chDomainGetNumaParameters, /* 8.1.0 */
|
||||||
.domainSave = chDomainSave, /* 10.2.0 */
|
.domainSave = chDomainSave, /* 10.2.0 */
|
||||||
.domainSaveFlags = chDomainSaveFlags, /* 10.2.0 */
|
.domainSaveFlags = chDomainSaveFlags, /* 10.2.0 */
|
||||||
|
.domainManagedSave = chDomainManagedSave, /* 10.2.0 */
|
||||||
};
|
};
|
||||||
|
|
||||||
static virConnectDriver chConnectDriver = {
|
static virConnectDriver chConnectDriver = {
|
||||||
|
@ -557,6 +557,13 @@ virCHMonitorNew(virDomainObj *vm, virCHDriverConfig *cfg)
|
|||||||
return NULL;
|
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);
|
cmd = virCommandNew(vm->def->emulator);
|
||||||
virCommandSetUmask(cmd, 0x002);
|
virCommandSetUmask(cmd, 0x002);
|
||||||
socket_fd = chMonitorCreateSocket(mon->socketpath);
|
socket_fd = chMonitorCreateSocket(mon->socketpath);
|
||||||
|
Loading…
Reference in New Issue
Block a user