[PATCH 0 of 2] Make ComputerSystem.EnabledState aware of snapshot

This makes the state of a guest appear to be suspended if there is a snapshot for the domain and the domain is offline. This also makes sure to prevent the user from starting the domain when such a snapshot exists, to force them to either apply or delete the snapshot.

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1217439903 25200 # Node ID e348d263e884ba9d0a2116f1e1b1ae706b654850 # Parent d7406e2f4670208cfe61ef9c0065164292ab3942 Make guests with save images appear to be in the suspended state and refuse to start a domain that has a snapshot. Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r d7406e2f4670 -r e348d263e884 src/Makefile.am --- a/src/Makefile.am Tue Jul 29 12:34:38 2008 -0700 +++ b/src/Makefile.am Wed Jul 30 10:45:03 2008 -0700 @@ -67,6 +67,8 @@ libVirt_ElementSettingData.la libVirt_ComputerSystem_la_SOURCES = Virt_ComputerSystem.c +libVirt_ComputerSystem_la_DEPENDENCIES = libVirt_VirtualSystemSnapshotService.la +libVirt_ComputerSystem_la_LIBADD = -lVirt_VirtualSystemSnapshotService libVirt_Device_la_SOURCES = Virt_Device.c libVirt_ComputerSystemIndication_la_DEPENDENCIES = libVirt_ComputerSystem.la libVirt_HostSystem.la diff -r d7406e2f4670 -r e348d263e884 src/Virt_ComputerSystem.c --- a/src/Virt_ComputerSystem.c Tue Jul 29 12:34:38 2008 -0700 +++ b/src/Virt_ComputerSystem.c Wed Jul 30 10:45:03 2008 -0700 @@ -43,6 +43,7 @@ #include "Virt_ComputerSystem.h" #include "Virt_HostSystem.h" +#include "Virt_VirtualSystemSnapshotService.h" const static CMPIBroker *_BROKER; @@ -229,6 +230,18 @@ } } +static uint16_t adjust_state_if_saved(const char *name, + uint16_t state) +{ + if (state != CIM_STATE_DISABLED) + return state; + + if (vsss_has_save_image(name)) + return CIM_STATE_SUSPENDED; + + return state; +} + static int set_state_from_dom(const CMPIBroker *broker, virDomainPtr dom, CMPIInstance *instance) @@ -248,6 +261,7 @@ return 0; cim_state = state_lv_to_cim((const int)info.state); + cim_state = adjust_state_if_saved(virDomainGetName(dom), cim_state); CMSetProperty(instance, "EnabledState", (CMPIValue *)&cim_state, CMPI_uint16); @@ -715,6 +729,29 @@ return ret; } +static CMPIStatus start_domain(virDomainPtr dom) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + + if (vsss_has_save_image(virDomainGetName(dom))) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_SUPPORTED, + "Domain has a snapshot"); + return s; + } + + if (virDomainCreate(dom) != 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to start domain"); + return s; + } + + set_scheduler_params(dom); + + return s; +} + static CMPIStatus state_change_enable(virDomainPtr dom, virDomainInfoPtr info) { CMPIStatus s = {CMPI_RC_OK, NULL}; @@ -723,8 +760,7 @@ switch (info->state) { case VIR_DOMAIN_SHUTOFF: CU_DEBUG("Start domain"); - ret = virDomainCreate(dom); - set_scheduler_params(dom); + s = start_domain(dom); break; case VIR_DOMAIN_PAUSED: CU_DEBUG("Unpause domain"); diff -r d7406e2f4670 -r e348d263e884 src/Virt_VirtualSystemSnapshotService.c --- a/src/Virt_VirtualSystemSnapshotService.c Tue Jul 29 12:34:38 2008 -0700 +++ b/src/Virt_VirtualSystemSnapshotService.c Wed Jul 30 10:45:03 2008 -0700 @@ -321,6 +321,24 @@ return path; } +bool vsss_has_save_image(const char *domname) +{ + char *path = NULL; + bool result = false; + + path = vsss_get_save_path(domname); + if (path == NULL) { + CU_DEBUG("Failed top get save path for %s", domname); + return false; + } + + result = access(path, R_OK | W_OK | F_OK) == 0; + + free(path); + + return result; +} + static struct snap_context *new_context(const char *name, CMPIStatus *s) { @@ -445,6 +463,30 @@ return s; } +CMPIStatus vsss_delete_snapshot(const char *domname) +{ + CMPIStatus s; + char *path = NULL; + + path = vsss_get_save_path(domname); + if (path == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get save_path"); + goto out; + } + + if (unlink(path) == -1) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to remove snapshot: %s", path); + } + out: + free(path); + + return s; +} + static CMPIStatus destroy_snapshot(CMPIMethodMI *self, const CMPIContext *context, const CMPIResult *results, @@ -455,7 +497,6 @@ CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIObjectPath *snap; char *name = NULL; - char *path = NULL; uint32_t retcode = CIM_RETURN_FAILED; if (cu_get_ref_arg(argsin, "AffectedSnapshot", &snap) != CMPI_RC_OK) { @@ -472,25 +513,15 @@ goto out; } - path = vsss_get_save_path(name); - if (path == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unable to get save_path"); - goto out; - } + s = vsss_delete_snapshot(name); - if (unlink(path) == -1) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unable to remove snapshot: %s", path); - } - - retcode = CIM_RETURN_COMPLETED; + if (s.rc == CMPI_RC_OK) + retcode = CIM_RETURN_COMPLETED; + else + retcode = CIM_RETURN_FAILED; out: CMReturnData(results, (CMPIValue *)&retcode, CMPI_uint32); - free(path); free(name); return s; diff -r d7406e2f4670 -r e348d263e884 src/Virt_VirtualSystemSnapshotService.h --- a/src/Virt_VirtualSystemSnapshotService.h Tue Jul 29 12:34:38 2008 -0700 +++ b/src/Virt_VirtualSystemSnapshotService.h Wed Jul 30 10:45:03 2008 -0700 @@ -21,6 +21,8 @@ /* Returns a malloc()'d string; caller must free() */ char *vsss_get_save_path(const char *domname); +bool vsss_has_save_image(const char *domname); +CMPIStatus vsss_delete_snapshot(const char *domname); CMPIStatus get_vsss(const CMPIBroker *broker, const CMPIObjectPath *ref,

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1217439908 25200 # Node ID 993c30cca30c370e1be4e146d26443c7949737cc # Parent e348d263e884ba9d0a2116f1e1b1ae706b654850 Make SnapshotService delete the snapshot image on resume Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r e348d263e884 -r 993c30cca30c src/Virt_VirtualSystemSnapshotService.c --- a/src/Virt_VirtualSystemSnapshotService.c Wed Jul 30 10:45:03 2008 -0700 +++ b/src/Virt_VirtualSystemSnapshotService.c Wed Jul 30 10:45:08 2008 -0700 @@ -195,6 +195,9 @@ snap_job_set_status(ctx, CIM_JOBSTATE_RUNNING, "Restore finished"); + + if (!ctx->save) + vsss_delete_snapshot(virDomainGetName(dom)); } CU_DEBUG("Snapshot (%s/%s) completed",

