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

bea_Volume Class Reference
[IVD Back-End Agent]

#include <bea_volume.h>

Inheritance diagram for bea_Volume:
Inheritance graph
[legend]
Collaboration diagram for bea_Volume:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 bea_Volume (bea_Medium *const a_medium, UInt32_t a_volNumber, UInt32_t a_size)
virtual ~bea_Volume ()
UInt32_t GetSize () const
 Declared volume size in MB.
UInt32_t GetVolumeNumber () const
virtual UInt32_t GetPosition ()=0
UInt32_t GetEstimTotalSize ()
 Estimated size w/ compression in MB.
UInt32_t GetEstimRemainingSize ()
 Estimated available space w/ compression in MB.
bea_MediumGetMedium () const
void Write (const UInt8_t *a_buf)
void WriteVolHdr (const UInt8_t *a_buf)
void Read (UInt8_t *a_buf)
void ReadVolHdr (UInt8_t *a_buf)
virtual void Erase ()=0
virtual void WriteFileMarks (UInt32_t a_count=1)=0
virtual void Flush ()=0
virtual void SeekEOD ()=0
virtual void Rewind ()=0
virtual void SeekBlock (UInt32_t a_block)=0
virtual void SeekFileMark (Int32_t a_relativeFM)=0
void InvalidateEOD ()
 Class "knows" if it is at the end of the volume or not.
void Init (const bea_VolInfo_t &a_volInfo)
bool MustDumpFRI (UInt32_t *a_checkOffset=NULL)
UInt32_t GetStartOfDataPosition () const
bea_VolumeType GetVolumeType ()
UInt32_t GetBlockSize ()
void SetBlockSize (UInt32_t a_blkSize)
void OverrideIDs (const cmn_UUID_t &a_volID, const cmn_UUID_t &a_poolID, const cmn_UUID_t &a_partID)
cmn_UUID_tGetVolumeID ()
cmn_UUID_tGetPoolID ()
cmn_UUID_tGetPartitionID ()
const bea_VolInfo_tGetVolumeInfo ()
bool IsSysVolume ()
UInt64_t GetJobID () const
bool DoMediumLogging () const
void ReadVolInfoFromHeader ()

Protected Member Functions

virtual void WriteRaw (const UInt8_t *a_buf, UInt32_t a_size)=0
virtual void ReadRaw (UInt8_t *a_buf, UInt32_t a_size)=0
virtual void ReadEstimSizes ()=0
void SetDeclaredSize (UInt32_t a_size)
void InvalidateSizes ()
void SetEstimatedSizes (UInt32_t a_size, UInt32_t a_free)

Protected Attributes

bea_Medium *const m_medium_p
bool m_atEOD

Private Member Functions

void ReadVolInfoFromMediumMem ()
void UpdateMediumMem (const bea_VolInfo_t &a_volInfo)

Private Attributes

 log_CLASSID_m
UInt32_t m_volNumber
UInt32_t m_size
bool m_validSizes
UInt32_t m_estimSize
UInt32_t m_estimFree
bool m_validVolInfo
 Is volume info record valid?
bea_VolInfo_t m_volInfo

Detailed Description

Definition at line 109 of file bea_volume.h.


Constructor & Destructor Documentation

bea_Volume::bea_Volume ( bea_Medium *const   a_medium,
UInt32_t  a_volNumber,
UInt32_t  a_size 
)

Definition at line 55 of file bea_volume.cpp.

References ie_INVALID_ARG, ivd_Error, log_FUNC_A_m, m_size, m_volNumber, and NULL.

  : m_medium_p(a_medium),
    m_atEOD(false),
    m_volNumber(a_volNumber),
    m_size(a_size),
    m_validSizes(false),
    m_estimSize(0),
    m_estimFree(0),
    m_validVolInfo(false) {

    log_FUNC_A_m(bea_Volume,
        "num: " << m_volNumber << " size: " << m_size);

    if (a_medium == NULL) {
        throw ivd_Error(ie_INVALID_ARG, "a_medium may not be NULL.");
    }
}

bea_Volume::~bea_Volume (  )  [virtual]

Definition at line 78 of file bea_volume.cpp.

References log_FUNC_m.


Member Function Documentation

bool bea_Volume::DoMediumLogging (  )  const
virtual void bea_Volume::Erase (  )  [pure virtual]
virtual void bea_Volume::Flush (  )  [pure virtual]

Implemented in bea_DiskVolume, and bea_TapeVolume.

Referenced by bea_FRI::CopyFromDiskToMedium(), bea_MigrationThread::Migrate(), and bea_DupWriteThread::WriteMedVolume().

Here is the caller graph for this function:

UInt32_t bea_Volume::GetBlockSize (  ) 
UInt32_t bea_Volume::GetEstimRemainingSize (  ) 

Estimated available space w/ compression in MB.

Estimated remaining capacity in MB.

Definition at line 118 of file bea_volume.cpp.

References log_FUNC_m, m_estimFree, m_validSizes, and ReadEstimSizes().

Referenced by bea_DupWriteThread::AppendVolume(), bea_MigrationThread::FRIVolumeEnd(), bea_MigrationThread::FRIVolumeStart(), MustDumpFRI(), and i_BackEndAgent_i::UpdateVolumeUsed().

Here is the call graph for this function:

Here is the caller graph for this function:

UInt32_t bea_Volume::GetEstimTotalSize (  ) 

Estimated size w/ compression in MB.

Estimated total capacity in MB.

Definition at line 105 of file bea_volume.cpp.

References log_FUNC_m, m_estimSize, m_validSizes, and ReadEstimSizes().

Referenced by bea_DupWriteThread::AppendVolume(), MustDumpFRI(), and i_BackEndAgent_i::UpdateVolumeUsed().

