# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1193849716 25200
# Node ID dde11a85b5c04cfe4c3028fe48dc5e383a80f946
# Parent bf5ad6924b99903d68d019a7c5faaa2f5a5d1ef9
Fix VSMS instance code to refuse to return an instance if ref is invalid
Tweaked to include the proper NOT_FOUND error code and fix the build order.
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r bf5ad6924b99 -r dde11a85b5c0 src/Makefile.am
--- a/src/Makefile.am Mon Oct 29 15:39:52 2007 -0400
+++ b/src/Makefile.am Wed Oct 31 09:55:16 2007 -0700
@@ -29,13 +29,13 @@ provider_LTLIBRARIES = libVirt_ComputerS
libVirt_SystemDevice.la \
libVirt_ComputerSystemIndication.la \
libVirt_RASD.la \
+ libVirt_HostSystem.la \
libVirt_VirtualSystemManagementService.la \
libVirt_VirtualSystemManagementCapabilities.la \
libVirt_EnabledLogicalElementCapabilities.la \
libVirt_AllocationCapabilities.la \
libVirt_SettingsDefineCapabilities.la \
libVirt_VSSD.la \
- libVirt_HostSystem.la \
libVirt_HostedDependency.la \
libVirt_RegisteredProfile.la \
libVirt_ElementConformsToProfile.la \
@@ -56,7 +56,7 @@ libVirt_ComputerSystemIndication_la_LIBA
libVirt_ComputerSystemIndication_la_LIBADD = -lVirt_ComputerSystem -lpthread -lrt
libVirt_VirtualSystemManagementService_la_SOURCES =
Virt_VirtualSystemManagementService.c
-libVirt_VirtualSystemManagementService_la_LIBADD = -lVirt_ComputerSystem
-lVirt_ComputerSystemIndication -lVirt_RASD
+libVirt_VirtualSystemManagementService_la_LIBADD = -lVirt_ComputerSystem
-lVirt_ComputerSystemIndication -lVirt_RASD -lVirt_HostSystem
libVirt_VirtualSystemManagementCapabilities_la_SOURCES =
Virt_VirtualSystemManagementCapabilities.c
diff -r bf5ad6924b99 -r dde11a85b5c0 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c Mon Oct 29 15:39:52 2007 -0400
+++ b/src/Virt_VirtualSystemManagementService.c Wed Oct 31 09:55:16 2007 -0700
@@ -44,6 +44,7 @@
#include "Virt_ComputerSystem.h"
#include "Virt_ComputerSystemIndication.h"
#include "Virt_RASD.h"
+#include "Virt_HostSystem.h"
#include "svpc_types.h"
const static CMPIBroker *_BROKER;
@@ -896,18 +897,24 @@ STDIM_MethodMIStub(, Virt_VirtualSystemM
STDIM_MethodMIStub(, Virt_VirtualSystemManagementService,
_BROKER, CMNoHook, my_handlers);
-
-static CMPIStatus return_vsms(const CMPIObjectPath *reference,
- const CMPIResult *results,
- int name_only)
+static CMPIStatus _get_vsms(const CMPIObjectPath *reference,
+ CMPIInstance **_inst,
+ int name_only)
{
CMPIStatus s;
CMPIInstance *inst;
+ CMPIInstance *host;
+ char *val = NULL;
+
+ s = get_host_cs(_BROKER, reference, &host);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
inst = get_typed_instance(_BROKER,
"VirtualSystemManagementService",
NAMESPACE(reference));
if (inst == NULL) {
+ CU_DEBUG("Failed to get typed instance");
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_FAILED,
"Failed to create instance");
@@ -916,6 +923,46 @@ static CMPIStatus return_vsms(const CMPI
CMSetProperty(inst, "Name",
(CMPIValue *)"Management Service", CMPI_chars);
+
+ if (cu_get_str_prop(host, "Name", &val) != CMPI_RC_OK) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to get name of System");
+ goto out;
+ }
+
+ CMSetProperty(inst, "SystemName",
+ (CMPIValue *)val, CMPI_chars);
+ free(val);
+
+ if (cu_get_str_prop(host, "CreationClassName", &val) != CMPI_RC_OK)
{
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to get creation class of system");
+ goto out;
+ }
+
+ CMSetProperty(inst, "SystemCreationClassName",
+ (CMPIValue *)val, CMPI_chars);
+ free(val);
+
+ CMSetStatus(&s, CMPI_RC_OK);
+
+ *_inst = inst;
+ out:
+ return s;
+}
+
+static CMPIStatus return_vsms(const CMPIObjectPath *reference,
+ const CMPIResult *results,
+ int name_only)
+{
+ CMPIInstance *inst;
+ CMPIStatus s;
+
+ s = _get_vsms(reference, &inst, name_only);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
if (name_only)
cu_return_instance_name(results, inst);
@@ -923,7 +970,6 @@ static CMPIStatus return_vsms(const CMPI
CMReturnInstance(results, inst);
CMSetStatus(&s, CMPI_RC_OK);
-
out:
return s;
}
@@ -946,13 +992,58 @@ static CMPIStatus EnumInstances(CMPIInst
return return_vsms(reference, results, 0);
}
+static int compare_prop(const CMPIObjectPath *ref,
+ const CMPIInstance *inst,
+ const char *name,
+ int mandatory)
+{
+ char *prop = NULL;
+ char *key = NULL;
+ int rc = 0;
+
+ key = cu_get_str_path(ref, name);
+ if (key == NULL) {
+ rc = !mandatory;
+ goto out;
+ }
+
+ if (cu_get_str_prop(inst, name, &prop) != CMPI_RC_OK)
+ goto out;
+
+ rc = STREQ(key, prop);
+ out:
+ free(prop);
+ free(key);
+
+ return rc;
+}
+
static CMPIStatus GetInstance(CMPIInstanceMI *self,
const CMPIContext *context,
const CMPIResult *results,
- const CMPIObjectPath *reference,
+ const CMPIObjectPath *ref,
const char **properties)
{
- return return_vsms(reference, results, 0);
+ CMPIInstance *inst;
+ CMPIStatus s;
+
+ s = _get_vsms(ref, &inst, 0);
+ if (s.rc != CMPI_RC_OK)
+ return s;
+
+ if (!compare_prop(ref, inst, "CreationClassName", 0) ||
+ !compare_prop(ref, inst, "SystemName", 0) ||
+ !compare_prop(ref, inst, "Name", 1) ||
+ !compare_prop(ref, inst, "SystemCreationClassName", 0))
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance");
+ else {
+ CMSetStatus(&s, CMPI_RC_OK);
+ CMReturnInstance(results, inst);
+ }
+
+ return s;
}
DEFAULT_CI();