Add managed save API entry points

virDomainManagedSave() is to be run on a running domain. Once the call
complete, as in virDomainSave() the domain is stopped upon completion,
but there is no restore counterpart as any order to start the domain
from the API would load the state from the managed file, similary if
the domain is autostarted when libvirtd starts.
Once a domain has restarted his managed save image is destroyed,
basically managed save image can only exist for a stopped domain,
for a running domain that would be by definition outdated data.

* include/libvirt/libvirt.h.in src/libvirt.c src/libvirt_public.syms:
  adds the new entry points virDomainManagedSave(),
  virDomainHasManagedSaveImage() and virDomainManagedSaveRemove()
* src/driver.h src/esx/esx_driver.c src/lxc/lxc_driver.c
  src/opennebula/one_driver.c  src/openvz/openvz_driver.c
  src/phyp/phyp_driver.c src/qemu/qemu_driver.c src/vbox/vbox_tmpl.c
  src/remote/remote_driver.c src/test/test_driver.c src/uml/uml_driver.c
  src/xen/xen_driver.c: add corresponding new internal drivers entry
  points
This commit is contained in:
Daniel Veillard 2010-04-01 10:46:28 +02:00
parent d002c250cd
commit 15c647a91e
15 changed files with 198 additions and 0 deletions

View File

@ -638,6 +638,16 @@ int virDomainSave (virDomainPtr domain,
int virDomainRestore (virConnectPtr conn,
const char *from);
/*
* Managed domain save
*/
int virDomainManagedSave (virDomainPtr dom,
unsigned int flags);
int virDomainHasManagedSaveImage(virDomainPtr dom,
unsigned int flags);
int virDomainManagedSaveRemove(virDomainPtr dom,
unsigned int flags);
/*
* Domain core dump
*/

View File

@ -402,6 +402,15 @@ typedef int
(*virDrvDomainEventDeregisterAny)(virConnectPtr conn,
int callbackID);
typedef int
(*virDrvDomainManagedSave)(virDomainPtr domain, unsigned int flags);
typedef int
(*virDrvDomainHasManagedSaveImage)(virDomainPtr domain, unsigned int flags);
typedef int
(*virDrvDomainManagedSaveRemove)(virDomainPtr domain, unsigned int flags);
/**
* _virDriver:
*
@ -499,6 +508,9 @@ struct _virDriver {
virDrvDomainMigrateSetMaxDowntime domainMigrateSetMaxDowntime;
virDrvDomainEventRegisterAny domainEventRegisterAny;
virDrvDomainEventDeregisterAny domainEventDeregisterAny;
virDrvDomainManagedSave domainManagedSave;
virDrvDomainHasManagedSaveImage domainHasManagedSaveImage;
virDrvDomainManagedSaveRemove domainManagedSaveRemove;
};
typedef int

View File

@ -3389,6 +3389,9 @@ static virDriver esxDriver = {
NULL, /* domainMigrateSetMaxDowntime */
NULL, /* domainEventRegisterAny */
NULL, /* domainEventDeregisterAny */
NULL, /* domainManagedSave */
NULL, /* domainHasManagedSaveImage */
NULL, /* domainManagedSaveRemove */
};

View File

