Commit 80cc337c authored by Daniele Francesco Kruse's avatar Daniele Francesco Kruse
Browse files

Added wrapper functions for Drive operations using the ST driver (no test just...

Added wrapper functions for Drive operations using the ST driver (no test just yet, will wait for the system test).
parent d255219e
......@@ -307,7 +307,24 @@ void Tape::Drive::setSTBufferWrite(bool bufWrite) throw (Tape::Exception) {
m_mtCmd.mt_op = MTSETDRVBUFFER;
m_mtCmd.mt_count = bufWrite ? (MT_ST_SETBOOLEANS | MT_ST_BUFFER_WRITES) : (MT_ST_CLEARBOOLEANS | MT_ST_BUFFER_WRITES);
if (-1 == m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd))
throw Tape::Exceptions::Errnum("Failed to (un)set ST Driver Option: MT_ST_BUFFER_WRITES");
throw Tape::Exceptions::Errnum("Failed ST ioctl (MTSETDRVBUFFER)");
}
/**
* Jump to end of recorded media. This will use setSTFastMTEOM() to disable MT_ST_FAST_MTEOM.
* (See TapeServer's handbook for details). This is used to rebuild the MIR (StorageTek)
* or tape directory (IBM).
* Tape directory rebuild is described only for IBM but currently applied to
* all tape drives.
* TODO: synchronous? Timeout?
*/
void Tape::Drive::spaceToEOM(void) throw (Tape::Exception) {
setSTFastMTEOM(false);
struct mtop m_mtCmd;
m_mtCmd.mt_op = MTEOM;
m_mtCmd.mt_count = 1;
if (-1 == m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd))
throw Tape::Exceptions::Errnum("Failed ST ioctl (MTEOM)");
}
/**
......@@ -321,7 +338,148 @@ void Tape::Drive::setSTFastMTEOM(bool fastMTEOM) throw (Tape::Exception) {
m_mtCmd.mt_op = MTSETDRVBUFFER;
m_mtCmd.mt_count = fastMTEOM ? (MT_ST_SETBOOLEANS | MT_ST_FAST_MTEOM) : (MT_ST_CLEARBOOLEANS | MT_ST_FAST_MTEOM);
if (-1 == m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd))
throw Tape::Exceptions::Errnum("Failed to (un)set ST Driver Option: MT_ST_FAST_EOM");
throw Tape::Exceptions::Errnum("Failed ST ioctl (MTSETDRVBUFFER)");
}
/**
* Jump to end of data. EOM in ST driver jargon, end of data (which is more accurate)
* in SCSI terminology). This uses the fast setting (not to be used for MIR rebuild)
*/
void Tape::Drive::fastSpaceToEOM(void) throw (Tape::Exception) {
setSTFastMTEOM(true);
struct mtop m_mtCmd;
m_mtCmd.mt_op = MTEOM;
m_mtCmd.mt_count = 1;
if (-1 == m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd))
throw Tape::Exceptions::Errnum("Failed ST ioctl (MTEOM)");
}
/**
* Rewind tape.
*/
void Tape::Drive::rewind(void) throw (Tape::Exception) {
struct mtop m_mtCmd;
m_mtCmd.mt_op = MTREW;
m_mtCmd.mt_count = 1;
if (-1 == m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd))
throw Tape::Exceptions::Errnum("Failed ST ioctl (MTREW)");
}
/**
* Space count files backwards.
* @param count
*/
void Tape::Drive::spaceFilesBackwards(size_t count) throw (Tape::Exception) {
struct mtop m_mtCmd;
m_mtCmd.mt_op = MTBSF;
m_mtCmd.mt_count = (int)count;
if (-1 == m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd))
throw Tape::Exceptions::Errnum("Failed ST ioctl (MTBSF)");
}
/**
* Space count files forward.
* @param count
*/
void Tape::Drive::spaceFilesForward(size_t count) throw (Tape::Exception) {
struct mtop m_mtCmd;
m_mtCmd.mt_op = MTFSF;
m_mtCmd.mt_count = (int)count;
if (-1 == m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd))
throw Tape::Exceptions::Errnum("Failed ST ioctl (MTFSF)");
}
/**
* Space count blocks backwards.
* @param count
*/
void Tape::Drive::spaceBlocksBackwards(size_t count) throw (Tape::Exception) {
struct mtop m_mtCmd;
m_mtCmd.mt_op = MTBSR;
m_mtCmd.mt_count = (int)count;
if (-1 == m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd))
throw Tape::Exceptions::Errnum("Failed ST ioctl (MTBSR)");
}
/**
* Space count blocks forward.
* @param count
*/
void Tape::Drive::spaceBlocksForward(size_t count) throw (Tape::Exception) {
struct mtop m_mtCmd;
m_mtCmd.mt_op = MTFSR;
m_mtCmd.mt_count = (int)count;
if (-1 == m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd))
throw Tape::Exceptions::Errnum("Failed ST ioctl (MTFSR)");
}
/**
* Unload the tape.
*/
void Tape::Drive::unloadTape(void) throw (Tape::Exception) {
struct mtop m_mtCmd;
m_mtCmd.mt_op = MTUNLOAD;
m_mtCmd.mt_count = 1;
if (-1 == m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd))
throw Tape::Exceptions::Errnum("Failed ST ioctl (MTUNLOAD)");
}
/**
* Synch call to the tape drive. This function will not return before the
* data in the drive's buffer is actually comitted to the medium.
*/
void Tape::Drive::sync(void) throw (Tape::Exception) {
struct mtop m_mtCmd;
m_mtCmd.mt_op = MTNOP; //The side effect of the no-op is to actually flush the driver's buffer to tape (see "man st").
m_mtCmd.mt_count = 1;
if (-1 == m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd))
throw Tape::Exceptions::Errnum("Failed ST ioctl (MTNOP)");
}
/**
* Write count file marks. The function does not return before the file marks
* are committed to medium.
* @param count
*/
void Tape::Drive::writeSyncFileMarks(size_t count) throw (Tape::Exception) {
struct mtop m_mtCmd;
m_mtCmd.mt_op = MTWEOF;
m_mtCmd.mt_count = (int)count;
if (-1 == m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd))
throw Tape::Exceptions::Errnum("Failed ST ioctl (MTWEOF)");
}
/**
* Write count file marks asynchronously. The file marks are just added to the drive's
* buffer and the function return immediately.
* @param count
*/
void Tape::Drive::writeImmediateFileMarks(size_t count) throw (Tape::Exception) {
struct mtop m_mtCmd;
m_mtCmd.mt_op = MTWEOFI; //Undocumented in "man st" needs the mtio_add.hh header file (see above)
m_mtCmd.mt_count = (int)count;
if (-1 == m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd))
throw Tape::Exceptions::Errnum("Failed ST ioctl (MTWEOFI)");
}
/**
* Write a data block to tape.
* @param data pointer the the data block
* @param count size of the data block
*/
void Tape::Drive::writeBlock(const unsigned char * data, size_t count) throw (Tape::Exception) {
if (-1 == m_sysWrapper.write(m_tapeFD, data, count))
throw Tape::Exceptions::Errnum("Failed ST write");
}
/**
* Read a data block from tape.
* @param data pointer the the data block
* @param count size of the data block
*/
void Tape::Drive::readBlock(unsigned char * data, size_t count) throw (Tape::Exception) {
if (-1 == m_sysWrapper.read(m_tapeFD, data, count))
throw Tape::Exceptions::Errnum("Failed ST read");
}
void Tape::Drive::SCSI_inquiry() {
......
......@@ -29,6 +29,8 @@
#include "../System/Wrapper.hh"
#include "../Exception/Exception.hh"
#include "mtio_add.hh"
/**
* Class wrapping the tape server. Has to be templated (and hence fully in .hh)
* to allow unit testing against system wrapper.
......@@ -223,14 +225,6 @@ namespace Tape {
*/
virtual void setSTBufferWrite(bool bufWrite) throw (Exception);
/**
* Set the MTFastEOM option of the ST driver. This function is used only internally in
* mounttape (in CAStor), so it could be a private function, not visible to
* the higher levels of the software (TODO: protected?).
* @param fastMTEOM the option switch.
*/
virtual void setSTFastMTEOM(bool fastMTEOM) throw (Exception);
/**
* Jump to end of media. This will use setSTFastMTEOM() to disable MT_ST_FAST_MTEOM.
* (See TapeServer's handbook for details). This is used to rebuild the MIR (StorageTek)
......@@ -239,107 +233,81 @@ namespace Tape {
* all tape drives.
* TODO: synchronous? Timeout?
*/
virtual void fastSpaceToEOM(void) throw (Exception) {
throw Exception("Not implemented");
}
virtual void fastSpaceToEOM(void) throw (Exception);
/**
* Rewind tape.
*/
virtual void rewind(void) throw (Exception) {
throw Exception("Not implemented");
}
virtual void rewind(void) throw (Exception);
/**
* Jump to end of data. EOM in ST driver jargon, end of data (which is more accurate)
* in SCSI terminology).
*/
virtual void spaceToEOM(void) throw (Exception) {
throw Exception("Not implemented");
}
virtual void spaceToEOM(void) throw (Exception);
/**
* Space count files backwards.
* @param count
*/
virtual void spaceFilesBackward(size_t count) throw (Exception) {
throw Exception("Not implemented");
}
virtual void spaceFilesBackwards(size_t count) throw (Exception);
/**
* Space count files forward.
* @param count
*/
virtual void spaceFilesForward(size_t count) throw (Exception) {
throw Exception("Not implemented");
}
virtual void spaceFilesForward(size_t count) throw (Exception);
/**
* Space count blocks backwards.
* @param count
*/
virtual void spaceBlocksBackwards(size_t count) throw (Exception) {
throw Exception("Not implemented");
}
virtual void spaceBlocksBackwards(size_t count) throw (Exception);
/**
* Space count blocks forward.
* @param count
*/
virtual void spaceBlocksForward(size_t count) throw (Exception) {
throw Exception("Not implemented");
}
virtual void spaceBlocksForward(size_t count) throw (Exception);
/**
* Unload the tape.
*/
virtual void unloadTape(void) throw (Exception) {
throw Exception("Not implemented");
}
virtual void unloadTape(void) throw (Exception);
/**
* Synch call to the tape drive. This function will not return before the
* data in the drive's buffer is actually comitted to the medium.
*/
virtual void sync(void) throw (Exception) {
throw Exception("Not implemented");
}
virtual void sync(void) throw (Exception);
/**
* Write count file marks. The function does not return before the file marks
* are committed to medium.
* @param count
*/
virtual void writeSyncFileMarks(size_t count) throw (Exception) {
throw Exception("Not implemented");
}
virtual void writeSyncFileMarks(size_t count) throw (Exception);
/**
* Write count file marks asynchronously. The file marks are just added to the drive's
* buffer and the function return immediately.
* @param count
*/
virtual void writeImmediateFileMarks(size_t count) throw (Exception) {
throw Exception("Not implemented");
}
virtual void writeImmediateFileMarks(size_t count) throw (Exception);
/**
* Write a data block to tape.
* @param data pointer the the data block
* @param count size of the data block
*/
virtual void writeBlock(const unsigned char * data, size_t count) throw (Exception) {
throw Exception("Not implemented");
}
virtual void writeBlock(const unsigned char * data, size_t count) throw (Exception);
/**
* Read a data block from tape.
* @param data pointer the the data block
* @param count size of the data block
*/
virtual void readBlock(unsigned char * data, size_t count) throw (Exception) {
throw Exception("Not implemented");
}
virtual void readBlock(unsigned char * data, size_t count) throw (Exception);
virtual ~Drive() {
if (-1 != m_tapeFD)
......@@ -356,7 +324,13 @@ namespace Tape {
Tape::System::virtualWrapper & m_sysWrapper;
struct mtget m_mtInfo;
private:
/**
* Set the MTFastEOM option of the ST driver. This function is used only internally in
* mounttape (in CAStor), so it could be a private function, not visible to
* the higher levels of the software (TODO: protected?).
* @param fastMTEOM the option switch.
*/
virtual void setSTFastMTEOM(bool fastMTEOM) throw (Exception);
void SCSI_inquiry(int fd);
};
......
......@@ -185,12 +185,6 @@ TEST(TapeDrive, setStDriverOptions) {
EXPECT_CALL(sysWrapper, ioctl(_,_,An<struct mtop *>())).Times(1);
drive.setSTBufferWrite(false);
EXPECT_CALL(sysWrapper, ioctl(_,_,An<struct mtop *>())).Times(1);
drive.setSTFastMTEOM(true);
EXPECT_CALL(sysWrapper, ioctl(_,_,An<struct mtop *>())).Times(1);
drive.setSTFastMTEOM(false);
}
}
}
......
/*
* Define the write immediate file mark operation code in case it is absent from mtio.h
*/
#ifndef _MTIO_ADD_H
#define _MTIO_ADD_H
/* in case MTWEOFI is not defined in linux/mtio.h */
#ifndef MTWEOFI
#define MTWEOFI 35
#endif
#endif
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