#include <bea_tapedrive.h>


Definition at line 27 of file bea_tapedrive.h.
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_IO > | m_scsiIO_ap |
| bea_TapeDrive::bea_TapeDrive | ( | ) |
Definition at line 35 of file bea_tapedrive.cpp.
References log_FUNC_m, and m_scsiIO_ap.
00035 { 00036 00037 log_FUNC_m(bea_TapeDrive); 00038 00039 #if TGT_OS_linux 00040 m_scsiIO_ap.reset(new scsi_LnxSG("")); 00041 #elif TGT_OS_windows 00042 m_scsiIO_ap.reset(new scsi_WinSG("")); 00043 #else 00044 #error "Which platform are compiling on ?!" 00045 #endif 00046 }
| bea_TapeDrive::~bea_TapeDrive | ( | ) | [protected, virtual] |
Definition at line 48 of file bea_tapedrive.cpp.
References log_FUNC_m.
00048 { 00049 log_FUNC_m(~bea_TapeDrive); 00050 }
| void bea_TapeDrive::Open | ( | const string & | a_scsiID, | |
| const string & | a_barcode, | |||
| UInt64_t | a_jobID | |||
| ) | [virtual] |
Implements bea_Drive.
Definition at line 52 of file bea_tapedrive.cpp.
References Close(), dbg_LOW, dt_TAPE, 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, ie_SCSI_NO_MEDIUM, ivd_Error, ivd_Sleep, log_DBG_m, log_FUNC_A_m, log_MARKLINE_m, log_WriteEvent(), m_scsiIO_ap, scsi_GetDeviceTypeText(), bea_Medium::SetBarcode(), bea_Drive::SetJobID(), bea_Drive::SetMedium(), and log_EventLogger::SetQualifier().
00055 { 00056 00057 log_FUNC_A_m(Open, 00058 "a_scsiID: " << a_scsiID << 00059 " a_bc: " << a_barcode << 00060 " a_jobID: " << a_jobID); 00061 00062 if (a_scsiID.empty()) { 00063 throw ivd_InternalError( 00064 ie_INVALID_ARG, "BUG: Job assigned empty SCSI id."); 00065 }; 00066 00067 m_scsiIO_ap->SetDeviceID(a_scsiID); 00068 g_cmn.evt.SetQualifier(a_scsiID); 00069 00070 bool noMediumRetried = false; 00071 00072 while (true) { 00073 try { 00074 m_scsiIO_ap->Open(); 00075 m_scsiIO_ap->WaitToBecomeReady(); 00076 00077 // WARNING: This break ensures that the loop exits if all OK 00078 break; 00079 } 00080 catch (const ivd_Error &ie) { 00081 if (ie.GetError() == ie_SCSI_NO_MEDIUM) { 00082 // Medium might be unloaded, try to load the medium. 00083 try { 00084 log_DBG_m(dbg_LOW, 00085 "ie_SCSI_NO_MEDIUM detected. " << 00086 "Trying to load the medium."); 00087 cdb_LoadUnload load(true); // load 00088 m_scsiIO_ap->IOCtl(load); 00089 // WARNING: This break ensures that the loop exits if load 00090 // succeeds. 00091 break; 00092 } 00093 catch (const ivd_Error &ie) { 00094 log_DBG_m(dbg_LOW, 00095 "Load didn't succeed. Ignore: " << ie.GetFriendly()); 00096 } 00097 Close(); 00098 if (noMediumRetried) { 00099 g_cmn.evt.SetQualifier(a_scsiID); 00100 ostringstream sstr; 00101 sstr 00102 << "id:" 00103 << m_scsiIO_ap->GetPort() << ":" 00104 << m_scsiIO_ap->GetChannel() << ":" 00105 << m_scsiIO_ap->GetID() << ":" 00106 << m_scsiIO_ap->GetLUN(); 00107 00108 log_WriteEvent( 00109 evt_ERROR, 00110 "Medium not present in drive.", 00111 "", 00112 GetJobID(), 00113 sstr.str()); 00114 00115 throw; 00116 } 00117 log_DBG_m(dbg_LOW, 00118 "ie_SCSI_NO_MEDIUM detected. " << endl << 00119 "Because of possible preceding medium load, " << 00120 "try once more after 10 seconds."); 00121 noMediumRetried = true; 00122 ivd_Sleep(10); 00123 } 00124 else { 00125 Close(); 00126 throw; 00127 } 00128 } 00129 } 00130 00131 if (m_scsiIO_ap->GetDeviceType() != dt_TAPE) { 00132 log_MARKLINE_m; 00133 ostringstream sstr; 00134 sstr 00135 << "Not a tape drive device, but " 00136 << scsi_GetDeviceTypeText(m_scsiIO_ap->GetDeviceType()) 00137 << " for " << a_scsiID; 00138 00139 log_WriteEvent(evt_ERROR, sstr.str(), "", GetJobID()); 00140 00141 Close(); 00142 throw ivd_Error(ie_BEA_INVDEVTYPE, sstr.str()); 00143 }; 00144 00145 SetMedium(new bea_TapeMedium(m_scsiIO_ap.get())); 00146 00147 SetJobID(a_jobID); 00148 00149 if (GetMedium()->GetBarcode() != a_barcode) { 00150 GetMedium()->SetBarcode(a_barcode); 00151 } 00152 }

| void bea_TapeDrive::Close | ( | ) | [virtual] |
Implements bea_Drive.
Definition at line 154 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().
00154 { 00155 log_FUNC_m(Close); 00156 00157 g_cmn.evt.SetQualifier(""); 00158 00159 if (m_scsiIO_ap->IsOpen()) { 00160 00161 bea_Medium* med_p = GetMedium(); 00162 if (med_p != NULL && med_p->IsMediumMemValid()) { 00163 log_DBG_m(dbg_LOW, "Writing medium memory to tape"); 00164 try { 00165 med_p->GetMediumMem()->Write(); 00166 } 00167 catch (const ivd_Exception &ie) { 00168 log_DBG_m(dbg_LOW, "CM write error: " << ie); 00169 } 00170 catch (const std::exception &se) { 00171 log_DBG_m(dbg_LOW, "CM write error: " << se.what()); 00172 } 00173 catch (...) { 00174 log_DBG_m(dbg_LOW, "CM write error: unknown"); 00175 } 00176 } 00177 00178 m_scsiIO_ap->Close(); 00179 00180 // Will deallocate the object 00181 SetMedium(NULL); 00182 } 00183 else { 00184 log_DBG_m(dbg_DETAIL, 00185 "Drive not open. Do not perform SCSI close."); 00186 } 00187 }


| const string & bea_TapeDrive::GetVendorID | ( | ) | const [virtual] |
Implements bea_Drive.
Definition at line 189 of file bea_tapedrive.cpp.
References m_scsiIO_ap, and NULL.
00189 { 00190 if (m_scsiIO_ap.get() == NULL || !m_scsiIO_ap->IsOpen()) { 00191 static const string c_noVendorID("Unknown vendor ID"); 00192 return c_noVendorID; 00193 } 00194 return m_scsiIO_ap->GetVendorID(); 00195 }
| const string & bea_TapeDrive::GetProductID | ( | ) | const [virtual] |
Implements bea_Drive.
Definition at line 197 of file bea_tapedrive.cpp.
References m_scsiIO_ap, and NULL.
00197 { 00198 if (m_scsiIO_ap.get() == NULL || !m_scsiIO_ap->IsOpen()) { 00199 static const string c_noProductID("Unknown product ID"); 00200 return c_noProductID; 00201 } 00202 return m_scsiIO_ap->GetProductID(); 00203 }
| const string & bea_TapeDrive::GetProductRevision | ( | ) | const [virtual] |
Implements bea_Drive.
Definition at line 205 of file bea_tapedrive.cpp.
References m_scsiIO_ap, and NULL.
00205 { 00206 if (m_scsiIO_ap.get() == NULL || !m_scsiIO_ap->IsOpen()) { 00207 static const string c_noProductRev("Unknown product revision"); 00208 return c_noProductRev; 00209 } 00210 return m_scsiIO_ap->GetProductRevision(); 00211 }
| const string & bea_TapeDrive::GetSerialNumber | ( | ) | const [virtual] |
Implements bea_Drive.
Definition at line 213 of file bea_tapedrive.cpp.
References m_scsiIO_ap, and NULL.
00213 { 00214 if (m_scsiIO_ap.get() == NULL || !m_scsiIO_ap->IsOpen()) { 00215 static const string c_noSN("Unknown serial number"); 00216 return c_noSN; 00217 } 00218 return m_scsiIO_ap->GetProductSerialNumber(); 00219 }
| string bea_TapeDrive::GetSCSIID | ( | ) | const [virtual] |
Reimplemented from bea_Drive.
Definition at line 221 of file bea_tapedrive.cpp.
References m_scsiIO_ap, and NULL.
00221 { 00222 if (m_scsiIO_ap.get() == NULL || !m_scsiIO_ap->IsOpen()) { 00223 static const string c_noSID("Unknown SCSI ID"); 00224 return c_noSID; 00225 } 00226 return m_scsiIO_ap->GetSCSIID(); 00227 }
| bool bea_TapeDrive::WasMediumChanged | ( | ) | const [virtual] |
Reimplemented from bea_Drive.
Definition at line 229 of file bea_tapedrive.cpp.
References m_scsiIO_ap, and NULL.
00229 { 00230 if (m_scsiIO_ap.get() == NULL || !m_scsiIO_ap->IsOpen()) { 00231 return false; 00232 } 00233 return m_scsiIO_ap->GetPossibleMediumChange(); 00234 }
| UInt64_t bea_TapeDrive::GetDefaultSeekThreshold | ( | ) | const [virtual] |
Reimplemented from bea_Drive.
Definition at line 236 of file bea_tapedrive.cpp.
References cfg_MEGABYTE, dbg_DETAIL, bea_Drive::GetMedium(), log_DBG_m, and log_FUNC_m.
00236 { 00237 00238 log_FUNC_m(GetDefaultSeekThreshold); 00239 00240 UInt64_t defaultThreshold(GetMedium()->GetSize()); 00241 defaultThreshold *= 5LL * cfg_MEGABYTE / 100LL; 00242 00243 log_DBG_m(dbg_DETAIL, "5% of med size: " << defaultThreshold); 00244 00245 return defaultThreshold; 00246 }

bea_TapeDrive::log_CLASSID_m [private] |
auto_ptr<scsi_IO> bea_TapeDrive::m_scsiIO_ap [private] |
Definition at line 53 of file bea_tapedrive.h.
Referenced by bea_TapeDrive(), Close(), GetProductID(), GetProductRevision(), GetSCSIID(), GetSerialNumber(), GetVendorID(), Open(), and WasMediumChanged().
1.5.6