Public Member Functions | Public Attributes | Private Member Functions | Private Attributes

rm_DiskBufAllocator Class Reference

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

#include <rm_diskbufferallocator.h>

List of all members.

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

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 49 of file rm_diskbufferallocator.h.


Constructor & Destructor Documentation

rm_DiskBufAllocator::rm_DiskBufAllocator (  ) 

Definition at line 52 of file rm_diskbufferallocator.cpp.

References DetectVolumes(), and log_FUNC_m.

Here is the call graph for this function:

rm_DiskBufAllocator::~rm_DiskBufAllocator (  )  [virtual]

Definition at line 60 of file rm_diskbufferallocator.cpp.

References log_FUNC_m.


Member Function Documentation

void rm_DiskBufAllocator::DetectFileSystems (  ) 
void rm_DiskBufAllocator::DetectVolumes (  )  [private]

Definition at line 184 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().

                                       {
    log_FUNC_m(DetectVolumes);

    try {
        //check if g_cmn.dirs.diskbuf is on it own file system
        if (cmn_IsMounted(g_cmn.dirs.diskbuf)){
            log_DBG_m(dbg_LOW, g_cmn.dirs.diskbuf <<
                                " is mounted on seperate file system.");
            //add to rm_DiskBuffer
            m_diskBuffers.push_back(rm_DiskBuffer(""));
        };
    } catch (ivd_SysError& ise) {
        log_ERR_m(ise);

        ostringstream sstr;
        sstr
            << "Failed to open Diskbuffer File System "
            << ise.GetText();
        log_WriteEvent(evt_ERROR, sstr.str());

        throw;
    }
    //go through all other entries in diskbuffer
    try {
        ivd_GenInode_t node;
        ivd_FileType_e type;
        string         name;
        cmn_FastDirLst dirList(g_cmn.dirs.diskbuf);
        while ((name = dirList.GetNextName(node, type)) != "") {
            if (cmn_IsSpecialName(name)) {
                //ignore
                continue;
            }
            else if (type == ift_DIR){
                log_DBG_m(dbg_LOW, "Found directory: " << name);
                //check if directory is on it own file system
                cmn_Path dir = g_cmn.dirs.diskbuf + name;
                if (cmn_IsMounted(dir)){
                    log_DBG_m(dbg_LOW, dir <<
                        " is mounted on separate file system.");
                    //add to rm_DiskBuffer
                    m_diskBuffers.push_back(rm_DiskBuffer(name));
                };
            }
        }
    }
    catch (ivd_SysError& ise) {
        log_DBG_m(dbg_LOW,
            ise << " ignored while doing dirList on " <<
            g_cmn.dirs.diskbuf);
    }
    if ( m_diskBuffers.empty() ) {
        //use std diskbuffer even if it is not mounted
        log_WRN_m("Using diskbuffer " <<
                  g_cmn.dirs.diskbuf  <<
                  ", but it is not mounted.");
        //add to rm_DiskBuffer
        m_diskBuffers.push_back(rm_DiskBuffer(""));
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

string rm_DiskBufAllocator::DumpState (  ) 

Definition at line 245 of file rm_diskbufferallocator.cpp.

References log_FUNC_m, and m_diskBuffers.

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

                                     {
    log_FUNC_m(DumpState);
    ostringstream msg;
    for (UInt32_t i(0); i < m_diskBuffers.size(); i++){
        msg << m_diskBuffers[i].DumpState();
    }
    return msg.str();
}

Here is the caller graph for this function:

UInt32_t rm_DiskBufAllocator::GetIndexMaxAvailable (  )  [private]
i_FileSize_t rm_DiskBufAllocator::GetMaxDiskBufferSize (  ) 

Definition at line 67 of file rm_diskbufferallocator.cpp.

References dbg_LOW, log_DBG_m, log_FUNC_m, and m_diskBuffers.

Referenced by i_ResourceManager_i::GetMaxDiskBufferSize().

                                                      {
    log_FUNC_m(GetMaxDiskBufferSize);

    UInt64_t maximum (0);
    for (UInt32_t i(0); i < m_diskBuffers.size(); i++){
        if (m_diskBuffers[i].GetSize() > maximum){
            maximum = m_diskBuffers[i].GetSize();
        }
    }
    log_DBG_m(dbg_LOW, "Max disk buffer size is " << maximum);
    return maximum;
}

Here is the caller graph for this function:

void rm_DiskBufAllocator::ReleaseDiskBuffer ( i_JobID_t  a_jobID  ) 

Definition at line 165 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().

                                                            {
    log_FUNC_m(ReleaseDiskBuffer);
    log_DBG_m(dbg_DETAIL, DumpState());//to be deleted for release

    bool found(false);
    for (UInt32_t i(0); i < m_diskBuffers.size(); i++){
        found = m_diskBuffers[i].FindJob(a_jobID);
        if (found){
            m_diskBuffers[i].RemoveJob(a_jobID);
            break;
        }
    }
    if (!found){
        throw ivd_Error(ie_NOTFOUND, "Can not release diskbuffer. Job not found.");
    }

    log_DBG_m(dbg_DETAIL, DumpState());//to be deleted for release
}

Here is the call graph for this function:

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 81 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().

                                                                      {
    log_FUNC_m(ReserveDiskBuffer);

    log_DBG_m(dbg_DETAIL, DumpState());//to be deleted for release
    UInt32_t current(m_current);


    UInt64_t maxAvail(0); //max amount of space available
    UInt32_t maxIndex(0); //index of filesystem with max amount available

    while (1){
        UInt64_t available = m_diskBuffers[m_current].GetAvailable();

        log_DBG_m(dbg_DETAIL, "m_current:" << m_current <<
            ", m_diskBuffers[m_current].GetSize():" << available );
        if (available > maxAvail){
            maxAvail = available;
            maxIndex = m_current;
        }

        if (a_maxJobSize > available){
            SetNextIndex();
            if (current == m_current){
                //checked all diskbuffer
                //none has enough space
                break;
            }
        } else {
            rm_JobStat jobStat( a_jobID,
                                a_maxJobSize,
                                a_jobType);

            m_diskBuffers[m_current].InsertJob(jobStat);
            UInt32_t allocatedIndex(m_current);
            SetNextIndex();
            log_DBG_m(dbg_DETAIL, DumpState()); //to be deleted for release
            a_allocatedJobSize = a_maxJobSize;
            return (m_diskBuffers[allocatedIndex].GetFSName());
        }
    }

    log_DBG_m(dbg_DETAIL, "No space for max diskbuffer. maxAvail:" << maxAvail
        << ", maxIndex:" << maxIndex);

    if ( a_minJobSize >= a_maxJobSize ){
        //nothing more I can do
        log_DBG_m(dbg_DETAIL,"Job:" << a_jobID <<
            " requested equal min/max diskbuffer");
        a_allocatedJobSize = 0;
        return "";
    }
    else if (a_minJobSize < maxAvail){

        log_DBG_m(dbg_DETAIL, "Allocated index:" << maxIndex); //to be deleted for release

        a_allocatedJobSize = m_diskBuffers[maxIndex].GetAvailable();
        rm_JobStat jobStat( a_jobID,
                            a_allocatedJobSize,
                            a_jobType);
        m_diskBuffers[maxIndex].InsertJob(jobStat);

        log_DBG_m(dbg_DETAIL, DumpState());//to be deleted for release
        return (m_diskBuffers[maxIndex].GetFSName());
    }
    else {
        log_DBG_m(dbg_DETAIL, "No space for min diskbuffer");
        a_allocatedJobSize = 0;
        return "";
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rm_DiskBufAllocator::SetNextIndex (  )  [private]

Definition at line 156 of file rm_diskbufferallocator.cpp.

References m_current, and m_diskBuffers.

Referenced by ReserveDiskBuffer().

                                      {
    m_current++;
    if (m_current == m_diskBuffers.size()){
        m_current = 0;
    }
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 77 of file rm_diskbufferallocator.h.

Definition at line 57 of file rm_diskbufferallocator.h.

Referenced by ReserveDiskBuffer(), and SetNextIndex().


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