Attached is a combined patch that supports cross-namespace association
for Xen_HostedComputerSystem. It includes Raj's filtering and my hacks
for smash integration. Xen_ComputerSystem was also modified to only
instrument root/cimv2. E.g. calling EnumInstanceNames on Xen_CS in
namespace smash will return 0 instances.
To use this patch, Xen_HCS and Xen_CS mof files must be imported to
'smash' namespace as well as root/cimv2. I have tested the patch quite
thoroughly and ensured the correct namespace is set in object paths
returned by provider.
So what do you think? If this approach is acceptable, I will convert
all effected associations (and their endpoints if appropriate) to use
this mechanism.
Jim
diff -r 8e52de626fb5 src/Xen_ComputerSystem.c
--- a/src/Xen_ComputerSystem.c Tue Jun 27 17:39:16 2006 -0600
+++ b/src/Xen_ComputerSystem.c Fri Jul 14 17:19:52 2006 -0600
@@ -25,6 +25,7 @@
#include "cmpift.h"
#include "cmpimacs.h"
+#define HOST_INSTRUMENTATION_NS "smash"
// ----------------------------------------------------------------------------
// COMMON GLOBAL VARIABLES
@@ -90,7 +91,7 @@ static CMPIStatus EnumInstanceNames(
CMPIObjectPath * reference) /* [in] Contains target
namespace and classname. */
{
CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM
operations. */
- _RESOURCES * resources; /* Handle to the list of system
resources. */
+ _RESOURCES * resources = NULL; /* Handle to the list
of system resources. */
_RESOURCE * resource; /* Handle to each system
resource. */
char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target
namespace. */
int found = 0; /* Found any instances? */
@@ -100,6 +101,11 @@ static CMPIStatus EnumInstanceNames(
_SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
context, NULL))));
_SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
reference, NULL))));
_SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
+
+ if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
+ _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for System
Virtualization Profile", namespace));
+ goto exit;
+ }
/* Get a handle to the list of system resources. */
if (!Xen_ComputerSystem_getResources(&resources)) {
@@ -147,9 +153,10 @@ static CMPIStatus EnumInstanceNames(
}
_SBLIM_TRACE(2,("--- %d object paths found", found));
+
+exit:
CMReturnDone(results);
-exit:
/* Free the list of system resources. */
if (!Xen_ComputerSystem_freeResources(resources)) {
_SBLIM_TRACE(1,("--- _freeResources() failed"));
@@ -171,7 +178,7 @@ static CMPIStatus EnumInstances(
const char ** properties) /* [in] List of desired
properties (NULL=all). */
{
CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM
operations. */
- _RESOURCES * resources; /* Handle to the list of system
resources. */
+ _RESOURCES * resources = NULL; /* Handle to the list
of system resources. */
_RESOURCE * resource; /* Handle to each system
resource. */
char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target
namespace. */
int found = 0; /* Found any resource
instances? */
@@ -181,6 +188,11 @@ static CMPIStatus EnumInstances(
_SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
context, NULL))));
_SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
reference, NULL))));
_SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
+
+ if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
+ _SBLIM_TRACE(2,("--- \"%s\" is not a valid namespace for System
Virtualization Profile", namespace));
+ goto exit;
+ }
/* Get a handle to the list of system resources. */
if (!Xen_ComputerSystem_getResources(&resources)) {
@@ -228,9 +240,10 @@ static CMPIStatus EnumInstances(
}
_SBLIM_TRACE(2,("--- %d instances found", found));
+
+exit:
CMReturnDone(results);
-exit:
/* Free the list of system resources. */
if (!Xen_ComputerSystem_freeResources(resources)) {
_SBLIM_TRACE(1,("--- _freeResources() failed"));
@@ -252,7 +265,7 @@ static CMPIStatus GetInstance(
const char ** properties) /* [in] List of desired
properties (NULL=all). */
{
CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM
operations. */
- _RESOURCES * resources; /* Handle to the list of system
resources. */
+ _RESOURCES * resources = NULL; /* Handle to the list
of system resources. */
_RESOURCE * resource; /* Handle to the system
resource. */
char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target
namespace. */
int found = 0; /* Found the target instance? */
@@ -262,6 +275,11 @@ static CMPIStatus GetInstance(
_SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
context, NULL))));
_SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
reference, NULL))));
_SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
+
+ if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
+ _SBLIM_TRACE(2,("--- \"%s\" is not a valid namespace for System
Virtualization Profile", namespace));
+ goto exit;
+ }
/* Get a handle to the list of system resources. */
if (!Xen_ComputerSystem_getResources(&resources)) {
@@ -313,9 +331,10 @@ static CMPIStatus GetInstance(
CMReturnInstance(results, instance);
_SBLIM_TRACE(2,("--- instance found"));
+
+exit:
CMReturnDone(results);
-exit:
/* Free the list of system resources. */
if (!Xen_ComputerSystem_freeResources(resources)) {
_SBLIM_TRACE(1,("--- _freeResources() failed"));
@@ -337,7 +356,7 @@ static CMPIStatus SetInstance(
CMPIInstance * newinstance) /* [in] Contains the new
instance data. */
{
CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM
operations. */
- _RESOURCES * resources; /* Handle to the list of system
resources. */
+ _RESOURCES * resources = NULL; /* Handle to the list
of system resources. */
_RESOURCE * resource; /* Handle to the system
resource. */
char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target
namespace. */
int found = 0; /* Found the target instance? */
@@ -349,6 +368,11 @@ static CMPIStatus SetInstance(
_SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
newinstance, NULL))));
_SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
+ if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
+ _SBLIM_TRACE(2,("--- \"%s\" is not a valid namespace for System
Virtualization Profile", namespace));
+ goto exit;
+ }
+
/* Get a handle to the list of system resources. */
if (!Xen_ComputerSystem_getResources(&resources)) {
_SBLIM_TRACE(1,("--- _getResources() failed"));
@@ -409,7 +433,7 @@ static CMPIStatus CreateInstance(
CMPIInstance * newinstance) /* [in] Contains the new
instance data. */
{
CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM
operations. */
- _RESOURCES * resources; /* Handle to the list of system
resources. */
+ _RESOURCES * resources = NULL; /* Handle to the list
of system resources. */
_RESOURCE * resource; /* Handle to the system
resource. */
char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target
namespace. */
int found = 0; /* Found the target instance? */
@@ -420,6 +444,11 @@ static CMPIStatus CreateInstance(
_SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
reference, NULL))));
_SBLIM_TRACE(2, ("--- newinstance=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
newinstance, NULL))));
_SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
+
+ if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
+ _SBLIM_TRACE(2,("--- \"%s\" is not a valid namespace for System
Virtualization Profile", namespace));
+ goto exit;
+ }
/* WORKAROUND FOR PEGASUS BUG?! reference does not contain object path,
only namespace & classname. */
reference = CMGetObjectPath(newinstance, NULL);
@@ -487,7 +516,7 @@ static CMPIStatus DeleteInstance(
CMPIObjectPath * reference) /* [in] Contains the target
namespace, classname and object path. */
{
CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM
operations. */
- _RESOURCES * resources; /* Handle to the list of system
resources. */
+ _RESOURCES * resources = NULL; /* Handle to the list
of system resources. */
_RESOURCE * resource; /* Handle to the system resource. */
char * namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target
namespace. */
int found = 0; /* Found the target instance? */
@@ -497,6 +526,11 @@ static CMPIStatus DeleteInstance(
_SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
context, NULL))));
_SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
reference, NULL))));
_SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
+
+ if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
+ _SBLIM_TRACE(2,("--- \"%s\" is not a valid namespace for System
Virtualization Profile", namespace));
+ goto exit;
+ }
/* Get a handle to the list of system resources. */
if (!Xen_ComputerSystem_getResources(&resources)) {
@@ -569,6 +603,12 @@ static CMPIStatus ExecQuery(
_SBLIM_TRACE(2, ("--- language=\"%s\"", language));
_SBLIM_TRACE(2, ("--- query=\"%s\"", query));
_SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
+
+ if (strcmp(namespace, HOST_INSTRUMENTATION_NS) == 0) {
+ _SBLIM_TRACE(1,("--- \"%s\" is not a valid namespace for System
Virtualization Profile", namespace));
+ CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_NAMESPACE,
"Invalid namespace specified for System Virtualization Profile");
+ goto exit;
+ }
/* EXECQUERY() IS NOT YET SUPPORTED FOR THIS CLASS */
CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
diff -r 8e52de626fb5 src/Xen_HostedComputerSystem.c
--- a/src/Xen_HostedComputerSystem.c Tue Jun 27 17:39:16 2006 -0600
+++ b/src/Xen_HostedComputerSystem.c Fri Jul 14 17:19:52 2006 -0600
@@ -54,6 +54,8 @@ static char * _RHSCLASSNAME = "CIM_Compu
static char * _RHSCLASSNAME = "CIM_ComputerSystem";
static char * _LHSPROPERTYNAME = "Dependent";
static char * _RHSPROPERTYNAME = "Antecedent";
+static char * _LHSNAMESPACE = "root/cimv2";
+static char * _RHSNAMESPACE = "smash";
// ----------------------------------------------------------------------------
// AssociationCleanup()
@@ -90,9 +92,9 @@ static CMPIStatus AssociatorNames(
const char * resultRole)
{
CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM
operations. */
- char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target
namespace. */
char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /*
Class of the source reference object */
char *targetclass; /* Class of the target
object(s). */
+ char *targetnamespace;
_SBLIM_ENTER("AssociatorNames");
_SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
@@ -102,12 +104,25 @@ static CMPIStatus AssociatorNames(
_SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
_SBLIM_TRACE(2, ("--- role=\"%s\"", role));
_SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
- _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
_SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
+ /* Determine the target class and namespace from the source class. */
+ if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
+ targetclass = _RHSCLASSNAME;
+ targetnamespace = _RHSNAMESPACE;
+ } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
+ targetclass = _LHSCLASSNAME;
+ targetnamespace = _LHSNAMESPACE;
+ } else {
+ _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
+ goto exit;
+ }
+ _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
+ _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
+
/* Check that the requested association class, if any, is supported. */
if (assocClass != NULL) {
- CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace,
_ASSOCCLASS, NULL);
+ CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, targetnamespace,
_ASSOCCLASS, NULL);
if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
_SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring
request."));
goto exit;
@@ -115,26 +130,14 @@ static CMPIStatus AssociatorNames(
}
/* Check that the reference matches the required role, if any. */
+ /* TODO: Not sure about this check. IIRC 'role' is a property name. */
if ((role != NULL) && strcmp(role, sourceclass) != 0) {
_SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring
request."));
goto exit;
}
- /* Determine the target class from the source class. */
- /* This used to be done with strcmp, we will now do it with CMClassPAthIsA*/
-
- if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
- targetclass = _RHSCLASSNAME;
- } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
- targetclass = _LHSCLASSNAME;
- } else {
- _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
- goto exit;
- }
- _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
-
/* Create an object path for the result class. */
- CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace,
targetclass, &status);
+ CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace,
targetclass, &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
_SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s",
CMGetCharPtr(status.msg)));
CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new
CMPIObjectPath");
@@ -149,19 +152,21 @@ static CMPIStatus AssociatorNames(
goto exit;
}
- /* Return all object paths that do not match the sourceClass and
resultClass, if specified.
- If the target class is CIM_ComputerSystem, the CIMOM will return both
Xen_ComputerSystem and the
- Host Provider. We need to return only the Host Provider.
- This will also work, if the source class is the Host Provider's class.
In that case, the only value returned
- will be the Xen_ComputerSystem.
- */
+ /* Return all object paths that match resultClass, if specified. */
while (CMHasNext(objectpaths, NULL)) {
CMPIData data = CMGetNext(objectpaths, NULL);
char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
- if (!(strcmp(class,sourceclass) == 0) && ((resultClass == NULL) ||
(strcmp(class,resultClass) == 0))) {
+
+ _SBLIM_TRACE(2, ("--- returning object path = \"%s\"",
CMGetCharPtr(CDToString(_BROKER, data.value.ref, NULL))));
+
+ /* Ignore possible instances of source class. */
+ if (strcmp(class,sourceclass) &&
+ (resultClass == NULL || CMClassPathIsA(_BROKER, data.value.ref,
resultClass, NULL))) {
+ _SBLIM_TRACE(2, ("--- returning object path = \"%s\"",
CMGetCharPtr(CDToString(_BROKER, data.value.ref, NULL))));
CMReturnObjectPath(results, data.value.ref);
}
}
+
CMReturnDone(results);
exit:
_SBLIM_RETURNSTATUS(status);
@@ -183,9 +188,9 @@ static CMPIStatus Associators(
char ** properties) /* [in] List of desired
properties (NULL=all). */
{
CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM
operations. */
- char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target
namespace. */
char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /*
Class of the source reference object */
char *targetclass; /* Class of the target
object(s). */
+ char *targetnamespace;
_SBLIM_ENTER("Associators");
_SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
@@ -195,12 +200,25 @@ static CMPIStatus Associators(
_SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
_SBLIM_TRACE(2, ("--- role=\"%s\"", role));
_SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole));
- _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
_SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
+
+ /* Determine the target class from the source class. */
+ if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
+ targetclass = _RHSCLASSNAME;
+ targetnamespace = _RHSNAMESPACE;
+ } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
+ targetclass = _LHSCLASSNAME;
+ targetnamespace = _LHSNAMESPACE;
+ } else {
+ _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
+ goto exit;
+ }
+ _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
+ _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
/* Check that the requested association class, if any, is supported. */
if (assocClass != NULL) {
- CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace,
_ASSOCCLASS, NULL);
+ CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, targetnamespace,
_ASSOCCLASS, NULL);
if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
_SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring
request."));
goto exit;
@@ -212,22 +230,9 @@ static CMPIStatus Associators(
_SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring
request."));
goto exit;
}
- CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_NOT_SUPPORTED, NULL);
-
- /* Determine the target class from the source class. */
- /* This used to be done with strcmp, we will now do it with CMClassPAthIsA*/
- if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
- targetclass = _RHSCLASSNAME;
- } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
- targetclass = _LHSCLASSNAME;
- } else {
- _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
- goto exit;
- }
- _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
/* Create an object path for the result class. */
- CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace,
targetclass, &status);
+ CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace,
targetclass, &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
_SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s",
CMGetCharPtr(status.msg)));
CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new
CMPIObjectPath");
@@ -242,17 +247,23 @@ static CMPIStatus Associators(
goto exit;
}
- /* Return all instances that exactly match the target class and
resultClass, if specified. */
+ /* Return all instances that match the resultClass, if specified. */
while (CMHasNext(instances, NULL)) {
CMPIData data = CMGetNext(instances, NULL);
- char *class =
CMGetCharPtr(CMGetClassName(CMGetObjectPath(data.value.inst,NULL), NULL));
- if (!(strcmp(class,targetclass) == 0) && ((resultClass == NULL) ||
(strcmp(class,resultClass) == 0))) {
-// BUG - returning data causes crash !?!
-_SBLIM_TRACE(2, ("--- data.value.inst=\"%s\"",
CMGetCharPtr(CDToString(_BROKER, data.value.inst, NULL))));
+ CMPIObjectPath *op = CMGetObjectPath(data.value.inst,NULL);
+ char *class = CMGetCharPtr(CMGetClassName(op, NULL));
+
+ _SBLIM_TRACE(2, ("--- got inst with object path = \"%s\"",
CMGetCharPtr(CDToString(_BROKER, op, NULL))));
+
+ /* Ignore possible instances of source class. */
+ if (strcmp(class,sourceclass) &&
+ (resultClass == NULL || CMClassPathIsA(_BROKER, op, resultClass,
NULL))) {
+ _SBLIM_TRACE(2, ("--- data.value.inst=\"%s\"",
CMGetCharPtr(CDToString(_BROKER, data.value.inst, NULL))));
+
CMReturnInstance(results, data.value.inst);
}
}
-
+
CMReturnDone(results);
exit:
@@ -268,27 +279,48 @@ static CMPIStatus ReferenceNames(
CMPIContext * context, /* [in] Additional context
info, if any. */
CMPIResult * results, /* [out] Results of this
operation. */
CMPIObjectPath * reference, /* [in] Contains the source
namespace, classname and object path. */
- const char *assocClass,
+ const char *resultClass,
const char *role)
{
CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM
operations. */
- char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target
namespace. */
char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /*
Class of the source reference object */
char *targetclass; /* Class of the target
object(s). */
+ char *targetnamespace;
_SBLIM_ENTER("ReferenceNames");
_SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
_SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
context, NULL))));
_SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
reference, NULL))));
- _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
+ _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
_SBLIM_TRACE(2, ("--- role=\"%s\"", role));
- _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
_SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
- /* Check that the requested association class, if any, is supported. */
- if (assocClass != NULL) {
- CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace,
_ASSOCCLASS, NULL);
- if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
+ /* Need to have object paths for objects on both sides of the returned
+ * association names. We are given one in the reference parameter. Need to
+ * fetch the others from cimom.
+ */
+ if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
+ targetclass = _RHSCLASSNAME;
+ targetnamespace = _RHSNAMESPACE;
+ /* Refences of LHS class should always be in LHS namespace. */
+ CMSetNameSpace(reference, _LHSNAMESPACE);
+ } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
+ targetclass = _LHSCLASSNAME;
+ targetnamespace = _LHSNAMESPACE;
+ } else {
+ _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
+ goto exit;
+ }
+ _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
+ _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
+
+ /* If resultClass is specified, it should be a Xen_HostedComputerSystem.
+ * Otherwise caller is looking for a different association than what this
+ * code implements.
+ */
+ if (resultClass != NULL) {
+ CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, _LHSNAMESPACE,
_ASSOCCLASS, NULL);
+ if (!CMClassPathIsA(_BROKER, assoc, resultClass, NULL)) {
_SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring
request."));
goto exit;
}
@@ -300,27 +332,14 @@ static CMPIStatus ReferenceNames(
goto exit;
}
- /* Determine the target class from the source class. */
- /* This used to be done with strcmp, we will now do it with CMClassPAthIsA*/
- if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
- targetclass = _RHSCLASSNAME;
- } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
- targetclass = _LHSCLASSNAME;
- } else {
- _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
- goto exit;
- }
- _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
-
- /* Create an object path for the result class. */
- CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace,
targetclass, &status);
+ /* Retrieve object paths of objects on other side of association. */
+ CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace,
targetclass, &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
_SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s",
CMGetCharPtr(status.msg)));
CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new
CMPIObjectPath");
goto exit;
}
- /* Get the list of all target class object paths from the CIMOM. */
CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context,
objectpath, &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
_SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s",
CMGetCharPtr(status.msg)));
@@ -328,37 +347,37 @@ static CMPIStatus ReferenceNames(
goto exit;
}
- /* Return all object paths that exactly match the target class and
resultClass, if specified. */
+ /* Already made it past the filters so return an association name
+ * (object path) for each association that exists to the source object.
+ */
while (CMHasNext(objectpaths, NULL)) {
CMPIData data = CMGetNext(objectpaths, NULL);
- //char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
- // This used to be strcmp, now replaced with CMClassPathIsA
- //if (strcmp(class,targetclass) == 0) {
- if(CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) {
- /* Create an object path for the association. */
- CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, namespace,
_ASSOCCLASS, &status);
+
+ if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
+ (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
+ /* Create an object path for the association. Note that the
association
+ * objects should exist in 'virt namespace' not the host namespace.
+ */
+ CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER,
_LHSNAMESPACE, _ASSOCCLASS, &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) {
_SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s",
CMGetCharPtr(status.msg)));
CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot
create new CMPIObjectPath");
goto exit;
}
-
+
/* Assign the references in the association appropriately. */
- /* This used to be strcmp (sourceclass, _RHSCLASSNAME), but since the
RHSCLASSNAME will always be CIM_COMPUTERSYSTEM,
- we will be better off comparing it to the _LHSCLASSNAME
- */
if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref,
CMPI_ref);
CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref);
} else {
- CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
+ CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref);
CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref,
CMPI_ref);
}
-
+
CMReturnObjectPath(results, refobjectpath);
}
}
-
+
exit:
_SBLIM_RETURNSTATUS(status);
}
@@ -372,28 +391,49 @@ static CMPIStatus References(
CMPIContext * context, /* [in] Additional context
info, if any. */
CMPIResult * results, /* [out] Results of this
operation. */
CMPIObjectPath * reference, /* [in] Contains the namespace,
classname and desired object path. */
- const char *assocClass,
+ const char *resultClass,
const char *role,
char **properties) /* [in] List of desired
properties (NULL=all). */
{
CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM
operations. */
- char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target
namespace. */
char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /*
Class of the source reference object */
char *targetclass; /* Class of the target
object(s). */
+ char *targetnamespace;
_SBLIM_ENTER("References");
_SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName));
_SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
context, NULL))));
_SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER,
reference, NULL))));
- _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass));
+ _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass));
_SBLIM_TRACE(2, ("--- role=\"%s\"", role));
- _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace));
_SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass));
- /* Check that the requested association class, if any, is supported. */
- if (assocClass != NULL) {
- CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace,
_ASSOCCLASS, NULL);
- if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) {
+ /* Need to have object paths for objects on both sides of the returned
+ * associations. We are given one in the reference parameter. Need to
+ * fetch the others from cimom.
+ */
+ if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
+ targetclass = _RHSCLASSNAME;
+ targetnamespace = _RHSNAMESPACE;
+ /* Refences of LHS class should always be in LHS namespace. */
+ CMSetNameSpace(reference, _LHSNAMESPACE);
+ } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
+ targetclass = _LHSCLASSNAME;
+ targetnamespace = _LHSNAMESPACE;
+ } else {
+ _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
+ goto exit;
+ }
+ _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
+ _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace));
+
+ /* If resultClass is specified, it should be a Xen_HostedComputerSystem.
+ * Otherwise caller is looking for a different association than what this
+ * code implements.
+ */
+ if (resultClass != NULL) {
+ CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, targetnamespace,
_ASSOCCLASS, NULL);
+ if (!CMClassPathIsA(_BROKER, assoc, resultClass, NULL)) {
_SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring
request."));
goto exit;
}
@@ -405,27 +445,15 @@ static CMPIStatus References(
goto exit;
}
- /* Determine the target class from the source class. */
- /* This used to be done with strcmp, we will now do it with CMClassPAthIsA*/
- if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) {
- targetclass = _RHSCLASSNAME;
- } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) {
- targetclass = _LHSCLASSNAME;
- } else {
- _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request."));
- goto exit;
- }
- _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass));
-
/* Create an object path for the result class. */
- CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, namespace,
targetclass, &status);
+ CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace,
targetclass, &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) {
_SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s",
CMGetCharPtr(status.msg)));
CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new
CMPIObjectPath");
goto exit;
}
- /* Get the list of all target class object paths from the CIMOM. */
+ /* Retrieve object paths of objects on other side of association. */
CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context,
objectpath, &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) {
_SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s",
CMGetCharPtr(status.msg)));
@@ -433,35 +461,36 @@ static CMPIStatus References(
goto exit;
}
- /* Return all object paths that exactly match the target class and
resultClass, if specified. */
+ /* Already made it past the filters so return an association instance
+ * for each association that exists to the source object.
+ */
while (CMHasNext(objectpaths, NULL)) {
CMPIData data = CMGetNext(objectpaths, NULL);
- //char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL));
- // This used to be strcmp, now replaced with CMClassPathIsA
- //if (strcmp(class,targetclass) == 0) {
- if(CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) {
- /* Create an instance for the association. */
- CMPIInstance * refinstance = _CMNewInstance(_BROKER, namespace,
_ASSOCCLASS, &status);
+
+ if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) &&
+ (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) {
+ /* Create an instance for the association. Note that the association
+ * objects should exist in 'virt namespace' not the host namespace.
+ */
+ CMPIInstance * refinstance = _CMNewInstance(_BROKER, _LHSNAMESPACE,
_ASSOCCLASS, &status);
if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) {
_SBLIM_TRACE(1,("--- CMNewInstance() failed - %s",
CMGetCharPtr(status.msg)));
CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot
create new CMPIInstance");
goto exit;
}
-
+
/* Assign the references in the association appropriately. */
- /* This used to be strcmp (sourceclass, _RHSCLASSNAME), but since the
RHSCLASSNAME will always be CIM_COMPUTERSYSTEM,
- we will be better off comparing it to the _LHSCLASSNAME
- */
if (strcmp(sourceclass, _LHSCLASSNAME) == 0) {
- CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref,
CMPI_ref);
+ CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref,
CMPI_ref);
CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref);
- } else {
- CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference,
CMPI_ref);
- CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref,
CMPI_ref);
+ } else {
+ CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref);
+ CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref,
CMPI_ref);
}
CMReturnInstance(results, refinstance);
}
}
+
exit:
_SBLIM_RETURNSTATUS(status);
}
_______________________________________________
Xen-cim mailing list
Xen-cim@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-cim
|