# HG changeset patch
# User Richard Maciel <rmaciel(a)linux.vnet.ibm.com>
# Date 1251475864 10800
# Node ID 483311e0e542c9882a81e00d77511a4b23334304
# 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
#3:
Changed code style
Signed-off-by: Richard Maciel <rmaciel(a)linux.vnet.ibm.com>
diff -r 7a5403380789 -r 483311e0e542 src/Virt_ComputerSystem.c
--- a/src/Virt_ComputerSystem.c Thu Aug 20 17:16:24 2009 -0700
+++ b/src/Virt_ComputerSystem.c Fri Aug 28 13:11:04 2009 -0300
@@ -439,6 +439,98 @@
return 1;
}
+static CMPIStatus set_properties_from_dominfo(const CMPIBroker *broker,
+ const char *prefix,
+ struct domain *dominfo,
+ CMPIInstance *instance)
+{
+ CMPIStatus s = {CMPI_RC_OK, 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_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_ERR_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_ERR_FAILED,
+ "Could not set other OtherIdentifyingInfo and "
+ "IdentifyingDescription");
+ goto out;
+ }
+
+ 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 483311e0e542 src/Virt_ComputerSystem.h
--- a/src/Virt_ComputerSystem.h Thu Aug 20 17:16:24 2009 -0700
+++ b/src/Virt_ComputerSystem.h Fri Aug 28 13:11:04 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 483311e0e542 src/Virt_ComputerSystemIndication.c
--- a/src/Virt_ComputerSystemIndication.c Thu Aug 20 17:16:24 2009 -0700
+++ b/src/Virt_ComputerSystemIndication.c Fri Aug 28 13:11:04 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