File sblim-gather-2.2.8-drop-libsysfs.patch of Package sblim-gather.18126
Index: sblim-gather-2.2.8/Makefile.am
===================================================================
--- sblim-gather-2.2.8.orig/Makefile.am
+++ sblim-gather-2.2.8/Makefile.am
@@ -354,7 +354,6 @@ hyptest_LDADD = libhypfs.la
channelclt_SOURCES = plugin/channelclt.c
channelclt_LDADD = libchannelutil.la libsysfswrapper.la
-channelclt_LDFLAGS = -lsysfs
# Gather init scripts
EXTRA_DIST += gatherer.init-suse.in gatherer.init-redhat.in \
Index: sblim-gather-2.2.8/configure.ac
===================================================================
--- sblim-gather-2.2.8.orig/configure.ac
+++ sblim-gather-2.2.8/configure.ac
@@ -63,10 +63,6 @@ AC_ARG_VAR([CIMSERVER],[the target CIM s
AC_CHECK_LIB([pthread], [pthread_create], [ GATHERLIBS="-lpthread" ])
AC_CHECK_LIB([dl], [dlopen], [ GATHERLIBS="-ldl $GATHERLIBS" ])
-if test "$enable_z" == "yes"; then
- AC_CHECK_LIB([sysfs], [sysfs_open_driver], [ ZHYPLIBS="-lsysfs" ], [AC_MSG_ERROR([Cannot find library -lsysfs. Is libsysfs installed?])])
-fi
-
if test "$enable_virt" == "yes"; then
AC_CHECK_HEADERS([libvirt/libvirt.h], [], [AC_MSG_ERROR([Cannot find header file <libvirt/libvirt.h>. Is libvirt-devel installed?])])
AC_CHECK_LIB([virt], [virConnectOpen], [ VIRTLIBS="-lvirt" ], [AC_MSG_ERROR([Cannot find library -lvirt. Is libvirt installed?])])
Index: sblim-gather-2.2.8/plugin/channelclt.c
===================================================================
--- sblim-gather-2.2.8.orig/plugin/channelclt.c
+++ sblim-gather-2.2.8/plugin/channelclt.c
@@ -11,117 +11,84 @@
* http://www.opensource.org/licenses/eclipse-1.0.php
*
* Author: Alexander Wolf-Reber <a.wolf-reber@de.ibm.com>
- * Contributors:
+ * Contributors:
*
* Description:
* system Z channel measurement command line tool
*
*/
-
-#include "sysfswrapper.h"
-#include "channelutil.h"
+
#include <stdio.h>
#include <unistd.h>
#include <string.h>
+#include "sysfswrapper.h"
+#include "channelutil.h"
const int true = (1==1);
-void showDevice(sysfsw_Device* device, size_t pos) {
-
- int i;
-
- printf("\ndevice %s\n", sysfsw_getDeviceName(device));
-
- sysfsw_Attribute* cmgAttr = sysfsw_openAttribute(device, "cmg");
- char* cmgVal = sysfsw_getAttributeValue(cmgAttr);
- int cmg = atoi(cmgVal);
- printf("cmg = %d\n", cmg);
- sysfsw_closeAttribute(cmgAttr);
+void showDevice(char *device, size_t pos) {
+ int i, cmg = 0;
+ char buff[256];
+ ssize_t len;
+
+ printf("\ndevice %s\n", device);
+
+ len = readSysfsAttr(device, "cmg", buff, 256);
+ if (len > 0) {
+ cmg = atoi(buff);
+ printf("cmg = %d\n", cmg);
+ }
- sysfsw_Attribute* mcAttr = sysfsw_openAttribute(device, "measurement_chars");
- char* mcVal = sysfsw_getAttributeValue(mcAttr);
+ len = readSysfsAttr(device, "measurement_chars", buff, 256);
+ if (len < 0)
+ return;
printf("measurement_chars = ");
- for (i=0; i<20; ++i) {
- printf("%02hx ", mcVal[i]);
+ for (i=0; i < (len > 20) ? 20 : len; ++i) {
+ printf("%02hx ", buff[i]);
}
printf("\n");
zChannelMeasurementCharacteristics cmc;
- parseCmc(cmg, mcVal, &cmc);
- sysfsw_closeAttribute(mcAttr);
+ parseCmc(cmg, buff, &cmc);
printChannelMeasurementCharacteristics(&cmc);
printf("\n");
- sysfsw_Attribute* measAttr = sysfsw_openAttribute(device, "measurement");
- char* measVal = sysfsw_getAttributeValue(measAttr);
-
+ len = readSysfsAttr(device, "measurement", buff, 256);
printf("measurement = ");
- for (i=0; i<32; ++i) {
- printf("%02hx ", measVal[i]);
+ for (i=0; i < (len > 32) ? 32 : len; ++i) {
+ printf("%02hx ", buff[i]);
}
printf("\n");
-
+
zChannelUtilization cu;
- parseCue(cmg, measVal, &cu);
- sysfsw_closeAttribute(measAttr);
+ parseCue(cmg, buff, &cu);
printChannelUtilization(&cu);
printf("\n");
-
- /* test code for stringify/destringify */
-/*
- char* cu_str = stringifyChannelUtilization(&cu);
- char* cmc_str = stringifyChannelMeasurementCharacteristics(&cmc);
- char* string = calloc(1, strlen(cu_str)+strlen(cmc_str)+2);
- strcpy( string, cu_str);
- strcat( string, "!");
- strcat( string, cmc_str);
-
- printf("%s\n", string);
-
- char* sep = strstr(string, "!");
- if (sep==NULL) return;
- zChannelUtilization dcu;
- zChannelMeasurementCharacteristics dcmc;
- destringifyChannelUtilization(string, &dcu);
- destringifyChannelMeasurementCharacteristics(++sep, &dcmc);
- printChannelUtilization(&dcu);
- printChannelMeasurementCharacteristics(&dcmc);
-
- destringifyChannelMeasurementCharacteristics(sep, NULL);
- printf("NULL\n");
-*/
}
-int filterDevice(sysfsw_Device* device) {
+int filterDevice(char * device) {
return true;
}
int main(int argc, char** argv) {
char * devicePath;
-
if (argc<2) {
printf("usage:\n\tchannelclt all | <chpid_path>\nexample:\n\tbtmtest /sys/devices/css0/chp0.41\n");
exit(1);
}
-
+
devicePath = argv[1];
printf("\nDisplay Channel Measurement Data\n");
-
if (strncmp(devicePath, "all", 3) == 0) {
size_t count = iterateChpids(showDevice, filterDevice);
printf("%zu chpids shown\n", count);
} else {
printf("%s\n", devicePath);
- sysfsw_Device* device = sysfsw_openDevice(devicePath);
- if (device!=NULL) {
- showDevice(device, 0);
- sysfsw_closeDevice(device);
- }
+ showDevice(devicePath, 0);
}
-
return 0;
}
Index: sblim-gather-2.2.8/plugin/channelutil.c
===================================================================
--- sblim-gather-2.2.8.orig/plugin/channelutil.c
+++ sblim-gather-2.2.8/plugin/channelutil.c
@@ -11,16 +11,18 @@
* http://www.opensource.org/licenses/eclipse-1.0.php
*
* Author: Alexander Wolf-Reber <a.wolf-reber@de.ibm.com>
- * Contributors:
+ * Contributors:
*
* Description:
* system Z channel measurement interface
*
*/
-
+
#include <stdio.h>
#include <unistd.h>
#include <string.h>
+#include <sys/types.h>
+#include <dirent.h>
#include "channelutil.h"
#define CSS0 "/sys/devices/css0"
@@ -303,21 +305,22 @@ zChannelMeasurementCharacteristics* dest
size_t iterateChpids(DeviceHandler handler, DeviceFilter filter) {
size_t count = 0;
- sysfsw_Device* rootDevice = sysfsw_openDeviceTree(CSS0);
- if (rootDevice!=NULL) {
- sysfsw_DeviceList* deviceList = sysfsw_getDeviceList(rootDevice);
- if (deviceList!=NULL) {
- sysfsw_startDeviceList(deviceList);
- while (sysfsw_nextDevice(deviceList)) {
- sysfsw_Device* device = sysfsw_getDevice(deviceList);
- if (strncmp(sysfsw_getDeviceName(device), "chp", 3) == 0) {
- if (filter(device)) {
- handler(device, count++);
- }
- }
- }
- }
- sysfsw_closeDeviceTree(rootDevice);
+ char devpath[256];
+ DIR *dirfd;
+ struct dirent *dent;
+
+ dirfd = opendir(CSS0);
+ if (!dirfd)
+ return 0;
+
+ while ((dent = readdir(dirfd)) != NULL) {
+ if (strncmp(dent->d_name, "chp", 3))
+ continue;
+ printf("Testing chpid %s\n", dent->d_name);
+ sprintf(devpath, "%s/%s", CSS0, dent->d_name);
+ if (filter(devpath))
+ handler(devpath, count++);
}
+ closedir(dirfd);
return count;
}
Index: sblim-gather-2.2.8/plugin/channelutil.h
===================================================================
--- sblim-gather-2.2.8.orig/plugin/channelutil.h
+++ sblim-gather-2.2.8/plugin/channelutil.h
@@ -11,7 +11,7 @@
* http://www.opensource.org/licenses/eclipse-1.0.php
*
* Author: Alexander Wolf-Reber <a.wolf-reber@de.ibm.com>
- * Contributors:
+ * Contributors:
*
* Description:
* system Z channel measurement interface
@@ -22,7 +22,6 @@
#define CHANNELUTIL_H_
#include <stdlib.h>
-#include "sysfswrapper.h"
typedef struct {
unsigned int cuiv_timestamp;
@@ -30,7 +29,7 @@ typedef struct {
unsigned int lpar_channel_path_busy_time;
} zCueBlock1;
-typedef struct {
+typedef struct {
unsigned int cuiv_timestamp;
unsigned int cpc_bus_cycles;
unsigned int cpc_channel_work_units;
@@ -69,7 +68,7 @@ void printChannelUtilization(zChannelUti
char* stringifyChannelUtilization(zChannelUtilization* cu);
zChannelUtilization* destringifyChannelUtilization(char* cu, zChannelUtilization* result);
-typedef struct {
+typedef struct {
unsigned int maximum_bus_cycles;
unsigned int maximum_channel_work_units;
unsigned int maximum_write_data_units;
@@ -98,8 +97,8 @@ void printChannelMeasurementCharacterist
char* stringifyChannelMeasurementCharacteristics(zChannelMeasurementCharacteristics* cmc);
zChannelMeasurementCharacteristics* destringifyChannelMeasurementCharacteristics(char* cmc, zChannelMeasurementCharacteristics* result);
-typedef void (DeviceHandler)(sysfsw_Device*, size_t);
-typedef int (DeviceFilter)(sysfsw_Device*);
+typedef void (DeviceHandler)(char*, size_t);
+typedef int (DeviceFilter)(char*);
size_t iterateChpids(DeviceHandler handler, DeviceFilter filter);
#endif /*CHANNELUTIL_H_*/
Index: sblim-gather-2.2.8/plugin/metriczCH.c
===================================================================
--- sblim-gather-2.2.8.orig/plugin/metriczCH.c
+++ sblim-gather-2.2.8/plugin/metriczCH.c
@@ -11,7 +11,7 @@
* http://www.opensource.org/licenses/eclipse-1.0.php
*
* Author: Alexander Wolf-Reber <a.wolf-reber@de.ibm.com>
- * Contributors:
+ * Contributors:
*
* Description:
* Metrics Gatherer Plugin for System z channel metrics
@@ -23,7 +23,7 @@
#include <mplugin.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
+#include <string.h>
#include <time.h>
#include <unistd.h>
#include <commutil.h>
@@ -34,7 +34,7 @@
#ifdef DEBUG
#define DBGONLY(X) X
#else
-#define DBGONLY(X)
+#define DBGONLY(X)
#endif
#define MAX_PATH_LENGTH 255
@@ -92,28 +92,26 @@ int _DefinedMetrics( MetricRegisterId *m
int _StartStopMetrics (int starting) {
if( starting ) {
- DBGONLY(fprintf(stderr,"--- %s(%i) : Metric processing starting\n",
- __FILE__,__LINE__);)
- deviceCount = 0;
- deviceList = calloc(MAX_CHPID_COUNT, MAX_PATH_LENGTH+1);
- pthread_mutex_init(&mutex, NULL);
- }
- else {
- DBGONLY(fprintf(stderr,"--- %s(%i) : Metric processing stopping\n",
- __FILE__,__LINE__);)
- deviceCount = 0;
- free(deviceList);
- deviceList = NULL;
- pthread_mutex_destroy(&mutex);
+ DBGONLY(fprintf(stderr,"--- %s(%i) : Metric processing starting\n",
+ __FILE__,__LINE__);)
+ deviceCount = 0;
+ deviceList = calloc(MAX_CHPID_COUNT, MAX_PATH_LENGTH+1);
+ pthread_mutex_init(&mutex, NULL);
+ } else {
+ DBGONLY(fprintf(stderr,"--- %s(%i) : Metric processing stopping\n",
+ __FILE__,__LINE__);)
+ deviceCount = 0;
+ free(deviceList);
+ deviceList = NULL;
+ pthread_mutex_destroy(&mutex);
}
-
+
return 0;
}
int sendMetric(int mid, MetricReturner mret, char* resourcepath, char* cue_values, char* cmc_values) {
-
MetricValue * mv = NULL;
-
+
if (mret==NULL) { fprintf(stderr,"Returner pointer is NULL\n"); return -1; }
char* resource = strrchr(resourcepath, '/') + 1;
@@ -140,44 +138,47 @@ int sendMetric(int mid, MetricReturner m
}
zChannelUtilization* readCue(char* devicePath, zChannelUtilization* cu) {
+ char measVal[256];
+ ssize_t len;
+
if (devicePath==NULL || cu==NULL) return NULL;
- sysfsw_Attribute* measAttr = sysfsw_openAttributePath(devicePath, "measurement");
- if (measAttr==NULL) return NULL;
-
- char* measVal = sysfsw_getAttributeValue(measAttr);
+ len = readSysfsAttr(devicePath, "measurement", measVal, 256);
+ if (len < 1) return NULL;
+
parseCue(2, measVal, cu);
- sysfsw_closeAttribute(measAttr);
return cu;
}
-zChannelMeasurementCharacteristics* readCmc(char* devicePath, zChannelMeasurementCharacteristics* cmc) {
+zChannelMeasurementCharacteristics* readCmc(char* devicePath,
+ zChannelMeasurementCharacteristics* cmc) {
+ char mcVal[256];
+ ssize_t len;
+
if (devicePath==NULL || cmc==NULL) return NULL;
- sysfsw_Attribute* mcAttr = sysfsw_openAttributePath(devicePath, "measurement_chars");
- if (mcAttr==NULL) return NULL;
-
- char* mcVal = sysfsw_getAttributeValue(mcAttr);
+ len = readSysfsAttr(devicePath, "measurement_chars", mcVal, 256);
+ if (len < 1) return NULL;
+
parseCmc(2, mcVal, cmc);
- sysfsw_closeAttribute(mcAttr);
return cmc;
}
-void updateDeviceList(sysfsw_Device* device, size_t pos) {
+void updateDeviceList(char * device, size_t pos) {
if (pos<MAX_CHPID_COUNT) {
- strncpy(deviceList+pos*(MAX_PATH_LENGTH+1), sysfsw_getDevicePath(device), MAX_PATH_LENGTH);
+ strncpy(deviceList+pos*(MAX_PATH_LENGTH+1),
+ device, MAX_PATH_LENGTH);
}
}
-int filterDevices(sysfsw_Device* device) {
- sysfsw_Attribute* cmgAttr = sysfsw_openAttribute(device, "cmg");
- if (cmgAttr==NULL) return false;
-
- char* cmgVal = sysfsw_getAttributeValue(cmgAttr);
- int cmg = atoi(cmgVal);
- sysfsw_closeAttribute(cmgAttr);
-
- return (cmg == 2);
+int filterDevices(char * device) {
+ char cmgVal[256];
+ ssize_t len;
+
+ len = readSysfsAttr(device, "cmg", cmgVal, 256);
+ if (len < 1) return false;
+
+ return (atoi(cmgVal) == 2);
}
int refreshDeviceList() {
@@ -192,13 +193,11 @@ int refreshDeviceList() {
return false;
}
-int metricRetrCUE( int mid,
- MetricReturner mret ) {
-
+int metricRetrCUE( int mid, MetricReturner mret ) {
size_t i, count;
-
+
if (!refreshDeviceList()) return 0;
-
+
for (count=0, i=0; i<deviceCount; ++i) {
zChannelUtilization cu;
zChannelMeasurementCharacteristics cmc;
Index: sblim-gather-2.2.8/plugin/metriczECKD.c
===================================================================
--- sblim-gather-2.2.8.orig/plugin/metriczECKD.c
+++ sblim-gather-2.2.8/plugin/metriczECKD.c
@@ -11,7 +11,7 @@
* http://www.opensource.org/licenses/eclipse-1.0.php
*
* Author: Alexander Wolf-Reber <a.wolf-reber@de.ibm.com>
- * Contributors:
+ * Contributors:
*
* Description:
* Metrics Gatherer Plugin for System z ECKD volume metrics
@@ -23,10 +23,12 @@
#include <mplugin.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
+#include <string.h>
#include <time.h>
#include <unistd.h>
#include <commutil.h>
+#include <dirent.h>
+
#include "sysfswrapper.h"
#define BUS "ccw"
@@ -84,213 +86,189 @@ int _DefinedMetrics( MetricRegisterId *m
int _StartStopMetrics (int starting) {
if( starting ) {
- DBGONLY(fprintf(stderr,"--- %s(%i) : Metric processing starting\n",
- __FILE__,__LINE__);)
+ DBGONLY(fprintf(stderr,"--- %s(%i) : Metric processing starting\n",
+ __FILE__,__LINE__);)
/* nothing to do */
}
else {
- DBGONLY(fprintf(stderr,"--- %s(%i) : Metric processing stopping\n",
- __FILE__,__LINE__);)
+ DBGONLY(fprintf(stderr,"--- %s(%i) : Metric processing stopping\n",
+ __FILE__,__LINE__);)
/* nothing to do */
}
-
+
return 0;
}
-int sendMetric(int mid, MetricReturner mret, sysfsw_Device* device, char* values) {
-
+int sendMetric(int mid, MetricReturner mret, char* device, char* values) {
MetricValue * mv = NULL;
-
- if (mret==NULL) { fprintf(stderr,"Returner pointer is NULL\n"); return -1; }
-
- char* resource = sysfsw_getDeviceName(device);
-
- mv = calloc(1, sizeof(MetricValue) +
- strlen(values) + 1 +
- strlen(resource) + 1 );
+
+ if (mret==NULL) {
+ fprintf(stderr,"Returner pointer is NULL\n");
+ return -1;
+ }
+
+ mv = calloc(1, sizeof(MetricValue) +
+ strlen(values) + 1 +
+ strlen(device) + 1 );
if (mv) {
- mv->mvId = mid;
- mv->mvTimeStamp = time(NULL);
- mv->mvDataType = MD_STRING;
- mv->mvDataLength = (strlen(values)+1);
- mv->mvData = (char*)mv + sizeof(MetricValue);
- strncpy( mv->mvData, values, strlen(values) );
- mv->mvResource = (char*)mv + sizeof(MetricValue) + strlen(values)+1;
- strcpy(mv->mvResource,resource);
- mret(mv);
- return 1;
- }
- return -1;
+ mv->mvId = mid;
+ mv->mvTimeStamp = time(NULL);
+ mv->mvDataType = MD_STRING;
+ mv->mvDataLength = (strlen(values)+1);
+ mv->mvData = (char*)mv + sizeof(MetricValue);
+ strncpy( mv->mvData, values, strlen(values) );
+ mv->mvResource = (char*)mv + sizeof(MetricValue) +
+ strlen(values) + 1;
+ strcpy(mv->mvResource, device);
+ mret(mv);
+ return 1;
+ }
+ return -1;
}
-char* readSysFs(char* devicePath) {
-
+char* readSysFs(char* deviceName) {
int i, attributeCount;
size_t strLength;
-
- sysfsw_Device* device = sysfsw_openDevice(devicePath);
- if (device!=NULL) {
- DBGONLY(printf("device opened\n");)
- } else {
- DBGONLY(printf("device open failed\n");)
- return NULL;
- }
-
const char* CMB_ENABLE = "cmb_enable";
-
const char* SAMPLE_COUNT = "cmf/sample_count";
-
- const char* ATTRIBUTES[] = {
- "cmf/avg_control_unit_queuing_time",
- "cmf/avg_device_active_only_time",
- "cmf/avg_device_busy_time",
- "cmf/avg_device_connect_time",
- "cmf/avg_device_disconnect_time",
- "cmf/avg_function_pending_time",
- "cmf/avg_initial_command_response_time",
- "cmf/avg_sample_interval",
- "cmf/avg_utilization",
- "cmf/ssch_rsch_count",
- "cmf/sample_count",
- NULL};
+ const char* ATTRIBUTES[] = {
+ "cmf/avg_control_unit_queuing_time",
+ "cmf/avg_device_active_only_time",
+ "cmf/avg_device_busy_time",
+ "cmf/avg_device_connect_time",
+ "cmf/avg_device_disconnect_time",
+ "cmf/avg_function_pending_time",
+ "cmf/avg_initial_command_response_time",
+ "cmf/avg_sample_interval",
+ "cmf/avg_utilization",
+ "cmf/ssch_rsch_count",
+ "cmf/sample_count",
+ NULL
+ };
+ char buff[256];
- for(attributeCount=0; ATTRIBUTES[attributeCount]!=NULL; ++attributeCount);
-
- sysfsw_Attribute* cmbEnableAttr = sysfsw_openAttribute(device, CMB_ENABLE);
-
- if (cmbEnableAttr==NULL) {
- DBGONLY(printf("cmb_enable could not be opened\n"));
- sysfsw_closeDevice(device);
- return NULL;
+ strLength = readSysfsAttr(deviceName, CMB_ENABLE, buff, 256);
+ if (strLength < 1) {
+ return NULL;
}
-
- int cmbEnable = sysfsw_getAttributeValue(cmbEnableAttr)!=NULL && sysfsw_getAttributeValue(cmbEnableAttr)[0]=='1';
- sysfsw_closeAttribute(cmbEnableAttr);
-
- if (!cmbEnable) {
- DBGONLY(printf("cmb_enable!=1\n"));
- sysfsw_closeDevice(device);
- return NULL;
+ if (buff[0] != '1') {
+ DBGONLY(printf("cmb_enable!=1\n");)
+ return NULL;
}
-
- sysfsw_Attribute** attributeValues = calloc(attributeCount, sizeof(sysfsw_Attribute*));
- if (attributeValues == NULL) {
+
+ for( attributeCount = 0;
+ ATTRIBUTES[attributeCount] != NULL;
+ ++attributeCount);
+
+ char** attributeValues = calloc(attributeCount, 256);
+ if (attributeValues == NULL) {
fprintf(stderr, "calloc() failed\n");
- sysfsw_closeDevice(device);
- return NULL;
+ return NULL;
}
int sampleCount1, sampleCount2;
- int loops = 0;
-
- do {
+ int loops = 0, len;
- if (loops > 0) {
- for(i=0; i<attributeCount; ++i) {
- sysfsw_closeAttribute(attributeValues[i]);
- }
- }
-
- sysfsw_Attribute* sampleCountAttr = sysfsw_openAttribute(device, SAMPLE_COUNT);
- if (sampleCountAttr==NULL) {
- DBGONLY(printf("sample_count could not be opened\n"));
+ do {
+ len = readSysfsAttr(deviceName, SAMPLE_COUNT, buff, 256);
+ if (len < 0) {
free(attributeValues);
- sysfsw_closeDevice(device);
- return NULL;
+ return NULL;
}
-
- sampleCount1 = sysfsw_getAttributeValue(sampleCountAttr)!=NULL ? atoi(sysfsw_getAttributeValue(sampleCountAttr)) : -1;
- sysfsw_closeAttribute(sampleCountAttr);
- if (sampleCount1<0) {
- DBGONLY(printf("sample_count <0\n"));
+ sampleCount1 = atoi(buff);
+
+ if (sampleCount1 < 0) {
+ DBGONLY(printf("sample_count < 0\n");)
free(attributeValues);
- sysfsw_closeDevice(device);
- return NULL;
+ return NULL;
}
strLength = 0;
-
- for(i=0; i<attributeCount; ++i) {
+ for(i = 0; i < attributeCount; ++i) {
DBGONLY(printf("%s=", ATTRIBUTES[i]);)
- attributeValues[i] = sysfsw_openAttribute(device, ATTRIBUTES[i]);
- if (attributeValues[i]==NULL) { printf("NULL\n"); strLength+=2; continue; }
- strLength += max(strlen(sysfsw_getAttributeValue(attributeValues[i])), 2);
- DBGONLY(printf("%s\n", sysfsw_getAttributeValue(attributeValues[i]));)
- }
-
- sampleCountAttr = attributeValues[attributeCount-1];
- if (sampleCountAttr==NULL) {
- DBGONLY(printf("sample_count could not be opened\n"));
- for(i=0; i<attributeCount; ++i) {
- sysfsw_closeAttribute(attributeValues[i]);
+ len = readSysfsAttr(deviceName, ATTRIBUTES[i],
+ attributeValues[i], 256);
+ if (len < 1) {
+ printf("NULL\n");
+ strLength+=2;
+ continue;
}
+ strLength += max(strlen(attributeValues[i]), 2);
+ DBGONLY(printf("%s\n", attributeValues[i]);)
+ }
+
+ len = readSysfsAttr(deviceName, SAMPLE_COUNT, buff, 256);
+ if (len < 0) {
free(attributeValues);
- sysfsw_closeDevice(device);
- return NULL;
+ return NULL;
}
-
- sampleCount2 = sysfsw_getAttributeValue(sampleCountAttr)!=NULL ? atoi(sysfsw_getAttributeValue(sampleCountAttr)) : -1;
-
+ sampleCount2 = atoi(buff);
++loops;
- DBGONLY(printf("sample count = %d/%d, loops = %d\n", sampleCount1, sampleCount2, loops);)
-
- } while (sampleCount2-sampleCount1 && loops<2);
+ DBGONLY(printf("sample count = %d/%d, loops = %d\n",
+ sampleCount1, sampleCount2, loops);)
+ } while (sampleCount2 - sampleCount1 && loops < 2);
- char* result = calloc(strLength+1, sizeof(char));
+ char* result = calloc(strLength+1, sizeof(char));
if (result==NULL) {
- for(i=0; i<attributeCount; ++i) {
- sysfsw_closeAttribute(attributeValues[i]);
- }
free(attributeValues);
- sysfsw_closeDevice(device);
return NULL;
}
-
+
size_t remainder = strLength;
- for(i=0; i<attributeCount; ++i) {
- char* value = (attributeValues[i]!=NULL) ? sysfsw_getAttributeValue(attributeValues[i]) : NULL;
- if (value==NULL || strlen(value)==0) { value = "0\n"; }
+ for(i = 0; i < attributeCount; ++i) {
+ char *value = attributeValues[i];
+
+ if (value == NULL || strlen(value)==0) { value = "0\n"; }
strncat(result, value, remainder);
remainder -= strlen(value);
- sysfsw_closeAttribute(attributeValues[i]);
result[strlen(result)-1] = ':';
}
free(attributeValues);
- sysfsw_closeDevice(device);
-
+
return result;
}
int metricRetrECKD( int mid,
MetricReturner mret ) {
-
+ char dirpath[256];
int deviceCount = 0;
-
- sysfsw_Driver* driver = sysfsw_openDriver(BUS, DRIVER);
- if (driver!=NULL) {
- sysfsw_DeviceList* deviceList = sysfsw_readDeviceList(driver);
- if (deviceList!=NULL) {
- sysfsw_startDeviceList(deviceList);
- while (sysfsw_nextDevice(deviceList)) {
- sysfsw_Device* device = sysfsw_getDevice(deviceList);
- DBGONLY(printf("device name = %s\n", sysfsw_getDeviceName(device));)
- char* values = readSysFs(sysfsw_getDevicePath(device));
- if (values!=NULL) {
- DBGONLY(printf("%s\n", values);)
- int result = sendMetric(mid, mret, device, values);
- free(values);
- if (!result) { deviceCount = -1; break; }
- ++deviceCount;
- }
- }
- }
- sysfsw_closeDriver(driver);
- }
-
+
+ DIR *dirfd;
+ struct dirent *dent;
+
+ sprintf(dirpath, "/sys/bus/%s/drivers/%s", BUS, DRIVER);
+ dirfd = opendir(dirpath);
+ if (!dirfd)
+ return 0;
+ while ((dent = readdir(dirfd)) != NULL) {
+ char *values;
+ unsigned css, lcss, ccw;
+
+ if (sscanf(dent->d_name,
+ "%x.%x.%4x", &css, &lcss, &ccw) != 3)
+ continue;
+
+ values = readSysFs(dent->d_name);
+ DBGONLY(printf("device name = %s\n", dent->d_name);)
+
+ if (values!=NULL) {
+ DBGONLY(printf("%s\n", values);)
+ int result = sendMetric(mid, mret,
+ dent->d_name, values);
+ free(values);
+ if (!result) {
+ deviceCount = -1;
+ break;
+ }
+ ++deviceCount;
+ }
+ }
+ closedir(dirfd);
+
return deviceCount;
}
/* ---------------------------------------------------------------------------*/
Index: sblim-gather-2.2.8/plugin/sysfswrapper.c
===================================================================
--- sblim-gather-2.2.8.orig/plugin/sysfswrapper.c
+++ sblim-gather-2.2.8/plugin/sysfswrapper.c
@@ -1,121 +1,36 @@
-#include "sysfswrapper.h"
-#include <sysfs/libsysfs.h>
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include <errno.h>
-#include <string.h>
-#include <memory.h>
-
-
-sysfsw_Driver* sysfsw_openDriver(const char* bus, const char* driver) {
-
- sysfsw_Driver* result = sysfs_open_driver(bus, driver);
-
- if (result == NULL) {
- fprintf(stderr, "error opening driver %s,%s (%d)\n", bus, driver, errno);
- } else {
-// printf("driver %s,%s opened\n", bus, driver);
- }
- return result;
-}
-
-sysfsw_DeviceList* sysfsw_readDeviceList(sysfsw_Driver* driver) {
-
- sysfsw_DeviceList* result = sysfs_get_driver_devices(driver);
-
- if (result == NULL) {
- fprintf(stderr, "error opening device list (%d)\n", errno);
- } else {
-// printf("device list opened\n");
- }
-
- return result;
-}
-
-void sysfsw_closeDriver(sysfsw_Driver* driver) {
- sysfs_close_driver(driver);
-}
-
-void sysfsw_startDeviceList(sysfsw_DeviceList* deviceList) {
- dlist_start(deviceList);
-}
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include "sysfswrapper.h"
-int sysfsw_nextDevice(sysfsw_DeviceList* deviceList) {
- if (deviceList->marker->next!=NULL && deviceList->marker->next!=deviceList->head) {
- dlist_next(deviceList);
- return 1;
+#ifdef DEBUG
+#define DBGONLY(X) X
+#else
+#define DBGONLY(X)
+#endif
+
+ssize_t readSysfsAttr(const char *devicePath, const char *deviceAttr,
+ char *value, ssize_t len)
+{
+ char attrpath[256];
+ ssize_t ret;
+ int fd;
+
+ sprintf(attrpath, "%s/%s", devicePath, deviceAttr);
+ fd = open(attrpath, O_RDONLY);
+ if (fd < 0) {
+ DBGONLY(printf("%s could not be opened\n", deviceAttr);)
+ return -1;
}
- return 0;
-}
-
-unsigned long sysfsw_getDeviceCount(sysfsw_DeviceList* deviceList) {
- return deviceList->count;
-}
-
-sysfsw_Device* sysfsw_getDevice(sysfsw_DeviceList* deviceList) {
- sysfsw_Device* result = dlist_mark(deviceList);
- return result;
-}
-
-sysfsw_Device* sysfsw_openDevice(const char* devicePath) {
- return sysfs_open_device_path(devicePath);
-}
-
-void sysfsw_closeDevice(sysfsw_Device* device) {
- sysfs_close_device(device);
-}
-
-sysfsw_Device* sysfsw_openDeviceTree(const char* devicePath) {
- return sysfs_open_device_tree(devicePath);
-}
-
-sysfsw_DeviceList* sysfsw_getDeviceList(sysfsw_Device* device) {
- return device->children;
-}
-
-void sysfsw_closeDeviceTree(sysfsw_Device* device) {
- sysfs_close_device_tree(device);
-}
-
-sysfsw_Attribute* sysfsw_openAttributePath(char* devicepath, const char* path) {
- char* attrpath = malloc(SYSFS_PATH_MAX+1);
- if (attrpath==NULL) return NULL;
-
- strncpy(attrpath, devicepath, SYSFS_PATH_MAX);
- strncat(attrpath, "/", SYSFS_PATH_MAX-strlen(attrpath));
- strncat(attrpath, path, SYSFS_PATH_MAX-strlen(attrpath));
-
- sysfsw_Attribute* attribute = sysfs_open_attribute(attrpath);
- sysfs_read_attribute(attribute);
- free(attrpath);
- return attribute;
-}
-
-sysfsw_Attribute* sysfsw_openAttribute(sysfsw_Device* device, const char* path) {
- return sysfsw_openAttributePath(device->path, path);
-}
-
-void sysfsw_closeAttribute(sysfsw_Attribute* attribute) {
- sysfs_close_attribute(attribute);
-}
-
-sysfsw_Attribute* sysfsw_getAttribute(sysfsw_Device* device, const char* name) {
-
- sysfsw_Attribute* result = sysfs_get_device_attr(device, name);
- if (result==NULL) {
- fprintf(stderr, "Get attribute failed %s (%d)", name, errno);
+ ret = read(fd, value, len);
+ close(fd);
+ if (ret < 0) {
+ DBGONLY(printf("%s could not be read\n", deviceAttr);)
+ return -1;
}
- return result;
-}
-
-char* sysfsw_getDeviceName(sysfsw_Device* device) {
- return device!=NULL ? device->name : NULL;
-}
-
-char* sysfsw_getDevicePath(sysfsw_Device* device) {
- return device!=NULL ? device->path : NULL;
-}
-
-char* sysfsw_getAttributeValue(sysfsw_Attribute* attribute) {
- return attribute->value;
+ return ret;
}
Index: sblim-gather-2.2.8/plugin/sysfswrapper.h
===================================================================
--- sblim-gather-2.2.8.orig/plugin/sysfswrapper.h
+++ sblim-gather-2.2.8/plugin/sysfswrapper.h
@@ -1,62 +1,7 @@
#ifndef SYSFSWRAPPER_H_
#define SYSFSWRAPPER_H_
-// forward declarations from libsysfs header
-struct sysfs_root_device;
-struct sysfs_device;
-struct dlist;
-
-typedef struct sysfs_driver sysfsw_Driver;
-
-typedef struct sysfs_device sysfsw_Device;
-
-typedef struct sysfs_attribute sysfsw_Attribute;
-
-typedef struct dlist sysfsw_DeviceList;
-
-/* Driver */
-sysfsw_Driver* sysfsw_openDriver(const char* bus, const char* driver);
-
-void sysfsw_closeDriver(sysfsw_Driver* driver);
-
-sysfsw_DeviceList* sysfsw_readDeviceList(sysfsw_Driver* driver);
-
-/* Device List */
-
-unsigned long sysfsw_getDeviceCount(sysfsw_DeviceList* deviceList);
-
-void sysfsw_startDeviceList(sysfsw_DeviceList* deviceList);
-
-int sysfsw_nextDevice(sysfsw_DeviceList* deviceList);
-
-sysfsw_Device* sysfsw_getDevice(sysfsw_DeviceList* deviceList);
-
-/* Device */
-
-sysfsw_Device* sysfsw_openDevice(const char *devicePath);
-
-char* sysfsw_getDeviceName(sysfsw_Device* device);
-
-char* sysfsw_getDevicePath(sysfsw_Device* device);
-
-void sysfsw_closeDevice(sysfsw_Device* device);
-
-sysfsw_Device* sysfsw_openDeviceTree(const char *devicePath);
-
-sysfsw_DeviceList* sysfsw_getDeviceList(sysfsw_Device* device);
-
-void sysfsw_closeDeviceTree(sysfsw_Device* device);
-
-/* Attribute */
-
-sysfsw_Attribute* sysfsw_getAttribute(sysfsw_Device* device, const char* name);
-
-sysfsw_Attribute* sysfsw_openAttributePath(char* devicepath, const char* path);
-
-sysfsw_Attribute* sysfsw_openAttribute(sysfsw_Device* device, const char* path);
-
-void sysfsw_closeAttribute(sysfsw_Attribute* attribute);
-
-char* sysfsw_getAttributeValue(sysfsw_Attribute* attribute);
+ssize_t readSysfsAttr(const char *deviceName, const char *deviceAttr,
+ char *value, ssize_t len);
#endif /*SYSFSWRAPPER_H_*/