Commit f666b08e authored by Michael Davis's avatar Michael Davis Committed by Cedric Caffy
Browse files

[LTO_RAO] Implements Drive::getPhysicalPositionInfo()

parent 818b1080
......@@ -334,6 +334,39 @@ drive::positionInfo drive::DriveGeneric::getPositionInfo()
return posInfo;
}
/**
* Return physical position of the drive.
*
* @return physicalPositionInfo class. This contains the wrap and linear position (LPOS).
*/
drive::physicalPositionInfo drive::DriveGeneric::getPhysicalPositionInfo()
{
SCSI::Structures::requestSenseCDB_t cdb;
SCSI::Structures::requestSenseData_t requestSenseData;
SCSI::Structures::senseData_t<255> senseBuff;
SCSI::Structures::LinuxSGIO_t sgh;
// The full Request Sense data record is 96 bytes. However, we are only interested in
// the PHYSICAL WRAP and LPOS fields (bytes 29-33) so we can discard the rest.
cdb.allocationLength = 34;
sgh.setCDB(&cdb);
sgh.setDataBuffer(&requestSenseData);
sgh.setSenseBuffer(&senseBuff);
sgh.dxfer_direction = SG_DXFER_FROM_DEV;
// Manage both system error and SCSI errors
cta::exception::Errnum::throwOnMinusOne(
m_sysWrapper.ioctl(m_tapeFD, SG_IO, &sgh),
"Failed SG_IO ioctl in DriveGeneric::getPhysicalPositionInfo");
SCSI::ExceptionLauncher(sgh, "SCSI error in getPhysicalPositionInfo:");
physicalPositionInfo posInfo;
posInfo.wrap = requestSenseData.physicalWrap;
posInfo.lpos = SCSI::Structures::toU32(requestSenseData.relativeLPOSValue);
return posInfo;
}
/**
* Get tape alert information from the drive. There is a quite long list of possible tape alerts.
* They are described in SSC-4, section 4.2.20: TapeAlert application client interface.
......
......@@ -132,7 +132,14 @@ namespace drive {
* on the dirty data still in the write buffer.
*/
virtual positionInfo getPositionInfo() ;
/**
* Return physical position of the drive.
*
* @return physicalPositionInfo class. This contains the wrap and linear position (LPOS).
*/
virtual physicalPositionInfo getPhysicalPositionInfo();
/**
* Get tape alert information from the drive. There is a quite long list of possible tape alerts.
* They are described in SSC-4, section 4.2.20: TapeAlert application client interface
......
......@@ -111,12 +111,12 @@ namespace drive {
uint32_t lpos;
/**
* FORWARD means the current direction is away from the
* physical beginning of tape. REVERSE means the current
* physical beginning of tape. BACKWARD means the current
* direction is towards the physical beginning of tape.
*/
enum Direction_t { FORWARD, REVERSE };
enum Direction_t { FORWARD, BACKWARD };
Direction_t direction() {
return wrap & 1 ? REVERSE : FORWARD;
return wrap & 1 ? BACKWARD : FORWARD;
}
};
......@@ -212,6 +212,7 @@ namespace drive {
virtual std::string getSerialNumber() = 0;
virtual void positionToLogicalObject(uint32_t blockId) = 0;
virtual positionInfo getPositionInfo() = 0;
virtual physicalPositionInfo getPhysicalPositionInfo() = 0;
virtual std::vector<uint16_t> getTapeAlertCodes() = 0;
virtual std::vector<std::string> getTapeAlerts(const std::vector<uint16_t>&) = 0;
virtual std::vector<std::string> getTapeAlertsCompact (const std::vector<uint16_t>&) = 0;
......
......@@ -113,7 +113,8 @@ TEST(castor_tape_drive_Drive, getPositionInfoAndPositionToLogicalObject) {
std::unique_ptr<castor::tape::tapeserver::drive::DriveInterface> drive (
castor::tape::tapeserver::drive::createDrive(*i, sysWrapper));
castor::tape::tapeserver::drive::positionInfo posInfo;
castor::tape::tapeserver::drive::physicalPositionInfo physicalPosInfo;
EXPECT_CALL(sysWrapper, ioctl(_,_,An<sg_io_hdr_t*>())).Times(1);
posInfo = drive->getPositionInfo();
......@@ -121,7 +122,13 @@ TEST(castor_tape_drive_Drive, getPositionInfoAndPositionToLogicalObject) {
ASSERT_EQ(0x12EFCDABU,posInfo.oldestDirtyObject);
ASSERT_EQ(0xABCDEFU,posInfo.dirtyObjectsCount);
ASSERT_EQ(0x12EFCDABU,posInfo.dirtyBytesCount);
EXPECT_CALL(sysWrapper, ioctl(_,_,An<sg_io_hdr_t*>())).Times(1);
physicalPosInfo = drive->getPhysicalPositionInfo();
ASSERT_EQ(0x0, physicalPosInfo.wrap);
ASSERT_EQ(0x0, physicalPosInfo.lpos);
ASSERT_EQ(castor::tape::tapeserver::drive::physicalPositionInfo::FORWARD, physicalPosInfo.direction());
EXPECT_CALL(sysWrapper, ioctl(_,_,An<sg_io_hdr_t*>())).Times(1);
drive->positionToLogicalObject(0xABCDEF0);
......
......@@ -81,6 +81,7 @@ void castor::tape::tapeserver::drive::FakeDrive::positionToLogicalObject(uint32_
}
m_currentPosition = blockId;
}
castor::tape::tapeserver::drive::positionInfo castor::tape::tapeserver::drive::FakeDrive::getPositionInfo() {
positionInfo pos;
pos.currentPosition = m_currentPosition;
......@@ -90,6 +91,13 @@ castor::tape::tapeserver::drive::positionInfo castor::tape::tapeserver::drive::F
return pos;
}
castor::tape::tapeserver::drive::physicalPositionInfo castor::tape::tapeserver::drive::FakeDrive::getPhysicalPositionInfo() {
physicalPositionInfo pos;
pos.lpos = 0;
pos.wrap = m_currentPosition;
return pos;
}
std::vector<uint16_t> castor::tape::tapeserver::drive::FakeDrive::getTapeAlertCodes() {
std::vector<uint16_t> empty;
return empty;
......
......@@ -71,6 +71,7 @@ namespace drive {
virtual std::string getSerialNumber() ;
virtual void positionToLogicalObject(uint32_t blockId) ;
virtual positionInfo getPositionInfo() ;
virtual physicalPositionInfo getPhysicalPositionInfo();
virtual std::vector<uint16_t> getTapeAlertCodes();
virtual std::vector<std::string> getTapeAlerts(const std::vector<uint16_t>&) ;
virtual std::vector<std::string> getTapeAlertsCompact(const std::vector<uint16_t>&) ;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment