00001 #ifndef __XRDFILECACHE_INFO_HH__ 00002 #define __XRDFILECACHE_INFO_HH__ 00003 //---------------------------------------------------------------------------------- 00004 // Copyright (c) 2014 by Board of Trustees of the Leland Stanford, Jr., University 00005 // Author: Alja Mrak-Tadel, Matevz Tadel, Brian Bockelman 00006 //---------------------------------------------------------------------------------- 00007 // XRootD is free software: you can redistribute it and/or modify 00008 // it under the terms of the GNU Lesser General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // XRootD is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public License 00018 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 00019 //---------------------------------------------------------------------------------- 00020 00021 #include <stdio.h> 00022 #include <time.h> 00023 #include <assert.h> 00024 00025 #include "XrdSys/XrdSysPthread.hh" 00026 #include "XrdCl/XrdClLog.hh" 00027 #include "XrdCl/XrdClConstants.hh" 00028 #include "XrdCl/XrdClDefaultEnv.hh" 00029 00030 class XrdOssDF; 00031 00032 namespace XrdCl 00033 { 00034 class Log; 00035 } 00036 00037 namespace XrdFileCache 00038 { 00039 class Stats; 00040 00041 //---------------------------------------------------------------------------- 00043 //---------------------------------------------------------------------------- 00044 class Info 00045 { 00046 private: 00047 static unsigned char cfiBIT(int n) { return 1 << n; } 00048 00049 public: 00050 //------------------------------------------------------------------------ 00052 //------------------------------------------------------------------------ 00053 Info(); 00054 00055 //------------------------------------------------------------------------ 00057 //------------------------------------------------------------------------ 00058 ~Info(); 00059 00060 //--------------------------------------------------------------------- 00064 //--------------------------------------------------------------------- 00065 void SetBit(int i); 00066 00067 //--------------------------------------------------------------------- 00071 //--------------------------------------------------------------------- 00072 void ResizeBits(int n); 00073 00074 //--------------------------------------------------------------------- 00080 //--------------------------------------------------------------------- 00081 int Read(XrdOssDF* fp); 00082 00083 //--------------------------------------------------------------------- 00085 //--------------------------------------------------------------------- 00086 void WriteHeader(XrdOssDF* fp); 00087 00088 //--------------------------------------------------------------------- 00090 //--------------------------------------------------------------------- 00091 void AppendIOStat(const Stats* stat, XrdOssDF* fp); 00092 00093 //--------------------------------------------------------------------- 00095 //--------------------------------------------------------------------- 00096 bool IsAnythingEmptyInRng(int firstIdx, int lastIdx) const; 00097 00098 //--------------------------------------------------------------------- 00100 //--------------------------------------------------------------------- 00101 int GetSizeInBytes() const; 00102 00103 //--------------------------------------------------------------------- 00105 //--------------------------------------------------------------------- 00106 int GetSizeInBits() const; 00107 00108 //---------------------------------------------------------------------- 00110 //---------------------------------------------------------------------- 00111 int GetHeaderSize() const; 00112 00113 //--------------------------------------------------------------------- 00115 //--------------------------------------------------------------------- 00116 bool GetLatestDetachTime(time_t& t, XrdOssDF* fp) const; 00117 00118 //--------------------------------------------------------------------- 00120 //--------------------------------------------------------------------- 00121 long long GetBufferSize() const; 00122 00123 //--------------------------------------------------------------------- 00125 //--------------------------------------------------------------------- 00126 bool TestBit(int i) const; 00127 00128 //--------------------------------------------------------------------- 00130 //--------------------------------------------------------------------- 00131 bool IsComplete() const; 00132 00133 //--------------------------------------------------------------------- 00135 //--------------------------------------------------------------------- 00136 void CheckComplete(); 00137 00138 const static char* m_infoExtension; 00139 00140 private: 00141 00142 XrdCl::Log* clLog() const { return XrdCl::DefaultEnv::GetLog(); } 00143 00144 //--------------------------------------------------------------------- 00146 //--------------------------------------------------------------------- 00147 struct AStat 00148 { 00149 time_t DetachTime; 00150 long long BytesDisk; 00151 long long BytesRam; 00152 long long BytesMissed; 00153 }; 00154 00155 int m_version; 00156 long long m_bufferSize; 00157 int m_sizeInBits; 00158 unsigned char *m_buff; 00159 int m_accessCnt; 00160 bool m_complete; 00161 }; 00162 00163 inline bool Info::TestBit(int i) const 00164 { 00165 int cn = i/8; 00166 assert(cn < GetSizeInBytes()); 00167 00168 int off = i - cn*8; 00169 return (m_buff[cn] & cfiBIT(off)) == cfiBIT(off); 00170 } 00171 00172 inline int Info::GetSizeInBytes() const 00173 { 00174 return ((m_sizeInBits -1)/8 + 1); 00175 } 00176 00177 inline int Info::GetSizeInBits() const 00178 { 00179 return m_sizeInBits; 00180 } 00181 00182 inline bool Info::IsComplete() const 00183 { 00184 return m_complete; 00185 } 00186 00187 inline bool Info::IsAnythingEmptyInRng(int firstIdx, int lastIdx) const 00188 { 00189 for (int i = firstIdx; i <= lastIdx; ++i) 00190 if (!TestBit(i)) return true; 00191 00192 return false; 00193 } 00194 00195 inline void Info::CheckComplete() 00196 { 00197 m_complete = !IsAnythingEmptyInRng(0, m_sizeInBits-1); 00198 } 00199 00200 inline void Info::SetBit(int i) 00201 { 00202 int cn = i/8; 00203 assert(cn < GetSizeInBytes()); 00204 00205 int off = i - cn*8; 00206 m_buff[cn] |= cfiBIT(off); 00207 } 00208 00209 inline long long Info::GetBufferSize() const 00210 { 00211 return m_bufferSize; 00212 } 00213 } 00214 #endif