Dan Smith wrote:
This makes the state of a guest appear to be suspended if there is a snapshot for the domain and the domain is offline. This also makes sure to prevent the user from starting the domain when such a snapshot exists, to force them to either apply or delete the snapshot.
+1 for this set. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Dan Smith wrote:
This makes the state of a guest appear to be suspended if there is a snapshot for the domain and the domain is offline. This also makes sure to prevent the user from starting the domain when such a snapshot exists, to force them to either apply or delete the snapshot.
+1 Just so I'm clear, CS.RequestStateChange(6==offline) will not suspend (aka save) the vm. This appears to be the case after a quick look at __state_change in Virt_ComputerSystem.c. In fact, RSC(6) would result in CMPI_RC_ERR_NOT_SUPPORTED. I assume this is noted in the capabilities :-). In order to do the equivalent of e.g. "xm save" in xen, one would invoke CreateSnapshot(). Following the operation, state would be suspended. To "restore", invoke ApplySnapshot(). Is this correct? Thanks, Jim

JF> Just so I'm clear, CS.RequestStateChange(6==offline) will not JF> suspend (aka save) the vm. This appears to be the case after a JF> quick look at __state_change in Virt_ComputerSystem.c. In fact, JF> RSC(6) would result in CMPI_RC_ERR_NOT_SUPPORTED. Correct. JF> I assume this is noted in the capabilities :-). It is. JF> In order to do the equivalent of e.g. "xm save" in xen, one would JF> invoke CreateSnapshot(). Following the operation, state would be JF> suspended. To "restore", invoke ApplySnapshot(). Is this JF> correct? That's correct. When libvirt supports coordinated disk/memory snapshots for things like KVM, the extra level of indirection will make more sense, I think. Thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com
participants (3)
-
Dan Smith
-
Jim Fehlig
-
Kaitlin Rupert