Commit 82b2ed27 authored by Steven Murray's avatar Steven Murray
Browse files

Added the placeholder castor::tapeserver::ProcessForker class

Please note that the ProcessForker class does not as yet do anything.
I am making this commit due to all of the reshulling work I have had
to do to get this far.
parent 408f6d9d
......@@ -245,6 +245,7 @@ set (CLIENT_LIB_SRC_FILES
stager/BulkRequestResult.cpp
stager/FileResult.cpp
utils/DebugBuf.cpp
utils/ProcessCap.cpp
utils/SmartFd.cpp
utils/SmartFILEPtr.cpp
utils/utils.cpp
......@@ -274,12 +275,26 @@ set (CLIENT_LIB_SRC_FILES
../client/src/stager/stager_client_api_listPrivileges.cpp
../client/src/stager/stager_errmsg.c
../client/src/stager/stager_mapper.c)
add_library (castorclient SHARED ${CLIENT_LIB_SRC_FILES})
# Try to find the libcap library because it will not exist on Mac OS X
find_library (LIBCAP_LIB cap)
if (LIBCAP_LIB)
message(STATUS "Found the libcap library")
message(STATUS "Adding source to castor::utils to support process capabilities")
set (CLIENT_LIB_PROC_CAP_SRC_FILES
utils/SmartCap.cpp
utils/ProcessCap.cpp)
endif (LIBCAP_LIB)
add_library (castorclient SHARED
${CLIENT_LIB_SRC_FILES}
${CLIENT_LIB_PROC_CAP_SRC_FILES})
# Relax compilation of old code full of pointer casting. Funnily enough,
# the compiler only complains in -O2 mode (RelWithDebInfo in cmake).
set_property(SOURCE ../client/src/stager/stager_errmsg.c APPEND PROPERTY COMPILE_FLAGS -fno-strict-aliasing)
CastorSetLibraryVersions (castorclient)
target_link_libraries (castorclient castordlf)
target_link_libraries (castorclient cap castordlf)
install (TARGETS castorclient DESTINATION ${CASTOR_DEST_LIB_DIR})
if (${COMPILE_SERVER} STREQUAL "1")
......
......@@ -9,6 +9,8 @@
#include "castor/tape/tapeserver/client/ClientInterface.hpp"
#include "castor/tape/tapegateway/FilesToRecallList.hpp"
#include "castor/tape/tapegateway/FileToRecallStruct.hpp"
#include <memory>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
......
......@@ -4,8 +4,6 @@ add_library(castorTapeServerDaemon
AdminAcceptHandler.cpp
AdminConnectionHandler.cpp
../client/ClientProxy.cpp
CapabilityUtils.cpp
CapabilityUtilsImpl.cpp
DiskReadThreadPool.cpp
DiskReadTask.cpp
DiskWriteTask.cpp
......@@ -24,10 +22,12 @@ add_library(castorTapeServerDaemon
MigrationReportPacker.cpp
MigrationTaskInjector.cpp
DataTransferSession.cpp
ProcessForker.cpp
ProcessForkerProxy.cpp
ProcessForkerProxySocket.cpp
RecallMemoryManager.cpp
RecallTaskInjector.cpp
RecallReportPacker.cpp
SmartCap.cpp
TapeMessageHandler.cpp
TapeDaemonMain.cpp
TapeWriteTask.cpp
......@@ -46,15 +46,6 @@ add_library(castorTapeServerDaemonTestDummies
add_executable(tapeserverd TapeDaemon.cpp)
find_library (LIBCAP_LIB cap)
if (LIBCAP_LIB)
message(STATUS "Found the libcap library")
set (LIBCAPUNITTEST_SRC_FILES
../castor/tape/tapeserver/daemon/SmartCapTest.cpp)
else (LIBCAP_LIB)
message(STATUS "Failed to find libcap library")
endif (LIBCAP_LIB)
target_link_libraries(tapeserverd
castorTapeServerDaemon
Exception
......
......@@ -31,11 +31,8 @@
#include "castor/tape/tapeserver/system/Wrapper.hpp"
#include "castor/tape/utils/utils.hpp"
#include "castor/tape/tapeserver/client/ClientProxy.hpp"
#include "castor/tape/tapeserver/daemon/CapabilityUtils.hpp"
#include "TapeSingleThreadInterface.hpp"
using namespace castor::tape;
using namespace castor::log;
#include "castor/tape/tapeserver/daemon/TapeSingleThreadInterface.hpp"
#include "castor/utils/ProcessCap.hpp"
namespace castor {
namespace legacymsg {
......@@ -107,7 +104,7 @@ namespace daemon {
const utils::DriveConfig & driveConfig,
castor::legacymsg::RmcProxy & rmc,
castor::messages::TapeserverProxy & initialProcess,
CapabilityUtils &capUtils,
castor::utils::ProcessCap &capUtils,
const CastorConf & castorConf);
/** The only method. It will execute (like a task, that it is) */
int execute() ;
......@@ -145,21 +142,21 @@ namespace daemon {
* all errors and hence does not throw exceptions. It returns NULL
* in case of failure. */
castor::tape::drives::DriveInterface * findDrive(
const utils::DriveConfig &driveConfig,LogContext & lc);
const utils::DriveConfig &driveConfig,log::LogContext & lc);
/** sub-part of execute for the read sessions */
int executeRead(LogContext & lc);
int executeRead(log::LogContext & lc);
/** sub-part of execute for a write session */
int executeWrite(LogContext & lc);
int executeWrite(log::LogContext & lc);
/** sub-part of execute for a dump session */
void executeDump(LogContext & lc);
void executeDump(log::LogContext & lc);
/** Reference to the RmcProxy, allowing the mounting of the tape by the
* library. It will be used exclusively by the tape thread. */
castor::legacymsg::RmcProxy & m_rmc;
/** Reference to the tape server's parent process to report detailed status */
castor::messages::TapeserverProxy & m_intialProcess;
/** Object providing utilities for working UNIX capabilities. */
CapabilityUtils &m_capUtils;
castor::utils::ProcessCap &m_capUtils;
/** copy of the process's argc to allow "command line reporting"
* i.e. snprintf to argv's, which will be visible in 'ps' */
int m_argc;
......
......@@ -27,32 +27,34 @@
#include <stdint.h>
#include <inttypes.h>
#include <gtest/gtest.h>
#include "castor/tape/tapeserver/client/ClientSimulator.hpp"
#include "castor/tape/tapeserver/client/ClientSimSingleReply.hpp"
#include "castor/tape/tapeserver/client/ClientProxy.hpp"
#include "castor/tape/tapeserver/daemon/CapabilityUtilsDummy.hpp"
#include "../threading/Threading.hpp"
#include "castor/log/StringLogger.hpp"
#include "DataTransferSession.hpp"
#include "../system/Wrapper.hpp"
#include "Ctape.h"
#include "castor/tape/tapegateway/Volume.hpp"
#include "castor/tape/tapegateway/NoMoreFiles.hpp"
#include "castor/tape/tapegateway/EndNotificationErrorReport.hpp"
#include "castor/tape/tapegateway/NotificationAcknowledge.hpp"
#include "castor/tape/tapeserver/file/File.hpp"
#include "castor/tape/tapegateway/RetryPolicyElement.hpp"
#include "smc_struct.h"
#include "castor/legacymsg/VmgrProxyDummy.hpp"
#include "castor/legacymsg/VdqmProxyDummy.hpp"
#include "castor/legacymsg/RmcProxyDummy.hpp"
#include "castor/log/StringLogger.hpp"
#include "castor/messages/TapeserverProxyDummy.hpp"
#include "castor/tape/tapegateway/EndNotificationErrorReport.hpp"
#include "castor/tape/tapegateway/NoMoreFiles.hpp"
#include "castor/tape/tapegateway/NotificationAcknowledge.hpp"
#include "castor/tape/tapegateway/RetryPolicyElement.hpp"
#include "castor/tape/tapegateway/Volume.hpp"
#include "castor/tape/tapeserver/client/ClientSimulator.hpp"
#include "castor/tape/tapeserver/client/ClientSimSingleReply.hpp"
#include "castor/tape/tapeserver/client/ClientProxy.hpp"
#include "castor/tape/tapeserver/daemon/DataTransferSession.hpp"
#include "castor/tape/tapeserver/system/Wrapper.hpp"
#include "castor/tape/tapeserver/threading/Threading.hpp"
#include "castor/tape/tapeserver/file/File.hpp"
#include "castor/utils/ProcessCapDummy.hpp"
#include "h/Ctape.h"
#include "h/smc_struct.h"
#include <fcntl.h>
#include <sys/mman.h>
#include <zlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <zlib.h>
using namespace castor::tape::tapeserver;
......@@ -83,8 +85,8 @@ TEST(tapeServer, DataTransferSessionGooddayRecall) {
uint32_t volReq = 0xBEEF;
std::string vid = "V12345";
std::string density = "8000GC";
client::ClientSimulator sim(volReq, vid, density, tapegateway::READ_TP,
tapegateway::READ);
client::ClientSimulator sim(volReq, vid, density,
castor::tape::tapegateway::READ_TP, castor::tape::tapegateway::READ);
client::ClientSimulator::ipPort clientAddr = sim.getCallbackAddress();
clientRunner simRun(sim);
simRun.start();
......@@ -149,7 +151,7 @@ TEST(tapeServer, DataTransferSessionGooddayRecall) {
sim.addFileToRecall(ftr, sizeof(data));
}
}
utils::DriveConfig driveConfig;
castor::tape::utils::DriveConfig driveConfig;
driveConfig.unitName = "T10D6116";
driveConfig.dgn = "T10KD6";
driveConfig.devFilename = "/dev/tape_T10D6116";
......@@ -164,7 +166,7 @@ TEST(tapeServer, DataTransferSessionGooddayRecall) {
castorConf.tapebridgeBulkRequestRecallMaxFiles = 1000;
castorConf.tapeserverdDiskThreads = 1;
castor::legacymsg::RmcProxyDummy rmc;
CapabilityUtilsDummy capUtils;
castor::utils::ProcessCap capUtils;
castor::messages::TapeserverProxyDummy initialProcess;
char argv_container [] = "tapeserver\0XXXXXXXX\0YYYYYYYYY\0ZZZZZZZZZZZ\0";
int argc = 4;
......@@ -196,8 +198,8 @@ TEST(tapeServer, DataTransferSessionNoSuchDrive) {
uint32_t volReq = 0xBEEF;
std::string vid = "V12345";
std::string density = "8000GC";
client::ClientSimulator sim(volReq, vid, density, tapegateway::READ_TP,
tapegateway::READ);
client::ClientSimulator sim(volReq, vid, density,
castor::tape::tapegateway::READ_TP, castor::tape::tapegateway::READ);
client::ClientSimulator::ipPort clientAddr = sim.getCallbackAddress();
clientRunner simRun(sim);
simRun.start();
......@@ -218,7 +220,7 @@ TEST(tapeServer, DataTransferSessionNoSuchDrive) {
mockSys.delegateToFake();
mockSys.disableGMockCallsCounting();
mockSys.fake.setupForVirtualDriveSLC6();
utils::DriveConfig driveConfig;
castor::tape::utils::DriveConfig driveConfig;
driveConfig.unitName = "T10D6116";
driveConfig.dgn = "T10KD6";
driveConfig.devFilename = "/dev/noSuchTape";
......@@ -233,7 +235,7 @@ TEST(tapeServer, DataTransferSessionNoSuchDrive) {
castor::legacymsg::VdqmProxyDummy vdqm(VDQMjob);
castor::legacymsg::RmcProxyDummy rmc;
castor::messages::TapeserverProxyDummy initialProcess;
CapabilityUtilsDummy capUtils;
castor::utils::ProcessCapDummy capUtils;
char argv_container [] = "tapeserver\0XXXXXXXX\0YYYYYYYYY\0ZZZZZZZZZZZ\0";
int argc = 4;
char * argv [4];
......@@ -322,8 +324,8 @@ TEST(tapeServer, DataTransferSessionGooddayMigration) {
uint32_t volReq = 0xBEEF;
std::string vid = "V12345";
std::string density = "8000GC";
client::ClientSimulator sim(volReq, vid, density, tapegateway::WRITE_TP,
tapegateway::WRITE);
client::ClientSimulator sim(volReq, vid, density,
castor::tape::tapegateway::WRITE_TP, castor::tape::tapegateway::WRITE);
client::ClientSimulator::ipPort clientAddr = sim.getCallbackAddress();
clientRunner simRun(sim);
simRun.start();
......@@ -370,7 +372,7 @@ TEST(tapeServer, DataTransferSessionGooddayMigration) {
expected.push_back(expectedResult(fseq, tf->checksum()));
tempFiles.push_back(tf.release());
}
utils::DriveConfig driveConfig;
castor::tape::utils::DriveConfig driveConfig;
driveConfig.unitName = "T10D6116";
driveConfig.dgn = "T10KD6";
driveConfig.devFilename = "/dev/tape_T10D6116";
......@@ -388,7 +390,7 @@ TEST(tapeServer, DataTransferSessionGooddayMigration) {
castor::legacymsg::VdqmProxyDummy vdqm(VDQMjob);
castor::legacymsg::RmcProxyDummy rmc;
castor::messages::TapeserverProxyDummy initialProcess;
CapabilityUtilsDummy capUtils;
castor::utils::ProcessCap capUtils;
char argv_container [] = "tapeserver\0XXXXXXXX\0YYYYYYYYY\0ZZZZZZZZZZZ\0";
int argc = 4;
char * argv [4];
......
/******************************************************************************
* castor/tape/tapeserver/daemon/ProcessForker.cpp
*
* 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 Steven.Murray@cern.ch
*****************************************************************************/
#include "castor/tape/tapeserver/daemon/ProcessForker.hpp"
#include "h/serrno.h"
#include <errno.h>
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::tape::tapeserver::daemon::ProcessForker::ProcessForker(log::Logger &log,
const int socketFd) throw(): m_log(log), m_socketFd(socketFd) {
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
castor::tape::tapeserver::daemon::ProcessForker::~ProcessForker() throw() {
if(-1 == close(m_socketFd)) {
char message[100];
sstrerror_r(errno, message, sizeof(message));
log::Param params[] = {log::Param("socketFd", m_socketFd),
log::Param("message", message)};
m_log(LOG_ERR, "Failed to close file-descriptor of ProcessForkerSocket",
params);
}
}
/******************************************************************************
* castor/tape/tapeserver/daemon/ProcessForker.hpp
*
* 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 Steven.Murray@cern.ch
*****************************************************************************/
#pragma once
#include "castor/log/Logger.hpp"
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
/**
* Class responsible for forking processes.
*/
class ProcessForker {
public:
/**
* Constructor.
*
* This class takes ownership of the socket used to communicate with the
* client. The destructor of this class will close the file-descriptor.
*
* @param log Object representing the API of the CASTOR logging system.
* @param socketFd The file-descriptor of the socket used to communicate with
* the client.
*/
ProcessForker(log::Logger &log, const int socketFd) throw();
/**
* Destructor.
*
* Closes the file-descriptor of the socket used to communicate with the
* client.
*/
~ProcessForker() throw();
private:
/**
* Object representing the API of the CASTOR logging system.
*/
log::Logger &m_log;
/**
* The file-descriptor of the socket used to communicate with the client.
*/
const int m_socketFd;
}; // class ProcessForker
} // namespace daemon
} // namespace tapeserver
} // namespace tape
} // namespace castor
/******************************************************************************
* castor/tape/tapeserver/daemon/CapabilityUtils.cpp
* castor/tape/tapeserver/daemon/ProcessForkerProxy.cpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
......@@ -22,10 +22,11 @@
* @author Steven.Murray@cern.ch
*****************************************************************************/
#include "castor/tape/tapeserver/daemon/CapabilityUtils.hpp"
#include "castor/tape/tapeserver/daemon/ProcessForkerProxy.hpp"
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
castor::tape::tapeserver::daemon::CapabilityUtils::~CapabilityUtils() throw() {
castor::tape::tapeserver::daemon::ProcessForkerProxy::~ProcessForkerProxy()
throw() {
}
/******************************************************************************
* castor/tape/tapeserver/daemon/CapabilityUtilsDummy.hpp
* castor/tape/tapeserver/daemon/ProcessForkerProxy.hpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
......@@ -24,10 +24,7 @@
#pragma once
#include "castor/tape/tapeserver/daemon/CapabilityUtils.hpp"
#include <string>
#include <sys/capability.h>
#include "castor/log/Logger.hpp"
namespace castor {
namespace tape {
......@@ -35,28 +32,31 @@ namespace tapeserver {
namespace daemon {
/**
* Concrete but dummy implementation of a utility class providing support for
* UNIX capabilities. This dummy class does nothing.
* Proxy class representing the process forker.
*/
class CapabilityUtilsDummy: public CapabilityUtils {
class ProcessForkerProxy {
public:
/**
* Destructor.
*/
~CapabilityUtilsDummy() throw();
virtual ~ProcessForkerProxy() throw() = 0;
/**
* Forks a mount-session process.
*/
virtual void forkMountSession() = 0;
/**
* C++ wrapper around the C functions cap_get_proc() and cap_to_text().
* Forks a label-session process.
*/
std::string capGetProcText();
virtual void forkLabelSession() = 0;
/**
* C++ wrapper around the C functions cap_from_text() and cap_set_proc().
* Forks a cleanup-session process.
*/
void capSetProcText(const std::string &text);
virtual void forkCleanupSession() = 0;
}; // class CapabilityUtils
}; // class ProcessForkerProxy
} // namespace daemon
} // namespace tapeserver
......
/******************************************************************************
* castor/tape/tapeserver/daemon/ProcessForkerProxySocket.cpp
*
* 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 Steven.Murray@cern.ch
*****************************************************************************/
#include "castor/tape/tapeserver/daemon/ProcessForkerProxySocket.hpp"
#include "h/serrno.h"
#include <errno.h>
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::tape::tapeserver::daemon::ProcessForkerProxySocket::
ProcessForkerProxySocket(log::Logger &log, const int socketFd) throw():
m_log(log), m_socketFd(socketFd) {
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
castor::tape::tapeserver::daemon::ProcessForkerProxySocket::
~ProcessForkerProxySocket() throw() {
if(-1 == close(m_socketFd)) {
char message[100];
sstrerror_r(errno, message, sizeof(message));
log::Param params[] = {log::Param("socketFd", m_socketFd),
log::Param("message", message)};
m_log(LOG_ERR,
"Failed to close file-descriptor of ProcessForkerProxySocket", params);
}
}
//------------------------------------------------------------------------------
// forkMountSession
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::ProcessForkerProxySocket::
forkMountSession() {
}
//------------------------------------------------------------------------------
// forkLabelSession
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::ProcessForkerProxySocket::
forkLabelSession() {
}
//------------------------------------------------------------------------------
// forkCleanupSession
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::ProcessForkerProxySocket::
forkCleanupSession() {
}
/******************************************************************************
* castor/tape/tapeserver/daemon/ProcessForkerProxySocket.hpp
*
* 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 Steven.Murray@cern.ch
*****************************************************************************/
#pragma once
#include "castor/log/Logger.hpp"
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
/**
* Concrete proxy class representing the process forker.
*
* This class uses a socket to communicate with the process forker.
*/
class ProcessForkerProxySocket {
public:
/**
* Constructor.
*
* This class takes ownership of the specified socket file-descriptor. The
* destructor of this class will close it.
*