rm_DiskBufAllocator Class Reference

#include <rm_diskbufferallocator.h>

List of all members.


Detailed Description

Class DiskBufferAllocator handles all configured file systems on a IVD system.

The file systems are detected and statistics about usage is done. This class allocates and releases space from the detected file systems on request by the job.

Author:
Toni Pljakoski, HERMES SoftLab
See also:
<reference>

Definition at line 35 of file rm_diskbufferallocator.h.


Public Member Functions

 rm_DiskBufAllocator ()
virtual ~rm_DiskBufAllocator ()
void DetectFileSystems ()
i_FileSize_t GetMaxDiskBufferSize ()
string ReserveDiskBuffer (i_JobID_t a_jobID, i_FileSize_t a_minJobSize, i_FileSize_t a_maxJobSize, i_FileSize_t &a_allocatedJobSize, i_JobType_t a_jobType)
void ReleaseDiskBuffer (i_JobID_t a_jobID)
string DumpState ()

Public Attributes

 log_CLASSID_m

Private Member Functions

void DetectVolumes ()
void SetNextIndex ()
UInt32_t GetIndexMaxAvailable ()

Private Attributes

vector< rm_DiskBufferm_diskBuffers
UInt32_t m_current

Constructor & Destructor Documentation

rm_DiskBufAllocator::rm_DiskBufAllocator (  ) 

Definition at line 38 of file rm_diskbufferallocator.cpp.

References DetectVolumes(), and log_FUNC_m.

00039     : m_current(0)
00040 {
00041     log_FUNC_m(rm_DiskBufAllocator);
00042     DetectVolumes();
00043 
00044 }

Here is the call graph for this function:

rm_DiskBufAllocator::~rm_DiskBufAllocator (  )  [virtual]

Definition at line 46 of file rm_diskbufferallocator.cpp.

References log_FUNC_m.

00046                                          {
00047     log_FUNC_m(~rm_DiskBufAllocator);
00048 }


Member Function Documentation

void rm_DiskBufAllocator::DetectVolumes (  )  [private]

Definition at line 170 of file rm_diskbufferallocator.cpp.

References cmn_IsMounted(), cmn_IsSpecialName(), dbg_LOW, cmn_Global::dirs, ivd_Directories::diskbuf, evt_ERROR, g_cmn, cmn_FastDirLst::GetNextName(), ivd_BaseException::GetText(), ift_DIR, log_DBG_m, log_ERR_m, log_FUNC_m, log_WriteEvent(), log_WRN_m, and m_diskBuffers.

Referenced by rm_DiskBufAllocator().

00170                                        {
00171     log_FUNC_m(DetectVolumes);
00172 
00173     try {
00174         //check if g_cmn.dirs.diskbuf is on it own file system
00175         if (cmn_IsMounted(g_cmn.dirs.diskbuf)){
00176             log_DBG_m(dbg_LOW, g_cmn.dirs.diskbuf <<
00177                                 " is mounted on seperate file system.");
00178             //add to rm_DiskBuffer
00179             m_diskBuffers.push_back(rm_DiskBuffer(""));
00180         };
00181     } catch (ivd_SysError& ise) {
00182         log_ERR_m(ise);
00183 
00184         ostringstream sstr;
00185         sstr
00186             << "Failed to open Diskbuffer File System "
00187             << ise.GetText();
00188         log_WriteEvent(evt_ERROR, sstr.str());
00189 
00190         throw;
00191     }
00192     //go through all other entries in diskbuffer
00193     try {
00194         ivd_GenInode_t node;
00195         ivd_FileType_e type;
00196         string         name;
00197         cmn_FastDirLst dirList(g_cmn.dirs.diskbuf);
00198         while ((name = dirList.GetNextName(node, type)) != "") {
00199             if (cmn_IsSpecialName(name)) {
00200                 //ignore
00201                 continue;
00202             }
00203             else if (type == ift_DIR){
00204                 log_DBG_m(dbg_LOW, "Found directory: " << name);
00205                 //check if directory is on it own file system
00206                 cmn_Path dir = g_cmn.dirs.diskbuf + name;
00207                 if (cmn_IsMounted(dir)){
00208                     log_DBG_m(dbg_LOW, dir <<
00209                         " is mounted on separate file system.");
00210                     //add to rm_DiskBuffer
00211                     m_diskBuffers.push_back(rm_DiskBuffer(name));
00212                 };
00213             }
00214         }
00215     }
00216     catch (ivd_SysError& ise) {
00217         log_DBG_m(dbg_LOW,
00218             ise << " ignored while doing dirList on " <<
00219             g_cmn.dirs.diskbuf);
00220     }
00221     if ( m_diskBuffers.empty() ) {
00222         //use std diskbuffer even if it is not mounted
00223         log_WRN_m("Using diskbuffer " <<
00224                   g_cmn.dirs.diskbuf  <<
00225                   ", but it is not mounted.");
00226         //add to rm_DiskBuffer
00227         m_diskBuffers.push_back(rm_DiskBuffer(""));
00228     }
00229 }