Here is the call graph for this function:

Here is the caller graph for this function:

UInt64_t bea_Volume::GetJobID (  )  const
bea_Medium * bea_Volume::GetMedium (  )  const

Definition at line 84 of file bea_volume.cpp.

References m_medium_p.

Referenced by bea_VolumeReader::Run(), and bea_MigrationThread::WriteBlock().

                                         {
    return m_medium_p;
}

Here is the caller graph for this function:

cmn_UUID_t & bea_Volume::GetPartitionID (  ) 

Definition at line 301 of file bea_volume.cpp.

References GetVolumeType(), ie_NOT_SUPPORTED, ivd_Error, log_FUNC_m, m_validVolInfo, m_volInfo, bea_VolInfo_t::partID, ReadVolInfoFromMediumMem(), and VOL_IVD.

Referenced by bea_FRI::CreateFRI(), bea_MigrationThread::Migrate(), i_BackEndAgent_i::ReadIDs(), and i_BackEndAgent_i::VerifyIDs().

                                       {
    if (!m_validVolInfo) {
        ReadVolInfoFromMediumMem();
    }
    if (GetVolumeType() != VOL_IVD) {
        log_FUNC_m(GetPartitionID);
        throw ivd_Error(ie_NOT_SUPPORTED, "Volume type is not HSM.");
    }
    return m_volInfo.partID;
}

Here is the call graph for this function:

Here is the caller graph for this function:

cmn_UUID_t & bea_Volume::GetPoolID (  ) 

Definition at line 288 of file bea_volume.cpp.

References GetVolumeType(), ie_NOT_SUPPORTED, ivd_Error, log_FUNC_m, m_validVolInfo, m_volInfo, bea_VolInfo_t::poolID, ReadVolInfoFromMediumMem(), and VOL_IVD.

