
# 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,