summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--cmake/modules/FindOpenLMI.cmake21
-rw-r--r--mof/LMI_Hardware.mof17
-rw-r--r--src/CMakeLists.txt16
-rw-r--r--src/fan/LMI_FanAssociatedSensorProvider.c2
-rw-r--r--src/fan/LMI_FanSensorProvider.c2
-rw-r--r--src/globals.h19
-rw-r--r--src/hardware/CMakeLists.txt2
-rw-r--r--src/hardware/LMI_Hardware.h1
-rw-r--r--src/hardware/LMI_MemoryProvider.c322
-rw-r--r--src/hardware/LMI_ProcessorCacheMemoryProvider.c1
-rw-r--r--src/hardware/LMI_ProcessorProvider.c2
-rw-r--r--src/hardware/dmidecode.c150
-rw-r--r--src/hardware/dmidecode.h29
-rw-r--r--src/hardware/lscpu.h1
-rw-r--r--src/hardware/procfs.c (renamed from src/hardware/cpuinfo.c)32
-rw-r--r--src/hardware/procfs.h (renamed from src/hardware/cpuinfo.h)13
-rw-r--r--src/hardware/sysfs.h1
-rw-r--r--src/openlmi.c (renamed from src/globals.c)69
-rw-r--r--src/openlmi.h80
-rw-r--r--src/openlmi.pc.in10
21 files changed, 750 insertions, 41 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 230ed26..b42debc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,3 +39,4 @@ install(PROGRAMS openlmi-register-pegasus DESTINATION libexec)
install(FILES cmake/modules/OpenLMIMacros.cmake DESTINATION share/cmake/Modules)
install(FILES cmake/modules/FindCMPI.cmake DESTINATION share/cmake/Modules)
install(FILES cmake/modules/FindKonkretCMPI.cmake DESTINATION share/cmake/Modules)
+install(FILES cmake/modules/FindOpenLMI.cmake DESTINATION share/cmake/Modules)
diff --git a/cmake/modules/FindOpenLMI.cmake b/cmake/modules/FindOpenLMI.cmake
new file mode 100644
index 0000000..d4338ca
--- /dev/null
+++ b/cmake/modules/FindOpenLMI.cmake
@@ -0,0 +1,21 @@
+
+find_path(OPENLMI_INCLUDE_DIR
+ NAMES openlmi.h
+ HINTS $ENV{OPENLMI_INCLUDE_DIR}
+ PATH_SUFFIXES include/openlmi
+ PATHS /usr /usr/local
+)
+
+find_library(OPENLMICOMMON_LIBRARY
+ NAMES openlmicommon
+ HINTS $ENV{OPENLMI_LIB_DIR}
+ PATH_SUFFIXES lib64 lib
+ PATHS /usr /usr/local
+)
+
+set(OPENLMI_LIBRARIES ${OPENLMICOMMON_LIBRARY})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(OPENLMI DEFAULT_MSG OPENLMI_LIBRARIES OPENLMI_INCLUDE_DIR)
+
+mark_as_advanced(OPENLMI_INCLUDE_DIR OPENLMI_LIBRARIES)
diff --git a/mof/LMI_Hardware.mof b/mof/LMI_Hardware.mof
index 0964291..3ceb886 100644
--- a/mof/LMI_Hardware.mof
+++ b/mof/LMI_Hardware.mof
@@ -19,6 +19,10 @@
* Peter Schiffer <pschiffe@redhat.com>
*/
+/******************************************************************************
+ * Processor
+ */
+
[ Provider("cmpi:cmpiLMI_Processor") ]
class LMI_Processor: CIM_Processor
{
@@ -158,6 +162,19 @@ class LMI_ProcessorChipRealizes: CIM_Realizes
LMI_Processor REF Dependent;
};
+/******************************************************************************
+ * Memory
+ */
+
+[ Provider("cmpi:cmpiLMI_Memory") ]
+class LMI_Memory: CIM_Memory
+{
+};
+
+/******************************************************************************
+ * PCI Devices
+ */
+
[ Provider("cmpi:cmpiLMI_PCIDevice") ]
class LMI_PCIDevice: CIM_PCIDevice
{
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7318911..6bf4b85 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,13 +1,21 @@
-include_directories(.)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMPI_INCLUDE_DIR})
add_library(openlmicommon SHARED
- globals.c
+ openlmi.c
)
-set_target_properties(openlmicommon PROPERTIES SOVERSION 0.0.1)
+set(OPENLMICOMMON_VERSION_MAJOR 0)
+set(OPENLMICOMMON_VERSION_MINOR 0)
+set(OPENLMICOMMON_VERSION_PATCH 1)
+set(OPENLMICOMMON_VERSION "${OPENLMICOMMON_VERSION_MAJOR}.${OPENLMICOMMON_VERSION_MINOR}.${OPENLMICOMMON_VERSION_PATCH}")
+
+set_target_properties(openlmicommon PROPERTIES VERSION ${OPENLMICOMMON_VERSION})
+set_target_properties(openlmicommon PROPERTIES SOVERSION ${OPENLMICOMMON_VERSION_MAJOR})
install(TARGETS openlmicommon DESTINATION lib${LIB_SUFFIX})
-install(FILES globals.h DESTINATION include/openlmi)
+install(FILES openlmi.h DESTINATION include/openlmi)
+configure_file(openlmi.pc.in openlmi.pc @ONLY)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/openlmi.pc DESTINATION lib${LIB_SUFFIX}/pkgconfig)
if (WITH-FAN)
add_subdirectory(fan)
diff --git a/src/fan/LMI_FanAssociatedSensorProvider.c b/src/fan/LMI_FanAssociatedSensorProvider.c
index d75bf5c..b462e83 100644
--- a/src/fan/LMI_FanAssociatedSensorProvider.c
+++ b/src/fan/LMI_FanAssociatedSensorProvider.c
@@ -21,7 +21,7 @@
#include <konkret/konkret.h>
#include "LMI_FanAssociatedSensor.h"
#include "fan.h"
-#include <globals.h>
+#include "globals.h"
static const CMPIBroker* _cb;
diff --git a/src/fan/LMI_FanSensorProvider.c b/src/fan/LMI_FanSensorProvider.c
index 47bd9d5..e63d266 100644
--- a/src/fan/LMI_FanSensorProvider.c
+++ b/src/fan/LMI_FanSensorProvider.c
@@ -22,7 +22,7 @@
#include <konkret/konkret.h>
#include "LMI_FanSensor.h"
#include "fan.h"
-#include <globals.h>
+#include "globals.h"
static const CMPIBroker* _cb = NULL;
diff --git a/src/globals.h b/src/globals.h
index a1cb18c..094602f 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -21,19 +21,16 @@
#ifndef GLOBALS_H
#define GLOBALS_H
-const char *get_system_name();
+#include "openlmi.h"
-const char *get_system_creation_class_name();
-
-int log_level(void);
-void set_log_level(int level);
-
-enum { NONE=0, ERROR, WARN, DEBUG };
-void _debug(int level, const char *file, int line, const char *format, ...);
-#define debug(...) _debug(DEBUG, __FILE__, __LINE__, __VA_ARGS__)
-#define warn(...) _debug(WARN, __FILE__, __LINE__, __VA_ARGS__)
-#define error(...) _debug(ERROR, __FILE__, __LINE__, __VA_ARGS__)
+// Shortcuts for functions and macros from openlmicommon library
+#define get_system_creation_class_name lmi_get_system_creation_class_name
+#define get_system_name lmi_get_system_name
+#define debug lmi_debug
+#define warn lmi_warn
+#define error lmi_error
#define ORGID "LMI"
+
#endif
diff --git a/src/hardware/CMakeLists.txt b/src/hardware/CMakeLists.txt
index 3949a8a..c50acef 100644
--- a/src/hardware/CMakeLists.txt
+++ b/src/hardware/CMakeLists.txt
@@ -6,7 +6,7 @@ set(provider_SRCS
utils.c
dmidecode.c
lscpu.c
- cpuinfo.c
+ procfs.c
sysfs.c
LMI_ProcessorProvider.c
LMI_ProcessorCapabilitiesProvider.c
diff --git a/src/hardware/LMI_Hardware.h b/src/hardware/LMI_Hardware.h
index 1f30be6..19a8ff7 100644
--- a/src/hardware/LMI_Hardware.h
+++ b/src/hardware/LMI_Hardware.h
@@ -28,5 +28,6 @@
#define CPU_CAP_CLASS_NAME "ProcessorCapabilities"
#define CPU_CACHE_CLASS_NAME "ProcessorCacheMemory"
#define CPU_CHIP_CLASS_NAME "ProcessorChip"
+#define MEM_CLASS_NAME "Memory"
#endif /* LMI_HARDWARE_H_ */
diff --git a/src/hardware/LMI_MemoryProvider.c b/src/hardware/LMI_MemoryProvider.c
new file mode 100644
index 0000000..6c9a2ec
--- /dev/null
+++ b/src/hardware/LMI_MemoryProvider.c
@@ -0,0 +1,322 @@
+/*
+ * 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_Memory.h"
+#include "LMI_Hardware.h"
+#include "globals.h"
+#include "dmidecode.h"
+#include "procfs.h"
+
+static const CMPIBroker* _cb = NULL;
+
+static void LMI_MemoryInitialize()
+{
+}
+
+static CMPIStatus LMI_MemoryCleanup(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_MemoryEnumInstanceNames(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ return KDefaultEnumerateInstanceNames(
+ _cb, mi, cc, cr, cop);
+}
+
+static CMPIStatus LMI_MemoryEnumInstances(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char** properties)
+{
+ LMI_Memory lmi_mem;
+ const char *ns = KNameSpace(cop), *name = "System Memory";
+ char *error_msg = NULL;
+ unsigned long fallback_memory_size = 0;
+ DmiMemory dmi_memory;
+
+ if (dmi_get_memory(&dmi_memory) != 0) {
+ fallback_memory_size = meminfo_get_memory_size();
+ if (!fallback_memory_size) {
+ error_msg = "Unable to get memory information.";
+ goto done;
+ }
+ }
+
+ LMI_Memory_Init(&lmi_mem, _cb, ns);
+
+ LMI_Memory_Set_SystemCreationClassName(&lmi_mem,
+ get_system_creation_class_name());
+ LMI_Memory_Set_SystemName(&lmi_mem, get_system_name());
+ LMI_Memory_Set_CreationClassName(&lmi_mem, ORGID "_" MEM_CLASS_NAME);
+
+ LMI_Memory_Set_DeviceID(&lmi_mem, "0");
+ LMI_Memory_Set_Volatile(&lmi_mem, 1);
+ LMI_Memory_Set_Access(&lmi_mem, LMI_Memory_Access_Read_Write_Supported);
+ LMI_Memory_Set_BlockSize(&lmi_mem, 1);
+ LMI_Memory_Set_EnabledState(&lmi_mem, LMI_Memory_EnabledState_Enabled);
+ LMI_Memory_Init_OperationalStatus(&lmi_mem, 1);
+ LMI_Memory_Set_OperationalStatus(&lmi_mem, 0,
+ LMI_Memory_OperationalStatus_Unknown);
+ LMI_Memory_Set_HealthState(&lmi_mem, LMI_Memory_HealthState_Unknown);
+ LMI_Memory_Set_ElementName(&lmi_mem, name);
+ LMI_Memory_Set_Caption(&lmi_mem, name);
+ 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_IsCompressed(&lmi_mem, 0);
+ LMI_Memory_Set_Purpose(&lmi_mem, "The system memory is temporary storage "
+ "area storing instructions and data required by processor "
+ "to run programs.");
+
+ if (!fallback_memory_size) {
+ LMI_Memory_Set_NumberOfBlocks(&lmi_mem, dmi_memory.physical_size);
+ LMI_Memory_Set_ConsumableBlocks(&lmi_mem, dmi_memory.available_size);
+ LMI_Memory_Set_StartingAddress(&lmi_mem, dmi_memory.start_addr);
+ LMI_Memory_Set_EndingAddress(&lmi_mem, dmi_memory.end_addr);
+ } else {
+ LMI_Memory_Set_NumberOfBlocks(&lmi_mem, fallback_memory_size);
+ }
+
+ KReturnInstance(cr, lmi_mem);
+
+done:
+ dmi_free_memory(&dmi_memory);
+
+ if (error_msg) {
+ KReturn2(_cb, ERR_FAILED, error_msg);
+ }
+
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_MemoryGetInstance(
+ 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_MemoryCreateInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const CMPIInstance* ci)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_MemoryModifyInstance(
+ 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_MemoryDeleteInstance(
+ CMPIInstanceMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop)
+{
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static CMPIStatus LMI_MemoryExecQuery(
+ 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_Memory,
+ LMI_Memory,
+ _cb,
+ LMI_MemoryInitialize())
+
+static CMPIStatus LMI_MemoryMethodCleanup(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ CMPIBoolean term)
+{
+ CMReturn(CMPI_RC_OK);
+}
+
+static CMPIStatus LMI_MemoryInvokeMethod(
+ CMPIMethodMI* mi,
+ const CMPIContext* cc,
+ const CMPIResult* cr,
+ const CMPIObjectPath* cop,
+ const char* meth,
+ const CMPIArgs* in,
+ CMPIArgs* out)
+{
+ return LMI_Memory_DispatchMethod(
+ _cb, mi, cc, cr, cop, meth, in, out);
+}
+
+CMMethodMIStub(
+ LMI_Memory,
+ LMI_Memory,
+ _cb,
+ LMI_MemoryInitialize())
+
+KUint32 LMI_Memory_RequestStateChange(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_MemoryRef* self,
+ const KUint16* RequestedState,
+ KRef* Job,
+ const KDateTime* TimeoutPeriod,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_Memory_SetPowerState(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_MemoryRef* self,
+ const KUint16* PowerState,
+ const KDateTime* Time,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_Memory_Reset(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_MemoryRef* self,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_Memory_EnableDevice(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_MemoryRef* self,
+ const KBoolean* Enabled,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_Memory_OnlineDevice(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_MemoryRef* self,
+ const KBoolean* Online,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_Memory_QuiesceDevice(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_MemoryRef* self,
+ const KBoolean* Quiesce,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_Memory_SaveProperties(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_MemoryRef* self,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KUint32 LMI_Memory_RestoreProperties(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_MemoryRef* self,
+ CMPIStatus* status)
+{
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, ERR_NOT_SUPPORTED);
+ return result;
+}
+
+KONKRET_REGISTRATION(
+ "root/cimv2",
+ "LMI_Memory",
+ "LMI_Memory",
+ "instance method")
diff --git a/src/hardware/LMI_ProcessorCacheMemoryProvider.c b/src/hardware/LMI_ProcessorCacheMemoryProvider.c
index afc5d7f..030ddd1 100644
--- a/src/hardware/LMI_ProcessorCacheMemoryProvider.c
+++ b/src/hardware/LMI_ProcessorCacheMemoryProvider.c
@@ -98,6 +98,7 @@ static CMPIStatus LMI_ProcessorCacheMemoryEnumInstances(
ORGID "_" CPU_CACHE_CLASS_NAME);
LMI_ProcessorCacheMemory_Set_BlockSize(&lmi_cpu_cache, 1);
+ LMI_ProcessorCacheMemory_Set_Volatile(&lmi_cpu_cache, 1);
LMI_ProcessorCacheMemory_Set_HealthState(&lmi_cpu_cache,
LMI_ProcessorCacheMemory_HealthState_Unknown);
LMI_ProcessorCacheMemory_Init_OperationalStatus(&lmi_cpu_cache, 1);
diff --git a/src/hardware/LMI_ProcessorProvider.c b/src/hardware/LMI_ProcessorProvider.c
index 99b0fad..c14b105 100644
--- a/src/hardware/LMI_ProcessorProvider.c
+++ b/src/hardware/LMI_ProcessorProvider.c
@@ -27,7 +27,7 @@
#include "globals.h"
#include "dmidecode.h"
#include "lscpu.h"
-#include "cpuinfo.h"
+#include "procfs.h"
CMPIUint16 get_family(const char *family);
CMPIUint16 get_cpustatus(const char *status);
diff --git a/src/hardware/dmidecode.c b/src/hardware/dmidecode.c
index 348c7a2..367a08c 100644
--- a/src/hardware/dmidecode.c
+++ b/src/hardware/dmidecode.c
@@ -692,3 +692,153 @@ void dmi_free_cpu_caches(DmiCpuCache **caches, unsigned *caches_nb)
*caches_nb = 0;
*caches = NULL;
}
+
+
+/******************************************************************************
+ * DmiMemory
+ */
+
+/*
+ * Initialize DmiMemory attributes.
+ * @param memory
+ */
+void init_dmi_memory_struct(DmiMemory *memory)
+{
+ memory->physical_size = 0;
+ memory->available_size = 0;
+ memory->start_addr = 0;
+ memory->end_addr = 0;
+ memory->modules = NULL;
+ memory->modules_nb = 0;
+}
+
+/*
+ * Initialize DmiMemoryModule attributes.
+ * @param mem
+ */
+void init_dmi_memory_module_struct(DmiMemoryModule *mem)
+{
+ mem->size = 0;
+}
+
+short dmi_get_memory(DmiMemory *memory)
+{
+ short ret = -1;
+ int curr_mem = -1;
+ unsigned i, buffer_size = 0;
+ char **buffer = NULL, *buf;
+
+ init_dmi_memory_struct(memory);
+
+ /* get dmidecode output for memory modules */
+ if (run_command("dmidecode -t 17", &buffer, &buffer_size) != 0) {
+ ret = -2;
+ goto done;
+ }
+
+ /* count modules */
+ for (i = 0; i < buffer_size; i++) {
+ if (strstr(buffer[i], "Size: ") &&
+ !strstr(buffer[i], "Size: No Module Installed")) {
+ memory->modules_nb++;
+ }
+ }
+
+ /* if no module was found */
+ if (memory->modules_nb < 1) {
+ warn("Dmidecode didn't recognize any memory module.");
+ ret = -3;
+ goto done;
+ }
+
+ /* allocate memory for modules */
+ memory->modules = (DmiMemoryModule *)calloc(memory->modules_nb, sizeof(DmiMemoryModule));
+ if (!memory->modules) {
+ warn("Failed to allocate memory.");
+ ret = -4;
+ goto done;
+ }
+
+ /* 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]);
+
+ /* 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;
+ }
+
+ continue;
+ }
+ /* ignore first useless lines */
+ if (curr_mem < 0) {
+ continue;
+ }
+ }
+
+ free_2d_buffer(&buffer, &buffer_size);
+
+ /* get dmidecode output for memory array */
+ if (run_command("dmidecode -t 19", &buffer, &buffer_size) != 0) {
+ ret = -5;
+ goto done;
+ }
+
+ /* parse information about memory array */
+ short first_array = 1;
+ unsigned long start_addr, end_addr;
+ for (i = 0; i < buffer_size; i++) {
+ /* Starting Address */
+ buf = copy_string_part_after_delim(buffer[i], "Starting Address: ");
+ if (buf) {
+ sscanf(buf, "%lx", &start_addr);
+ if (first_array || start_addr < memory->start_addr) {
+ memory->start_addr = start_addr / 1024; /* in Bytes, we want KB */
+ first_array = 0;
+ }
+ free(buf);
+ buf = NULL;
+ continue;
+ }
+ /* Ending Address */
+ buf = copy_string_part_after_delim(buffer[i], "Ending Address: ");
+ if (buf) {
+ sscanf(buf, "%lx", &end_addr);
+ if (end_addr > memory->end_addr) {
+ memory->end_addr = end_addr / 1024; /* in Bytes, we want KB */
+ }
+ memory->available_size += end_addr - start_addr;
+ free(buf);
+ buf = NULL;
+ continue;
+ }
+ }
+
+ ret = 0;
+
+done:
+ free_2d_buffer(&buffer, &buffer_size);
+
+ if (ret != 0) {
+ dmi_free_memory(memory);
+ }
+
+ return ret;
+}
+
+void dmi_free_memory(DmiMemory *memory)
+{
+ if (memory->modules_nb > 0) {
+ free (memory->modules);
+ }
+ memory->modules_nb = 0;
+ memory->modules = NULL;
+}
diff --git a/src/hardware/dmidecode.h b/src/hardware/dmidecode.h
index 9190ea4..d3320ea 100644
--- a/src/hardware/dmidecode.h
+++ b/src/hardware/dmidecode.h
@@ -24,7 +24,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "globals.h"
#include "utils.h"
@@ -65,6 +64,20 @@ typedef struct _DmiCpuCache {
char *associativity; /* Cache Associativity */
} DmiCpuCache;
+/* Memory module from dmidecode. */
+typedef struct _DmiMemoryModule {
+ unsigned long size; /* Memory Module Size in Bytes */
+} DmiMemoryModule;
+
+/* Memory from dmidecode. */
+typedef struct _DmiMemory {
+ unsigned long physical_size; /* Physical Memory Size in Bytes */
+ unsigned long available_size; /* Available Memory Size in Bytes */
+ unsigned long start_addr; /* Starting Address of Memory Array in KB */
+ unsigned long end_addr; /* Ending Address of Memory Array in KB */
+ DmiMemoryModule *modules; /* Memory Modules */
+ unsigned modules_nb; /* Number of Memory Modules */
+} DmiMemory;
/*
* Get array of processors according to the dmidecode program.
@@ -98,5 +111,19 @@ short dmi_get_cpu_caches(DmiCpuCache **caches, unsigned *caches_nb);
*/
void dmi_free_cpu_caches(DmiCpuCache **caches, unsigned *caches_nb);
+/*
+ * Get memory structure according to the dmidecode program.
+ * @param memory structure, this function will allocate
+ * necessary memory, but caller is responsible for freeing it
+ * @return 0 if success, negative value otherwise
+ */
+short dmi_get_memory(DmiMemory *memory);
+
+/*
+ * Free memory structure.
+ * @param memory structure
+ */
+void dmi_free_memory(DmiMemory *memory);
+
#endif /* DMIDECODE_H_ */
diff --git a/src/hardware/lscpu.h b/src/hardware/lscpu.h
index 5dc5bd5..39c85b6 100644
--- a/src/hardware/lscpu.h
+++ b/src/hardware/lscpu.h
@@ -24,7 +24,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "globals.h"
#include "utils.h"
diff --git a/src/hardware/cpuinfo.c b/src/hardware/procfs.c
index 6634b05..288c8a9 100644
--- a/src/hardware/cpuinfo.c
+++ b/src/hardware/procfs.c
@@ -18,7 +18,7 @@
* Authors: Peter Schiffer <pschiffe@redhat.com>
*/
-#include "cpuinfo.h"
+#include "procfs.h"
/*
@@ -140,3 +140,33 @@ void cpuinfo_free_processor(CpuinfoProcessor *cpu)
return;
}
+
+unsigned long meminfo_get_memory_size()
+{
+ unsigned long ret = 0;
+ unsigned i, buffer_size = 0;
+ char **buffer = NULL, *buf;
+
+ /* read /proc/meminfo file */
+ if (read_file("/proc/meminfo", &buffer, &buffer_size) != 0) {
+ goto done;
+ }
+
+ /* read memory size */
+ for (i = 0; i < buffer_size; i++) {
+ /* memory size */
+ buf = copy_string_part_after_delim(buffer[i], "MemTotal:");
+ if (buf) {
+ sscanf(buf, "%lu", &ret);
+ ret *= 1024; /* it's in kB, we want B */
+ free(buf);
+ buf = NULL;
+ break;
+ }
+ }
+
+done:
+ free_2d_buffer(&buffer, &buffer_size);
+
+ return ret;
+}
diff --git a/src/hardware/cpuinfo.h b/src/hardware/procfs.h
index 5ec5dd5..3545398 100644
--- a/src/hardware/cpuinfo.h
+++ b/src/hardware/procfs.h
@@ -18,13 +18,12 @@
* Authors: Peter Schiffer <pschiffe@redhat.com>
*/
-#ifndef CPUINFO_H_
-#define CPUINFO_H_
+#ifndef PROCFS_H_
+#define PROCFS_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "globals.h"
#include "utils.h"
@@ -50,5 +49,11 @@ short cpuinfo_get_processor(CpuinfoProcessor *cpu);
*/
void cpuinfo_free_processor(CpuinfoProcessor *cpu);
+/*
+ * Get total memory from /proc/meminfo file.
+ * @return memory size or 0 in case of a problem
+ */
+unsigned long meminfo_get_memory_size();
+
-#endif /* CPUINFO_H_ */
+#endif /* PROCFS_H_ */
diff --git a/src/hardware/sysfs.h b/src/hardware/sysfs.h
index 0e0b523..028b559 100644
--- a/src/hardware/sysfs.h
+++ b/src/hardware/sysfs.h
@@ -27,7 +27,6 @@
#include <dirent.h>
#include <errno.h>
#include <limits.h>
-#include "globals.h"
#include "utils.h"
#define SYSFS_CPU_PATH "/sys/devices/system/cpu"
diff --git a/src/globals.c b/src/openlmi.c
index 7e58817..786bdd2 100644
--- a/src/globals.c
+++ b/src/openlmi.c
@@ -18,7 +18,7 @@
* Authors: Radek Novacek <rnovacek@redhat.com>
*/
-#include "globals.h"
+#include "openlmi.h"
#include <stdlib.h>
#include <stdarg.h>
@@ -27,11 +27,14 @@
#include <string.h>
#include <netdb.h>
#include <stdio.h>
+#include <cmpimacs.h>
static char *_fqdn = NULL;
-static int _log_level = DEBUG;
+static int _log_level = _LMI_DEBUG_DEBUG;
+static const CMPIBroker *_cb = NULL;
+static char *_log_id = NULL;
-char *getFQDN(void)
+static char *getFQDN(void)
{
struct utsname uts;
if ((uname(&uts) > 0) && (uts.nodename != NULL)) {
@@ -66,7 +69,7 @@ char *getFQDN(void)
return strdup(hostname);
}
-const char *get_system_name()
+const char *lmi_get_system_name()
{
if (_fqdn == NULL) {
_fqdn = getFQDN();
@@ -74,25 +77,63 @@ const char *get_system_name()
return _fqdn;
}
-const char *get_system_creation_class_name()
+const char *lmi_get_system_creation_class_name()
{
return "Linux_ComputerSystem";
}
-void _debug(int level, const char *file, int line, const char *format, ...)
+void lmi_init_logging(const char *log_id, const CMPIBroker *cb)
{
- if (level > _log_level) {
- return;
+ if (_log_id != NULL) {
+ free(_log_id);
+ }
+ _log_id = strdup(log_id);
+ _cb = cb;
+}
+
+int lmi_log_level(void)
+{
+ return _log_level;
+}
+
+void lmi_set_log_level(int level)
+{
+ _log_level = level;
+}
+
+void _lmi_debug(int level, const char *file, int line, const char *format, ...)
+{
+ const char *lvl[] = { "NONE", "ERROR", "INFO", "WARNING", "DEBUG" };
+ if (level > 4) {
+ level = 4;
+ }
+ if (level < 1) {
+ level = 1;
}
- FILE *trace_file = stderr;
- const char *lvl[] = { "NONE", "ERROR", "WARNING", "DEBUG" };
- // TODO: use logger from sfcbd and pegasus
- fprintf(trace_file, "[%s] %s:%d\t", lvl[level], file, line);
+ char *message, *text;
va_list args;
va_start(args, format);
- vfprintf(stderr, format, args);
+ vasprintf(&message, format, args);
va_end(args);
+ asprintf(&text, "[%s] %s:%d\t%s", lvl[level], file, line, message);
+ free(message);
+
+ CMPIStatus rc;
+ rc.rc = CMPI_RC_OK;
+ if (_cb != NULL) {
+ // try to use standard CMPI logging
+ rc = _cb->eft->trace(_cb, CMPI_LEV_INFO, _log_id, text, NULL);
+ }
+
+ if (_cb == NULL || rc.rc != CMPI_RC_OK) {
+ // Fallback to stderr
+ if (level > _log_level) {
+ free(text);
+ return;
+ }
- fprintf(stderr, "\n");
+ fprintf(stderr, "%s\n", text);
+ }
+ free(text);
}
diff --git a/src/openlmi.h b/src/openlmi.h
new file mode 100644
index 0000000..9b27d07
--- /dev/null
+++ b/src/openlmi.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2012-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: Radek Novacek <rnovacek@redhat.com>
+ */
+
+#ifndef OPENLMI_H
+#define OPENLMI_H
+
+#include <cmpidt.h>
+
+/**
+ * This function returns FQDN (fully qualified domain name) of the machine
+ *
+ * @note Use this in the SystemName property of all provider created instances.
+ *
+ * @return The scoping System's Name.
+ */
+const char *lmi_get_system_name();
+
+/**
+ * This function returns system creation class name
+ *
+ * @note Use this in the SystemCreationClassName property of all provider
+ * created instances.
+ *
+ * @return The scoping System's Creation class name.
+ */
+const char *lmi_get_system_creation_class_name();
+
+/**
+ * To use standard CIMOM logging facility, broker must be assigned. Without
+ * calling this function, logging will go to stderr.
+ *
+ * \p log_id Identification of log messages
+ * \p cb CMPIBroker
+ */
+void lmi_init_logging(const char *log_id, const CMPIBroker *cb);
+
+/**
+ * Get currently set logging level
+ *
+ * @return logging level
+ */
+int lmi_log_level(void);
+
+/**
+ * Set logging level
+ *
+ * @param level new logging level
+ */
+void lmi_set_log_level(int level);
+
+enum {
+ _LMI_DEBUG_NONE=0, _LMI_DEBUG_ERROR, _LMI_DEBUG_WARN,
+ _LMI_DEBUG_INFO, _LMI_DEBUG_DEBUG
+};
+
+void _lmi_debug(int level, const char *file, int line, const char *format, ...);
+
+#define lmi_debug(...) _lmi_debug(_LMI_DEBUG_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
+#define lmi_info(...) _lmi_debug(_LMI_DEBUG_INFO, __FILE__, __LINE__, __VA_ARGS__)
+#define lmi_warn(...) _lmi_debug(_LMI_DEBUG_WARN, __FILE__, __LINE__, __VA_ARGS__)
+#define lmi_error(...) _lmi_debug(_LMI_DEBUG_ERROR, __FILE__, __LINE__, __VA_ARGS__)
+
+#endif
diff --git a/src/openlmi.pc.in b/src/openlmi.pc.in
new file mode 100644
index 0000000..939d672
--- /dev/null
+++ b/src/openlmi.pc.in
@@ -0,0 +1,10 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=${prefix}
+includedir=${prefix}/include
+libdir=${exec_prefix}/lib@LIB_SUFFIX@
+
+Name: openlmi
+Description: OpenLMI provider support
+Version: @OPENLMICOMMON_VERSION@
+Libs: -L${libdir} -lopenlmicommon
+CFlags: -I${includedir}/openlmi