From: Heidi E. <hei...@us...> - 2005-04-20 11:40:31
|
Update of /cvsroot/sblim/cmpi-fsvol In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5454 Modified Files: AUTHORS ChangeLog Makefile.am README configure.ac Added Files: OSBase_BlockStorageStatisticalData.c OSBase_BlockStorageStatisticalData.h cmpiOSBase_BlockStorageStatisticalData.c cmpiOSBase_BlockStorageStatisticalData.h cmpiOSBase_BlockStorageStatisticalDataProvider.c Log Message: feature request# 1186595: support for LogicalDisk statistical data added ... contribution by Michael Schuele :) ... thx --- NEW FILE: cmpiOSBase_BlockStorageStatisticalData.h --- #ifndef _CMPIOSBASE_BLOCKSTORAGESTATISTICALDATA_H_ #define _CMPIOSBASE_BLOCKSTORAGESTATISTICALDATA_H_ /* * cmpiOSBase_BlockStorageStatisticalData.h * * (C) Copyright IBM Corp. 2004, 2005 * * THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. * * You can obtain a current copy of the Common Public License from * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html * * Author: Michael Schuele <sch...@de...> * Contributors: * * Interface Type : Common Magabeablity Programming Interface ( CMPI ) * * Description: * This file defines the interfaces for the factory implementation of the * CIM class Linux_BlockStorageStatisticalData. * */ /* ---------------------------------------------------------------------------*/ #include "cmpidt.h" #include "OSBase_BlockStorageStatisticalData.h" /* ---------------------------------------------------------------------------*/ static char * _ClassName = "Linux_BlockStorageStatisticalData"; static const char * _INSTANCE_PREFIX = "Linux:"; static int _INSTANCE_PREFIX_LENGTH = 6; /* ---------------------------------------------------------------------------*/ /* method to create a CMPIObjectPath of this class */ CMPIObjectPath * _makePath_BlockStorageStatisticalData(CMPIBroker * _broker, CMPIContext * ctx, CMPIObjectPath * cop, CMPIStatus * rc, struct disk_data *disk); /* method to create a CMPIInstance of this class */ CMPIInstance * _makeInst_BlockStorageStatisticalData(CMPIBroker * _broker, CMPIContext * ctx, CMPIObjectPath * cop, const char ** properties, CMPIStatus * rc, struct disk_data *disk); /* ---------------------------------------------------------------------------*/ #endif Index: configure.ac =================================================================== RCS file: /cvsroot/sblim/cmpi-fsvol/configure.ac,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- configure.ac 19 Apr 2005 16:00:13 -0000 1.2 +++ configure.ac 20 Apr 2005 11:40:19 -0000 1.3 @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT(SBLIM BaseOS Filesystem Providers, 1.3.0, sbl...@li...,sblim-cmpi-fsvol) +AC_INIT(SBLIM BaseOS Filesystem Providers, 1.4.0, sbl...@li...,sblim-cmpi-fsvol) AC_CONFIG_SRCDIR([OSBase_CommonFsvol.c]) AC_CONFIG_HEADER([config.h]) AM_INIT_AUTOMAKE Index: Makefile.am =================================================================== RCS file: /cvsroot/sblim/cmpi-fsvol/Makefile.am,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Makefile.am 15 Apr 2005 14:28:15 -0000 1.1 +++ Makefile.am 20 Apr 2005 11:40:19 -0000 1.2 @@ -43,6 +43,7 @@ # OSBase CMPI provider libraries provider_LTLIBRARIES = libcmpiOSBase_LocalFileSystemProvider.la \ libcmpiOSBase_NFSProvider.la \ + libcmpiOSBase_BlockStorageStatisticalDataProvider.la \ libcmpiOSBase_HostedFileSystemProvider.la \ libcmpiOSBase_BootOSFromFSProvider.la @@ -62,6 +63,14 @@ libcmpiOSBase_NFSProvider_la_LIBADD = \ -lcmpiOSBase_CommonFsvol +# Block Storage Statistical Data +libcmpiOSBase_BlockStorageStatisticalDataProvider_la_SOURCES = \ + cmpiOSBase_BlockStorageStatisticalDataProvider.c \ + cmpiOSBase_BlockStorageStatisticalData.c \ + OSBase_BlockStorageStatisticalData.c +libcmpiOSBase_BlockStorageStatisticalDataProvider_la_LIBADD = \ + -lcmpiOSBase_CommonFsvol + # Hosted Filesystem (Association) libcmpiOSBase_HostedFileSystemProvider_la_SOURCES = \ cmpiOSBase_HostedFileSystemProvider.c @@ -88,8 +97,10 @@ # Non-Installable Header Files noinst_HEADERS = OSBase_LocalFileSystem.h \ OSBase_NFS.h \ + OSBase_BlockStorageStatisticalData.h \ cmpiOSBase_LocalFileSystem.h \ cmpiOSBase_NFS.h \ + cmpiOSBase_BlockStorageStatisticalData.h \ cmpiOSBase_BootOSFromFS.h # We must explicity add the RPM spec file to the distribution package @@ -146,6 +157,7 @@ test/cim/Linux_Ext3FileSystem.cim \ test/cim/Linux_HostedFileSystem.cim \ test/cim/Linux_NFS.cim \ + test/cim/Linux_BlockStorageStatisticalData.cim \ test/cim/Linux_ReiserFileSystem.cim runtest: install Index: ChangeLog =================================================================== RCS file: /cvsroot/sblim/cmpi-fsvol/ChangeLog,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ChangeLog 15 Apr 2005 14:28:15 -0000 1.1 +++ ChangeLog 20 Apr 2005 11:40:19 -0000 1.2 @@ -15,8 +15,15 @@ * test script accepts userID and password // =================================================================== -// new in version 1.3 : +// new in version 1.3.0 : * support for property list filter on EnumInstances and GetInstance // =================================================================== +// new in version 1.4.0 : + +* feature request# 1186595: added support for class + Linux_BlockStorageStatisticalData + ... contribution by Michael Schuele ... thx :) + +// =================================================================== Index: README =================================================================== RCS file: /cvsroot/sblim/cmpi-fsvol/README,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- README 15 Apr 2005 14:28:15 -0000 1.6 +++ README 20 Apr 2005 11:40:19 -0000 1.7 @@ -32,6 +32,7 @@ - Linux_Ext3FileSystem - Linux_ReiserFileSystem - Linux_NFS +- Linux_BlockStorageStatisticalData - Linux_HostedFileSystem - Linux_BootOSFromFS @@ -138,6 +139,12 @@ - cmpiOSBase_NFS.c/.h - OSBase_NFS.c/.h +class Linux_BlockStorageStatisticalData +........................... +- cmpiOSBase_BlockStorageStatisticalDataProvider.c +- cmpiOSBase_BlockStorageStatisticalData.c/.h +- OSBase_BlockStorageStatisticalData.c/.h + association Linux_HostedFileSystem ........................... --- NEW FILE: OSBase_BlockStorageStatisticalData.h --- #ifndef _LINUX_BLOCKSTORAGESTATISTICALDATA_H_ #define _LINUX_BLOCKSTORAGESTATISTICALDATA_H_ /* * Linux_BlockStorageStatisticalData.h * * (C) Copyright IBM Corp. 2004, 2005 * * THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. * * You can obtain a current copy of the Common Public License from * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html * * Author: Michael Schuele <sch...@de...> * Contributors: * * Description: * This file defines the interfaces for the resource access implementation * of the CIM class Linux_BlockStorageStatisticalData * */ /* ---------------------------------------------------------------------------*/ //#include <pthread.h> #include <sys/types.h> #ifdef __cplusplus extern "C" { #endif //static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /* ---------------------------------------------------------------------------*/ /** the data of one single drive */ struct disk_data { char *id; unsigned long long kb_read; unsigned long long kb_transfered; unsigned long long read_ios; unsigned long long write_ios; unsigned long long total_ios; unsigned long long io_time; }; /** the list of all known drives */ struct disk_list { struct disk_data *disk; struct disk_list *next; }; /** * Returns a list of all currently known disk drives * This function allocates memory which must be freed by * free_disk_list() (only if return value is not 0). * @param list the list is returned using this parameter * @return amount of available disk drives, 0 if no drive * was found. */ int enum_all_disks(struct disk_list **list); /** * Returns the current values of a specific disk drive. * This function allocates memory which must be freed by * free_disk() (only if return value is 1). * @param id a unique indentifier of the disk * @param disk the current data is returned using this parameter * @return 1 on success, 0 otherwise */ int get_disk_data(char *id, struct disk_data **disk); /** * Frees the memory allocated by enum_all_disks * @param list the list of all known drives returned by enum_all_disks * @see enum_all_disks */ void free_disk_list(struct disk_list *list); /** * Frees the memory allocated by a drive structure * @param drive the structure to free */ void free_disk(struct disk_data *disk); /** * Resets the given counters. * @param counters the counters to reset */ void reset_counters(); /* ---------------------------------------------------------------------------*/ #ifdef __cplusplus } #endif /* ---------------------------------------------------------------------------*/ #endif --- NEW FILE: cmpiOSBase_BlockStorageStatisticalData.c --- /* * cmpiOSBase_BlockStorageStatisticalData.c * * (C) Copyright IBM Corp. 2004, 2005 * * THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. * * You can obtain a current copy of the Common Public License from * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html * * Author: Michael Schuele <sch...@de...> * Contributors: * * Interface Type : Common Magabeablity Programming Interface ( CMPI ) * * Description: * This is the factory implementation for creating instances of CIM * class Linux_BlockStorageStatisticalData. * */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include "cmpidt.h" #include "cmpimacs.h" #include "cmpiOSBase_Common.h" #include "OSBase_Common.h" #include "cmpiOSBase_BlockStorageStatisticalData.h" /* ---------------------------------------------------------------------------*/ /* private declarations */ /* ---------------------------------------------------------------------------*/ /* ---------------------------------------------------------------------------*/ /* Factory functions */ /* ---------------------------------------------------------------------------*/ /* ---------- method to create a CMPIObjectPath of this class ----------------*/ CMPIObjectPath * _makePath_BlockStorageStatisticalData(CMPIBroker * _broker, CMPIContext * ctx, CMPIObjectPath * ref, CMPIStatus * rc, struct disk_data *disk) { CMPIObjectPath * op = NULL; char * instanceID = NULL; char * hostname = NULL; _OSBASE_TRACE(2,("--- _makePath_BlockStorageStatisticalData() called")); op = CMNewObjectPath( _broker, CMGetCharPtr(CMGetNameSpace(ref,rc)), _ClassName, rc ); if (CMIsNullObject(op)) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "Create CMPIObjectPath failed." ); _OSBASE_TRACE(2,("--- _makePath_BlockStorageStatisticalData() failed : %s",CMGetCharPtr(rc->msg))); goto exit; } /* keys are unique identifiers for an instance */ // Linux:<hostname>_<disk_id> hostname = get_system_name(); instanceID = calloc(_INSTANCE_PREFIX_LENGTH + strlen(hostname) + 1 + strlen(disk->id) + 1, sizeof(char)); strcpy(instanceID, _INSTANCE_PREFIX); strcat(instanceID, hostname); strcat(instanceID, "_"); strcat(instanceID, disk->id); CMAddKey(op, "InstanceID", instanceID, CMPI_chars); if (instanceID) free(instanceID); exit: _OSBASE_TRACE(2,("--- _makePath_BlockStorageStatisticalData() exited")); return op; } /* ----------- method to create a CMPIInstance of this class ----------------*/ CMPIInstance * _makeInst_BlockStorageStatisticalData(CMPIBroker * _broker, CMPIContext * ctx, CMPIObjectPath * ref, const char ** properties, CMPIStatus * rc, struct disk_data *disk) { CMPIObjectPath * op = NULL; CMPIInstance * ci = NULL; const char ** keys = NULL; int keyCount = 0; char * instanceID = NULL; CMPIDateTime * dt = NULL; char * hostname = NULL; _OSBASE_TRACE(2,("--- _makeInst_BlockStorageStatisticalData() called")); op = CMNewObjectPath( _broker, CMGetCharPtr(CMGetNameSpace(ref,rc)), _ClassName, rc ); if (CMIsNullObject(op)) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "Create CMPIObjectPath failed." ); _OSBASE_TRACE(2,("--- _makeInst_BlockStorageStatisticalData() failed : %s",CMGetCharPtr(rc->msg))); goto exit; } ci = CMNewInstance( _broker, op, rc); if (CMIsNullObject(ci)) { CMSetStatusWithChars( _broker, rc, CMPI_RC_ERR_FAILED, "Create CMPIInstance failed." ); _OSBASE_TRACE(2,("--- _makeInst_BlockStorageStatisticalData() failed : %s",CMGetCharPtr(rc->msg))); goto exit; } /* set property filter */ /* keys = calloc(7,sizeof(char*)); keys[0] = strdup("CreationClassName"); keys[1] = strdup("DeviceCreationClassName"); keys[2] = strdup("DeviceID"); keys[3] = strdup("Name"); keys[4] = strdup("SystemCreationClassName"); keys[5] = strdup("SystemName"); keys[6] = NULL; CMSetPropertyFilter(ci,properties,keys); for( ;keys[keyCount]!=NULL;keyCount++) { free((char*)keys[keyCount]); } free(keys); */ // create instanceID: Linux:<hostname>_<disk_id> hostname = get_system_name(); instanceID = calloc(_INSTANCE_PREFIX_LENGTH + strlen(hostname) + 1 + strlen(disk->id) + 1, sizeof(char)); strcpy(instanceID, _INSTANCE_PREFIX); strcat(instanceID, hostname); strcat(instanceID, "_"); strcat(instanceID, disk->id); CMSetProperty(ci, "InstanceID", instanceID, CMPI_chars); if (instanceID) free(instanceID); /* from CIM_ManagedElement */ CMSetProperty(ci, "Caption", _ClassName, CMPI_chars); CMSetProperty(ci, "Description", "statistical information about disk drives", CMPI_chars); CMSetProperty(ci, "ElementName", disk->id, CMPI_chars); /* from CIM_StatisticalData */ // not supported CMSetProperty(ci, "StartStatisticTime", NULL, CMPI_dateTime); dt = CMNewDateTime(_broker,rc); CMSetProperty(ci, "StatisticTime", (CMPIValue*)&(dt), CMPI_dateTime); // there's no consistent time interval //CMSetProperty(ci, "SampleInterval", NULL, CMPI_uint64); /* from CIM_BlockStorageStatisticalData */ CMSetProperty(ci, "ReadIOs", (CMPIValue*)&(disk->read_ios), CMPI_uint64); CMSetProperty(ci, "WriteIOs", (CMPIValue*)&(disk->write_ios), CMPI_uint64); CMSetProperty(ci, "TotalIOs", (CMPIValue*)&(disk->total_ios), CMPI_uint64); CMSetProperty(ci, "KBytesRead", (CMPIValue*)&(disk->kb_read), CMPI_uint64); CMSetProperty(ci, "KBytesTransfered", (CMPIValue*)&(disk->kb_transfered), CMPI_uint64); CMSetProperty(ci, "IOTimeCounter", (CMPIValue*)&(disk->io_time), CMPI_uint64); exit: _OSBASE_TRACE(2,("--- _makeInst_BlockStorageStatisticalData() exited")); return ci; } /* ---------------------------------------------------------------------------*/ /* end of cmpiOSBase_BlockStorageStatisticalData.c */ /* ---------------------------------------------------------------------------*/ --- NEW FILE: cmpiOSBase_BlockStorageStatisticalDataProvider.c --- /* * cmpiOSBase_BlockStorageStatisticalData * * (C) Copyright IBM Corp. 2004, 2005 * * THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. * * You can obtain a current copy of the Common Public License from * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html * * Author: Michael Schuele <sch...@de...> * Contributors: * * Interface Type : Common Manageability Programming Interface ( CMPI ) * * Description: Provider for BlockStorageStatisticalData * */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include "cmpidt.h" #include "cmpift.h" #include "cmpimacs.h" #include "OSBase_Common.h" #include "cmpiOSBase_Common.h" #include "cmpiOSBase_BlockStorageStatisticalData.h" static CMPIBroker * _broker; /* ---------------------------------------------------------------------------*/ /* private declarations */ /* ---------------------------------------------------------------------------*/ /* ---------------------------------------------------------------------------*/ /* Instance Provider Interface */ /* ---------------------------------------------------------------------------*/ CMPIStatus OSBase_BlockStorageStatisticalDataProviderCleanup(CMPIInstanceMI * mi, CMPIContext * ctx) { _OSBASE_TRACE(1,("--- %s CMPI Cleanup() called",_ClassName)); CMReturn(CMPI_RC_OK); } CMPIStatus OSBase_BlockStorageStatisticalDataProviderEnumInstanceNames(CMPIInstanceMI * mi, CMPIContext * ctx, CMPIResult * rslt, CMPIObjectPath * ref) { CMPIStatus rc = {CMPI_RC_OK, NULL}; CMPIObjectPath * op = NULL; struct disk_list * disk_list = NULL; struct disk_list * list_backup = NULL; _OSBASE_TRACE(4,("--- CMPI EnumInstanceNames() entered")); enum_all_disks(&disk_list); _OSBASE_TRACE(1,("--- %s CMPI EnumInstanceNames() called",_ClassName)); if (disk_list == NULL) { _OSBASE_TRACE(1,("--- CMPI EnumInstanceNames() failed : no disks available")); return rc; } list_backup = disk_list; while (disk_list != NULL) { op = _makePath_BlockStorageStatisticalData(_broker,ctx,ref,&rc, disk_list->disk); if (op == NULL) { if (rc.msg != NULL) { _OSBASE_TRACE(1,("--%s CMPI EnumInstanceNames() failed : %s", _ClassName,CMGetCharPtr(rc.msg))); } else { _OSBASE_TRACE(1,("--%s CMPI EnumInstanceNames() failed", _ClassName)); } return rc; } CMReturnObjectPath(rslt, op); disk_list = disk_list->next; } if (list_backup) { free_disk_list(list_backup); } CMReturnDone(rslt); _OSBASE_TRACE(1,("--- %s CMPI EnumInstanceNames() exited",_ClassName)); return rc; } CMPIStatus OSBase_BlockStorageStatisticalDataProviderEnumInstances(CMPIInstanceMI * mi, CMPIContext * ctx, CMPIResult * rslt, CMPIObjectPath * ref, char ** properties) { CMPIStatus rc = {CMPI_RC_OK, NULL}; CMPIInstance * ci = NULL; struct disk_list * disk_list = NULL; struct disk_list * list_backup = NULL; _OSBASE_TRACE(1,("--- %s CMPI EnumInstances() called",_ClassName)); enum_all_disks(&disk_list); list_backup = disk_list; if (disk_list == NULL) { _OSBASE_TRACE(1,("--- CMPI EnumInstances() failed : no disks available")); return rc; } while (disk_list != NULL) { ci = _makeInst_BlockStorageStatisticalData(_broker, ctx, ref, properties, &rc, disk_list->disk); if (ci == NULL) { if (rc.msg != NULL) { _OSBASE_TRACE(1,("--%s CMPI EnumInstances() failed : %s", _ClassName,CMGetCharPtr(rc.msg))); } else { _OSBASE_TRACE(1,("--%s CMPI EnumInstances() failed", _ClassName)); } return rc; } CMReturnInstance( rslt, ci ); disk_list = disk_list->next; } if (list_backup) free_disk_list(list_backup); CMReturnDone( rslt ); _OSBASE_TRACE(1,("--- %s CMPI EnumInstances() exited",_ClassName)); return rc; } CMPIStatus OSBase_BlockStorageStatisticalDataProviderGetInstance(CMPIInstanceMI * mi, CMPIContext * ctx, CMPIResult * rslt, CMPIObjectPath * cop, char ** properties) { CMPIInstance * ci = NULL; CMPIStatus rc = {CMPI_RC_OK, NULL}; CMPIString * name = NULL; char * c_name = NULL; char * disk_id = NULL; struct disk_data * disk = NULL; int cmdrc = 0; _OSBASE_TRACE(1,("--- %s CMPI GetInstance() called",_ClassName)); name = CMGetKey( cop, "InstanceID", &rc).value.string; c_name = CMGetCharPtr(name); disk_id = strrchr(c_name,'_'); disk_id += 1; if (strlen(disk_id) <= 0) { CMSetStatusWithChars( _broker, &rc, CMPI_RC_ERR_FAILED, "Could not get disk name." ); _OSBASE_TRACE(1,("--- %s CMPI GetInstance() failed for %s : %s",_ClassName,c_name,CMGetCharPtr(rc.msg))); return rc; } cmdrc = get_disk_data(disk_id, &disk); if (cmdrc == 0 || disk == NULL) { CMSetStatusWithChars( _broker, &rc, CMPI_RC_ERR_NOT_FOUND, "disk does not exist"); _OSBASE_TRACE(1,("--- %s CMPI GetInstance() exited : %s",_ClassName,CMGetCharPtr(rc.msg))); if (disk) free_disk(disk); return rc; } ci = _makeInst_BlockStorageStatisticalData(_broker, ctx, cop, properties, &rc, disk); if (disk) free_disk(disk); CMReturnInstance( rslt, ci ); CMReturnDone(rslt); _OSBASE_TRACE(1,("--- %s CMPI GetInstance() exited",_ClassName)); return rc; } CMPIStatus OSBase_BlockStorageStatisticalDataProviderCreateInstance(CMPIInstanceMI * mi, CMPIContext * ctx, CMPIResult * rslt, CMPIObjectPath * cop, CMPIInstance * ci) { CMPIStatus rc = {CMPI_RC_OK, NULL}; _OSBASE_TRACE(1,("--- %s CMPI CreateInstance() called",_ClassName)); CMSetStatusWithChars( _broker, &rc, CMPI_RC_ERR_NOT_SUPPORTED, "CIM_ERR_NOT_SUPPORTED" ); _OSBASE_TRACE(1,("--- %s CMPI CreateInstance() exited",_ClassName)); return rc; } CMPIStatus OSBase_BlockStorageStatisticalDataProviderSetInstance(CMPIInstanceMI * mi, CMPIContext * ctx, CMPIResult * rslt, CMPIObjectPath * cop, CMPIInstance * ci, char **properties) { CMPIStatus rc = {CMPI_RC_OK, NULL}; _OSBASE_TRACE(1,("--- %s CMPI SetInstance() called",_ClassName)); CMSetStatusWithChars( _broker, &rc, CMPI_RC_ERR_NOT_SUPPORTED, "CIM_ERR_NOT_SUPPORTED" ); _OSBASE_TRACE(1,("--- %s CMPI SetInstance() exited",_ClassName)); return rc; } CMPIStatus OSBase_BlockStorageStatisticalDataProviderDeleteInstance(CMPIInstanceMI * mi, CMPIContext * ctx, CMPIResult * rslt, CMPIObjectPath * cop) { CMPIStatus rc = {CMPI_RC_OK, NULL}; _OSBASE_TRACE(1,("--- %s CMPI DeleteInstance() called",_ClassName)); CMSetStatusWithChars( _broker, &rc, CMPI_RC_ERR_NOT_SUPPORTED, "CIM_ERR_NOT_SUPPORTED" ); _OSBASE_TRACE(1,("--- %s CMPI DeleteInstance() exited",_ClassName)); return rc; } CMPIStatus OSBase_BlockStorageStatisticalDataProviderExecQuery(CMPIInstanceMI * mi, CMPIContext * ctx, CMPIResult * rslt, CMPIObjectPath * ref, char * lang, char * query) { CMPIStatus rc = {CMPI_RC_OK, NULL}; _OSBASE_TRACE(1,("--- %s CMPI ExecQuery() called",_ClassName)); CMSetStatusWithChars( _broker, &rc, CMPI_RC_ERR_NOT_SUPPORTED, "CIM_ERR_NOT_SUPPORTED" ); _OSBASE_TRACE(1,("--- %s CMPI ExecQuery() exited",_ClassName)); return rc; } /* ---------------------------------------------------------------------------*/ /* Method Provider Interface */ /* ---------------------------------------------------------------------------*/ CMPIStatus OSBase_BlockStorageStatisticalDataProviderMethodCleanup( CMPIMethodMI * mi, CMPIContext * ctx) { _OSBASE_TRACE(1,("--- %s CMPI MethodCleanup() called",_ClassName)); _OSBASE_TRACE(1,("--- %s CMPI MethodCleanup() exited",_ClassName)); CMReturn(CMPI_RC_OK); } CMPIStatus OSBase_BlockStorageStatisticalDataProviderInvokeMethod( CMPIMethodMI * mi, CMPIContext * ctx, CMPIResult * rslt, CMPIObjectPath * ref, const char * methodName, CMPIArgs * in, CMPIArgs * out) { CMPIString * class = NULL; CMPIStatus rc = {CMPI_RC_OK, NULL}; _OSBASE_TRACE(1,("--- %s CMPI InvokeMethod() called",_ClassName)); class = CMGetClassName(ref, &rc); if( strcasecmp(CMGetCharPtr(class), _ClassName) == 0 && strcasecmp("ResetSelectedStats",methodName) == 0 ) { CMSetStatusWithChars( _broker, &rc, CMPI_RC_ERR_NOT_SUPPORTED, methodName ); } else { CMSetStatusWithChars( _broker, &rc, CMPI_RC_ERR_NOT_FOUND, methodName ); } _OSBASE_TRACE(1,("--- %s CMPI InvokeMethod() exited",_ClassName)); return rc; } /* ---------------------------------------------------------------------------*/ /* Provider Factory */ /* ---------------------------------------------------------------------------*/ CMInstanceMIStub(OSBase_BlockStorageStatisticalDataProvider, OSBase_BlockStorageStatisticalDataProvider, _broker, CMNoHook); CMMethodMIStub( OSBase_BlockStorageStatisticalDataProvider, OSBase_BlockStorageStatisticalDataProvider, _broker, CMNoHook); /* ---------------------------------------------------------------------------*/ /* end of cmpiOSBase_BlockStorageStatisticalDataProvider */ /* ---------------------------------------------------------------------------*/ --- NEW FILE: OSBase_BlockStorageStatisticalData.c --- /* * Linux_BlockStorageStatisticalData.c * * (C) Copyright IBM Corp. 2004, 2005 * * THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. * * You can obtain a current copy of the Common Public License from * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html * * Author: Michael Schuele <sch...@de...> * Contributors: * * Description: * This shared library provides resource access functionality for the class * Linux_BlockStorageStatisticalData. * It is independent from any specific CIM technology. */ /* ---------------------------------------------------------------------------*/ #include "OSBase_BlockStorageStatisticalData.h" #include "OSBase_Common.h" /* logging */ #include <unistd.h> #include <errno.h> #include <dirent.h> #define CHECK_FCT_PARAM #define HD_CMD "grep \"[hs]d[a-z] \" /proc/partitions" #define HD_CMD_26 "grep \"[hs]d[a-z] \" /proc/diskstats" #define STATS_FILE "/proc/partitions" #define STATS_FILE_26 "/proc/diskstats" // uncomment to exclude CD drives //#define HD_ONLY /* ---------------------------------------------------------------------------*/ // private declarations #define IDENTIFIER_LENGTH 255 /** * Allocates memory, retrieves data from the given char array * and sets the values of a single disk_data item. * Prior to this it is checked if the given drive is really a disk * (and not a cdrom or other media) (can be changed using HD_ONLY define). * Currently only IDE disks are supported! * Returned memory has to be freed using free_disk(). * *@param ddisk one line of the file /proc/partitions (if kernel26==0) * or one line of the file /proc/diskstats (if kernel26==1) *@param kernel26 0 if passed data is formatted in kernel24 style, any other * value indicates that data has style of kernel26. * @return NULL if an error occured, otherwise a structure with the data retrieved * from ddata */ struct disk_data * create_disk_data(char *ddata, int kernel26); /** * Checks if the given name identifies a disk or not. * Only IDE disks are supported! * @param name the name to check * @return 1 if the device is a disk, 0 otherwise */ int is_disk(const char * name); /* ---------------------------------------------------------------------------*/ /* linux disk statistics (read <linux-kernel-source>/Documentation/iostats.txt for details): * * 2.4: /proc/partitions * major minor #blocks name rio rmerge rsect ruse wio wmerge wsect wuse running use aveq * 3 0 39082680 hda 446216 784926 9550688 4382310 424847 312726 5922052 19310380 0 3376340 23705160 * 3 1 9221278 hda1 35486 0 35496 38030 0 0 0 0 0 38030 38030 * * 2.6 /proc/diskstats: * major minor name rio rmerge rsect ruse wio wmerge wsect wuse running use aveq * 3 0 hda 446216 784926 9550688 4382310 424847 312726 5922052 19310380 0 3376340 23705160 * 3 1 hda1 35486 38030 38030 38030 * * not supported by this implementation * 2.6 sysfs: * 446216 784926 9550688 4382310 424847 312726 5922052 19310380 0 3376340 23705160 * 35486 38030 38030 38030 */ int enum_all_disks(struct disk_list **list) { struct disk_list *disk_list_item = NULL; int i = 0; int rc = 0; int total_disks = 0; char **hdout = NULL; int kernel26 = 0; FILE *stats26 = NULL; char *cmd = NULL; struct disk_data *dd = NULL; _OSBASE_TRACE(3,("enum_all_disks called")); stats26 = fopen(STATS_FILE_26,"r"); if (stats26) { fclose(stats26); cmd = HD_CMD_26; kernel26 = 1; } else { cmd = HD_CMD; } rc = runcommand(cmd,NULL,&hdout,NULL); if (rc == 0 && hdout != NULL) { while (hdout[i]) { dd = create_disk_data(hdout[i],kernel26); if (dd != NULL) { if (total_disks == 0) { disk_list_item = (struct disk_list *)calloc(1, sizeof(struct disk_list)); disk_list_item->disk = dd; *list = disk_list_item; //disk_list_item->next = NULL; } else { disk_list_item->next = (struct disk_list *)calloc(1, sizeof(struct disk_list)); disk_list_item->next->disk = dd; disk_list_item = disk_list_item->next; //disk_list_item->next = NULL; } disk_list_item->next = NULL; total_disks++; } i++; } } else { _OSBASE_TRACE(1,("enum_all_discs: error while running %s",cmd)); } freeresultbuf(hdout); _OSBASE_TRACE(3,("enum_all_disks exited")); return total_disks; } /** * Allocates memory and gets the data for the specified drive. * @param id the id of the drive * @param disk the data will be returned through this parameter. * The memory has to be freed using free_disk_data(). * @return 1 if data is available and some memory has been assigned * to "disk", 0 otherwise. */ int get_disk_data(char *id, struct disk_data **disk) { int res = 0; int rc = 0; char *cmd; char **hdout = NULL; int kernel26 = 0; FILE *stats26 = NULL; _OSBASE_TRACE(3,("get_disk_data called")); int cmdlen = strlen(id)+31; cmd = malloc(cmdlen); strcpy(cmd, "grep \""); strcat(cmd, id); stats26 = fopen(STATS_FILE_26,"r"); if (stats26) { fclose(stats26); strcat(cmd, " \" "); strcat(cmd, STATS_FILE_26); kernel26 = 1; } else { strcat(cmd, " \" "); strcat(cmd,STATS_FILE); } rc = runcommand(cmd,NULL,&hdout,NULL); if (rc == 0 && hdout != NULL) { *disk = create_disk_data(hdout[0],kernel26); if (*disk != NULL) { res = 1; } } else { _OSBASE_TRACE(1,("get_disk_data: could not run %s (%s)",cmd,hdout)); } freeresultbuf(hdout); free(cmd); _OSBASE_TRACE(3,("get_disk_data exited")); return res; } struct disk_data * create_disk_data(char *ddisk, int kernel26) { long long rio = 0; long long rsect = 0; long long wio = 0; long long wsect = 0; long long use = 0; int sres = 0; int id_length = 0; char dname[IDENTIFIER_LENGTH]; struct disk_data * res = NULL; _OSBASE_TRACE(3,("create_disk_data called")); if (kernel26) { sres = sscanf(ddisk,"%*d %*d %s %lld %*d %lld %*d %lld %*d %lld %*d %*d %lld %*d", dname,&rio,&rsect,&wio,&wsect,&use); } else { sres = sscanf(ddisk,"%*d %*d %*d %s %lld %*d %lld %*d %lld %*d %lld %*d %*d %lld %*d", dname,&rio,&rsect,&wio,&wsect,&use); } if (sres != 6 || sres == EOF) { _OSBASE_TRACE(1,("create_disk_data: could not get data, wrong kernel version or kernel config (CONFIG_BLK_STATS)")); return 0; } #ifdef HD_ONLY if (is_disk(dname)) { #endif res = (struct disk_data *)calloc(1,sizeof(struct disk_data)); // free in free_disk id_length = strlen(dname); if (id_length > 0) { res->id = (char*)malloc(strlen(dname)+1); strncpy(res->id, dname, id_length); *(res->id+strlen(dname)) = '\0'; } else { res->id = '\0'; } // one sect has a size of 512 bytes res->kb_read = rsect * 512; res->kb_transfered = wsect * 512 + res->kb_read; res->read_ios = rio; res->write_ios = wio; res->total_ios = rio + wio; res->io_time = use; _OSBASE_TRACE(3,("name %s, rio %lld, rbw %lld, wio %lld, wbw %lld, use %lld",dname, rio,rsect*512,wio,wsect*512,use)); #ifdef HD_ONLY } #endif _OSBASE_TRACE(3,("create_disk_data exited")); return res; } void free_disk_list(struct disk_list *list) { struct disk_list *list_item = NULL; int count = 0; _OSBASE_TRACE(3,("free_disk_list called")); while (list != NULL) { if (list->disk) free_disk(list->disk); list_item = list; list = list->next; free(list_item); count++; } _OSBASE_TRACE(3,("free_disk_list exited")); } void free_disk(struct disk_data *disk) { _OSBASE_TRACE(3,("free_disk called")); #ifdef CHECK_FCT_PARAM if (disk == NULL) { _OSBASE_TRACE(2,("free_disk: called with NULL arg")); return; } #endif if (disk->id) free(disk->id); free(disk); _OSBASE_TRACE(3,("free_disk exited")); } int is_disk(const char * name) { int res = 0; FILE *f = NULL; int length = strlen(name); char filename[length+17]; char media[10]; _OSBASE_TRACE(3,("is_disk called")); // /proc/ide/<name>/media strcpy(filename,"/proc/ide/"); strcat(filename,name); strcat(filename,"/media"); if ((f = fopen(filename,"r")) != NULL) { fgets(media,9,f); if (strncmp(media,"disk",4) == 0) { res = 1; } else { _OSBASE_TRACE(2,("is_disk: %s is not a disk drive, type is %s - ",name,media)); } fclose(f); } else { _OSBASE_TRACE(1,("is_disk: could not open %s: %s",filename,strerror(errno))); } _OSBASE_TRACE(3,("is_disk ended: res=%d",res)); return res; } #warning TODO: implement reset_counters void reset_counters() { // resetting counters not yet supported //pthread_mutex_lock(&mutex); // nothing //pthread_mutex_unlock(&mutex); } /* ---------------------------------------------------------------------------*/ /* end of OSBase_BlockStorageStatisticalData.c */ /* ---------------------------------------------------------------------------*/ Index: AUTHORS =================================================================== RCS file: /cvsroot/sblim/cmpi-fsvol/AUTHORS,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- AUTHORS 15 Apr 2005 14:28:15 -0000 1.1 +++ AUTHORS 20 Apr 2005 11:40:19 -0000 1.2 @@ -1,2 +1,7 @@ -The cmpi-base provider package was originally written by Heidi Neumann +The cmpi-fsvol provider package was originally written by Heidi Neumann <hei...@de...>. + +Contributions: + +support for class Linux_BlockStorageStatisticalData was done by +Michael Schuele <sch...@de...> ... thx :) |