os-cmpi-xen
annotate src/Xen_ProcessorPoolComponent.c @ 143:fc498265d293
Fixed warning (and bug) in Xen_DiskSettingData.
Signed-off-by: Jim Fehlig <jfehlig@novell.com>
Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author | Jim Fehlig <jfehlig@novell.com> |
---|---|
date | Thu Aug 16 17:49:08 2007 -0600 (2007-08-16) |
parents | ab8e99c757f5 |
children |
rev | line source |
---|---|
jfehlig@25 | 1 // Copyright (C) 2006 Novell, Inc. |
jfehlig@24 | 2 // |
jfehlig@24 | 3 // This library is free software; you can redistribute it and/or |
jfehlig@24 | 4 // modify it under the terms of the GNU Lesser General Public |
jfehlig@24 | 5 // License as published by the Free Software Foundation; either |
jfehlig@24 | 6 // version 2.1 of the License, or (at your option) any later version. |
jfehlig@24 | 7 // |
jfehlig@24 | 8 // This library is distributed in the hope that it will be useful, |
jfehlig@24 | 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
jfehlig@24 | 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
jfehlig@24 | 11 // Lesser General Public License for more details. |
jfehlig@24 | 12 // |
jfehlig@24 | 13 // You should have received a copy of the GNU Lesser General Public |
jfehlig@24 | 14 // License along with this library; if not, write to the Free Software |
jfehlig@24 | 15 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
jfehlig@24 | 16 // ============================================================================ |
jfehlig@25 | 17 // Authors: Jim Fehlig, <jfehlig@novell.com> |
jfehlig@24 | 18 // Contributors: |
jfehlig@24 | 19 // Description: |
jfehlig@24 | 20 // ============================================================================ |
jfehlig@24 | 21 |
jfehlig@24 | 22 #include <string.h> |
jfehlig@24 | 23 |
jfehlig@24 | 24 /* Include the required CMPI data types, function headers, and macros */ |
jfehlig@24 | 25 #include "cmpidt.h" |
jfehlig@24 | 26 #include "cmpift.h" |
jfehlig@24 | 27 #include "cmpimacs.h" |
jfehlig@24 | 28 |
jfehlig@24 | 29 |
jfehlig@24 | 30 // ---------------------------------------------------------------------------- |
jfehlig@24 | 31 // COMMON GLOBAL VARIABLES |
jfehlig@24 | 32 // ---------------------------------------------------------------------------- |
jfehlig@24 | 33 |
jfehlig@24 | 34 /* Handle to the CIM broker. Initialized when the provider lib is loaded. */ |
jfehlig@31 | 35 static const CMPIBroker *_BROKER; |
jfehlig@24 | 36 |
jfehlig@24 | 37 /* Include utility functions */ |
jfehlig@24 | 38 #include "cmpiutil.h" |
jfehlig@24 | 39 |
jfehlig@24 | 40 /* Include _SBLIM_TRACE() logging support */ |
jfehlig@24 | 41 #include "cmpitrace.h" |
jfehlig@24 | 42 |
jfehlig@24 | 43 |
jfehlig@24 | 44 // ============================================================================ |
jfehlig@24 | 45 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE |
jfehlig@24 | 46 // ============================================================================ |
jfehlig@24 | 47 |
jfehlig@24 | 48 // ---------------------------------------------------------------------------- |
jfehlig@24 | 49 // Info for the class supported by the association provider |
jfehlig@24 | 50 // ---------------------------------------------------------------------------- |
jfehlig@24 | 51 |
jfehlig@24 | 52 /* Name of the left and right hand side classes of this association. */ |
jfehlig@24 | 53 static char * _ASSOCCLASS = "Xen_ProcessorPoolComponent"; |
jfehlig@24 | 54 static char * _LHSCLASSNAME = "Xen_ProcessorPool"; |
jfehlig@24 | 55 static char * _RHSCLASSNAME = "CIM_Processor"; |
jfehlig@24 | 56 static char * _LHSPROPERTYNAME = "GroupComponent"; |
jfehlig@24 | 57 static char * _RHSPROPERTYNAME = "PartComponent"; |
jfehlig@24 | 58 static char * _LHSNAMESPACE = "root/cimv2"; |
jfehlig@24 | 59 static char * _RHSNAMESPACE = "smash"; |
jfehlig@24 | 60 |
jfehlig@24 | 61 static char * _XEN_DOMU_PROCESSOR_CLASS = "Xen_Processor"; |
jfehlig@24 | 62 |
jfehlig@24 | 63 |
jfehlig@24 | 64 // ---------------------------------------------------------------------------- |
jfehlig@24 | 65 // AssociationCleanup() |
jfehlig@24 | 66 // Perform any necessary cleanup immediately before this provider is unloaded. |
jfehlig@24 | 67 // ---------------------------------------------------------------------------- |
jfehlig@24 | 68 static CMPIStatus AssociationCleanup( |
jfehlig@24 | 69 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */ |
jfehlig@31 | 70 const CMPIContext * context, /* [in] Additional context info, if any. */ |
jfehlig@31 | 71 CMPIBoolean terminating) /* [in] True if MB is terminating */ |
jfehlig@24 | 72 { |
jfehlig@24 | 73 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ |
jfehlig@24 | 74 |
jfehlig@24 | 75 _SBLIM_ENTER("AssociationCleanup"); |
jfehlig@24 | 76 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); |
jfehlig@24 | 77 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); |
jfehlig@24 | 78 |
jfehlig@24 | 79 /* Nothing needs to be done for cleanup. */ |
jfehlig@24 | 80 _SBLIM_RETURNSTATUS(status); |
jfehlig@24 | 81 } |
jfehlig@24 | 82 |
jfehlig@24 | 83 |
jfehlig@24 | 84 // ---------------------------------------------------------------------------- |
jfehlig@24 | 85 // AssociatorNames() |
jfehlig@24 | 86 // ---------------------------------------------------------------------------- |
jfehlig@24 | 87 static CMPIStatus AssociatorNames( |
jfehlig@24 | 88 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */ |
jfehlig@31 | 89 const CMPIContext * context, /* [in] Additional context info, if any. */ |
jfehlig@31 | 90 const CMPIResult * results, /* [out] Results of this operation. */ |
jfehlig@31 | 91 const CMPIObjectPath * reference, /* [in] Contains source namespace, classname and object path. */ |
jfehlig@24 | 92 const char * assocClass, |
jfehlig@24 | 93 const char * resultClass, |
jfehlig@24 | 94 const char * role, |
jfehlig@24 | 95 const char * resultRole) |
jfehlig@24 | 96 { |
jfehlig@24 | 97 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ |
jfehlig@24 | 98 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ |
jfehlig@24 | 99 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */ |
jfehlig@24 | 100 char *targetclass; /* Class of the target object(s). */ |
jfehlig@24 | 101 char *targetnamespace; |
jfehlig@24 | 102 |
jfehlig@24 | 103 _SBLIM_ENTER("AssociatorNames"); |
jfehlig@24 | 104 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); |
jfehlig@24 | 105 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); |
jfehlig@24 | 106 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); |
jfehlig@24 | 107 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass)); |
jfehlig@24 | 108 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass)); |
jfehlig@24 | 109 _SBLIM_TRACE(2, ("--- role=\"%s\"", role)); |
jfehlig@24 | 110 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole)); |
jfehlig@24 | 111 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); |
jfehlig@24 | 112 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass)); |
jfehlig@24 | 113 |
jfehlig@24 | 114 /* Ensure the source class is not a virtual processor */ |
jfehlig@24 | 115 if (strcmp(sourceclass, _XEN_DOMU_PROCESSOR_CLASS) == 0) { |
jfehlig@24 | 116 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_PROCESSOR_CLASS)); |
jfehlig@24 | 117 goto exit; |
jfehlig@24 | 118 } |
jfehlig@24 | 119 |
jfehlig@24 | 120 /* Check that the requested association class, if any, is supported. */ |
jfehlig@24 | 121 if (assocClass != NULL) { |
jfehlig@24 | 122 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL); |
jfehlig@24 | 123 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) { |
jfehlig@24 | 124 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request.")); |
jfehlig@24 | 125 goto exit; |
jfehlig@24 | 126 } |
jfehlig@24 | 127 } |
jfehlig@24 | 128 |
jfehlig@24 | 129 /* Check that the reference matches the required role, if any. */ |
jfehlig@24 | 130 if ((role != NULL) && strcmp(role, sourceclass) != 0) { |
jfehlig@24 | 131 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request.")); |
jfehlig@24 | 132 goto exit; |
jfehlig@24 | 133 } |
jfehlig@24 | 134 |
jfehlig@24 | 135 /* Determine the target class from the source class. */ |
jfehlig@24 | 136 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) { |
jfehlig@24 | 137 targetclass = _RHSCLASSNAME; |
jfehlig@24 | 138 targetnamespace = _RHSNAMESPACE; |
jfehlig@24 | 139 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) { |
jfehlig@24 | 140 targetclass = _LHSCLASSNAME; |
jfehlig@24 | 141 targetnamespace = _LHSNAMESPACE; |
jfehlig@24 | 142 } else { |
jfehlig@24 | 143 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request.")); |
jfehlig@24 | 144 goto exit; |
jfehlig@24 | 145 } |
jfehlig@24 | 146 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass)); |
jfehlig@24 | 147 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace)); |
jfehlig@24 | 148 |
jfehlig@24 | 149 /* Create an object path for the result class. */ |
jfehlig@24 | 150 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status); |
jfehlig@24 | 151 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { |
jfehlig@24 | 152 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg))); |
jfehlig@24 | 153 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath"); |
jfehlig@24 | 154 goto exit; |
jfehlig@24 | 155 } |
jfehlig@24 | 156 |
jfehlig@24 | 157 /* Get the list of all target class object paths from the CIMOM. */ |
jfehlig@24 | 158 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status); |
jfehlig@24 | 159 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) { |
jfehlig@24 | 160 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg))); |
jfehlig@24 | 161 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class"); |
jfehlig@24 | 162 goto exit; |
jfehlig@24 | 163 } |
jfehlig@24 | 164 |
jfehlig@24 | 165 /* Return all object paths that exactly match the target class and resultClass, if specified. */ |
jfehlig@24 | 166 while (CMHasNext(objectpaths, NULL)) { |
jfehlig@24 | 167 CMPIData data = CMGetNext(objectpaths, NULL); |
jfehlig@24 | 168 char *class = CMGetCharPtr(CMGetClassName(data.value.ref, NULL)); |
jfehlig@24 | 169 |
jfehlig@24 | 170 _SBLIM_TRACE(2, ("--- got objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, data.value.ref, NULL)))); |
jfehlig@24 | 171 |
jfehlig@24 | 172 /* Ignore possible instances of source class. */ |
jfehlig@24 | 173 if (strcmp(class,sourceclass) && |
jfehlig@24 | 174 (resultClass == NULL || CMClassPathIsA(_BROKER, data.value.ref, resultClass, NULL))) { |
jfehlig@24 | 175 |
jfehlig@24 | 176 CMReturnObjectPath(results, data.value.ref); |
jfehlig@24 | 177 } |
jfehlig@24 | 178 } |
jfehlig@24 | 179 |
jfehlig@24 | 180 CMReturnDone(results); |
jfehlig@24 | 181 |
jfehlig@24 | 182 exit: |
jfehlig@24 | 183 _SBLIM_RETURNSTATUS(status); |
jfehlig@24 | 184 } |
jfehlig@24 | 185 |
jfehlig@24 | 186 |
jfehlig@24 | 187 // ---------------------------------------------------------------------------- |
jfehlig@24 | 188 // Associators() |
jfehlig@24 | 189 // ---------------------------------------------------------------------------- |
jfehlig@24 | 190 static CMPIStatus Associators( |
jfehlig@24 | 191 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */ |
jfehlig@31 | 192 const CMPIContext * context, /* [in] Additional context info, if any. */ |
jfehlig@31 | 193 const CMPIResult * results, /* [out] Results of this operation. */ |
jfehlig@31 | 194 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */ |
jfehlig@24 | 195 const char *assocClass, |
jfehlig@24 | 196 const char *resultClass, |
jfehlig@24 | 197 const char *role, |
jfehlig@24 | 198 const char *resultRole, |
jfehlig@31 | 199 const char ** properties) /* [in] List of desired properties (NULL=all). */ |
jfehlig@24 | 200 { |
jfehlig@24 | 201 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ |
jfehlig@24 | 202 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ |
jfehlig@24 | 203 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */ |
jfehlig@24 | 204 char *targetclass; /* Class of the target object(s). */ |
jfehlig@24 | 205 char *targetnamespace; |
jfehlig@24 | 206 |
jfehlig@24 | 207 _SBLIM_ENTER("Associators"); |
jfehlig@24 | 208 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); |
jfehlig@24 | 209 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); |
jfehlig@24 | 210 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); |
jfehlig@24 | 211 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass)); |
jfehlig@24 | 212 _SBLIM_TRACE(2, ("--- resultClass=\"%s\"", resultClass)); |
jfehlig@24 | 213 _SBLIM_TRACE(2, ("--- role=\"%s\"", role)); |
jfehlig@24 | 214 _SBLIM_TRACE(2, ("--- resultRole=\"%s\"", resultRole)); |
jfehlig@24 | 215 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); |
jfehlig@24 | 216 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass)); |
jfehlig@24 | 217 |
jfehlig@24 | 218 /* Ensure the source class is not a virtual processor */ |
jfehlig@24 | 219 if (strcmp(sourceclass, _XEN_DOMU_PROCESSOR_CLASS) == 0) { |
jfehlig@24 | 220 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_PROCESSOR_CLASS)); |
jfehlig@24 | 221 goto exit; |
jfehlig@24 | 222 } |
jfehlig@24 | 223 |
jfehlig@24 | 224 /* Check that the requested association class, if any, is supported. */ |
jfehlig@24 | 225 if (assocClass != NULL) { |
jfehlig@24 | 226 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL); |
jfehlig@24 | 227 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) { |
jfehlig@24 | 228 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request.")); |
jfehlig@24 | 229 goto exit; |
jfehlig@24 | 230 } |
jfehlig@24 | 231 } |
jfehlig@24 | 232 |
jfehlig@24 | 233 /* Check that the reference matches the required role, if any. */ |
jfehlig@24 | 234 if ((role != NULL) && strcmp(role, sourceclass) != 0) { |
jfehlig@24 | 235 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request.")); |
jfehlig@24 | 236 goto exit; |
jfehlig@24 | 237 } |
jfehlig@24 | 238 |
jfehlig@24 | 239 /* Determine the target class from the source class. */ |
jfehlig@24 | 240 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) { |
jfehlig@24 | 241 targetclass = _RHSCLASSNAME; |
jfehlig@24 | 242 targetnamespace = _RHSNAMESPACE; |
jfehlig@24 | 243 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) { |
jfehlig@24 | 244 targetclass = _LHSCLASSNAME; |
jfehlig@24 | 245 targetnamespace = _LHSNAMESPACE; |
jfehlig@24 | 246 } else { |
jfehlig@24 | 247 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request.")); |
jfehlig@24 | 248 goto exit; |
jfehlig@24 | 249 } |
jfehlig@24 | 250 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass)); |
jfehlig@24 | 251 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace)); |
jfehlig@24 | 252 |
jfehlig@24 | 253 /* Create an object path for the result class. */ |
jfehlig@24 | 254 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status); |
jfehlig@24 | 255 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { |
jfehlig@24 | 256 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg))); |
jfehlig@24 | 257 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath"); |
jfehlig@24 | 258 goto exit; |
jfehlig@24 | 259 } |
jfehlig@24 | 260 |
jfehlig@24 | 261 /* Get the list of all target class instances from the CIMOM. */ |
jfehlig@24 | 262 CMPIEnumeration * instances = CBEnumInstances(_BROKER, context, objectpath, NULL, &status); |
jfehlig@24 | 263 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(instances)) { |
jfehlig@24 | 264 _SBLIM_TRACE(1,("--- CBEnumInstances() failed - %s", CMGetCharPtr(status.msg))); |
jfehlig@24 | 265 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class"); |
jfehlig@24 | 266 goto exit; |
jfehlig@24 | 267 } |
jfehlig@24 | 268 |
jfehlig@24 | 269 /* Return all instances that exactly match the target class and resultClass, if specified. */ |
jfehlig@24 | 270 while (CMHasNext(instances, NULL)) { |
jfehlig@24 | 271 CMPIData data = CMGetNext(instances, NULL); |
jfehlig@24 | 272 CMPIObjectPath *op = CMGetObjectPath(data.value.inst,NULL); |
jfehlig@24 | 273 char *class = CMGetCharPtr(CMGetClassName(op, NULL)); |
jfehlig@24 | 274 |
jfehlig@24 | 275 CMSetNameSpace(op, targetnamespace); |
jfehlig@24 | 276 _SBLIM_TRACE(2, ("--- got objectpath=\"%s\"", CMGetCharPtr(CDToString(_BROKER, op, NULL)))); |
jfehlig@24 | 277 _SBLIM_TRACE(2, ("--- got class=\"%s\"", class)); |
jfehlig@24 | 278 |
jfehlig@24 | 279 /* Ignore possible instances of source class. */ |
jfehlig@24 | 280 if (strcmp(class,sourceclass) && |
jfehlig@24 | 281 (resultClass == NULL || CMClassPathIsA(_BROKER, op, resultClass, NULL))) { |
jfehlig@24 | 282 _SBLIM_TRACE(2, ("--- returning instance")); |
jfehlig@24 | 283 CMReturnInstance(results, data.value.inst); |
jfehlig@24 | 284 } |
jfehlig@24 | 285 } |
jfehlig@24 | 286 |
jfehlig@24 | 287 CMReturnDone(results); |
jfehlig@24 | 288 |
jfehlig@24 | 289 exit: |
jfehlig@24 | 290 _SBLIM_RETURNSTATUS(status); |
jfehlig@24 | 291 } |
jfehlig@24 | 292 |
jfehlig@24 | 293 |
jfehlig@24 | 294 // ---------------------------------------------------------------------------- |
jfehlig@24 | 295 // ReferenceNames() |
jfehlig@24 | 296 // ---------------------------------------------------------------------------- |
jfehlig@24 | 297 static CMPIStatus ReferenceNames( |
jfehlig@24 | 298 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */ |
jfehlig@31 | 299 const CMPIContext * context, /* [in] Additional context info, if any. */ |
jfehlig@31 | 300 const CMPIResult * results, /* [out] Results of this operation. */ |
jfehlig@31 | 301 const CMPIObjectPath * reference, /* [in] Contains the source namespace, classname and object path. */ |
jfehlig@24 | 302 const char *assocClass, |
jfehlig@24 | 303 const char *role) |
jfehlig@24 | 304 { |
jfehlig@24 | 305 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ |
jfehlig@24 | 306 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ |
jfehlig@24 | 307 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */ |
jfehlig@24 | 308 char *targetclass; /* Class of the target object(s). */ |
jfehlig@24 | 309 char *targetnamespace; |
jfehlig@24 | 310 |
jfehlig@24 | 311 _SBLIM_ENTER("ReferenceNames"); |
jfehlig@24 | 312 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); |
jfehlig@24 | 313 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); |
jfehlig@24 | 314 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); |
jfehlig@24 | 315 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass)); |
jfehlig@24 | 316 _SBLIM_TRACE(2, ("--- role=\"%s\"", role)); |
jfehlig@24 | 317 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); |
jfehlig@24 | 318 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass)); |
jfehlig@24 | 319 |
jfehlig@24 | 320 /* Ensure the source class is not a virtual processor */ |
jfehlig@24 | 321 if (strcmp(sourceclass, _XEN_DOMU_PROCESSOR_CLASS) == 0) { |
jfehlig@24 | 322 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_PROCESSOR_CLASS)); |
jfehlig@24 | 323 goto exit; |
jfehlig@24 | 324 } |
jfehlig@24 | 325 |
jfehlig@24 | 326 /* Check that the requested association class, if any, is supported. */ |
jfehlig@24 | 327 if (assocClass != NULL) { |
jfehlig@24 | 328 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL); |
jfehlig@24 | 329 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) { |
jfehlig@24 | 330 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request.")); |
jfehlig@24 | 331 goto exit; |
jfehlig@24 | 332 } |
jfehlig@24 | 333 } |
jfehlig@24 | 334 |
jfehlig@24 | 335 /* Check that the reference matches the required role, if any. */ |
jfehlig@24 | 336 if ((role != NULL) && strcmp(role, sourceclass) != 0) { |
jfehlig@24 | 337 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request.")); |
jfehlig@24 | 338 goto exit; |
jfehlig@24 | 339 } |
jfehlig@24 | 340 |
jfehlig@24 | 341 /* Determine the target class from the source class. */ |
jfehlig@24 | 342 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) { |
jfehlig@24 | 343 targetclass = _RHSCLASSNAME; |
jfehlig@24 | 344 targetnamespace = _RHSNAMESPACE; |
jfehlig@24 | 345 /* Refences of LHS class should always be in LHS namespace. */ |
jfehlig@31 | 346 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE); |
jfehlig@24 | 347 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) { |
jfehlig@24 | 348 targetclass = _LHSCLASSNAME; |
jfehlig@24 | 349 targetnamespace = _LHSNAMESPACE; |
jfehlig@24 | 350 } else { |
jfehlig@24 | 351 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request.")); |
jfehlig@24 | 352 goto exit; |
jfehlig@24 | 353 } |
jfehlig@24 | 354 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass)); |
jfehlig@24 | 355 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace)); |
jfehlig@24 | 356 |
jfehlig@24 | 357 /* Create an object path for the result class. */ |
jfehlig@24 | 358 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status); |
jfehlig@24 | 359 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { |
jfehlig@24 | 360 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg))); |
jfehlig@24 | 361 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath"); |
jfehlig@24 | 362 goto exit; |
jfehlig@24 | 363 } |
jfehlig@24 | 364 |
jfehlig@24 | 365 /* Get the list of all target class object paths from the CIMOM. */ |
jfehlig@24 | 366 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status); |
jfehlig@24 | 367 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) { |
jfehlig@24 | 368 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg))); |
jfehlig@24 | 369 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class"); |
jfehlig@24 | 370 goto exit; |
jfehlig@24 | 371 } |
jfehlig@24 | 372 |
jfehlig@24 | 373 /* Return all object paths that exactly match the target class and resultClass, if specified. */ |
jfehlig@24 | 374 while (CMHasNext(objectpaths, NULL)) { |
jfehlig@24 | 375 CMPIData data = CMGetNext(objectpaths, NULL); |
jfehlig@24 | 376 |
jfehlig@24 | 377 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) && |
jfehlig@24 | 378 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) { |
jfehlig@24 | 379 /* Create an object path for the association. Note that the association |
jfehlig@24 | 380 * objects should exist in 'virt namespace' not the host namespace. |
jfehlig@24 | 381 */ |
jfehlig@24 | 382 CMPIObjectPath * refobjectpath = CMNewObjectPath(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status); |
jfehlig@24 | 383 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refobjectpath)) { |
jfehlig@24 | 384 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg))); |
jfehlig@24 | 385 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath"); |
jfehlig@24 | 386 goto exit; |
jfehlig@24 | 387 } |
jfehlig@24 | 388 |
jfehlig@24 | 389 /* Assign the references in the association appropriately. */ |
jfehlig@24 | 390 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) { |
jfehlig@24 | 391 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &reference, CMPI_ref); |
jfehlig@24 | 392 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref); |
jfehlig@24 | 393 } else { |
jfehlig@24 | 394 CMAddKey(refobjectpath, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref); |
jfehlig@24 | 395 CMAddKey(refobjectpath, _LHSPROPERTYNAME, &reference, CMPI_ref); |
jfehlig@24 | 396 } |
jfehlig@24 | 397 |
jfehlig@24 | 398 CMReturnObjectPath(results, refobjectpath); |
jfehlig@24 | 399 } |
jfehlig@24 | 400 } |
jfehlig@24 | 401 |
jfehlig@24 | 402 exit: |
jfehlig@24 | 403 _SBLIM_RETURNSTATUS(status); |
jfehlig@24 | 404 } |
jfehlig@24 | 405 |
jfehlig@24 | 406 |
jfehlig@24 | 407 // ---------------------------------------------------------------------------- |
jfehlig@24 | 408 // References() |
jfehlig@24 | 409 // ---------------------------------------------------------------------------- |
jfehlig@24 | 410 static CMPIStatus References( |
jfehlig@24 | 411 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */ |
jfehlig@31 | 412 const CMPIContext * context, /* [in] Additional context info, if any. */ |
jfehlig@31 | 413 const CMPIResult * results, /* [out] Results of this operation. */ |
jfehlig@31 | 414 const CMPIObjectPath * reference, /* [in] Contains the namespace, classname and desired object path. */ |
jfehlig@24 | 415 const char *assocClass, |
jfehlig@24 | 416 const char *role, |
jfehlig@31 | 417 const char **properties) /* [in] List of desired properties (NULL=all). */ |
jfehlig@24 | 418 { |
jfehlig@24 | 419 CMPIStatus status = { CMPI_RC_OK, NULL }; /* Return status of CIM operations. */ |
jfehlig@24 | 420 char *namespace = CMGetCharPtr(CMGetNameSpace(reference, NULL)); /* Target namespace. */ |
jfehlig@24 | 421 char *sourceclass = CMGetCharPtr(CMGetClassName(reference, &status)); /* Class of the source reference object */ |
jfehlig@24 | 422 char *targetclass; /* Class of the target object(s). */ |
jfehlig@24 | 423 char *targetnamespace; |
jfehlig@24 | 424 |
jfehlig@24 | 425 _SBLIM_ENTER("References"); |
jfehlig@24 | 426 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); |
jfehlig@24 | 427 _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); |
jfehlig@24 | 428 _SBLIM_TRACE(2, ("--- reference=\"%s\"", CMGetCharPtr(CDToString(_BROKER, reference, NULL)))); |
jfehlig@24 | 429 _SBLIM_TRACE(2, ("--- assocClass=\"%s\"", assocClass)); |
jfehlig@24 | 430 _SBLIM_TRACE(2, ("--- role=\"%s\"", role)); |
jfehlig@24 | 431 _SBLIM_TRACE(2, ("--- namespace=\"%s\"", namespace)); |
jfehlig@24 | 432 _SBLIM_TRACE(2, ("--- sourceclass=\"%s\"", sourceclass)); |
jfehlig@24 | 433 |
jfehlig@24 | 434 /* Ensure the source class is not a virtual processor */ |
jfehlig@24 | 435 if (strcmp(sourceclass, _XEN_DOMU_PROCESSOR_CLASS) == 0) { |
jfehlig@24 | 436 _SBLIM_TRACE(2, ("--- Ignoring source class %s.", _XEN_DOMU_PROCESSOR_CLASS)); |
jfehlig@24 | 437 goto exit; |
jfehlig@24 | 438 } |
jfehlig@24 | 439 |
jfehlig@24 | 440 /* Check that the requested association class, if any, is supported. */ |
jfehlig@24 | 441 if (assocClass != NULL) { |
jfehlig@24 | 442 CMPIObjectPath * assoc = CMNewObjectPath(_BROKER, namespace, _ASSOCCLASS, NULL); |
jfehlig@24 | 443 if (!CMClassPathIsA(_BROKER, assoc, assocClass, NULL)) { |
jfehlig@24 | 444 _SBLIM_TRACE(2, ("--- Unrecognized association class. Ignoring request.")); |
jfehlig@24 | 445 goto exit; |
jfehlig@24 | 446 } |
jfehlig@24 | 447 } |
jfehlig@24 | 448 |
jfehlig@24 | 449 /* Check that the reference matches the required role, if any. */ |
jfehlig@24 | 450 if ((role != NULL) && strcmp(role, sourceclass) != 0) { |
jfehlig@24 | 451 _SBLIM_TRACE(2, ("--- Reference does not match required role. Ignoring request.")); |
jfehlig@24 | 452 goto exit; |
jfehlig@24 | 453 } |
jfehlig@24 | 454 |
jfehlig@24 | 455 /* Determine the target class from the source class. */ |
jfehlig@24 | 456 if (CMClassPathIsA(_BROKER, reference, _LHSCLASSNAME, NULL)) { |
jfehlig@24 | 457 targetclass = _RHSCLASSNAME; |
jfehlig@24 | 458 targetnamespace = _RHSNAMESPACE; |
jfehlig@24 | 459 /* Refences of LHS class should always be in LHS namespace. */ |
jfehlig@31 | 460 CMSetNameSpace((CMPIObjectPath *)reference, _LHSNAMESPACE); |
jfehlig@24 | 461 } else if (CMClassPathIsA(_BROKER, reference, _RHSCLASSNAME, NULL)) { |
jfehlig@24 | 462 targetclass = _LHSCLASSNAME; |
jfehlig@24 | 463 targetnamespace = _LHSNAMESPACE; |
jfehlig@24 | 464 } else { |
jfehlig@24 | 465 _SBLIM_TRACE(2, ("--- Unrecognized source class. Ignoring request.")); |
jfehlig@24 | 466 goto exit; |
jfehlig@24 | 467 } |
jfehlig@24 | 468 _SBLIM_TRACE(2, ("--- targetclass=\"%s\"", targetclass)); |
jfehlig@24 | 469 _SBLIM_TRACE(2, ("--- targetnamespace=\"%s\"", targetnamespace)); |
jfehlig@24 | 470 |
jfehlig@24 | 471 /* Create an object path for the result class. */ |
jfehlig@24 | 472 CMPIObjectPath * objectpath = CMNewObjectPath(_BROKER, targetnamespace, targetclass, &status); |
jfehlig@24 | 473 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath)) { |
jfehlig@24 | 474 _SBLIM_TRACE(1,("--- CMNewObjectPath() failed - %s", CMGetCharPtr(status.msg))); |
jfehlig@24 | 475 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIObjectPath"); |
jfehlig@24 | 476 goto exit; |
jfehlig@24 | 477 } |
jfehlig@24 | 478 |
jfehlig@24 | 479 /* Get the list of all target class object paths from the CIMOM. */ |
jfehlig@24 | 480 CMPIEnumeration * objectpaths = CBEnumInstanceNames(_BROKER, context, objectpath, &status); |
jfehlig@24 | 481 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpaths)) { |
jfehlig@24 | 482 _SBLIM_TRACE(1,("--- CBEnumInstanceNames() failed - %s", CMGetCharPtr(status.msg))); |
jfehlig@24 | 483 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot enumerate target class"); |
jfehlig@24 | 484 goto exit; |
jfehlig@24 | 485 } |
jfehlig@24 | 486 |
jfehlig@24 | 487 /* Return all object paths that exactly match the target class and resultClass, if specified. */ |
jfehlig@24 | 488 while (CMHasNext(objectpaths, NULL)) { |
jfehlig@24 | 489 CMPIData data = CMGetNext(objectpaths, NULL); |
jfehlig@24 | 490 |
jfehlig@24 | 491 if((CMClassPathIsA(_BROKER, data.value.ref, targetclass, NULL)) && |
jfehlig@24 | 492 (!CMClassPathIsA(_BROKER, data.value.ref, sourceclass, NULL))) { |
jfehlig@24 | 493 /* Create an instance for the association. Note that the association |
jfehlig@24 | 494 * objects should exist in 'virt namespace' not the host namespace. |
jfehlig@24 | 495 */ |
jfehlig@24 | 496 CMPIInstance * refinstance = _CMNewInstance(_BROKER, _LHSNAMESPACE, _ASSOCCLASS, &status); |
jfehlig@24 | 497 if ((status.rc != CMPI_RC_OK) || CMIsNullObject(refinstance)) { |
jfehlig@24 | 498 _SBLIM_TRACE(1,("--- CMNewInstance() failed - %s", CMGetCharPtr(status.msg))); |
jfehlig@24 | 499 CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERROR, "Cannot create new CMPIInstance"); |
jfehlig@24 | 500 goto exit; |
jfehlig@24 | 501 } |
jfehlig@24 | 502 |
jfehlig@24 | 503 /* Assign the references in the association appropriately. */ |
jfehlig@24 | 504 if (strcmp(sourceclass, _RHSCLASSNAME) == 0) { |
jfehlig@24 | 505 CMSetProperty(refinstance, _RHSPROPERTYNAME, &reference, CMPI_ref); |
jfehlig@24 | 506 CMSetProperty(refinstance, _LHSPROPERTYNAME, &data.value.ref, CMPI_ref); |
jfehlig@24 | 507 } else { |
jfehlig@24 | 508 CMSetProperty(refinstance, _RHSPROPERTYNAME, &data.value.ref, CMPI_ref); |
jfehlig@24 | 509 CMSetProperty(refinstance, _LHSPROPERTYNAME, &reference, CMPI_ref); |
jfehlig@24 | 510 } |
jfehlig@24 | 511 |
jfehlig@24 | 512 CMReturnInstance(results, refinstance); |
jfehlig@24 | 513 } |
jfehlig@24 | 514 } |
jfehlig@24 | 515 exit: |
jfehlig@24 | 516 _SBLIM_RETURNSTATUS(status); |
jfehlig@24 | 517 } |
jfehlig@24 | 518 |
jfehlig@24 | 519 |
jfehlig@24 | 520 // ---------------------------------------------------------------------------- |
jfehlig@24 | 521 // AssociationInitialize() |
jfehlig@24 | 522 // Perform any necessary initialization immediately after this provider is |
jfehlig@24 | 523 // first loaded. |
jfehlig@24 | 524 // ---------------------------------------------------------------------------- |
jfehlig@24 | 525 static void AssociationInitialize( |
jfehlig@24 | 526 CMPIAssociationMI * self, /* [in] Handle to this provider (i.e. 'self'). */ |
jfehlig@31 | 527 const CMPIContext * context) /* [in] Additional context info, if any. */ |
jfehlig@24 | 528 { |
jfehlig@24 | 529 _SBLIM_ENTER("AssociationInitialize"); |
jfehlig@24 | 530 _SBLIM_TRACE(2, ("--- self=\"%s\"", self->ft->miName)); |
jfehlig@24 | 531 // _SBLIM_TRACE(2, ("--- context=\"%s\"", CMGetCharPtr(CDToString(_BROKER, context, NULL)))); |
jfehlig@24 | 532 |
jfehlig@24 | 533 /* Nothing needs to be done to initialize this provider */ |
jfehlig@24 | 534 _SBLIM_RETURN(); |
jfehlig@24 | 535 } |
jfehlig@24 | 536 |
jfehlig@24 | 537 |
jfehlig@24 | 538 // ============================================================================ |
jfehlig@24 | 539 // CMPI ASSOCIATION PROVIDER FUNCTION TABLE SETUP |
jfehlig@24 | 540 // ============================================================================ |
jfehlig@24 | 541 CMAssociationMIStub( , Xen_ProcessorPoolComponent, _BROKER, AssociationInitialize(&mi, ctx)); |