Public Member Functions | Protected Member Functions | Private Attributes

bea_TapeDrive Class Reference
[IVD Back-End Agent]

#include <bea_tapedrive.h>

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

List of all members.

Public Member Functions

 bea_TapeDrive ()
virtual void Open (const string &a_scsiID, const string &a_barcode, UInt64_t a_jobID)
virtual void Close ()
virtual const string & GetVendorID () const
virtual const string & GetProductID () const
virtual const string & GetProductRevision () const
virtual const string & GetSerialNumber () const
virtual string GetSCSIID () const
virtual bool WasMediumChanged () const
virtual UInt64_t GetDefaultSeekThreshold () const

Protected Member Functions

virtual ~bea_TapeDrive ()

Private Attributes

 log_CLASSID_m
auto_ptr< scsi_IOm_scsiIO_ap

Detailed Description

Definition at line 41 of file bea_tapedrive.h.


Constructor & Destructor Documentation

bea_TapeDrive::bea_TapeDrive (  ) 

Definition at line 49 of file bea_tapedrive.cpp.

References log_FUNC_m, and m_scsiIO_ap.

                             {

    log_FUNC_m(bea_TapeDrive);

#if TGT_OS_linux
    m_scsiIO_ap.reset(new scsi_LnxSG(""));
#elif TGT_OS_windows
    m_scsiIO_ap.reset(new scsi_WinSG(""));
#else
    #error "Which platform are compiling on ?!"
#endif
}

bea_TapeDrive::~bea_TapeDrive (  )  [protected, virtual]

Definition at line 62 of file bea_tapedrive.cpp.

References log_FUNC_m.


Member Function Documentation

void bea_TapeDrive::Close (  )  [virtual]

Implements bea_Drive.

Definition at line 168 of file bea_tapedrive.cpp.

References dbg_DETAIL, dbg_LOW, cmn_Global::evt, g_cmn, bea_Drive::GetMedium(), bea_Medium::GetMediumMem(), bea_Medium::IsMediumMemValid(), log_DBG_m, log_FUNC_m, m_scsiIO_ap, NULL, bea_Drive::SetMedium(), log_EventLogger::SetQualifier(), and bea_MediumMemory::Write().