@ -12136,3 +12136,143 @@ error:
virDispatchError(conn);
return -1;
}
/**
* virDomainManagedSave:
* @dom: pointer to the domain
* @flags: optional flags currently unused
*
* This method will suspend a domain and save its memory contents to
* a file on disk. After the call, if successful, the domain is not
* listed as running anymore.
* The difference from virDomainSave() is that libvirt is keeping track of
* the saved state itself, and will reuse it once the domain is being
* restarted (automatically or via an explicit libvirt call).
* As a result any running domain is sure to not have a managed saved image.
*
* Returns 0 in case of success or -1 in case of failure
*/
int virDomainManagedSave(virDomainPtr dom, unsigned int flags)
{
virConnectPtr conn;
VIR_DEBUG("dom=%p, flags=%u", dom, flags);
virResetLastError();
if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
conn = dom->conn;
if (conn->flags & VIR_CONNECT_RO) {
virLibDomainError(dom, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
goto error;
}
if (conn->driver->domainManagedSave) {
int ret;
ret = conn->driver->domainManagedSave(dom, flags);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
virDispatchError(conn);
return -1;
}
/**
* virDomainHasManagedSaveImage:
* @dom: pointer to the domain
* @flags: optional flags currently unused
*
* Check if a domain has a managed save image as created by
* virDomainManagedSave(). Note that any running domain should not have
* such an image, as it should have been removed on restart.
*
* Returns 0 if no image is present, 1 if an image is present, and
* -1 in case of error
*/
int virDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
{
virConnectPtr conn;
VIR_DEBUG("dom=%p, flags=%u", dom, flags);
virResetLastError();
if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
conn = dom->conn;
if (conn->driver->domainHasManagedSaveImage) {
int ret;
ret = conn->driver->domainHasManagedSaveImage(dom, flags);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
virDispatchError(conn);
return -1;
}
/**
* virDomainManagedSaveRemove:
* @dom: pointer to the domain
* @flags: optional flags currently unused
*
* Remove any managed save image as for this domain.
*
* Returns 0 in case of success, and -1 in case of error
*/
int virDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags)
{
virConnectPtr conn;
VIR_DEBUG("dom=%p, flags=%u", dom, flags);
virResetLastError();
if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
conn = dom->conn;
if (conn->flags & VIR_CONNECT_RO) {
virLibDomainError(dom, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
goto error;
}
if (conn->driver->domainManagedSaveRemove) {
int ret;
ret = conn->driver->domainManagedSaveRemove(dom, flags);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
virDispatchError(conn);
return -1;
}

View File

@ -378,6 +378,9 @@ LIBVIRT_0.7.8 {
virNWFilterRef;
virNWFilterDefineXML;
virNWFilterUndefine;
virDomainManagedSave;
virDomainHasManagedSaveImage;
virDomainManagedSaveRemove;
} LIBVIRT_0.7.7;

View File

@ -2538,6 +2538,9 @@ static virDriver lxcDriver = {
NULL, /* domainMigrateSetMaxDowntime */
lxcDomainEventRegisterAny, /* domainEventRegisterAny */
lxcDomainEventDeregisterAny, /* domainEventDeregisterAny */
NULL, /* domainManagedSave */
NULL, /* domainHasManagedSaveImage */
NULL, /* domainManagedSaveRemove */
};
static virStateDriver lxcStateDriver = {

View File

@ -792,6 +792,9 @@ static virDriver oneDriver = {
NULL, /* domainMigrateSetMaxDowntime */
NULL, /* domainEventRegisterAny */
NULL, /* domainEventDeregisterAny */
NULL, /* domainManagedSave */
NULL, /* domainHasManagedSaveImage */
NULL, /* domainManagedSaveRemove */
};
static virStateDriver oneStateDriver = {

View File

@ -1544,6 +1544,9 @@ static virDriver openvzDriver = {
NULL, /* domainMigrateSetMaxDowntime */
NULL, /* domainEventRegisterAny */
NULL, /* domainEventDeregisterAny */
NULL, /* domainManagedSave */
NULL, /* domainHasManagedSaveImage */
NULL, /* domainManagedSaveRemove */
};
int openvzRegister(void) {

View File

@ -1651,6 +1651,9 @@ virDriver phypDriver = {
NULL, /* domainMigrateSetMaxDowntime */
NULL, /* domainEventRegisterAny */
NULL, /* domainEventDeregisterAny */
NULL, /* domainManagedSave */
NULL, /* domainHasManagedSaveImage */
NULL, /* domainManagedSaveRemove */
};
int

View File

@ -10312,6 +10312,9 @@ static virDriver qemuDriver = {
qemuDomainMigrateSetMaxDowntime, /* domainMigrateSetMaxDowntime */
qemuDomainEventRegisterAny, /* domainEventRegisterAny */
qemuDomainEventDeregisterAny, /* domainEventDeregisterAny */
NULL, /* domainManagedSave */
NULL, /* domainHasManagedSaveImage */
NULL, /* domainManagedSaveRemove */
};

View File

@ -9818,6 +9818,9 @@ static virDriver remote_driver = {
remoteDomainMigrateSetMaxDowntime, /* domainMigrateSetMaxDowntime */
remoteDomainEventRegisterAny, /* domainEventRegisterAny */
remoteDomainEventDeregisterAny, /* domainEventDeregisterAny */
NULL, /* domainManagedSave */
NULL, /* domainHasManagedSaveImage */
NULL, /* domainManagedSaveRemove */
};
static virNetworkDriver network_driver = {

View File

@ -5306,6 +5306,9 @@ static virDriver testDriver = {
NULL, /* domainMigrateSetMaxDowntime */
testDomainEventRegisterAny, /* domainEventRegisterAny */
testDomainEventDeregisterAny, /* domainEventDeregisterAny */
NULL, /* domainManagedSave */
NULL, /* domainHasManagedSaveImage */
NULL, /* domainManagedSaveRemove */
};
static virNetworkDriver testNetworkDriver = {

View File

@ -1937,6 +1937,9 @@ static virDriver umlDriver = {
NULL, /* domainMigrateSetMaxDowntime */
NULL, /* domainEventRegisterAny */
NULL, /* domainEventDeregisterAny */
NULL, /* domainManagedSave */
NULL, /* domainHasManagedSaveImage */
NULL, /* domainManagedSaveRemove */
};

View File

@ -7184,6 +7184,9 @@ virDriver NAME(Driver) = {
vboxDomainEventRegisterAny, /* domainEventRegisterAny */
vboxDomainEventDeregisterAny, /* domainEventDeregisterAny */
#endif
NULL, /* domainManagedSave */
NULL, /* domainHasManagedSaveImage */
NULL, /* domainManagedSaveRemove */
};
virNetworkDriver NAME(NetworkDriver) = {

View File

@ -1980,6 +1980,9 @@ static virDriver xenUnifiedDriver = {
NULL, /* domainMigrateSetMaxDowntime */
xenUnifiedDomainEventRegisterAny, /* domainEventRegisterAny */
xenUnifiedDomainEventDeregisterAny, /* domainEventDeregisterAny */
NULL, /* domainManagedSave */
NULL, /* domainHasManagedSaveImage */
NULL, /* domainManagedSaveRemove */
};
/**