00001 /* 00002 * Copyright (C) 2009, Edmundo Albuquerque de Souza e Silva. 00003 * 00004 * This file may be distributed under the terms of the Q Public License 00005 * as defined by Trolltech AS of Norway and appearing in the file 00006 * LICENSE.QPL included in the packaging of this file. 00007 * 00008 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING 00009 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00010 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 00011 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 00012 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00013 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 00014 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 * 00016 * Thanks: Jose Renato Santos 00017 * 00018 */ 00019 00020 /////////////////////////////////////////////////////////////////////////////// 00021 // storagedevice.h : Defines class CStorageDevice, which 00022 // process I/O request to disk devices 00023 /////////////////////////////////////////////////////////////////////////////// 00024 00025 #ifndef __STORAGEDEVICE_H_ 00026 #define __STORAGEDEVICE_H_ 00027 00028 #include <vsitypesint.h> 00029 #include <vsithread.h> 00030 #include <vsidevice.h> 00031 00032 #include <request.h> 00033 00034 #include <fstream> 00035 #include <sys/time.h> 00036 00037 // Para obter o valor MaxPathSize 00038 #include "RioInterfaceTypes.h" 00039 00040 using namespace std; 00041 class CStorageDevice; 00042 00043 typedef struct 00044 { 00045 char *DeviceName; 00046 int ThreadNumber; 00047 u64 DeviceSize; 00048 CStorageDevice* Device; 00049 } ThreadParameter; 00050 00051 typedef struct 00052 { 00053 int ActiveThreads; // number of active threads when this one was started 00054 StrRequest* Request; 00055 bool Available; 00056 } ThreadRequestParameter; 00057 00058 class CStorageDevice 00059 { 00060 public: 00061 CStorageDevice(); 00062 ~CStorageDevice(); 00063 int Initialize(char* DeviceName); 00064 00065 void Stop(); 00066 void ProcessRequest(StrRequest* Request); 00067 int SectorSize(); 00068 u64 Size(); 00069 00070 // Foi adicionado mais um parametro a esta funcao Initialize 00071 // que cria um log para o StorageDevice: o diretorio onde 00072 // este log deve ser salvo. O valor NULL para este parametro 00073 // indicara, assim como antes, que o log deve ser salvo no 00074 // diretorio onde esta o codigo do storage server. 00075 int Initialize (char* DeviceName, 00076 char* ip, 00077 int nDiskThreads, 00078 double EstimatedParameter, 00079 bool CollectMeasures, 00080 char *LogsDirectory ); 00081 00082 void GetDiskServiceTime( double averageservicetime[301] ); 00083 double GetEstimatedTime(); 00084 void LoadMeasures( char *filename ); 00085 00086 ofstream m_log; 00087 char logname[ MaxPathSize ]; // 200 00088 int logopen; 00089 int m_MaxActiveDiskThreads; 00090 pthread_mutex_t m_Mutex, m_MutexThreads[300]; 00091 pthread_cond_t m_Condition; 00092 pthread_cond_t m_ConditionNew[300]; 00093 pthread_cond_t m_ConditionExitThread; 00094 int m_ActiveDiskThreads; 00095 ThreadRequestParameter m_RequestsForThreads[300]; 00096 00097 double m_EstServiceTime; 00098 double m_DevServiceTime; 00099 double m_EstServiceTimeAccThreads[301]; 00100 double m_DevServiceTimeAccThreads[301]; 00101 00102 double m_EstResponseTime; 00103 double m_DevResponseTime; 00104 double m_EstResponseTimeAccThreads[301]; 00105 double m_DevResponseTimeAccThreads[301]; 00106 unsigned long long int m_NRespTSamplesAccThreads[301]; 00107 00108 double m_AvgServiceTime_Model; 00109 double m_VarServiceTime_Model; 00110 unsigned long long int m_NSamples; 00111 double m_AvgServiceTimeAccThreads[301]; 00112 double m_VarServiceTimeAccThreads[301]; 00113 unsigned long long int m_NSamplesAccThreads[301]; 00114 00115 double m_EstimatedParameter; 00116 bool m_CollectMeasures; 00117 struct timeval m_LastServiceTime; 00118 bool m_StartingServiceInterval; 00119 00120 private: 00121 static void* Thread( void* Param); 00122 static void* BlockThread(void* Param); 00123 CvsiThread m_Thread; 00124 CvsiDevice m_Device; 00125 CRequestQueue m_Queue; 00126 int m_Status; 00127 char* m_Name; 00128 unsigned int m_NumberOfSaveMeasures; 00129 }; 00130 00131 #endif /* __STORAGEDEVICE_H_ */