Referenced by Open().

                          {
    log_FUNC_m(Close);

    g_cmn.evt.SetQualifier("");

    if (m_scsiIO_ap->IsOpen()) {

        bea_Medium* med_p = GetMedium();
        if (med_p != NULL && med_p->IsMediumMemValid()) {
            log_DBG_m(dbg_LOW, "Writing medium memory to tape");
            try {
                med_p->GetMediumMem()->Write();
            }
            catch (const ivd_Exception &ie) {
                log_DBG_m(dbg_LOW, "CM write error: " << ie);
            }
            catch (const std::exception &se) {
                log_DBG_m(dbg_LOW, "CM write error: " << se.what());
            }
            catch (...) {
                log_DBG_m(dbg_LOW, "CM write error: unknown");
            }
        }

        m_scsiIO_ap->Close();

        // Will deallocate the object
        SetMedium(NULL);
    }
    else {
        log_DBG_m(dbg_DETAIL,
            "Drive not open. Do not perform SCSI close.");
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

UInt64_t bea_TapeDrive::GetDefaultSeekThreshold (  )  const [virtual]

Reimplemented from bea_Drive.

Definition at line 250 of file bea_tapedrive.cpp.

References cfg_MEGABYTE, dbg_DETAIL, bea_Drive::GetMedium(), log_DBG_m, and log_FUNC_m.

                                                      {

    log_FUNC_m(GetDefaultSeekThreshold);

    UInt64_t defaultThreshold(GetMedium()->GetSize());
    defaultThreshold *= 5LL * cfg_MEGABYTE / 100LL;

    log_DBG_m(dbg_DETAIL, "5% of med size: " << defaultThreshold);

    return defaultThreshold;
}

Here is the call graph for this function:

const string & bea_TapeDrive::GetProductID (  )  const [virtual]

Implements bea_Drive.

Definition at line 211 of file bea_tapedrive.cpp.

References m_scsiIO_ap, and NULL.

                                                {
    if (m_scsiIO_ap.get() == NULL || !m_scsiIO_ap->IsOpen()) {
        static const string c_noProductID("Unknown product ID");
        return c_noProductID;
    }
    return m_scsiIO_ap->GetProductID();
}

const string & bea_TapeDrive::GetProductRevision (  )  const [virtual]

Implements bea_Drive.

Definition at line 219 of file bea_tapedrive.cpp.

References m_scsiIO_ap, and NULL.

                                                      {
    if (m_scsiIO_ap.get() == NULL || !m_scsiIO_ap->IsOpen()) {
        static const string c_noProductRev("Unknown product revision");
        return c_noProductRev;
    }
    return m_scsiIO_ap->GetProductRevision();
}

string bea_TapeDrive::GetSCSIID (  )  const [virtual]

Reimplemented from bea_Drive.

Definition at line 235 of file bea_tapedrive.cpp.

References m_scsiIO_ap, and NULL.

                                      {
    if (m_scsiIO_ap.get() == NULL || !m_scsiIO_ap->IsOpen()) {
        static const string c_noSID("Unknown SCSI ID");
        return c_noSID;
    }
    return m_scsiIO_ap->GetSCSIID();
}

const string & bea_TapeDrive::GetSerialNumber (  )  const [virtual]

Implements bea_Drive.

Definition at line 227 of file bea_tapedrive.cpp.

References m_scsiIO_ap, and NULL.

                                                   {
    if (m_scsiIO_ap.get() == NULL || !m_scsiIO_ap->IsOpen()) {
        static const string c_noSN("Unknown serial number");
        return c_noSN;
    }
    return m_scsiIO_ap->GetProductSerialNumber();
}

const string & bea_TapeDrive::GetVendorID (  )  const [virtual]

Implements bea_Drive.

Definition at line 203 of file bea_tapedrive.cpp.

References m_scsiIO_ap, and NULL.

                                               {
    if (m_scsiIO_ap.get() == NULL || !m_scsiIO_ap->IsOpen()) {
        static const string c_noVendorID("Unknown vendor ID");
        return c_noVendorID;
    }
    return m_scsiIO_ap->GetVendorID();
}

void bea_TapeDrive::Open ( const string &  a_scsiID,
const string &  a_barcode,
UInt64_t  a_jobID 
) [virtual]

Implements bea_Drive.

Definition at line 66 of file bea_tapedrive.cpp.

References Close(), dbg_LOW, cmn_Global::evt, evt_ERROR, g_cmn, ivd_BaseException::GetError(), ivd_BaseException::GetFriendly(), bea_Drive::GetJobID(), bea_Drive::GetMedium(), ie_BEA_INVDEVTYPE, ie_INVALID_ARG, ivd_Error, ivd_Sleep, log_DBG_m, log_FUNC_A_m, log_WriteEvent(), m_scsiIO_ap, scsi_GetDeviceTypeText(), bea_Medium::SetBarcode(), bea_Drive::SetJobID(), bea_Drive::SetMedium(), and log_EventLogger::SetQualifier().

                               {

    log_FUNC_A_m(Open,
        "a_scsiID: " << a_scsiID <<
        " a_bc: " << a_barcode <<
        " a_jobID: " << a_jobID);

    if (a_scsiID.empty()) {
        throw ivd_InternalError(
            ie_INVALID_ARG, "BUG: Job assigned empty SCSI id.");
    };

    m_scsiIO_ap->SetDeviceID(a_scsiID);
    g_cmn.evt.SetQualifier(a_scsiID);

    bool noMediumRetried = false;

    while (true) {
        try {
            m_scsiIO_ap->Open();
            m_scsiIO_ap->WaitToBecomeReady();

            // WARNING: This break ensures that the loop exits if all OK
            break;
        }
        catch (const ivd_Error &ie) {
            if (ie.GetError() == ie_SCSI_NO_MEDIUM) {
                // Medium might be unloaded, try to load the medium.
                try {
                    log_DBG_m(dbg_LOW,
                        "ie_SCSI_NO_MEDIUM detected. " <<
                        "Trying to load the medium.");
                    cdb_LoadUnload  load(true); // load
                    m_scsiIO_ap->IOCtl(load);
                    // WARNING: This break ensures that the loop exits if load
                    // succeeds.
                    break;
                }
                catch (const ivd_Error &ie) {
                    log_DBG_m(dbg_LOW,
                        "Load didn't succeed. Ignore: " << ie.GetFriendly());
                }
                Close();
                if (noMediumRetried) {
                    g_cmn.evt.SetQualifier(a_scsiID);
                    ostringstream sstr;
                    sstr
                        << "id:"
                        << m_scsiIO_ap->GetPort() << ":"
                        << m_scsiIO_ap->GetChannel() << ":"
                        << m_scsiIO_ap->GetID() << ":"
                        << m_scsiIO_ap->GetLUN();

                    log_WriteEvent(
                        evt_ERROR,
                        "Medium not present in drive.",
                        "",
                        GetJobID(),
                        sstr.str());

                    throw;
                }
                log_DBG_m(dbg_LOW,
                    "ie_SCSI_NO_MEDIUM detected. " << endl <<
                    "Because of possible preceding medium load, " <<
                    "try once more after 10 seconds.");
                noMediumRetried = true;
                ivd_Sleep(10);
            }
            else {
                Close();
                throw;
            }
        }
    }

    if (m_scsiIO_ap->GetDeviceType() != dt_TAPE) {
        log_MARKLINE_m;
        ostringstream sstr;
        sstr
            << "Not a tape drive device, but "
            << scsi_GetDeviceTypeText(m_scsiIO_ap->GetDeviceType())
            << " for " << a_scsiID;

        log_WriteEvent(evt_ERROR, sstr.str(), "", GetJobID());

        Close();
        throw ivd_Error(ie_BEA_INVDEVTYPE, sstr.str());
    };

    SetMedium(new bea_TapeMedium(m_scsiIO_ap.get()));

    SetJobID(a_jobID);

    if (GetMedium()->GetBarcode() != a_barcode) {
        GetMedium()->SetBarcode(a_barcode);
    }
}

Here is the call graph for this function:

bool bea_TapeDrive::WasMediumChanged (  )  const [virtual]

Reimplemented from bea_Drive.

Definition at line 243 of file bea_tapedrive.cpp.

References m_scsiIO_ap, and NULL.

                                           {
    if (m_scsiIO_ap.get() == NULL || !m_scsiIO_ap->IsOpen()) {
        return false;
    }
    return m_scsiIO_ap->GetPossibleMediumChange();
}


Member Data Documentation

Reimplemented from bea_Drive.

Definition at line 65 of file bea_tapedrive.h.

auto_ptr<scsi_IO> bea_TapeDrive::m_scsiIO_ap [private]

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