[PATCH 0 of 2] [#2] ComputerSystemDeletedIndication is called with all fields properly filled

# HG changeset patch # User Richard Maciel <rmaciel@linux.vnet.ibm.com> # Date 1251388779 10800 # Node ID 84de50fc3126ea6de453da4543d43b28539eff67 # Parent 7a5403380789571fca9496003461c45f23e18c2f ComputerSystemDeletedIndication wasn't being called when a guest was removed. This patch fix it. Added and exported a function from ComputerSystem, so the indication can create an instance of the guest based on the domain structure stored. #2: Improved status information return in set_instance_state function Signed-off-by: Richard Maciel <rmaciel@linux.vnet.ibm.com> diff -r 7a5403380789 -r 84de50fc3126 src/Virt_ComputerSystem.c --- a/src/Virt_ComputerSystem.c Thu Aug 20 17:16:24 2009 -0700 +++ b/src/Virt_ComputerSystem.c Thu Aug 27 12:59:39 2009 -0300 @@ -439,6 +439,102 @@ return 1; } +static CMPIStatus set_properties_from_dominfo(const CMPIBroker *broker, + const char *prefix, + struct domain *dominfo, + CMPIInstance *instance) +{ + CMPIStatus s = {CMPI_RC_ERR_FAILED, NULL}; + CMPIObjectPath *ref = NULL; + + ref = CMGetObjectPath(instance, &s); + if ((ref == NULL) || (s.rc != CMPI_RC_OK)) + return s; + + CMSetProperty(instance, "Name", + (CMPIValue *)dominfo->name, CMPI_chars); + + CMSetProperty(instance, "ElementName", + (CMPIValue *)dominfo->name, CMPI_chars); + + CMSetProperty(instance, "UUID", + (CMPIValue *)dominfo->uuid, CMPI_chars); + + if (!set_capdesc_from_dominfo(broker, dominfo, ref, instance)) { + CU_DEBUG("Problem in set_capdesc_from_dominfo function"); + cu_statusf(broker, &s, + CMPI_RC_FAILED, + "Could not set caption and description properties"); + goto out; + } + + /* We don't set state, because struct domain doesn't have that + * information */ + + if (!set_creation_class(instance)) { + CU_DEBUG("Problem in set_creation_class function"); + cu_statusf(broker, &s, + CMPI_RC_FAILED, + "Could not set creation class"); + goto out; + } + + if (!set_other_id_info(broker, dominfo->uuid, prefix, instance)) { + CU_DEBUG("Problem in set_other_id_info function"); + cu_statusf(broker, &s, + CMPI_RC_FAILED, + "Could not set other OtherIdentifyingInfo and " + "IdentifyingDescription"); + goto out; + } + + cu_statusf(broker, &s, + CMPI_RC_OK, + ""); + + out: + return s; +} + +CMPIStatus instance_from_dominfo(const CMPIBroker *broker, + const char *namespace, + const char *prefix, + struct domain *dominfo, + CMPIInstance **_inst) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; + + inst = get_typed_instance(broker, + prefix, + "ComputerSystem", + namespace); + + if (inst == NULL) { + CU_DEBUG("Could not init CS instance. " + "typestr: %s, namespace: %s", prefix, namespace); + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Unable to init ComputerSystem instance"); + goto out; + } + + s = set_properties_from_dominfo(broker, + prefix, + dominfo, + inst); + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("Could not set instance properties"); + goto out; + } + + *_inst = inst; + + out: + return s; + +} + /* Populate an instance with information from a domain */ static CMPIStatus set_properties(const CMPIBroker *broker, virDomainPtr dom, diff -r 7a5403380789 -r 84de50fc3126 src/Virt_ComputerSystem.h --- a/src/Virt_ComputerSystem.h Thu Aug 20 17:16:24 2009 -0700 +++ b/src/Virt_ComputerSystem.h Thu Aug 27 12:59:39 2009 -0300 @@ -22,6 +22,7 @@ #define __VIRT_COMPUTERSYSTEM_H #include "misc_util.h" +#include "device_parsing.h" /** * Get a list of domain instances @@ -62,6 +63,25 @@ const char *name, CMPIInstance **_inst); +/** + * Create a domain instance from the domain structure. Note that the instance + * doesn't necessarily represents an existing domain (can represent a deleted + * one, for instance) + * + * @param broker A pointer to the current broker + * @param namespace The namespace to used by the domain instance + * @param prefix The virtualization prefix (i.e. KVM, Xen, LXC) + * @param dominfo A pointer to the struct domain used to fill the instance + * @param _inst In case of success the pointer to the instance + * @returns CMPIStatus + */ +CMPIStatus instance_from_dominfo(const CMPIBroker *broker, + const char *namespace, + const char *prefix, + struct domain *dominfo, + CMPIInstance **_inst); + + #endif /* diff -r 7a5403380789 -r 84de50fc3126 src/Virt_ComputerSystemIndication.c --- a/src/Virt_ComputerSystemIndication.c Thu Aug 20 17:16:24 2009 -0700 +++ b/src/Virt_ComputerSystemIndication.c Thu Aug 27 12:59:39 2009 -0300 @@ -330,6 +330,41 @@ return false; } +static bool create_deleted_guest_inst(char *xml, + char *namespace, + char *prefix, + CMPIInstance **inst) +{ + bool rc = false; + struct domain *dominfo = NULL; + int res; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + res = get_dominfo_from_xml(xml, &dominfo); + if (res == 0) { + CU_DEBUG("failed to extract domain info from xml"); + goto out; + } + + s = instance_from_dominfo(_BROKER, + namespace, + prefix, + dominfo, + inst); + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("instance from domain info error: %s", s.msg); + goto out; + } + /* Must set guest state */ + + rc = true; + + out: + cleanup_dominfo(&dominfo); + + return rc; +} + static bool async_ind(CMPIContext *context, virConnectPtr conn, int ind_type, @@ -360,12 +395,27 @@ cn = get_typed_class(prefix, "ComputerSystem"); op = CMNewObjectPath(_BROKER, args->ns, cn, &s); - if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op)) + if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op)) { + CU_DEBUG("op error"); goto out; + } - s = get_domain_by_name(_BROKER, op, name, &affected_inst); - if (s.rc != CMPI_RC_OK) - goto out; + if (ind_type == CS_CREATED || ind_type == CS_MODIFIED) { + s = get_domain_by_name(_BROKER, op, name, &affected_inst); + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("domain by name error"); + goto out; + } + } else if (ind_type == CS_DELETED) { + rc = create_deleted_guest_inst(prev_dom.xml, + args->ns, + prefix, + &affected_inst); + if (!rc) { + CU_DEBUG("Could not recreate guest instance"); + goto out; + } + } /* FIXME: We are unable to get the previous CS instance after it has been modified. Consider keeping track of the previous

+static CMPIStatus set_properties_from_dominfo(const CMPIBroker *broker, + const char *prefix, + struct domain *dominfo, + CMPIInstance *instance) +{ + CMPIStatus s = {CMPI_RC_ERR_FAILED, NULL};
Since you set the status when an error occurs, just set this to CMPI_RC_OK.
+ CMPIObjectPath *ref = NULL; + + ref = CMGetObjectPath(instance, &s); + if ((ref == NULL) || (s.rc != CMPI_RC_OK)) + return s; + + CMSetProperty(instance, "Name", + (CMPIValue *)dominfo->name, CMPI_chars); + + CMSetProperty(instance, "ElementName", + (CMPIValue *)dominfo->name, CMPI_chars); + + CMSetProperty(instance, "UUID", + (CMPIValue *)dominfo->uuid, CMPI_chars); + + if (!set_capdesc_from_dominfo(broker, dominfo, ref, instance)) { + CU_DEBUG("Problem in set_capdesc_from_dominfo function"); + cu_statusf(broker, &s, + CMPI_RC_FAILED,
This should be CMPI_RC_ERR_FAILED.
+ "Could not set caption and description properties"); + goto out; + } + + /* We don't set state, because struct domain doesn't have that + * information */ + + if (!set_creation_class(instance)) { + CU_DEBUG("Problem in set_creation_class function"); + cu_statusf(broker, &s, + CMPI_RC_FAILED,
Here's as well.
+ "Could not set creation class"); + goto out; + } + + if (!set_other_id_info(broker, dominfo->uuid, prefix, instance)) { + CU_DEBUG("Problem in set_other_id_info function"); + cu_statusf(broker, &s, + CMPI_RC_FAILED,
Here too.
+ "Could not set other OtherIdentifyingInfo and " + "IdentifyingDescription"); + goto out; + } + + cu_statusf(broker, &s, + CMPI_RC_OK, + "");
This is not needed if you initialize s to be CMPI_RC_OK.
+ + out: + return s; +}
-- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

# HG changeset patch # User Richard Maciel <rmaciel@linux.vnet.ibm.com> # Date 1251388782 10800 # Node ID 570b94a6c4277eae667be11ec48b23668a3c5e17 # Parent 84de50fc3126ea6de453da4543d43b28539eff67 Adds state information to the instance created in ComputerSystemDeletedIndication Had to export the state enumerations in ComputerSystem.c to use in the indication code #2: - Changed OtherEnabledState value to 'Guest destroyed' - Moved state enums to svpc_types.h Signed-off-by: Richard Maciel <rmaciel@linux.vnet.ibm.com> diff -r 84de50fc3126 -r 570b94a6c427 src/Virt_ComputerSystem.c --- a/src/Virt_ComputerSystem.c Thu Aug 27 12:59:39 2009 -0300 +++ b/src/Virt_ComputerSystem.c Thu Aug 27 12:59:42 2009 -0300 @@ -47,18 +47,6 @@ const static CMPIBroker *_BROKER; -enum CIM_state { - CIM_STATE_UNKNOWN = 0, - CIM_STATE_ENABLED = 2, - CIM_STATE_DISABLED = 3, - CIM_STATE_SHUTDOWN = 4, - CIM_STATE_NOCHANGE = 5, - CIM_STATE_SUSPENDED = 6, - CIM_STATE_PAUSED = 9, - CIM_STATE_REBOOT = 10, - CIM_STATE_RESET = 11, -}; - /* Set the "Name" property of an instance from a domain */ static int set_name_from_dom(virDomainPtr dom, CMPIInstance *instance) { @@ -159,15 +147,6 @@ static uint16_t state_lv_to_cim_health(const char lv_state) { - enum CIM_health_state { - CIM_HEALTH_UNKNOWN = 0, - CIM_HEALTH_OK = 5, - CIM_HEALTH_MINOR_FAILURE = 15, - CIM_HEALTH_MAJOR_FAILURE = 20, - CIM_HEALTH_CRITICAL_FAILURE = 25, - CIM_HEALTH_NON_RECOVERABLE = 30, - }; - switch (lv_state) { case VIR_DOMAIN_NOSTATE: case VIR_DOMAIN_SHUTDOWN: @@ -189,28 +168,6 @@ static uint16_t state_lv_to_cim_oings(const char lv_state, const bool migrating) { - enum CIM_oping_status { - CIM_OPING_STATUS_UNKNOWN = 0, - CIM_OPING_STATUS_NOT_AVAILABLE = 1, - CIM_OPING_STATUS_SERVICING = 2, - CIM_OPING_STATUS_STARTING = 3, - CIM_OPING_STATUS_STOPPING = 4, - CIM_OPING_STATUS_STOPPED = 5, - CIM_OPING_STATUS_ABORTED = 6, - CIM_OPING_STATUS_DORMANT = 7, - CIM_OPING_STATUS_COMPLETED = 8, - CIM_OPING_STATUS_MIGRATING = 9, - CIM_OPING_STATUS_EMIGRATING = 10, - CIM_OPING_STATUS_IMMIGRATING = 11, - CIM_OPING_STATUS_SNAPSHOTTING = 12, - CIM_OPING_STATUS_SHUTTING_DOWN = 13, - CIM_OPING_STATUS_IN_TEST = 14, - CIM_OPING_STATUS_TRANSITIONING = 15, - CIM_OPING_STATUS_IN_SERVICE = 16, - CIM_OPING_STATUS_STARTED = 32768, - }; - - if (migrating) return CIM_OPING_STATUS_MIGRATING; @@ -237,27 +194,6 @@ static uint16_t state_lv_to_cim_os(const char lv_state) { - enum CIM_op_status { - CIM_OP_STATUS_UNKNOWN = 0, - CIM_OP_STATUS_OTHER = 1, - CIM_OP_STATUS_OK = 2, - CIM_OP_STATUS_DEGRADED = 3, - CIM_OP_STATUS_STRESSED = 4, - CIM_OP_STATUS_PREDICTIVE_FAILURE = 5, - CIM_OP_STATUS_ERROR = 6, - CIM_OP_STATUS_NON_RECOVERABLE = 7, - CIM_OP_STATUS_STARTING = 8, - CIM_OP_STATUS_STOPPING = 9, - CIM_OP_STATUS_STOPPED = 10, - CIM_OP_STATUS_IN_SERVICE = 11, - CIM_OP_STATUS_NO_CONTACT = 12, - CIM_OP_STATUS_LOST_COMMS = 13, - CIM_OP_STATUS_ABORTED = 14, - CIM_OP_STATUS_DORMANT = 15, - CIM_OP_STATUS_COMPLETED = 17, - CIM_OP_STATUS_POWER_MODE = 18, - }; - switch (lv_state) { case VIR_DOMAIN_NOSTATE: case VIR_DOMAIN_SHUTDOWN: @@ -463,7 +399,7 @@ if (!set_capdesc_from_dominfo(broker, dominfo, ref, instance)) { CU_DEBUG("Problem in set_capdesc_from_dominfo function"); cu_statusf(broker, &s, - CMPI_RC_FAILED, + CMPI_RC_ERR_FAILED, "Could not set caption and description properties"); goto out; } @@ -474,7 +410,7 @@ if (!set_creation_class(instance)) { CU_DEBUG("Problem in set_creation_class function"); cu_statusf(broker, &s, - CMPI_RC_FAILED, + CMPI_RC_ERR_FAILED, "Could not set creation class"); goto out; } @@ -482,7 +418,7 @@ if (!set_other_id_info(broker, dominfo->uuid, prefix, instance)) { CU_DEBUG("Problem in set_other_id_info function"); cu_statusf(broker, &s, - CMPI_RC_FAILED, + CMPI_RC_ERR_FAILED, "Could not set other OtherIdentifyingInfo and " "IdentifyingDescription"); goto out; diff -r 84de50fc3126 -r 570b94a6c427 src/Virt_ComputerSystemIndication.c --- a/src/Virt_ComputerSystemIndication.c Thu Aug 27 12:59:39 2009 -0300 +++ b/src/Virt_ComputerSystemIndication.c Thu Aug 27 12:59:42 2009 -0300 @@ -330,6 +330,51 @@ return false; } +static bool set_instance_state(CMPIInstance *instance) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIUint16 cim_state; + CMPIString *cim_state_other = NULL; + CMPIUint16 health_state; + CMPIUint16 req_state; + CMPIUint16 oping_status; + CMPIUint16 op_status; + CMPIArray *array; + + cim_state = CIM_STATE_OTHER; + cim_state_other = CMNewString(_BROKER, "Guest destroyed", &s); + CMSetProperty(instance, "EnabledState", + (CMPIValue *)&cim_state, CMPI_uint16); + CMSetProperty(instance, "OtherEnabledState", + (CMPIValue *)&cim_state_other, CMPI_string); + + health_state = CIM_HEALTH_UNKNOWN; + CMSetProperty(instance, "HealthState", + (CMPIValue *)&health_state, CMPI_uint16); + + array = CMNewArray(_BROKER, 2, CMPI_uint16, &s); + if ((s.rc != CMPI_RC_OK) || (CMIsNullObject(array))) + return false; + + op_status = CIM_OP_STATUS_COMPLETED; + CMSetArrayElementAt(array, 0, &op_status, CMPI_uint16); + op_status = CIM_OP_STATUS_OK; + CMSetArrayElementAt(array, 1, &op_status, CMPI_uint16); + + CMSetProperty(instance, "OperationalStatus", + (CMPIValue *)&array, CMPI_uint16A); + + oping_status = CIM_OPING_STATUS_COMPLETED; + CMSetProperty(instance, "OperatingStatus", + (CMPIValue *)&oping_status, CMPI_uint16); + + req_state = CIM_STATE_UNKNOWN; + CMSetProperty(instance, "RequestedState", + (CMPIValue *)&req_state, CMPI_uint16); + + return true; +} + static bool create_deleted_guest_inst(char *xml, char *namespace, char *prefix, @@ -355,9 +400,10 @@ CU_DEBUG("instance from domain info error: %s", s.msg); goto out; } - /* Must set guest state */ - rc = true; + rc = set_instance_state(*inst); + if (!rc) + CU_DEBUG("Error setting instance state"); out: cleanup_dominfo(&dominfo); diff -r 84de50fc3126 -r 570b94a6c427 src/svpc_types.h --- a/src/svpc_types.h Thu Aug 27 12:59:39 2009 -0300 +++ b/src/svpc_types.h Thu Aug 27 12:59:42 2009 -0300 @@ -102,4 +102,70 @@ return CIM_VSSD_RECOVERY_NONE; } +/* State enums used by ComputerSystem */ +enum CIM_state { + CIM_STATE_UNKNOWN = 0, + CIM_STATE_OTHER = 1, + CIM_STATE_ENABLED = 2, + CIM_STATE_DISABLED = 3, + CIM_STATE_SHUTDOWN = 4, + CIM_STATE_NOCHANGE = 5, + CIM_STATE_SUSPENDED = 6, + CIM_STATE_PAUSED = 9, + CIM_STATE_REBOOT = 10, + CIM_STATE_RESET = 11, +}; + +enum CIM_health_state { + CIM_HEALTH_UNKNOWN = 0, + CIM_HEALTH_OK = 5, + CIM_HEALTH_MINOR_FAILURE = 15, + CIM_HEALTH_MAJOR_FAILURE = 20, + CIM_HEALTH_CRITICAL_FAILURE = 25, + CIM_HEALTH_NON_RECOVERABLE = 30, +}; + +enum CIM_oping_status { + CIM_OPING_STATUS_UNKNOWN = 0, + CIM_OPING_STATUS_NOT_AVAILABLE = 1, + CIM_OPING_STATUS_SERVICING = 2, + CIM_OPING_STATUS_STARTING = 3, + CIM_OPING_STATUS_STOPPING = 4, + CIM_OPING_STATUS_STOPPED = 5, + CIM_OPING_STATUS_ABORTED = 6, + CIM_OPING_STATUS_DORMANT = 7, + CIM_OPING_STATUS_COMPLETED = 8, + CIM_OPING_STATUS_MIGRATING = 9, + CIM_OPING_STATUS_EMIGRATING = 10, + CIM_OPING_STATUS_IMMIGRATING = 11, + CIM_OPING_STATUS_SNAPSHOTTING = 12, + CIM_OPING_STATUS_SHUTTING_DOWN = 13, + CIM_OPING_STATUS_IN_TEST = 14, + CIM_OPING_STATUS_TRANSITIONING = 15, + CIM_OPING_STATUS_IN_SERVICE = 16, + CIM_OPING_STATUS_STARTED = 32768, +}; + +enum CIM_op_status { + CIM_OP_STATUS_UNKNOWN = 0, + CIM_OP_STATUS_OTHER = 1, + CIM_OP_STATUS_OK = 2, + CIM_OP_STATUS_DEGRADED = 3, + CIM_OP_STATUS_STRESSED = 4, + CIM_OP_STATUS_PREDICTIVE_FAILURE = 5, + CIM_OP_STATUS_ERROR = 6, + CIM_OP_STATUS_NON_RECOVERABLE = 7, + CIM_OP_STATUS_STARTING = 8, + CIM_OP_STATUS_STOPPING = 9, + CIM_OP_STATUS_STOPPED = 10, + CIM_OP_STATUS_IN_SERVICE = 11, + CIM_OP_STATUS_NO_CONTACT = 12, + CIM_OP_STATUS_LOST_COMMS = 13, + CIM_OP_STATUS_ABORTED = 14, + CIM_OP_STATUS_DORMANT = 15, + CIM_OP_STATUS_COMPLETED = 17, + CIM_OP_STATUS_POWER_MODE = 18, +}; + + #endif

@@ -463,7 +399,7 @@ if (!set_capdesc_from_dominfo(broker, dominfo, ref, instance)) { CU_DEBUG("Problem in set_capdesc_from_dominfo function"); cu_statusf(broker, &s, - CMPI_RC_FAILED, + CMPI_RC_ERR_FAILED,
Oh, I hadn't looked at this patch yet when I reviewed the first one. Instead of making the changes in this patch.. just make these changes in the first one. No need to have your second patch fix errors in the first patch.
"Could not set caption and description properties"); goto out; } @@ -474,7 +410,7 @@ if (!set_creation_class(instance)) { CU_DEBUG("Problem in set_creation_class function"); cu_statusf(broker, &s, - CMPI_RC_FAILED, + CMPI_RC_ERR_FAILED, "Could not set creation class"); goto out; } @@ -482,7 +418,7 @@ if (!set_other_id_info(broker, dominfo->uuid, prefix, instance)) { CU_DEBUG("Problem in set_other_id_info function"); cu_statusf(broker, &s, - CMPI_RC_FAILED, + CMPI_RC_ERR_FAILED, "Could not set other OtherIdentifyingInfo and " "IdentifyingDescription"); goto out;
-- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Richard Maciel