Commit 3b999449 authored by Victor Kotlyar's avatar Victor Kotlyar
Browse files

Copied ACLS C-API wrapper from tape::rmc to acs.

parent e4709081
/******************************************************************************
*
* 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/acs/Acs.hpp"
#include "castor/tape/utils/utils.hpp"
#include "castor/utils/utils.hpp"
#include <iomanip>
#include <sstream>
#include <stdint.h>
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
castor::acs::Acs::~Acs() throw() {
}
//------------------------------------------------------------------------------
// alpd2DriveId
//------------------------------------------------------------------------------
DRIVEID castor::acs::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::acs::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;
}
//------------------------------------------------------------------------------
// driveId2Str
//------------------------------------------------------------------------------
std::string castor::acs::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();
}
\ No newline at end of file
/******************************************************************************
*
* 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 acs {
/**
* 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;
/**
* 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 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;
}; // class Acs
} // namespace acs
} // namespace castor
......@@ -33,7 +33,7 @@ castor::acs::AcsDismountTape::AcsDismountTape(
const uint32_t lsm,
const uint32_t panel,
const uint32_t drive,
castor::tape::rmc::Acs &acsWrapper,
Acs &acsWrapper,
log::Logger &log,
const AcsDaemon::CastorConf &castorConf):
AcsLibraryInteraction(acsWrapper,log),
......
......@@ -23,7 +23,7 @@
#pragma once
#include "castor/tape/rmc/Acs.hpp"
#include "castor/acs/Acs.hpp"
#include "castor/acs/AcsLibraryInteraction.hpp"
#include "castor/log/Logger.hpp"
#include "castor/acs/AcsDaemon.hpp"
......@@ -44,7 +44,7 @@ public:
AcsDismountTape(
const std::string &vid, const uint32_t acs,
const uint32_t lsm, const uint32_t panel, const uint32_t drive,
castor::tape::rmc::Acs &acsWrapper, log::Logger &log,
Acs &acsWrapper, log::Logger &log,
const AcsDaemon::CastorConf &castorConf);
/**
......@@ -97,7 +97,7 @@ protected:
/**
* Object providing c wrapper for ACS commands.
*/
tape::rmc::Acs &m_acsWrapper;
Acs &m_acsWrapper;
/**
* Logger.
......
/******************************************************************************
*
* 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/acs/AcsImpl.hpp"
#include <errno.h>
#include <sstream>
#include <string.h>
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
castor::acs::AcsImpl::~AcsImpl() throw() {
}
//------------------------------------------------------------------------------
// mount
//------------------------------------------------------------------------------
STATUS castor::acs::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::acs::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::acs::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);
}
/******************************************************************************
*
* 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/acs/Acs.hpp"
namespace castor {
namespace acs {
/**
* 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();
}; // class AcsImpl
} // namespace acs
} // namespace castor
......@@ -30,7 +30,7 @@
// constructor
//------------------------------------------------------------------------------
castor::acs::AcsLibraryInteraction::AcsLibraryInteraction(
castor::tape::rmc::Acs &acs, log::Logger &log) throw(): m_acs(acs), m_log(log) {
Acs &acs, log::Logger &log) throw(): m_acs(acs), m_log(log) {
}
//------------------------------------------------------------------------------
......
......@@ -25,7 +25,7 @@
#include "castor/exception/Mismatch.hpp"
#include "castor/exception/RequestFailed.hpp"
#include "castor/tape/rmc/Acs.hpp"
#include "castor/acs/Acs.hpp"
#include "castor/log/Logger.hpp"
#include <string>
......@@ -50,7 +50,7 @@ public:
*
* @param acs Wrapper around the ACSLS C-API.
*/
AcsLibraryInteraction(castor::tape::rmc::Acs &acs, log::Logger &log) throw();
AcsLibraryInteraction(Acs &acs, log::Logger &log) throw();
/**
* Pure-virtual destructor to guarantee this class is abstract.
......@@ -105,7 +105,7 @@ protected:
/**
* Wrapper around the ACSLS C-API.
*/
castor::tape::rmc::Acs &m_acs;
Acs &m_acs;
/**
* Logger.
......
......@@ -31,8 +31,8 @@
#include "castor/acs/AcsMountTapeForMigration.hpp"
#include "castor/acs/AcsDaemon.hpp"
#include "castor/tape/utils/utils.hpp"
#include "castor/tape/rmc/Acs.hpp"
#include "castor/tape/rmc/AcsImpl.hpp"
#include "castor/acs/Acs.hpp"
#include "castor/acs/AcsImpl.hpp"
#include <sstream>
......@@ -222,7 +222,7 @@ castor::messages::Frame castor::acs::AcsMessageHandler::
log::Param("DRIVE", drive)};
m_log(LOG_INFO, "AcsMountTapeForRecall message", params);
castor::tape::rmc::AcsImpl acsWrapper;
castor::acs::AcsImpl acsWrapper;
castor::acs::AcsMountTapeForRecall acsMountTapeForRecall(vid, acs, lsm,
panel, drive, acsWrapper, m_log, m_castorConf);
try {
......@@ -266,7 +266,7 @@ castor::messages::Frame castor::acs::AcsMessageHandler::
log::Param("DRIVE", drive)};
m_log(LOG_INFO, "AcsMountTapeForMigration message", params);
castor::tape::rmc::AcsImpl acsWrapper;
castor::acs::AcsImpl acsWrapper;
castor::acs::AcsMountTapeForMigration acsMountTapeForMigration(vid, acs,
lsm, panel, drive, acsWrapper, m_log, m_castorConf);
try {
......@@ -310,7 +310,7 @@ castor::messages::Frame castor::acs::AcsMessageHandler::
log::Param("DRIVE", drive)};
m_log(LOG_INFO, "AcsDismountTape message", params);
castor::tape::rmc::AcsImpl acsWrapper;
castor::acs::AcsImpl acsWrapper;
castor::acs::AcsDismountTape acsDismountTape(vid, acs, lsm, panel, drive,
acsWrapper, m_log, m_castorConf);
try {
......
......@@ -33,7 +33,7 @@ castor::acs::AcsMountTapeForMigration::AcsMountTapeForMigration(
const uint32_t lsm,
const uint32_t panel,
const uint32_t drive,
castor::tape::rmc::Acs &acsWrapper,
Acs &acsWrapper,
log::Logger &log,
const AcsDaemon::CastorConf &castorConf):
AcsLibraryInteraction(acsWrapper,log),
......
......@@ -23,7 +23,7 @@
#pragma once
#include "castor/tape/rmc/Acs.hpp"
#include "castor/acs/Acs.hpp"
#include "castor/acs/AcsLibraryInteraction.hpp"
#include "castor/log/Logger.hpp"
#include "castor/acs/AcsDaemon.hpp"
......@@ -44,7 +44,7 @@ public:
AcsMountTapeForMigration(
const std::string &vid, const uint32_t acs,
const uint32_t lsm, const uint32_t panel, const uint32_t drive,
castor::tape::rmc::Acs &acsWrapper,log::Logger &log,
Acs &acsWrapper,log::Logger &log,
const AcsDaemon::CastorConf &castorConf);
/**
......@@ -97,7 +97,7 @@ protected:
/**
* Object providing C wrapper for ACS commands.
*/
tape::rmc::Acs &m_acsWrapper;
Acs &m_acsWrapper;
/**
* Logger.
......
......@@ -33,7 +33,7 @@ castor::acs::AcsMountTapeForRecall::AcsMountTapeForRecall(
const uint32_t lsm,
const uint32_t panel,
const uint32_t drive,
castor::tape::rmc::Acs &acsWrapper,
Acs &acsWrapper,
log::Logger &log,
const AcsDaemon::CastorConf &castorConf):
AcsLibraryInteraction(acsWrapper,log),
......
......@@ -23,7 +23,7 @@
#pragma once
#include "castor/tape/rmc/Acs.hpp"
#include "castor/acs/Acs.hpp"
#include "castor/acs/AcsLibraryInteraction.hpp"
#include "castor/acs/AcsDaemon.hpp"
#include "castor/log/Logger.hpp"
......@@ -44,7 +44,7 @@ public:
AcsMountTapeForRecall(
const std::string &vid, const uint32_t acs,
const uint32_t lsm, const uint32_t panel, const uint32_t drive,
castor::tape::rmc::Acs &acsWrapper,log::Logger &log,
Acs &acsWrapper,log::Logger &log,
const AcsDaemon::CastorConf &castorConf);
/**
......@@ -97,7 +97,7 @@ protected:
/**
* Object providing c wrapper for ACS commands.
*/
tape::rmc::Acs &m_acsWrapper;
Acs &m_acsWrapper;
/**
* Logger.
......
......@@ -42,8 +42,8 @@ if (STK_API_LIB AND STK_UTL_LIB AND STK_IPC_LIB AND STK_CL_LIB)
AcsMountTapeForRecall.cpp
AcsMountTapeForMigration.cpp
AcsLibraryInteraction.cpp
../../castor/tape/rmc/Acs.cpp
../../castor/tape/rmc/AcsImpl.cpp)
Acs.cpp
AcsImpl.cpp)
target_link_libraries(castorAcsDaemon castortapereactor)
set_target_properties (castorAcsDaemon PROPERTIES
......
......@@ -74,7 +74,8 @@ if (STK_API_LIB AND STK_UTL_LIB AND STK_IPC_LIB AND STK_CL_LIB)
../castor/acs/AcsMountTapeForRecall.cpp
../castor/acs/AcsMountTapeForMigration.cpp