diff options
author | Peter Schiffer <pschiffe@redhat.com> | 2013-04-23 15:43:40 +0200 |
---|---|---|
committer | Peter Schiffer <pschiffe@redhat.com> | 2013-04-23 15:43:40 +0200 |
commit | 1e4187b50657065445a33148bfb2224005fb0dff (patch) | |
tree | be2a363d74215eab1c98be2776b408dfc98cff23 /src/hardware | |
parent | e229f6f4752c30c4fb48c429174f81bbda02242d (diff) | |
download | openlmi-providers-1e4187b50657065445a33148bfb2224005fb0dff.tar.gz openlmi-providers-1e4187b50657065445a33148bfb2224005fb0dff.tar.xz openlmi-providers-1e4187b50657065445a33148bfb2224005fb0dff.zip |
Hardware: Added Physical Memory Provider
New Providers:
* LMI_PhysicalMemoryProvider
* LMI_PhysicalMemoryRealizesProvider
Other Changes:
* Fixed InstanceID in hardware to match the rest of the providers
* Removed some unused variables
Diffstat (limited to 'src/hardware')
-rw-r--r-- | src/hardware/LMI_Hardware.h | 1 | ||||
-rw-r--r-- | src/hardware/LMI_MemoryProvider.c | 3 | ||||
-rw-r--r-- | src/hardware/LMI_PhysicalMemoryProvider.c | 327 | ||||
-rw-r--r-- | src/hardware/LMI_PhysicalMemoryRealizesProvider.c | 263 | ||||
-rw-r--r-- | src/hardware/LMI_ProcessorCacheMemoryProvider.c | 4 | ||||
-rw-r--r-- | src/hardware/LMI_ProcessorCapabilitiesProvider.c | 5 | ||||
-rw-r--r-- | src/hardware/LMI_ProcessorChipProvider.c | 8 | ||||
-rw-r--r-- | src/hardware/LMI_ProcessorChipRealizesProvider.c | 5 | ||||
-rw-r--r-- | src/hardware/LMI_ProcessorElementCapabilitiesProvider.c | 5 | ||||
-rw-r--r-- | src/hardware/LMI_ProcessorProvider.c | 4 | ||||
-rw-r--r-- | src/hardware/dmidecode.c | 272 | ||||
-rw-r--r-- | src/hardware/dmidecode.h | 12 |
12 files changed, 873 insertions, 36 deletions
diff --git a/src/hardware/LMI_Hardware.h b/src/hardware/LMI_Hardware.h index 19a8ff7..12e9871 100644 --- a/src/hardware/LMI_Hardware.h +++ b/src/hardware/LMI_Hardware.h @@ -29,5 +29,6 @@ #define CPU_CACHE_CLASS_NAME "ProcessorCacheMemory" #define CPU_CHIP_CLASS_NAME "ProcessorChip" #define MEM_CLASS_NAME "Memory" +#define PHYS_MEM_CLASS_NAME "PhysicalMemory" #endif /* LMI_HARDWARE_H_ */ diff --git a/src/hardware/LMI_MemoryProvider.c b/src/hardware/LMI_MemoryProvider.c index 6c9a2ec..0d77c17 100644 --- a/src/hardware/LMI_MemoryProvider.c +++ b/src/hardware/LMI_MemoryProvider.c @@ -91,7 +91,8 @@ static CMPIStatus LMI_MemoryEnumInstances( LMI_Memory_Set_Name(&lmi_mem, name); LMI_Memory_Set_Description(&lmi_mem, "This object represents all memory available in system."); - LMI_Memory_Set_InstanceID(&lmi_mem, ORGID ":" MEM_CLASS_NAME ":0"); + LMI_Memory_Set_InstanceID(&lmi_mem, + ORGID ":" ORGID "_" MEM_CLASS_NAME ":0"); LMI_Memory_Set_IsCompressed(&lmi_mem, 0); LMI_Memory_Set_Purpose(&lmi_mem, "The system memory is temporary storage " "area storing instructions and data required by processor " diff --git a/src/hardware/LMI_PhysicalMemoryProvider.c b/src/hardware/LMI_PhysicalMemoryProvider.c new file mode 100644 index 0000000..51be88f --- /dev/null +++ b/src/hardware/LMI_PhysicalMemoryProvider.c @@ -0,0 +1,327 @@ +/* + * Copyright (C) 2013 Red Hat, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Peter Schiffer <pschiffe@redhat.com> + */ + +#include <konkret/konkret.h> +#include "LMI_PhysicalMemory.h" +#include "LMI_Hardware.h" +#include "globals.h" +#include "dmidecode.h" + +CMPIUint16 get_form_factor(const char *dmi_ff); +CMPIUint16 get_memory_type(const char *dmi_type); + +static const CMPIBroker* _cb = NULL; + +static void LMI_PhysicalMemoryInitialize() +{ +} + +static CMPIStatus LMI_PhysicalMemoryCleanup( + CMPIInstanceMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_PhysicalMemoryEnumInstanceNames( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + return KDefaultEnumerateInstanceNames( + _cb, mi, cc, cr, cop); +} + +static CMPIStatus LMI_PhysicalMemoryEnumInstances( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + LMI_PhysicalMemory lmi_phys_mem; + const char *ns = KNameSpace(cop); + char instance_id[INSTANCE_ID_LEN]; + unsigned i; + DmiMemory dmi_memory; + + if (dmi_get_memory(&dmi_memory) != 0 || dmi_memory.modules_nb < 1) { + goto done; + } + + for (i = 0; i < dmi_memory.modules_nb; i++) { + LMI_PhysicalMemory_Init(&lmi_phys_mem, _cb, ns); + + LMI_PhysicalMemory_Set_CreationClassName(&lmi_phys_mem, + ORGID "_" PHYS_MEM_CLASS_NAME); + + snprintf(instance_id, INSTANCE_ID_LEN, + ORGID ":" ORGID "_" PHYS_MEM_CLASS_NAME ":%s", + dmi_memory.modules[i].serial_number); + + LMI_PhysicalMemory_Set_Tag(&lmi_phys_mem, + dmi_memory.modules[i].serial_number); + LMI_PhysicalMemory_Set_Capacity(&lmi_phys_mem, + dmi_memory.modules[i].size); + LMI_PhysicalMemory_Set_FormFactor(&lmi_phys_mem, + get_form_factor(dmi_memory.modules[i].form_factor)); + LMI_PhysicalMemory_Set_MemoryType(&lmi_phys_mem, + get_memory_type(dmi_memory.modules[i].type)); + LMI_PhysicalMemory_Set_Speed(&lmi_phys_mem, + dmi_memory.modules[i].speed_time); + LMI_PhysicalMemory_Set_BankLabel(&lmi_phys_mem, + dmi_memory.modules[i].bank_label); + LMI_PhysicalMemory_Set_ElementName(&lmi_phys_mem, + dmi_memory.modules[i].name); + LMI_PhysicalMemory_Set_Manufacturer(&lmi_phys_mem, + dmi_memory.modules[i].manufacturer); + LMI_PhysicalMemory_Set_SerialNumber(&lmi_phys_mem, + dmi_memory.modules[i].serial_number); + LMI_PhysicalMemory_Set_PartNumber(&lmi_phys_mem, + dmi_memory.modules[i].part_number); + LMI_PhysicalMemory_Set_Caption(&lmi_phys_mem, "Physical Memory Module"); + LMI_PhysicalMemory_Set_Description(&lmi_phys_mem, + "This object represents one physical memory module in system."); + LMI_PhysicalMemory_Set_InstanceID(&lmi_phys_mem, instance_id); + LMI_PhysicalMemory_Set_Name(&lmi_phys_mem, dmi_memory.modules[i].name); + LMI_PhysicalMemory_Set_ConfiguredMemoryClockSpeed(&lmi_phys_mem, + dmi_memory.modules[i].speed_clock); + LMI_PhysicalMemory_Set_TotalWidth(&lmi_phys_mem, + dmi_memory.modules[i].total_width); + LMI_PhysicalMemory_Set_DataWidth(&lmi_phys_mem, + dmi_memory.modules[i].data_width); + + KReturnInstance(cr, lmi_phys_mem); + } + +done: + dmi_free_memory(&dmi_memory); + + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_PhysicalMemoryGetInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + return KDefaultGetInstance( + _cb, mi, cc, cr, cop, properties); +} + +static CMPIStatus LMI_PhysicalMemoryCreateInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_PhysicalMemoryModifyInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci, + const char** properties) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_PhysicalMemoryDeleteInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_PhysicalMemoryExecQuery( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* lang, + const char* query) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +CMInstanceMIStub( + LMI_PhysicalMemory, + LMI_PhysicalMemory, + _cb, + LMI_PhysicalMemoryInitialize()) + +static CMPIStatus LMI_PhysicalMemoryMethodCleanup( + CMPIMethodMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_PhysicalMemoryInvokeMethod( + CMPIMethodMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* meth, + const CMPIArgs* in, + CMPIArgs* out) +{ + return LMI_PhysicalMemory_DispatchMethod( + _cb, mi, cc, cr, cop, meth, in, out); +} + +/* + * Get Memory Type according to the dmidecode output. + * @param dmi_type memory type from dmidecode + * @return memory type ID defined by CIM + */ +CMPIUint16 get_memory_type(const char *dmi_type) +{ + if (!dmi_type || strlen(dmi_type) < 1) { + return 0; /* Unknown */ + } + + static struct { + CMPIUint16 value_map; /* ValueMap defined by CIM */ + char *search; /* String used to match the dmidecode memory type */ + } mem_types[] = { + {0, "Unknown"}, + {1, "Other"}, + {2, "DRAM"}, + /* + {3, "Synchronous DRAM"}, + {4, "Cache DRAM"}, + {5, "EDO"}, + */ + {6, "EDRAM"}, + {7, "VRAM"}, + {8, "SRAM"}, + {9, "RAM"}, + {10, "ROM"}, + {11, "Flash"}, + {12, "EEPROM"}, + {13, "FEPROM"}, + {14, "EPROM"}, + {15, "CDRAM"}, + {16, "3DRAM"}, + {17, "SDRAM"}, + {18, "SGRAM"}, + {19, "RDRAM"}, + {20, "DDR"}, + {21, "DDR2"}, + /* + {22, "BRAM"}, + */ + {23, "DDR2 FB-DIMM"}, + {24, "DDR3"}, + {25, "FBD2"}, + }; + + size_t i, types_length = sizeof(mem_types) / sizeof(mem_types[0]); + + for (i = 0; i < types_length; i++) { + if (strcmp(dmi_type, mem_types[i].search) == 0) { + return mem_types[i].value_map; + } + } + + return 1; /* Other */ +} + +/* + * Get Form Factor according to the dmidecode output. + * @param dmi_ff form factor from dmidecode + * @return form factor ID defined by CIM + */ +CMPIUint16 get_form_factor(const char *dmi_ff) +{ + if (!dmi_ff || strlen(dmi_ff) < 1) { + return 0; /* Unknown */ + } + + static struct { + CMPIUint16 value_map; /* ValueMap defined by CIM */ + char *search; /* String used to match the dmidecode form factor */ + } form_factors[] = { + {0, "Unknown"}, + {1, "Other"}, + {2, "SIP"}, + {3, "DIP"}, + {4, "ZIP"}, + /* + {5, "SOJ"}, + */ + {6, "Proprietary Card"}, + {7, "SIMM"}, + {8, "DIMM"}, + {9, "TSOP"}, + /* + {10, "PGA"}, + */ + {11, "RIMM"}, + {12, "SODIMM"}, + {13, "SRIMM"}, + /* + {14, "SMD"}, + {15, "SSMP"}, + {16, "QFP"}, + {17, "TQFP"}, + {18, "SOIC"}, + {19, "LCC"}, + {20, "PLCC"}, + {21, "BGA"}, + {22, "FPBGA"}, + {23, "LGA"}, + */ + }; + + size_t i, ff_length = sizeof(form_factors) / sizeof(form_factors[0]); + + for (i = 0; i < ff_length; i++) { + if (strcmp(dmi_ff, form_factors[i].search) == 0) { + return form_factors[i].value_map; + } + } + + return 1; /* Other */ +} + +CMMethodMIStub( + LMI_PhysicalMemory, + LMI_PhysicalMemory, + _cb, + LMI_PhysicalMemoryInitialize()) + +KONKRET_REGISTRATION( + "root/cimv2", + "LMI_PhysicalMemory", + "LMI_PhysicalMemory", + "instance method") diff --git a/src/hardware/LMI_PhysicalMemoryRealizesProvider.c b/src/hardware/LMI_PhysicalMemoryRealizesProvider.c new file mode 100644 index 0000000..0da8d33 --- /dev/null +++ b/src/hardware/LMI_PhysicalMemoryRealizesProvider.c @@ -0,0 +1,263 @@ +/* + * Copyright (C) 2013 Red Hat, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Peter Schiffer <pschiffe@redhat.com> + */ + +#include <konkret/konkret.h> +#include "LMI_PhysicalMemoryRealizes.h" +#include "LMI_Hardware.h" +#include "globals.h" +#include "dmidecode.h" + +static const CMPIBroker* _cb; + +static void LMI_PhysicalMemoryRealizesInitialize() +{ +} + +static CMPIStatus LMI_PhysicalMemoryRealizesCleanup( + CMPIInstanceMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_PhysicalMemoryRealizesEnumInstanceNames( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + return KDefaultEnumerateInstanceNames( + _cb, mi, cc, cr, cop); +} + +static CMPIStatus LMI_PhysicalMemoryRealizesEnumInstances( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + LMI_PhysicalMemoryRealizes lmi_phys_mem_realizes; + LMI_PhysicalMemoryRef lmi_phys_mem; + LMI_MemoryRef lmi_mem; + const char *ns = KNameSpace(cop); + unsigned i; + DmiMemory dmi_memory; + + if (dmi_get_memory(&dmi_memory) != 0 || dmi_memory.modules_nb < 1) { + goto done; + } + + LMI_MemoryRef_Init(&lmi_mem, _cb, ns); + LMI_MemoryRef_Set_SystemCreationClassName(&lmi_mem, + get_system_creation_class_name()); + LMI_MemoryRef_Set_SystemName(&lmi_mem, get_system_name()); + LMI_MemoryRef_Set_CreationClassName(&lmi_mem, ORGID "_" MEM_CLASS_NAME); + LMI_MemoryRef_Set_DeviceID(&lmi_mem, "0"); + + for (i = 0; i < dmi_memory.modules_nb; i++) { + LMI_PhysicalMemoryRealizes_Init(&lmi_phys_mem_realizes, _cb, ns); + + LMI_PhysicalMemoryRef_Init(&lmi_phys_mem, _cb, ns); + LMI_PhysicalMemoryRef_Set_CreationClassName(&lmi_phys_mem, + ORGID "_" PHYS_MEM_CLASS_NAME); + LMI_PhysicalMemoryRef_Set_Tag(&lmi_phys_mem, + dmi_memory.modules[i].serial_number); + + LMI_PhysicalMemoryRealizes_Set_Antecedent(&lmi_phys_mem_realizes, + &lmi_phys_mem); + LMI_PhysicalMemoryRealizes_Set_Dependent(&lmi_phys_mem_realizes, + &lmi_mem); + + KReturnInstance(cr, lmi_phys_mem_realizes); + } + +done: + dmi_free_memory(&dmi_memory); + + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_PhysicalMemoryRealizesGetInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + return KDefaultGetInstance( + _cb, mi, cc, cr, cop, properties); +} + +static CMPIStatus LMI_PhysicalMemoryRealizesCreateInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_PhysicalMemoryRealizesModifyInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci, + const char**properties) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_PhysicalMemoryRealizesDeleteInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_PhysicalMemoryRealizesExecQuery( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* lang, + const char* query) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_PhysicalMemoryRealizesAssociationCleanup( + CMPIAssociationMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_PhysicalMemoryRealizesAssociators( + CMPIAssociationMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* assocClass, + const char* resultClass, + const char* role, + const char* resultRole, + const char** properties) +{ + return KDefaultAssociators( + _cb, + mi, + cc, + cr, + cop, + LMI_PhysicalMemoryRealizes_ClassName, + assocClass, + resultClass, + role, + resultRole, + properties); +} + +static CMPIStatus LMI_PhysicalMemoryRealizesAssociatorNames( + CMPIAssociationMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* assocClass, + const char* resultClass, + const char* role, + const char* resultRole) +{ + return KDefaultAssociatorNames( + _cb, + mi, + cc, + cr, + cop, + LMI_PhysicalMemoryRealizes_ClassName, + assocClass, + resultClass, + role, + resultRole); +} + +static CMPIStatus LMI_PhysicalMemoryRealizesReferences( + CMPIAssociationMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* assocClass, + const char* role, + const char** properties) +{ + return KDefaultReferences( + _cb, + mi, + cc, + cr, + cop, + LMI_PhysicalMemoryRealizes_ClassName, + assocClass, + role, + properties); +} + +static CMPIStatus LMI_PhysicalMemoryRealizesReferenceNames( + CMPIAssociationMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* assocClass, + const char* role) +{ + return KDefaultReferenceNames( + _cb, + mi, + cc, + cr, + cop, + LMI_PhysicalMemoryRealizes_ClassName, + assocClass, + role); +} + +CMInstanceMIStub( + LMI_PhysicalMemoryRealizes, + LMI_PhysicalMemoryRealizes, + _cb, + LMI_PhysicalMemoryRealizesInitialize()) + +CMAssociationMIStub( + LMI_PhysicalMemoryRealizes, + LMI_PhysicalMemoryRealizes, + _cb, + LMI_PhysicalMemoryRealizesInitialize()) + +KONKRET_REGISTRATION( + "root/cimv2", + "LMI_PhysicalMemoryRealizes", + "LMI_PhysicalMemoryRealizes", + "instance association") diff --git a/src/hardware/LMI_ProcessorCacheMemoryProvider.c b/src/hardware/LMI_ProcessorCacheMemoryProvider.c index 030ddd1..9fe0230 100644 --- a/src/hardware/LMI_ProcessorCacheMemoryProvider.c +++ b/src/hardware/LMI_ProcessorCacheMemoryProvider.c @@ -120,7 +120,7 @@ static CMPIStatus LMI_ProcessorCacheMemoryEnumInstances( /* do we have dmidecode output? */ if (dmi_cpu_caches_nb > 0) { snprintf(instance_id, INSTANCE_ID_LEN, - ORGID ":" CPU_CACHE_CLASS_NAME ":%s", + ORGID ":" ORGID "_" CPU_CACHE_CLASS_NAME ":%s", dmi_cpu_caches[i].id); LMI_ProcessorCacheMemory_Set_DeviceID(&lmi_cpu_cache, @@ -136,7 +136,7 @@ static CMPIStatus LMI_ProcessorCacheMemoryEnumInstances( get_cachestatus(dmi_cpu_caches[i].status)); } else { snprintf(instance_id, INSTANCE_ID_LEN, - ORGID ":" CPU_CACHE_CLASS_NAME ":%s", + ORGID ":" ORGID "_" CPU_CACHE_CLASS_NAME ":%s", sysfs_cpu_caches[i].id); LMI_ProcessorCacheMemory_Set_DeviceID(&lmi_cpu_cache, diff --git a/src/hardware/LMI_ProcessorCapabilitiesProvider.c b/src/hardware/LMI_ProcessorCapabilitiesProvider.c index c771124..0d816f0 100644 --- a/src/hardware/LMI_ProcessorCapabilitiesProvider.c +++ b/src/hardware/LMI_ProcessorCapabilitiesProvider.c @@ -91,14 +91,15 @@ static CMPIStatus LMI_ProcessorCapabilitiesEnumInstances( /* do we have output from dmidecode program? */ if (dmi_cpus_nb > 0) { snprintf(instance_id, INSTANCE_ID_LEN, - ORGID ":" CPU_CAP_CLASS_NAME ":%s", dmi_cpus[i].id); + ORGID ":" ORGID "_" CPU_CAP_CLASS_NAME ":%s", + dmi_cpus[i].id); snprintf(element_name, ELEMENT_NAME_LEN, "%s%s", element_name_string, dmi_cpus[i].id); cores = dmi_cpus[i].cores; threads = dmi_cpus[i].threads; } else { snprintf(instance_id, INSTANCE_ID_LEN, - ORGID ":" CPU_CAP_CLASS_NAME ":%u", i); + ORGID ":" ORGID "_" CPU_CAP_CLASS_NAME ":%u", i); snprintf(element_name, ELEMENT_NAME_LEN, "%s%u", element_name_string, i); cores = lscpu.cores; diff --git a/src/hardware/LMI_ProcessorChipProvider.c b/src/hardware/LMI_ProcessorChipProvider.c index 47ba488..1606dce 100644 --- a/src/hardware/LMI_ProcessorChipProvider.c +++ b/src/hardware/LMI_ProcessorChipProvider.c @@ -57,7 +57,7 @@ static CMPIStatus LMI_ProcessorChipEnumInstances( { LMI_ProcessorChip lmi_cpu_chip; const char *ns = KNameSpace(cop); - char *error_msg = NULL, instance_id[INSTANCE_ID_LEN]; + char instance_id[INSTANCE_ID_LEN]; unsigned i; DmiProcessor *dmi_cpus = NULL; unsigned dmi_cpus_nb = 0; @@ -73,7 +73,7 @@ static CMPIStatus LMI_ProcessorChipEnumInstances( ORGID "_" CPU_CHIP_CLASS_NAME); snprintf(instance_id, INSTANCE_ID_LEN, - ORGID ":" CPU_CHIP_CLASS_NAME ":%s", dmi_cpus[i].id); + ORGID ":" ORGID "_" CPU_CHIP_CLASS_NAME ":%s", dmi_cpus[i].id); LMI_ProcessorChip_Set_Tag(&lmi_cpu_chip, dmi_cpus[i].id); LMI_ProcessorChip_Set_ElementName(&lmi_cpu_chip, dmi_cpus[i].name); @@ -96,10 +96,6 @@ static CMPIStatus LMI_ProcessorChipEnumInstances( done: dmi_free_processors(&dmi_cpus, &dmi_cpus_nb); - if (error_msg) { - KReturn2(_cb, ERR_FAILED, error_msg); - } - CMReturn(CMPI_RC_OK); } diff --git a/src/hardware/LMI_ProcessorChipRealizesProvider.c b/src/hardware/LMI_ProcessorChipRealizesProvider.c index 6dfd4bf..55efba8 100644 --- a/src/hardware/LMI_ProcessorChipRealizesProvider.c +++ b/src/hardware/LMI_ProcessorChipRealizesProvider.c @@ -59,7 +59,6 @@ static CMPIStatus LMI_ProcessorChipRealizesEnumInstances( LMI_ProcessorChipRef lmi_cpu_chip; LMI_ProcessorRef lmi_cpu; const char *ns = KNameSpace(cop); - char *error_msg = NULL; unsigned i; DmiProcessor *dmi_cpus = NULL; unsigned dmi_cpus_nb = 0; @@ -95,10 +94,6 @@ static CMPIStatus LMI_ProcessorChipRealizesEnumInstances( done: dmi_free_processors(&dmi_cpus, &dmi_cpus_nb); - if (error_msg) { - KReturn2(_cb, ERR_FAILED, error_msg); - } - CMReturn(CMPI_RC_OK); } diff --git a/src/hardware/LMI_ProcessorElementCapabilitiesProvider.c b/src/hardware/LMI_ProcessorElementCapabilitiesProvider.c index 322e966..b9b042d 100644 --- a/src/hardware/LMI_ProcessorElementCapabilitiesProvider.c +++ b/src/hardware/LMI_ProcessorElementCapabilitiesProvider.c @@ -103,14 +103,15 @@ static CMPIStatus LMI_ProcessorElementCapabilitiesEnumInstances( LMI_ProcessorRef_Set_DeviceID(&lmi_cpu, dmi_cpus[i].id); snprintf(instance_id, INSTANCE_ID_LEN, - ORGID ":" CPU_CAP_CLASS_NAME ":%s", dmi_cpus[i].id); + ORGID ":" ORGID "_" CPU_CAP_CLASS_NAME ":%s", + dmi_cpus[i].id); } else { char cpu_id[LONG_INT_LEN]; snprintf(cpu_id, LONG_INT_LEN, "%u", i); LMI_ProcessorRef_Set_DeviceID(&lmi_cpu, cpu_id); snprintf(instance_id, INSTANCE_ID_LEN, - ORGID ":" CPU_CAP_CLASS_NAME ":%u", i); + ORGID ":" ORGID "_" CPU_CAP_CLASS_NAME ":%u", i); } LMI_ProcessorCapabilitiesRef_Set_InstanceID(&lmi_cpu_cap, instance_id); diff --git a/src/hardware/LMI_ProcessorProvider.c b/src/hardware/LMI_ProcessorProvider.c index c14b105..d96c679 100644 --- a/src/hardware/LMI_ProcessorProvider.c +++ b/src/hardware/LMI_ProcessorProvider.c @@ -141,7 +141,7 @@ static CMPIStatus LMI_ProcessorEnumInstances( enabled_cores = dmi_cpus[i].enabled_cores; stepping = dmi_cpus[i].stepping; snprintf(instance_id, INSTANCE_ID_LEN, - ORGID ":" CPU_CLASS_NAME ":%s", dmi_cpus[i].id); + ORGID ":" ORGID "_" CPU_CLASS_NAME ":%s", dmi_cpus[i].id); LMI_Processor_Set_DeviceID(&lmi_cpu, dmi_cpus[i].id); LMI_Processor_Set_Family(&lmi_cpu, family); @@ -175,7 +175,7 @@ static CMPIStatus LMI_ProcessorEnumInstances( char cpu_id[LONG_INT_LEN]; snprintf(cpu_id, LONG_INT_LEN, "%u", i); snprintf(instance_id, INSTANCE_ID_LEN, - ORGID ":" CPU_CLASS_NAME ":%s", cpu_id); + ORGID ":" ORGID "_" CPU_CLASS_NAME ":%s", cpu_id); cpustatus = get_cpustatus("Enabled"); enabledstate = get_enabledstate(cpustatus); if (enabledstate == LMI_Processor_EnabledState_Enabled) { diff --git a/src/hardware/dmidecode.c b/src/hardware/dmidecode.c index 367a08c..f034b56 100644 --- a/src/hardware/dmidecode.c +++ b/src/hardware/dmidecode.c @@ -719,14 +719,80 @@ void init_dmi_memory_struct(DmiMemory *memory) void init_dmi_memory_module_struct(DmiMemoryModule *mem) { mem->size = 0; + mem->serial_number = NULL; + mem->form_factor = NULL; + mem->type = NULL; + mem->slot = -1; + mem->speed_time = 0; + mem->bank_label = NULL; + mem->name = NULL; + mem->manufacturer = NULL; + mem->part_number = NULL; + mem->speed_clock = 0; + mem->data_width = 0; + mem->total_width = 0; +} + +/* + * Check attributes of memory structure and fill in defaults if needed. + * @param memory + * @return 0 if success, negative value otherwise + */ +short check_dmi_memory_attributes(DmiMemory *memory) +{ + short ret = -1; + unsigned i; + + for (i = 0; i < memory->modules_nb; i++) { + if (!memory->modules[i].serial_number) { + if (!(memory->modules[i].serial_number = strdup(""))) { + ret = -2; + goto done; + } + if (!(memory->modules[i].form_factor = strdup("Unknown"))) { + ret = -3; + goto done; + } + if (!(memory->modules[i].type = strdup("Unknown"))) { + ret = -4; + goto done; + } + if (!(memory->modules[i].bank_label = strdup(""))) { + ret = -5; + goto done; + } + if (!(memory->modules[i].name = strdup("Memory Module"))) { + ret = -6; + goto done; + } + if (!(memory->modules[i].manufacturer = strdup(""))) { + ret = -7; + goto done; + } + if (!(memory->modules[i].part_number = strdup(""))) { + ret = -8; + goto done; + } + } + } + + ret = 0; + +done: + if (ret != 0) { + warn("Failed to allocate memory."); + } + + return ret; } short dmi_get_memory(DmiMemory *memory) { short ret = -1; - int curr_mem = -1; - unsigned i, buffer_size = 0; - char **buffer = NULL, *buf; + int curr_mem = -1, last_mem = -1, slot = -1; + unsigned i, j, buffer_size = 0, data_width = 0, total_width = 0; + unsigned long memory_size; + char **buffer = NULL, *buf, *str_format; init_dmi_memory_struct(memory); @@ -761,34 +827,184 @@ short dmi_get_memory(DmiMemory *memory) /* parse information about modules */ for (i = 0; i < buffer_size; i++) { - if (strstr(buffer[i], "Size: ") && - !strstr(buffer[i], "Size: No Module Installed")) { - curr_mem++; - init_dmi_memory_module_struct(&memory->modules[curr_mem]); + /* Total Width */ + buf = copy_string_part_after_delim(buffer[i], "Total Width: "); + if (buf) { + sscanf(buf, "%u", &total_width); + free(buf); + buf = NULL; + continue; + } + /* Memory Module Data Width */ + buf = copy_string_part_after_delim(buffer[i], "Data Width: "); + if (buf) { + sscanf(buf, "%u", &data_width); + free(buf); + buf = NULL; + continue; + } + if (strstr(buffer[i], "Size: ")) { + if (strstr(buffer[i], "Size: No Module Installed")) { + last_mem = curr_mem; + curr_mem = -1; + continue; + } else { + curr_mem = last_mem + 1; + init_dmi_memory_module_struct(&memory->modules[curr_mem]); + /* Module Size */ + buf = copy_string_part_after_delim(buffer[i], "Size: "); + if (buf) { + sscanf(buf, "%lu", &memory->modules[curr_mem].size); + memory->modules[curr_mem].size *= 1048576; /* It's in MB, we want B */ + memory->physical_size += memory->modules[curr_mem].size; + free(buf); + buf = NULL; + } + /*Pretty, human readable module name */ + if (memory->modules[curr_mem].size >= 1073741824) { + memory_size = memory->modules[curr_mem].size / 1073741824; + str_format = "%lu GB Memory Module"; + } else { + memory_size = memory->modules[curr_mem].size / 1048576; + str_format = "%lu MB Memory Module"; + } + if (asprintf(&memory->modules[curr_mem].name, str_format, memory_size) < 0) { + memory->modules[curr_mem].name = NULL; + warn("Failed to allocate memory."); + ret = -5; + goto done; + } + + memory->modules[curr_mem].total_width = total_width; + memory->modules[curr_mem].data_width = data_width; + total_width = 0; + data_width = 0; - /* Module Size */ - buf = copy_string_part_after_delim(buffer[i], "Size: "); + continue; + } + } + /* ignore useless lines */ + if (curr_mem < 0) { + continue; + } + /* Serial Number */ + buf = copy_string_part_after_delim(buffer[i], "Serial Number: "); + if (buf) { + if (strcmp(buf, "Not Specified") != 0) { + memory->modules[curr_mem].serial_number = buf; + buf = NULL; + } else { + free(buf); + buf = NULL; + if (asprintf(&memory->modules[curr_mem].serial_number, "%u", curr_mem) < 0) { + memory->modules[curr_mem].serial_number = NULL; + warn("Failed to allocate memory."); + ret = -6; + goto done; + } + } + continue; + } + if (!strstr(buffer[i], "Bank Locator:")) { + /* Slot */ + buf = copy_string_part_after_delim(buffer[i], "Locator: "); if (buf) { - sscanf(buf, "%lu", &memory->modules[curr_mem].size); - memory->modules[curr_mem].size *= 1048576; /* It's in MB, we want B */ - memory->physical_size += memory->modules[curr_mem].size; + sscanf(buf, "%*s %d", &memory->modules[curr_mem].slot); free(buf); buf = NULL; + continue; } + } else { + /* Memory Module Bank Label */ + buf = copy_string_part_after_delim(buffer[i], "Bank Locator: "); + if (buf) { + memory->modules[curr_mem].bank_label = buf; + buf = NULL; + continue; + } + } + /* Form Factor */ + buf = copy_string_part_after_delim(buffer[i], "Form Factor: "); + if (buf) { + memory->modules[curr_mem].form_factor = buf; + buf = NULL; + continue; + } + /* Memory Module Type */ + buf = copy_string_part_after_delim(buffer[i], "Type: "); + if (buf) { + memory->modules[curr_mem].type = buf; + buf = NULL; + continue; + } + /* Manufacturer */ + buf = copy_string_part_after_delim(buffer[i], "Manufacturer: "); + if (buf) { + memory->modules[curr_mem].manufacturer = buf; + buf = NULL; + continue; + } + /* Part Number */ + buf = copy_string_part_after_delim(buffer[i], "Part Number: "); + if (buf) { + memory->modules[curr_mem].part_number = buf; + buf = NULL; + continue; + } + /* Speed in MHz */ + buf = copy_string_part_after_delim(buffer[i], "Speed: "); + if (buf) { + sscanf(buf, "%u", &memory->modules[curr_mem].speed_clock); + free(buf); + buf = NULL; + continue; + } + } + + free_2d_buffer(&buffer, &buffer_size); + /* get additional dmidecode output for memory modules */ + if (run_command("dmidecode -t 6", &buffer, &buffer_size) != 0) { + ret = -7; + goto done; + } + + /* parse additional information about modules */ + for (i = 0; i < buffer_size; i++) { + /* Slot */ + buf = copy_string_part_after_delim(buffer[i], "Socket Designation: "); + if (buf) { + sscanf(buf, "%*s %*s %d", &slot); + free(buf); + buf = NULL; continue; } - /* ignore first useless lines */ - if (curr_mem < 0) { + /* ignore useless lines */ + if (slot < 0) { continue; } + /* Memory Speed */ + buf = copy_string_part_after_delim(buffer[i], "Current Speed: "); + if (buf) { + if (slot != -1) { + for (j = 0; j < memory->modules_nb; j++) { + if (memory->modules[j].slot == slot) { + sscanf(buf, "%u", &memory->modules[j].speed_time); + break; + } + } + } + free(buf); + buf = NULL; + slot = -1; + } } free_2d_buffer(&buffer, &buffer_size); /* get dmidecode output for memory array */ if (run_command("dmidecode -t 19", &buffer, &buffer_size) != 0) { - ret = -5; + ret = -8; goto done; } @@ -822,6 +1038,12 @@ short dmi_get_memory(DmiMemory *memory) } } + /* fill in default attributes if needed */ + if (check_dmi_memory_attributes(memory) != 0) { + ret = -9; + goto done; + } + ret = 0; done: @@ -836,8 +1058,26 @@ done: void dmi_free_memory(DmiMemory *memory) { + unsigned i; + if (memory->modules_nb > 0) { - free (memory->modules); + for (i = 0; i < memory->modules_nb; i++) { + free(memory->modules[i].serial_number); + memory->modules[i].serial_number = NULL; + free(memory->modules[i].form_factor); + memory->modules[i].form_factor = NULL; + free(memory->modules[i].type); + memory->modules[i].type = NULL; + free(memory->modules[i].bank_label); + memory->modules[i].bank_label = NULL; + free(memory->modules[i].name); + memory->modules[i].name = NULL; + free(memory->modules[i].manufacturer); + memory->modules[i].manufacturer = NULL; + free(memory->modules[i].part_number); + memory->modules[i].part_number = NULL; + } + free(memory->modules); } memory->modules_nb = 0; memory->modules = NULL; diff --git a/src/hardware/dmidecode.h b/src/hardware/dmidecode.h index d3320ea..d838cf5 100644 --- a/src/hardware/dmidecode.h +++ b/src/hardware/dmidecode.h @@ -67,6 +67,18 @@ typedef struct _DmiCpuCache { /* Memory module from dmidecode. */ typedef struct _DmiMemoryModule { unsigned long size; /* Memory Module Size in Bytes */ + char *serial_number; /* Memory Module Serial Number */ + char *form_factor; /* Memory Module Form Factor */ + char *type; /* Memory Module Type */ + int slot; /* Slot where Memory Module is placed */ + unsigned speed_time; /* Memory Speed in ns */ + char *bank_label; /* Memory Module Bank Label */ + char *name; /* Memory Module Name */ + char *manufacturer; /* Memory Module Manufacturer */ + char *part_number; /* Memory Module Part Number */ + unsigned speed_clock; /* Memory Module Speed in MHz */ + unsigned data_width; /* Memory Module Data Width in bits */ + unsigned total_width; /* Memory Module Total Width in bits */ } DmiMemoryModule; /* Memory from dmidecode. */ |