Here is the call graph for this function:

Here is the caller graph for this function:

void rm_DiskBufAllocator::SetNextIndex (  )  [private]

Definition at line 142 of file rm_diskbufferallocator.cpp.

References m_current, and m_diskBuffers.

Referenced by ReserveDiskBuffer().

00142                                       {
00143     m_current++;
00144     if (m_current == m_diskBuffers.size()){
00145         m_current = 0;
00146     }
00147 }

Here is the caller graph for this function:

UInt32_t rm_DiskBufAllocator::GetIndexMaxAvailable (  )  [private]

void rm_DiskBufAllocator::DetectFileSystems (  ) 

i_FileSize_t rm_DiskBufAllocator::GetMaxDiskBufferSize (  ) 

Definition at line 53 of file rm_diskbufferallocator.cpp.

References dbg_LOW, log_DBG_m, log_FUNC_m, and m_diskBuffers.

Referenced by i_ResourceManager_i::GetMaxDiskBufferSize().

00053                                                       {
00054     log_FUNC_m(GetMaxDiskBufferSize);
00055 
00056     UInt64_t maximum (0);
00057     for (UInt32_t i(0); i < m_diskBuffers.size(); i++){
00058         if (m_diskBuffers[i].GetSize() > maximum){
00059             maximum = m_diskBuffers[i].GetSize();
00060         }
00061     }
00062     log_DBG_m(dbg_LOW, "Max disk buffer size is " << maximum);
00063     return maximum;
00064 }

Here is the caller graph for this function:

string rm_DiskBufAllocator::ReserveDiskBuffer ( i_JobID_t  a_jobID,
i_FileSize_t  a_minJobSize,
i_FileSize_t  a_maxJobSize,
i_FileSize_t a_allocatedJobSize,
i_JobType_t  a_jobType 
)

Definition at line 67 of file rm_diskbufferallocator.cpp.

References dbg_DETAIL, DumpState(), log_DBG_m, log_FUNC_m, m_current, m_diskBuffers, and SetNextIndex().

Referenced by i_ResourceManager_i::ReserveDiskBuffer().

