os-cmpi-xen

annotate src/Xen_ProcessorPool.c @ 143:fc498265d293

Fixed warning (and bug) in Xen_DiskSettingData.

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 26f10941718e
children
rev   line source
jfehlig@137 1 // Copyright (C) 2007 Novell, Inc.
jbulpin@0 2 //
jbulpin@0 3 // This library is free software; you can redistribute it and/or
jbulpin@0 4 // modify it under the terms of the GNU Lesser General Public
jbulpin@0 5 // License as published by the Free Software Foundation; either
jbulpin@0 6 // version 2.1 of the License, or (at your option) any later version.
jbulpin@0 7 //
jbulpin@0 8 // This library is distributed in the hope that it will be useful,
jbulpin@0 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
jbulpin@0 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
jbulpin@0 11 // Lesser General Public License for more details.
jbulpin@0 12 //
jbulpin@0 13 // You should have received a copy of the GNU Lesser General Public
jbulpin@0 14 // License along with this library; if not, write to the Free Software
jbulpin@0 15 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
jbulpin@0 16 // ============================================================================
jbulpin@0 17 // Authors: Dr. Gareth S. Bestor, <bestor@us.ibm.com>
jfehlig@137 18 // Contributors: Jim Fehlig, <jfehlig@novell.com>
jfehlig@137 19 // Description: Xen implementation of CIM_ResourcePool for CPU.
jbulpin@0 20 // ============================================================================
jbulpin@0 21
jfehlig@137 22 /* Common declarations for each CMPI "Cimpler" instance provider */
jfehlig@137 23 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
jfehlig@137 24 #include <cmpidt.h>
jfehlig@137 25 #include <cmpimacs.h>
jbulpin@0 26
jfehlig@137 27 #include "cmpilify.h"
jbulpin@0 28
jbulpin@0 29
jfehlig@137 30 static const CMPIInstanceMI* mi;
jbulpin@0 31
jbulpin@0 32
jfehlig@137 33 #define _BROKER (((CMPILIFYInstance1ROMI*)(mi->hdl))->brkr)
jfehlig@137 34 #define _CLASS (((CMPILIFYInstance1ROMI*)(mi->hdl))->cn)
jfehlig@137 35 #define _KEYS (((CMPILIFYInstance1ROMI*)(mi->hdl))->kys)
jbulpin@0 36
jfehlig@137 37 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
jfehlig@137 38
jfehlig@137 39 #include <stdlib.h>
jbulpin@0 40
jfehlig@137 41 #include <xen_common.h>
jfehlig@137 42 #include <xen_host.h>
jfehlig@137 43 #include <xen_host_cpu.h>
jbulpin@0 44
jfehlig@137 45 #include "cmpitrace.h"
jfehlig@137 46 #include "xen_utils.h"
jfehlig@137 47 #include "provider_common.h"
jbulpin@0 48
jfehlig@137 49 /* Class keys */
jfehlig@137 50 static const char *keys[] = {"InstanceID", NULL};
jfehlig@137 51
jfehlig@137 52
jfehlig@137 53 /* Xen session object. Initialize when the provider is loaded, close when
jfehlig@137 54 * provider unloaded. */
jfehlig@137 55 static xen_utils_session *session = NULL;
jfehlig@137 56
jfehlig@137 57
jfehlig@137 58 static CMPIrc load()
jbulpin@0 59 {
jfehlig@137 60 /* Initialized Xen session object. */
jfehlig@137 61 if (!session)
jfehlig@137 62 xen_utils_xen_init(&session);
jbulpin@0 63
jfehlig@137 64 return CMPI_RC_OK;
jbulpin@0 65 }
jbulpin@0 66
jbulpin@0 67
jfehlig@137 68 static CMPIrc unload(const int terminating)
jbulpin@0 69 {
jfehlig@137 70 (void)terminating;
jfehlig@137 71
jfehlig@137 72 /* Close Xen session object. */
jfehlig@137 73 if (session) {
jfehlig@137 74 xen_utils_xen_close(session);
jfehlig@137 75 session = NULL;
jbulpin@0 76 }
jbulpin@0 77
jfehlig@137 78 return CMPI_RC_OK;
jbulpin@0 79 }
jbulpin@0 80
jbulpin@0 81
jfehlig@137 82 /* Get the single instance. */
jfehlig@137 83 static CMPIrc get(void **res, const char** properties)
jbulpin@0 84 {
jfehlig@137 85 xen_host_cpu_set *host_cpus;
jbulpin@0 86
jfehlig@137 87 (void)properties;
jfehlig@137 88
jfehlig@137 89 if (!xen_utils_validate_session(&session)) {
jfehlig@137 90 _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
jfehlig@137 91 ("--- Unable to establish connection with Xend"));
jfehlig@137 92 return CMPI_RC_ERR_FAILED;
jfehlig@137 93 }
jbulpin@0 94
jfehlig@137 95 if (!xen_host_get_host_cpus(session->xen, &host_cpus, session->host)) {
jfehlig@137 96 _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR,
jfehlig@137 97 ("--- Failed to retrieve host cpus from Xend"));
jfehlig@137 98 _SBLIM_TRACE_FUNCTION(_SBLIM_TRACE_LEVEL_ERROR,
jfehlig@137 99 xen_utils_trace_error(session->xen));
jfehlig@137 100 return CMPI_RC_ERR_FAILED;
jfehlig@25 101 }
jfehlig@25 102
jfehlig@137 103 *res = (void *)host_cpus;
jfehlig@137 104 return CMPI_RC_OK;
jfehlig@137 105 }
jfehlig@137 106
jbulpin@0 107
jfehlig@137 108 static void release(void *res)
jfehlig@137 109 {
jfehlig@137 110 if (res)
jfehlig@137 111 xen_host_cpu_set_free((xen_host_cpu_set *)res);
jbulpin@0 112 }
jbulpin@0 113
jfehlig@137 114
jfehlig@137 115 /* Set CMPIInstance properties from the resource data. */
jfehlig@137 116 static CMPIrc setproperties(CMPIInstance *inst, const void *res,
jfehlig@137 117 const char **properties)
jbulpin@0 118 {
jfehlig@137 119 xen_host_cpu_set *host_cpus = (xen_host_cpu_set *)res;
jfehlig@137 120 char *host_name;
jfehlig@137 121 char buf[MAX_INSTANCEID_LEN];
jfehlig@137 122 uint64_t prop_val_64;
jfehlig@137 123 int prop_val_32;
jfehlig@137 124
jfehlig@137 125 if (host_cpus == NULL)
jfehlig@137 126 return CMPI_RC_ERR_FAILED;
jfehlig@137 127
jfehlig@137 128 if (CMIsNullObject(inst))
jfehlig@137 129 return CMPI_RC_ERR_FAILED;
jfehlig@137 130
jfehlig@137 131 /* Setup a filter to only return the desired properties. */
jfehlig@137 132 CMSetPropertyFilter(inst, properties, keys);
jbulpin@0 133
jfehlig@137 134 session->xen->ok = true;
jfehlig@137 135 xen_host_get_name_label(session->xen, &host_name, session->host);
jfehlig@137 136 if (session->xen->ok) {
jfehlig@137 137 snprintf(buf, MAX_INSTANCEID_LEN, "Xen:%s:ProcessorPool",
jfehlig@137 138 host_name);
jfehlig@137 139 CMSetProperty(inst, "InstanceID", (CMPIValue *)buf, CMPI_chars);
jfehlig@137 140 free(host_name);
jfehlig@137 141 }
jfehlig@137 142 else {
jfehlig@137 143 CMSetProperty(inst, "InstanceID",
jfehlig@137 144 (CMPIValue *)"Xen:ProcessorPool", CMPI_chars);
jfehlig@137 145 }
jfehlig@137 146
jfehlig@137 147 CMSetProperty(inst, "PoolID", (CMPIValue *)"XenProcessorPool", CMPI_chars);
jfehlig@137 148
jfehlig@137 149 prop_val_32 = 3; /* 3 == Processor */
jfehlig@137 150 CMSetProperty(inst, "ResourceType", (CMPIValue *)&prop_val_32, CMPI_uint16);
jfehlig@137 151 CMSetProperty(inst, "AllocationUnits", (CMPIValue *)"Cores", CMPI_chars);
jfehlig@137 152
jfehlig@137 153 /* Capacity is the number of items in xen_host_cpu_set. */
jfehlig@137 154 prop_val_64 = host_cpus->size;
jfehlig@137 155 CMSetProperty(inst, "Capacity", (CMPIValue *)&prop_val_64, CMPI_uint64);
jfehlig@137 156
jfehlig@137 157 /*
jfehlig@137 158 * Xen does not currently support dedicated processor allocation,
jfehlig@137 159 * therefore no processors can be exclusively 'reserved' by a DomU.
jfehlig@137 160 */
jfehlig@137 161 prop_val_64 = 0;
jfehlig@137 162 CMSetProperty(inst, "Reserved", (CMPIValue *)&prop_val_64, CMPI_uint64);
jfehlig@137 163
jfehlig@137 164 prop_val_32 = 1;
jfehlig@137 165 CMSetProperty(inst, "Primordial" , (CMPIValue *)&prop_val_32, CMPI_boolean);
jfehlig@137 166
jfehlig@137 167 return CMPI_RC_OK;
jbulpin@0 168 }
jbulpin@0 169
jfehlig@137 170
jfehlig@137 171 /* Setup CMPILIFY function tables and instance provider entry point.*/
jfehlig@137 172 /* CMPILIFYInstance1ROMIStub(<CLASS>,<PROVIDERNAME>,<KEYS>,<MIHANDLE>) */
jfehlig@137 173 CMPILIFYInstance1ROMIStub(Xen_ProcessorPool, Xen_ProcessorPool, keys, mi)