Skip to content
Snippets Groups Projects
Commit 345711de authored by Daniele Kruse's avatar Daniele Kruse
Browse files

moved job receiving and checking inside VdqmConnectionHandler

parent f8f4defc
Branches
Tags
No related merge requests found
......@@ -42,17 +42,6 @@ public:
*/
virtual ~Vdqm() throw() = 0;
/**
* Receives a job from the specified connection with the vdqm daemon,
* sends back a positive acknowledgement and closes the connection.
*
* @param connection The file descriptor of the connection with the vdqm
* daemon.
* @return The job request from the vdqm.
*/
virtual legacymsg::RtcpJobRqstMsgBody receiveJob(const int connection)
throw(castor::exception::Exception) = 0;
/**
* Sets the status of the specified tape drive to down.
*
......
......@@ -36,8 +36,9 @@ castor::tape::tapeserver::daemon::VdqmConnectionHandler::VdqmConnectionHandler(
m_reactor(reactor),
m_log(log),
m_vdqm(vdqm),
m_driveCatalogue(driveCatalogue) {
}
m_driveCatalogue(driveCatalogue),
m_netTimeout(1) //hard-coded to 1 second
{}
//------------------------------------------------------------------------------
// destructor
......@@ -74,7 +75,7 @@ void castor::tape::tapeserver::daemon::VdqmConnectionHandler::handleEvent(
return;
}
const legacymsg::RtcpJobRqstMsgBody job = m_vdqm.receiveJob(fd.fd);
const legacymsg::RtcpJobRqstMsgBody job = receiveJob(fd.fd);
logVdqmJobReception(job);
m_reactor.removeHandler(this);
......@@ -98,3 +99,105 @@ void
log::Param("clientUserName", job.clientUserName)};
m_log(LOG_INFO, "Received job from the vdqmd daemon", params);
}
//------------------------------------------------------------------------------
// receiveJob
//------------------------------------------------------------------------------
castor::tape::legacymsg::RtcpJobRqstMsgBody
castor::tape::tapeserver::daemon::VdqmConnectionHandler::receiveJob(const int connection)
throw(castor::exception::Exception) {
const legacymsg::MessageHeader header = receiveJobMsgHeader(connection);
const legacymsg::RtcpJobRqstMsgBody body =
receiveJobMsgBody(connection, header.lenOrStatus);
return body;
}
//------------------------------------------------------------------------------
// receiveJobMsgHeader
//------------------------------------------------------------------------------
castor::tape::legacymsg::MessageHeader
castor::tape::tapeserver::daemon::VdqmConnectionHandler::receiveJobMsgHeader(
const int connection) throw(castor::exception::Exception) {
// Read in the message header
char buf[3 * sizeof(uint32_t)]; // magic + request type + len
io::readBytes(connection, m_netTimeout, sizeof(buf), buf);
const char *bufPtr = buf;
size_t bufLen = sizeof(buf);
legacymsg::MessageHeader header;
memset(&header, '\0', sizeof(header));
legacymsg::unmarshal(bufPtr, bufLen, header);
checkJobMsgMagic(header.magic);
checkJobMsgReqType(header.reqType);
// The length of the message body is checked later, just before it is read in
// to memory
return header;
}
//------------------------------------------------------------------------------
// receiveJobMsgBody
//------------------------------------------------------------------------------
castor::tape::legacymsg::RtcpJobRqstMsgBody
castor::tape::tapeserver::daemon::VdqmConnectionHandler::receiveJobMsgBody(
const int connection, const uint32_t len)
throw(castor::exception::Exception) {
char buf[1024];
checkJobMsgLen(sizeof(buf), len);
io::readBytes(connection, m_netTimeout, len, buf);
legacymsg::RtcpJobRqstMsgBody body;
memset(&body, '\0', sizeof(body));
const char *bufPtr = buf;
size_t bufLen = sizeof(buf);
legacymsg::unmarshal(bufPtr, bufLen, body);
return body;
}
//------------------------------------------------------------------------------
// checkJobMsgMagic
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::VdqmConnectionHandler::checkJobMsgMagic(
const uint32_t magic) const throw(castor::exception::Exception) {
const uint32_t expectedMagic = RTCOPY_MAGIC_OLD0;
if(expectedMagic != magic) {
castor::exception::Exception ex(EBADMSG);
ex.getMessage() << "Invalid vdqm job message: Invalid magic number"
": expected=0x" << std::hex << expectedMagic <<
" actual: 0x" << std::hex << magic;
throw ex;
}
}
//------------------------------------------------------------------------------
// checkJobMsgReqType
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::VdqmConnectionHandler::checkJobMsgReqType(
const uint32_t reqType) const throw(castor::exception::Exception) {
const uint32_t expectedReqType = VDQM_CLIENTINFO;
if(expectedReqType != reqType) {
castor::exception::Exception ex(EBADMSG);
ex.getMessage() << "Invalid vdqm job message: Invalid request type"
": expected=0x" << std::hex << expectedReqType <<
" actual=0x" << std::hex << reqType;
throw ex;
}
}
//------------------------------------------------------------------------------
// checkJobMsgLen
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::VdqmConnectionHandler::checkJobMsgLen(
const size_t maxLen, const size_t len) const
throw(castor::exception::Exception) {
if(maxLen < len) {
castor::exception::Exception ex(EBADMSG);
ex.getMessage() << "Invalid vdqm job message"
": Maximum message length exceeded"
": maxLen=" << maxLen << " len=" << len;
throw ex;
}
}
......@@ -28,6 +28,13 @@
#include "castor/log/Logger.hpp"
#include "castor/tape/tapeserver/daemon/DriveCatalogue.hpp"
#include "castor/tape/tapeserver/daemon/Vdqm.hpp"
#include "castor/tape/legacymsg/MessageHeader.hpp"
#include "castor/io/io.hpp"
#include "castor/tape/legacymsg/CommonMarshal.hpp"
#include "castor/tape/legacymsg/RtcpMarshal.hpp"
#include "castor/tape/legacymsg/VdqmMarshal.hpp"
#include "h/vdqm_constants.h"
#include "h/rtcp_constants.h"
#include <poll.h>
......@@ -105,13 +112,77 @@ private:
* The catalogue of tape drives controlled by the tape server daemon.
*/
DriveCatalogue &m_driveCatalogue;
/**
* The timeout in seconds to be applied when performing network read and
* write operations.
*/
const int m_netTimeout;
/**
* Logs the reception of the specified job message from the vdqmd daemon.
*/
void logVdqmJobReception(const legacymsg::RtcpJobRqstMsgBody &job)
const throw();
/**
* Receives a job from the specified connection with the vdqm daemon,
* sends back a positive acknowledgement and closes the connection.
*
* @param connection The file descriptor of the connection with the vdqm
* daemon.
* @return The job request from the vdqm.
*/
legacymsg::RtcpJobRqstMsgBody receiveJob(const int connection)
throw(castor::exception::Exception);
/**
* Receives the header of a job message from the specified connection with
* the vdqm daemon.
*
* @param connection The file descriptor of the connection with the vdqm
* daemon.
* @return The message header.
*/
legacymsg::MessageHeader receiveJobMsgHeader(const int connection)
throw(castor::exception::Exception);
/**
* Receives the body of a job message from the specified connection with the
* vdqm daemon.
*
* @param connection The file descriptor of the connection with the vdqm
* daemon.
* @param len The length of the message body in bytes.
* @return The message body.
*/
legacymsg::RtcpJobRqstMsgBody receiveJobMsgBody(const int connection,
const uint32_t len) throw(castor::exception::Exception);
/**
* Throws an exception if the specified magic number is invalid for a vdqm
* job message.
*/
void checkJobMsgMagic(const uint32_t magic) const
throw(castor::exception::Exception);
/**
* Throws an exception if the specified request type is invalid for a vdqm
* job message.
*/
void checkJobMsgReqType(const uint32_t reqType) const
throw(castor::exception::Exception);
/**
* Throws an exception if the specified message body length is invalid for
* a vdqm job message.
*
* @param maxLen The maximum length in bytes
* @param len The actual length in bytes.
*/
void checkJobMsgLen(const size_t maxLen, const size_t len) const
throw(castor::exception::Exception);
}; // class VdqmConnectionHandler
} // namespace daemon
......
......@@ -53,108 +53,6 @@ castor::tape::tapeserver::daemon::VdqmImpl::VdqmImpl(
castor::tape::tapeserver::daemon::VdqmImpl::~VdqmImpl() throw() {
}
//------------------------------------------------------------------------------
// receiveJob
//------------------------------------------------------------------------------
castor::tape::legacymsg::RtcpJobRqstMsgBody
castor::tape::tapeserver::daemon::VdqmImpl::receiveJob(const int connection)
throw(castor::exception::Exception) {
const legacymsg::MessageHeader header = receiveJobMsgHeader(connection);
const legacymsg::RtcpJobRqstMsgBody body =
receiveJobMsgBody(connection, header.lenOrStatus);
return body;
}
//------------------------------------------------------------------------------
// receiveJobMsgHeader
//------------------------------------------------------------------------------
castor::tape::legacymsg::MessageHeader
castor::tape::tapeserver::daemon::VdqmImpl::receiveJobMsgHeader(
const int connection) throw(castor::exception::Exception) {
// Read in the message header
char buf[3 * sizeof(uint32_t)]; // magic + request type + len
io::readBytes(connection, m_netTimeout, sizeof(buf), buf);
const char *bufPtr = buf;
size_t bufLen = sizeof(buf);
legacymsg::MessageHeader header;
memset(&header, '\0', sizeof(header));
legacymsg::unmarshal(bufPtr, bufLen, header);
checkJobMsgMagic(header.magic);
checkJobMsgReqType(header.reqType);
// The length of the message body is checked later, just before it is read in
// to memory
return header;
}
//------------------------------------------------------------------------------
// checkJobMsgMagic
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::VdqmImpl::checkJobMsgMagic(
const uint32_t magic) const throw(castor::exception::Exception) {
const uint32_t expectedMagic = RTCOPY_MAGIC_OLD0;
if(expectedMagic != magic) {
castor::exception::Exception ex(EBADMSG);
ex.getMessage() << "Invalid vdqm job message: Invalid magic number"
": expected=0x" << std::hex << expectedMagic <<
" actual: 0x" << std::hex << magic;
throw ex;
}
}
//------------------------------------------------------------------------------
// checkJobMsgReqType
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::VdqmImpl::checkJobMsgReqType(
const uint32_t reqType) const throw(castor::exception::Exception) {
const uint32_t expectedReqType = VDQM_CLIENTINFO;
if(expectedReqType != reqType) {
castor::exception::Exception ex(EBADMSG);
ex.getMessage() << "Invalid vdqm job message: Invalid request type"
": expected=0x" << std::hex << expectedReqType <<
" actual=0x" << std::hex << reqType;
throw ex;
}
}
//------------------------------------------------------------------------------
// receiveJobMsgBody
//------------------------------------------------------------------------------
castor::tape::legacymsg::RtcpJobRqstMsgBody
castor::tape::tapeserver::daemon::VdqmImpl::receiveJobMsgBody(
const int connection, const uint32_t len)
throw(castor::exception::Exception) {
char buf[1024];
checkJobMsgLen(sizeof(buf), len);
io::readBytes(connection, m_netTimeout, len, buf);
legacymsg::RtcpJobRqstMsgBody body;
memset(&body, '\0', sizeof(body));
const char *bufPtr = buf;
size_t bufLen = sizeof(buf);
legacymsg::unmarshal(bufPtr, bufLen, body);
return body;
}
//------------------------------------------------------------------------------
// checkJobMsgLen
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::VdqmImpl::checkJobMsgLen(
const size_t maxLen, const size_t len) const
throw(castor::exception::Exception) {
if(maxLen < len) {
castor::exception::Exception ex(EBADMSG);
ex.getMessage() << "Invalid vdqm job message"
": Maximum message length exceeded"
": maxLen=" << maxLen << " len=" << len;
throw ex;
}
}
//------------------------------------------------------------------------------
// setTapeDriveStatusDown
//------------------------------------------------------------------------------
......
......@@ -59,17 +59,6 @@ public:
*/
~VdqmImpl() throw();
/**
* Receives a job from the specified connection with the vdqm daemon,
* sends back a positive acknowledgement and closes the connection.
*
* @param connection The file descriptor of the connection with the vdqm
* daemon.
* @return The job request from the vdqm.
*/
legacymsg::RtcpJobRqstMsgBody receiveJob(const int connection)
throw(castor::exception::Exception);
/**
* Sets the status of the specified tape drive to down.
*
......@@ -96,53 +85,6 @@ public:
private:
/**
* Receives the header of a job message from the specified connection with
* the vdqm daemon.
*
* @param connection The file descriptor of the connection with the vdqm
* daemon.
* @return The message header.
*/
legacymsg::MessageHeader receiveJobMsgHeader(const int connection)
throw(castor::exception::Exception);
/**
* Throws an exception if the specified magic number is invalid for a vdqm
* job message.
*/
void checkJobMsgMagic(const uint32_t magic) const
throw(castor::exception::Exception);
/**
* Throws an exception if the specified request type is invalid for a vdqm
* job message.
*/
void checkJobMsgReqType(const uint32_t reqType) const
throw(castor::exception::Exception);
/**
* Receives the body of a job message from the specified connection with the
* vdqm daemon.
*
* @param connection The file descriptor of the connection with the vdqm
* daemon.
* @param len The length of the message body in bytes.
* @return The message body.
*/
legacymsg::RtcpJobRqstMsgBody receiveJobMsgBody(const int connection,
const uint32_t len) throw(castor::exception::Exception);
/**
* Throws an exception if the specified message body length is invalid for
* a vdqm job message.
*
* @param maxLen The maximum length in bytes
* @param len The actual length in bytes.
*/
void checkJobMsgLen(const size_t maxLen, const size_t len) const
throw(castor::exception::Exception);
/**
* Sets the status of the specified drive to the specified value.
*
......@@ -176,7 +118,7 @@ private:
* The TCP/IP port on which the vdqmd daemon is listening.
*/
const unsigned short m_vdqmPort;
/**
* The timeout in seconds to be applied when performing network read and
* write operations.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment