diff --git a/.gitignore b/.gitignore index 710a8d72aca1479b247bd0decac75a06b475cc63..d96d064043299cf1005d91ea1c2d03da81acc894 100644 --- a/.gitignore +++ b/.gitignore @@ -38,7 +38,6 @@ castor/tape/rechandler/rechandlerd castor/tape/rmc/castor-tape-acs-dismount castor/tape/rmc/castor-tape-acs-mount castor/tape/rmc/castor-tape-acs-queryvolume -castor/tape/rmc/castor-tape-mount castor/tape/tapebridge/tapebridged castor/tape/tapegateway/tapegatewayd castor/tape/tpcp/dumptp diff --git a/castor/legacymsg/CMakeLists.txt b/castor/legacymsg/CMakeLists.txt index 853a3aa655edd83901f591c59d087cb0724efdd8..65d93bd61514c50255de21c8fc8d59f509364a8d 100644 --- a/castor/legacymsg/CMakeLists.txt +++ b/castor/legacymsg/CMakeLists.txt @@ -38,7 +38,6 @@ set (CASTOR_LEGACYMSG_LIB_SRC_FILES NsProxyFactory.cpp NsProxy_TapeAlwaysEmpty.cpp NsProxy_TapeAlwaysEmptyFactory.cpp - RmcAcsMntMsgBody.cpp RmcMarshal.cpp RmcMountMsgBody.cpp RmcProxy.cpp diff --git a/castor/legacymsg/RmcAcsMntMsgBody.cpp b/castor/legacymsg/RmcAcsMntMsgBody.cpp deleted file mode 100644 index b3812aa25459d1b45cf2a8338e9059ba6df98194..0000000000000000000000000000000000000000 --- a/castor/legacymsg/RmcAcsMntMsgBody.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/legacymsg/RmcAcsMntMsgBody.hpp" - -#include <string.h> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::legacymsg::RmcAcsMntMsgBody::RmcAcsMntMsgBody() throw(): - uid(0), - gid(0), - acs(0), - lsm(0), - panel(0), - transport(0) { - memset(vid, '\0', sizeof(vid)); -} diff --git a/castor/legacymsg/RmcAcsMntMsgBody.hpp b/castor/legacymsg/RmcAcsMntMsgBody.hpp deleted file mode 100644 index de9902356af89754eff6255c38394ef0da25d3da..0000000000000000000000000000000000000000 --- a/castor/legacymsg/RmcAcsMntMsgBody.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "h/Castor_limits.h" - -#include <stdint.h> - -namespace castor { -namespace legacymsg { - -/** - * The body of an RMC_ACS_MOUNT message. - */ -struct RmcAcsMntMsgBody { - uint32_t uid; - uint32_t gid; - uint32_t acs; - uint32_t lsm; - uint32_t panel; - uint32_t transport; - char vid[CA_MAXVIDLEN + 1]; - - /** - * Constructor. - * - * Sets all integer member-variables to 0 and all string member-variables to - * the empty string. - */ - RmcAcsMntMsgBody() throw(); -}; // struct RmcAcsMntMsgBody - -} // namespace legacymsg -} // namespace castor - diff --git a/castor/legacymsg/RmcMarshal.cpp b/castor/legacymsg/RmcMarshal.cpp index 1a610b8bb83208f4bfbde9b965a275a720689e96..c5ed602f6f7578070e7f93680cd9ce0b18824930 100644 --- a/castor/legacymsg/RmcMarshal.cpp +++ b/castor/legacymsg/RmcMarshal.cpp @@ -29,110 +29,6 @@ #include <string.h> -//----------------------------------------------------------------------------- -// marshal -//----------------------------------------------------------------------------- -size_t castor::legacymsg::marshal(char *const dst, const size_t dstLen, const RmcAcsMntMsgBody &src) { - const char *task = "marshal RmcAcsMntMsgBody"; - - if(dst == NULL) { - castor::exception::Exception ex; - ex.getMessage() << "Failed to " << task << - ": Pointer to destination buffer is NULL"; - throw ex; - } - - // Calculate the length of the message body - const uint32_t bodyLen = - sizeof(src.uid) + - sizeof(src.gid) + - sizeof(src.acs) + - sizeof(src.lsm) + - sizeof(src.panel) + - sizeof(src.transport) + - strlen(src.vid) + 1; - - // Calculate the total length of the message (header + body) - const uint32_t totalLen = - sizeof(uint32_t) + // magic - sizeof(uint32_t) + // reqType - sizeof(uint32_t) + // len - bodyLen; - - // Check that the message buffer is big enough - if(totalLen > dstLen) { - castor::exception::Exception ex; - ex.getMessage() << "Failed to " << task << - ": Buffer too small: required=" << totalLen << " actual=" << dstLen; - throw ex; - } - - // Marshal message header - char *p = dst; - try { - const uint32_t magic = RMC_MAGIC; - const uint32_t reqType = RMC_ACS_MOUNT; - io::marshalUint32(magic , p); - io::marshalUint32(reqType, p); - io::marshalUint32(bodyLen, p); - } catch(castor::exception::Exception &ne) { - castor::exception::Exception ex; - ex.getMessage() << "Failed to " << task << ": Failed to marshal header: " - << ne.getMessage().str(); - throw ex; - } - - // Marshal message body - try { - io::marshalUint32(src.uid, p); - io::marshalUint32(src.gid, p); - io::marshalUint32(src.acs, p); - io::marshalUint32(src.lsm, p); - io::marshalUint32(src.panel, p); - io::marshalUint32(src.transport, p); - io::marshalString(src.vid, p); - } catch(castor::exception::Exception &ne) { - castor::exception::Exception ex; - ex.getMessage() << "Failed to " << task << ": Failed to marshal body: " - << ne.getMessage().str(); - throw ex; - } - - // Calculate the number of bytes actually marshalled - const size_t nbBytesMarshalled = p - dst; - - // Check that the number of bytes marshalled was what was expected - if(totalLen != nbBytesMarshalled) { - castor::exception::Exception ex; - ex.getMessage() << "Failed to " << task << - ": Mismatch between expected total length and actual" - ": expected=" << totalLen << " actual=" << nbBytesMarshalled; - throw ex; - } - - return totalLen; -} - -//----------------------------------------------------------------------------- -// unmarshal -//----------------------------------------------------------------------------- -void castor::legacymsg::unmarshal(const char * &src, size_t &srcLen, RmcAcsMntMsgBody &dst) { - try { - io::unmarshalUint32(src, srcLen, dst.uid); - io::unmarshalUint32(src, srcLen, dst.gid); - io::unmarshalUint32(src, srcLen, dst.acs); - io::unmarshalUint32(src, srcLen, dst.lsm); - io::unmarshalUint32(src, srcLen, dst.panel); - io::unmarshalUint32(src, srcLen, dst.transport); - io::unmarshalString(src, srcLen, dst.vid); - } catch(castor::exception::Exception &ne) { - castor::exception::Exception ex; - ex.getMessage() << "Failed to unmarshal RmcAcsMntMsgBody: " << - ne.getMessage().str(); - throw ex; - } -} - //----------------------------------------------------------------------------- // marshal //----------------------------------------------------------------------------- @@ -174,7 +70,7 @@ size_t castor::legacymsg::marshal(char *const dst, const size_t dstLen, const Rm char *p = dst; try { const uint32_t magic = RMC_MAGIC; - const uint32_t reqType = RMC_SCSI_MOUNT; + const uint32_t reqType = RMC_MOUNT; io::marshalUint32(magic , p); io::marshalUint32(reqType, p); io::marshalUint32(totalLen, p); @@ -275,7 +171,7 @@ size_t castor::legacymsg::marshal(char *const dst, const size_t dstLen, const Rm char *p = dst; try { const uint32_t magic = RMC_MAGIC; - const uint32_t reqType = RMC_SCSI_UNMOUNT; + const uint32_t reqType = RMC_UNMOUNT; io::marshalUint32(magic , p); io::marshalUint32(reqType, p); io::marshalUint32(totalLen, p); diff --git a/castor/legacymsg/RmcMarshal.hpp b/castor/legacymsg/RmcMarshal.hpp index 9694f6363b8995a4c767ebddc8f0880f7246ac80..b1742f36a7b151bc9e4e89e1176f5e0c1855328f 100644 --- a/castor/legacymsg/RmcMarshal.hpp +++ b/castor/legacymsg/RmcMarshal.hpp @@ -25,51 +25,12 @@ #pragma once #include "castor/exception/Exception.hpp" -#include "castor/legacymsg/RmcAcsMntMsgBody.hpp" #include "castor/legacymsg/RmcMountMsgBody.hpp" #include "castor/legacymsg/RmcUnmountMsgBody.hpp" namespace castor { namespace legacymsg { -/** - * Marshals the specified source message body structure and its implicit - * header into the specified destination buffer. - * - * @param dst The destination message buffer. - * @param dstLen The length of the destination buffer. - * @param src The source structure. - * @return The total length of the message (header + body). - */ -size_t marshal(char *const dst, const size_t dstLen, const RmcAcsMntMsgBody &src) ; - -/** - * Marshals the specified source message body structure and its implicit - * header into the specified destination buffer. - * - * @param dst The destination message buffer. - * @param src The source structure. - * @return The total length of the message (header + body). - */ -template<int n> size_t marshal(char (&dst)[n], const RmcAcsMntMsgBody &src) { - return marshal(dst, n, src); -} - -/** - * Unmarshals a message body with the specified destination structure type - * from the specified source buffer. - * - * @param src In/out parameter, before invocation points to the source - * buffer where the message body should be unmarshalled from and on return - * points to the byte in the source buffer immediately after the - * unmarshalled message body. - * @param srcLen In/out parameter, before invocation is the length of the - * source buffer from where the message body should be unmarshalled and on - * return is the number of bytes remaining in the source buffer. - * @param dst The destination message body structure. - */ -void unmarshal(const char * &src, size_t &srcLen, RmcAcsMntMsgBody &dst) ; - /** * Marshals the specified source message body structure and its implicit * header into the specified destination buffer. diff --git a/castor/legacymsg/RmcMarshalTest.cpp b/castor/legacymsg/RmcMarshalTest.cpp index beb03433c62167b8107188c0e756596c88dd0679..a6d54da8c017ad407cab228b7be5e1f22452e04e 100644 --- a/castor/legacymsg/RmcMarshalTest.cpp +++ b/castor/legacymsg/RmcMarshalTest.cpp @@ -40,64 +40,6 @@ protected: } }; -TEST_F(castor_legacymsg_RmcMarshalTest, marshalRmcAcsMntMsgBody) { - using namespace castor::legacymsg; - char buf[40]; // Expect message (header + body) to occupy exactly 40 bytes - - // Marshal entire message (header + body) - { - RmcAcsMntMsgBody srcMsgBody; - - srcMsgBody.uid = 1; - srcMsgBody.gid = 2; - srcMsgBody.acs = 3; - srcMsgBody.lsm = 4; - srcMsgBody.panel = 5; - srcMsgBody.transport = 6; - castor::utils::copyString(srcMsgBody.vid, "VID"); - - size_t bufLen = sizeof(buf); - size_t totalLen = 0; // Total length of message (header + body) - - ASSERT_NO_THROW(totalLen = marshal(buf, bufLen, srcMsgBody)); - - ASSERT_EQ((size_t)40, totalLen); - } - - // Unmarshall message header - { - MessageHeader dstHeader; - const char *bufPtr = buf; - size_t bufLen = 12; // Length of the message header - ASSERT_NO_THROW(unmarshal(bufPtr, bufLen, dstHeader)); - ASSERT_EQ(buf + 12, bufPtr); - ASSERT_EQ((size_t)0, bufLen); - - ASSERT_EQ((uint32_t)RMC_MAGIC, dstHeader.magic); - ASSERT_EQ((uint32_t)RMC_ACS_MOUNT, dstHeader.reqType); - ASSERT_EQ((uint32_t)28, dstHeader.lenOrStatus); - } - - // Unmarshall message body - { - RmcAcsMntMsgBody dstMsgBody; - - const char *bufPtr = buf + 12; // Point at beginning of message body - size_t bufLen = 28; // Length of the message body - ASSERT_NO_THROW(unmarshal(bufPtr, bufLen, dstMsgBody)); - ASSERT_EQ(buf + 40, bufPtr); - ASSERT_EQ((size_t)0, bufLen); - - ASSERT_EQ((uint32_t)1, dstMsgBody.uid); - ASSERT_EQ((uint32_t)2, dstMsgBody.gid); - ASSERT_EQ((uint32_t)3, dstMsgBody.acs); - ASSERT_EQ((uint32_t)4, dstMsgBody.lsm); - ASSERT_EQ((uint32_t)5, dstMsgBody.panel); - ASSERT_EQ((uint32_t)6, dstMsgBody.transport); - ASSERT_EQ(std::string("VID"), dstMsgBody.vid); - } -} - TEST_F(castor_legacymsg_RmcMarshalTest, marshalRmcMountMsgBody) { using namespace castor::legacymsg; char buf[29]; // Expect message (header + body) to occupy exactly 29 bytes @@ -130,7 +72,7 @@ TEST_F(castor_legacymsg_RmcMarshalTest, marshalRmcMountMsgBody) { ASSERT_EQ((size_t)0, bufLen); ASSERT_EQ((uint32_t)RMC_MAGIC, dstHeader.magic); - ASSERT_EQ((uint32_t)RMC_SCSI_MOUNT, dstHeader.reqType); + ASSERT_EQ((uint32_t)RMC_MOUNT, dstHeader.reqType); ASSERT_EQ((uint32_t)29, dstHeader.lenOrStatus); } diff --git a/castor/tape/rmc/AcceptHandler.cpp b/castor/tape/rmc/AcceptHandler.cpp deleted file mode 100644 index b4a6eed22f75c88edfa85086d32df6d09c7a1064..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcceptHandler.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/exception/BadAlloc.hpp" -#include "castor/exception/Errnum.hpp" -#include "castor/io/io.hpp" -#include "castor/tape/rmc/AcceptHandler.hpp" -#include "castor/tape/rmc/ConnectionHandler.hpp" -#include "castor/utils/SmartFd.hpp" - -#include <errno.h> -#include <memory> -#include <string.h> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::tape::rmc::AcceptHandler::AcceptHandler(const int fd, - reactor::ZMQReactor &reactor, log::Logger &log) throw(): m_fd(fd), - m_reactor(reactor), m_log(log) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -castor::tape::rmc::AcceptHandler::~AcceptHandler() throw() { - { - log::Param params[] = { - log::Param("fd", m_fd)}; - m_log(LOG_DEBUG, "Closing listen socket", params); - } - close(m_fd); -} - -//------------------------------------------------------------------------------ -// getName -//------------------------------------------------------------------------------ -std::string castor::tape::rmc::AcceptHandler::getName() const throw() { - return "rmc::AcceptHandler"; -} - -//------------------------------------------------------------------------------ -// fillPollFd -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcceptHandler::fillPollFd(zmq_pollitem_t &fd) throw() { - fd.fd = m_fd; - fd.events = ZMQ_POLLIN; - fd.revents = 0; - fd.socket = NULL; -} - -//------------------------------------------------------------------------------ -// handleEvent -//------------------------------------------------------------------------------ -bool castor::tape::rmc::AcceptHandler::handleEvent( - const zmq_pollitem_t &fd) { - log::Param params[] = { - log::Param("fd", fd.fd), - log::Param("ZMQ_POLLIN", fd.revents & ZMQ_POLLIN ? "true" : "false"), - log::Param("ZMQ_POLLOUT", fd.revents & ZMQ_POLLOUT ? "true" : "false"), - log::Param("ZMQ_POLLERR", fd.revents & ZMQ_POLLERR ? "true" : "false")}; - m_log(LOG_DEBUG, "I/O event on rmc listen socket", params); - - checkHandleEventFd(fd.fd); - - // Accept the connection - castor::utils::SmartFd connection; - try { - connection.reset(io::acceptConnection(fd.fd, 1)); - } catch(castor::exception::Exception &ne) { - castor::exception::Exception ex; - ex.getMessage() << "Failed to accept a connection: " << ne.getMessage().str(); - throw ex; - } - - m_log(LOG_DEBUG, "Accepted a possible client connection"); - - // Create a new connection handler - std::auto_ptr<ConnectionHandler> connectionHandler; - try { - connectionHandler.reset(new ConnectionHandler(connection.get(), - m_reactor, m_log)); - connection.release(); - } catch(std::bad_alloc &ba) { - castor::exception::BadAlloc ex; - ex.getMessage() << "Failed to allocate a new connection handler" - ": " << ba.what(); - throw ex; - } - - m_log(LOG_DEBUG, "Created a new connection handler"); - - // Register the new connection handler with the reactor - try { - m_reactor.registerHandler(connectionHandler.get()); - connectionHandler.release(); - } catch(castor::exception::Exception &ne) { - castor::exception::Exception ex; - ex.getMessage() << "Failed to register a new connection handler" - ": " << ne.getMessage().str(); - } - - m_log(LOG_DEBUG, "Registered the new connection handler"); - - return false; // Stay registered with the reactor -} - -//------------------------------------------------------------------------------ -// checkHandleEventFd -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcceptHandler::checkHandleEventFd(const int fd) { - if(m_fd != fd) { - castor::exception::Exception ex; - ex.getMessage() << "Failed to accept connection from client" - ": Event handler passed wrong file descriptor" - ": expected=" << m_fd << " actual=" << fd; - throw ex; - } -} diff --git a/castor/tape/rmc/AcceptHandler.hpp b/castor/tape/rmc/AcceptHandler.hpp deleted file mode 100644 index cb64900cd47b46b8ca4746d218adb97c2280f674..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcceptHandler.hpp +++ /dev/null @@ -1,107 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/log/Logger.hpp" -#include "castor/tape/reactor/PollEventHandler.hpp" -#include "castor/tape/reactor/ZMQReactor.hpp" - -#include <poll.h> - -namespace castor { -namespace tape { -namespace rmc { - -/** - * Handles the events of the socket listening for connections from clients of - * the rmcd daemon. - */ -class AcceptHandler: public reactor::ZMQPollEventHandler { -public: - - /** - * Constructor. - * - * @param fd The file descriptor of the socket listening for connections - * from clients of the rmcd daemon. - * @param reactor The reactor to which new connection handlers are to be - * registered. - * @param log The object representing the API of the CASTOR logging system. - */ - AcceptHandler(const int fd, reactor::ZMQReactor &reactor, log::Logger &log) throw(); - - /** - * Returns the human-readable name this event handler. - */ - std::string getName() const throw(); - - /** - * Fills the specified poll file-descriptor ready to be used in a call to - * poll(). - */ - void fillPollFd(zmq_pollitem_t &fd) throw(); - - /** - * Handles the specified event. - * - * @param fd The poll file-descriptor describing the event. - * @return true if the event handler should be removed from and deleted by - * the reactor. - */ - bool handleEvent(const zmq_pollitem_t &fd); - - /** - * Destructor. - * - * Closes the listen socket. - */ - ~AcceptHandler() throw(); - -private: - - /** - * Throws an exception if the specified file-descriptor is not that of the - * socket listening for client connections. - */ - void checkHandleEventFd(const int fd); - - /** - * The file descriptor of the socket listening for client connections. - */ - const int m_fd; - - /** - * The reactor to which new connection handlers are to be registered. - */ - reactor::ZMQReactor &m_reactor; - - /** - * The object representing the API of the CASTOR logging system. - */ - log::Logger &m_log; - -}; // class AcceptHandler - -} // namespace rmc -} // namespace tape -} // namespace castor - diff --git a/castor/tape/rmc/Acs.cpp b/castor/tape/rmc/Acs.cpp deleted file mode 100644 index eb3e66635853455c5c32154ccbfedb54423d39e8..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/Acs.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/Acs.hpp" -#include "castor/tape/utils/utils.hpp" -#include "castor/utils/utils.hpp" - -#include <iomanip> -#include <sstream> -#include <stdint.h> - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -castor::tape::rmc::Acs::~Acs() throw() { -} - -//------------------------------------------------------------------------------ -// str2DriveId -//------------------------------------------------------------------------------ -DRIVEID castor::tape::rmc::Acs::str2DriveId(const std::string &str) - const { - std::vector<std::string> components; - castor::utils::splitString(str, ':', components); - - // The drive ID should consist of 4 components: ACS, LSM, Panel and Transport - if(4 != components.size()) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Invalid number of components in drive ID" - ": expected=4, actual=" << components.size(); - throw ex; - } - - const std::string &acsStr = components[0]; - const std::string &lsmStr = components[1]; - const std::string &panStr = components[2]; - const std::string &drvStr = components[3]; - - // Each of the 4 components must be between 1 and than 3 characters long - if(1 > acsStr.length() || 3 < acsStr.length()) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Invalid ACS string length" - ": expected=1..3, actual=" << acsStr.length(); - throw ex; - } - if(1 > lsmStr.length() || 3 < lsmStr.length()) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Invalid LSM string length" - ": expected=1..3, actual=" << lsmStr.length(); - throw ex; - } - if(1 > panStr.length() || 3 < panStr.length()) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Invalid panel string length" - ": expected=1..3, actual=" << panStr.length(); - throw ex; - } - if(1 > drvStr.length() || 3 < drvStr.length()) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Invalid drive string length" - ": expected=1..3, actual=" << drvStr.length(); - throw ex; - } - - // Each of the 4 components must only contain numerals - if(!onlyContainsNumerals(acsStr)) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "ACS must only contain numerals: value=" << acsStr; - throw ex; - } - if(!onlyContainsNumerals(lsmStr)) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "LSM must only contain numerals: value=" << acsStr; - throw ex; - } - if(!onlyContainsNumerals(panStr)) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Panel must only contain numerals: value=" << acsStr; - throw ex; - } - if(!onlyContainsNumerals(drvStr)) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Drive/Transport must only contain numerals: value=" << - acsStr; - throw ex; - } - - DRIVEID driveId; - driveId.panel_id.lsm_id.acs = (ACS)atoi(acsStr.c_str()); - driveId.panel_id.lsm_id.lsm = (LSM)atoi(lsmStr.c_str()); - driveId.panel_id.panel = (PANEL)atoi(panStr.c_str()); - driveId.drive = (DRIVE)atoi(drvStr.c_str()); - - return driveId; -} - -//------------------------------------------------------------------------------ -// alpd2DriveId -//------------------------------------------------------------------------------ -DRIVEID castor::tape::rmc::Acs::alpd2DriveId(const uint32_t acs, - const uint32_t lsm, const uint32_t panel, const uint32_t drive) - const throw () { - - DRIVEID driveId; - driveId.panel_id.lsm_id.acs = (ACS)acs; - driveId.panel_id.lsm_id.lsm = (LSM)lsm; - driveId.panel_id.panel = (PANEL)panel; - driveId.drive = (DRIVE)drive; - - return driveId; -} - -//------------------------------------------------------------------------------ -// str2Volid -//------------------------------------------------------------------------------ -VOLID castor::tape::rmc::Acs::str2Volid(const std::string &str) const - { - if(EXTERNAL_LABEL_SIZE < str.length()) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Failed to convert string to volume identifier" - ": String is longer than the " << EXTERNAL_LABEL_SIZE << - " character maximum"; - throw ex; - } - - VOLID v; - strncpy(v.external_label, str.c_str(), sizeof(v.external_label)); - v.external_label[sizeof(v.external_label) - 1] = '\0'; - return v; -} - -//------------------------------------------------------------------------------ -// onlyContainsNumerals -//------------------------------------------------------------------------------ -bool castor::tape::rmc::Acs::onlyContainsNumerals( - const std::string &str) const throw() { - for(std::string::const_iterator itor = str.begin(); itor != str.end(); - itor++) { - if(*itor < '0' || *itor > '9') { - return false; - } - } - return true; -} - -//------------------------------------------------------------------------------ -// driveId2Str -//------------------------------------------------------------------------------ -std::string castor::tape::rmc::Acs::driveId2Str(const DRIVEID &driveId) - const throw() { - std::ostringstream oss; - oss << std::setfill('0') << - std::setw(3) << (int32_t)driveId.panel_id.lsm_id.acs << ":" << - std::setw(3) << (int32_t)driveId.panel_id.lsm_id.lsm << ":" << - std::setw(3) << (int32_t)driveId.panel_id.panel << ":" << - std::setw(3) << (int32_t)driveId.drive; - return oss.str(); -} diff --git a/castor/tape/rmc/Acs.hpp b/castor/tape/rmc/Acs.hpp deleted file mode 100644 index b709219f21ecf9408899967e0c52dc159b5c26bd..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/Acs.hpp +++ /dev/null @@ -1,189 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/exception/InvalidArgument.hpp" - -extern "C" { -#include "acssys.h" -#include "acsapi.h" -} - -#include <string> -#include <stdint.h> - -namespace castor { -namespace tape { -namespace rmc { - -/** - * Abstract class that defines the interface to an object that wraps the ACLS - * C-API. - */ -class Acs { -public: - /** - * Pure-virtual destructor to ensure this class is abstract. - */ - virtual ~Acs() throw() = 0; - - /** - * Parses the specified string and returns the corresponding drive ID object. - * - * This method throws a castor::exception::InvalidArgument if the syntax of - * the string is invalid. - * - * @param str The string to be parsed. - * @return The drive ID object. - */ - DRIVEID str2DriveId(const std::string &str) const - ; - - /** - * Converts acs, lsm, panel, drive numbers to the corresponding - * drive ID object. - * - * @param acs The integer for acs. - * @param lsm The integer for lsm. - * @param panel The integer for panel. - * @param drive The integer for drive. - * @return The drive ID object. - */ - DRIVEID alpd2DriveId(const uint32_t acs, const uint32_t lsm, - const uint32_t panel, const uint32_t drive) const throw() - ; - - /** - * Returns the VOLID equibvalent of the specified string. - * - * This method throws a castor::exception::InvalidArgument if the string is - * longer than EXTERNAL_LABEL_SIZE. - * - * @param str The string representation of the volume identifier. - * @return The VOLID representation of the volume identifier. - */ - VOLID str2Volid(const std::string &str) const - ; - - /** - * Returns true if the specified string only contains numerals else false. - * - * @return True if the specified string only contains numerals else false. - */ - bool onlyContainsNumerals(const std::string &str) const throw(); - - /** - * Returns the string reprsentation of the specified drive identifier. - * - * The string format is ACS:LSM:panel:drive - * - * @param driveId The drive identifier. - * @return The string representation. - */ - std::string driveId2Str(const DRIVEID &driveId) const throw(); - - /** - * C++ wrapper around the acs_mount() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param lockId Lock identifier or 0 meaning no lock. - * @param volId The indentifier of volume to be mounted. - * @param driveId The ID of the drive into which the volume is to be mounted. - * @param readOnly Set to true to request the volume be mounted for read-only - * access. - * @param bypass Set to true to override the ACSLS verification of - * compatibility between the drive and the media type of the volume. - * @return status value returned by acs_mount(). - */ - virtual STATUS mount( - const SEQ_NO seqNumber, - const LOCKID lockId, - const VOLID &volId, - const DRIVEID &driveId, - const BOOLEAN readOnly, - const BOOLEAN bypass) - throw() = 0; - - /** - * C++ wrapper around the acs_dismount() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param lockId Lock identifier or 0 meaning no lock. - * @param volId The identifier of the volume to be mounted. - * @param driveId The ID of the drive into which the volume is to be mounted. - * @param force Set to true if the dismount should be forced. Forcing a - * dismount means dismounting the volume from the specified drive without - * checking the identifier of the volume. - * @return status value returned by acs_dismount(). - */ - virtual STATUS dismount( - const SEQ_NO seqNumber, - const LOCKID lockId, - const VOLID &volId, - const DRIVEID &driveId, - const BOOLEAN force) - throw() = 0; - - /** - * C++ wrapper around the acs_response() function of the ACSLS C-API. - * - * @param timeout Time in seconds to wait for a response. A value of -1 - * means block indefinitely and an a value of 0 means poll for the existence - * of a response. - * @param seqNumber Output parameter. If a response exists then seqNumber - * is set. - * @param reqId Output parameter. For an acknowledge response reqId is set - * to the request identifier of the original request. For an intermediate or - * final response reqId will be set to 0. - * @param rType Output parameter. Set to the type of the response. - * @param rBuf Output parameter. Set to the response information. - * @return status value returned by acs_response(). - */ - virtual STATUS response( - const int timeout, - SEQ_NO &seqNumber, - REQ_ID &reqId, - ACS_RESPONSE_TYPE &rType, - ALIGNED_BYTES rBuf) throw() = 0; - - /** - * C++ wrapper around the acs_query_volume() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param volIds Array of the volume identifiers to be queried. - * @param count The number of volume identifiers contained iwthin the volId - * parameter. - * @return status value returned by acs_response(). - */ - virtual STATUS queryVolume( - const SEQ_NO seqNumber, - VOLID (&volIds)[MAX_ID], - const unsigned short count) throw() = 0; -}; // class Acs - -} // namespace rmc -} // namespace tape -} // namespace castor - - diff --git a/castor/tape/rmc/AcsCmd.cpp b/castor/tape/rmc/AcsCmd.cpp deleted file mode 100644 index 511da6bd3b6db540132be8f280f428a414c84a1b..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsCmd.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/AcsCmd.hpp" -#include "castor/tape/utils/utils.hpp" - -#include <stdlib.h> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::tape::rmc::AcsCmd::AcsCmd(std::istream &inStream, - std::ostream &outStream, std::ostream &errStream, Acs &acs) throw(): - Cmd(inStream, outStream, errStream), m_acs(acs) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -castor::tape::rmc::AcsCmd::~AcsCmd() throw() { -} - -//------------------------------------------------------------------------------ -// bool2Str -//------------------------------------------------------------------------------ -std::string castor::tape::rmc::AcsCmd::bool2Str(const BOOLEAN value) const - throw() { - return value ? "TRUE" : "FALSE"; -} - -//------------------------------------------------------------------------------ -// requestResponsesUntilFinal -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsCmd::requestResponsesUntilFinal( - const SEQ_NO requestSeqNumber, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)], - const int queryInterval, const int timeout) - { - ACS_RESPONSE_TYPE responseType = RT_NONE; - int elapsedTime = 0; - do { - const int remainingTime = timeout - elapsedTime; - const int responseTimeout = remainingTime > queryInterval ? - queryInterval : remainingTime; - - const time_t startTime = time(NULL); - responseType = requestResponse(responseTimeout, requestSeqNumber, buf); - elapsedTime += time(NULL) - startTime; - - if(RT_ACKNOWLEDGE == responseType) { - m_dbg << "Received RT_ACKNOWLEDGE" << std::endl; - } - - if(elapsedTime >= timeout) { - castor::exception::RequestFailed ex; - ex.getMessage() << "Timed out after " << timeout << " seconds"; - throw ex; - } - } while(RT_FINAL != responseType); - - m_dbg << "Received RT_FINAL" << std::endl; -} - -//------------------------------------------------------------------------------ -// requestResponse -//------------------------------------------------------------------------------ -ACS_RESPONSE_TYPE castor::tape::rmc::AcsCmd::requestResponse( - const int timeout, const SEQ_NO requestSeqNumber, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) - { - SEQ_NO responseSeqNumber = 0; - REQ_ID reqId = (REQ_ID)0; - ACS_RESPONSE_TYPE responseType = RT_NONE; - - m_dbg << "Calling Acs::response()" << std::endl; - const STATUS s = m_acs.response(timeout, responseSeqNumber, reqId, - responseType, buf); - m_dbg << "Acs::response() returned " << acs_status(s) << std::endl; - - switch(s) { - case STATUS_SUCCESS: - checkResponseSeqNumber(requestSeqNumber, responseSeqNumber); - return responseType; - case STATUS_PENDING: - return RT_NONE; - default: - castor::exception::RequestFailed ex; - ex.getMessage() << "Failed to request response: " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// checkSeqNumber -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsCmd::checkResponseSeqNumber( - const SEQ_NO requestSeqNumber, const SEQ_NO responseSeqNumber) - { - if(requestSeqNumber != responseSeqNumber) { - castor::exception::Mismatch ex; - ex.getMessage() << ": Sequence number mismatch: requestSeqNumber=" - << requestSeqNumber << " responseSeqNumber=" << responseSeqNumber; - throw ex; - } -} diff --git a/castor/tape/rmc/AcsCmd.hpp b/castor/tape/rmc/AcsCmd.hpp deleted file mode 100644 index cece5e474b50e2da892793cf2b4cbd6b6414d801..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsCmd.hpp +++ /dev/null @@ -1,130 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/exception/InvalidArgument.hpp" -#include "castor/exception/Mismatch.hpp" -#include "castor/exception/RequestFailed.hpp" -#include "castor/tape/rmc/Acs.hpp" -#include "castor/tape/rmc/Cmd.hpp" - -#include <istream> -#include <ostream> -#include <string> - -extern "C" { -#include "acssys.h" -#include "acsapi.h" -} - -namespace castor { -namespace tape { -namespace rmc { - -/** - * Abstract class implementing common code and data structures for command-line - * tools that interact with ACLS compatible tape libraries. - */ -class AcsCmd: public Cmd { -public: - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - * @param acs Wrapper around the ACSLS C-API. - */ - AcsCmd(std::istream &inStream, std::ostream &outStream, - std::ostream &errStream, Acs &acs) throw(); - - /** - * Pure-virtual destructor to guarantee this class is abstract. - */ - virtual ~AcsCmd() throw() = 0; - -protected: - - /** - * Wrapper around the ACSLS C-API. - */ - Acs &m_acs; - - /** - * Returns the string representation of the specfied boolean value. - * - * @param value The boolean value. - */ - std::string bool2Str(const BOOLEAN value) const throw(); - - /** - * Requests responses from ACSLS in a loop until the RT_FINAL response is - * received. - * - * @param requestSeqNumber The sequemce number that was sent in the initial - * request to the ACSLS. - * @param buf Output parameter. Message buffer into which the RT_FINAL - * response shall be written. - * @param queryInterval Time in seconds to wait between queries to ACS for - * responses. - * @param timeout The time in seconds to spend trying to get the RT_FINAL - * response. - */ - void requestResponsesUntilFinal(const SEQ_NO requestSeqNumber, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)], - const int queryInterval, const int timeout) - ; - - /** - * Sends a request for a response to the ACSLS. - * - * @param timeout The timeout. - * @param requestSeqNumber The sequemce number that was sent in the initial - * request to the ACSLS. - * @param buf Output parameter. The response message if there is one. - * @return The type of the response message if there is one or RT_NONE if - * there isn't one. - */ - ACS_RESPONSE_TYPE requestResponse(const int timeout, - const SEQ_NO requestSeqNumber, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) - ; - - /** - * Throws castor::exception::Mismatch if the specified request and - * response sequence-numbers do not match. - * - * @param requestSeqNumber Request sequence-number. - * @param responseSeqNumber Response sequence-number. - */ - void checkResponseSeqNumber(const SEQ_NO requestSeqNumber, - const SEQ_NO responseSeqNumber) ; - -}; // class AcsCmd - -} // namespace rmc -} // namespace tape -} // namespace castor - - diff --git a/castor/tape/rmc/AcsDismountCmd.cpp b/castor/tape/rmc/AcsDismountCmd.cpp deleted file mode 100644 index 737679d3447c07271e1e8deb11ab8af308619fe3..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsDismountCmd.cpp +++ /dev/null @@ -1,313 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/AcsDismountCmd.hpp" -#include "castor/tape/utils/utils.hpp" - -#include <getopt.h> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::tape::rmc::AcsDismountCmd::AcsDismountCmd( - std::istream &inStream, std::ostream &outStream, std::ostream &errStream, - Acs &acs) throw(): - AcsCmd(inStream, outStream, errStream, acs), m_defaultQueryInterval(10), - m_defaultTimeout(600) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -castor::tape::rmc::AcsDismountCmd::~AcsDismountCmd() throw() { - // Do nothing -} - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int castor::tape::rmc::AcsDismountCmd::main(const int argc, - char *const *const argv) throw() { - try { - m_cmdLine = parseCmdLine(argc, argv); - } catch(castor::exception::InvalidArgument &ia) { - m_err << "Aborting: Invalid command-line: " << ia.getMessage().str() << - std::endl; - m_err << std::endl; - usage(m_err); - return 1; - } catch(castor::exception::MissingOperand &mo) { - m_err << "Aborting: Missing operand: " << mo.getMessage().str() << - std::endl; - m_err << std::endl; - usage(m_err); - return 1; - } catch(castor::exception::Exception &ie) { - m_err << "Aborting: Internal error: " << ie.getMessage().str() << - std::endl; - return 1; - } - - // Display the usage message to standard out and exit with success if the - // user requested help - if(m_cmdLine.help) { - usage(m_out); - return 0; - } - - // Setup debug mode to be on or off depending on the command-line arguments - m_debugBuf.setDebug(m_cmdLine.debug); - - m_dbg << "force = " << (m_cmdLine.force ? "TRUE" : "FALSE") << std::endl; - m_dbg << "query = " << m_cmdLine.queryInterval << std::endl; - m_dbg << "timeout = " << m_cmdLine.timeout << std::endl; - m_dbg << "VID = " << m_cmdLine.volId.external_label << std::endl; - m_dbg << "DRIVE = " << m_acs.driveId2Str(m_cmdLine.driveId) << std::endl; - - try { - syncDismount(); - } catch(castor::exception::Exception &ex) { - m_err << "Aborting: " << ex.getMessage().str() << std::endl; - return 1; - } - - return 0; -} - -//------------------------------------------------------------------------------ -// usage -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsDismountCmd::usage(std::ostream &os) - const throw() { - os << - "Usage:\n" - "\n" - " castor-tape-acs-dismount [options] VID DRIVE\n" - "\n" - "Where:\n" - "\n" - " VID The VID of the volume to be dismounted.\n" - "\n" - " DRIVE The drive from which the volume is to be dismounted.\n" - " The format of DRIVE is:\n" - "\n" - " ACS:LSM:panel:transport\n" - "\n" - "Options:\n" - "\n" - " -d|--debug Turn on the printing of debug information.\n" - "\n" - " -f|--force Force the dismount.\n" - "\n" - " -h|--help Print this help message and exit.\n" - "\n" - " -q|--query SECONDS Time to wait between queries to ACS for responses.\n" - " SECONDS must be an integer value greater than 0.\n" - " The default value of SECONDS is " - << m_defaultQueryInterval << ".\n" - "\n" - " -t|--timeout SECONDS Time to wait for the dismount to conclude. SECONDS\n" - " must be an integer value greater than 0. The\n" - " default value of SECONDS is " - << m_defaultTimeout << ".\n" - "\n" - "Comments to: Castor.Support@cern.ch" << std::endl; -} - -//------------------------------------------------------------------------------ -// parseCmdLine -//------------------------------------------------------------------------------ -castor::tape::rmc::AcsDismountCmdLine - castor::tape::rmc::AcsDismountCmd::parseCmdLine( - const int argc, char *const *const argv) - throw(castor::exception::Exception, castor::exception::InvalidArgument, - castor::exception::MissingOperand) { - - static struct option longopts[] = { - {"debug", 0, NULL, 'd'}, - {"force", 0, NULL, 'f'}, - {"help" , 0, NULL, 'h'}, - {"query" , required_argument, NULL, 'q'}, - {"timeout" , required_argument, NULL, 't'}, - {NULL , 0, NULL, 0 } - }; - AcsDismountCmdLine cmdLine; - char c; - - // Set the query option to the default value - cmdLine.queryInterval = m_defaultQueryInterval; - - // Set timeout option to the default value - cmdLine.timeout = m_defaultTimeout; - - // Prevent getopt() from printing an error message if it does not recognize - // an option character - opterr = 0; - while((c = getopt_long(argc, argv, ":dfhq:t:", longopts, NULL)) != -1) { - - switch (c) { - case 'd': - cmdLine.debug = true; - break; - case 'f': - cmdLine.force = TRUE; - break; - case 'h': - cmdLine.help = true; - break; - case 'q': - cmdLine.queryInterval = atoi(optarg); - if(0 >= cmdLine.queryInterval) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Query value must be an integer greater than 0" - ": value=" << cmdLine.queryInterval; - throw ex; - } - break; - case 't': - cmdLine.timeout = atoi(optarg); - if(0 >= cmdLine.timeout) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Timeout value must be an integer greater than 0" - ": value=" << cmdLine.timeout; - throw ex; - } - break; - case ':': - { - castor::exception::InvalidArgument ex; - ex.getMessage() << "The -" << (char)optopt - << " option requires a parameter"; - throw ex; - } - break; - case '?': - { - castor::exception::InvalidArgument ex; - - if(optopt == 0) { - ex.getMessage() << "Unknown command-line option"; - } else { - ex.getMessage() << "Unknown command-line option: -" << (char)optopt; - } - throw ex; - } - break; - default: - { - castor::exception::Exception ex; - ex.getMessage() << - "getopt_long returned the following unknown value: 0x" << - std::hex << (int)c; - throw ex; - } - } // switch (c) - } // while ((c = getopt_long( ... )) != -1) - - // There is no need to continue parsing when the help option is set - if(cmdLine.help) { - return cmdLine; - } - - // Calculate the number of non-option ARGV-elements - const int nbArgs = argc-optind; - - // Check that both VID and DRIVE has been specified - if(nbArgs < 2) { - castor::exception::MissingOperand ex; - - ex.getMessage() << - "Both VID and DRIVE must be specified"; - - throw ex; - } - - // Parse the volume identifier of the command-line argument - cmdLine.volId = m_acs.str2Volid(argv[optind]); - - // Move on to the next command-line argument - optind++; - - // Parse the drive-identifier command-line argument - cmdLine.driveId = m_acs.str2DriveId(argv[optind]); - - return cmdLine; -} - -//------------------------------------------------------------------------------ -// syncDismount -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsDismountCmd::syncDismount() - { - const SEQ_NO requestSeqNumber = 1; - ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - - try { - sendDismountRequest(requestSeqNumber); - requestResponsesUntilFinal(requestSeqNumber, buf, m_cmdLine.queryInterval, - m_cmdLine.timeout); - processDismountResponse(buf); - } catch(castor::exception::Exception &ex) { - castor::exception::DismountFailed df; - df.getMessage() << "Failed to dismount volume " << - m_cmdLine.volId.external_label << ": " << ex.getMessage().str(); - throw df; - } -} - -//------------------------------------------------------------------------------ -// sendDismountRequest -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsDismountCmd::sendDismountRequest( - const SEQ_NO seqNumber) { - const LOCKID lockId = 0; // No lock - - m_dbg << "Calling Acs::dismount()" << std::endl; - const STATUS s = m_acs.dismount(seqNumber, lockId, m_cmdLine.volId, - m_cmdLine.driveId, m_cmdLine.force); - m_dbg << "Acs::dismount() returned " << acs_status(s) << std::endl; - if(STATUS_SUCCESS != s) { - castor::exception::DismountFailed ex; - ex.getMessage() << "Failed to send request to dismount volume " << - m_cmdLine.volId.external_label << " from drive " << - m_acs.driveId2Str(m_cmdLine.driveId) << ": force=" << - (m_cmdLine.force ? "TRUE" : "FALSE") << ": " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// processDismountResponse -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsDismountCmd::processDismountResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) - { - const ACS_DISMOUNT_RESPONSE *const msg = (ACS_DISMOUNT_RESPONSE *)buf; - - if(STATUS_SUCCESS != msg->dismount_status) { - castor::exception::DismountFailed ex; - ex.getMessage() << "Status of dismount response is not success: " << - acs_status(msg->dismount_status); - throw ex; - } -} diff --git a/castor/tape/rmc/AcsDismountCmd.hpp b/castor/tape/rmc/AcsDismountCmd.hpp deleted file mode 100644 index 41dfe169df586d125383335f9bcb925cd5ef3967..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsDismountCmd.hpp +++ /dev/null @@ -1,146 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/exception/DismountFailed.hpp" -#include "castor/exception/InvalidArgument.hpp" -#include "castor/exception/MissingOperand.hpp" -#include "castor/tape/rmc/AcsCmd.hpp" -#include "castor/tape/rmc/AcsDismountCmdLine.hpp" - -namespace castor { -namespace tape { -namespace rmc { - -/** - * The class implementing the mount command. - */ -class AcsDismountCmd: public AcsCmd { -public: - - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - * @param acs Wrapper around the ACSLS C-API. - */ - AcsDismountCmd(std::istream &inStream, std::ostream &outStream, - std::ostream &errStream, Acs &acs) throw(); - - /** - * Destructor. - */ - virtual ~AcsDismountCmd() throw(); - - /** - * The entry function of the command. - * - * This method sets the m_cmdLine member-variable. - * - * @param argc The number of command-line arguments. - * @param argv The command-line arguments. - */ - int main(const int argc, char *const *const argv) throw(); - -protected: - - /** - * Writes the command-line usage message of to the specified output stream. - * - * @param os Output stream to be written to. - */ - void usage(std::ostream &os) const throw(); - - /** - * Parses the specified command-line arguments. - * - * @param argc Argument count from the executable's entry function: main(). - * @param argv Argument vector from the executable's entry function: main(). - * @return The parsed command-line. - */ - AcsDismountCmdLine parseCmdLine(const int argc, char *const *const argv) - throw(castor::exception::Exception, castor::exception::InvalidArgument, - castor::exception::MissingOperand); - - /** - * Dismounts the tape with the specified VID into the drive with the specified - * drive ID. - * - * This method does not return until the mount has either suceeded, failed or - * the specified timeout has been reached. - * - * @param dismountTimeout The maximum amount of time in seconds to wait for - * the dismount operation to conclude. - * @param queryInterval The amount of time in seconds to wait between - * querying ACS for responses. - */ - void syncDismount() ; - - /** - * Sends the dismount request to ACSLS. - * - * @param seqNumber The sequence number to be used in the request. - */ - void sendDismountRequest(const SEQ_NO seqNumber) - ; - - /** - * Throws castor::exception::DismountFailed if the mount was not - * successful. - * - * @param buf The mount-response message. - */ - void processDismountResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) - ; - -private: - - /** - * The parsed command-line. - * - * This member-variable is set by the main() method of this class. - */ - AcsDismountCmdLine m_cmdLine; - - /** - * The default time in seconds to wait between queries to ACS for responses. - */ - const int m_defaultQueryInterval; - - /** - * The default timeout value in seconds for the dismount to conclude either - * success or failure. - */ - const int m_defaultTimeout; - -}; // class AcsDismountCmd - -} // namespace rmc -} // namespace tape -} // namespace castor - - diff --git a/castor/tape/rmc/AcsDismountCmdLine.cpp b/castor/tape/rmc/AcsDismountCmdLine.cpp deleted file mode 100644 index 7acfab31227909eb47bdf314ec5aef2d09b1d9ad..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsDismountCmdLine.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/AcsDismountCmdLine.hpp" - -#include <string.h> - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -castor::tape::rmc::AcsDismountCmdLine::AcsDismountCmdLine() throw(): - debug(false), - force(FALSE), - help(false), - queryInterval(0), - timeout(0) { - driveId.panel_id.lsm_id.acs = (ACS)0; - driveId.panel_id.lsm_id.lsm = (LSM)0; - driveId.panel_id.panel = (PANEL)0; - driveId.drive = (DRIVE)0; - memset(volId.external_label, '\0', sizeof(volId.external_label)); -} diff --git a/castor/tape/rmc/AcsDismountCmdLine.hpp b/castor/tape/rmc/AcsDismountCmdLine.hpp deleted file mode 100644 index 35b847370f7a168e14cd2993e4d7c2e20bf0e623..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsDismountCmdLine.hpp +++ /dev/null @@ -1,93 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -extern "C" { -#include "acssys.h" -#include "acsapi.h" -} - -#include <string> - -namespace castor { -namespace tape { -namespace rmc { - -/** - * Data type used to store the results of parsing the command-line. - */ -struct AcsDismountCmdLine { - /** - * Constructor. - * - * Initialises all boolean member-variables to false, all integer - * member-variables to 0 and the volume identifier to an empty string. - */ - AcsDismountCmdLine() throw(); - - /** - * True if the debug option has been set. - */ - bool debug; - - /** - * True if the dismount should be forced. - * - * Forcing a dismount means dismounting the tape in the specified drive - * without checking the volume identifier of the tape. - */ - BOOLEAN force; - - /** - * True if the help option has been set. - */ - bool help; - - /** - * Time in seconds to wait between queries to ACS for responses. - */ - int queryInterval; - - /** - * Time in seconds to wait for the dismount to conclude. - */ - int timeout; - - /** - * The volume identifier of the tape to be mounted. - */ - VOLID volId; - - /** - * The drive into which the tape is to be mounted. - */ - DRIVEID driveId; - -}; // class AcsDismountCmdLine - -} // namespace rmc -} // namespace tape -} // namespace castor - - diff --git a/castor/tape/rmc/AcsDismountCmdLineTest.cpp b/castor/tape/rmc/AcsDismountCmdLineTest.cpp deleted file mode 100644 index e99c17e66b5ce58c190b576e477b1f5b58ed9b81..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsDismountCmdLineTest.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/AcsDismountCmdLine.hpp" - -#include <gtest/gtest.h> - -namespace unitTests { - -class castor_test_rmc_AcsDismountCmdLineTest: public ::testing::Test { -protected: - - virtual void SetUp() { - } - - virtual void TearDown() { - } - -}; // class castor_test_rmc_AcsDismountCmdLineTest - -TEST_F( castor_test_rmc_AcsDismountCmdLineTest, constructor) { - const castor::tape::rmc::AcsDismountCmdLine cmdLine; - ASSERT_EQ(false, cmdLine.debug); - ASSERT_EQ((BOOLEAN)FALSE, cmdLine.force); - ASSERT_EQ(false, cmdLine.help); - ASSERT_EQ(0, cmdLine.timeout); - ASSERT_EQ(0, cmdLine.queryInterval); - ASSERT_EQ(0, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(0, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(0, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(0, (int)cmdLine.driveId.drive); - ASSERT_EQ('\0', cmdLine.volId.external_label[0]); -} - -} // namespace unitTests diff --git a/castor/tape/rmc/AcsDismountCmdTest.cpp b/castor/tape/rmc/AcsDismountCmdTest.cpp deleted file mode 100644 index 9f3dac9b41cb8829fb7fdbc0d6dbdad97f4ad7da..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsDismountCmdTest.cpp +++ /dev/null @@ -1,487 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/MockAcs.hpp" -#include "castor/tape/rmc/TestingAcsDismountCmd.hpp" - -#include <gtest/gtest.h> -#include <list> -#include <memory> -#include <sstream> -#include <string.h> - -namespace unitTests { - -class castor_tape_rmc_AcsDismountCmdTest: public ::testing::Test { -protected: - - virtual void SetUp() { - } - - - virtual void TearDown() { - // Allow getopt_long to be called again - optind = 0; - - for(ArgcvList::const_iterator itor = m_argsList.begin(); - itor != m_argsList.end(); itor++) { - for(int i=0; i < (*itor)->argc; i++) { - delete[] (*itor)->argv[i]; - } - delete[] (*itor)->argv; - delete *itor; - } - } - - struct Argcv { - int argc; - char **argv; - Argcv(): argc(0), argv(NULL) { - } - }; - typedef std::list<Argcv*> ArgcvList; - ArgcvList m_argsList; - - /** - * Creates a duplicate string usin the new operator. - */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; - } -}; // class castor_tape_rmc_AcsDismountCmdTest - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithNoArgs) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 1; - args->argv = new char *[2]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::MissingOperand); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithOnlyVolId) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("VIDVID"); - args->argv[2] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::MissingOperand); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithShortForce) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 4; - args->argv = new char *[5]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("-f"); - args->argv[2] = dupString("VIDVID"); - args->argv[3] = dupString("111:112:113:114"); - args->argv[4] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - AcsDismountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ((BOOLEAN)TRUE, cmdLine.force); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithLongForce) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 4; - args->argv = new char *[5]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("--force"); - args->argv[2] = dupString("VIDVID"); - args->argv[3] = dupString("111:112:113:114"); - args->argv[4] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - AcsDismountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ((BOOLEAN)TRUE, cmdLine.force); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithShortHelp) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("-h"); - args->argv[2] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - AcsDismountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(true, cmdLine.help); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithLongHelp) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("--help"); - args->argv[2] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - AcsDismountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(true, cmdLine.help); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithVolIdAndDrive) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 3; - args->argv = new char *[4]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("VIDVID"); - args->argv[2] = dupString("111:112:113:114"); - args->argv[3] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - AcsDismountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(false, cmdLine.debug); - ASSERT_EQ(false, cmdLine.help); - ASSERT_EQ(10, cmdLine.queryInterval); - ASSERT_EQ(600, cmdLine.timeout); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithShortDebug) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 4; - args->argv = new char *[5]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("-d"); - args->argv[2] = dupString("VIDVID"); - args->argv[3] = dupString("111:112:113:114"); - args->argv[4] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - AcsDismountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(true, cmdLine.debug); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithLongDebug) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 4; - args->argv = new char *[5]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("--debug"); - args->argv[2] = dupString("VIDVID"); - args->argv[3] = dupString("111:112:113:114"); - args->argv[4] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - AcsDismountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(true, cmdLine.debug); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithTooLongVolIdAndDrive) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 3; - args->argv = new char *[4]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("VIDVID7"); - args->argv[2] = dupString("111:112:113:114"); - args->argv[3] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithValidVolIdAndInvalidDrive) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 3; - args->argv = new char *[4]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("VIDVID"); - args->argv[2] = dupString("INVALID_DRIVE"); - args->argv[3] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithShortTimeout) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 5; - args->argv = new char *[6]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("-t"); - args->argv[2] = dupString("2"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = dupString("111:112:113:114"); - args->argv[5] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - AcsDismountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(2, cmdLine.timeout); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithLongTimeout) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 5; - args->argv = new char *[6]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("--timeout"); - args->argv[2] = dupString("2"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = dupString("111:112:113:114"); - args->argv[5] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - AcsDismountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(2, cmdLine.timeout); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWith0Timeout) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 5; - args->argv = new char *[6]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("--timeout"); - args->argv[2] = dupString("0"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = dupString("111:112:113:114"); - args->argv[5] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithShortQuery) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 5; - args->argv = new char *[6]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("-q"); - args->argv[2] = dupString("1"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = dupString("111:112:113:114"); - args->argv[5] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - AcsDismountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(1, cmdLine.queryInterval); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWithLongQuery) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 5; - args->argv = new char *[6]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("--query"); - args->argv[2] = dupString("1"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = dupString("111:112:113:114"); - args->argv[5] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - AcsDismountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(1, cmdLine.queryInterval); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsDismountCmdTest, testParceCmdLineWith0Query) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 5; - args->argv = new char *[6]; - args->argv[0] = dupString("dismountacs"); - args->argv[1] = dupString("--query"); - args->argv[2] = dupString("0"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = dupString("111:112:113:114"); - args->argv[5] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsDismountCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::InvalidArgument); -} - -} // namespace unitTests diff --git a/castor/tape/rmc/AcsDismountMain.cpp b/castor/tape/rmc/AcsDismountMain.cpp deleted file mode 100644 index a9aca3fd98b1329d34595549270e2ad8a56de0fa..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsDismountMain.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/AcsImpl.hpp" -#include "castor/tape/rmc/AcsDismountCmd.hpp" - -#include <iostream> - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int main(const int argc, char *const *const argv) { - castor::tape::rmc::AcsImpl acs; - castor::tape::rmc::AcsDismountCmd cmd(std::cin, std::cout, std::cerr, acs); - - return cmd.main(argc, argv); -} diff --git a/castor/tape/rmc/AcsImpl.cpp b/castor/tape/rmc/AcsImpl.cpp deleted file mode 100644 index c0c429204c8d575d4a2d17d06066397b04882618..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsImpl.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/AcsImpl.hpp" - -#include <errno.h> -#include <sstream> -#include <string.h> - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -castor::tape::rmc::AcsImpl::~AcsImpl() throw() { -} - -//------------------------------------------------------------------------------ -// mount -//------------------------------------------------------------------------------ -STATUS castor::tape::rmc::AcsImpl::mount( - const SEQ_NO seqNumber, - const LOCKID lockId, - const VOLID &volId, - const DRIVEID &driveId, - const BOOLEAN readOnly, - const BOOLEAN bypass) - throw() { - return acs_mount(seqNumber, lockId, volId, driveId, readOnly, bypass); -} - -//------------------------------------------------------------------------------ -// dismount -//------------------------------------------------------------------------------ -STATUS castor::tape::rmc::AcsImpl::dismount( - const SEQ_NO seqNumber, - const LOCKID lockId, - const VOLID &volId, - const DRIVEID &driveId, - const BOOLEAN force) - throw() { - return acs_dismount(seqNumber, lockId, volId, driveId, force); -} - -//------------------------------------------------------------------------------ -// response -//------------------------------------------------------------------------------ -STATUS castor::tape::rmc::AcsImpl::response( - const int timeout, - SEQ_NO &seqNumber, - REQ_ID &reqId, - ACS_RESPONSE_TYPE &rType, - ALIGNED_BYTES rBuf) throw() { - return acs_response(timeout, &seqNumber, &reqId, &rType, rBuf); -} - -//------------------------------------------------------------------------------ -// queryVolume -//------------------------------------------------------------------------------ -STATUS castor::tape::rmc::AcsImpl::queryVolume( - const SEQ_NO seqNumber, - VOLID (&volIds)[MAX_ID], - const unsigned short count) throw() { - return acs_query_volume(seqNumber, volIds, count); -} diff --git a/castor/tape/rmc/AcsImpl.hpp b/castor/tape/rmc/AcsImpl.hpp deleted file mode 100644 index 3832628b14ba53bbf860ba66a71dfc520fb64ff2..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsImpl.hpp +++ /dev/null @@ -1,126 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/tape/rmc/Acs.hpp" - -namespace castor { -namespace tape { -namespace rmc { - -/** - * Concrete class that wraps the ACLS C-API. - */ -class AcsImpl: public Acs { -public: - /** - * Destructor. - */ - ~AcsImpl() throw(); - - /** - * C++ wrapper around the acs_mount() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param lockId Lock identifier or 0 meaning no lock. - * @param volId The identifier of the volume to be mounted. - * @param driveId The ID of the drive into which the volume is to be mounted. - * @param readOnly Set to true to request the volume be mounted for read-only - * access. - * @param bypass Set to true to override the ACSLS verification of - * compatibility between the drive and the media type of the volume. - * @return status value returned by acs_mount(). - */ - STATUS mount( - const SEQ_NO seqNumber, - const LOCKID lockId, - const VOLID &volId, - const DRIVEID &driveId, - const BOOLEAN readOnly, - const BOOLEAN bypass) - throw(); - - /** - * C++ wrapper around the acs_dismount() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param lockId Lock identifier or 0 meaning no lock. - * @param volId The identifier of the volume to be mounted. - * @param driveId The ID of the drive into which the volume is to be mounted. - * @param force Set to true if the dismount should be forced. Forcing a - * dismount means dismounting the volume from the specified drive without - * checking the identifier of the volume. - * @return status value returned by acs_dismount(). - */ - STATUS dismount( - const SEQ_NO seqNumber, - const LOCKID lockId, - const VOLID &volId, - const DRIVEID &driveId, - const BOOLEAN force) - throw(); - - /** - * C++ wrapper around the acs_response() function of the ACSLS C-API. - * - * @param timeout Time in seconds to wait for a response. A value of -1 - * means block indefinitely and an a value of 0 means poll for the existence - * of a response. - * @param seqNumber Output parameter. If a response exists then seqNumber - * is set. - * @param reqId Output parameter. For an acknowledge response reqId is set - * to the request identifier of the original request. For an intermediate or - * final response reqId will be set to 0. - * @param rType Output parameter. Set to the type of the response. - * @param rBuf Output parameter. Set to the response information. - * @return status value returned by acs_response(). - */ - STATUS response( - const int timeout, - SEQ_NO &seqNumber, - REQ_ID &reqId, - ACS_RESPONSE_TYPE &rType, - ALIGNED_BYTES rBuf) throw(); - - /** - * C++ wrapper around the acs_query_volume() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param volIds Array of the volume identifiers to be queried. - * @param count The number of volume identifiers contained iwthin the volId - * parameter. - * @return status value returned by acs_response(). - */ - STATUS queryVolume( - const SEQ_NO seqNumber, - VOLID (&volIds)[MAX_ID], - const unsigned short count) throw(); - -}; // class AcsImpl - -} // namespace rmc -} // namespace tape -} // namespace castor - - diff --git a/castor/tape/rmc/AcsMountCmd.cpp b/castor/tape/rmc/AcsMountCmd.cpp deleted file mode 100644 index a8ee5b4eb9d1ddfbe96dd6cb03f6370df865f7f5..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsMountCmd.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/AcsMountCmd.hpp" -#include "castor/tape/utils/utils.hpp" - -#include <getopt.h> -#include <iostream> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::tape::rmc::AcsMountCmd::AcsMountCmd( - std::istream &inStream, std::ostream &outStream, std::ostream &errStream, - Acs &acs) throw(): - AcsCmd(inStream, outStream, errStream, acs), m_defaultQueryInterval(10), - m_defaultTimeout(600) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -castor::tape::rmc::AcsMountCmd::~AcsMountCmd() throw() { - // Do nothing -} - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int castor::tape::rmc::AcsMountCmd::main(const int argc, - char *const *const argv) throw() { - try { - m_cmdLine = parseCmdLine(argc, argv); - } catch(castor::exception::InvalidArgument &ia) { - m_err << "Aborting: Invalid command-line: " << ia.getMessage().str() << - std::endl; - m_err << std::endl; - usage(m_err); - return 1; - } catch(castor::exception::MissingOperand &mo) { - m_err << "Aborting: Missing operand: " << mo.getMessage().str() << - std::endl; - m_err << std::endl; - usage(m_err); - return 1; - } catch(castor::exception::Exception &ie) { - m_err << "Aborting: Internal error: " << ie.getMessage().str() << - std::endl; - return 1; - } - - // Display the usage message to standard out and exit with success if the - // user requested help - if(m_cmdLine.help) { - usage(m_out); - return 0; - } - - // Setup debug mode to be on or off depending on the command-line arguments - m_debugBuf.setDebug(m_cmdLine.debug); - - m_dbg << "query = " << m_cmdLine.queryInterval << std::endl; - m_dbg << "readonly = " << bool2Str(m_cmdLine.readOnly) << std::endl; - m_dbg << "timeout = " << m_cmdLine.timeout << std::endl; - m_dbg << "VID = " << m_cmdLine.volId.external_label << std::endl; - m_dbg << "DRIVE = " << m_acs.driveId2Str(m_cmdLine.driveId) << std::endl; - - try { - syncMount(); - } catch(castor::exception::Exception &ex) { - m_err << "Aborting: " << ex.getMessage().str() << std::endl; - return 1; - } - - return 0; -} - -//------------------------------------------------------------------------------ -// parseCmdLine -//------------------------------------------------------------------------------ -castor::tape::rmc::AcsMountCmdLine - castor::tape::rmc::AcsMountCmd::parseCmdLine( - const int argc, char *const *const argv) - throw(castor::exception::Exception, castor::exception::InvalidArgument, - castor::exception::MissingOperand) { - - static struct option longopts[] = { - {"debug", 0, NULL, 'd'}, - {"help" , 0, NULL, 'h'}, - {"query" , required_argument, NULL, 'q'}, - {"readonly" , 0, NULL, 'r'}, - {"timeout" , required_argument, NULL, 't'}, - {NULL, 0, NULL, 0} - }; - AcsMountCmdLine cmdLine; - char c; - - // Set the query option to the default value - cmdLine.queryInterval = m_defaultQueryInterval; - - // Set timeout option to the default value - cmdLine.timeout = m_defaultTimeout; - - // Prevent getopt() from printing an error message if it does not recognize - // an option character - opterr = 0; - while((c = getopt_long(argc, argv, ":dhq:rt:", longopts, NULL)) != -1) { - - switch (c) { - case 'd': - cmdLine.debug = true; - break; - case 'h': - cmdLine.help = true; - break; - case 'q': - cmdLine.queryInterval = atoi(optarg); - if(0 >= cmdLine.queryInterval) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Query value must be an integer greater than 0" - ": value=" << cmdLine.queryInterval; - throw ex; - } - break; - case 'r': - cmdLine.readOnly = TRUE; - break; - case 't': - cmdLine.timeout = atoi(optarg); - if(0 >= cmdLine.timeout) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Timeout value must be an integer greater than 0" - ": value=" << cmdLine.timeout; - throw ex; - } - break; - case ':': - { - castor::exception::InvalidArgument ex; - ex.getMessage() << "The -" << (char)optopt - << " option requires a parameter"; - throw ex; - } - break; - case '?': - { - castor::exception::InvalidArgument ex; - - if(optopt == 0) { - ex.getMessage() << "Unknown command-line option"; - } else { - ex.getMessage() << "Unknown command-line option: -" << (char)optopt; - } - throw ex; - } - break; - default: - { - castor::exception::Exception ex; - ex.getMessage() << - "getopt_long returned the following unknown value: 0x" << - std::hex << (int)c; - throw ex; - } - } // switch (c) - } // while ((c = getopt_long( ... )) != -1) - - // There is no need to continue parsing when the help option is set - if(cmdLine.help) { - return cmdLine; - } - - // Calculate the number of non-option ARGV-elements - const int nbArgs = argc - optind; - - // Check that both VID and DRIVE has been specified - if(nbArgs < 2) { - castor::exception::MissingOperand ex; - ex.getMessage() << "Both VID and DRIVE must be specified"; - throw ex; - } - - // Parse the VID command-line argument - cmdLine.volId = m_acs.str2Volid(argv[optind]); - - // Move on to the next command-line argument - optind++; - - // Parse the DRIVE command-line argument - cmdLine.driveId = m_acs.str2DriveId(argv[optind]); - - return cmdLine; -} - -//------------------------------------------------------------------------------ -// usage -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsMountCmd::usage(std::ostream &os) - const throw() { - os << - "Usage:\n" - "\n" - " castor-tape-acs-mount [options] VID DRIVE\n" - "\n" - "Where:\n" - "\n" - " VID The VID of the volume to be mounted.\n" - " DRIVE The ID of the drive into which the volume is to be mounted.\n" - " The format of DRIVE is:\n" - "\n" - " ACS:LSM:panel:transport\n" - "\n" - "Options:\n" - "\n" - " -d|--debug Turn on the printing of debug information.\n" - "\n" - " -h|--help Print this help message and exit.\n" - "\n" - " -q|--query SECONDS Time to wait between queries to ACS for responses.\n" - " SECONDS must be an integer value greater than 0.\n" - " The default value of SECONDS is " - << m_defaultQueryInterval << ".\n" - "\n" - " -r|--readOnly Request the volume is mounted for read-only access\n" - "\n" - " -t|--timeout SECONDS Time to wait for the mount to conclude. SECONDS\n" - " must be an integer value greater than 0. The\n" - " default value of SECONDS is " - << m_defaultTimeout << ".\n" - "\n" - "Comments to: Castor.Support@cern.ch" << std::endl; -} - -//------------------------------------------------------------------------------ -// syncMount -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsMountCmd::syncMount() - { - const SEQ_NO requestSeqNumber = 1; - ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - - try { - sendMountRequest(requestSeqNumber); - requestResponsesUntilFinal(requestSeqNumber, buf, m_cmdLine.queryInterval, - m_cmdLine.timeout); - processMountResponse(buf); - } catch(castor::exception::Exception &ex) { - castor::exception::MountFailed mf; - mf.getMessage() << "Failed to mount volume " << - m_cmdLine.volId.external_label << ": " << ex.getMessage().str(); - throw mf; - } -} - -//------------------------------------------------------------------------------ -// sendMountRequest -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsMountCmd::sendMountRequest( - const SEQ_NO seqNumber) { - const LOCKID lockId = 0; // No lock - const BOOLEAN bypass = FALSE; - - m_dbg << "Calling Acs::mount()" << std::endl; - const STATUS s = m_acs.mount(seqNumber, lockId, m_cmdLine.volId, - m_cmdLine.driveId, m_cmdLine.readOnly, bypass); - m_dbg << "Acs::mount() returned " << acs_status(s) << std::endl; - - if(STATUS_SUCCESS != s) { - castor::exception::MountFailed ex; - ex.getMessage() << "Failed to send request to mount volume " << - m_cmdLine.volId.external_label << " into drive " << - m_acs.driveId2Str(m_cmdLine.driveId) << ": readOnly=" << - (m_cmdLine.readOnly ? "TRUE" : "FALSE") << ": " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// processMountResponse -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsMountCmd::processMountResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) - { - const ACS_MOUNT_RESPONSE *const msg = (ACS_MOUNT_RESPONSE *)buf; - - if(STATUS_SUCCESS != msg->mount_status) { - castor::exception::MountFailed ex; - ex.getMessage() << "Status of mount response is not success: " << - acs_status(msg->mount_status); - throw ex; - } -} diff --git a/castor/tape/rmc/AcsMountCmd.hpp b/castor/tape/rmc/AcsMountCmd.hpp deleted file mode 100644 index 34668abfda3bc55065b1d21455a88aeb780ee4b3..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsMountCmd.hpp +++ /dev/null @@ -1,140 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/exception/InvalidArgument.hpp" -#include "castor/exception/MissingOperand.hpp" -#include "castor/exception/MountFailed.hpp" -#include "castor/tape/rmc/AcsCmd.hpp" -#include "castor/tape/rmc/AcsMountCmdLine.hpp" - -#include <stdint.h> - -namespace castor { -namespace tape { -namespace rmc { - -/** - * The class implementing the mount command. - */ -class AcsMountCmd: public AcsCmd { -public: - - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - * @param acs Wrapper around the ACSLS C-API. - */ - AcsMountCmd(std::istream &inStream, std::ostream &outStream, - std::ostream &errStream, Acs &acs) throw(); - - /** - * Destructor. - */ - virtual ~AcsMountCmd() throw(); - - /** - * The entry function of the command. - * - * @param argc The number of command-line arguments. - * @param argv The command-line arguments. - */ - int main(const int argc, char *const *const argv) throw(); - -protected: - - /** - * Parses the specified command-line arguments. - * - * @param argc Argument count from the executable's entry function: main(). - * @param argv Argument vector from the executable's entry function: main(). - * @return The parsed command-line. - */ - AcsMountCmdLine parseCmdLine(const int argc, char *const *const argv) - throw(castor::exception::Exception, castor::exception::InvalidArgument, - castor::exception::MissingOperand); - - /** - * Writes the command-line usage message of to the specified output stream. - * - * @param os Output stream to be written to. - */ - void usage(std::ostream &os) const throw(); - - /** - * Mounts the tape with the specified VID into the drive with the specified - * drive ID. - * - * This method does not return until the mount has either suceeded, failed or - * the specified timeout has been reached. - */ - void syncMount() ; - - /** - * Sends the mount request to ACSLS. - * - * @param seqNumber The sequence number to be used in the request. - */ - void sendMountRequest(const SEQ_NO seqNumber) - ; - - /** - * Throws castor::exception::DismountFailed if the mount was not - * successful. - * - * @param buf The mount-response message. - */ - void processMountResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) - ; - -private: - - /** - * The parsed command-line. - * - * The value of this member variable is set within the main() method of this - * class. - */ - AcsMountCmdLine m_cmdLine; - - /** - * The default time in seconds to wait between queries to ACS for responses. - */ - const int m_defaultQueryInterval; - - /** - * The default timeout value in seconds for the mount to conclude either - * success or failure. - */ - const int m_defaultTimeout; -}; // class AcsMountCmd - -} // namespace rmc -} // namespace tape -} // namespace castor - diff --git a/castor/tape/rmc/AcsMountCmdLine.cpp b/castor/tape/rmc/AcsMountCmdLine.cpp deleted file mode 100644 index 67b8fc7708faa29d387ed32f1bb7141991d1756f..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsMountCmdLine.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/AcsMountCmdLine.hpp" - -#include <string.h> - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -castor::tape::rmc::AcsMountCmdLine::AcsMountCmdLine() throw(): - debug(false), - help(false), - queryInterval(0), - readOnly(FALSE), - timeout(0) { - driveId.panel_id.lsm_id.acs = (ACS)0; - driveId.panel_id.lsm_id.lsm = (LSM)0; - driveId.panel_id.panel = (PANEL)0; - driveId.drive = (DRIVE)0; - memset(volId.external_label, '\0', sizeof(volId.external_label)); -} diff --git a/castor/tape/rmc/AcsMountCmdLine.hpp b/castor/tape/rmc/AcsMountCmdLine.hpp deleted file mode 100644 index 953b19b38823ecc4b718aefb901cdeb217451553..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsMountCmdLine.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -extern "C" { -#include "acssys.h" -#include "acsapi.h" -} - -#include <string> - -namespace castor { -namespace tape { -namespace rmc { - -/** - * Data type used to store the results of parsing the command-line. - */ -struct AcsMountCmdLine { - /** - * Constructor. - * - * Initialises all BOOLEAN member-variables to FALSE, all integer - * member-variables to 0 and the volume identifier to an empty string. - */ - AcsMountCmdLine() throw(); - - /** - * True if the debug option has been set. - */ - bool debug; - - /** - * True if the help option has been set. - */ - bool help; - - /** - * Time in seconds to wait between queries to ACS for responses. - */ - int queryInterval; - - /** - * True if the tape is to be mount for read-only access. - */ - BOOLEAN readOnly; - - /** - * Time in seconds to wait for the mount to conclude. - */ - int timeout; - - /** - * The volume identifier of the tape to be mounted. - */ - VOLID volId; - - /** - * The identifier of the drive into which the tape is to be mounted. - */ - DRIVEID driveId; - -}; // class AcsMountCmdLine - -} // namespace rmc -} // namespace tape -} // namespace castor - - diff --git a/castor/tape/rmc/AcsMountCmdLineTest.cpp b/castor/tape/rmc/AcsMountCmdLineTest.cpp deleted file mode 100644 index 2b296a9b977d1bfdd1df254deca83ab39ff2f5af..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsMountCmdLineTest.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/AcsMountCmdLine.hpp" - -#include <gtest/gtest.h> - -namespace unitTests { - -class castor_tape_rmc_AcsMountCmdLineTest: public ::testing::Test { -protected: - - virtual void SetUp() { - } - - virtual void TearDown() { - } -}; - -TEST_F(castor_tape_rmc_AcsMountCmdLineTest, constructor) { - const castor::tape::rmc::AcsMountCmdLine cmdLine; - ASSERT_EQ(false, cmdLine.debug); - ASSERT_EQ(false, cmdLine.help); - ASSERT_EQ((BOOLEAN)FALSE, cmdLine.readOnly); - ASSERT_EQ(0, cmdLine.timeout); - ASSERT_EQ(0, cmdLine.queryInterval); - ASSERT_EQ(0, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(0, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(0, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(0, (int)cmdLine.driveId.drive); - ASSERT_EQ('\0', cmdLine.volId.external_label[0]); -} - -} // namespace unitTests diff --git a/castor/tape/rmc/AcsMountCmdTest.cpp b/castor/tape/rmc/AcsMountCmdTest.cpp deleted file mode 100644 index ae83f647a5de57e951c9f3767358dec1e5f67fc3..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsMountCmdTest.cpp +++ /dev/null @@ -1,486 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/MockAcs.hpp" -#include "castor/tape/rmc/TestingAcsMountCmd.hpp" - -#include <gtest/gtest.h> -#include <list> -#include <memory> -#include <sstream> -#include <string.h> - -namespace unitTests { - -class castor_tape_rmc_AcsMountCmdTest: public ::testing::Test { -protected: - - struct Argcv { - int argc; - char **argv; - Argcv(): argc(0), argv(NULL) { - } - }; - typedef std::list<Argcv*> ArgcvList; - ArgcvList m_argsList; - - /** - * Creates a duplicate string usin the new operator. - */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; - } - - virtual void SetUp() { - } - - virtual void TearDown() { - // Allow getopt_long to be called again - optind = 0; - - for(ArgcvList::const_iterator itor = m_argsList.begin(); - itor != m_argsList.end(); itor++) { - for(int i=0; i < (*itor)->argc; i++) { - delete[] (*itor)->argv[i]; - } - delete[] (*itor)->argv; - delete *itor; - } - } -}; // class castor_tape_rmc_AcsMountCmdTest - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithNoArgs) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 1; - args->argv = new char *[2]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::MissingOperand); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithOnlyVolId) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("VIDVID"); - args->argv[2] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::MissingOperand); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithShortReadOnly) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 4; - args->argv = new char *[5]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("-r"); - args->argv[2] = dupString("VIDVID"); - args->argv[3] = dupString("111:112:113:114"); - args->argv[4] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - AcsMountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ((BOOLEAN)TRUE, cmdLine.readOnly); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithLongReadOnly) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 4; - args->argv = new char *[5]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("--readonly"); - args->argv[2] = dupString("VIDVID"); - args->argv[3] = dupString("111:112:113:114"); - args->argv[4] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - AcsMountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ((BOOLEAN)TRUE, cmdLine.readOnly); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithShortHelp) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("-h"); - args->argv[2] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - AcsMountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(true, cmdLine.help); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithLongHelp) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("--help"); - args->argv[2] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - AcsMountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(true, cmdLine.help); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithVolIdAndDrive) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 3; - args->argv = new char *[4]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("VIDVID"); - args->argv[2] = dupString("111:112:113:114"); - args->argv[3] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - AcsMountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(false, cmdLine.debug); - ASSERT_EQ(false, cmdLine.help); - ASSERT_EQ(10, cmdLine.queryInterval); - ASSERT_EQ(600, cmdLine.timeout); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithShortDebug) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 4; - args->argv = new char *[5]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("-d"); - args->argv[2] = dupString("VIDVID"); - args->argv[3] = dupString("111:112:113:114"); - args->argv[4] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - AcsMountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(true, cmdLine.debug); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithLongDebug) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 4; - args->argv = new char *[5]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("--debug"); - args->argv[2] = dupString("VIDVID"); - args->argv[3] = dupString("111:112:113:114"); - args->argv[4] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - AcsMountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(true, cmdLine.debug); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithTooLongVolIdAndDrive) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 3; - args->argv = new char *[4]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("VIDVID7"); - args->argv[2] = dupString("111:112:113:114"); - args->argv[3] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithValidVolIdAndInvalidDrive) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 3; - args->argv = new char *[4]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("VIDVID"); - args->argv[2] = dupString("INVALID_DRIVE"); - args->argv[3] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithShortTimeout) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 5; - args->argv = new char *[6]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("-t"); - args->argv[2] = dupString("2"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = dupString("111:112:113:114"); - args->argv[5] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - AcsMountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(2, cmdLine.timeout); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithLongTimeout) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 5; - args->argv = new char *[6]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("--timeout"); - args->argv[2] = dupString("2"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = dupString("111:112:113:114"); - args->argv[5] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - AcsMountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(2, cmdLine.timeout); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWith0Timeout) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 5; - args->argv = new char *[6]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("--timeout"); - args->argv[2] = dupString("0"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = dupString("111:112:113:114"); - args->argv[5] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithShortQuery) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 5; - args->argv = new char *[6]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("-q"); - args->argv[2] = dupString("1"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = dupString("111:112:113:114"); - args->argv[5] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - AcsMountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(1, cmdLine.queryInterval); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWithLongQuery) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 5; - args->argv = new char *[6]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("--query"); - args->argv[2] = dupString("1"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = dupString("111:112:113:114"); - args->argv[5] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - AcsMountCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(1, cmdLine.queryInterval); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); - ASSERT_EQ(111, (int)cmdLine.driveId.panel_id.lsm_id.acs); - ASSERT_EQ(112, (int)cmdLine.driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(113, (int)cmdLine.driveId.panel_id.panel); - ASSERT_EQ(114, (int)cmdLine.driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsMountCmdTest, parceCmdLineWith0Query) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 5; - args->argv = new char *[6]; - args->argv[0] = dupString("mountacs"); - args->argv[1] = dupString("--query"); - args->argv[2] = dupString("0"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = dupString("111:112:113:114"); - args->argv[5] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsMountCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::InvalidArgument); -} - -} // namespace unitTests diff --git a/castor/tape/rmc/AcsMountMain.cpp b/castor/tape/rmc/AcsMountMain.cpp deleted file mode 100644 index 8d82b947008ee887fe78d09c0a1344c352c461cb..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsMountMain.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/AcsImpl.hpp" -#include "castor/tape/rmc/AcsMountCmd.hpp" - -#include <iostream> - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int main(const int argc, char *const *const argv) { - - castor::tape::rmc::AcsImpl acs; - castor::tape::rmc::AcsMountCmd cmd(std::cin, std::cout, std::cerr, acs); - - return cmd.main(argc, argv); -} diff --git a/castor/tape/rmc/AcsQueryVolumeCmd.cpp b/castor/tape/rmc/AcsQueryVolumeCmd.cpp deleted file mode 100644 index e615953d047daa9f9755882d4f199130d3df805b..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsQueryVolumeCmd.cpp +++ /dev/null @@ -1,351 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/AcsQueryVolumeCmd.hpp" -#include "castor/tape/utils/utils.hpp" - -#include <getopt.h> -#include <iostream> -#include <string.h> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::tape::rmc::AcsQueryVolumeCmd::AcsQueryVolumeCmd( - std::istream &inStream, std::ostream &outStream, std::ostream &errStream, - Acs &acs) throw(): - AcsCmd(inStream, outStream, errStream, acs), m_defaultQueryInterval(1), - m_defaultTimeout(20) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -castor::tape::rmc::AcsQueryVolumeCmd::~AcsQueryVolumeCmd() throw() { - // Do nothing -} - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int castor::tape::rmc::AcsQueryVolumeCmd::main(const int argc, - char *const *const argv) throw() { - try { - m_cmdLine = parseCmdLine(argc, argv); - } catch(castor::exception::InvalidArgument &ia) { - m_err << "Aborting: Invalid command-line: " << ia.getMessage().str() << - std::endl; - m_err << std::endl; - usage(m_err); - return 1; - } catch(castor::exception::MissingOperand &mo) { - m_err << "Aborting: Missing operand: " << mo.getMessage().str() << - std::endl; - m_err << std::endl; - usage(m_err); - return 1; - } catch(castor::exception::Exception &ie) { - m_err << "Aborting: Internal error: " << ie.getMessage().str() << - std::endl; - return 1; - } - - // Display the usage message to standard out and exit with success if the - // user requested help - if(m_cmdLine.help) { - usage(m_out); - return 0; - } - - // Setup debug mode to be on or off depending on the command-line arguments - m_debugBuf.setDebug(m_cmdLine.debug); - - m_dbg << "query = " << m_cmdLine.queryInterval << std::endl; - m_dbg << "timeout = " << m_cmdLine.timeout << std::endl; - m_dbg << "VID = " << m_cmdLine.volId.external_label << std::endl; - - try { - syncQueryVolume(); - } catch(castor::exception::QueryVolumeFailed &ex) { - m_err << "Aborting: " << ex.getMessage().str() << std::endl; - return 1; - } - - return 0; -} - -//------------------------------------------------------------------------------ -// parseCmdLine -//------------------------------------------------------------------------------ -castor::tape::rmc::AcsQueryVolumeCmdLine - castor::tape::rmc::AcsQueryVolumeCmd::parseCmdLine( - const int argc, char *const *const argv) - throw(castor::exception::Exception, castor::exception::InvalidArgument, - castor::exception::MissingOperand) { - - static struct option longopts[] = { - {"debug", 0, NULL, 'd'}, - {"help" , 0, NULL, 'h'}, - {"query" , required_argument, NULL, 'q'}, - {"timeout" , required_argument, NULL, 't'}, - {NULL, 0, NULL, 0} - }; - AcsQueryVolumeCmdLine cmdLine; - char c; - - // Set the query option to the default value - cmdLine.queryInterval = m_defaultQueryInterval; - - // Set timeout option to the default value - cmdLine.timeout = m_defaultTimeout; - - // Prevent getopt() from printing an error message if it does not recognize - // an option character - opterr = 0; - while((c = getopt_long(argc, argv, ":dhq:t:", longopts, NULL)) != -1) { - - switch (c) { - case 'd': - cmdLine.debug = true; - break; - case 'h': - cmdLine.help = true; - break; - case 'q': - cmdLine.queryInterval = atoi(optarg); - if(0 >= cmdLine.queryInterval) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Query value must be an integer greater than 0" - ": value=" << cmdLine.queryInterval; - throw ex; - } - break; - case 't': - cmdLine.timeout = atoi(optarg); - if(0 >= cmdLine.timeout) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Timeout value must be an integer greater than 0" - ": value=" << cmdLine.timeout; - throw ex; - } - break; - case ':': - { - castor::exception::InvalidArgument ex; - ex.getMessage() << "The -" << (char)optopt - << " option requires a parameter"; - throw ex; - } - break; - case '?': - { - castor::exception::InvalidArgument ex; - - if(optopt == 0) { - ex.getMessage() << "Unknown command-line option"; - } else { - ex.getMessage() << "Unknown command-line option: -" << (char)optopt; - } - throw ex; - } - break; - default: - { - castor::exception::Exception ex; - ex.getMessage() << - "getopt_long returned the following unknown value: 0x" << - std::hex << (int)c; - throw ex; - } - } // switch (c) - } // while ((c = getopt_long( ... )) != -1) - - // There is no need to continue parsing when the help option is set - if(cmdLine.help) { - return cmdLine; - } - - // Calculate the number of non-option ARGV-elements - const int nbArgs = argc - optind; - - // Check that VID has been specified - if(nbArgs < 1) { - castor::exception::MissingOperand ex; - ex.getMessage() << "VID must be specified"; - throw ex; - } - - // Parse the VID command-line argument - cmdLine.volId = m_acs.str2Volid(argv[optind]); - - return cmdLine; -} - -//------------------------------------------------------------------------------ -// usage -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsQueryVolumeCmd::usage(std::ostream &os) - const throw() { - os << - "Usage:\n" - " castor-tape-acs-queryvolume [options] VID\n" - "\n" - "Where:\n" - "\n" - " VID The VID of the volume to be queried.\n" - "\n" - "Options:\n" - "\n" - " -d|--debug Turn on the printing of debug information.\n" - " -h|--help Print this help message and exit.\n" - " -q|--query SECONDS Time to wait between queries to ACS for responses.\n" - " SECONDS must be an integer value greater than 0.\n" - " The default value of SECONDS is " - << m_defaultQueryInterval << ".\n" - " -t|--timeout SECONDS Time to wait for the query to conclude. SECONDS\n" - " must be an integer value greater than 0. The\n" - " default value of SECONDS in " - << m_defaultTimeout << ".\n" - "\n" - "Comments to: Castor.Support@cern.ch" << std::endl; -} - -//------------------------------------------------------------------------------ -// syncQueryVolume -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsQueryVolumeCmd::syncQueryVolume() - { - const SEQ_NO requestSeqNumber = 1; - ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - - try { - sendQueryVolumeRequest(requestSeqNumber); - requestResponsesUntilFinal(requestSeqNumber, buf, m_cmdLine.queryInterval, - m_cmdLine.timeout); - processQueryResponse(m_out, buf); - } catch(castor::exception::Exception &ex) { - castor::exception::QueryVolumeFailed qf; - qf.getMessage() << "Failed to query volume " << - m_cmdLine.volId.external_label << ": " << ex.getMessage().str(); - throw qf; - } -} - -//------------------------------------------------------------------------------ -// sendQueryVolumeRequest -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsQueryVolumeCmd::sendQueryVolumeRequest( - const SEQ_NO seqNumber) { - VOLID volIds[MAX_ID]; - - memset(volIds, '\0', sizeof(volIds)); - strncpy(volIds[0].external_label, m_cmdLine.volId.external_label, - sizeof(volIds[0].external_label)); - volIds[0].external_label[sizeof(volIds[0].external_label) - 1] = '\0'; - - m_dbg << "Calling Acs::queryVolume()" << std::endl; - const STATUS s = m_acs.queryVolume(seqNumber, volIds, 1); - m_dbg << "Acs::queryVolume() returned " << acs_status(s) << std::endl; - - if(STATUS_SUCCESS != s) { - castor::exception::QueryVolumeFailed ex; - ex.getMessage() << "Failed to send query request for volume " << - m_cmdLine.volId.external_label << ": " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// processQueryResponse -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsQueryVolumeCmd::processQueryResponse( - std::ostream &os, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) - { - - const ACS_QUERY_VOL_RESPONSE *const msg = (ACS_QUERY_VOL_RESPONSE *)buf; - - if(STATUS_SUCCESS != msg->query_vol_status) { - castor::exception::QueryVolumeFailed ex; - ex.getMessage() << "Status of query response is not success: " << - acs_status(msg->query_vol_status); - throw ex; - } - - if((unsigned short)1 != msg->count) { - castor::exception::QueryVolumeFailed ex; - ex.getMessage() << "Query response does not contain a single volume: count=" - << msg->count; - throw ex; - } - - // count is 1 so it is safe to make a reference to the single volume status - const QU_VOL_STATUS &volStatus = msg->vol_status[0]; - - if(strcmp(m_cmdLine.volId.external_label, volStatus.vol_id.external_label)) { - castor::exception::QueryVolumeFailed ex; - ex.getMessage() << - "Volume identifier of query response does not match that of request" - ": requestVID=" << m_cmdLine.volId.external_label << - " responseVID=" << volStatus.vol_id.external_label; - throw ex; - } - - writeVolumeStatus(os, volStatus); -} - -//------------------------------------------------------------------------------ -// writeVolumeStatus -//------------------------------------------------------------------------------ -void castor::tape::rmc::AcsQueryVolumeCmd::writeVolumeStatus( - std::ostream &os, const QU_VOL_STATUS &s) throw() { - os << "Volume identifier: " << s.vol_id.external_label << std::endl; - os << "Media type (media_types.dat): " << (int)s.media_type << std::endl; - - switch(s.location_type) { - case LOCATION_CELL: { - os << "Location type: cell" << std::endl; - const CELLID &cellId = s.location.cell_id; - os << "ACS: " << (int)cellId.panel_id.lsm_id.acs << std::endl; - os << "LSM: " << (int)cellId.panel_id.lsm_id.lsm << std::endl; - os << "Panel: " << (int)cellId.panel_id.panel << std::endl; - os << "Row: " << (int)cellId.row << std::endl; - os << "Column: " << (int)cellId.col << std::endl; - break; - } - case LOCATION_DRIVE: { - os << "Location type: drive" << std::endl; - const DRIVEID &driveId = s.location.drive_id; - os << "ACS: " << (int)driveId.panel_id.lsm_id.acs << std::endl; - os << "LSM: " << (int)driveId.panel_id.lsm_id.lsm << std::endl; - os << "Panel: " << (int)driveId.panel_id.panel << std::endl; - os << "Drive: " << (int)driveId.drive << std::endl; - break; - } - default: - os << "Location type: UNKNOWN" << std::endl; - break; - } - - os << "Status: " << acs_status(s.status) << std::endl; -} diff --git a/castor/tape/rmc/AcsQueryVolumeCmd.hpp b/castor/tape/rmc/AcsQueryVolumeCmd.hpp deleted file mode 100644 index 82ed535ff92c93f63cfdd1405acb47293b339272..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsQueryVolumeCmd.hpp +++ /dev/null @@ -1,155 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/exception/InvalidArgument.hpp" -#include "castor/exception/MissingOperand.hpp" -#include "castor/exception/QueryVolumeFailed.hpp" -#include "castor/tape/rmc/AcsCmd.hpp" -#include "castor/tape/rmc/AcsQueryVolumeCmdLine.hpp" - -#include <stdint.h> - -namespace castor { -namespace tape { -namespace rmc { - -/** - * The class implementing the mount command. - */ -class AcsQueryVolumeCmd: public AcsCmd { -public: - - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - * @param acs Wrapper around the ACSLS C-API. - */ - AcsQueryVolumeCmd(std::istream &inStream, std::ostream &outStream, - std::ostream &errStream, Acs &acs) throw(); - - /** - * Destructor. - */ - virtual ~AcsQueryVolumeCmd() throw(); - - /** - * The entry function of the command. - * - * @param argc The number of command-line arguments. - * @param argv The command-line arguments. - */ - int main(const int argc, char *const *const argv) throw(); - -protected: - - /** - * Parses the specified command-line arguments. - * - * @param argc Argument count from the executable's entry function: main(). - * @param argv Argument vector from the executable's entry function: main(). - * @return The parsed command-line. - */ - AcsQueryVolumeCmdLine parseCmdLine(const int argc, char *const *const argv) - throw(castor::exception::Exception, castor::exception::InvalidArgument, - castor::exception::MissingOperand); - - /** - * Writes the command-line usage message of to the specified output stream. - * - * @param os Output stream to be written to. - */ - void usage(std::ostream &os) const throw(); - - /** - * Queries ACS for information about the volume identifier specified on the - * command-line. - * - * This method does not return until the information has been successfully - * retrieved, an error has occurred or the specified timeout has been - * reached. - * - * @return The volume status of the volume identifier specified on the - * command-line. - */ - void syncQueryVolume() ; - - /** - * Sends the query volume request to ACSLS. - * - * @param seqNumber The sequence number to be used in the request. - */ - void sendQueryVolumeRequest(const SEQ_NO seqNumber) - ; - - /** - * Extracts the volume status from the specified query-response message and - * writes it in human-readable form to the specified output stream. - * - * @param os The output stream. - * @param buf The query-response message. - */ - void processQueryResponse(std::ostream &os, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) - ; - - /** - * Writes a human readable representation of the specified volume status to - * the specified output stream. - * - * @param os The output stream. - * @param s The volume status. - */ - void writeVolumeStatus(std::ostream &os, const QU_VOL_STATUS &s) throw(); - -private: - - /** - * The parsed command-line. - * - * The value of this member variable is set within the main() method of this - * class. - */ - AcsQueryVolumeCmdLine m_cmdLine; - - /** - * The default time in seconds to wait between queries to ACS for responses. - */ - const int m_defaultQueryInterval; - - /** - * The default timeout value in seconds for the query to conclude either - * success or failure. - */ - const int m_defaultTimeout; - -}; // class AcsQueryVolumeCmd - -} // namespace rmc -} // namespace tape -} // namespace castor - diff --git a/castor/tape/rmc/AcsQueryVolumeCmdLine.cpp b/castor/tape/rmc/AcsQueryVolumeCmdLine.cpp deleted file mode 100644 index ca0ad417dca6026169dab20ba8756ad48ccfafcd..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsQueryVolumeCmdLine.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/AcsQueryVolumeCmdLine.hpp" - -#include <string.h> - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -castor::tape::rmc::AcsQueryVolumeCmdLine::AcsQueryVolumeCmdLine() - throw(): - debug(FALSE), - help(FALSE), - queryInterval(0), - timeout(0) { - memset(volId.external_label, '\0', sizeof(volId.external_label)); -} diff --git a/castor/tape/rmc/AcsQueryVolumeCmdLine.hpp b/castor/tape/rmc/AcsQueryVolumeCmdLine.hpp deleted file mode 100644 index e4966108d902d0bc9f2e90524d454c3aeddde13e..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsQueryVolumeCmdLine.hpp +++ /dev/null @@ -1,80 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -extern "C" { -#include "acssys.h" -#include "acsapi.h" -} - -#include <string> - -namespace castor { -namespace tape { -namespace rmc { - -/** - * Data type used to store the results of parsing the command-line. - */ -struct AcsQueryVolumeCmdLine { - /** - * Constructor. - * - * Initialises all BOOLEAN member-variables to FALSE, all integer - * member-variables to 0 and the volume identifier to an empty string. - */ - AcsQueryVolumeCmdLine() throw(); - - /** - * True if the debug option has been set. - */ - BOOLEAN debug; - - /** - * True if the help option has been set. - */ - BOOLEAN help; - - /** - * Time in seconds to wait between queries to ACS for responses. - */ - int queryInterval; - - /** - * Time in seconds to wait for the dismount to conclude. - */ - int timeout; - - /** - * The volume identifier of the tape to be mounted. - */ - VOLID volId; - -}; // class AcsQueryVolumeCmdLine - -} // namespace rmc -} // namespace tape -} // namespace castor - - diff --git a/castor/tape/rmc/AcsQueryVolumeCmdLineTest.cpp b/castor/tape/rmc/AcsQueryVolumeCmdLineTest.cpp deleted file mode 100644 index 0e39ec9c5adbc01683a9e4cb31a561f534b18021..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsQueryVolumeCmdLineTest.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/AcsQueryVolumeCmdLine.hpp" - -#include <gtest/gtest.h> - -namespace unitTests { - -class castor_tape_rmc_AcsQueryVolumeCmdLineTest: public ::testing::Test { -protected: - - virtual void SetUp() { - } - - virtual void TearDown() { - } -}; // class castor_tape_rmc_AcsQueryVolumeCmdLineTest - -TEST_F(castor_tape_rmc_AcsQueryVolumeCmdLineTest, constructor) { - const castor::tape::rmc::AcsQueryVolumeCmdLine cmdLine; - ASSERT_EQ((BOOLEAN)FALSE, cmdLine.debug); - ASSERT_EQ((BOOLEAN)FALSE, cmdLine.help); - ASSERT_EQ(0, cmdLine.timeout); - ASSERT_EQ(0, cmdLine.queryInterval); - ASSERT_EQ('\0', cmdLine.volId.external_label[0]); -} - -} // namespace unitTests diff --git a/castor/tape/rmc/AcsQueryVolumeCmdTest.cpp b/castor/tape/rmc/AcsQueryVolumeCmdTest.cpp deleted file mode 100644 index 36c3b944d6bf5b9d8105521bd71b2c4c5cc874dd..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsQueryVolumeCmdTest.cpp +++ /dev/null @@ -1,355 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/MockAcs.hpp" -#include "castor/tape/rmc/TestingAcsQueryVolumeCmd.hpp" - -#include <gtest/gtest.h> -#include <list> -#include <memory> -#include <sstream> -#include <string.h> - -namespace unitTests { - -class castor_tape_rmc_AcsQueryVolumeCmdTest: public ::testing::Test { -protected: - - struct Argcv { - int argc; - char **argv; - Argcv(): argc(0), argv(NULL) { - } - }; - typedef std::list<Argcv*> ArgcvList; - ArgcvList m_argsList; - - /** - * Creates a duplicate string usin the new operator. - */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; - } - - virtual void SetUp() { - } - - virtual void TearDown() { - // Allow getopt_long to be called again - optind = 0; - - for(ArgcvList::const_iterator itor = m_argsList.begin(); - itor != m_argsList.end(); itor++) { - for(int i=0; i < (*itor)->argc; i++) { - delete[] (*itor)->argv[i]; - } - delete[] (*itor)->argv; - delete *itor; - } - } -}; // class castor_tape_rmc_AcsQueryVolumeCmdTest - -TEST_F(castor_tape_rmc_AcsQueryVolumeCmdTest, parceCmdLineWithNoArgs) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 1; - args->argv = new char *[2]; - args->argv[0] = dupString("queryvolume"); - args->argv[1] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsQueryVolumeCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::MissingOperand); -} - -TEST_F(castor_tape_rmc_AcsQueryVolumeCmdTest, parceCmdLineWithValidVolId) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("queryvolume"); - args->argv[1] = dupString("VIDVID"); - args->argv[2] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsQueryVolumeCmd cmd(inStream, outStream, errStream, acs); - AcsQueryVolumeCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ((BOOLEAN)FALSE, cmdLine.debug); - ASSERT_EQ((BOOLEAN)FALSE, cmdLine.help); - ASSERT_EQ(1, cmdLine.queryInterval); - ASSERT_EQ(20, cmdLine.timeout); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); -} - -TEST_F(castor_tape_rmc_AcsQueryVolumeCmdTest, parceCmdLineWithShortHelp) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("queryvolume"); - args->argv[1] = dupString("-h"); - args->argv[2] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsQueryVolumeCmd cmd(inStream, outStream, errStream, acs); - AcsQueryVolumeCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ((BOOLEAN)TRUE, cmdLine.help); -} - -TEST_F(castor_tape_rmc_AcsQueryVolumeCmdTest, parceCmdLineWithLongHelp) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("queryvolume"); - args->argv[1] = dupString("--help"); - args->argv[2] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsQueryVolumeCmd cmd(inStream, outStream, errStream, acs); - AcsQueryVolumeCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ((BOOLEAN)TRUE, cmdLine.help); -} - -TEST_F(castor_tape_rmc_AcsQueryVolumeCmdTest, parceCmdLineWithShortDebug) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 3; - args->argv = new char *[4]; - args->argv[0] = dupString("queryvolume"); - args->argv[1] = dupString("-d"); - args->argv[2] = dupString("VIDVID"); - args->argv[3] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsQueryVolumeCmd cmd(inStream, outStream, errStream, acs); - AcsQueryVolumeCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ((BOOLEAN)TRUE, cmdLine.debug); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); -} - -TEST_F(castor_tape_rmc_AcsQueryVolumeCmdTest, parceCmdLineWithLongDebug) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 3; - args->argv = new char *[4]; - args->argv[0] = dupString("queryvolume"); - args->argv[1] = dupString("--debug"); - args->argv[2] = dupString("VIDVID"); - args->argv[3] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsQueryVolumeCmd cmd(inStream, outStream, errStream, acs); - AcsQueryVolumeCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ((BOOLEAN)TRUE, cmdLine.debug); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); -} - -TEST_F(castor_tape_rmc_AcsQueryVolumeCmdTest, parceCmdLineWithTooLongVolId) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("queryvolume"); - args->argv[1] = dupString("VIDVID7"); - args->argv[2] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsQueryVolumeCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsQueryVolumeCmdTest, parceCmdLineWithShortTimeout) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 4; - args->argv = new char *[5]; - args->argv[0] = dupString("queryvolume"); - args->argv[1] = dupString("-t"); - args->argv[2] = dupString("2"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsQueryVolumeCmd cmd(inStream, outStream, errStream, acs); - AcsQueryVolumeCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(2, cmdLine.timeout); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); -} - -TEST_F(castor_tape_rmc_AcsQueryVolumeCmdTest, parceCmdLineWithLongTimeout) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 4; - args->argv = new char *[5]; - args->argv[0] = dupString("queryvolume"); - args->argv[1] = dupString("--timeout"); - args->argv[2] = dupString("2"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsQueryVolumeCmd cmd(inStream, outStream, errStream, acs); - AcsQueryVolumeCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(2, cmdLine.timeout); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); -} - -TEST_F(castor_tape_rmc_AcsQueryVolumeCmdTest, parceCmdLineWith0Timeout) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 4; - args->argv = new char *[5]; - args->argv[0] = dupString("queryvolume"); - args->argv[1] = dupString("--timeout"); - args->argv[2] = dupString("0"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsQueryVolumeCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsQueryVolumeCmdTest, parceCmdLineWithShortQuery) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 4; - args->argv = new char *[5]; - args->argv[0] = dupString("queryvolume"); - args->argv[1] = dupString("-q"); - args->argv[2] = dupString("1"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsQueryVolumeCmd cmd(inStream, outStream, errStream, acs); - AcsQueryVolumeCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(1, cmdLine.queryInterval); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); -} - -TEST_F(castor_tape_rmc_AcsQueryVolumeCmdTest, parceCmdLineWithLongQuery) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 4; - args->argv = new char *[5]; - args->argv[0] = dupString("queryvolume"); - args->argv[1] = dupString("--query"); - args->argv[2] = dupString("1"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsQueryVolumeCmd cmd(inStream, outStream, errStream, acs); - AcsQueryVolumeCmdLine cmdLine; - ASSERT_NO_THROW(cmdLine = cmd.parseCmdLine(args->argc, args->argv)); - ASSERT_EQ(1, cmdLine.queryInterval); - ASSERT_EQ(std::string("VIDVID"), std::string(cmdLine.volId.external_label)); -} - -TEST_F(castor_tape_rmc_AcsQueryVolumeCmdTest, parceCmdLineWith0Query) { - using namespace castor::tape::rmc; - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 4; - args->argv = new char *[5]; - args->argv[0] = dupString("queryvolume"); - args->argv[1] = dupString("--query"); - args->argv[2] = dupString("0"); - args->argv[3] = dupString("VIDVID"); - args->argv[4] = NULL; - - std::istringstream inStream; - std::ostringstream outStream; - std::ostringstream errStream; - MockAcs acs; - TestingAcsQueryVolumeCmd cmd(inStream, outStream, errStream, acs); - ASSERT_THROW(cmd.parseCmdLine(args->argc, args->argv), - castor::exception::InvalidArgument); -} - -} // namespace unitTests diff --git a/castor/tape/rmc/AcsQueryVolumeMain.cpp b/castor/tape/rmc/AcsQueryVolumeMain.cpp deleted file mode 100644 index 1d65ce5c1dd8bb044b16487a2c18e6c67f9bf20f..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsQueryVolumeMain.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/AcsImpl.hpp" -#include "castor/tape/rmc/AcsQueryVolumeCmd.hpp" - -#include <iostream> - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int main(const int argc, char *const *const argv) { - - castor::tape::rmc::AcsImpl acs; - castor::tape::rmc::AcsQueryVolumeCmd - cmd(std::cin, std::cout, std::cerr, acs); - - return cmd.main(argc, argv); -} diff --git a/castor/tape/rmc/AcsTest.cpp b/castor/tape/rmc/AcsTest.cpp deleted file mode 100644 index 02b5b6b0fb1ae18b2b33dd4c7352b3c17d354e6e..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/AcsTest.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/MockAcs.hpp" - -#include <gtest/gtest.h> - -namespace unitTests { - -class castor_tape_rmc_AcsTest: public ::testing::Test { -protected: - - virtual void SetUp() { - } - - virtual void TearDown() { - } -}; // class castor_tape_rmc_AcsTest - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithValidDriveId) { - using namespace castor::tape::rmc; - const std::string str = "111:112:113:114"; - DRIVEID driveId; - MockAcs acs; - ASSERT_NO_THROW(driveId = acs.str2DriveId(str)); - ASSERT_EQ((ACS)111, driveId.panel_id.lsm_id.acs); - ASSERT_EQ((LSM)112, driveId.panel_id.lsm_id.lsm); - ASSERT_EQ((PANEL)113, driveId.panel_id.panel); - ASSERT_EQ((DRIVE)114, driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithEmptyString) { - using namespace castor::tape::rmc; - const std::string str = ""; - MockAcs acs; - ASSERT_THROW(acs.str2DriveId(str), castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveWithPrecedingZeros) { - using namespace castor::tape::rmc; - const std::string str = "011:012:013:014"; - DRIVEID driveId; - MockAcs acs; - ASSERT_NO_THROW(driveId = acs.str2DriveId(str)); - ASSERT_EQ((ACS)11, driveId.panel_id.lsm_id.acs); - ASSERT_EQ((LSM)12, driveId.panel_id.lsm_id.lsm); - ASSERT_EQ((PANEL)13, driveId.panel_id.panel); - ASSERT_EQ((DRIVE)14, driveId.drive); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithTooManyColons) { - using namespace castor::tape::rmc; - const std::string str = "111:112:113:114:115"; - MockAcs acs; - ASSERT_THROW(acs.str2DriveId(str), castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsTest, driveId2StrWithArbitrary3DigitValues) { - using namespace castor::tape::rmc; - DRIVEID driveId; - driveId.panel_id.lsm_id.acs = (ACS)111; - driveId.panel_id.lsm_id.lsm = (LSM)112; - driveId.panel_id.panel = (PANEL)113; - driveId.drive = (DRIVE)114; - MockAcs acs; - ASSERT_EQ(std::string("111:112:113:114"), acs.driveId2Str(driveId)); -} - -TEST_F(castor_tape_rmc_AcsTest, driveId2StrWithArbitrary1DigitValues) { - using namespace castor::tape::rmc; - DRIVEID driveId; - driveId.panel_id.lsm_id.acs = (ACS)1; - driveId.panel_id.lsm_id.lsm = (LSM)2; - driveId.panel_id.panel = (PANEL)3; - driveId.drive = (DRIVE)4; - MockAcs acs; - ASSERT_EQ(std::string("001:002:003:004"), acs.driveId2Str(driveId)); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithTooLongAcs) { - using namespace castor::tape::rmc; - const std::string str = "1111:112:113:114"; - MockAcs acs; - ASSERT_THROW(acs.str2DriveId(str), castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithTooLongLsm) { - using namespace castor::tape::rmc; - const std::string str = "111:1122:113:114"; - MockAcs acs; - ASSERT_THROW(acs.str2DriveId(str), castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithTooLongPanel) { - using namespace castor::tape::rmc; - const std::string str = "111:112:1133:114"; - MockAcs acs; - ASSERT_THROW(acs.str2DriveId(str), castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithTooLongTransport) { - using namespace castor::tape::rmc; - const std::string str = "111:112:113:1144"; - MockAcs acs; - ASSERT_THROW(acs.str2DriveId(str), castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithNonNumericAcs) { - using namespace castor::tape::rmc; - const std::string str = "acs:112:113:114"; - MockAcs acs; - ASSERT_THROW(acs.str2DriveId(str), castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithNonNumericLsm) { - using namespace castor::tape::rmc; - const std::string str = "111:lsm:113:114"; - MockAcs acs; - ASSERT_THROW(acs.str2DriveId(str), castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithNonNumericPanel) { - using namespace castor::tape::rmc; - const std::string str = "111:112:pan:114"; - MockAcs acs; - ASSERT_THROW(acs.str2DriveId(str), castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithNonNumericTransport) { - using namespace castor::tape::rmc; - const std::string str = "111:112:113:tra"; - MockAcs acs; - ASSERT_THROW(acs.str2DriveId(str), castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithEmptyAcs) { - using namespace castor::tape::rmc; - const std::string str = ":112:113:114"; - MockAcs acs; - ASSERT_THROW(acs.str2DriveId(str), castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithEmptyLsm) { - using namespace castor::tape::rmc; - const std::string str = "111::113:114"; - MockAcs acs; - ASSERT_THROW(acs.str2DriveId(str), castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithEmptyPanel) { - using namespace castor::tape::rmc; - const std::string str = "111:112::114"; - MockAcs acs; - ASSERT_THROW(acs.str2DriveId(str), castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsTest, str2DriveIdWithEmptyTransport) { - using namespace castor::tape::rmc; - const std::string str = "111:112:113:"; - MockAcs acs; - ASSERT_THROW(acs.str2DriveId(str), castor::exception::InvalidArgument); -} - -TEST_F(castor_tape_rmc_AcsTest, str2VolidWithEmptyString) { - using namespace castor::tape::rmc; - const std::string str = ""; - VOLID volId; - MockAcs acs; - ASSERT_NO_THROW(volId = acs.str2Volid(str)); - ASSERT_EQ('\0', volId.external_label[0]); -} - -TEST_F(castor_tape_rmc_AcsTest, str2VolidWith6CharacterString) { - using namespace castor::tape::rmc; - const std::string str = "123456"; - VOLID volId; - MockAcs acs; - ASSERT_NO_THROW(volId = acs.str2Volid(str)); - ASSERT_EQ(str, std::string(volId.external_label)); -} - -TEST_F(castor_tape_rmc_AcsTest, str2VolidWith7CharacterString) { - using namespace castor::tape::rmc; - const std::string str = "1234567"; - MockAcs acs; - ASSERT_THROW(acs.str2Volid(str), castor::exception::InvalidArgument); -} - -} // namespace unitTests diff --git a/castor/tape/rmc/CMakeLists.txt b/castor/tape/rmc/CMakeLists.txt deleted file mode 100644 index b097ea9df3eb32f428175cee35703c72d264bc42..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/CMakeLists.txt +++ /dev/null @@ -1,173 +0,0 @@ -# -# castor/tape/rmc/CMakeLists.txt -# -# This file is part of the Castor project. -# See http://castor.web.cern.ch/castor -# -# Copyright (C) 2003 CERN -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# -# Steven.Murray@cern.ch -# -cmake_minimum_required (VERSION 2.6) - -if (${COMPILE_SERVER} STREQUAL "1") - ############################################################################## - # Rules to build and install rmcd - ############################################################################## - set (RMCD_SRC_FILES - AcceptHandler.cpp - ConnectionHandler.cpp - RmcDaemon.cpp - RmcDaemonMain.cpp) - add_executable (newrmcd ${RMCD_SRC_FILES}) - target_link_libraries (newrmcd - castorclient - castorcommon - castorlegacymsg - castormediachangerclient - castorserver - castortapereactor - zmq) - #install (TARGETS newrmcd DESTINATION ${CASTOR_DEST_LIB_DIR}) - #CastorInstallExeManPage(newrmcd) - - ############################################################################## - # Rules to build and install castor-tape-mount - ############################################################################## - set (MOUNT_SRC_FILES - Cmd.cpp - MountCmd.cpp - MountCmdLine.cpp - MountMain.cpp) - add_executable (castor-tape-mount ${MOUNT_SRC_FILES}) - target_link_libraries (castor-tape-mount castorclient castorcommon castorrmc) - #install (TARGETS castor-tape-mount DESTINATION ${CASTOR_DEST_LIB_DIR}) - #CastorInstallExeManPage(castor-tape-mount) - - ############################################################################## - # Try to find the four STK client libaries: libapi.so, libutl.so, libipc.so - # and libcl.so - ############################################################################## - find_library (STK_API_LIB api - PATHS /usr/lib64/CDK /usr/lib/CDK NO_DEFAULT_PATH) - if (STK_API_LIB) - message(STATUS "Found the STK api library: ${STK_API_LIB}") - endif (STK_API_LIB) - find_library (STK_UTL_LIB utl - PATHS /usr/lib64/CDK /usr/lib/CDK NO_DEFAULT_PATH) - if (STK_UTL_LIB) - message(STATUS "Found the STK utl library: ${STK_UTL_LIB}") - endif (STK_UTL_LIB) - find_library (STK_IPC_LIB ipc - PATHS /usr/lib64/CDK /usr/lib/CDK NO_DEFAULT_PATH) - if (STK_IPC_LIB) - message(STATUS "Found the STK ipc library: ${STK_IPC_LIB}") - endif (STK_IPC_LIB) - find_library (STK_CL_LIB cl PATHS /usr/lib64/CDK /usr/lib/CDK NO_DEFAULT_PATH) - if (STK_CL_LIB) - message(STATUS "Found the STK cl library: ${STK_CL_LIB}") - endif (STK_CL_LIB) - - ############################################################################## - # Add the castor-tape-acs-dismount, castor-tape-acs-mount and - # castor-tape-queryvolume targets if all four STK client libaries - # (libapi.so, libutl.so, libipc.so and libcl.so) have been found - ############################################################################## - if (STK_API_LIB AND STK_UTL_LIB AND STK_IPC_LIB AND STK_CL_LIB) - message(STATUS "Found all four STK libraries") - - ############################################################################ - # Rules to build and install castor-tape-acs-dismount - ############################################################################ - message(STATUS "Adding castor-tape-acs-dismount target") - set (ACS_DISMOUNT_SRC_FILES - Acs.cpp - AcsCmd.cpp - AcsImpl.cpp - AcsDismountCmd.cpp - AcsDismountCmdLine.cpp - AcsDismountMain.cpp - Cmd.cpp) - add_executable (castor-tape-acs-dismount ${ACS_DISMOUNT_SRC_FILES}) - set_target_properties (castor-tape-acs-dismount PROPERTIES - COMPILE_FLAGS -I/usr/include/CDK - COMPILE_DEFINITIONS LINUX) - target_link_libraries (castor-tape-acs-dismount - castorclient - castorcommon - castortapeutils - ${STK_API_LIB} - ${STK_UTL_LIB} - ${STK_IPC_LIB} - ${STK_CL_LIB}) - #install (TARGETS castor-tape-acs-dismount - # DESTINATION ${CASTOR_DEST_LIB_DIR}) - #CastorInstallExeManPage(castor-tape-acs-dismount) - - ############################################################################ - # Rules to build and install castor-tape-acs-mount - ############################################################################ - set (ACS_MOUNT_SRC_FILES - Acs.cpp - AcsCmd.cpp - AcsImpl.cpp - AcsMountCmd.cpp - AcsMountCmdLine.cpp - AcsMountMain.cpp - Cmd.cpp) - add_executable (castor-tape-acs-mount ${ACS_MOUNT_SRC_FILES}) - set_target_properties (castor-tape-acs-mount PROPERTIES - COMPILE_FLAGS -I/usr/include/CDK - COMPILE_DEFINITIONS LINUX) - target_link_libraries (castor-tape-acs-mount - castorclient - castorcommon - castortapeutils - ${STK_API_LIB} - ${STK_UTL_LIB} - ${STK_IPC_LIB} - ${STK_CL_LIB}) - #install (TARGETS castor-tape-acs-mount DESTINATION ${CASTOR_DEST_LIB_DIR}) - #CastorInstallExeManPage(castor-tape-acs-mount) - - ############################################################################ - # Rules to build and install castor-tape-acs-queryvolume - ############################################################################ - message(STATUS "Adding castor-tape-acs-queryvolume target") - set (ACS_QUERYVOLUME_SRC_FILES - Acs.cpp - AcsCmd.cpp - AcsImpl.cpp - AcsQueryVolumeCmd.cpp - AcsQueryVolumeCmdLine.cpp - AcsQueryVolumeMain.cpp - Cmd.cpp) - add_executable (castor-tape-acs-queryvolume ${ACS_QUERYVOLUME_SRC_FILES}) - target_link_libraries (castor-tape-acs-queryvolume - castorclient - castorcommon - castortapeutils - ${STK_API_LIB} - ${STK_UTL_LIB} - ${STK_IPC_LIB} - ${STK_CL_LIB}) - set_target_properties (castor-tape-acs-queryvolume PROPERTIES - COMPILE_FLAGS -I/usr/include/CDK - COMPILE_DEFINITIONS LINUX) - #install (TARGETS castor-tape-acs-queryvolume - # DESTINATION ${CASTOR_DEST_LIB_DIR}) - #CastorInstallExeManPage(castor-tape-acs-queryvolume) - endif (STK_API_LIB AND STK_UTL_LIB AND STK_IPC_LIB AND STK_CL_LIB) -endif (${COMPILE_SERVER} STREQUAL "1") diff --git a/castor/tape/rmc/Cmd.cpp b/castor/tape/rmc/Cmd.cpp deleted file mode 100644 index 2850a027dc3795fc79807816c0b240431d727000..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/Cmd.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/Cmd.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::tape::rmc::Cmd::Cmd(std::istream &inStream, - std::ostream &outStream, std::ostream &errStream) throw(): - m_in(inStream), m_out(outStream), m_err(errStream), m_debugBuf(outStream), - m_dbg(&m_debugBuf) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -castor::tape::rmc::Cmd::~Cmd() throw() { -} - -//------------------------------------------------------------------------------ -// bool2Str -//------------------------------------------------------------------------------ -std::string castor::tape::rmc::Cmd::bool2Str(const bool value) const throw() { - return value ? "TRUE" : "FALSE"; -} diff --git a/castor/tape/rmc/Cmd.hpp b/castor/tape/rmc/Cmd.hpp deleted file mode 100644 index 0953ed056d28add4a729ef9bae18444e7491e150..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/Cmd.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/utils/DebugBuf.hpp" - -#include <istream> -#include <ostream> -#include <string> - -namespace castor { -namespace tape { -namespace rmc { - -/** - * Abstract class implementing common code and data structures for a - * command-line tool. - */ -class Cmd { -public: - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - */ - Cmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream) - throw(); - - /** - * Pure-virtual destructor to guarantee this class is abstract. - */ - virtual ~Cmd() throw() = 0; - -protected: - - /** - * Standard input stream. - */ - std::istream &m_in; - - /** - * Standard output stream. - */ - std::ostream &m_out; - - /** - * Standard error stream. - */ - std::ostream &m_err; - - /** - * Debug stream buffer that inserts a standard debug preamble before each - * message-line written to it. - */ - utils::DebugBuf m_debugBuf; - - /** - * Stream used to write debug messages. - * - * This stream will insert a standard debug preamble before each message-line - * written to it. - */ - std::ostream m_dbg; - - /** - * Returns the string representation of the specfied boolean value. - * - * @param value The boolean value. - */ - std::string bool2Str(const bool value) const throw(); - -}; // class Cmd - -} // namespace rmc -} // namespace tape -} // namespace castor - diff --git a/castor/tape/rmc/ConnectionHandler.cpp b/castor/tape/rmc/ConnectionHandler.cpp deleted file mode 100644 index 536eb83ca184c2356afe25428d7deb2d078ed8d5..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/ConnectionHandler.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/ConnectionHandler.hpp" -#include "h/common.h" -#include "h/serrno.h" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::tape::rmc::ConnectionHandler::ConnectionHandler(const int fd, - reactor::ZMQReactor &reactor, log::Logger &log) throw(): - m_fd(fd), - m_reactor(reactor), - m_log(log), - m_netTimeout(1) // Timneout in seconds -{ -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -castor::tape::rmc::ConnectionHandler::~ConnectionHandler() throw() { - log::Param params[] = {log::Param("fd", m_fd)}; - m_log(LOG_DEBUG, "Closing client connection", params); - close(m_fd); -} - -//------------------------------------------------------------------------------ -// getName -//------------------------------------------------------------------------------ -std::string castor::tape::rmc::ConnectionHandler::getName() const throw() { - return "rmc::ConnectionHandler"; -} - -//------------------------------------------------------------------------------ -// fillPollFd -//------------------------------------------------------------------------------ -void castor::tape::rmc::ConnectionHandler::fillPollFd(zmq_pollitem_t &fd) throw() { - fd.fd = m_fd; - fd.events = ZMQ_POLLIN; - fd.revents = 0; - fd.socket = NULL; -} - -//------------------------------------------------------------------------------ -// handleEvent -//------------------------------------------------------------------------------ -bool castor::tape::rmc::ConnectionHandler::handleEvent(const zmq_pollitem_t &fd) { - log::Param params[] = { - log::Param("fd", fd.fd), - log::Param("ZMQ_POLLIN", fd.revents & ZMQ_POLLIN ? "true" : "false"), - log::Param("ZMQ_POLLOUT", fd.revents & ZMQ_POLLOUT ? "true" : "false"), - log::Param("ZMQ_POLLERR", fd.revents & ZMQ_POLLERR ? "true" : "false")}; - m_log(LOG_DEBUG, "I/O event on rmc connection", params); - - checkHandleEventFd(fd.fd); - - if(!connectionIsAuthorized()) { - return true; // Ask reactor to remove and delete this handler - } - - return true; // Ask reactor to remove and delete this handler -} - -//------------------------------------------------------------------------------ -// checkHandleEventFd -//------------------------------------------------------------------------------ -void castor::tape::rmc::ConnectionHandler::checkHandleEventFd(const int fd) { - if(m_fd != fd) { - castor::exception::Exception ex; - ex.getMessage() << "Failed to handle client connection" - ": Event handler passed wrong file descriptor" - ": expected=" << m_fd << " actual=" << fd; - throw ex; - } -} - -//------------------------------------------------------------------------------ -// connectionIsAuthorized -//------------------------------------------------------------------------------ -bool castor::tape::rmc::ConnectionHandler::connectionIsAuthorized() throw() { -/* - if (Cupv_check (uid, gid, rqst_context->clienthost, - rqst_context->localhost, P_TAPE_SYSTEM)) { - rmc_sendrep (rqst_context->rpfd, MSG_ERR, "%s\n", - sstrerror(serrno)); - rmc_logit (func, "returns %d\n", ERMCUNREC); - return ERMCUNREC; - } -*/ - return true; // Client is authorized -} diff --git a/castor/tape/rmc/ConnectionHandler.hpp b/castor/tape/rmc/ConnectionHandler.hpp deleted file mode 100644 index a1689a797c6bddbefe7e373e113f4722dac0f307..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/ConnectionHandler.hpp +++ /dev/null @@ -1,117 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/io/io.hpp" -#include "castor/legacymsg/CommonMarshal.hpp" -#include "castor/legacymsg/MessageHeader.hpp" -#include "castor/log/Logger.hpp" -#include "castor/tape/reactor/PollEventHandler.hpp" -#include "castor/tape/reactor/ZMQReactor.hpp" - -namespace castor { -namespace tape { -namespace rmc { - -/** - * Handles the events of a client connection. - */ -class ConnectionHandler: public reactor::ZMQPollEventHandler { -public: - - /** - * Constructor. - * - * @param fd The file descriptor of the client connection. - * @param reactor The reactor with which this event handler is registered. - * @param log The object representing the API of the CASTOR logging system. - */ - ConnectionHandler( - const int fd, - reactor::ZMQReactor &reactor, - log::Logger &log) throw(); - - /** - * Returns the human-readable name this event handler. - */ - std::string getName() const throw(); - - /** - * Fills the specified poll file-descriptor ready to be used in a call to - * poll(). - */ - void fillPollFd(zmq_pollitem_t &fd) throw(); - - /** - * Handles the specified event. - * - * @param fd The poll file-descriptor describing the event. - */ - bool handleEvent(const zmq_pollitem_t &fd) ; - - /** - * Destructor. - * - * Closes the connection with the client. - */ - ~ConnectionHandler() throw(); - -private: - - /** - * The file descriptor of the connection with the client. - */ - const int m_fd; - - /** - * The reactor with which this event handler is registered. - */ - reactor::ZMQReactor &m_reactor; - - /** - * The object representing the API of the CASTOR logging system. - */ - log::Logger &m_log; - - /** - * The timeout in seconds to be applied when performing network read and - * write operations. - */ - const int m_netTimeout; - - /** - * Throws an exception if the specified file-descriptor is not that of the - * connection with the client. - */ - void checkHandleEventFd(const int fd) ; - - /** - * Returns true if the peer host of the connection being handled is - * authorized. - */ - bool connectionIsAuthorized() throw(); - -}; // class ConnectionHandler - -} // namespace rmc -} // namespace tape -} // namespace castor diff --git a/castor/tape/rmc/MockAcs.hpp b/castor/tape/rmc/MockAcs.hpp deleted file mode 100644 index 2a950a29fc33d961632350beaf49b4d738fe636c..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/MockAcs.hpp +++ /dev/null @@ -1,132 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/tape/rmc/AcsCmd.hpp" - -namespace castor { -namespace tape { -namespace rmc { - -class MockAcs: public Acs { -public: - - /** - * Destructor. - */ - ~MockAcs() throw() { - } - - /** - * C++ wrapper around the acs_mount() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param lockId Lock identifier or 0 meaning no lock. - * @param volId The identifier of the volume to be mounted. - * @param driveId The ID of the drive into which the volume is to be mounted. - * @param readOnly Set to true to request the volume be mounted for read-only - * access. - * @param bypass Set to true to override the ACSLS verification of - * compatibility between the drive and the media type of the volume. - * @return status value returned by acs_mount(). - */ - STATUS mount( - const SEQ_NO seqNumber, - const LOCKID lockId, - const VOLID &volId, - const DRIVEID &driveId, - const BOOLEAN readOnly, - const BOOLEAN bypass) - throw() { - return STATUS_SUCCESS; - } - - /** - * C++ wrapper around the acs_dismount() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param lockId Lock identifier or 0 meaning no lock. - * @param volId The identifier of the volume to be mounted. - * @param driveId The ID of the drive into which the volume is to be mounted. - * @param force Set to true if the dismount should be forced. Forcing a - * dismount means dismounting the volume from the specified drive without - * checking the identifier of the volume. - * @return status value returned by acs_dismount(). - */ - STATUS dismount( - const SEQ_NO seqNumber, - const LOCKID lockId, - const VOLID &volId, - const DRIVEID &driveId, - const BOOLEAN force) - throw() { - return STATUS_SUCCESS; - } - - /** - * C++ wrapper around the acs_response() function of the ACSLS C-API. - * - * @param timeout Time in seconds to wait for a response. A value of -1 - * means block indefinitely and an a value of 0 means poll for the existence - * of a response. - * @param seqNumber Output parameter. If a response exists then seqNumber - * is set. - * @param reqId Output parameter. For an acknowledge response reqId is set - * to the request identifier of the original request. For an intermediate or - * final response reqId will be set to 0. - * @param rType Output parameter. Set to the type of the response. - * @param rBuf Output parameter. Set to the response information. - * @return status value returned by acs_response(). - */ - STATUS response( - const int timeout, - SEQ_NO &seqNumber, - REQ_ID &reqId, - ACS_RESPONSE_TYPE &rType, - ALIGNED_BYTES rBuf) throw() { - return STATUS_SUCCESS; - } - - /** - * C++ wrapper around the acs_query_volume() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param volIds Array of the volume identifiers to be queried. - * @param count The number of volume identifiers contained iwthin the volId - * parameter. - * @return status value returned by acs_response(). - */ - STATUS queryVolume( - const SEQ_NO seqNumber, - VOLID (&volIds)[MAX_ID], - const unsigned short count) throw() { - return STATUS_SUCCESS; - } - -}; // class MockAcs - -} // namespace rmc -} // namespace tape -} // namespace castor - diff --git a/castor/tape/rmc/MountCmd.cpp b/castor/tape/rmc/MountCmd.cpp deleted file mode 100644 index a2c32966ca31b5e0ec6edcb47d6bdebaaab93d51..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/MountCmd.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/MountCmd.hpp" -#include "castor/tape/utils/utils.hpp" -#include "h/rmc_api.h" -#include "h/serrno.h" - -#include <getopt.h> -#include <iostream> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::tape::rmc::MountCmd::MountCmd(std::istream &inStream, - std::ostream &outStream, std::ostream &errStream) throw(): - Cmd(inStream, outStream, errStream), m_defaultTimeout(600) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -castor::tape::rmc::MountCmd::~MountCmd() throw() { - // Do nothing -} - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int castor::tape::rmc::MountCmd::main(const int argc, - char *const *const argv) throw() { - try { - m_cmdLine = parseCmdLine(argc, argv); - } catch(castor::exception::InvalidArgument &ia) { - m_err << "Aborting: Invalid command-line: " << ia.getMessage().str() << - std::endl; - m_err << std::endl; - usage(m_err); - return 1; - } catch(castor::exception::MissingOperand &mo) { - m_err << "Aborting: Missing operand: " << mo.getMessage().str() << - std::endl; - m_err << std::endl; - usage(m_err); - return 1; - } catch(castor::exception::Exception &ie) { - m_err << "Aborting: Internal error: " << ie.getMessage().str() << - std::endl; - return 1; - } - - // Display the usage message to standard out and exit with success if the - // user requested help - if(m_cmdLine.help) { - usage(m_out); - return 0; - } - - // Setup debug mode to be on or off depending on the command-line arguments - m_debugBuf.setDebug(m_cmdLine.debug); - - m_dbg << "readonly = " << bool2Str(m_cmdLine.readOnly) << std::endl; - m_dbg << "timeout = " << m_cmdLine.timeout << std::endl; - m_dbg << "VID = " << m_cmdLine.volId << std::endl; - m_dbg << "DRIVE = " << m_cmdLine.driveId << std::endl; - - const int rmc_mnt_rc = rmc_mnt(m_cmdLine.volId.c_str(), - m_cmdLine.driveId.c_str()); - const int rmc_mnt_serrno = serrno; - switch(rmc_mnt_rc) { - case 1: - m_out << - "You have requested a manual mount. The castor-tape-mount command\n" - " does nothing for this type of mount." << std::endl; - return 0; - case 0: - m_out << m_cmdLine.volId << " has been mounted" << std::endl; - return 0; - case -1: - m_err << "Failed to mount " << m_cmdLine.volId << ": " << - sstrerror(rmc_mnt_serrno) << std::endl; - return -1; - default: - m_err << "Internal error: rmc_mnt() returned the unexpected value of " << - rmc_mnt_rc << std::endl; - return -1; - } -} - -//------------------------------------------------------------------------------ -// parseCmdLine -//------------------------------------------------------------------------------ -castor::tape::rmc::MountCmdLine castor::tape::rmc::MountCmd::parseCmdLine( - const int argc, char *const *const argv) - throw(castor::exception::Exception, castor::exception::InvalidArgument, - castor::exception::MissingOperand) { - - static struct option longopts[] = { - {"debug", 0, NULL, 'd'}, - {"help" , 0, NULL, 'h'}, - {"readonly", 0, NULL, 'r'}, - {"timeout", required_argument, NULL, 't'}, - {NULL, 0, NULL, 0} - }; - MountCmdLine cmdLine; - char c; - - // Set timeout option to the default value - cmdLine.timeout = m_defaultTimeout; - - // Prevent getopt() from printing an error message if it does not recognize - // an option character - opterr = 0; - while((c = getopt_long(argc, argv, ":dhrt:", longopts, NULL)) != -1) { - - switch (c) { - case 'd': - cmdLine.debug = true; - break; - case 'h': - cmdLine.help = true; - break; - case 'r': - cmdLine.readOnly = true; - break; - case 't': - cmdLine.timeout = atoi(optarg); - if(0 >= cmdLine.timeout) { - castor::exception::InvalidArgument ex; - ex.getMessage() << "Timeout value must be an integer greater than 0" - ": value=" << cmdLine.timeout; - throw ex; - } - break; - case ':': - { - castor::exception::InvalidArgument ex; - ex.getMessage() << "The -" << (char)optopt - << " option requires a parameter"; - throw ex; - } - break; - case '?': - { - castor::exception::InvalidArgument ex; - - if(optopt == 0) { - ex.getMessage() << "Unknown command-line option"; - } else { - ex.getMessage() << "Unknown command-line option: -" << (char)optopt; - } - throw ex; - } - break; - default: - { - castor::exception::Exception ex; - ex.getMessage() << - "getopt_long returned the following unknown value: 0x" << - std::hex << (int)c; - throw ex; - } - } // switch (c) - } // while ((c = getopt_long( ... )) != -1) - - // There is no need to continue parsing when the help option is set - if(cmdLine.help) { - return cmdLine; - } - - // Calculate the number of non-option ARGV-elements - const int nbArgs = argc - optind; - - // Check that both VID and DRIVE has been specified - if(nbArgs < 2) { - castor::exception::MissingOperand ex; - ex.getMessage() << "Both VID and DRIVE must be specified"; - throw ex; - } - - // Parse the VID command-line argument - cmdLine.volId = argv[optind]; - - // Move on to the next command-line argument - optind++; - - // Parse the DRIVE command-line argument - cmdLine.driveId = argv[optind]; - - return cmdLine; -} - -//------------------------------------------------------------------------------ -// usage -//------------------------------------------------------------------------------ -void castor::tape::rmc::MountCmd::usage(std::ostream &os) - const throw() { - os << - "Usage:\n" - "\n" - " castor-tape-mount [options] VID DRIVE\n" - "\n" - "Where:\n" - "\n" - " VID The indentifier of the volume to be mounted.\n" - "\n" - " DRIVE The drive in one of the following three forms corresponding to the\n" - " three supported drive-loader types, namely acs, manual and smc:\n" - "\n" - " smc@rmc_host,drive_ordinal\n" - "\n" - " manual\n" - "\n" - " acsACS,LSM,panel,transport\n" - "\n" - "Options:\n" - "\n" - " -d|--debug Turn on the printing of debug information.\n" - "\n" - " -h|--help Print this help message and exit.\n" - "\n" - " -r|--readOnly Request the volume is mounted for read-only access\n" - "\n" - " -t|--timeout SECONDS Time to wait for the mount to conclude. SECONDS\n" - " must be an integer value greater than 0. The\n" - " default value of SECONDS is " - << m_defaultTimeout << ".\n" - "\n" - "Comments to: Castor.Support@cern.ch" << std::endl; -} diff --git a/castor/tape/rmc/MountCmd.hpp b/castor/tape/rmc/MountCmd.hpp deleted file mode 100644 index e31aac2faea92eac017e3dd58391951ea903e1ca..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/MountCmd.hpp +++ /dev/null @@ -1,107 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/exception/InvalidArgument.hpp" -#include "castor/exception/MissingOperand.hpp" -#include "castor/tape/rmc/Cmd.hpp" -#include "castor/tape/rmc/MountCmdLine.hpp" - -#include <stdint.h> - -namespace castor { -namespace tape { -namespace rmc { - -/** - * The class implementing the mount command. - */ -class MountCmd: public Cmd { -public: - - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - */ - MountCmd(std::istream &inStream, std::ostream &outStream, - std::ostream &errStream) throw(); - - /** - * Destructor. - */ - virtual ~MountCmd() throw(); - - /** - * The entry function of the command. - * - * @param argc The number of command-line arguments. - * @param argv The command-line arguments. - */ - int main(const int argc, char *const *const argv) throw(); - -protected: - - /** - * Parses the specified command-line arguments. - * - * @param argc Argument count from the executable's entry function: main(). - * @param argv Argument vector from the executable's entry function: main(). - * @return The parsed command-line. - */ - MountCmdLine parseCmdLine(const int argc, char *const *const argv) - throw(castor::exception::Exception, castor::exception::InvalidArgument, - castor::exception::MissingOperand); - - /** - * Writes the command-line usage message of to the specified output stream. - * - * @param os Output stream to be written to. - */ - void usage(std::ostream &os) const throw(); - -private: - - /** - * The parsed command-line. - * - * The value of this member variable is set within the main() method of this - * class. - */ - MountCmdLine m_cmdLine; - - /** - * The default timeout value in seconds for the mount to conclude either - * success or failure. - */ - const int m_defaultTimeout; - -}; // class MountCmd - -} // namespace rmc -} // namespace tape -} // namespace castor - diff --git a/castor/tape/rmc/MountCmdLine.cpp b/castor/tape/rmc/MountCmdLine.cpp deleted file mode 100644 index eb8be7c033438444f0d360918401f034e4bc04a1..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/MountCmdLine.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/MountCmdLine.hpp" - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -castor::tape::rmc::MountCmdLine::MountCmdLine() throw(): - debug(false), - help(false), - readOnly(false), - timeout(0) { -} diff --git a/castor/tape/rmc/MountCmdLine.hpp b/castor/tape/rmc/MountCmdLine.hpp deleted file mode 100644 index 744587fb1f4f6bf8527b72ee9e6d122544c90f2a..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/MountCmdLine.hpp +++ /dev/null @@ -1,80 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include <string> - -namespace castor { -namespace tape { -namespace rmc { - -/** - * Data type used to store the results of parsing the command-line. - */ -struct MountCmdLine { - /** - * Constructor. - * - * Initialises all bool member-variables to false, all integer - * member-variables to 0 and the volume identifier to an empty string. - */ - MountCmdLine() throw(); - - /** - * True if the debug option has been set. - */ - bool debug; - - /** - * True if the help option has been set. - */ - bool help; - - /** - * True if the tape is to be mount for read-only access. - */ - bool readOnly; - - /** - * Time in seconds to wait for the mount to conclude. - */ - int timeout; - - /** - * The volume identifier of the tape to be mounted. - */ - std::string volId; - - /** - * The identifier of the drive into which the tape is to be mounted. - */ - std::string driveId; - -}; // class MountCmdLine - -} // namespace rmc -} // namespace tape -} // namespace castor - - diff --git a/castor/tape/rmc/MountMain.cpp b/castor/tape/rmc/MountMain.cpp deleted file mode 100644 index 0cb72d477238388d3c056ed2102fca9a20160617..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/MountMain.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/tape/rmc/MountCmd.hpp" - -#include <iostream> - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int main(const int argc, char *const *const argv) { - - castor::tape::rmc::MountCmd cmd(std::cin, std::cout, std::cerr); - - return cmd.main(argc, argv); -} diff --git a/castor/tape/rmc/RmcDaemon.cpp b/castor/tape/rmc/RmcDaemon.cpp deleted file mode 100644 index 0e2285faf5afc4173b05cfb72b5ca165db359fa0..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/RmcDaemon.cpp +++ /dev/null @@ -1,442 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/common/CastorConfiguration.hpp" -#include "castor/exception/Errnum.hpp" -#include "castor/exception/BadAlloc.hpp" -#include "castor/io/io.hpp" -#include "castor/tape/rmc/AcceptHandler.hpp" -#include "castor/tape/rmc/RmcDaemon.hpp" -#include "castor/tape/utils/utils.hpp" -#include "castor/utils/SmartFd.hpp" -#include "castor/utils/utils.hpp" -#include "h/rmc_constants.h" - -#include <algorithm> -#include <limits.h> -#include <memory> -#include <poll.h> -#include <signal.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <unistd.h> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::tape::rmc::RmcDaemon::RmcDaemon::RmcDaemon( - std::ostream &stdOut, - std::ostream &stdErr, - log::Logger &log, - reactor::ZMQReactor &reactor, - legacymsg::CupvProxy &cupv) : - castor::server::Daemon(stdOut, stdErr, log), - m_reactor(reactor), - m_cupv(cupv), - m_programName("rmcd"), - m_hostName(getHostName()), - m_rmcPort(getRmcPort()) { -} - -//------------------------------------------------------------------------------ -// getHostName -//------------------------------------------------------------------------------ -std::string castor::tape::rmc::RmcDaemon::RmcDaemon::getHostName() - const { - char nameBuf[81]; - if(gethostname(nameBuf, sizeof(nameBuf))) { - char errBuf[100]; - sstrerror_r(errno, errBuf, sizeof(errBuf)); - castor::exception::Exception ex; - ex.getMessage() << "Failed to get host name: " << errBuf; - throw ex; - } - - return nameBuf; -} - -//------------------------------------------------------------------------------ -// getRmcPort -//------------------------------------------------------------------------------ -unsigned short castor::tape::rmc::RmcDaemon::getRmcPort() - { - std::string configParamValue; - - // If RMC PORT is not in /etc/castor.conf then use the compile time default - try { - const std::string category = "RMC"; - const std::string name = "PORT"; - configParamValue = getConfigParam(category, name); - } catch(castor::exception::Exception &ex) { - return RMC_PORT; - } - - // If RMC PORT is in /etc/castor.conf then it must be a valid unsigned integer - if(!castor::utils::isValidUInt(configParamValue.c_str())) { - castor::exception::Exception ex; - ex.getMessage() << "RMC PORT is not a valid unsigned integer"; - throw ex; - } - - return atoi(configParamValue.c_str()); -} - -//------------------------------------------------------------------------------ -// getConfigParam -//------------------------------------------------------------------------------ -std::string castor::tape::rmc::RmcDaemon::getConfigParam( - const std::string &category, - const std::string &name) - { - std::ostringstream task; - task << "get " << category << ":" << name << " from castor.conf"; - - common::CastorConfiguration config; - std::string value; - - try { - config = common::CastorConfiguration::getConfig(); - } catch(castor::exception::Exception &ne) { - castor::exception::Exception ex; - ex.getMessage() << "Failed to " << task.str() << - ": Failed to get castor configuration: " << ne.getMessage().str(); - throw ex; - } - - try { - value = config.getConfEntString(category.c_str(), name.c_str()); - } catch(castor::exception::Exception &ne) { - castor::exception::Exception ex; - ex.getMessage() << "Failed to " << task.str() << - ": Failed to get castor configuration entry: " << ne.getMessage().str(); - throw ex; - } - - return value; -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -castor::tape::rmc::RmcDaemon::~RmcDaemon() throw() { -} - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int castor::tape::rmc::RmcDaemon::main(const int argc, char **const argv) throw() { - try { - - exceptionThrowingMain(argc, argv); - - } catch (castor::exception::Exception &ex) { - std::ostringstream msg; - msg << "Aborting: Caught an unexpected exception: " << - ex.getMessage().str(); - m_stdErr << std::endl << msg.str() << std::endl << std::endl; - - log::Param params[] = { - log::Param("Message", msg.str()), - log::Param("Code" , ex.code())}; - m_log(LOG_ERR, msg.str(), params); - - return 1; - } - - return 0; -} - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ -void castor::tape::rmc::RmcDaemon::exceptionThrowingMain( - const int argc, char **const argv) { - logStartOfDaemon(argc, argv); - parseCommandLine(argc, argv); - const bool runAsStagerSuperuser = false; - daemonizeIfNotRunInForeground(runAsStagerSuperuser); - blockSignals(); - setUpReactor(); - mainEventLoop(); -} - -//------------------------------------------------------------------------------ -// logStartOfDaemon -//------------------------------------------------------------------------------ -void castor::tape::rmc::RmcDaemon::logStartOfDaemon( - const int argc, const char *const *const argv) throw() { - const std::string concatenatedArgs = argvToString(argc, argv); - std::ostringstream msg; - msg << m_programName << " started"; - - log::Param params[] = { - log::Param("argv", concatenatedArgs)}; - m_log(LOG_INFO, msg.str(), params); -} - -//------------------------------------------------------------------------------ -// argvToString -//------------------------------------------------------------------------------ -std::string castor::tape::rmc::RmcDaemon::argvToString( - const int argc, const char *const *const argv) throw() { - std::string str; - - for(int i=0; i < argc; i++) { - if(i != 0) { - str += " "; - } - - str += argv[i]; - } - return str; -} - -//------------------------------------------------------------------------------ -// blockSignals -//------------------------------------------------------------------------------ -void castor::tape::rmc::RmcDaemon::blockSignals() const - { - sigset_t sigs; - sigemptyset(&sigs); - // The signals that should not asynchronously disturb the daemon - sigaddset(&sigs, SIGHUP); - sigaddset(&sigs, SIGINT); - sigaddset(&sigs, SIGQUIT); - sigaddset(&sigs, SIGPIPE); - sigaddset(&sigs, SIGTERM); - sigaddset(&sigs, SIGUSR1); - sigaddset(&sigs, SIGUSR2); - sigaddset(&sigs, SIGCHLD); - sigaddset(&sigs, SIGTSTP); - sigaddset(&sigs, SIGTTIN); - sigaddset(&sigs, SIGTTOU); - sigaddset(&sigs, SIGPOLL); - sigaddset(&sigs, SIGURG); - sigaddset(&sigs, SIGVTALRM); - castor::exception::Errnum::throwOnNonZero( - sigprocmask(SIG_BLOCK, &sigs, NULL), - "Failed to block signals: sigprocmask() failed"); -} - -//------------------------------------------------------------------------------ -// setUpReactor -//------------------------------------------------------------------------------ -void castor::tape::rmc::RmcDaemon::setUpReactor() - { - createAndRegisterAcceptHandler(); -} - -//------------------------------------------------------------------------------ -// createAndRegisterAcceptHandler -//------------------------------------------------------------------------------ -void castor::tape::rmc::RmcDaemon::createAndRegisterAcceptHandler() { - castor::utils::SmartFd listenSock; - try { - listenSock.reset(io::createListenerSock(m_rmcPort)); - } catch(castor::exception::Exception &ne) { - castor::exception::Exception ex(ne.code()); - ex.getMessage() << "Failed to create socket to listen for client connections" - ": " << ne.getMessage().str(); - throw ex; - } - { - log::Param params[] = { - log::Param("listeningPort", m_rmcPort)}; - m_log(LOG_INFO, "Listening for client connections", params); - } - - std::auto_ptr<AcceptHandler> acceptHandler; - try { - acceptHandler.reset(new AcceptHandler(listenSock.get(), m_reactor, m_log)); - listenSock.release(); - } catch(std::bad_alloc &ba) { - castor::exception::BadAlloc ex; - ex.getMessage() << - "Failed to create the event handler for accepting client connections" - ": " << ba.what(); - throw ex; - } - m_reactor.registerHandler(acceptHandler.get()); - acceptHandler.release(); -} - -//------------------------------------------------------------------------------ -// mainEventLoop -//------------------------------------------------------------------------------ -void castor::tape::rmc::RmcDaemon::mainEventLoop() - { - while(handleEvents()) { - forkChildProcesses(); - } -} - -//------------------------------------------------------------------------------ -// handleEvents -//------------------------------------------------------------------------------ -bool castor::tape::rmc::RmcDaemon::handleEvents() - { - const int timeout = 100; // 100 milliseconds - m_reactor.handleEvents(timeout); - return handlePendingSignals(); -} - -//------------------------------------------------------------------------------ -// handlePendingSignals -//------------------------------------------------------------------------------ -bool castor::tape::rmc::RmcDaemon::handlePendingSignals() - throw() { - bool continueMainEventLoop = true; - int sig = 0; - sigset_t allSignals; - siginfo_t sigInfo; - sigfillset(&allSignals); - struct timespec immedTimeout = {0, 0}; - - // While there is a pending signal to be handled - while (0 < (sig = sigtimedwait(&allSignals, &sigInfo, &immedTimeout))) { - switch(sig) { - case SIGINT: // Signal number 2 - m_log(LOG_INFO, "Stopping gracefully because SIGINT was received"); - continueMainEventLoop = false; - break; - case SIGTERM: // Signal number 15 - m_log(LOG_INFO, "Stopping gracefully because SIGTERM was received"); - continueMainEventLoop = false; - break; - case SIGCHLD: // Signal number 17 - reapZombies(); - break; - default: - { - log::Param params[] = {log::Param("signal", sig)}; - m_log(LOG_INFO, "Ignoring signal", params); - } - break; - } - } - - return continueMainEventLoop; -} - -//------------------------------------------------------------------------------ -// reapZombies -//------------------------------------------------------------------------------ -void castor::tape::rmc::RmcDaemon::reapZombies() throw() { - pid_t childPid = 0; - int waitpidStat = 0; - - while (0 < (childPid = waitpid(-1, &waitpidStat, WNOHANG))) { - reapZombie(childPid, waitpidStat); - } -} - -//------------------------------------------------------------------------------ -// reapZombie -//------------------------------------------------------------------------------ -void castor::tape::rmc::RmcDaemon::reapZombie(const pid_t childPid, const int waitpidStat) throw() { - logChildProcessTerminated(childPid, waitpidStat); -} - -//------------------------------------------------------------------------------ -// logChildProcessTerminated -//------------------------------------------------------------------------------ -void castor::tape::rmc::RmcDaemon::logChildProcessTerminated(const pid_t childPid, const int waitpidStat) throw() { - std::list<log::Param> params; - params.push_back(log::Param("childPid", childPid)); - - if(WIFEXITED(waitpidStat)) { - params.push_back(log::Param("WEXITSTATUS", WEXITSTATUS(waitpidStat))); - } - - if(WIFSIGNALED(waitpidStat)) { - params.push_back(log::Param("WTERMSIG", WTERMSIG(waitpidStat))); - } - - if(WCOREDUMP(waitpidStat)) { - params.push_back(log::Param("WCOREDUMP", "true")); - } else { - params.push_back(log::Param("WCOREDUMP", "false")); - } - - if(WIFSTOPPED(waitpidStat)) { - params.push_back(log::Param("WSTOPSIG", WSTOPSIG(waitpidStat))); - } - - if(WIFCONTINUED(waitpidStat)) { - params.push_back(log::Param("WIFCONTINUED", "true")); - } else { - params.push_back(log::Param("WIFCONTINUED", "false")); - } - - m_log(LOG_INFO, "Child-process terminated", params); -} - -//------------------------------------------------------------------------------ -// forkChildProcesses -//------------------------------------------------------------------------------ -void castor::tape::rmc::RmcDaemon::forkChildProcesses() throw() { -/* - const std::list<std::string> unitNames = - m_driveCatalogue.getUnitNames(DriveCatalogue::DRIVE_STATE_WAITFORK); - - for(std::list<std::string>::const_iterator itor = unitNames.begin(); - itor != unitNames.end(); itor++) { - forkChildProcess(*itor); - } -*/ -} - -//------------------------------------------------------------------------------ -// forkChildProcess -//------------------------------------------------------------------------------ -void castor::tape::rmc::RmcDaemon::forkChildProcess() throw() { -/* - m_log.prepareForFork(); - const pid_t childPid = fork(); - - // If fork failed - if(0 > childPid) { - // Log an error message and return - char errBuf[100]; - sstrerror_r(errno, errBuf, sizeof(errBuf)); - log::Param params[] = {log::Param("message", errBuf)}; - m_log(LOG_ERR, "Failed to fork mount session for tape drive", params); - - // Else if this is the parent process - } else if(0 < childPid) { - m_driveCatalogue.forkedDataTransferSession(unitName, childPid); - - // Else this is the child process - } else { - // Clear the reactor which in turn will close all of the open - // file-descriptors owned by the event handlers - m_reactor.clear(); - - runDataTransferSession(unitName); - - // The runDataTransferSession() should call exit() and should therefore never - // return - m_log(LOG_ERR, "runDataTransferSession() returned unexpectedly"); - } -*/ -} diff --git a/castor/tape/rmc/RmcDaemon.hpp b/castor/tape/rmc/RmcDaemon.hpp deleted file mode 100644 index 130d72ba101933d7c9270943be6f2a55af07d646..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/RmcDaemon.hpp +++ /dev/null @@ -1,219 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/exception/Exception.hpp" -#include "castor/legacymsg/CupvProxy.hpp" -#include "castor/server/Daemon.hpp" -#include "castor/tape/reactor/ZMQReactor.hpp" - -#include <string> - -namespace castor { -namespace tape { -namespace rmc { - -/** - * Daemon responsible for mounting and unmount tapes. - */ -class RmcDaemon : public castor::server::Daemon { - -public: - - /** - * Constructor. - * - * @param stdOut Stream representing standard out. - * @param stdErr Stream representing standard error. - * @param log The object representing the API of the CASTOR logging system. - * @param reactor The reactor responsible for dispatching the I/O events of - * the parent process of the rmcd daemon. - * @param cupv Proxy object representing the cupvd daemon. - */ - RmcDaemon( - std::ostream &stdOut, - std::ostream &stdErr, - log::Logger &log, - reactor::ZMQReactor &reactor, - legacymsg::CupvProxy &cupv) ; - - /** - * Destructor. - */ - ~RmcDaemon() throw(); - - /** - * The main entry function of the daemon. - * - * @param argc The number of command-line arguments. - * @param argv The array of command-line arguments. - * @return The return code of the process. - */ - int main(const int argc, char **const argv) throw(); - -protected: - - /** - * Returns the name of the host on which the daemon is running. - */ - std::string getHostName() const ; - - /** - * Determines and returns the TCP/IP port onwhich the rmcd daemon should - * listen for client connections. - */ - unsigned short getRmcPort() ; - - /** - * Tries to get the value of the specified parameter from parsing - * /etc/castor/castor.conf. - * - * @param category The category of the configuration parameter. - * @param name The name of the configuration parameter. - */ - std::string getConfigParam(const std::string &category, const std::string &name) ; - - /** - * Exception throwing main() function. - * - * @param argc The number of command-line arguments. - * @param argv The array of command-line arguments. - */ - void exceptionThrowingMain(const int argc, char **const argv) - ; - - /** - * Logs the start of the daemon. - */ - void logStartOfDaemon(const int argc, const char *const *const argv) throw(); - - /** - * Creates a string that contains the specified command-line arguments - * separated by single spaces. - * - * @param argc The number of command-line arguments. - * @param argv The array of command-line arguments. - */ - std::string argvToString(const int argc, const char *const *const argv) - throw(); - - /** - * Blocks the signals that should not asynchronously disturb the daemon. - */ - void blockSignals() const ; - - /** - * Sets up the reactor. - */ - void setUpReactor() ; - - /** - * Creates the handler to accept client connections and registers it with - * the reactor. - */ - void createAndRegisterAcceptHandler() ; - - /** - * The main event loop of the daemon. - */ - void mainEventLoop() ; - - /** - * Handles any pending events. - * - * @return True if the main event loop should continue, else false. - */ - bool handleEvents() ; - - /** - * Handles any pending signals. - * - * @return True if the main event loop should continue, else false. - */ - bool handlePendingSignals() throw(); - - /** - * Reaps any zombie processes. - */ - void reapZombies() throw(); - - /** - * Reaps the specified zombie process. - * - * @param childPid The process ID of the zombie child-process. - * @param waitpidStat The status information given by a call to waitpid(). - */ - void reapZombie(const pid_t childPid, const int waitpidStat) throw(); - - /** - * Logs the fact that the specified child-process has terminated. - * - * @param childPid The process ID of the child-process. - * @param waitpidStat The status information given by a call to waitpid(). - */ - void logChildProcessTerminated(const pid_t childPid, const int waitpidStat) throw(); - - /** - * Forks a child-process for every pending tape mount/unmount request - * handled by the previous call to m_reactor.handleEvebts(). - */ - void forkChildProcesses() throw(); - - /** - * Forks a child-process to mount/unmount a tape. - */ - void forkChildProcess() throw(); - - /** - * The reactor responsible for dispatching the file-descriptor event-handlers - * of the rmcd daemon. - */ - reactor::ZMQReactor &m_reactor; - - /** - * Proxy object representing the cupvd daemon. - */ - legacymsg::CupvProxy &m_cupv; - - /** - * The program name of the tape daemon. - */ - const std::string m_programName; - - /** - * The name of the host on which the daemon is running. - */ - const std::string m_hostName; - - /** - * The TCP/IP port on which the rmcd daemon listens for client connections. - */ - const unsigned short m_rmcPort; - -}; // class RmcDaemon - -} // namespace rmc -} // namespace tape -} // namespace castor - diff --git a/castor/tape/rmc/RmcDaemonMain.cpp b/castor/tape/rmc/RmcDaemonMain.cpp deleted file mode 100644 index eb163be8d9380f46294badb21e33003211e28f96..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/RmcDaemonMain.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/common/CastorConfiguration.hpp" -#include "castor/legacymsg/CupvProxyTcpIp.hpp" -#include "castor/log/SyslogLogger.hpp" -#include "castor/tape/reactor/ZMQReactor.hpp" -#include "castor/tape/rmc/RmcDaemon.hpp" -#include "h/Cupv_constants.h" - -#include <iostream> - -//------------------------------------------------------------------------------ -// getConfigParam -// -// Tries to get the value of the specified parameter from parsing -// /etc/castor/castor.conf. -//------------------------------------------------------------------------------ -static std::string getConfigParam(const std::string &category, const std::string &name); - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -// -// The main() function delegates the bulk of its implementation to this -// exception throwing version. -// -// @param argc The number of command-line arguments. -// @param argv The command-line arguments. -// @param log The logging system. -// @param zmqContext The ZMQ context. -//------------------------------------------------------------------------------ -static int exceptionThrowingMain(const int argc, char **const argv, - castor::log::Logger &log, void *const zmqContext); - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int main(const int argc, char **const argv) { - // Try to instantiate the logging system API - castor::log::Logger *logPtr = NULL; - try { - logPtr = new castor::log::SyslogLogger("rmcd"); - } catch(castor::exception::Exception &ex) { - std::cerr << "Failed to instantiate object representing CASTOR logging system" - ": " << ex.getMessage().str() << std::endl; - return 1; - } - castor::log::Logger &log = *logPtr; - - // Try to instantiate a ZMQ context - const int sizeOfIOThreadPoolForZMQ = 1; - void *const zmqContext = zmq_init(sizeOfIOThreadPoolForZMQ); - if(NULL == zmqContext) { - char message[100]; - sstrerror_r(errno, message, sizeof(message)); - castor::log::Param params[] = {castor::log::Param("message", message)}; - log(LOG_ERR, "Failed to instantiate ZMQ context", params); - return 1; - } - - int programRc = 1; // Be pessimistic - try { - programRc = exceptionThrowingMain(argc, argv, log, zmqContext); - } catch(castor::exception::Exception &ex) { - castor::log::Param params[] = {castor::log::Param("message", ex.getMessage().str())}; - log(LOG_ERR, "Caught an unexpected CASTOR exception", params); - } catch(std::exception &se) { - castor::log::Param params[] = {castor::log::Param("what", se.what())}; - log(LOG_ERR, "Caught an unexpected standard exception", params); - } catch(...) { - log(LOG_ERR, "Caught an unexpected and unknown exception"); - } - - // Try to destroy the ZMQ context - if(zmq_term(zmqContext)) { - char message[100]; - sstrerror_r(errno, message, sizeof(message)); - castor::log::Param params[] = {castor::log::Param("message", message)}; - log(LOG_ERR, "Failed to destroy ZMQ context", params); - return 1; - } - - return programRc; -} - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ -static int exceptionThrowingMain(const int argc, char **const argv, - castor::log::Logger &log, void *const zmqContext) { - const std::string cupvHostName = getConfigParam("UPV", "HOST"); - castor::tape::reactor::ZMQReactor reactor(log); - const int netTimeout = 10; // Timeout in seconds - castor::legacymsg::CupvProxyTcpIp cupv(log, cupvHostName, CUPV_PORT, netTimeout); - castor::tape::rmc::RmcDaemon daemon(std::cout, std::cerr, log, reactor, cupv); - - return daemon.main(argc, argv); -} - -//------------------------------------------------------------------------------ -// getConfigParam -//------------------------------------------------------------------------------ -static std::string getConfigParam(const std::string &category, const std::string &name) { - using namespace castor; - - std::ostringstream task; - task << "get " << category << ":" << name << " from castor.conf"; - - common::CastorConfiguration config; - std::string value; - - try { - config = common::CastorConfiguration::getConfig(); - } catch(castor::exception::Exception &ne) { - castor::exception::Exception ex; - ex.getMessage() << "Failed to " << task.str() << - ": Failed to get castor configuration: " << ne.getMessage().str(); - throw ex; - } - - try { - value = config.getConfEntString(category.c_str(), name.c_str()); - } catch(castor::exception::Exception &ne) { - castor::exception::Exception ex; - ex.getMessage() << "Failed to " << task.str() << - ": Failed to get castor configuration entry: " << ne.getMessage().str(); - throw ex; - } - - return value; -} diff --git a/castor/tape/rmc/RmcDaemonTest.cpp b/castor/tape/rmc/RmcDaemonTest.cpp deleted file mode 100644 index 336c0184536e0f44f2df9d3e68a372ffe65ea656..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/RmcDaemonTest.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "castor/legacymsg/CupvProxyDummy.hpp" -#include "castor/log/DummyLogger.hpp" -#include "castor/tape/reactor/DummyPollReactor.hpp" -#include "castor/tape/rmc/RmcDaemon.hpp" - -#include <gtest/gtest.h> -#include <memory> -#include <sstream> - -namespace unitTest { - -class castor_tape_rmc_RmcDaemonTest : public ::testing::Test { -protected: - void *const m_zmqContext; - - castor_tape_rmc_RmcDaemonTest(): m_zmqContext(zmq_init(1)) { - } - - ~castor_tape_rmc_RmcDaemonTest() { - if(NULL != m_zmqContext) { - zmq_term(m_zmqContext); - } - } - - virtual void SetUp() { - } - - virtual void TearDown() { - } -}; // class castor_tape_rmc_RmcDaemonTest - -TEST_F(castor_tape_rmc_RmcDaemonTest, zmqContext) { - ASSERT_NE((void *const)0, m_zmqContext); -} - -TEST_F(castor_tape_rmc_RmcDaemonTest, constructor) { - using namespace castor::tape::rmc; - - std::ostringstream stdOut; - std::ostringstream stdErr; - castor::log::DummyLogger logger("unittest"); - castor::tape::reactor::ZMQReactor reactor(logger); - const bool isGrantedReturnValue = true; - castor::legacymsg::CupvProxyDummy cupv(isGrantedReturnValue); - - std::auto_ptr<RmcDaemon> daemon; - daemon.reset(new RmcDaemon(stdOut, stdErr, logger, reactor, cupv)); -} - -} // namespace unitTests diff --git a/castor/tape/rmc/TestingAcsDismountCmd.hpp b/castor/tape/rmc/TestingAcsDismountCmd.hpp deleted file mode 100644 index e17868411425488fb097a07a60589b2e9a8fbce7..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/TestingAcsDismountCmd.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/tape/rmc/AcsDismountCmd.hpp" - -namespace castor { -namespace tape { -namespace rmc { - -class TestingAcsDismountCmd: public AcsDismountCmd { -public: - - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - * @param acs Wrapper around the ACSLS C-API. - */ - TestingAcsDismountCmd(std::istream &inStream, std::ostream &outStream, - std::ostream &errStream, Acs &acs) throw(): - AcsDismountCmd(inStream, outStream, errStream, acs) { - } - - using AcsDismountCmd::parseCmdLine; - -}; // class TestingAcsDismountCmd - -} // namespace rmc -} // namespace tape -} // namespace castor - diff --git a/castor/tape/rmc/TestingAcsMountCmd.hpp b/castor/tape/rmc/TestingAcsMountCmd.hpp deleted file mode 100644 index 6d944732168d9df7cf9e6199ceb4bcd49efff88f..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/TestingAcsMountCmd.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/tape/rmc/AcsMountCmd.hpp" - -namespace castor { -namespace tape { -namespace rmc { - -class TestingAcsMountCmd: public AcsMountCmd { -public: - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - * @param acs Wrapper around the ACSLS C-API. - */ - TestingAcsMountCmd(std::istream &inStream, std::ostream &outStream, - std::ostream &errStream, Acs &acs) throw(): - AcsMountCmd(inStream, outStream, errStream, acs) { - } - - using AcsMountCmd::parseCmdLine; - -}; // class TestingAcsMountCmd - -} // namespace rmc -} // namespace tape -} // namespace castor - diff --git a/castor/tape/rmc/TestingAcsQueryVolumeCmd.hpp b/castor/tape/rmc/TestingAcsQueryVolumeCmd.hpp deleted file mode 100644 index 387cda1e31cb53eaf65e5cc2c8040c52b16066d7..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/TestingAcsQueryVolumeCmd.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#pragma once - -#include "castor/tape/rmc/AcsQueryVolumeCmd.hpp" - -namespace castor { -namespace tape { -namespace rmc { - -class TestingAcsQueryVolumeCmd: public AcsQueryVolumeCmd { -public: - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - * @param acs Wrapper around the ACSLS C-API. - */ - TestingAcsQueryVolumeCmd(std::istream &inStream, std::ostream &outStream, - std::ostream &errStream, Acs &acs) throw(): - AcsQueryVolumeCmd(inStream, outStream, errStream, acs) { - } - - using AcsQueryVolumeCmd::parseCmdLine; - -}; // class TestingAcsQueryVolumeCmd - -} // namespace rmc -} // namespace tape -} // namespace castor - diff --git a/castor/tape/rmc/castor-tape-acs-dismount.man b/castor/tape/rmc/castor-tape-acs-dismount.man deleted file mode 100644 index 6285c731c0bc811ac25f4e5b7d0fd75f1663bef3..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/castor-tape-acs-dismount.man +++ /dev/null @@ -1,56 +0,0 @@ -.\" Copyright (C) 2003 CERN -.\" This program is free software; you can redistribute it and/or -.\" modify it under the terms of the GNU General Public License -.\" as published by the Free Software Foundation; either version 2 -.\" of the License, or (at your option) any later version. -.\" This program is distributed in the hope that it will be useful, -.\" but WITHOUT ANY WARRANTY; without even the implied warranty of -.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -.\" GNU General Public License for more details. -.\" You should have received a copy of the GNU General Public License -.\" along with this program; if not, write to the Free Software -.\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -.TH CASTOR-TAPE-ACS-DISMOUNT "1castor" "$Date: 2013/10/09 14:00:00 $" CASTOR "CASTOR" -.SH NAME -castor-tape-acs-dismount \- dismount a volume -.SH SYNOPSIS -.BI "castor-tape-acs-dismount [options] VID DRIVE" - -.SH DESCRIPTION -.B castor-tape-acs-dismount -dismounts the volume with the specfied VID from the drive with the specified -DRIVE ID. The DRIVE ID format is: - -.B ACS:LSM:panel:transport - -.SH OPTIONS -.TP -\fB\-d, \-\-debug -Turns on the printing of debug information. -.TP -\fB\-f, \-\-force -Force the dismount. -.TP -\fB\-h, \-\-help -Prints the usage message. -.TP -\fB\-q, \-\-query SECONDS -Time wait between queries to ACLS for responses. -SECONDS must be an integer value greater than 0. -The default value of SECONDS is 10. -.TP -\fB\-t, \-\-timeout SECONDS -Time to wait for the dismount operation to conclude. -SECONDS must be an integer value greater than 0. -The default value of SECONDS is 600. - -.SH "RETURN CODES" -.TP -\fB 0 -Ok. -.TP -\fB 1 -Command failed. - -.SH AUTHOR -\fBCASTOR\fP Team <castor.support@cern.ch> diff --git a/castor/tape/rmc/castor-tape-acs-mount.man b/castor/tape/rmc/castor-tape-acs-mount.man deleted file mode 100644 index 15c1bc0b770e0ff4bad256530d663a93bff762a1..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/castor-tape-acs-mount.man +++ /dev/null @@ -1,56 +0,0 @@ -.\" Copyright (C) 2003 CERN -.\" This program is free software; you can redistribute it and/or -.\" modify it under the terms of the GNU General Public License -.\" as published by the Free Software Foundation; either version 2 -.\" of the License, or (at your option) any later version. -.\" This program is distributed in the hope that it will be useful, -.\" but WITHOUT ANY WARRANTY; without even the implied warranty of -.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -.\" GNU General Public License for more details. -.\" You should have received a copy of the GNU General Public License -.\" along with this program; if not, write to the Free Software -.\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -.TH CASTOR-TAPE-ACS-MOUNT "1castor" "$Date: 2013/10/09 14:00:00 $" CASTOR "CASTOR" -.SH NAME -castor-tape-acs-mount \- mount a volume -.SH SYNOPSIS -.BI "castor-tape-acs-mount [options] VID DRIVE" - -.SH DESCRIPTION -.B castor-tape-acs-mount -mounts the volume with the specfied VID in an ACS compatible tape-library into -the drive with the specified DRIVE ID. The DRIVE ID format is: - -.B ACS:LSM:panel:transport - -.SH OPTIONS -.TP -\fB\-d, \-\-debug -Turns on the printing of debug information. -.TP -\fB\-h, \-\-help -Prints the usage message. -.TP -\fB\-q, \-\-query SECONDS -Time wait between queries to ACLS for responses. -SECONDS must be an integer value greater than 0. -The default value of SECONDS is 10. -.TP -\fB\-r, \-\-readonly -Request the volume is mounted for read-only access. -.TP -\fB\-t, \-\-timeout SECONDS -Time to wait for the mount operation to conclude. -SECONDS must be an integer value greater than 0. -The default value of SECONDS is 600. - -.SH "RETURN CODES" -.TP -\fB 0 -Ok. -.TP -\fB 1 -Command failed. - -.SH AUTHOR -\fBCASTOR\fP Team <castor.support@cern.ch> diff --git a/castor/tape/rmc/castor-tape-acs-queryvolume.man b/castor/tape/rmc/castor-tape-acs-queryvolume.man deleted file mode 100644 index 2860fa147d0c8a32e00c50164c663e5e5a8c810f..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/castor-tape-acs-queryvolume.man +++ /dev/null @@ -1,50 +0,0 @@ -.\" Copyright (C) 2003 CERN -.\" This program is free software; you can redistribute it and/or -.\" modify it under the terms of the GNU General Public License -.\" as published by the Free Software Foundation; either version 2 -.\" of the License, or (at your option) any later version. -.\" This program is distributed in the hope that it will be useful, -.\" but WITHOUT ANY WARRANTY; without even the implied warranty of -.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -.\" GNU General Public License for more details. -.\" You should have received a copy of the GNU General Public License -.\" along with this program; if not, write to the Free Software -.\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -.TH CASTOR-TAPE-ACS-QUERYVOLUME "1castor" "$Date: 2013/10/09 14:00:00 $" CASTOR "CASTOR" -.SH NAME -castor-tape-acs-queryvolume \- queries a volume -.SH SYNOPSIS -.BI "castor-tape-acs-queryvolume [options] VID" - -.SH DESCRIPTION -.B castor-tape-acs-queryvolume -quieries ACS for information about the volume with the specfied VID. - -.SH OPTIONS -.TP -\fB\-d, \-\-debug -Turns on the printing of debug information. -.TP -\fB\-h, \-\-help -Prints the usage message. -.TP -\fB\-q, \-\-query SECONDS -Time wait between queries to ACLS for responses. -SECONDS must be an integer value greater than 0. -The default values of SECONDS is 300. -.TP -\fB\-t, \-\-timeout SECONDS -Time to wait for the mount operation to conclude. -SECONDS must be an integer value greater than 0. -The default value of SECONDS is 10. - -.SH "RETURN CODES" -.TP -\fB 0 -Ok. -.TP -\fB 1 -Command failed. - -.SH AUTHOR -\fBCASTOR\fP Team <castor.support@cern.ch> diff --git a/castor/tape/rmc/castor-tape-mount.man b/castor/tape/rmc/castor-tape-mount.man deleted file mode 100644 index dbcb782fd9c136f84c300f3d952fbb90c402cb4b..0000000000000000000000000000000000000000 --- a/castor/tape/rmc/castor-tape-mount.man +++ /dev/null @@ -1,70 +0,0 @@ -.\" Copyright (C) 2003 CERN -.\" This program is free software; you can redistribute it and/or -.\" modify it under the terms of the GNU General Public License -.\" as published by the Free Software Foundation; either version 2 -.\" of the License, or (at your option) any later version. -.\" This program is distributed in the hope that it will be useful, -.\" but WITHOUT ANY WARRANTY; without even the implied warranty of -.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -.\" GNU General Public License for more details. -.\" You should have received a copy of the GNU General Public License -.\" along with this program; if not, write to the Free Software -.\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -.TH CASTOR-TAPE-MOUNT 1 "$Date: 2009/08/07 15:56:38 $" CASTOR "CASTOR" -.SH NAME -castor-tape-mount \- mount a volume -.SH SYNOPSIS -.BI "castor-tape-mount [options] VID DRIVE" - -.SH DESCRIPTION -.B castor-tape-mount -mounts the volume with the specfied VID in into the drive with the specified -DRIVE ID. The DRIVE ID format depends on the type of tape library being used. -The -.B castor-tape-mount -currently supports three types of tape library, namely ACS compatible, manual -and SCSI compatible. - -The DRIVE ID format for ACS-compatible libraries is: - -.B acsACS:LSM:panel:transport - -The DRIVE ID format for manual is simply: - -.B manual - -The DRIVE ID format for SCSI-compatible libraries is: - -.B smc@rmc_host,drive_ordinal - -.SH OPTIONS -.TP -\fB\-d, \-\-debug -Turns on the printing of debug information. -.TP -\fB\-h, \-\-help -Prints the usage message. -.TP -\fB\-q, \-\-query SECONDS -Time wait between queries to ACLS for responses. -SECONDS must be an integer value greater than 0. -The default value of SECONDS is 10. -.TP -\fB\-r, \-\-readonly -Request the volume is mounted for read-only access. -.TP -\fB\-t, \-\-timeout SECONDS -Time to wait for the mount operation to conclude. -SECONDS must be an integer value greater than 0. -The default value of SECONDS is 600. - -.SH "RETURN CODES" -.TP -\fB 0 -Ok. -.TP -\fB 1 -Command failed. - -.SH AUTHOR -\fBCASTOR\fP Team <castor.support@cern.ch> diff --git a/h/rmc_api.h b/h/rmc_api.h index 6f48388fefa73fedeb99e1f4991d3fc82948667e..ef99db8e066218387ac7d505e3896523dfc5fa97 100644 --- a/h/rmc_api.h +++ b/h/rmc_api.h @@ -27,6 +27,4 @@ EXTERN_C int rmc_mount(const char *const server, const char *const vid, const in EXTERN_C int rmc_read_elem_status(const char *const server, const int type, const int startaddr, const int nbelem, struct smc_element_info *const element_info); EXTERN_C void rmc_seterrbuf(const char *const buffer, const int buflen); EXTERN_C int send2rmc(const char *const host, const char *const reqp, const int reql, char *const user_repbuf, const int user_repbuf_len); -EXTERN_C int rmc_mnt(const char *const vid, const char *const drive); -EXTERN_C int rmc_unmnt(const char *const vid, const char *const drive); diff --git a/h/rmc_constants.h b/h/rmc_constants.h index fbfd5d81f6d2dbddc0c602326ec66692005343bd..fbe2c1e0db6bd53c3a27769631683b008b0bdd26 100644 --- a/h/rmc_constants.h +++ b/h/rmc_constants.h @@ -32,15 +32,15 @@ /* Request types */ -#define RMC_SCSI_GETGEOM 1 /* Get robot geometry */ -#define RMC_SCSI_FINDCART 2 /* Find cartridge(s) */ -#define RMC_SCSI_READELEM 3 /* Read element status */ -#define RMC_SCSI_MOUNT 4 /* Mount request */ -#define RMC_SCSI_UNMOUNT 5 /* Unmount request */ -#define RMC_SCSI_EXPORT 6 /* Export tape request */ -#define RMC_SCSI_IMPORT 7 /* Import tape request */ -#define RMC_ACS_MOUNT 8 /* ACS mount request */ -#define RMC_ACS_UNMOUNT 9 /* ACS unmount request */ +#define RMC_GETGEOM 1 /* Get robot geometry */ +#define RMC_FINDCART 2 /* Find cartridge(s) */ +#define RMC_READELEM 3 /* Read element status */ +#define RMC_MOUNT 4 /* Mount request */ +#define RMC_UNMOUNT 5 /* Unmount request */ +#define RMC_EXPORT 6 /* Export tape request */ +#define RMC_IMPORT 7 /* Import tape request */ +#define RMC_GENERICMOUNT 8 /* Generic (SCSI or ACS) mount request */ +#define RMC_GENERICUNMOUNT 9 /* Generic (SCSI or ACS) mount request */ /* SCSI media changer server reply types */ diff --git a/h/rmc_find_char.h b/h/rmc_find_char.h deleted file mode 100644 index 06b6c3564339b3d549260716048f6a1631cfbd5f..0000000000000000000000000000000000000000 --- a/h/rmc_find_char.h +++ /dev/null @@ -1,41 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -/****************************************************************************** - * Please note that this file is part of the internal API of the rmc daemon - * and its client software and should therefore not be distributed to end users - *****************************************************************************/ - -#pragma once - -/** - * Returns the index of the specified character within the specified string. - * The search for the character is performed from left to right and stops at the - * first coccurence of the character. - * - * @param str The string to be searched. - * @param c The character to be seacrhed for. - * @return The index of the character if it was found else -1 if not. - */ -int rmc_find_char(const char *const str, const char c); - diff --git a/h/rmc_get_acs_drive_id.h b/h/rmc_get_acs_drive_id.h deleted file mode 100644 index 1eec268f7e2d5a83a7de7497341e206183b03c27..0000000000000000000000000000000000000000 --- a/h/rmc_get_acs_drive_id.h +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -/****************************************************************************** - * Please note that this file is part of the internal API of the rmc daemon - * and its client software and should therefore not be distributed to end users - *****************************************************************************/ - -#pragma once - -/** - * Structure representing the identifier of a drive withn an ACS compatible - * tape library. - */ -struct rmc_acs_drive_id { - int acs; - int lsm; - int panel; - int transport; -}; - -/** - * Returns the drive id of the specified drive string of the form: - * - * acs@rmc_host,acs,lsm,panel,transport - * - * There are three RMC loader types, namely acs, manual and smc. The drive - * string is expected to be in one of the following forms respectively: - * - * acs@rmc_host[:rmc_port],ACS_NUMBER,LSM_NUMBER,PANEL_NUMBER,TRANSPORT_NUMBER - * manual - * smc@rmc_host[:rmc_port],drive_ordinal - * - * @return The loader type. - */ -int rmc_get_acs_drive_id(const char *const drive, - struct rmc_acs_drive_id *const drive_id); - diff --git a/h/rmc_get_loader_type.h b/h/rmc_get_loader_type.h deleted file mode 100644 index f993abf8f56ea1431502c7dfb653e8c6ee94bbff..0000000000000000000000000000000000000000 --- a/h/rmc_get_loader_type.h +++ /dev/null @@ -1,51 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -/****************************************************************************** - * Please note that this file is part of the internal API of the rmc daemon - * and its client software and should therefore not be distributed to end users - *****************************************************************************/ - -#pragma once - -typedef enum { - RMC_LOADER_TYPE_ACS, - RMC_LOADER_TYPE_MANUAL, - RMC_LOADER_TYPE_SMC, - RMC_LOADER_TYPE_UNKNOWN} rmc_loader_type; - -/** - * Returns the loader type of the specified drive string. - * - * There are three RMC loader types, namely acs, manual and smc. The drive - * string is expected to be in one of the following forms respectively: - * - * acs@rmc_host[:rmc_port],ACS_NUMBER,LSM_NUMBER,PANEL_NUMBER,TRANSPORT_NUMBER - * manual - * smc@rmc_host[:rmc_port],drive_ordinal - * - * @param drive The drive string. - * @return The loader type. - */ -rmc_loader_type rmc_get_loader_type(const char *const drive); - diff --git a/h/rmc_get_rmc_host_of_drive.h b/h/rmc_get_rmc_host_of_drive.h deleted file mode 100644 index 0dd130943f877a141d14091d2581f36d5510336f..0000000000000000000000000000000000000000 --- a/h/rmc_get_rmc_host_of_drive.h +++ /dev/null @@ -1,48 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -/****************************************************************************** - * Please note that this file is part of the internal API of the rmc daemon - * and its client software and should therefore not be distributed to end users - *****************************************************************************/ - -#pragma once - -/** - * Returns the rmc host of the specified drive string. The drive string either - * starts with: - * - * acs@rmc_host, - * or: - * - * smc@rmc_host, - * - * @param drive The drive string - * @param rmc_host_buf Output parameter. The buffer into which the rmc host - * should be written as a null terminated string. - * @param rmc_host_buflen The length of the rmc host buffer. - * @return 0 on success and -1 on failure. - */ -int rmc_get_rmc_host_of_drive(const char *const drive, - char *const rmc_host_buf, const int rmc_host_buflen); - diff --git a/h/rmc_procreq.h b/h/rmc_procreq.h index 3e95da8d9de90f3cac51775dde3d94469ccffcd5..0cea59fed78853f1d3d3fa541ed6e15376ac5d06 100644 --- a/h/rmc_procreq.h +++ b/h/rmc_procreq.h @@ -31,13 +31,10 @@ struct rmc_srv_rqst_context { const char *clienthost; }; -int rmc_srv_export(const struct rmc_srv_rqst_context *const rqst_context); +int rmc_srv_export (const struct rmc_srv_rqst_context *const rqst_context); int rmc_srv_findcart(const struct rmc_srv_rqst_context *const rqst_context); -int rmc_srv_getgeom(const struct rmc_srv_rqst_context *const rqst_context); -int rmc_srv_import(const struct rmc_srv_rqst_context *const rqst_context); -int rmc_srv_mount(const struct rmc_srv_rqst_context *const rqst_context); +int rmc_srv_getgeom (const struct rmc_srv_rqst_context *const rqst_context); +int rmc_srv_import (const struct rmc_srv_rqst_context *const rqst_context); +int rmc_srv_mount (const struct rmc_srv_rqst_context *const rqst_context); int rmc_srv_readelem(const struct rmc_srv_rqst_context *const rqst_context); -int rmc_srv_unmount(const struct rmc_srv_rqst_context *const rqst_context); -int rmc_srv_acs_mnt(const struct rmc_srv_rqst_context *const rqst_context); -int rmc_srv_acs_unmnt(const struct rmc_srv_rqst_context *const rqst_context); - +int rmc_srv_unmount (const struct rmc_srv_rqst_context *const rqst_context); diff --git a/rmc/CMakeLists.txt b/rmc/CMakeLists.txt index 5574f816ce4b3f58e2cf4ad042a2361792b311d0..86cd4bc92f5022d14c103f7e102a7d9d9e9d22a0 100644 --- a/rmc/CMakeLists.txt +++ b/rmc/CMakeLists.txt @@ -31,16 +31,11 @@ if (${COMPILE_SERVER} STREQUAL "1") rmc_errmsg.c rmc_export.c rmc_find_cartridge.c - rmc_find_char.c rmc_get_geometry.c - rmc_get_acs_drive_id.c - rmc_get_rmc_host_of_drive.c - rmc_get_loader_type.c rmc_import.c rmc_mount.c rmc_mnt.c rmc_read_elem_status.c - rmc_unmnt.c send2rmc.c) add_library (castorrmc SHARED ${RMC_LIB_SRC_FILES}) CastorSetLibraryVersions (castorrmc) diff --git a/rmc/rmc_dismount.c b/rmc/rmc_dismount.c index 1831f4f3f2d75cb427a1de04ecde81a04e1c8ab7..6b4690177177747d55dc168dd8ca17e30ca156db 100644 --- a/rmc/rmc_dismount.c +++ b/rmc/rmc_dismount.c @@ -35,7 +35,7 @@ int rmc_dismount( sbp = sendbuf; marshall_LONG (sbp, RMC_MAGIC); - marshall_LONG (sbp, RMC_SCSI_UNMOUNT); + marshall_LONG (sbp, RMC_UNMOUNT); q = sbp; /* save pointer. The next field will be updated */ msglen = 3 * LONGSIZE; marshall_LONG (sbp, msglen); diff --git a/rmc/rmc_export.c b/rmc/rmc_export.c index dd8d00f9faf472e938b97f5fbdc06836f5f7e68d..08bc1ccd03eae32eab5c8e4cdfc48ef761b80961 100644 --- a/rmc/rmc_export.c +++ b/rmc/rmc_export.c @@ -30,7 +30,7 @@ int rmc_export(const char *const server, const char *const vid) sbp = sendbuf; marshall_LONG (sbp, RMC_MAGIC); - marshall_LONG (sbp, RMC_SCSI_EXPORT); + marshall_LONG (sbp, RMC_EXPORT); q = sbp; /* save pointer. The next field will be updated */ msglen = 3 * LONGSIZE; marshall_LONG (sbp, msglen); diff --git a/rmc/rmc_find_cartridge.c b/rmc/rmc_find_cartridge.c index 890e1d1d98cc665a11bb0be79efd5c0ffb1e6ee4..8728ba2f4e1dd0285d06f85beaceb08896ddf12c 100644 --- a/rmc/rmc_find_cartridge.c +++ b/rmc/rmc_find_cartridge.c @@ -40,7 +40,7 @@ int rmc_find_cartridge( sbp = sendbuf; marshall_LONG (sbp, RMC_MAGIC); - marshall_LONG (sbp, RMC_SCSI_FINDCART); + marshall_LONG (sbp, RMC_FINDCART); q = sbp; /* save pointer. The next field will be updated */ msglen = 3 * LONGSIZE; marshall_LONG (sbp, msglen); diff --git a/rmc/rmc_find_char.c b/rmc/rmc_find_char.c deleted file mode 100644 index ecd8ce38349c2915ce291bfe80773d1ecbbf832c..0000000000000000000000000000000000000000 --- a/rmc/rmc_find_char.c +++ /dev/null @@ -1,40 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "h/rmc_find_char.h" - -#include <string.h> - -int rmc_find_char(const char *const str, const char c) { - if(NULL != str) { - const int str_len = strlen(str); - int i = 0; - - for(i = 0; i < str_len; i++) { - if(c == str[i]) { - return i; - } - } - } - return -1; -} diff --git a/rmc/rmc_get_acs_drive_id.c b/rmc/rmc_get_acs_drive_id.c deleted file mode 100644 index 1fd34e07e4b8bfde8bf98e0bcb1c21216213d7ad..0000000000000000000000000000000000000000 --- a/rmc/rmc_get_acs_drive_id.c +++ /dev/null @@ -1,123 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "h/rmc_get_acs_drive_id.h" - -#include <string.h> - -/** - * A simple function that converts the string representation of the unsigned - * integer in the specified character buffer to an integer. - * - * @return A value of 0 or greater than 0 if the conversion was a success or -1 - * if the conversion was not a success. - */ -static int rmc_buf2uint(const char *const buf, int buflen) { - int i = 0; - int value = 0; - - /* Fail conversion if there is nothing to convert */ - if(NULL == buf || 0 == buflen) { - return -1; - } - - for(i = 0; i < buflen; i++) { - const char c = buf[i]; - - /* Fail conversion if the character is not a decimal digit */ - if(c < '0' || c > '9') { - return -1; - } - value *= 10; - value += (c - '0'); - } - return value; -} - -int rmc_get_acs_drive_id(const char *const drive, - struct rmc_acs_drive_id *const drive_id) { - int str_len = 0; - int i = 0; - int nbCommas = 0; - int commaIndex[4]; - - /* Fail if there is nothing to work on */ - if(NULL == drive) { - return -1; - } - - str_len = strlen(drive); - - /* An acs drive string starts with "acs@" */ - /* */ - /* Fail if the first 4 characters do not exist or are not as expected */ - if(4 > str_len || strncmp("acs@", drive, 4)) { - return -1; - } - - /* The drive string should be of the form */ - /* "acs@rmc_host,acs,lsm,panel,transport" */ - /* therefore there should be 4 commas (',') */ - - /* Find the expected 4 commas */ - for(i=0; i < str_len; i++) { - if(',' == drive[i]) { - /* Fail if there are too many commas */ - if(4 < nbCommas) { - return -1; - } - commaIndex[nbCommas] = i; - nbCommas++; - } - } - - /* Fail if there are too few commas */ - if(4 != nbCommas) { - return -1; - } - - /* Fail if the rmc_host has zero length */ - if(0 == commaIndex[0] - 3 /* index of at sign ('@') */) { - return -1; - } - - /* Try to convert the 4 drive id numbers to integers */ - drive_id->acs = rmc_buf2uint(drive + commaIndex[0] + 1, - commaIndex[1] - commaIndex[0] - 1); - drive_id->lsm = rmc_buf2uint(drive + commaIndex[1] + 1, - commaIndex[2] - commaIndex[1] - 1); - drive_id->panel = rmc_buf2uint(drive + commaIndex[2] + 1, - commaIndex[3] - commaIndex[2] - 1); - drive_id->transport = rmc_buf2uint(drive + commaIndex[3] + 1, - str_len - 1 - commaIndex[3]); - - /* Fail if one of the drive id numbers could not be converted */ - if( -1 == drive_id->acs || - -1 == drive_id->lsm || - -1 == drive_id->panel || - -1 == drive_id->transport) { - return -1; - } - - return 0; -} diff --git a/rmc/rmc_get_geometry.c b/rmc/rmc_get_geometry.c index b6937005bed7b9ea4ca0d4030bd3d1ca4b8fef2b..16f7e42f5c57ed7f94ae8636bcd92aac904593e4 100644 --- a/rmc/rmc_get_geometry.c +++ b/rmc/rmc_get_geometry.c @@ -34,7 +34,7 @@ int rmc_get_geometry( sbp = sendbuf; marshall_LONG (sbp, RMC_MAGIC); - marshall_LONG (sbp, RMC_SCSI_GETGEOM); + marshall_LONG (sbp, RMC_GETGEOM); q = sbp; /* save pointer. The next field will be updated */ msglen = 3 * LONGSIZE; marshall_LONG (sbp, msglen); diff --git a/rmc/rmc_get_loader_type.c b/rmc/rmc_get_loader_type.c deleted file mode 100644 index 1ceeb8c0758834215ff4614f0162e08351b15b9e..0000000000000000000000000000000000000000 --- a/rmc/rmc_get_loader_type.c +++ /dev/null @@ -1,38 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "h/rmc_get_loader_type.h" - -#include <string.h> - -rmc_loader_type rmc_get_loader_type(const char *const drive) { - if(strncmp("acs@", drive, 3) == 0) { - return RMC_LOADER_TYPE_ACS; - } else if(strcmp("manual", drive) == 0) { - return RMC_LOADER_TYPE_MANUAL; - } else if(strncmp("smc@", drive, 3) == 0) { - return RMC_LOADER_TYPE_SMC; - } else { - return RMC_LOADER_TYPE_UNKNOWN; - } -} diff --git a/rmc/rmc_get_rmc_host_of_drive.c b/rmc/rmc_get_rmc_host_of_drive.c deleted file mode 100644 index aef8fb3a45e5c64117ac9d78cf224898387b023c..0000000000000000000000000000000000000000 --- a/rmc/rmc_get_rmc_host_of_drive.c +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "h/rmc_find_char.h" -#include "h/rmc_get_rmc_host_of_drive.h" - -#include <string.h> - -int rmc_get_rmc_host_of_drive(const char *const drive, - char *const rmc_host_buf, const int rmc_host_buflen) { - int indexOfComma = 0; - int rmc_host_len = 0; - - /* Fail if there is nothing to work on */ - if(NULL == drive || NULL == rmc_host_buf || 0 == rmc_host_buflen) { - return -1; - } - - /* Fail if the drive string does not start with either "acs@" or */ - /* "smc@" */ - if(strncmp("acs@", drive, 4) && strncmp("smc@", drive, 4)) { - return -1; - } - - /* The rmc_host should follow the at sign ('@') and be terminated by */ - /* a comma (',') for example "acs@rmc_host," */ - - indexOfComma = rmc_find_char(drive, ','); - rmc_host_len = indexOfComma - 3 /* index of the at sign */ - 1; - if( 0 >= rmc_host_len || /* rmc_host contains no characters */ - rmc_host_buflen <= rmc_host_len) { /* rmc_host is too long */ - return -1; - } - - memcpy(rmc_host_buf, drive + 4, rmc_host_len); - rmc_host_buf[rmc_host_len] = '\0'; - return 0; -} diff --git a/rmc/rmc_import.c b/rmc/rmc_import.c index 73e2280d6c323c2fb05abc5534669a0c16bda5f9..bc0d20e3ab2ba984a4ad2c6f65f004105d86d379 100644 --- a/rmc/rmc_import.c +++ b/rmc/rmc_import.c @@ -31,7 +31,7 @@ int rmc_import(const char *const server, const char *const vid) sbp = sendbuf; marshall_LONG (sbp, RMC_MAGIC); - marshall_LONG (sbp, RMC_SCSI_IMPORT); + marshall_LONG (sbp, RMC_IMPORT); q = sbp; /* save pointer. The next field will be updated */ msglen = 3 * LONGSIZE; marshall_LONG (sbp, msglen); diff --git a/rmc/rmc_mnt.c b/rmc/rmc_mnt.c index 11b78e8ff79d984531b5f5507637f014142b97db..ddb7202cbe22695041f1370f0bf78d4d93a72726 100644 --- a/rmc/rmc_mnt.c +++ b/rmc/rmc_mnt.c @@ -31,97 +31,49 @@ #include "h/marshall.h" #include "h/rmc_api.h" #include "h/rmc_constants.h" -#include "h/rmc_get_acs_drive_id.h" -#include "h/rmc_get_rmc_host_of_drive.h" -#include "h/rmc_get_loader_type.h" #include "h/serrno.h" #include <errno.h> #include <string.h> -static int rmc_acs_mnt(const char *const vid, const char *const drive); -static int rmc_manual_mnt(const char *const vid, const char *const drive); -static int rmc_smc_mnt(const char *const vid, const char *const drive); - -int rmc_mnt(const char *const vid, const char *const drive) { - /* If there is nothing to work on then return EINVAL */ - if(NULL == vid || NULL == drive) { - errno = EINVAL; - serrno = errno; - return -1; - } - - if(CA_MAXVIDLEN < strlen(vid)) { - errno = ERMCVIDTOOLONG; /* VID is too long */ - serrno = errno; - return -1; - } - - switch(rmc_get_loader_type(drive)) { - case RMC_LOADER_TYPE_ACS: - return rmc_acs_mnt(vid, drive); - case RMC_LOADER_TYPE_MANUAL: - return rmc_manual_mnt(vid, drive); - case RMC_LOADER_TYPE_SMC: - return rmc_smc_mnt(vid, drive); - default: - errno = ERMCUKNLDRTYPE; /* Unknown loader type */ - serrno = errno; - return -1; - } -} - -static int rmc_acs_mnt(const char *const vid, const char *const drive) { +int rmc_mnt( + const char *const server, + const char *const vid, + const char *const loader) +{ const gid_t gid = getgid(); const uid_t uid = getuid(); /* The total length of the fixed size members of the request message */ - /* is Magic (4 bytes) + request ID (4 bytes) + msglen (4 bytes) + */ - /* uid (4 bytes) + gid (4 bytes) + ACS number (4 bytes) + LSM number */ - /* (4 bytes) + panel number (4 bytes) + transport number (4 bytes) = */ - /* 40 bytes */ - const int msglen = 40 + strlen(vid); + /* is Magic (4 bytes) + request ID (4 bytes) + length (4 bytes) + */ + /* uid (4 bytes) + gid (4 bytes) = 20 bytes */ + const int msglen = 20 + strlen(vid) + 1 + strlen(loader) + 1; char repbuf[1]; char *sbp = NULL; char sendbuf[RMC_REQBUFSZ]; - char rmc_host[CA_MAXHOSTNAMELEN+1]; - struct rmc_acs_drive_id drive_id = {0, 0, 0, 0}; - - if(rmc_get_rmc_host_of_drive(drive, rmc_host, sizeof(rmc_host))) { - errno = ERMCPARSERMCHOST; /* Failed to parse RMC host */ - serrno = errno; - return -1; - } - - if(rmc_get_acs_drive_id(drive, &drive_id)) { - errno = ERMCPARSEACSDRV; /* Failed to parse ACS drive id */ - serrno = errno; - return -1; - } - /* It is an internal error if the total size of the request message */ - /* would be greater than RMC_REQBUFSZ */ + /* Consider the function arguments invalid if the total size of the */ + /* request message would be greater than RMC_REQBUFSZ */ if(msglen > RMC_REQBUFSZ) { - errno = SEINTERNAL; + errno = ERMCUNREC; serrno = errno; return -1; } /* Build request header */ + sbp = sendbuf; marshall_LONG (sbp, RMC_MAGIC); - marshall_LONG (sbp, RMC_ACS_MOUNT); + marshall_LONG (sbp, RMC_MOUNT); marshall_LONG (sbp, msglen); /* Build request body */ + marshall_LONG (sbp, uid); marshall_LONG (sbp, gid); - marshall_LONG (sbp, drive_id.acs); - marshall_LONG (sbp, drive_id.lsm); - marshall_LONG (sbp, drive_id.panel); - marshall_LONG (sbp, drive_id.transport); marshall_STRING (sbp, vid); + marshall_STRING (sbp, loader); /* Being paranoid; checking the calculated message length against */ /* the number of bytes marshalled */ @@ -131,15 +83,5 @@ static int rmc_acs_mnt(const char *const vid, const char *const drive) { return -1; } - return send2rmc (rmc_host, sendbuf, msglen, repbuf, sizeof(repbuf)); -} - -static int rmc_manual_mnt(const char *const vid, const char *const drive) { - /* Return 1 indicating the mount is manual */ - return 1; -} - -static int rmc_smc_mnt(const char *const vid, const char *const drive) { - - return 0; + return send2rmc (server, sendbuf, msglen, repbuf, sizeof(repbuf)); } diff --git a/rmc/rmc_mnt.man b/rmc/rmc_mnt.man index 421b63ab6c3cf2da41ff5b75f36cfda825fc9eab..144854e59c7283214511af79998cdc08ad7537ad 100644 --- a/rmc/rmc_mnt.man +++ b/rmc/rmc_mnt.man @@ -9,56 +9,46 @@ rmc_mnt \- send a request to the Remote Media Changer daemon to have a volume mo .br \fB#include "rmc_api.h"\fR .sp -.BI "int \fBrmc_mnt\f[](const char *const \fIvid\f[], const char *const \fIdrive\f[]); +.BI "int rmc_mnt (char *" server , +.BI "char *" vid , +.BI "char *" loader ); .SH DESCRIPTION .B rmc_mnt -asks the remote media-changer daemon to mount the volume +asks the Remote Media Changer server running on +.I server +to mount the volume .I vid on the drive specified by -.IR drive . +.IR loader . +.TP +.I server +specifies the Remote Media Changer to be contacted. .TP .I vid is the volume visual identifier. It must be at most six characters long. .TP -.I drive -specifies the drive in one of the following three forms corresponding to the three supported drive-loader types, namely acs, manual and smc: +.I loader +specifies the drive in the robot in the following form: .RS .TP -acsACS_NUMBER,LSM_NUMBER,PANEL_NUMBER,TRANSPORT_NUMBER -.TP -manual -.TP -smc@rmc_host,drive_ordinal +smc@hostname,drive_ordinal .RE .LP This function requires TP_SYSTEM privilege in the Cupv database. .SH RETURN VALUE -.TP -.B 0 -The mount operation was successful. -.TP -.B 1 -The mount operations is manual and the rmc_mnt() function has therefore not -taken any further action. -.TP -.B -1 -The mount operation has failed and both -.B errno -and +This routine returns 0 if the operation was successful or -1 if the operation +failed. In the latter case, .B serrno have been set appropriately. .SH ERRORS -.TP 1.8i -.B EINVAL -If either \fIvid\f[] or \fIdrive\f[] are passed a NULL pointer. -.TP +.TP 1.2i .B SECOMERR Communication error. .TP .B ERMCUNREC -Unknown host or invalid drive or requester does not have +Unknown host or invalid loader or vid too long or requester does not have TP_SYSTEM privilege in the Cupv database. .TP .B ERMCFASTR @@ -66,21 +56,6 @@ Unit attention. .TP .B ERMCOMSGR Hardware error or Medium Removal Prevented. -.TP -.B ERMCUKNLDRTYPE -Unknown drive-loader type. -.TP -.B ERMCVIDTOOLONG -VID is too long. -.TP -.B ERMCPARSERMCHOST -Failed to parse RMC host. -.TP -.B ERMCPARSEACSDRV -Failed to parse ACS drive id. -.TP -.B SEINTERNAL -Internal error. .SH SEE ALSO .BR Cupvlist(3) .SH AUTHOR diff --git a/rmc/rmc_mount.c b/rmc/rmc_mount.c index 94abde365ef16be4f2b7a99c9885a8ac66b85406..aa72260c325419e5dac143eca669ec7383e84b87 100644 --- a/rmc/rmc_mount.c +++ b/rmc/rmc_mount.c @@ -35,7 +35,7 @@ int rmc_mount( sbp = sendbuf; marshall_LONG (sbp, RMC_MAGIC); - marshall_LONG (sbp, RMC_SCSI_MOUNT); + marshall_LONG (sbp, RMC_MOUNT); q = sbp; /* save pointer. The next field will be updated */ msglen = 3 * LONGSIZE; marshall_LONG (sbp, msglen); diff --git a/rmc/rmc_procreq.c b/rmc/rmc_procreq.c index 07efc5a38512adc03915cbfcbeaeee447383f688..616a529c41b4677df1dc2bc5658edf93138c7a86 100644 --- a/rmc/rmc_procreq.c +++ b/rmc/rmc_procreq.c @@ -407,8 +407,7 @@ int rmc_srv_unmount(const struct rmc_srv_rqst_context *const rqst_context) { uid_t uid; char vid[CA_MAXVIDLEN+1]; - strncpy (func, "rmc_srv_unmount", sizeof(func)); - func[sizeof(func) - 1] = '\0'; + strncpy (func, "rmc_srv_unmount", 16); rbp = rqst_context->req_data; unmarshall_LONG (rbp, uid); unmarshall_LONG (rbp, gid); @@ -448,30 +447,10 @@ int rmc_srv_unmount(const struct rmc_srv_rqst_context *const rqst_context) { return c; } -/* rmc_srv_acs_mnt - mount a cartridge into a drive in an ACS compatible */ -/* tape library */ - -int rmc_srv_acs_mnt( - const struct rmc_srv_rqst_context *const rqst_context) { - char func[16]; - strncpy (func, "rmc_srv_acs_mnt", sizeof(func)); - func[sizeof(func) - 1] = '\0'; - - rmc_logreq (func, "Called"); - +int rmc_srv_genericmount(struct rmc_srv_rqst_context *const rqst_context) { return 0; } -/* rmc_srv_acs_unmnt - unmount a cartridge from a drive in an ACS */ -/* compatible tape library */ - -int rmc_srv_acs_unmnt( - const struct rmc_srv_rqst_context *const rqst_context) { - char func[18]; - strncpy (func, "rmc_srv_acs_unmnt", sizeof(func)); - func[sizeof(func) - 1] = '\0'; - - rmc_logreq (func, "Called"); - +int rmc_srv_genericunmount(struct rmc_srv_rqst_context *const rqst_context) { return 0; } diff --git a/rmc/rmc_read_elem_status.c b/rmc/rmc_read_elem_status.c index 07dd2a3799ee2df19d293ea2f3d9b17f6a292f51..551c256b827ba9b1edf7457ce1da495ae05bf0eb 100644 --- a/rmc/rmc_read_elem_status.c +++ b/rmc/rmc_read_elem_status.c @@ -39,7 +39,7 @@ int rmc_read_elem_status( sbp = sendbuf; marshall_LONG (sbp, RMC_MAGIC); - marshall_LONG (sbp, RMC_SCSI_READELEM); + marshall_LONG (sbp, RMC_READELEM); q = sbp; /* save pointer. The next field will be updated */ msglen = 3 * LONGSIZE; marshall_LONG (sbp, msglen); diff --git a/rmc/rmc_serv.c b/rmc/rmc_serv.c index 8311fe2c6f8433ecb20b94d4e09f88d26a88a91c..b22567a3f25143458602797468b44985893ec3b3 100644 --- a/rmc/rmc_serv.c +++ b/rmc/rmc_serv.c @@ -436,16 +436,14 @@ static int dispatchRqstHandlerWithFastRetry(const int req_type, */ static const char *rmc_req_type_to_str(const int req_type) { switch (req_type) { - case RMC_SCSI_MOUNT : return "RMC_SCSI_MOUNT"; - case RMC_SCSI_UNMOUNT : return "RMC_SCSI_UNMOUNT"; - case RMC_SCSI_EXPORT : return "RMC_SCSI_EXPORT"; - case RMC_SCSI_IMPORT : return "RMC_SCSI_IMPORT"; - case RMC_SCSI_GETGEOM : return "RMC_SCSI_GETGEOM"; - case RMC_SCSI_READELEM: return "RMC_SCSI_READELEM"; - case RMC_SCSI_FINDCART: return "RMC_SCSI_FINDCART"; - case RMC_ACS_MOUNT : return "RMC_ACS_MOUNT"; - case RMC_ACS_UNMOUNT : return "RMC_ACS_UNMOUNT"; - default : return "UNKNOWN"; + case RMC_MOUNT : return "RMC_MOUNT"; + case RMC_UNMOUNT : return "RMC_UNMOUNT"; + case RMC_EXPORT : return "RMC_EXPORT"; + case RMC_IMPORT : return "RMC_IMPORT"; + case RMC_GETGEOM : return "RMC_GETGEOM"; + case RMC_READELEM: return "RMC_READELEM"; + case RMC_FINDCART: return "RMC_FINDCART"; + default : return "UNKNOWN"; } } @@ -459,24 +457,20 @@ static const char *rmc_req_type_to_str(const int req_type) { static int dispatchRqstHandler(const int req_type, const struct rmc_srv_rqst_context *const rqst_context) { switch (req_type) { - case RMC_SCSI_MOUNT: + case RMC_MOUNT: return rmc_srv_mount (rqst_context); - case RMC_SCSI_UNMOUNT: + case RMC_UNMOUNT: return rmc_srv_unmount (rqst_context); - case RMC_SCSI_EXPORT: + case RMC_EXPORT: return rmc_srv_export (rqst_context); - case RMC_SCSI_IMPORT: + case RMC_IMPORT: return rmc_srv_import (rqst_context); - case RMC_SCSI_GETGEOM: + case RMC_GETGEOM: return rmc_srv_getgeom (rqst_context); - case RMC_SCSI_READELEM: + case RMC_READELEM: return rmc_srv_readelem (rqst_context); - case RMC_SCSI_FINDCART: + case RMC_FINDCART: return rmc_srv_findcart (rqst_context); - case RMC_ACS_MOUNT: - return rmc_srv_acs_mnt (rqst_context); - case RMC_ACS_UNMOUNT: - return rmc_srv_acs_unmnt (rqst_context); default: return ERMCUNREC; } diff --git a/rmc/rmc_unmnt.c b/rmc/rmc_unmnt.c deleted file mode 100644 index cf9800d074e25408b33fb04fa9293dba6fc0e991..0000000000000000000000000000000000000000 --- a/rmc/rmc_unmnt.c +++ /dev/null @@ -1,145 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -/* rmc_unmnt - unmount a cartridge from a drive that maybe in either */ -/* a SCSI compatible or an ACS compatible tape library */ - -#include <stdlib.h> -#include <sys/types.h> -#include <unistd.h> -#include <netinet/in.h> -#include "h/marshall.h" -#include "h/rmc_api.h" -#include "h/rmc_constants.h" -#include "h/rmc_get_acs_drive_id.h" -#include "h/rmc_get_rmc_host_of_drive.h" -#include "h/rmc_get_loader_type.h" -#include "h/serrno.h" - -#include <errno.h> -#include <string.h> - -static int rmc_acs_unmnt(const char *const vid, const char *const drive); -static int rmc_manual_unmnt(const char *const vid, const char *const drive); -static int rmc_smc_unmnt(const char *const vid, const char *const drive); - -int rmc_unmnt(const char *const vid, const char *const drive) { - /* If there is nothing to work on then return EINVAL */ - if(NULL == vid || NULL == drive) { - errno = EINVAL; - serrno = errno; - return -1; - } - - if(CA_MAXVIDLEN < strlen(vid)) { - errno = ERMCVIDTOOLONG; /* VID is too long */ - serrno = errno; - return -1; - } - - switch(rmc_get_loader_type(drive)) { - case RMC_LOADER_TYPE_ACS: - return rmc_acs_unmnt(vid, drive); - case RMC_LOADER_TYPE_MANUAL: - return rmc_manual_unmnt(vid, drive); - case RMC_LOADER_TYPE_SMC: - return rmc_smc_unmnt(vid, drive); - default: - errno = ERMCUNREC; - serrno = errno; - return -1; - } -} - -int rmc_acs_unmnt(const char *const vid, const char *const drive) { - const gid_t gid = getgid(); - const uid_t uid = getuid(); - - /* The total length of the fixed size members of the request message */ - /* is Magic (4 bytes) + request ID (4 bytes) + msglen (4 bytes) + */ - /* uid (4 bytes) + gid (4 bytes) + ACS number (4 bytes) + LSM number */ - /* (4 bytes) + panel number (4 bytes) + transport number (4 bytes) = */ - /* 40 bytes */ - const int msglen = 40 + strlen(vid); - - char repbuf[1]; - char *sbp = NULL; - char sendbuf[RMC_REQBUFSZ]; - char rmc_host[CA_MAXHOSTNAMELEN+1]; - struct rmc_acs_drive_id drive_id = {0, 0, 0, 0}; - - if(rmc_get_rmc_host_of_drive(drive, rmc_host, sizeof(rmc_host))) { - errno = ERMCPARSERMCHOST; /* Failed to parse RMC host */ - serrno = errno; - return -1; - } - - if(rmc_get_acs_drive_id(drive, &drive_id)) { - errno = ERMCPARSEACSDRV; /* Failed to parse ACS drive id */ - serrno = errno; - return -1; - } - - /* It is an internal error if the total size of the request message */ - /* would be greater than RMC_REQBUFSZ */ - if(msglen > RMC_REQBUFSZ) { - errno = SEINTERNAL; - serrno = errno; - return -1; - } - - /* Build request header */ - sbp = sendbuf; - marshall_LONG (sbp, RMC_MAGIC); - marshall_LONG (sbp, RMC_ACS_UNMOUNT); - marshall_LONG (sbp, msglen); - - /* Build request body */ - marshall_LONG (sbp, uid); - marshall_LONG (sbp, gid); - marshall_LONG (sbp, drive_id.acs); - marshall_LONG (sbp, drive_id.lsm); - marshall_LONG (sbp, drive_id.panel); - marshall_LONG (sbp, drive_id.transport); - marshall_STRING (sbp, vid); - - /* Being paranoid; checking the calculated message length against */ - /* the number of bytes marshalled */ - if(sbp - sendbuf != msglen) { - errno = SEINTERNAL; - serrno = errno; - return -1; - } - - return send2rmc (rmc_host, sendbuf, msglen, repbuf, sizeof(repbuf)); -} - -static int rmc_manual_unmnt(const char *const vid, const char *const drive) { - - return 0; -} - -static int rmc_smc_unmnt(const char *const vid, const char *const drive) { - - return 0; -} diff --git a/rmc/rmc_unmnt.man b/rmc/rmc_unmnt.man deleted file mode 100644 index 98b7d1f9e7a01d4346f12e8d20adf8c479453103..0000000000000000000000000000000000000000 --- a/rmc/rmc_unmnt.man +++ /dev/null @@ -1,78 +0,0 @@ -.\" Copyright (C) 2002 by CERN/IT/PDP/DM -.\" All rights reserved -.\" -.TH RMC_UNMNT 3 "$Date: 2013/11/18 16:21:00 $" CASTOR "rmc Library Functions" -.SH NAME -rmc_unmnt \- send a request to the Remote Media Changer daemon to have a volume unmounted -.SH SYNOPSIS -.B #include <sys/types.h> -.br -\fB#include "rmc_api.h"\fR -.sp -int \fBrmc_unmnt\f[](const char *const \fIvid\f[], const char *const \fIdrive\f[]); -.SH DESCRIPTION -.B rmc_unmnt -asks the Remote media-changer daemon (rmcd) to unmount the volume -.I vid -from the drive specified by -.IR drive . -.TP -.I vid -is the volume visual identifier. -It must be at most six characters long. -.TP -.I drive -specifies the drive in one of the following three forms corresponding to the three supported drive-loader types, namely acs, manual and smc: -.RS -.TP -acsACS_NUMBER,LSM_NUMBER,PANEL_NUMBER,TRANSPORT_NUMBER -.TP -manual -.TP -smc@rmc_host,drive_ordinal -.RE - -.LP -This function requires TP_SYSTEM privilege in the Cupv database. -.SH RETURN VALUE -This routine returns 0 if a unmount operation was successful, 1 if the unmount -is manual and therefore the system is now waiting for an operator to perform the -unmount, or -1 if the operation failed. In the latter case, -.B serrno -is set appropriately. -.SH ERRORS -.TP 1.2i -.B EINVAL -If either \fIvid\f[] or \fIdrive\f[] are passed a NULL pointer. -.TP -.B SECOMERR -Communication error. -.TP -.B ERMCUNREC -Unknown host or invalid drive or vid too long or requester does not have -TP_SYSTEM privilege in the Cupv database. -.TP -.B ERMCFASTR -Unit attention. -.TP -.B ERMCOMSGR -Hardware error or Medium Removal Prevented. -.TP -.B ERMCUKNLDRTYPE -Unknown drive-loader type. -.TP -.B ERMCVIDTOOLONG -VID is too long. -.TP -.B ERMCPARSERMCHOST -Failed to parse RMC host. -.TP -.B ERMCPARSEACSDRV -Failed to parse ACS drive id. -.TP -.B SEINTERNAL -Internal error -.SH SEE ALSO -.BR Cupvlist(3) -.SH AUTHOR -\fBCASTOR\fP Team <castor.support@cern.ch> diff --git a/rmc/rmcd.man b/rmc/rmcd.man index 3fa1649aaf6a1acae2a55c3df12551a12bd52b49..51e08b0ad1a4d11a299005179c462a30165f1879 100644 --- a/rmc/rmcd.man +++ b/rmc/rmcd.man @@ -5,72 +5,77 @@ .SH NAME rmcd \- start the Remote Media Changer daemon .SH SYNOPSIS -.B rmcd [OPTIONS] +.B rmcd +.I smc_ldr .SH DESCRIPTION .LP The .B rmcd command starts the Remote Media Changer daemon. -.SH OPTIONS -.TP -\fB\-f -Remain in the foreground. -.SH CASTOR CONFIGURATION PARAMETERS READ BY THE SERVER -The remote media changer daemon reads and uses the following CASTOR -configuration parameters which are specified within the CASTOR -configuration file /etc/castor/castor.conf. -.TP -\fBRMC MODE -The compatibility mode of the the remote media-changer daemon. Valid values -are ACS, MOCK and SMC. A remote media-changer daemon can either be configured -to work with an ACS compatible tape library or with a SCSI compatible tape -library. In addition a remote media-changer daemon can be configured to run -in MOCK mode for debugging purposes. In MOCK mode a remote media-changer will -do nothing but log the client requests it receives. It is \fBNOT\f[] -recommended to run a remote media-changer daemon in MOCK mode in production -unless you really know what you are doing. -.TP -\fBRMC PORT -The port on which the remote media changer daemon will listen for client -requests. The default value is 5014. This configuration parameter should -\fBNOT\fP normally be set and the default should be used. -.TP -\fBRMC SMCDEV -The path to the device file representing the SCSI media changer. This -configuration parameter is only read by a remote media-changer daemon -configured to run in SMC compatibility mode. See \fBRMC MODE\f[] above. - -.SH CASTOR CONFIGURATION PARAMETERS READ BY THE CLIENTS -The clients of the remote media changer daemon read and use the following -CASTOR configuration parameters which are specified within the CASTOR -configuration file /etc/castor/castor.conf. -.TP -\fBRMC HOST -The host on which the rmcd daemon is running and listening for client requests. -.TP -\fBRMC PORT -The port on which the remote media changer daemon will listen for client -requests. The default value is 5014. This configuration parameter should -\fBNOT\fP normally be set and the default should be used. - -.SH ENVIRONMENT VARIABLES READ BY THE CLIENTS -The clients of the remote media changer daemon read and use the following -environment variables. Please note that an environment variable will override -the equivalent CASTOR configuration parameter located within the CASTOR -configuration file /etc/castor/castor.conf. -.TP -\fBRMC_HOST -The same meaning as the CASTOR configuration parameter \fBRMC HOST\f[] -described above. -.TP -\fBRMC_PORT -The same meaning as the CASTOR configuration parameter \fBRMC PORT\f[] described -above. - -.SH THE SERVER LOG FILE +This command is usually executed at system startup time +.RB ( /etc/rc.local ). +.LP +.I smc_ldr +is the picker device as defined in /dev. +.LP +If the Remote Media Changer daemon is not active, +the requests are automatically retried by the client API. +.LP +All error messages and statistical information are kept in a log. +.LP +The Remote Media Changer daemon listen port number can be defined on client +hosts and on the Remote Media Changer host itself in either of the following +ways: +.RS +.LP +setting an environment variable RMC_PORT +.RS +.HP +setenv RMC_PORT 5014 +.RE +.LP +an entry in +.B /etc/castor/castor.conf +like: +.RS +.HP +RMC PORT 5014 +.RE +.LP +an entry in +.B /etc/services +like: +.RS +.HP +rmc 5014/tcp # CASTOR Remote Media Changer +.RE +.RE +.LP +If none of these methods is used, the default port number is taken from the +definition of RMC_PORT in rmc_constants.h. +.LP +The Remote Media Changer host name can be defined on client hosts +in either of the following ways: +.RS +.LP +setting an environment variable RMC_HOST, for example: +.RS +.HP +setenv RMC_HOST castor5 +.RE +.LP +an entry in +.B /etc/castor/castor.conf +for example: +.RS +.HP +RMC HOST castor5 +.RE +.RE +.LP +If none of these methods is used, the default host is the local host. .LP -All error messages and statistical information are written to the file -/var/log/castor/rmcd.log. Each entry within the log has a timestamp. +In the log each entry has a timestamp. For each user command there is one message RMC92 giving information about the requestor (hostname, uid, gid) and one message RMC98 giving the command itself. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index babc607c887c790ad6dc089d2f8f57d26f922727..221613fe414723070393c5cd3d116dbb11ffe4e2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -47,26 +47,6 @@ set (STK_UNITTEST_SRC_FILES) if (STK_API_LIB AND STK_UTL_LIB AND STK_IPC_LIB AND STK_CL_LIB) message(STATUS "Found all four STK libraries - adding STK related unit tests") set (STK_UNITTEST_SRC_FILES - ../castor/tape/rmc/AcceptHandler.cpp - ../castor/tape/rmc/Acs.cpp - ../castor/tape/rmc/AcsCmd.cpp - ../castor/tape/rmc/AcsDismountCmd.cpp - ../castor/tape/rmc/AcsDismountCmdLine.cpp - ../castor/tape/rmc/AcsDismountCmdLineTest.cpp - ../castor/tape/rmc/AcsDismountCmdTest.cpp - ../castor/tape/rmc/AcsMountCmd.cpp - ../castor/tape/rmc/AcsMountCmdLine.cpp - ../castor/tape/rmc/AcsMountCmdLineTest.cpp - ../castor/tape/rmc/AcsMountCmdTest.cpp - ../castor/tape/rmc/AcsQueryVolumeCmd.cpp - ../castor/tape/rmc/AcsQueryVolumeCmdLine.cpp - ../castor/tape/rmc/AcsQueryVolumeCmdLineTest.cpp - ../castor/tape/rmc/AcsQueryVolumeCmdTest.cpp - ../castor/tape/rmc/AcsTest.cpp - ../castor/tape/rmc/Cmd.cpp - ../castor/tape/rmc/ConnectionHandler.cpp - ../castor/tape/rmc/RmcDaemon.cpp - ../castor/tape/rmc/RmcDaemonTest.cpp ../castor/acs/AcsDaemon.cpp ../castor/acs/AcsDaemonTest.cpp ../castor/acs/AcsMessageHandler.cpp diff --git a/test/unittest/Makefile b/test/unittest/Makefile index 79d2d7abbfba473011c3198296406b3e7a8c9766..06268181dd90c31e83071d7270f11d5b353404b0 100644 --- a/test/unittest/Makefile +++ b/test/unittest/Makefile @@ -360,7 +360,6 @@ rununittests: $(RMC_OBJECTS) \ unittest_PendingMigrationsStoreTest.o \ unittest_BulkRequestConfigParamsTest.o \ unittest_IndexedContainerTest.o \ - unittest_RmcLibTest.o \ unittest_TapeFseqRangeListSequenceTest.o \ unittest_TapeFseqRangeSequenceTest.o \ unittest_TapeFseqRangeTest.o \ @@ -760,15 +759,6 @@ rmc_AcsCmd.o: $(ROOT_DIR)/castor/tape/rmc/AcsCmd.cpp rmc_DebugBuf.o: $(ROOT_DIR)/castor/tape/rmc/DebugBuf.cpp g++ $(COMMON_OPS) -c $(INCLUDE_OPS) -o $@ $^ -rmc_find_char.o: $(ROOT_DIR)/rmc/rmc_find_char.c - g++ $(COMMON_OPS) -c $(INCLUDE_OPS) -o $@ $^ - -rmc_get_acs_drive_id.o: $(ROOT_DIR)/rmc/rmc_get_acs_drive_id.c - g++ $(COMMON_OPS) -c $(INCLUDE_OPS) -o $@ $^ - -rmc_get_rmc_host_of_drive.o: $(ROOT_DIR)/rmc/rmc_get_rmc_host_of_drive.c - g++ $(COMMON_OPS) -c $(INCLUDE_OPS) -o $@ $^ - rmc_AcsDismountCmdLine.o: $(ROOT_DIR)/castor/tape/rmc/AcsDismountCmdLine.cpp g++ $(COMMON_OPS) -c $(INCLUDE_OPS) -o $@ $^ @@ -1663,12 +1653,6 @@ unittest_BulkRequestConfigParamsTest.o: $(ROOT_DIR)/test/unittest/castor/tape/ta unittest_IndexedContainerTest.o: $(ROOT_DIR)/test/unittest/castor/tape/utils/IndexedContainerTest.cpp g++ $(COMMON_OPS) -c $(INCLUDE_OPS) -o $@ $^ -unittest_RmcDaemonTest.o: $(ROOT_DIR)/test/unittest/castor/tape/rmc/RmcDaemonTest.cpp - g++ $(COMMON_OPS) -c $(INCLUDE_OPS) -o $@ $^ - -unittest_RmcLibTest.o: $(ROOT_DIR)/test/unittest/rmc/RmcLibTest.cpp - g++ $(COMMON_OPS) -c $(INCLUDE_OPS) -o $@ $^ - unittest_TapeFseqRangeListSequenceTest.o: $(ROOT_DIR)/test/unittest/castor/tape/tpcp/TapeFseqRangeListSequenceTest.cpp g++ $(COMMON_OPS) -c $(INCLUDE_OPS) -o $@ $^ diff --git a/test/unittest/rmc/RmcLibTest.cpp b/test/unittest/rmc/RmcLibTest.cpp deleted file mode 100644 index 37263868ecef8993503afe1a58c2e1b7327bb1e7..0000000000000000000000000000000000000000 --- a/test/unittest/rmc/RmcLibTest.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/****************************************************************************** - * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor - * - * Copyright (C) 2003 CERN - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * - * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ - -#include "h/Castor_limits.h" -#include "h/rmc_find_char.h" -#include "h/rmc_get_acs_drive_id.h" -#include "h/rmc_get_rmc_host_of_drive.h" - -#include <cppunit/extensions/HelperMacros.h> -#include <errno.h> -#include <stdint.h> -#include <string.h> - -class RmcLibTest: public CppUnit::TestFixture { -private: - - const char *const m_acsDrive; - const char *const m_smcDrive; - -public: - - RmcLibTest(): - m_acsDrive("acs1,23,456,7890"), - m_smcDrive("smc@rmc_host_for_smc,123") { - } - - void setUp() { - } - - void tearDown() { - } - - void testRmc_find_char_with_comma_at_9() { - const char *const strWithComma = "012345678,012345,78"; - CPPUNIT_ASSERT_EQUAL_MESSAGE("Find comma at index 9", - 9, rmc_find_char(strWithComma, ',')); - } - - void testRmc_find_char_with_no_comma() { - const char *const strWithoutComma = "0123456789012345678"; - CPPUNIT_ASSERT_EQUAL_MESSAGE("Find comma that does not exist", - -1, rmc_find_char(strWithoutComma, ',')); - } - - void testRmc_get_rmc_host_of_drive_with_acs_drive() { - char rmcHost[CA_MAXHOSTNAMELEN+1]; - memset(rmcHost, '0', sizeof(rmcHost)); - - CPPUNIT_ASSERT_EQUAL_MESSAGE("Good day get rmc host", - 0, rmc_get_rmc_host_of_drive(m_acsDrive, rmcHost, sizeof(rmcHost))); - - CPPUNIT_ASSERT_EQUAL_MESSAGE("Test extracted rmc host has the right value", - std::string("rmc_host_for_acs"), std::string(rmcHost)); - } - - void testRmc_get_rmc_host_of_drive_with_smc_drive() { - char rmcHost[CA_MAXHOSTNAMELEN+1]; - memset(rmcHost, '0', sizeof(rmcHost)); - - CPPUNIT_ASSERT_EQUAL_MESSAGE("Good day get rmc host", - 0, rmc_get_rmc_host_of_drive(m_smcDrive, rmcHost, sizeof(rmcHost))); - - CPPUNIT_ASSERT_EQUAL_MESSAGE("Test extracted rmc host has the right value", - std::string("rmc_host_for_smc"), std::string(rmcHost)); - } - - void testRmc_getacs_drive_id() { - rmc_acs_drive_id driveId = {0, 0, 0, 0}; - CPPUNIT_ASSERT_EQUAL_MESSAGE("Good day get acs drive id", - 0, rmc_get_acs_drive_id(m_acsDrive, &driveId)); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Checking ACS number", - 1, driveId.acs); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Checking LSM number", - 23, driveId.lsm); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Checking panel number", - 456, driveId.panel); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Checking transport number", - 7890, driveId.transport); - } - - CPPUNIT_TEST_SUITE(RmcLibTest); - CPPUNIT_TEST(testRmc_find_char_with_comma_at_9); - CPPUNIT_TEST(testRmc_find_char_with_no_comma); - CPPUNIT_TEST(testRmc_get_rmc_host_of_drive_with_acs_drive); - CPPUNIT_TEST(testRmc_get_rmc_host_of_drive_with_smc_drive); - CPPUNIT_TEST(testRmc_getacs_drive_id); - CPPUNIT_TEST_SUITE_END(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(RmcLibTest);