00071                                                                       {
00072     log_FUNC_m(ReserveDiskBuffer);
00073 
00074     log_DBG_m(dbg_DETAIL, DumpState());//to be deleted for release
00075     UInt32_t current(m_current);
00076 
00077 
00078     UInt64_t maxAvail(0); //max amount of space available
00079     UInt32_t maxIndex(0); //index of filesystem with max amount available
00080 
00081     while (1){
00082         UInt64_t available = m_diskBuffers[m_current].GetAvailable();
00083 
00084         log_DBG_m(dbg_DETAIL, "m_current:" << m_current <<
00085             ", m_diskBuffers[m_current].GetSize():" << available );
00086         if (available > maxAvail){
00087             maxAvail = available;
00088             maxIndex = m_current;
00089         }
00090 
00091         if (a_maxJobSize > available){
00092             SetNextIndex();
00093             if (current == m_current){
00094                 //checked all diskbuffer
00095                 //none has enough space
00096                 break;
00097             }
00098         } else {
00099             rm_JobStat jobStat( a_jobID,
00100                                 a_maxJobSize,
00101                                 a_jobType);
00102 
00103             m_diskBuffers[m_current].InsertJob(jobStat);
00104             UInt32_t allocatedIndex(m_current);
00105             SetNextIndex();
00106             log_DBG_m(dbg_DETAIL, DumpState()); //to be deleted for release
00107             a_allocatedJobSize = a_maxJobSize;
00108             return (m_diskBuffers[allocatedIndex].GetFSName());
00109         }
00110     }
00111 
00112     log_DBG_m(dbg_DETAIL, "No space for max diskbuffer. maxAvail:" << maxAvail
00113         << ", maxIndex:" << maxIndex);
00114 
00115     if ( a_minJobSize >= a_maxJobSize ){
00116         //nothing more I can do
00117         log_DBG_m(dbg_DETAIL,"Job:" << a_jobID <<
00118             " requested equal min/max diskbuffer");
00119         a_allocatedJobSize = 0;
00120         return "";
00121     }
00122     else if (a_minJobSize < maxAvail){
00123 
00124         log_DBG_m(dbg_DETAIL, "Allocated index:" << maxIndex); //to be deleted for release
00125 
00126         a_allocatedJobSize = m_diskBuffers[maxIndex].GetAvailable();
00127         rm_JobStat jobStat( a_jobID,
00128                             a_allocatedJobSize,
00129                             a_jobType);
00130         m_diskBuffers[maxIndex].InsertJob(jobStat);
00131 
00132         log_DBG_m(dbg_DETAIL, DumpState());//to be deleted for release
00133         return (m_diskBuffers[maxIndex].GetFSName());
00134     }
00135     else {
00136         log_DBG_m(dbg_DETAIL, "No space for min diskbuffer");
00137         a_allocatedJobSize = 0;
00138         return "";
00139     }
00140 }

Here is the call graph for this function:

Here is the caller graph for this function:

void rm_DiskBufAllocator::ReleaseDiskBuffer ( i_JobID_t  a_jobID  ) 

Definition at line 151 of file rm_diskbufferallocator.cpp.

References dbg_DETAIL, DumpState(), ie_NOTFOUND, ivd_Error, log_DBG_m, log_FUNC_m, and m_diskBuffers.

Referenced by i_ResourceManager_i::ReleaseDiskBuffer().

00151                                                             {
00152     log_FUNC_m(ReleaseDiskBuffer);
00153     log_DBG_m(dbg_DETAIL, DumpState());//to be deleted for release
00154 
00155     bool found(false);
00156     for (UInt32_t i(0); i < m_diskBuffers.size(); i++){
00157         found = m_diskBuffers[i].FindJob(a_jobID);
00158         if (found){
00159             m_diskBuffers[i].RemoveJob(a_jobID);
00160             break;
00161         }
00162     }
00163     if (!found){
00164         throw ivd_Error(ie_NOTFOUND, "Can not release diskbuffer. Job not found.");
00165     }
00166 
00167     log_DBG_m(dbg_DETAIL, DumpState());//to be deleted for release
00168 }

Here is the call graph for this function:

Here is the caller graph for this function:

string rm_DiskBufAllocator::DumpState (  ) 

Definition at line 231 of file rm_diskbufferallocator.cpp.

References log_FUNC_m, and m_diskBuffers.

Referenced by i_ResourceManager_i::i_ResourceManager_i(), ReleaseDiskBuffer(), and ReserveDiskBuffer().

00231                                      {
00232     log_FUNC_m(DumpState);
00233     ostringstream msg;
00234     for (UInt32_t i(0); i < m_diskBuffers.size(); i++){
00235         msg << m_diskBuffers[i].DumpState();
00236     }
00237     return msg.str();
00238 }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 43 of file rm_diskbufferallocator.h.

Referenced by ReserveDiskBuffer(), and SetNextIndex().

Definition at line 63 of file rm_diskbufferallocator.h.


The documentation for this class was generated from the following files:

Generated on Mon Feb 27 19:46:18 2012 for OPENARCHIVE by  doxygen 1.5.6