
# HG changeset patch # User Jay Gagnon <grendel@linux.vnet.ibm.com> # Date 1194557443 18000 # Node ID 2d09468e2de7ed9194907bfff1efbb16ba40202d # Parent 0ed8747c1dfbf14ff7f6e23ff792a35852294fa6 Add processor support to SettingsDefineCapabilities. Signed-off-by: Jay Gagnon <grendel@linux.vnet.ibm.com> diff -r 0ed8747c1dfb -r 2d09468e2de7 src/Virt_SettingsDefineCapabilities.c --- a/src/Virt_SettingsDefineCapabilities.c Thu Nov 08 16:29:37 2007 -0500 +++ b/src/Virt_SettingsDefineCapabilities.c Thu Nov 08 16:30:43 2007 -0500 @@ -26,6 +26,8 @@ #include <sys/vfs.h> #include <errno.h> +#include <libvirt.h> + #include "config.h" #include "cmpidt.h" @@ -195,6 +197,121 @@ static struct sdc_rasd_prop *mem_inc(con return rasd; } +static struct sdc_rasd_prop *proc_min(const CMPIObjectPath *ref, + CMPIStatus *s) +{ + bool ret; + uint16_t num_procs = 1; + struct sdc_rasd_prop *rasd = NULL; + + struct sdc_rasd_prop tmp[] = { + {"InstanceID", (CMPIValue *)"Minimum", CMPI_chars}, + {"AllocationUnits", (CMPIValue *)"Processors", CMPI_chars}, + {"VirtualQuantity", (CMPIValue *)&num_procs, CMPI_uint16}, + PROP_END + }; + + ret = dup_rasd_prop_list(tmp, &rasd); + if (!ret) { + cu_statusf(_BROKER, s, CMPI_RC_ERR_FAILED, + "Could not copy RASD."); + } + + return rasd; +} + +static struct sdc_rasd_prop *proc_max(const CMPIObjectPath *ref, + CMPIStatus *s) +{ + bool ret; + int cpu_num; + FILE *cpuinfo; + size_t len = 0; + char *line = NULL; + uint16_t num_procs = 0; + struct sdc_rasd_prop *rasd = NULL; + + CU_DEBUG("In proc_max()"); + + cpuinfo = fopen("/proc/cpuinfo", "r"); + if (cpuinfo == NULL) { + cu_statusf(_BROKER, s, CMPI_RC_ERR_FAILED, + "Could not copy open cpuinfo."); + goto out; + } + + while (getline(&line, &len, cpuinfo) > 0) { + if (sscanf(line, "processor : %d", &cpu_num) == 1) { + CU_DEBUG("Line matched. num_procs++"); + num_procs++; + } + } + + struct sdc_rasd_prop tmp[] = { + {"InstanceID", (CMPIValue *)"Maximum", CMPI_chars}, + {"AllocationUnits", (CMPIValue *)"Processors", CMPI_chars}, + {"VirtualQuantity", (CMPIValue *)&num_procs, CMPI_uint16}, + PROP_END + }; + + ret = dup_rasd_prop_list(tmp, &rasd); + if (!ret) { + cu_statusf(_BROKER, s, CMPI_RC_ERR_FAILED, + "Could not copy RASD."); + } + + out: + free(line); + fclose(cpuinfo); + return rasd; +} + +static struct sdc_rasd_prop *proc_def(const CMPIObjectPath *ref, + CMPIStatus *s) +{ + bool ret; + uint16_t num_procs = 1; + struct sdc_rasd_prop *rasd = NULL; + + struct sdc_rasd_prop tmp[] = { + {"InstanceID", (CMPIValue *)"Default", CMPI_chars}, + {"AllocationUnits", (CMPIValue *)"Processors", CMPI_chars}, + {"VirtualQuantity", (CMPIValue *)&num_procs, CMPI_uint16}, + PROP_END + }; + + ret = dup_rasd_prop_list(tmp, &rasd); + if (!ret) { + cu_statusf(_BROKER, s, CMPI_RC_ERR_FAILED, + "Could not copy RASD."); + } + + return rasd; +} + +static struct sdc_rasd_prop *proc_inc(const CMPIObjectPath *ref, + CMPIStatus *s) +{ + bool ret; + uint16_t num_procs = 1; + struct sdc_rasd_prop *rasd = NULL; + + struct sdc_rasd_prop tmp[] = { + {"InstanceID", (CMPIValue *)"Increment", CMPI_chars}, + {"AllocationUnits", (CMPIValue *)"Processors", CMPI_chars}, + {"VirtualQuantity", (CMPIValue *)&num_procs, CMPI_uint16}, + PROP_END + }; + + ret = dup_rasd_prop_list(tmp, &rasd); + if (!ret) { + cu_statusf(_BROKER, s, CMPI_RC_ERR_FAILED, + "Could not copy RASD."); + } + + return rasd; +} + static struct sdc_rasd_prop *net_min(const CMPIObjectPath *ref, CMPIStatus *s) { @@ -413,6 +530,14 @@ static struct sdc_rasd mem = { .inc = mem_inc }; +static struct sdc_rasd processor = { + .resource_type = CIM_RASD_TYPE_PROC, + .min = proc_min, + .max = proc_max, + .def = proc_def, + .inc = proc_inc +}; + static struct sdc_rasd network = { .resource_type = CIM_RASD_TYPE_NET, .min = net_min, @@ -431,6 +556,7 @@ static struct sdc_rasd disk = { static struct sdc_rasd *sdc_rasd_list[] = { &mem, + &processor, &network, &disk, NULL