[PATCH] Cleanups and schema install additions to the RPM spec
by Dan Smith
# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1194559255 28800
# Node ID fbc36f46718fd7390d43e61bbb35276a1ba55a6e
# Parent 90ffd19dda747eb615f12b10aa04e4f9bc978b31
Cleanups and schema install additions to the RPM spec
- Removed references to the register_bash.sh script
- Added schema install/uninstall to scriptlets
I have tested this on Fedora 8 with the bundled pegasus installation.
We still need to figure out how we're going to get the CIM v2.16 Exp
schema on the box, but if you do that manually (into /root/virt) before
installing the RPM, it works as expected.
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 90ffd19dda74 -r fbc36f46718f libvirt-cim.spec.in
--- a/libvirt-cim.spec.in Thu Nov 08 13:54:24 2007 -0800
+++ b/libvirt-cim.spec.in Thu Nov 08 14:00:55 2007 -0800
@@ -34,7 +34,7 @@ rm -fr %{buildroot}
rm -fr %{buildroot}
%makeinstall PROVIDERDIR=%{buildroot}%{_libdir}/cmpi
-cp provider-register.sh register_base.sh %{buildroot}%{_datadir}/libvirt-cim/
+cp provider-register.sh %{buildroot}%{_datadir}/libvirt-cim/
rm -f $RPM_BUILD_ROOT%{_libdir}/*.la
rm -f $RPM_BUILD_ROOT%{_libdir}/*.a
rm -f $RPM_BUILD_ROOT%{_libdir}/cmpi/*.la
@@ -43,17 +43,34 @@ rm -f $RPM_BUILD_ROOT%{_libdir}/cmpi/*.a
%clean
rm -fr %{buildroot}
+%pre
+%define REGISTRATION %{_datadir}/%{name}/*.registration
+%define SCHEMA %{_datadir}/%{name}/*.mof
+%define NAMESPACE /root/virt
+
+%{_datadir}/%{name}/provider-register.sh -d -t pegasus \
+ -n %{NAMESPACE} \
+ -r %{REGISTRATION} -m %{SCHEMA} || true
+
%post
/sbin/ldconfig
-%postun
+%{_datadir}/%{name}/provider-register.sh -t pegasus \
+ -n %{NAMESPACE} \
+ -r %{REGISTRATION} -m %{SCHEMA} || true
+
+%preun
/sbin/ldconfig
+
+%{_datadir}/%{name}/provider-register.sh -d -t pegasus \
+ -n %{NAMESPACE} \
+ -r %{REGISTRATION} -m %{SCHEMA} || true
%files
%defattr(-, root, root)
%doc README doc/CodingStyle doc/SubmittingPatches
-%doc provider-register.sh register_base.sh
+%doc provider-register.sh
%{_libdir}/lib*.so*
%{_libdir}/cmpi/lib*.so*
%{_datadir}/libvirt-cim/*.sh
17 years, 1 month
[PATCH] Add association results filtering
by Kaitlin Rupert
# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1194546376 28800
# Node ID 66548720dc50f268b861d336ac295003a9a03ec9
# Parent 404c4803b1b542676c4d283226a7cc3b7f3ab58d
Add association results filtering.
This adds result filtering so that an association only returns instances that match the result class specified during the query. Such an example is the following:
HostedService needs to return VSMS and RPCS instances when queried using CIM_ManagedElement as the result class. However, if CIM_VSMS is specified as the result class, then only the VSMS instance needs to be returned.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 404c4803b1b5 -r 66548720dc50 std_association.c
--- a/std_association.c Fri Nov 02 15:29:38 2007 -0700
+++ b/std_association.c Thu Nov 08 10:26:16 2007 -0800
@@ -47,6 +47,17 @@ void set_reference(struct std_assoc *ass
(CMPIValue *)&target, CMPI_ref);
}
+static bool match_op(const CMPIBroker *broker,
+ CMPIObjectPath *op,
+ const char *filter_class)
+{
+ if ((filter_class == NULL) ||
+ CMClassPathIsA(broker, op, filter_class, NULL))
+ return true;
+ else
+ return false;
+}
+
static bool match_class(const CMPIBroker *broker,
const char *ns,
const char *test_class,
@@ -58,10 +69,44 @@ static bool match_class(const CMPIBroker
if ((test_class == NULL) ||
(comp_class == NULL) ||
- CMClassPathIsA(broker, rop, comp_class, NULL))
+ match_op(broker, rop, comp_class))
return true;
else
return false;
+}
+
+static CMPIStatus filter_results(struct inst_list *list,
+ char *ns,
+ const char *filter_class,
+ const CMPIBroker *broker)
+{
+ struct inst_list result_list;
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIObjectPath *op;
+ int i;
+
+ result_list = *list;
+ inst_list_init(list);
+
+ for (i = 0; result_list.list[i] != NULL; i++) {
+ op = CMGetObjectPath(result_list.list[i], &s);
+ if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op))
+ goto out;
+
+ s = CMSetNameSpace(op, ns);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ if (!match_op(broker, op, filter_class))
+ continue;
+
+ inst_list_add(list, result_list.list[i]);
+ }
+
+out:
+ inst_list_free(&result_list);
+
+ return s;
}
static struct std_assoc *
@@ -142,6 +187,20 @@ static CMPIStatus do_assoc(struct std_as
goto out;
} else {
CU_DEBUG("\thandler returned CMPI_RC_OK.\n");
+ }
+
+ if (list.list == NULL) {
+ CU_DEBUG("\tlist is empty.\n");
+ goto out;
+ }
+
+ s = filter_results(&list,
+ NAMESPACE(ref),
+ info->result_class,
+ ctx->brkr);
+ if (s.rc != CMPI_RC_OK) {
+ CU_DEBUG("\tfilter_results did not return CMPI_RC_OK.\n");
+ goto out;
}
if (list.list == NULL) {
17 years, 1 month
[PATCH] Fix device pool list to include Disk and Network
by Dan Smith
# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1194547428 28800
# Node ID bd1b1067d106ecc1546c3b2436a43f59f8eaba15
# Parent 0dddeb4368b37821390aa7c56fdcca2db839e824
Fix device pool list to include Disk and Network
This makes HostedResourcePool return all four pools instead of
just Memory and Processor pools.
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 0dddeb4368b3 -r bd1b1067d106 src/Virt_DevicePool.c
--- a/src/Virt_DevicePool.c Thu Nov 08 09:56:43 2007 -0800
+++ b/src/Virt_DevicePool.c Thu Nov 08 10:43:48 2007 -0800
@@ -45,7 +45,11 @@
static const CMPIBroker *_BROKER;
-char *device_pool_names[] = {"ProcessorPool", "MemoryPool", NULL};
+char *device_pool_names[] = {"ProcessorPool",
+ "MemoryPool",
+ "DiskPool",
+ "NetworkPool",
+ NULL};
struct disk_pool {
char *tag;
17 years, 1 month
[PATCH] Add association results filtering
by Kaitlin Rupert
# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1194471308 28800
# Node ID 5959f8f0e5e87540fb7da0bc5a0365388112452b
# Parent 404c4803b1b542676c4d283226a7cc3b7f3ab58d
Add association results filtering.
This adds result filtering so that an association only returns instances that match the result class specified during the query. Such an example is the following:
HostedService needs to return VSMS and RPCS instances when queried using CIM_ManagedElement as the result class. However, if CIM_VSMS is specified as the result class, then only the VSMS instance needs to be returned.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 404c4803b1b5 -r 5959f8f0e5e8 std_association.c
--- a/std_association.c Fri Nov 02 15:29:38 2007 -0700
+++ b/std_association.c Wed Nov 07 13:35:08 2007 -0800
@@ -47,6 +47,17 @@ void set_reference(struct std_assoc *ass
(CMPIValue *)&target, CMPI_ref);
}
+static bool match_op(const CMPIBroker *broker,
+ CMPIObjectPath *op,
+ const char *filter_class)
+{
+ if ((filter_class == NULL) ||
+ CMClassPathIsA(broker, op, filter_class, NULL))
+ return true;
+ else
+ return false;
+}
+
static bool match_class(const CMPIBroker *broker,
const char *ns,
const char *test_class,
@@ -58,10 +69,55 @@ static bool match_class(const CMPIBroker
if ((test_class == NULL) ||
(comp_class == NULL) ||
- CMClassPathIsA(broker, rop, comp_class, NULL))
+ match_op(broker, rop, comp_class))
return true;
else
return false;
+}
+
+static CMPIStatus filter_results(struct inst_list *list,
+ char *ns,
+ const char *filter_class,
+ const CMPIBroker *broker)
+{
+ struct inst_list result_list;
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIObjectPath *op;
+ int i, c = 0;
+
+ inst_list_init(&result_list);
+
+ for (i = 0; list->list[i] != NULL; i++) {
+ op = CMGetObjectPath(list->list[i], &s);
+ if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op))
+ goto out;
+
+ s = CMSetNameSpace(op, ns);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ if (!match_op(broker, op, filter_class))
+ continue;
+
+ inst_list_add(&result_list, list->list[i]);
+ c++;
+ }
+
+ inst_list_free(list);
+ if (list->list != NULL) {
+ CU_DEBUG("\tinst_list_free failed.\n");
+ goto out;
+ }
+
+ inst_list_init(list);
+
+ for (i = 0; i <= c; i++)
+ inst_list_add(list, result_list.list[i]);
+
+out:
+ inst_list_free(&result_list);
+
+ return s;
}
static struct std_assoc *
@@ -142,6 +198,20 @@ static CMPIStatus do_assoc(struct std_as
goto out;
} else {
CU_DEBUG("\thandler returned CMPI_RC_OK.\n");
+ }
+
+ if (list.list == NULL) {
+ CU_DEBUG("\tlist is empty.\n");
+ goto out;
+ }
+
+ s = filter_results(&list,
+ NAMESPACE(ref),
+ info->result_class,
+ ctx->brkr);
+ if (s.rc != CMPI_RC_OK) {
+ CU_DEBUG("\tfilter_results did not return CMPI_RC_OK.\n");
+ goto out;
}
if (list.list == NULL) {
17 years, 1 month
[PATCH] Fix some really horrible cruft in ComputerSystem
by Dan Smith
# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1194492744 28800
# Node ID af241b38b17ee4b3f2c2ee94f41aafd3023240d7
# Parent 92ed39296eb881deddc2d34fa9ee0524aefc1a53
Fix some really horrible cruft in ComputerSystem
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 92ed39296eb8 -r af241b38b17e src/Virt_ComputerSystem.c
--- a/src/Virt_ComputerSystem.c Wed Nov 07 09:01:06 2007 -0800
+++ b/src/Virt_ComputerSystem.c Wed Nov 07 19:32:24 2007 -0800
@@ -376,7 +376,7 @@ static CMPIStatus get_domain(const CMPIO
const CMPIResult *results,
char *name)
{
- CMPIInstance *inst[2] = {NULL, NULL};
+ CMPIInstance *inst;
CMPIStatus s;
virConnectPtr conn = NULL;
const char *prop = NULL;
@@ -385,15 +385,15 @@ static CMPIStatus get_domain(const CMPIO
if (conn == NULL)
return s;
- inst[0] = instance_from_name(_BROKER, conn, name, reference);
- if (inst[0] == NULL) {
+ inst = instance_from_name(_BROKER, conn, name, reference);
+ if (inst == NULL) {
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_FAILED,
"Unable to find `%s'", name);
goto out;
}
- prop = cu_compare_ref(reference, inst[0]);
+ prop = cu_compare_ref(reference, inst);
if (prop != NULL) {
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_NOT_FOUND,
@@ -401,10 +401,8 @@ static CMPIStatus get_domain(const CMPIO
goto out;
}
- cu_return_instances(results, inst);
-
+ CMReturnInstance(results, inst);
CMSetStatus(&s, CMPI_RC_OK);
-
out:
virConnectClose(conn);
17 years, 1 month
[PATCH 0 of 5] VSMS Dynamic Devices
by Dan Smith
This set adds dynamic attach/detach support to device_parsing, as well
as some other tweaks necessary for the changes to VSMS to work. This
makes VSMS dynamically attach/detach devices if the domain is running.
Currently this only works for Network and Disk devices, but adding
processor and memory support in the attach functions should be easy.
17 years, 1 month
[PATCH] Update CS and VSMS for compare_ref changes
by Dan Smith
# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1194453696 28800
# Node ID 55d37343f11204b02dde1df910001e8021a5afc5
# Parent 704edab17bc7ceac8a0d59285cf7bfb3c900b188
Update CS and VSMS for compare_ref changes
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 704edab17bc7 -r 55d37343f112 src/Virt_ComputerSystem.c
--- a/src/Virt_ComputerSystem.c Mon Nov 05 11:12:26 2007 -0800
+++ b/src/Virt_ComputerSystem.c Wed Nov 07 08:41:36 2007 -0800
@@ -379,12 +379,7 @@ static CMPIStatus get_domain(const CMPIO
CMPIInstance *inst[2] = {NULL, NULL};
CMPIStatus s;
virConnectPtr conn = NULL;
- const struct cu_property *prop;
- static struct cu_property props[] = {
- {"CreationClassName", 0},
- {"Name", 1},
- {NULL, 0}
- };
+ const char *prop = NULL;
conn = lv_connect(_BROKER, &s);
if (conn == NULL)
@@ -398,11 +393,11 @@ static CMPIStatus get_domain(const CMPIO
goto out;
}
- prop = cu_compare_ref(reference, inst[0], props);
+ prop = cu_compare_ref(reference, inst[0]);
if (prop != NULL) {
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_NOT_FOUND,
- "No such instance (%s)", prop->name);
+ "No such instance (%s)", prop);
goto out;
}
diff -r 704edab17bc7 -r 55d37343f112 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c Mon Nov 05 11:12:26 2007 -0800
+++ b/src/Virt_VirtualSystemManagementService.c Wed Nov 07 08:41:36 2007 -0800
@@ -1030,24 +1030,17 @@ static CMPIStatus GetInstance(CMPIInstan
{
CMPIInstance *inst;
CMPIStatus s;
- const struct cu_property *prop;
- static struct cu_property props[] = {
- {"CreationClassName", 0},
- {"SystemName", 0},
- {"SystemCreationClassName", 0},
- {"Name", 1},
- {NULL, 0}
- };
+ const char *prop;
s = _get_vsms(ref, &inst, 0);
if (s.rc != CMPI_RC_OK)
return s;
- prop = cu_compare_ref(ref, inst, props);
+ prop = cu_compare_ref(ref, inst);
if (prop != NULL) {
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_NOT_FOUND,
- "No such instance (%s)", prop->name);
+ "No such instance (%s)", prop);
} else {
CMSetStatus(&s, CMPI_RC_OK);
CMReturnInstance(results, inst);
17 years, 1 month
[PATCH] Make ResourcePoolConfigurationService return errors when appropriate
by Dan Smith
# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1194454371 28800
# Node ID 2626820d78b2d70564096dcacf6a2f1b2bc726e1
# Parent 55d37343f11204b02dde1df910001e8021a5afc5
Make ResourcePoolConfigurationService return errors when appropriate
and fix up some other general error-handling around the needed changes.
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 55d37343f112 -r 2626820d78b2 src/Virt_ResourcePoolConfigurationService.c
--- a/src/Virt_ResourcePoolConfigurationService.c Wed Nov 07 08:41:36 2007 -0800
+++ b/src/Virt_ResourcePoolConfigurationService.c Wed Nov 07 08:52:51 2007 -0800
@@ -89,7 +89,8 @@ DEFAULT_EQ();
DEFAULT_EQ();
DEFAULT_INST_CLEANUP();
-static CMPIInstance *rpcs_instance(const CMPIObjectPath *reference)
+static CMPIStatus rpcs_instance(const CMPIObjectPath *reference,
+ CMPIInstance **_inst)
{
CMPIInstance *inst;
CMPIInstance *host;
@@ -98,28 +99,47 @@ static CMPIInstance *rpcs_instance(const
s = get_host_cs(_BROKER, reference, &host);
if (s.rc != CMPI_RC_OK)
- return NULL;
+ goto out;
inst = get_typed_instance(_BROKER,
"ResourcePoolConfigurationService",
NAMESPACE(reference));
+ if (inst == NULL) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to get "
+ "ResourcePoolConfigurationService instance");
+ goto out;
+ }
CMSetProperty(inst, "Name",
(CMPIValue *)"RPCS", CMPI_chars);
prop = CMGetProperty(host, "CreationClassName", &s);
- if (s.rc != CMPI_RC_OK)
- return NULL;
+ if (s.rc != CMPI_RC_OK) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to get CreationClassName from HostSystem");
+ goto out;
+ }
+
CMSetProperty(inst, "SystemCreationClassName",
(CMPIValue *)&prop.value.string, CMPI_string);
prop = CMGetProperty(host, "Name", NULL);
- if (s.rc != CMPI_RC_OK)
- return NULL;
+ if (s.rc != CMPI_RC_OK) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to get Name from HostSystem");
+ goto out;
+ }
+
CMSetProperty(inst, "SystemName",
(CMPIValue *)&prop.value.string, CMPI_string);
- return inst;
+ *_inst = inst;
+ out:
+ return s;
}
static CMPIStatus GetInstance(CMPIInstanceMI *self,
@@ -129,12 +149,23 @@ static CMPIStatus GetInstance(CMPIInstan
const char **properties)
{
CMPIInstance *inst;
-
- inst = rpcs_instance(reference);
-
- CMReturnInstance(results, inst);
-
- return (CMPIStatus){CMPI_RC_OK, NULL};
+ CMPIStatus s;
+ const char *prop = NULL;
+
+ s = rpcs_instance(reference, &inst);
+ if (s.rc != CMPI_RC_OK)
+ return s;
+
+ prop = cu_compare_ref(reference, inst);
+ if (prop != NULL) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance (%s)", prop);
+ } else {
+ CMReturnInstance(results, inst);
+ }
+
+ return s;
}
static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self,
@@ -143,12 +174,13 @@ static CMPIStatus EnumInstanceNames(CMPI
const CMPIObjectPath *reference)
{
CMPIInstance *inst;
-
- inst = rpcs_instance(reference);
-
- cu_return_instance_name(results, inst);
-
- return (CMPIStatus){CMPI_RC_OK, NULL};
+ CMPIStatus s;
+
+ s = rpcs_instance(reference, &inst);
+ if (s.rc == CMPI_RC_OK)
+ cu_return_instance_name(results, inst);
+
+ return s;
}
static CMPIStatus EnumInstances(CMPIInstanceMI *self,
@@ -159,12 +191,13 @@ static CMPIStatus EnumInstances(CMPIInst
{
CMPIInstance *inst;
-
- inst = rpcs_instance(reference);
-
- CMReturnInstance(results, inst);
-
- return (CMPIStatus){CMPI_RC_OK, NULL};
+ CMPIStatus s;
+
+ s = rpcs_instance(reference, &inst);
+ if (s.rc == CMPI_RC_OK)
+ CMReturnInstance(results, inst);
+
+ return s;
}
17 years, 1 month
[PATCH] Fix the XML we generate for an incoming system to include the <os> block
by Dan Smith
# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1423944550 28800
# Node ID 5789eadba6e6f71822493043214c3a8749ebb2f6
# Parent babb2ffdc4c2c3f11a3281af4fb33cc3257127f8
Fix the XML we generate for an incoming system to include the <os> block
which seems to be required. Without it, libvirt-0.2.0 seems to break.
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r babb2ffdc4c2 -r 5789eadba6e6 libxkutil/xmlgen.c
--- a/libxkutil/xmlgen.c Tue Oct 30 11:11:32 2007 -0700
+++ b/libxkutil/xmlgen.c Sat Feb 14 12:09:10 2015 -0800
@@ -33,7 +33,6 @@
#include "cmpimacs.h"
#endif
-#if 0
static char *__tag_attr(struct kv *attrs, int count)
{
char *result = strdup("");
@@ -94,7 +93,6 @@ static char *tagify(char *tagname, char
return result;
}
-#endif
static char *disk_block_xml(const char *path, const char *vdev)
{
@@ -265,11 +263,55 @@ static char *system_xml(struct domain *d
return xml;
}
+static char *os_xml(struct domain *domain)
+{
+ struct os_info *os = &domain->os_info;
+ int ret;
+ char *xml;
+ char *type = NULL;
+ char *kernel = NULL;
+ char *initrd = NULL;
+ char *cmdline = NULL;
+
+ if (os->type == NULL)
+ os->type = strdup("linux");
+
+ if (os->kernel == NULL)
+ os->kernel = strdup("/dev/null");
+
+ type = tagify("type", os->type, NULL, 0);
+ kernel = tagify("kernel", os->kernel, NULL, 0);
+ initrd = tagify("initrd", os->initrd, NULL, 0);
+ cmdline = tagify("cmdline", os->cmdline, NULL, 0);
+
+ ret = asprintf(&xml,
+ "<os>\n"
+ " %s\n"
+ " %s\n"
+ " %s\n"
+ " %s\n"
+ "</os>\n",
+ type,
+ kernel,
+ initrd,
+ cmdline);
+ if (ret == -1)
+ xml = NULL;
+
+ free(type);
+ free(kernel);
+ free(initrd);
+ free(cmdline);
+
+ return xml;
+}
+
char *system_to_xml(struct domain *dominfo)
{
char *devxml = strdup("");
char *sysdevxml = strdup("");
char *sysxml = NULL;
+ char *osxml = NULL;
char *xml = NULL;
int ret;
uint8_t uuid[16];
@@ -285,18 +327,21 @@ char *system_to_xml(struct domain *domin
concat_devxml(&sysdevxml, dominfo->dev_vcpu, dominfo->dev_vcpu_ct);
sysxml = system_xml(dominfo);
+ osxml = os_xml(dominfo);
ret = asprintf(&xml,
"<domain type='xen'>\n"
"<uuid>%s</uuid>\n"
- "%s\n"
- "%s\n"
+ "%s"
+ "%s"
+ "%s"
"<devices>\n"
- "%s\n"
+ "%s"
"</devices>\n"
"</domain>\n",
uuidstr,
sysxml,
+ osxml,
sysdevxml,
devxml);
if (ret == -1)
@@ -304,6 +349,7 @@ char *system_to_xml(struct domain *domin
free(devxml);
free(sysdevxml);
+ free(osxml);
free(sysxml);
return xml;
17 years, 1 month
[PATCH] Add cu_compare_ref()
by Dan Smith
# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1194042578 25200
# Node ID 0df048ad2e99c8eda6c843f148168a9fa0161399
# Parent 05b01d03f0b801afe266d8d012bc464be6a2d165
Add cu_compare_ref()
This provides a generic way to easily compare a given ref against an instance,
which should be useful in GetInstance functions for making sure the returned
instance matches what was asked.
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 05b01d03f0b8 -r 0df048ad2e99 instance_util.c
--- a/instance_util.c Sun Feb 15 22:01:53 2015 -0800
+++ b/instance_util.c Fri Nov 02 15:29:38 2007 -0700
@@ -19,6 +19,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdbool.h>
+#include <string.h>
#include "libcmpiutil.h"
@@ -68,6 +69,59 @@ unsigned int cu_return_instance_names(co
return c;
}
+static bool _compare_data(const CMPIData *a, const CMPIData *b)
+{
+ if (a->type != b->type)
+ return false;
+
+ if (a->type & CMPI_string) {
+ const char *as = CMGetCharPtr(a->value.string);
+ const char *bs = CMGetCharPtr(b->value.string);
+
+ return STREQ(as, bs);
+ } else if (a->type & CMPI_INTEGER) {
+ return memcmp(&a->value, &b->value, sizeof(a->value)) == 0;
+ }
+
+ CU_DEBUG("Unhandled CMPI type: `%i'", a->type);
+
+ return false;
+}
+
+const struct cu_property *cu_compare_ref(const CMPIObjectPath *ref,
+ const CMPIInstance *inst,
+ const struct cu_property *props)
+{
+ const struct cu_property *p = NULL;
+ int i;
+ CMPIStatus s;
+
+ for (i = 0; props[i].name != NULL; i++) {
+ CMPIData kd, pd;
+
+ p = &props[i];
+
+ kd = CMGetKey(ref, p->name, &s);
+ if (s.rc != CMPI_RC_OK) {
+ if (p->required)
+ goto out;
+ else
+ continue;
+ }
+
+ pd = CMGetProperty(inst, p->name, &s);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ if (!_compare_data(&kd, &pd))
+ goto out;
+ }
+
+ p = NULL;
+ out:
+ return p;
+}
+
/*
* Local Variables:
* mode: C
diff -r 05b01d03f0b8 -r 0df048ad2e99 libcmpiutil.h
--- a/libcmpiutil.h Sun Feb 15 22:01:53 2015 -0800
+++ b/libcmpiutil.h Fri Nov 02 15:29:38 2007 -0700
@@ -336,6 +336,27 @@ void inst_list_free(struct inst_list *li
* @returns nonzero on success, zero on failure
*/
int inst_list_add(struct inst_list *list, CMPIInstance *inst);
+
+struct cu_property {
+ const char *name;
+ bool required;
+};
+
+/**
+ * Compare key values in a reference to properties in an instance,
+ * making sure they are identical. If props identifies a particular
+ * key as not required, then absence in the object path will not
+ * result in failure of this test.
+ *
+ * @param ref The ObjectPath to examine
+ * @param inst The Instance to compare
+ * @param props A NULL-terminated list of properties to compare
+ * @returns A pointer to the property structure of the first
+ * non-matching property, or NULL if all match
+ */
+const struct cu_property *cu_compare_ref(const CMPIObjectPath *ref,
+ const CMPIInstance *inst,
+ const struct cu_property *props);
#define DEFAULT_EIN(pn) \
static CMPIStatus pn##EnumInstanceNames(CMPIInstanceMI *self, \
17 years, 1 month