Commit d5a8098c authored by Cristina Moraru's avatar Cristina Moraru
Browse files

After feedback


Signed-off-by: default avatarCristina Moraru <cristina-gabriela.moraru@cern.ch>
parent c8b74a53
......@@ -1309,6 +1309,7 @@ namespace SCSI {
blockLims() {
zeroStruct(this);
}
unsigned char fseq[10];
int begin;
int end;
};
......
......@@ -33,6 +33,7 @@
#include <string>
#include <map>
#include <list>
namespace castor {
namespace tape {
......@@ -757,19 +758,12 @@ SCSI::Structures::RAO::udsLimitsPage_t drive::DriveGeneric::getLimitUDS() {
SCSI::Structures::LinuxSGIO_t sgh;
SCSI::Structures::RAO::recieveRAO_t cdb;
SCSI::Structures::senseData_t<127> senseBuff;
unsigned char dataBuff[4];
SCSI::Structures::setU32(cdb.allocationLength, SCSI::modeRAO::DEFAULT_RRAO_ALLOCATION);
if (this->getDeviceInfo().vendor.substr(0, 3) == "IBM") {
cdb.serviceAction = 0x11;
std::cout << "vendor IBM" << std::endl;
}
else if (this->getDeviceInfo().vendor.substr(0, 3) == "STK") {
cdb.serviceAction = 0x1d;
}
unsigned char dataBuff[sizeof(SCSI::Structures::RAO::udsLimitsPage_t)];
cdb.serviceAction = 0x1d;
cdb.udsLimits = 1;
SCSI::Structures::setU32(cdb.allocationLength, SCSI::modeRAO::DEFAULT_RRAO_ALLOCATION);
sgh.setCDB(&cdb);
sgh.setSenseBuffer(&senseBuff);
sgh.setDataBuffer(&dataBuff);
......@@ -783,26 +777,25 @@ SCSI::Structures::RAO::udsLimitsPage_t drive::DriveGeneric::getLimitUDS() {
SCSI::Structures::RAO::udsLimitsPage_t & limits =
*(SCSI::Structures::RAO::udsLimitsPage_t *) dataBuff;
return limits;
}
void drive::DriveGeneric::generateRAO(std::map<std::string, SCSI::Structures::RAO::blockLims> blocks,
int maxSupported) {
void drive::DriveGeneric::generateRAO(std::list<SCSI::Structures::RAO::blockLims> &files,
int maxSupported) {
SCSI::Structures::LinuxSGIO_t sgh;
SCSI::Structures::RAO::generateRAO_t cdb;
SCSI::Structures::senseData_t<127> senseBuff;
//unsigned char dataBuff[1024];
int udSize = std::min((int) blocks.size(), maxSupported);
SCSI::Structures::RAO::udsDescriptor *ud = new SCSI::Structures::RAO::udsDescriptor[udSize];
auto it = blocks.begin();
for (int i = 0;i < udSize;++i) {
memcpy(ud[i].udsName, it->first.c_str(), sizeof(ud[i].udsName));
SCSI::Structures::setU64(ud[i].beginLogicalObjID, it->second.begin);
SCSI::Structures::setU64(ud[i].endLogicalObjID, it->second.end);
int udSize = std::min((int) files.size(), maxSupported);
std::unique_ptr<SCSI::Structures::RAO::udsDescriptor[]> ud (new SCSI::Structures::RAO::udsDescriptor[udSize]());
auto it = files.begin();
for (int i = 0; i < udSize; ++i) {
strncpy((char*)ud.get()[i].udsName, (char*)it->fseq, 10);
SCSI::Structures::setU64(ud.get()[i].beginLogicalObjID, it->begin);
SCSI::Structures::setU64(ud.get()[i].endLogicalObjID, it->end);
++it;
}
......@@ -810,14 +803,11 @@ void drive::DriveGeneric::generateRAO(std::map<std::string, SCSI::Structures::RA
int real_params_len = sizeof(params) - (2000 - udSize) *
sizeof(SCSI::Structures::RAO::udsDescriptor);
if (this->getDeviceInfo().vendor.substr(0, 3) == "IBM")
cdb.serviceAction = 0x11;
else if (this->getDeviceInfo().vendor.substr(0, 3) == "STK")
cdb.serviceAction = 0x1d;
cdb.serviceAction = 0x1d;
SCSI::Structures::setU32(cdb.paramsListLength, real_params_len);
SCSI::Structures::setU32(params.additionalData, udSize * sizeof(*ud));
memcpy(&params.userDataSegmentDescriptors, ud, udSize * sizeof(*ud));
SCSI::Structures::setU32(params.additionalData, udSize * sizeof(*(ud.get())));
memcpy(&params.userDataSegmentDescriptors, ud.get(), udSize * sizeof(*(ud.get())));
sgh.setCDB(&cdb);
sgh.setSenseBuffer(&senseBuff);
......@@ -836,14 +826,10 @@ void drive::DriveGeneric::receiveRAO(int offset, int allocationLength) {
SCSI::Structures::LinuxSGIO_t sgh;
SCSI::Structures::RAO::recieveRAO_t cdb;
SCSI::Structures::senseData_t<255> senseBuff;
unsigned char dataBuff[64008];
unsigned char dataBuff[sizeof(SCSI::Structures::RAO::raoList)];
cdb.udsLimits = 0;
if (this->getDeviceInfo().vendor.substr(0, 3) == "IBM")
cdb.serviceAction = 0x11;
else if (this->getDeviceInfo().vendor.substr(0, 3) == "STK")
cdb.serviceAction = 0x1d;
cdb.serviceAction = 0x1d;
SCSI::Structures::setU32(cdb.allocationLength, allocationLength);
SCSI::Structures::setU32(cdb.raoListOffset, offset);
......@@ -869,34 +855,7 @@ void drive::DriveGeneric::receiveRAO(int offset, int allocationLength) {
}
}
std::vector<std::string> split(std::string to_split, std::string delimiter) {
std::vector<std::string> toBeReturned;
int pos = 0;
while ((pos = to_split.find(delimiter)) != -1) {
std::string token = to_split.substr(0, pos);
toBeReturned.push_back(token);
to_split.erase(0, pos + delimiter.length());
}
toBeReturned.push_back(to_split);
return toBeReturned;
}
void drive::DriveGeneric::queryRAO(char *filename) {
std::map<std::string, SCSI::Structures::RAO::blockLims> files;
std::ifstream ns_file_pick(filename);
if (ns_file_pick.is_open()) {
std::string line;
while (getline(ns_file_pick, line)) {
std::vector<std::string> tokens = split(line, ":");
SCSI::Structures::RAO::blockLims lims;
lims.begin = std::stoi(tokens[1]);
lims.end = std::stoi(tokens[2]);
files[tokens[0]] = lims;
}
}
else {
throw -1;
}
void drive::DriveGeneric::queryRAO(std::list<SCSI::Structures::RAO::blockLims> &files) {
SCSI::Structures::RAO::udsLimitsPage_t limits = getLimitUDS();
generateRAO(files, limits.maxSupported);
......
......@@ -458,7 +458,7 @@ namespace drive {
* @param filename The name of the file containing the sequential order of
* a list of files [line format: ID:BLOCK_START:BLOCK_END]
*/
virtual void queryRAO(char *filename);
virtual void queryRAO(std::list<SCSI::Structures::RAO::blockLims> &files);
protected:
SCSI::DeviceInfo m_SCSIInfo;
......@@ -507,7 +507,7 @@ namespace drive {
* and a pair of block limits
* @param maxSupported The maximum number of UDS supported - obtained by getLimitUDS()
*/
virtual void generateRAO(std::map<std::string, SCSI::Structures::RAO::blockLims> blocks, int maxSupported);
virtual void generateRAO(std::list<SCSI::Structures::RAO::blockLims> &files, int maxSupported);
/**
* Receive the Recommended Access Order
......
......@@ -33,6 +33,8 @@
#include "common/exception/Exception.hpp"
#include "common/exception/TimeOut.hpp"
#include <list>
/**
* Class wrapping the tape server. Has to be templated (and hence fully in .hh)
* to allow unit testing against system wrapper.
......@@ -230,7 +232,7 @@ namespace drive {
virtual lbpToUse getLbpToUse() = 0;
virtual bool hasTapeInPlace() = 0;
virtual void queryRAO(char *filename) = 0;
virtual void queryRAO(std::list<SCSI::Structures::RAO::blockLims> &files) = 0;
/**
* The configuration of the tape drive as parsed from the TPCONFIG file.
......
......@@ -297,7 +297,8 @@ bool castor::tape::tapeserver::drive::FakeDrive::hasTapeInPlace() {
return true;
}
void castor::tape::tapeserver::drive::FakeDrive::queryRAO(char *filename) {
void castor::tape::tapeserver::drive::FakeDrive::queryRAO(
std::list<SCSI::Structures::RAO::blockLims> &files) {
throw cta::exception::Exception("In DriveFakeDrive::queryRAO: Not implemented.");
}
......
......@@ -109,7 +109,7 @@ namespace drive {
virtual bool isTapeBlank();
virtual lbpToUse getLbpToUse();
virtual bool hasTapeInPlace();
virtual void queryRAO(char *filename);
virtual void queryRAO(std::list<SCSI::Structures::RAO::blockLims> &files);
};
}}}}
......@@ -35,6 +35,7 @@
#include <assert.h>
#include <memory>
#include <string>
#include <list>
char gen_random() {
static const char alphanum[] =
......@@ -69,6 +70,18 @@ public:
}
};
std::vector<std::string> split(std::string to_split, std::string delimiter) {
std::vector<std::string> toBeReturned;
int pos = 0;
while ((pos = to_split.find(delimiter)) != -1) {
std::string token = to_split.substr(0, pos);
toBeReturned.push_back(token);
to_split.erase(0, pos + delimiter.length());
}
toBeReturned.push_back(to_split);
return toBeReturned;
}
int main (int argc, char *argv[])
{
int fail = 0;
......@@ -227,7 +240,27 @@ int main (int argc, char *argv[])
}
else {
drive->rewind();
drive->queryRAO(argv[1]);
std::list<castor::tape::SCSI::Structures::RAO::blockLims> files;
std::ifstream ns_file_pick(argv[1]);
if (ns_file_pick.is_open()) {
std::string line;
while (getline(ns_file_pick, line)) {
std::vector<std::string> tokens = split(line, ":");
castor::tape::SCSI::Structures::RAO::blockLims lims;
std::cout << tokens[0].c_str() << std::endl;
tokens[0] += '\0';
strcpy((char*)lims.fseq, tokens[0].c_str());
lims.begin = std::stoi(tokens[1]);
lims.end = std::stoi(tokens[2]);
files.push_back(lims);
}
}
else {
throw -1;
}
drive->queryRAO(files);
}
}
......
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