Referenced by bea_FRI::CreateFRI(), bea_MigrationThread::Migrate(), i_BackEndAgent_i::ReadIDs(), and i_BackEndAgent_i::VerifyIDs().

                                  {
    if (!m_validVolInfo) {
        ReadVolInfoFromMediumMem();
    }
    if (GetVolumeType() != VOL_IVD) {
        log_FUNC_m(GetPoolID);
        throw ivd_Error(ie_NOT_SUPPORTED, "Volume type is not HSM.");
    }
    return m_volInfo.poolID;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual UInt32_t bea_Volume::GetPosition (  )  [pure virtual]
UInt32_t bea_Volume::GetSize (  )  const

Declared volume size in MB.

Definition at line 96 of file bea_volume.cpp.

References m_size.

Referenced by bea_DupWriteThread::AppendVolume(), bea_DiskVolume::ReadEstimSizes(), bea_DiskVolume::ReadVolInfo(), and bea_DiskVolume::WriteVolInfo().

                                   {
    return m_size;
}

Here is the caller graph for this function:

UInt32_t bea_Volume::GetStartOfDataPosition (  )  const

Definition at line 570 of file bea_volume.cpp.

Referenced by bea_MigrationThread::CheckFRI(), bea_FRI::CloseVolume(), bea_FRI::CreateFRI(), bea_FRIThread::ProcessFromDataVol(), and bea_FRI::ReadFRIStart().

                                                  {
    // The position immediatelly after the volume header.
    return 3;
}

Here is the caller graph for this function:

cmn_UUID_t & bea_Volume::GetVolumeID (  ) 
const bea_VolInfo_t & bea_Volume::GetVolumeInfo (  ) 

Definition at line 314 of file bea_volume.cpp.

References m_validVolInfo, m_volInfo, and ReadVolInfoFromMediumMem().

Here is the call graph for this function:

UInt32_t bea_Volume::GetVolumeNumber (  )  const
bea_VolumeType bea_Volume::GetVolumeType (  ) 

Definition at line 214 of file bea_volume.cpp.

References m_validVolInfo, m_volInfo, ReadVolInfoFromMediumMem(), and bea_VolInfo_t::type.

Referenced by GetBlockSize(), GetPartitionID(), GetPoolID(), GetVolumeID(), Init(), i_BackEndAgent_i::ReadIDs(), and i_BackEndAgent_i::VerifyIDs().

Here is the call graph for this function:

Here is the caller graph for this function:

void bea_Volume::Init ( const bea_VolInfo_t a_volInfo  ) 

Definition at line 344 of file bea_volume.cpp.

References bea_VolInfo_t::accessNum, bea_VolInfo_t::accessTime, bea_VolInfo_t::appendNum, bea_VolInfo_t::appendTime, bea_VolInfo_t::blockSize, bea_Medium::ChangeVolume(), dbg_LOW, dbg_NORM, cmn_File::DeleteFile(), df_verMaj_c, df_verMin_c, df_volFlagSystem_c, df_VOLHDR_REC_SIZE, cmn_Global::dirs, Erase(), ivd_Directories::fri, g_cmn, bea_Medium::GetCurVolNumber(), ivd_BaseException::GetError(), GetPosition(), ivd_Versions::GetProductVersionShort(), GetVolumeType(), ie_BEA_INIT, ie_MEDIUM_BLANK, ie_MEDIUM_EOD, bea_Medium::IsWORM(), ivd_Error, log_DBG_m, log_FUNC_m, m_medium_p, ivd_Product::m_nameShort, m_validVolInfo, m_volInfo, m_volNumber, bea_VolInfo_t::medVolID, bea_VolInfo_t::owriteNum, bea_VolInfo_t::owriteTime, bea_VolInfo_t::partID, bea_VolInfo_t::poolID, cmn_Global::prod, ReadVolInfoFromHeader(), Rewind(), SeekEOD(), SetBlockSize(), bea_VolInfo_t::sysVolNum, cmn_UUID_t::ToString(), UpdateMediumMem(), VOL_IVD, Write(), WriteFileMarks(), df_Packer::WriteRecMedVolHdr(), and WriteVolHdr().

                                                    {
    log_FUNC_m(Init);

    log_DBG_m(dbg_LOW,
        "** Initializing medium volume " << endl <<
        "Volume ID: " << a_volInfo.medVolID << endl <<
        "Pool ID  : " << a_volInfo.poolID << endl <<
        "Part ID  : " << a_volInfo.partID << endl <<
        "Vol #    : " << m_volNumber << endl <<
        "SysVol on: " << a_volInfo.sysVolNum << endl <<
        "Blk size : " << a_volInfo.blockSize);

    try {
        if (m_medium_p->GetCurVolNumber() != m_volNumber) {
            m_medium_p->ChangeVolume(m_volNumber, 0);
        }
        else {
            Rewind();
        }

        ReadVolInfoFromHeader();
        if (GetVolumeType() == VOL_IVD) {
            cmn_Path fri = g_cmn.dirs.fri + m_volInfo.medVolID.ToString();
            log_DBG_m(dbg_LOW, "Trying to delete old FRI file: " << fri);
            try {
                cmn_File::DeleteFile(fri);
            }
            catch (...) {
                // Ignore all errors
            }
        }
    }
    catch (ivd_Error &ie) {
        if (ie.GetError() == ie_MEDIUM_BLANK ||
            ie.GetError() == ie_MEDIUM_EOD ||
            ie.GetError() == ie_MEDIUM_EOM) {
            log_DBG_m(dbg_NORM, "Blank volume. Just proceed.");
        }
        else {
            log_DBG_m(dbg_NORM,
                "Init volume: Got error on seek: " << ie);
            throw;
        }
    }

    if (m_medium_p->IsWORM()) {
        // Verify volume type and prevent initialization of non-blank media.
        if (GetVolumeType() != VOL_BLANK) {
            log_MARKLINE_m;
            throw ivd_Error(ie_BEA_INIT, "WORM medium: volume is not blank.");
        }
    }

    // Invalidate contents of volume info.
    m_validVolInfo = false;
    SetBlockSize(a_volInfo.blockSize);

    if (m_medium_p->IsWORM()) {
        // Worm media doesn't like to be erased on any position.
        // Writing new blocks will do.
        log_DBG_m(dbg_NORM, "WORM medium. Won't use Erase(). Position to EOD.");
        // Sony AIT WORM drive doesn't "know" that it is at the end of the volume
        // so it is necessary to seek to EOD on empty volume.
        SeekEOD();
    }
    else {
        Rewind();
        Erase();
    }

    {
        vector<UInt8_t> hdrBlock(df_VOLHDR_REC_SIZE, 0);

        ostringstream appStr;
        appStr
            << g_cmn.prod.m_nameShort << " "
            << ivd_Versions::GetProductVersionShort() << "/"
            << df_verMaj_c << "." << df_verMin_c;

        df_Packer::WriteRecMedVolHdr(
            a_volInfo.medVolID,
            a_volInfo.poolID,
            a_volInfo.partID,
            m_volNumber, /* We need ECMA partition # here (starts from 1) */
            a_volInfo.blockSize,
            a_volInfo.accessNum,
            a_volInfo.appendNum,
            a_volInfo.owriteNum,
            a_volInfo.accessTime,
            a_volInfo.appendTime,
            a_volInfo.owriteTime,
            appStr.str(),
            (a_volInfo.sysVolNum == m_volNumber) ? df_volFlagSystem_c : 0,
            a_volInfo.sysVolNum,

            &(hdrBlock[0]),
            (UInt32_t)(df_VOLHDR_REC_SIZE));

        WriteVolHdr(&(hdrBlock[0]));
        {
            log_DBG_m(dbg_NORM, "HSM: Writing second header block for future use.");

            vector<UInt8_t> emptyBlock(a_volInfo.blockSize, 0);
            Write(&(emptyBlock[0]));
        }

        log_DBG_m(dbg_NORM, "HSM: Writing filemark after reserved block.");
        WriteFileMarks(1);

        log_DBG_m(dbg_NORM, "Position on medium after volume header: " << GetPosition());
    }

    UpdateMediumMem(a_volInfo);

    log_DBG_m(dbg_LOW, "Medium volume initialized");
}

Here is the call graph for this function:

void bea_Volume::InvalidateEOD (  ) 

Class "knows" if it is at the end of the volume or not.

By invoking this call it resets this internal state.

Definition at line 178 of file bea_volume.cpp.

References log_FUNC_m, and m_atEOD.

Referenced by bea_TapeMedium::ChangeVolume(), bea_TapeVolume::Erase(), bea_TapeVolume::Rewind(), bea_TapeVolume::SeekBlock(), bea_DiskVolume::SeekBlock(), bea_TapeVolume::SeekFileMark(), and bea_DiskVolume::SeekFileMark().

Here is the caller graph for this function:

void bea_Volume::InvalidateSizes (  )  [protected]
bool bea_Volume::IsSysVolume (  ) 

Definition at line 323 of file bea_volume.cpp.

References m_validVolInfo, m_volInfo, ReadVolInfoFromMediumMem(), and bea_VolInfo_t::sysVol.

Referenced by bea_FRI::ReadFRI(), and bea_FRIThread::ReadFromSysVol().

Here is the call graph for this function:

Here is the caller graph for this function:

bool bea_Volume::MustDumpFRI ( UInt32_t a_checkOffset = NULL  ) 

Definition at line 463 of file bea_volume.cpp.

References cmn_GetEnvVariable(), cmn_Str2Num(), dbg_DETAIL, dbg_LOW, dbg_NORM, cmn_Global::dirs, ivd_Directories::fri, g_cmn, GetBlockSize(), ivd_BaseException::GetError(), GetEstimRemainingSize(), GetEstimTotalSize(), bea_Medium::GetMediumFamily(), GetVolumeID(), log_DBG_m, log_FUNC_m, log_WRN_m, m_medium_p, NULL, and cmn_File::StatF().

Referenced by bea_FRI::CreateFRI(), and bea_MigrationThread::Migrate().

                                                    {
    log_FUNC_m(MustDumpFRI);

    //parse env variable, should be in MB
    static const char* const FriTapeSafetyBuf_c("HSM_FRI_SAFETYBUF_TAPE");
    string friTapeSafetyBuf = cmn_GetEnvVariable(FriTapeSafetyBuf_c);

    UInt32_t friTapeSafetyBufNum(100*1024);
    UInt32_t parsedValue = cmn_Str2Num(friTapeSafetyBuf);

    log_DBG_m(dbg_NORM, "friTapeSafetyBuf: " << friTapeSafetyBuf <<
        ",  parsedValue:" << parsedValue );

    if (parsedValue*1024 < friTapeSafetyBufNum){
        if (parsedValue > 0){
            //ignore less than minimum
            log_WRN_m("HSM_FRI_SAFETYBUF_TAPE was set to " <<
                parsedValue << " MB. Minimum value is " << friTapeSafetyBuf <<
                " MB.");
        }
    }
    else {
        friTapeSafetyBufNum = parsedValue*1024;
        log_DBG_m(dbg_LOW, "Using friTapeSafetyBuf:" <<
                                parsedValue  << "KB");
    };

    // Safety buffer for disk media is much smaller than for tape media
    static const UInt32_t c_FriTapeSafetyBuf(friTapeSafetyBufNum);  // in KB 100 MB by default
    static const UInt32_t c_FriDiskSafetyBuf(5*1024);   // in KB - 5 MB by default
    UInt32_t safetyBuf;

    if (m_medium_p->GetMediumFamily() == bmf_DISK) {
        safetyBuf = c_FriDiskSafetyBuf;
    }
    else {
        safetyBuf = c_FriTapeSafetyBuf;
    };

    UInt64_t friSize(0); // in KB

    try {
        cmn_File friFile(g_cmn.dirs.fri + GetVolumeID().ToString());
        ivd_FileInfo_t  friInfo;
        friFile.StatF(friInfo);
        friSize = (friInfo.size / 1024);
    }
    catch (const ivd_SysError &se) {
        if (se.GetError() == ENOENT) {
            // FRI does not exist yet - that's fine
            log_DBG_m(dbg_DETAIL, "No FRI yet.");
        }
        else {
            throw;
        }
    };

    // Convert from MB to kB
    UInt32_t remain = GetEstimRemainingSize() * 1024;
    UInt32_t total  = GetEstimTotalSize() * 1024;

    log_DBG_m(dbg_LOW, "FRI Capacity Check:" << endl <<
            "Remaining  = " << remain << " KB  " <<
            "FRISize   = " << friSize << " KB  " <<
            "SafetyBuf = " << safetyBuf << " KB");

    friSize += safetyBuf;

    if (friSize > remain) {
        log_DBG_m(dbg_LOW, "FRI must be dumped.");
        return true;
    }

    if (a_checkOffset != NULL) {
        // Space left on volume -> calculate # of blocks to next check

        // Best case: the remaining blocks until EOM
        UInt32_t chkOffset = (remain - friSize) / (GetBlockSize() / 1024);

        // Decrease check interval as medium is getting filled up
        UInt32_t fullRatio = (total)/(remain+1);
        if (fullRatio < 1) {
            fullRatio = 1;
        }
        fullRatio *= 2;

        static const UInt32_t mb300_c(300*1024); // 300 MB in KB units
        static const UInt32_t mb100_c(100*1024); // 100 MB in KB units
        // Check the capacity more often when approaching end of medium
        if (remain < mb300_c) {
            *a_checkOffset = 4;
        }
        else if (remain < mb100_c) {
            *a_checkOffset = 1;
        }
        else {
            *a_checkOffset = (chkOffset/fullRatio) + 1;
        }

        log_DBG_m(dbg_LOW, "Next capacity check offset: " << (*a_checkOffset) );
    }

    return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void bea_Volume::OverrideIDs ( const cmn_UUID_t a_volID,
const cmn_UUID_t a_poolID,
const cmn_UUID_t a_partID 
)

Definition at line 251 of file bea_volume.cpp.

References dbg_LOW, cmn_UUID_t::IsNull(), log_DBG_m, log_FUNC_m, m_validVolInfo, m_volInfo, bea_VolInfo_t::medVolID, bea_VolInfo_t::partID, bea_VolInfo_t::poolID, and bea_VolInfo_t::type.

Referenced by bea_MigrationThread::PrepareVolume().

                                {

    log_FUNC_m(OverrideIDs);

    if (!m_volInfo.medVolID.IsNull() ||
        !m_volInfo.poolID.IsNull() ||
        !m_volInfo.partID.IsNull() ) {

        log_DBG_m(dbg_LOW, "* OVERRIDING EXISTING IDs. **");
    }

    m_validVolInfo = true;
    m_volInfo.type = VOL_IVD;
    m_volInfo.medVolID = a_volID;
    m_volInfo.poolID = a_poolID;
    m_volInfo.partID = a_partID;

}

Here is the call graph for this function:

Here is the caller graph for this function:

void bea_Volume::Read ( UInt8_t a_buf  ) 

Definition at line 146 of file bea_volume.cpp.

References bea_VolInfo_t::blockSize, dbg_NORM, ivd_BaseException::GetError(), log_DBG_m, log_ERR_m, log_FUNC_m, m_volInfo, and ReadRaw().

Referenced by bea_FRI::ReadFRI(), bea_FRI::ReadFRIStart(), bea_DupReadThread::ReadMedVolume(), bea_RecallThread::Recall(), bea_VolumeReader::Run(), and bea_FRI::VerifyExistenceOfFileMark().

                                    {
    try {
        ReadRaw(a_buf, m_volInfo.blockSize);
    }
    catch (const ivd_Error& ie) {
        log_FUNC_m(Read);
        if (ie.GetError() == ie_SCSI_EOM) {
            log_DBG_m(dbg_NORM, "Ignored early EOM on reading.");
        }
        else if (ie.GetError() == ie_SCSI_ILENGTH) {
            log_ERR_m("Invalid block size when reading data:" << ie);
            throw;
        }
        else {
            throw;
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void bea_Volume::ReadEstimSizes (  )  [protected, pure virtual]

Implemented in bea_DiskVolume, and bea_TapeVolume.

Referenced by GetEstimRemainingSize(), and GetEstimTotalSize().

Here is the caller graph for this function:

virtual void bea_Volume::ReadRaw ( UInt8_t a_buf,
UInt32_t  a_size 
) [protected, pure virtual]

Implemented in bea_DiskVolume, and bea_TapeVolume.

Referenced by Read(), and ReadVolHdr().

Here is the caller graph for this function:

void bea_Volume::ReadVolHdr ( UInt8_t a_buf  ) 

Definition at line 167 of file bea_volume.cpp.

References df_VOLHDR_REC_SIZE, log_FUNC_m, and ReadRaw().

Referenced by bea_DupReadThread::ReadMedVolume(), and ReadVolInfoFromHeader().

Here is the call graph for this function:

Here is the caller graph for this function:

void bea_Volume::ReadVolInfoFromHeader (  ) 

Definition at line 577 of file bea_volume.cpp.

References bea_VolInfo_t::accessNum, bea_VolInfo_t::accessTime, bea_VolInfo_t::appendNum, bea_VolInfo_t::appendTime, df_RecVolHdr_t::blockSize, bea_VolInfo_t::blockSize, cmn_HexDump(), dbg_DETAIL, dbg_LOW, dbg_NORM, df_volFlagSystem_c, df_volFlagSysVolValid_c, df_VOLHDR_REC_SIZE, df_ECMAVolumeLabel_t::ecmaHdr, df_ECMAVolumeLabel_t::first, df_RecVolHdr_t::flags, bea_Medium::GetBarcode(), bea_Medium::GetCurVolNumber(), ivd_BaseException::GetError(), GetVolumeID(), ie_INVALID_ARG, ie_MEDIUM_BLANK, ie_MEDIUM_EOD, df_ECMAFirstVolumeLabel_t::implID, bea_VolInfo_t::implID, ivd_Error, log_DBG_m, log_FUNC_m, log_WRN_m, m_medium_p, m_size, m_validVolInfo, m_volInfo, m_volNumber, bea_VolInfo_t::medVolID, ntoh(), NULL, df_RecVolHdr_t::numAccess, df_RecVolHdr_t::numAppends, df_ECMALblHdr_t::number, df_RecVolHdr_t::numOverwrites, bea_VolInfo_t::owriteNum, bea_VolInfo_t::owriteTime, df_RecVolHdr_t::partID, bea_VolInfo_t::partID, df_RecVolHdr_t::poolID, bea_VolInfo_t::poolID, ReadVolHdr(), Rewind(), bea_VolInfo_t::size, bea_VolInfo_t::sysVol, df_RecVolHdr_t::sysVolIndex, bea_VolInfo_t::sysVolNum, df_RecVolHdr_t::timeAccess, df_RecVolHdr_t::timeOverwrite, df_RecVolHdr_t::timeWrite, bea_VolInfo_t::type, UpdateMediumMem(), df_RecVolHdr_t::volID, and bea_VolInfo_t::volNum.

Referenced by bea_TapeMedium::Format(), Init(), bea_FRIThread::ProcessFromDataVol(), bea_FRIThread::ReadFromSysVol(), and i_BackEndAgent_i::ReadIDs().

                                       {
    log_FUNC_m(ReadVolInfoFromHeader);

    if (m_medium_p->GetCurVolNumber() != m_volNumber) {
        throw ivd_Error(
            ie_INVALID_ARG,
            "Volume info can only be read for current volume.");
    };

    vector<UInt8_t> medVolHdr(df_VOLHDR_REC_SIZE, 0);
    df_ECMAVolumeLabel_t    *ecmaHdr_p(NULL);
    df_RecVolHdr_t          *ivdHdr_p(NULL);

    { // Init the records
        m_validVolInfo = false;
        bea_VolInfo_t nilVolInfo;
        m_volInfo = nilVolInfo;
    }

    m_volInfo.volNum    = m_volNumber;
    m_volInfo.size      = m_size;

    try {
        Rewind();
        ReadVolHdr(&(medVolHdr[0]));

        log_DBG_m(dbg_DETAIL,
            "Header hex dump: " << endl <<
            cmn_HexDump( &(medVolHdr[0]), 255, 16, true) );
    }
    catch(ivd_Error &ie) {
        if (ie.GetError() == ie_MEDIUM_BLANK ||
            ie.GetError() == ie_MEDIUM_EOD ||
            ie.GetError() == ie_MEDIUM_EOM ) {

            log_DBG_m(dbg_LOW, "Assuming blank volume. " <<
                endl << "Error: " << ie);

            m_volInfo.type = VOL_BLANK;
            m_validVolInfo = true;
            return;
        }
        else if (ie.GetError() == ie_MEDIUM_ILENGTH) {
            log_DBG_m(dbg_LOW,
                "Different block size than HSMs. Will try to parse it." <<
                endl << "Error: " << ie);
        }
        else if (ie.GetError() == ie_MEDIUM_FILEMARK) {
            log_DBG_m(dbg_LOW, "Unknown volume type - filemark detected. " <<
                endl << "Error: " << ie);

            m_volInfo.type = VOL_OTHER;
            m_validVolInfo = true;
            return;
        }
        else {
            log_DBG_m(dbg_LOW,
                "Got ivd_Error during medvol scan. Don't assume anything. " <<
                endl << "Error: " << ie);

            //
            // Other errors (media, hardware) are propagated
            // to the caller and marked in RMDB.
            //
            throw;
        }
    }
    catch(ivd_SysError &ie) {
        log_DBG_m(dbg_LOW,
            "Got ivd_SysError during medvol scan. Unknown volume type. " <<
            endl << "Error: " << ie);
        throw;
    }

    // Successful read. medium is not empty.

    df_BlockScanner::GetVolumeID(&(medVolHdr[0]), ecmaHdr_p, ivdHdr_p);
    if (ecmaHdr_p != NULL) {
        m_volInfo.sysVol = false;

        log_DBG_m(dbg_NORM, "Got ECMA header.");
        m_volInfo.type    = VOL_ECMA;

        // Get the ECMA implementator ID (IVD or other)
        if (ecmaHdr_p->ecmaHdr.number == 1) {
            m_volInfo.implID = string(
                reinterpret_cast<const char*>(ecmaHdr_p->first.implID),
                sizeof(ecmaHdr_p->first.implID) );
        };
        if (ivdHdr_p != NULL) {

            log_DBG_m(dbg_NORM, "Got HSM header. Reading parameters.");

            m_volInfo.type         = VOL_IVD;
            m_volInfo.medVolID     = ivdHdr_p->volID;
            m_volInfo.poolID       = ivdHdr_p->poolID;
            m_volInfo.partID       = ivdHdr_p->partID;
            m_volInfo.blockSize    = ntoh(ivdHdr_p->blockSize);
            m_volInfo.accessNum    = ntoh(ivdHdr_p->numAccess);
            m_volInfo.appendNum    = ntoh(ivdHdr_p->numAppends);
            m_volInfo.owriteNum    = ntoh(ivdHdr_p->numOverwrites);
            m_volInfo.accessTime   = ntoh(ivdHdr_p->timeAccess);
            m_volInfo.appendTime   = ntoh(ivdHdr_p->timeWrite);
            m_volInfo.owriteTime   = ntoh(ivdHdr_p->timeOverwrite);
            if ( (ntoh(ivdHdr_p->flags) & df_volFlagSysVolValid_c) != 0) {
                m_volInfo.sysVolNum = ivdHdr_p->sysVolIndex;
                m_volInfo.sysVol    = (m_volInfo.sysVolNum == m_volNumber);
            }
            else {
                m_volInfo.sysVol = (ntoh(ivdHdr_p->flags) & df_volFlagSystem_c) != 0;
                log_WRN_m(
                    m_medium_p->GetBarcode() << ":" << m_volNumber <<
                    ": Detected data format 01.00." <<
                    " Can't determine the index of system volume.");
            }
            UpdateMediumMem(m_volInfo);
        };
    }
    else if (memcmp(&(medVolHdr[257]), "ustar", 5) == 0) {
        /*
        *  Detect POSIX/GNU tar archives
        *    Magic cookie from /usr/share/magic (file command)
        */
        log_DBG_m(dbg_NORM, "Detected TAR header.");
        m_volInfo.type = VOL_TAR;
    }
    else if(memcmp(&(medVolHdr[0]),
            "Infini<Store<<Virtual<<<Disk<<<<Media<<<<<Head_98",
            49) == 0) {
        /*
        *  Detect VOL_IVD_NT media
        */
        log_DBG_m(dbg_NORM, "Detected IVD-NT header.");
        m_volInfo.type = VOL_IVD_NT;
    };

    m_validVolInfo = true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void bea_Volume::ReadVolInfoFromMediumMem (  )  [private]

Definition at line 720 of file bea_volume.cpp.

References bea_VolInfo_t::accessNum, bea_VolInfo_t::accessTime, bea_VolInfo_t::appendNum, bea_VolInfo_t::appendTime, df_TCMMediaVolume_t::blockSize, bea_VolInfo_t::blockSize, dbg_LOW, dbg_NORM, df_volFlagSystem_c, df_TCMMediaVolume_t::flags, bea_Medium::GetMediumMem(), bea_Medium::GetVolumeCount(), bea_MediumMemory::GetVolumeRecord(), bea_Medium::IsMediumMemValid(), cmn_UUID_t::IsNull(), log_DBG_m, log_FUNC_m, m_medium_p, m_size, m_validVolInfo, m_volInfo, m_volNumber, bea_VolInfo_t::medVolID, df_TCMMediaVolume_t::numAccesses, df_TCMMediaVolume_t::numAppends, df_TCMMediaVolume_t::numOverwrites, bea_VolInfo_t::owriteNum, bea_VolInfo_t::owriteTime, bea_VolInfo_t::partID, df_TCMMediaVolume_t::partID, bea_VolInfo_t::poolID, df_TCMMediaVolume_t::poolID, bea_VolInfo_t::size, bea_VolInfo_t::sysVol, bea_VolInfo_t::sysVolNum, df_TCMMediaVolume_t::timeAccess, df_TCMMediaVolume_t::timeOverwrite, df_TCMMediaVolume_t::timeWrite, bea_VolInfo_t::type, df_TCMMediaVolume_t::volID, and bea_VolInfo_t::volNum.

Referenced by GetBlockSize(), GetPartitionID(), GetPoolID(), GetVolumeID(), GetVolumeInfo(), GetVolumeType(), and IsSysVolume().

                                          {
    log_FUNC_m(ReadVolInfoFromMediumMem);

    { // Init the records
        m_validVolInfo = false;
        bea_VolInfo_t nilVolInfo;
        m_volInfo = nilVolInfo;
    }

    if (!m_medium_p->IsMediumMemValid()) {
        return;
    }
    bea_MediumMemory* mm = m_medium_p->GetMediumMem();

    df_TCMMediaVolume_t medVolNote = mm->GetVolumeRecord(m_volNumber);

    m_volInfo.volNum    = m_volNumber;
    m_volInfo.size      = m_size;

    log_DBG_m(dbg_NORM,
        "VolID : " << medVolNote.volID << endl <<
        "PoolID: " << medVolNote.poolID << endl <<
        "PartID: " << medVolNote.partID);

    if (medVolNote.volID.IsNull()  ||
        medVolNote.poolID.IsNull() ||
        medVolNote.partID.IsNull() ) {

        log_DBG_m(dbg_LOW,
            "Failed reading volume info from medium memory: " <<
            "One of the UUIDs in MIC is null. ");
        return;
    };
    m_volInfo.type         = VOL_IVD;
    m_volInfo.sysVol       = (medVolNote.flags & df_volFlagSystem_c) != 0;
    m_volInfo.medVolID     = medVolNote.volID;
    m_volInfo.poolID       = medVolNote.poolID;
    m_volInfo.partID       = medVolNote.partID;
    m_volInfo.blockSize    = medVolNote.blockSize;
    m_volInfo.accessNum    = medVolNote.numAccesses;
    m_volInfo.appendNum    = medVolNote.numAppends;
    m_volInfo.owriteNum    = medVolNote.numOverwrites;
    m_volInfo.accessTime   = medVolNote.timeAccess;
    m_volInfo.appendTime   = medVolNote.timeWrite;
    m_volInfo.owriteTime   = medVolNote.timeOverwrite;
    m_volInfo.sysVolNum    = 0; // Assume no system volume.

    for (UInt32_t i = 0; i < m_medium_p->GetVolumeCount(); i++) {
        medVolNote = mm->GetVolumeRecord(i+1);
        if ( (medVolNote.flags & df_volFlagSystem_c) != 0 ) {
            log_DBG_m(dbg_LOW,
                "System volume detected on volume: " << (i+1));
            m_volInfo.sysVolNum = i+1;
            break;
        }
    };

    log_DBG_m(dbg_NORM, "Media volume info read from MIC.");
    m_validVolInfo = true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void bea_Volume::Rewind (  )  [pure virtual]
virtual void bea_Volume::SeekBlock ( UInt32_t  a_block  )  [pure virtual]
virtual void bea_Volume::SeekEOD (  )  [pure virtual]

Implemented in bea_DiskVolume, and bea_TapeVolume.

Referenced by bea_FRI::CloseVolume(), Init(), and bea_MigrationThread::PrepareVolume().

Here is the caller graph for this function:

virtual void bea_Volume::SeekFileMark ( Int32_t  a_relativeFM  )  [pure virtual]

Implemented in bea_DiskVolume, and bea_TapeVolume.

Referenced by bea_FRI::CloseVolume(), bea_FRI::CreateFRI(), bea_FRI::PositionToStartOfFRI(), and bea_FRIThread::ReadFromSysVol().

Here is the caller graph for this function:

void bea_Volume::SetBlockSize ( UInt32_t  a_blkSize  ) 

Definition at line 237 of file bea_volume.cpp.

References bea_VolInfo_t::blockSize, dbg_LOW, log_DBG_m, log_FUNC_A_m, m_validVolInfo, m_volInfo, and bea_VolInfo_t::type.

Referenced by Init(), bea_MigrationThread::PrepareVolume(), bea_RecallThread::Recall(), and bea_DupWriteThread::WriteMedVolume().

                                                {
    log_FUNC_A_m(SetBlockSize, "size: " << a_blkSize);

    if (m_validVolInfo) {
        log_DBG_m(dbg_LOW, "* OVERRIDING BLOCK SIZE. **");
    }
    else {
        m_validVolInfo = true;
        m_volInfo.type = VOL_IVD;
    }
    m_volInfo.blockSize = a_blkSize;
}

Here is the caller graph for this function:

void bea_Volume::SetDeclaredSize ( UInt32_t  a_size  )  [protected]

Definition at line 199 of file bea_volume.cpp.

References log_FUNC_m, log_WRN_m, and m_size.

Referenced by bea_DiskVolume::bea_DiskVolume(), and bea_DiskVolume::ReadVolInfo().

                                                {
    if (m_size == a_size) {
        return;
    }
    if (m_size > 0) {
        log_FUNC_m(SetDeclaredSize);
        log_WRN_m(
            "Changing declared volume size from " <<
            m_size << " to " << a_size);
    }
    m_size = a_size;
}

Here is the caller graph for this function:

void bea_Volume::SetEstimatedSizes ( UInt32_t  a_size,
UInt32_t  a_free 
) [protected]

Definition at line 193 of file bea_volume.cpp.

References m_estimFree, m_estimSize, and m_validSizes.

Referenced by bea_TapeVolume::ReadEstimSizes(), and bea_DiskVolume::ReadEstimSizes().

                                                                   {
    m_validSizes = true, m_estimSize = a_size, m_estimFree = a_free;
}

Here is the caller graph for this function:

void bea_Volume::UpdateMediumMem ( const bea_VolInfo_t a_volInfo  )  [private]

Definition at line 783 of file bea_volume.cpp.

References df_TCMMedium_t::barcode, bea_VolInfo_t::blockSize, df_TCMMediaVolume_t::blockSize, dbg_LOW, dbg_NORM, df_volFlagSystem_c, evt_ERROR, df_TCMMediaVolume_t::flags, bea_Medium::GetBarcode(), ivd_BaseException::GetFriendly(), GetJobID(), bea_Medium::GetMediumMem(), df_TCMMediaVolume_t::initTime, bea_Medium::IsMediumMemDetected(), bea_Medium::IsMediumMemValid(), log_DBG_m, log_FUNC_m, log_WriteEvent(), m_medium_p, m_volNumber, bea_VolInfo_t::medVolID, NULL, df_TCMMediaVolume_t::numAccesses, df_TCMMediaVolume_t::numAppends, df_TCMMediaVolume_t::numOverwrites, bea_VolInfo_t::partID, df_TCMMediaVolume_t::partID, bea_VolInfo_t::poolID, df_TCMMediaVolume_t::poolID, bea_VolInfo_t::sysVol, df_TCMMediaVolume_t::timeAccess, df_TCMMediaVolume_t::timeOverwrite, df_TCMMediaVolume_t::timeWrite, bea_MediumMemory::UpdateMediumRecord(), bea_MediumMemory::UpdateVolumeRecord(), and df_TCMMediaVolume_t::volID.

Referenced by Init(), and ReadVolInfoFromHeader().

                                                               {
    log_FUNC_m(UpdateMediumMem);

    if (!m_medium_p->IsMediumMemDetected()) {
        log_DBG_m(dbg_NORM, "Medium memory not detected. Can't update.");
        return;
    }

    log_DBG_m(dbg_LOW, "Updating medium memory.");
    bea_MediumMemory* mm = m_medium_p->GetMediumMem();
    try {
        if (!m_medium_p->IsMediumMemValid()) {
            log_DBG_m(dbg_LOW, "No medium memory contents on. Creating new.");

            df_TCMMedium_t newMedNote;
            memcpy(newMedNote.barcode,
                m_medium_p->GetBarcode().data(),
                m_medium_p->GetBarcode().length() );

            mm->UpdateMediumRecord(newMedNote);
        } // if (!m_medium_p->IsMediumMemValid())
        else {
            log_DBG_m(dbg_LOW, "Medium memory contents is valid!");
        };

        df_TCMMediaVolume_t medVolNote;
        if (a_volInfo.sysVol) {
            medVolNote.flags = df_volFlagSystem_c;
        };

        medVolNote.blockSize = a_volInfo.blockSize;
        medVolNote.volID = a_volInfo.medVolID;
        medVolNote.poolID = a_volInfo.poolID;
        medVolNote.partID = a_volInfo.partID;
        medVolNote.numAccesses = 0;
        medVolNote.numAppends = 0;
        medVolNote.numOverwrites = 0;
        medVolNote.initTime = (ivd_Time_t)time(NULL);
        medVolNote.timeWrite = 0;
        medVolNote.timeAccess = 0;
        medVolNote.timeOverwrite = 0;

        mm->UpdateVolumeRecord(m_volNumber, medVolNote);
    }
    catch (ivd_Exception &ie) {
        ostringstream sstr;
        sstr << "Writing to MIC FAILED (" << ie.GetFriendly() << ").";
        log_WriteEvent(
            evt_ERROR,
            sstr.str(),
            "",
            GetJobID(),
            m_medium_p->GetBarcode());
    }
    catch(...) {
        log_WriteEvent(
            evt_ERROR,
            "Writing to MIC FAILED.",
            "",
            GetJobID(),
            m_medium_p->GetBarcode());
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void bea_Volume::Write ( const UInt8_t a_buf  ) 

Definition at line 129 of file bea_volume.cpp.

References bea_VolInfo_t::blockSize, m_atEOD, m_validSizes, m_volInfo, and WriteRaw().

Referenced by bea_FRI::CopyFromDiskToMedium(), Init(), bea_MigrationThread::WriteBlock(), and bea_DupWriteThread::WriteMedVolume().

                                           {
    m_validSizes = false;
    WriteRaw(a_buf, m_volInfo.blockSize);
    m_atEOD = true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void bea_Volume::WriteFileMarks ( UInt32_t  a_count = 1  )  [pure virtual]

Implemented in bea_DiskVolume, and bea_TapeVolume.

Referenced by bea_FRI::CloseVolume(), Init(), and bea_DupWriteThread::WriteMedVolume().

Here is the caller graph for this function:

virtual void bea_Volume::WriteRaw ( const UInt8_t a_buf,
UInt32_t  a_size 
) [protected, pure virtual]

Implemented in bea_DiskVolume, and bea_TapeVolume.

Referenced by Write(), and WriteVolHdr().

Here is the caller graph for this function:

void bea_Volume::WriteVolHdr ( const UInt8_t a_buf  ) 

Definition at line 137 of file bea_volume.cpp.

References df_VOLHDR_REC_SIZE, log_FUNC_m, m_atEOD, m_validSizes, and WriteRaw().

Referenced by Init(), and bea_DupWriteThread::WriteMedVolume().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented in bea_DiskVolume, and bea_TapeVolume.

Definition at line 198 of file bea_volume.h.

bool bea_Volume::m_atEOD [protected]

Definition at line 208 of file bea_volume.h.

Referenced by GetEstimRemainingSize(), and SetEstimatedSizes().

Definition at line 207 of file bea_volume.h.

Referenced by GetEstimTotalSize(), and SetEstimatedSizes().

bea_Medium* const bea_Volume::m_medium_p [protected]
bool bea_Volume::m_validSizes [private]

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