diff --git a/tapeserver/castor/exception/Errnum.cpp b/tapeserver/castor/exception/Errnum.cpp deleted file mode 100644 index 8711523912b926bd76297787fbdf1c3cb1462c2f..0000000000000000000000000000000000000000 --- a/tapeserver/castor/exception/Errnum.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/exception/Errnum.hpp" -#include "common/utils/utils.hpp" - -#include <errno.h> -#include <string.h> - -using namespace castor::exception; - -Errnum::Errnum(std::string what):Exception("") { - m_errnum = errno; - ErrnumConstructorBottomHalf(what); -} - -Errnum::Errnum(int err, std::string what):Exception("") { - m_errnum = err; - ErrnumConstructorBottomHalf(what); -} - -void Errnum::ErrnumConstructorBottomHalf(const std::string & what) { - m_strerror = cta::utils::errnoToString(m_errnum); - std::stringstream w2; - if (what.size()) - w2 << what << " "; - w2 << "Errno=" << m_errnum << ": " << m_strerror; - getMessage().str(w2.str()); -} - -void Errnum::throwOnReturnedErrno (int err, std::string context) { - if (err) throw Errnum(err, context); -} - -void Errnum::throwOnNonZero(int status, std::string context) { - if (status) throw Errnum(context); -} - -void Errnum::throwOnZero(int status, std::string context) { - if (!status) throw Errnum(context); -} - -void Errnum::throwOnNull(void * f, std::string context) { - if (NULL == f) throw Errnum(context); -} - -void Errnum::throwOnNegative(int ret, std::string context) { - if (ret < 0) throw Errnum(context); -} - -void Errnum::throwOnMinusOne(int ret, std::string context) { - if (-1 == ret) throw Errnum(context); -} diff --git a/tapeserver/castor/exception/Errnum.hpp b/tapeserver/castor/exception/Errnum.hpp deleted file mode 100644 index 5d140c35d2ae29bdd90bc229cc32d8b9f8fcfddf..0000000000000000000000000000000000000000 --- a/tapeserver/castor/exception/Errnum.hpp +++ /dev/null @@ -1,50 +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 "common/exception/Exception.hpp" - -namespace castor { -namespace exception { - class Errnum: public cta::exception::Exception { - public: - Errnum(std::string what = ""); - Errnum (int err, std::string what = ""); - virtual ~Errnum() throw() {}; - int errorNumber() const { return m_errnum; } - std::string strError() const { return m_strerror; } - static void throwOnReturnedErrno(int err, std::string context = ""); - static void throwOnNonZero(int status, std::string context = ""); - static void throwOnZero(int status, std::string context = ""); - static void throwOnNull(void * f, std::string context = ""); - static void throwOnNegative(int ret, std::string context = ""); - static void throwOnMinusOne(int ret, std::string context = ""); - protected: - void ErrnumConstructorBottomHalf(const std::string & what); - int m_errnum; - std::string m_strerror; - }; -} -} diff --git a/tapeserver/castor/exception/ExceptionTest.cpp b/tapeserver/castor/exception/ExceptionTest.cpp index 392404273c2d3fc5ba3687b574c5f802139fb1e8..e6bf0ecdc5a18af714439e93bcd608e585a82346 100644 --- a/tapeserver/castor/exception/ExceptionTest.cpp +++ b/tapeserver/castor/exception/ExceptionTest.cpp @@ -22,7 +22,7 @@ *****************************************************************************/ #include "common/exception/Exception.hpp" -#include "Errnum.hpp" +#include "common/exception/Errnum.hpp" #include <errno.h> #include <gtest/gtest.h> @@ -75,51 +75,51 @@ namespace unitTests { } } - TEST(castor_exceptions, errnum_throwing) { + TEST(cta_exceptions, errnum_throwing) { /* Mickey Mouse test as we had trouble which throwing Errnum (with errno=ENOENT)*/ errno = ENOENT; try { - throw castor::exception::Errnum("Test ENOENT"); + throw cta::exception::Errnum("Test ENOENT"); } catch (std::exception & e) { std::string temp = e.what(); temp += " "; } } - TEST(castor_exceptions, Errnum_throwers) { + TEST(cta_exceptions, Errnum_throwers) { /* throwOnReturnedErrno */ - ASSERT_NO_THROW(castor::exception::Errnum::throwOnReturnedErrno(0, "Context")); - ASSERT_THROW(castor::exception::Errnum::throwOnReturnedErrno(ENOSPC, "Context"), - castor::exception::Errnum); + ASSERT_NO_THROW(cta::exception::Errnum::throwOnReturnedErrno(0, "Context")); + ASSERT_THROW(cta::exception::Errnum::throwOnReturnedErrno(ENOSPC, "Context"), + cta::exception::Errnum); /* throwOnNonZero */ errno = ENOENT; - ASSERT_NO_THROW(castor::exception::Errnum::throwOnNonZero(0, "Context")); - ASSERT_THROW(castor::exception::Errnum::throwOnNonZero(-1, "Context"), - castor::exception::Errnum); + ASSERT_NO_THROW(cta::exception::Errnum::throwOnNonZero(0, "Context")); + ASSERT_THROW(cta::exception::Errnum::throwOnNonZero(-1, "Context"), + cta::exception::Errnum); /* throwOnMinusOne */ errno = ENOENT; - ASSERT_NO_THROW(castor::exception::Errnum::throwOnMinusOne(0, "Context")); - ASSERT_THROW(castor::exception::Errnum::throwOnMinusOne(-1, "Context"), - castor::exception::Errnum); + ASSERT_NO_THROW(cta::exception::Errnum::throwOnMinusOne(0, "Context")); + ASSERT_THROW(cta::exception::Errnum::throwOnMinusOne(-1, "Context"), + cta::exception::Errnum); /* throwOnNegative */ errno = ENOENT; - ASSERT_NO_THROW(castor::exception::Errnum::throwOnNegative(0, "Context")); - ASSERT_THROW(castor::exception::Errnum::throwOnNegative(-1, "Context"), - castor::exception::Errnum); + ASSERT_NO_THROW(cta::exception::Errnum::throwOnNegative(0, "Context")); + ASSERT_THROW(cta::exception::Errnum::throwOnNegative(-1, "Context"), + cta::exception::Errnum); /* throwOnNull */ errno = ENOENT; - ASSERT_NO_THROW(castor::exception::Errnum::throwOnNull(this, "Context")); - ASSERT_THROW(castor::exception::Errnum::throwOnNull(NULL, "Context"), - castor::exception::Errnum); + ASSERT_NO_THROW(cta::exception::Errnum::throwOnNull(this, "Context")); + ASSERT_THROW(cta::exception::Errnum::throwOnNull(NULL, "Context"), + cta::exception::Errnum); /* throwOnZero */ errno = ENOENT; - ASSERT_NO_THROW(castor::exception::Errnum::throwOnZero(1, "Context")); - ASSERT_THROW(castor::exception::Errnum::throwOnZero(0, "Context"), - castor::exception::Errnum); + ASSERT_NO_THROW(cta::exception::Errnum::throwOnZero(1, "Context")); + ASSERT_THROW(cta::exception::Errnum::throwOnZero(0, "Context"), + cta::exception::Errnum); } } diff --git a/tapeserver/castor/io/IoTest.cpp b/tapeserver/castor/io/IoTest.cpp index 48af276c6471b264e130ab33acfd3af2e8a114fc..9a9504f48b040382fb00efd3743cb8c158a40246 100644 --- a/tapeserver/castor/io/IoTest.cpp +++ b/tapeserver/castor/io/IoTest.cpp @@ -24,7 +24,7 @@ #include "castor/io/io.hpp" #include "castor/utils/SmartFd.hpp" #include "castor/io/marshall.h" -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include <fcntl.h> #include <gtest/gtest.h> @@ -82,7 +82,7 @@ protected: strncpy(listenAddr.sun_path, listenSockPath, sizeof(listenAddr.sun_path) - 1); - castor::exception::Errnum::throwOnNonZero( + cta::exception::Errnum::throwOnNonZero( bind(smartListenSock.get(), (const struct sockaddr *)&listenAddr, sizeof(listenAddr)), "Call to bind() failed: "); } diff --git a/tapeserver/castor/messages/Mutex.cpp b/tapeserver/castor/messages/Mutex.cpp index 908b7d5da1e3e9d278c36c9bfc5bddac95af92d8..fdd3817f201a8f298aba328ea4499b608d9bdb0a 100644 --- a/tapeserver/castor/messages/Mutex.cpp +++ b/tapeserver/castor/messages/Mutex.cpp @@ -1,5 +1,5 @@ #include "castor/messages/Mutex.hpp" -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include "common/exception/Exception.hpp" //------------------------------------------------------------------------------ @@ -7,17 +7,17 @@ //------------------------------------------------------------------------------ castor::messages::Mutex::Mutex() { pthread_mutexattr_t attr; - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutexattr_init(&attr), "Error from pthread_mutexattr_init in castor::messages::Mutex::Mutex()"); - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK), "Error from pthread_mutexattr_settype in castor::messages::Mutex::Mutex()"); - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutex_init(&m_mutex, &attr), "Error from pthread_mutex_init in castor::messages::Mutex::Mutex()"); try { - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutexattr_destroy(&attr), "Error from pthread_mutexattr_destroy in" " castor::messages::Mutex::Mutex()"); @@ -38,7 +38,7 @@ castor::messages::Mutex::~Mutex() throw() { // lock //------------------------------------------------------------------------------ void castor::messages::Mutex::lock() { - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutex_lock(&m_mutex), "Error from pthread_mutex_lock in castor::messages::Mutex::lock()"); } @@ -47,7 +47,7 @@ void castor::messages::Mutex::lock() { // unlock //------------------------------------------------------------------------------ void castor::messages::Mutex::unlock() { - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutex_unlock(&m_mutex), "Error from pthread_mutex_unlock in castor::messages::Mutex::unlock()"); } diff --git a/tapeserver/castor/messages/MutexLockerTest.cpp b/tapeserver/castor/messages/MutexLockerTest.cpp index dc5524406c7a307255d233d72885e069cc96997a..47ac78299142f2e03fcccef3977e52917da5ceb0 100644 --- a/tapeserver/castor/messages/MutexLockerTest.cpp +++ b/tapeserver/castor/messages/MutexLockerTest.cpp @@ -21,7 +21,7 @@ * @author Castor Dev team, castor-dev@cern.ch *****************************************************************************/ -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include "castor/messages/MutexLocker.hpp" #include <gtest/gtest.h> @@ -46,7 +46,7 @@ TEST(castor_messages_MutexLockerTest, { MutexLocker ml(&m); // This is a different flavour of duplicate locking - ASSERT_THROW(m.lock(),castor::exception::Errnum); + ASSERT_THROW(m.lock(),cta::exception::Errnum); ASSERT_NO_THROW(m.unlock()); ASSERT_NO_THROW(m.lock()); } diff --git a/tapeserver/castor/messages/MutexTest.cpp b/tapeserver/castor/messages/MutexTest.cpp index b2a3fdde6ac1303bbb37b7441ad90c9727bbc7e0..cb5c6cc253099f7183bcbb96d85fb083a93bc5be 100644 --- a/tapeserver/castor/messages/MutexTest.cpp +++ b/tapeserver/castor/messages/MutexTest.cpp @@ -21,7 +21,7 @@ * @author Castor Dev team, castor-dev@cern.ch *****************************************************************************/ -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include "castor/messages/Mutex.hpp" #include <gtest/gtest.h> @@ -46,11 +46,11 @@ TEST(castor_messages_MutexTest, Mutex_properly_throws_exceptions) { ASSERT_NO_THROW(m.lock()); // Duplicate lock - ASSERT_THROW(m.lock(),castor::exception::Errnum); + ASSERT_THROW(m.lock(),cta::exception::Errnum); ASSERT_NO_THROW(m.unlock()); // Duplicate release - ASSERT_THROW(m.unlock(),castor::exception::Errnum); + ASSERT_THROW(m.unlock(),cta::exception::Errnum); } } // namespace unitTests diff --git a/tapeserver/castor/server/ChildProcess.hpp b/tapeserver/castor/server/ChildProcess.hpp index a12f6068ebdde9041c074389b3386d235c742df6..3e933da6b6984f0813ac2687986ad028599462c8 100644 --- a/tapeserver/castor/server/ChildProcess.hpp +++ b/tapeserver/castor/server/ChildProcess.hpp @@ -22,7 +22,7 @@ *****************************************************************************/ #pragma once -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include "common/exception/Exception.hpp" #include <unistd.h> diff --git a/tapeserver/castor/server/Daemon.cpp b/tapeserver/castor/server/Daemon.cpp index 677168f58f52de45d4ae6b510acb64a6088ae049..3ca40df70813fcb22a433f659b6f2d1930b55277 100644 --- a/tapeserver/castor/server/Daemon.cpp +++ b/tapeserver/castor/server/Daemon.cpp @@ -19,7 +19,7 @@ * @author Castor Dev team, castor-dev@cern.ch ******************************************************************************/ -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include "castor/server/Daemon.hpp" #include "castor/server/ThreadNotification.hpp" #include "castor/System.hpp" @@ -163,7 +163,7 @@ void castor::server::Daemon::daemonizeIfNotRunInForeground( { pid_t pid = 0; - castor::exception::Errnum::throwOnNegative(pid = fork(), + cta::exception::Errnum::throwOnNegative(pid = fork(), "Failed to daemonize: Failed to fork"); // If we got a good PID, then we can exit the parent process if (0 < pid) { @@ -179,17 +179,17 @@ void castor::server::Daemon::daemonizeIfNotRunInForeground( umask(0); // Run the daemon in a new session - castor::exception::Errnum::throwOnNegative(setsid(), + cta::exception::Errnum::throwOnNegative(setsid(), "Failed to daemonize: Failed to run daemon is a new session"); // Redirect standard files to /dev/null - castor::exception::Errnum::throwOnNull( + cta::exception::Errnum::throwOnNull( freopen("/dev/null", "r", stdin), "Failed to daemonize: Falied to freopen stdin"); - castor::exception::Errnum::throwOnNull( + cta::exception::Errnum::throwOnNull( freopen("/dev/null", "w", stdout), "Failed to daemonize: Failed to freopen stdout"); - castor::exception::Errnum::throwOnNull( + cta::exception::Errnum::throwOnNull( freopen("/dev/null", "w", stderr), "Failed to daemonize: Failed to freopen stderr"); } // if (!m_foreground) diff --git a/tapeserver/castor/server/Mutex.cpp b/tapeserver/castor/server/Mutex.cpp index 22f3b2d8dbbd5d3f70edfe0e477ef98750a3b9d9..6725415f8e21a4f9be21a4d43b150d035fd86b2e 100644 --- a/tapeserver/castor/server/Mutex.cpp +++ b/tapeserver/castor/server/Mutex.cpp @@ -1,5 +1,5 @@ #include "castor/server/Mutex.hpp" -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include "common/exception/Exception.hpp" //------------------------------------------------------------------------------ @@ -7,17 +7,17 @@ //------------------------------------------------------------------------------ castor::server::Mutex::Mutex() { pthread_mutexattr_t attr; - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutexattr_init(&attr), "Error from pthread_mutexattr_init in castor::server::Mutex::Mutex()"); - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK), "Error from pthread_mutexattr_settype in castor::server::Mutex::Mutex()"); - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutex_init(&m_mutex, &attr), "Error from pthread_mutex_init in castor::server::Mutex::Mutex()"); try { - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutexattr_destroy(&attr), "Error from pthread_mutexattr_destroy in castor::server::Mutex::Mutex()"); } catch (...) { @@ -35,7 +35,7 @@ castor::server::Mutex::~Mutex() { //lock //------------------------------------------------------------------------------ void castor::server::Mutex::lock() { - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutex_lock(&m_mutex), "Error from pthread_mutex_lock in castor::server::Mutex::lock()"); } @@ -43,7 +43,7 @@ void castor::server::Mutex::lock() { //unlock //------------------------------------------------------------------------------ void castor::server::Mutex::unlock() { - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutex_unlock(&m_mutex), "Error from pthread_mutex_unlock in castor::server::Mutex::unlock()"); } diff --git a/tapeserver/castor/server/Semaphores.cpp b/tapeserver/castor/server/Semaphores.cpp index 92e6cc048b9f488303bcb798219e0a0d9a5bc9ac..4e681bab19fe3524092c936d8f3bce42ed69da7e 100644 --- a/tapeserver/castor/server/Semaphores.cpp +++ b/tapeserver/castor/server/Semaphores.cpp @@ -1,7 +1,7 @@ #include "castor/server/MutexLocker.hpp" #include "castor/server/Semaphores.hpp" #include "castor/server/Threading.hpp" -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include "common/exception/Exception.hpp" #include <errno.h> #include <sys/time.h> @@ -11,7 +11,7 @@ //------------------------------------------------------------------------------ castor::server::PosixSemaphore::PosixSemaphore(int initial) { - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( sem_init(&m_sem, 0, initial), "Error from sem_init in castor::server::PosixSemaphore::PosixSemaphore()"); } @@ -34,7 +34,7 @@ void castor::server::PosixSemaphore::acquire() /* If we receive EINTR, we should just keep trying (signal interruption) */ while((ret = sem_wait(&m_sem)) && EINTR == errno) {} /* If it was not EINTR, it's a failure */ - castor::exception::Errnum::throwOnNonZero(ret, + cta::exception::Errnum::throwOnNonZero(ret, "Error from sem_wait in castor::server::PosixSemaphore::acquire()"); } //------------------------------------------------------------------------------ @@ -57,7 +57,7 @@ void castor::server::PosixSemaphore::acquireWithTimeout(uint64_t timeout_us) /* If we got a timeout, throw a special exception */ if (ret && ETIMEDOUT == errno) { throw Timeout(); } /* If it was not EINTR, it's a failure */ - castor::exception::Errnum::throwOnNonZero(ret, + cta::exception::Errnum::throwOnNonZero(ret, "Error from sem_wait in castor::server::PosixSemaphore::acquireWithTimeout()"); } @@ -69,7 +69,7 @@ bool castor::server::PosixSemaphore::tryAcquire() int ret = sem_trywait(&m_sem); if (!ret) return true; if (ret && EAGAIN == errno) return false; - castor::exception::Errnum::throwOnNonZero(ret, + cta::exception::Errnum::throwOnNonZero(ret, "Error from sem_trywait in castor::server::PosixSemaphore::tryAcquire()"); /* unreacheable, just for compiler happiness */ return false; @@ -81,7 +81,7 @@ void castor::server::PosixSemaphore::release(int n) { for (int i=0; i<n; i++) { MutexLocker ml(&m_mutexPosterProtection); - castor::exception::Errnum::throwOnNonZero(sem_post(&m_sem), + cta::exception::Errnum::throwOnNonZero(sem_post(&m_sem), "Error from sem_post in castor::server::PosixSemaphore::release()"); } } @@ -90,10 +90,10 @@ void castor::server::PosixSemaphore::release(int n) //------------------------------------------------------------------------------ castor::server::CondVarSemaphore::CondVarSemaphore(int initial) :m_value(initial) { - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_cond_init(&m_cond, NULL), "Error from pthread_cond_init in castor::server::CondVarSemaphore::CondVarSemaphore()"); - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutex_init(&m_mutex, NULL), "Error from pthread_mutex_init in castor::server::CondVarSemaphore::CondVarSemaphore()"); } @@ -115,16 +115,16 @@ castor::server::CondVarSemaphore::~CondVarSemaphore() { //------------------------------------------------------------------------------ void castor::server::CondVarSemaphore::acquire() { - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutex_lock(&m_mutex), "Error from pthread_mutex_lock in castor::server::CondVarSemaphore::acquire()"); while (m_value <= 0) { - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_cond_wait(&m_cond, &m_mutex), "Error from pthread_cond_wait in castor::server::CondVarSemaphore::acquire()"); } m_value--; - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutex_unlock(&m_mutex), "Error from pthread_mutex_unlock in castor::server::CondVarSemaphore::acquire()"); } @@ -134,7 +134,7 @@ void castor::server::CondVarSemaphore::acquire() bool castor::server::CondVarSemaphore::tryAcquire() { bool ret; - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutex_lock(&m_mutex), "Error from pthread_mutex_lock in castor::server::CondVarSemaphore::tryAcquire()"); if (m_value > 0) { @@ -143,7 +143,7 @@ bool castor::server::CondVarSemaphore::tryAcquire() } else { ret = false; } - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutex_unlock(&m_mutex), "Error from pthread_mutex_unlock in castor::server::CondVarSemaphore::tryAcquire()"); return ret; @@ -154,14 +154,14 @@ bool castor::server::CondVarSemaphore::tryAcquire() void castor::server::CondVarSemaphore::release(int n) { for (int i=0; i<n; i++) { - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutex_lock(&m_mutex), "Error from pthread_mutex_unlock in castor::server::CondVarSemaphore::release()"); m_value++; - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_cond_signal(&m_cond), "Error from pthread_cond_signal in castor::server::CondVarSemaphore::release()"); - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_mutex_unlock(&m_mutex), "Error from pthread_mutex_unlock in castor::server::CondVarSemaphore::release()"); } diff --git a/tapeserver/castor/server/Threading.cpp b/tapeserver/castor/server/Threading.cpp index 9dcc3bb0151da7c994d3336000cd727be1f46011..36d3f7c7cb87b413fccae13d3004045543e61f04 100644 --- a/tapeserver/castor/server/Threading.cpp +++ b/tapeserver/castor/server/Threading.cpp @@ -34,7 +34,7 @@ //------------------------------------------------------------------------------ void castor::server::Thread::start() { - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_create(&m_thread, NULL, pthread_runner, this), "Error from pthread_create in castor::server::Thread::start()"); } @@ -43,7 +43,7 @@ void castor::server::Thread::start() //------------------------------------------------------------------------------ void castor::server::Thread::wait() { - castor::exception::Errnum::throwOnReturnedErrno( + cta::exception::Errnum::throwOnReturnedErrno( pthread_join(m_thread, NULL), "Error from pthread_join in castor::server::Thread::wait()"); if (m_hadException) { diff --git a/tapeserver/castor/server/Threading.hpp b/tapeserver/castor/server/Threading.hpp index 03b7cb55a801ad01e7eb67322af5c6e807c8e353..543987fc79ccf381e1ff695259b892f453126311 100644 --- a/tapeserver/castor/server/Threading.hpp +++ b/tapeserver/castor/server/Threading.hpp @@ -25,7 +25,7 @@ #include <pthread.h> #include <semaphore.h> -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include "castor/server/Mutex.hpp" #include "common/exception/Exception.hpp" diff --git a/tapeserver/castor/server/ThreadingTests.cpp b/tapeserver/castor/server/ThreadingTests.cpp index e48581f1d7bfbf57f55e26bfba09cd3854951ece..5333e77242e79a8052f7c9937852e26d938ecb4d 100644 --- a/tapeserver/castor/server/ThreadingTests.cpp +++ b/tapeserver/castor/server/ThreadingTests.cpp @@ -39,10 +39,10 @@ namespace unitTests { castor::server::Mutex m; ASSERT_NO_THROW(m.lock()); /* Duplicate lock */ - ASSERT_THROW(m.lock(),castor::exception::Errnum); + ASSERT_THROW(m.lock(),cta::exception::Errnum); ASSERT_NO_THROW(m.unlock()); /* Duplicate release */ - ASSERT_THROW(m.unlock(),castor::exception::Errnum); + ASSERT_THROW(m.unlock(),cta::exception::Errnum); } TEST(castor_tape_threading, MutexLocker_locks_and_properly_throws_exceptions) { @@ -50,7 +50,7 @@ namespace unitTests { { castor::server::MutexLocker ml(&m); /* This is a different flavourr of duplicate locking */ - ASSERT_THROW(m.lock(),castor::exception::Errnum); + ASSERT_THROW(m.lock(),cta::exception::Errnum); ASSERT_NO_THROW(m.unlock()); ASSERT_NO_THROW(m.lock()); } diff --git a/tapeserver/castor/tape/tapeserver/SCSI/Device.cpp b/tapeserver/castor/tape/tapeserver/SCSI/Device.cpp index 10f0e301b3c73e842629e2cdfced96511acb6bd8..cefbee8ca9aae0842f7fe1cb188ce7847413b2a4 100644 --- a/tapeserver/castor/tape/tapeserver/SCSI/Device.cpp +++ b/tapeserver/castor/tape/tapeserver/SCSI/Device.cpp @@ -25,7 +25,7 @@ #include <scsi/sg.h> #include "Device.hpp" -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" using namespace castor::tape; @@ -40,7 +40,7 @@ SCSI::DeviceVector::DeviceVector(System::virtualWrapper& sysWrapper) : m_sysWrap utils::Regex ifFirstCharIsDigit("^[[:digit:]]"); std::vector<std::string> checkResult; DIR* dirp; - castor::exception::Errnum::throwOnNull( + cta::exception::Errnum::throwOnNull( dirp = m_sysWrapper.opendir(sysDevsPath.c_str()), "Error opening sysfs scsi devs"); while (struct dirent * dent = m_sysWrapper.readdir(dirp)) { @@ -51,7 +51,7 @@ SCSI::DeviceVector::DeviceVector(System::virtualWrapper& sysWrapper) : m_sysWrap std::string fullpath = sysDevsPath + "/" + std::string(dent->d_name); /* We expect only symbolic links in this directory, */ char rp[PATH_MAX]; - castor::exception::Errnum::throwOnNull( + cta::exception::Errnum::throwOnNull( m_sysWrapper.realpath(fullpath.c_str(), rp), "Could not find realpath for " + fullpath); this->push_back(getDeviceInfo(rp)); @@ -61,7 +61,7 @@ SCSI::DeviceVector::DeviceVector(System::virtualWrapper& sysWrapper) : m_sysWrap SCSI::DeviceInfo & SCSI::DeviceVector::findBySymlink(std::string path) { struct stat sbuff; - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.stat(path.c_str(), &sbuff), std::string("Could not stat path: ")+path); for(std::vector<DeviceInfo>::iterator i = begin(); i!= end(); i++) { @@ -75,17 +75,17 @@ SCSI::DeviceInfo & SCSI::DeviceVector::findBySymlink(std::string path) { std::string SCSI::DeviceVector::readfile(std::string path) { int fd; - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( fd = m_sysWrapper.open(path.c_str(), 0), std::string("Could not open file ") + path); char buf[readfileBlockSize]; std::string ret; while (ssize_t sread = m_sysWrapper.read(fd, buf, readfileBlockSize)) { - castor::exception::Errnum::throwOnMinusOne(sread, + cta::exception::Errnum::throwOnMinusOne(sread, std::string("Could not read from open file ") + path); ret.append(buf, sread); } - castor::exception::Errnum::throwOnNonZero( + cta::exception::Errnum::throwOnNonZero( m_sysWrapper.close(fd), std::string("Error closing file ") + path); return ret; @@ -101,7 +101,7 @@ SCSI::DeviceInfo::DeviceFile SCSI::DeviceVector::readDeviceFile(std::string path SCSI::DeviceInfo::DeviceFile SCSI::DeviceVector::statDeviceFile(std::string path) { struct stat sbuf; - castor::exception::Errnum::throwOnNonZero( + cta::exception::Errnum::throwOnNonZero( m_sysWrapper.stat(path.c_str(), &sbuf), std::string("Could not stat file ") + path); if (!S_ISCHR(sbuf.st_mode)) @@ -133,7 +133,7 @@ void SCSI::DeviceVector::getTapeInfo(DeviceInfo & devinfo) { if (!dirp) { /* here we open sysfs_entry for SLC5 */ - castor::exception::Errnum::throwOnNull( + cta::exception::Errnum::throwOnNull( dirp = m_sysWrapper.opendir(devinfo.sysfs_entry.c_str()), std::string("Error opening tape device directory ") + devinfo.sysfs_entry + tapeDir+" or "+devinfo.sysfs_entry); @@ -233,7 +233,7 @@ SCSI::DeviceInfo SCSI::DeviceVector::getDeviceInfo(const char * path) { char rl[PATH_MAX]; std::string lp = ret.sysfs_entry + "/generic"; ssize_t rlSize; - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( rlSize = m_sysWrapper.readlink(lp.c_str(), rl, sizeof (rl) - 1), std::string("Could not read link ") + lp); rl[rlSize] = '\0'; diff --git a/tapeserver/castor/tape/tapeserver/SCSI/DeviceTest.cpp b/tapeserver/castor/tape/tapeserver/SCSI/DeviceTest.cpp index 1feccd3a592256d97e66a0acec57f66b234a7e95..0d89e4d91bb915d1b9c4b4f040bdbc62971022e8 100644 --- a/tapeserver/castor/tape/tapeserver/SCSI/DeviceTest.cpp +++ b/tapeserver/castor/tape/tapeserver/SCSI/DeviceTest.cpp @@ -25,7 +25,7 @@ #include <gmock/gmock-cardinalities.h> #include "Device.hpp" #include "../system/Wrapper.hpp" -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" using ::testing::AtLeast; using ::testing::Return; @@ -133,7 +133,7 @@ TEST(castor_tape_SCSI_DeviceList, FindBySymlink) { castor::tape::SCSI::DeviceVector dl(sysWrapper); ASSERT_NO_THROW(dl.findBySymlink("/dev/tape_T10D6116")); ASSERT_THROW(dl.findBySymlink("NoSuchPath"), - castor::exception::Errnum); + cta::exception::Errnum); ASSERT_THROW(dl.findBySymlink("/dev/noSuchTape"), castor::tape::SCSI::DeviceVector::NotFound); castor::tape::SCSI::DeviceInfo & di = dl.findBySymlink("/dev/tape_T10D6116"); diff --git a/tapeserver/castor/tape/tapeserver/daemon/TapeDaemon.cpp b/tapeserver/castor/tape/tapeserver/daemon/TapeDaemon.cpp index f54640aea57c43c8926368d9ce027b2a944cdd12..64014a907fe6a0c94ada18825838c41af467b7ee 100644 --- a/tapeserver/castor/tape/tapeserver/daemon/TapeDaemon.cpp +++ b/tapeserver/castor/tape/tapeserver/daemon/TapeDaemon.cpp @@ -22,7 +22,7 @@ *****************************************************************************/ #include "castor/common/CastorConfiguration.hpp" -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include "common/exception/BadAlloc.hpp" #include "castor/io/io.hpp" #include "castor/legacymsg/CommonMarshal.hpp" @@ -517,7 +517,7 @@ void castor::tape::tapeserver::daemon::TapeDaemon::blockSignals() const { sigaddset(&sigs, SIGPOLL); sigaddset(&sigs, SIGURG); sigaddset(&sigs, SIGVTALRM); - castor::exception::Errnum::throwOnNonZero( + cta::exception::Errnum::throwOnNonZero( sigprocmask(SIG_BLOCK, &sigs, NULL), "Failed to block signals: sigprocmask() failed"); } diff --git a/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.cpp b/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.cpp index 1190423f4423f24b1466bc7c758baa2efd83a04e..6cf312c8c70b843016d052f68b95eec0362a3524 100644 --- a/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.cpp +++ b/tapeserver/castor/tape/tapeserver/daemon/TapeWriteSingleThread.cpp @@ -295,8 +295,8 @@ void castor::tape::tapeserver::daemon::TapeWriteSingleThread::run() { // If it's not the error we're looking for, we will go about our business // in the catch section. dynamic cast will throw, and we'll do ourselves // if the error code is not the one we want. - const castor::exception::Errnum & en = - dynamic_cast<const castor::exception::Errnum &>(e); + const cta::exception::Errnum & en = + dynamic_cast<const cta::exception::Errnum &>(e); if(en.errorNumber()!= ENOSPC) { throw 0; } @@ -326,8 +326,8 @@ void castor::tape::tapeserver::daemon::TapeWriteSingleThread::run() { // Override if we got en ENOSPC error (end of tape) // This is try { - const castor::exception::Errnum & errnum = - dynamic_cast<const castor::exception::Errnum &> (e); + const cta::exception::Errnum & errnum = + dynamic_cast<const cta::exception::Errnum &> (e); if (ENOSPC == errnum.errorNumber()) { errorCode = ENOSPC; errorMessage = "End of migration due to tape full"; diff --git a/tapeserver/castor/tape/tapeserver/daemon/TapeWriteTask.cpp b/tapeserver/castor/tape/tapeserver/daemon/TapeWriteTask.cpp index 7359656e21d0fefc7eac7cd1cbd89f76b1f25da8..81d6601d6609ef35e465c1899fe13713e2fc10f0 100644 --- a/tapeserver/castor/tape/tapeserver/daemon/TapeWriteTask.cpp +++ b/tapeserver/castor/tape/tapeserver/daemon/TapeWriteTask.cpp @@ -21,7 +21,7 @@ * @author Castor Dev team, castor-dev@cern.ch *****************************************************************************/ -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include "castor/tape/tapeserver/daemon/TapeWriteTask.hpp" #include "castor/tape/tapeserver/daemon/DataPipeline.hpp" #include "castor/tape/tapeserver/daemon/MigrationMemoryManager.hpp" @@ -166,8 +166,8 @@ namespace daemon { // If it's not the error we're looking for, we will go about our business // in the catch section. dynamic cast will throw, and we'll do ourselves // if the error code is not the one we want. - const castor::exception::Errnum & en = - dynamic_cast<const castor::exception::Errnum &>(e); + const cta::exception::Errnum & en = + dynamic_cast<const cta::exception::Errnum &>(e); if(en.errorNumber()!= ENOSPC) { throw 0; } @@ -192,8 +192,8 @@ namespace daemon { int errorCode = 666; // TODO - Remove error code int errorLevel = LOG_ERR; try { - const castor::exception::Errnum & errnum = - dynamic_cast<const castor::exception::Errnum &> (e); + const cta::exception::Errnum & errnum = + dynamic_cast<const cta::exception::Errnum &> (e); if (ENOSPC == errnum.errorNumber()) { errorCode = ENOSPC; errorLevel = LOG_INFO; diff --git a/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp b/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp index 3b596566ae6a685ac3aef78d493d4b4818572426..4d134f0972d6de63d373889f8a36bc2b44bbf76d 100644 --- a/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp +++ b/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp @@ -63,7 +63,7 @@ m_tapeFD(-1), m_sysWrapper(sw), m_lbpToUse(lbpToUse::disabled) { /* We open the tape device file non-blocking as blocking open on rewind tapes (at least) * will fail after a long timeout when no tape is present (at least with mhvtl) */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_tapeFD = m_sysWrapper.open(m_SCSIInfo.nst_dev.c_str(), O_RDWR | O_NONBLOCK), std::string("Could not open device file: ") + m_SCSIInfo.nst_dev); } @@ -86,7 +86,7 @@ void drive::DriveGeneric::clearCompressionStats() { sgh.dxfer_direction = SG_DXFER_NONE; /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl in DriveGeneric::clearCompressionStats"); SCSI::ExceptionLauncher(sgh, "SCSI error in clearCompressionStats:"); @@ -111,7 +111,7 @@ drive::deviceInfo drive::DriveGeneric::getDeviceInfo() { sgh.dxfer_direction = SG_DXFER_FROM_DEV; /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl in DriveGeneric::getDeviceInfo"); SCSI::ExceptionLauncher(sgh, "SCSI error in getDeviceInfo:"); @@ -144,7 +144,7 @@ std::string drive::DriveGeneric::getSerialNumber() { sgh.dxfer_direction = SG_DXFER_FROM_DEV; /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl in DriveGeneric::getSerialNumber"); SCSI::ExceptionLauncher(sgh, "SCSI error in getSerialNumber:"); @@ -175,7 +175,7 @@ void drive::DriveGeneric::positionToLogicalObject(uint32_t blockId) //sgh.timeout = defaultTimeout; // set globally by SCSI::Structures.hpp (defaultTimeout) /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl in DriveGeneric::positionToLogicalObject"); SCSI::ExceptionLauncher(sgh, "SCSI error in positionToLogicalObject:"); @@ -206,7 +206,7 @@ drive::positionInfo drive::DriveGeneric::getPositionInfo() sgh.dxfer_direction = SG_DXFER_FROM_DEV; /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl in DriveGeneric::getPositionInfo"); SCSI::ExceptionLauncher(sgh, "SCSI error in getPositionInfo:"); @@ -253,7 +253,7 @@ std::vector<uint16_t> drive::DriveGeneric::getTapeAlertCodes(){ sgh.setSenseBuffer(&senseBuff); sgh.dxfer_direction = SG_DXFER_FROM_DEV; /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl in DriveGeneric::getTapeAlerts"); SCSI::ExceptionLauncher(sgh, "SCSI error in getTapeAlerts:"); @@ -323,7 +323,7 @@ void drive::DriveGeneric::setDensityAndCompression(bool compression, sgh.dxfer_direction = SG_DXFER_FROM_DEV; /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl in DriveGeneric::setDensityAndCompression"); SCSI::ExceptionLauncher(sgh, "SCSI error in setDensityAndCompression:"); @@ -348,7 +348,7 @@ void drive::DriveGeneric::setDensityAndCompression(bool compression, sgh.dxfer_direction = SG_DXFER_TO_DEV; /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl in DriveGeneric::setDensityAndCompression"); SCSI::ExceptionLauncher(sgh, "SCSI error in setDensityAndCompression:"); @@ -379,7 +379,7 @@ void drive::DriveGeneric::setLogicalBlockProtection( sgh.dxfer_direction = SG_DXFER_FROM_DEV; /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl" ); SCSI::ExceptionLauncher(sgh, @@ -417,7 +417,7 @@ void drive::DriveGeneric::setLogicalBlockProtection( sgh.dxfer_direction = SG_DXFER_TO_DEV; /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl" ); SCSI::ExceptionLauncher(sgh, @@ -474,7 +474,7 @@ drive::LBPInfo drive::DriveGeneric::getLBPInfo() { sgh.dxfer_direction = SG_DXFER_FROM_DEV; /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl" ); SCSI::ExceptionLauncher(sgh, @@ -531,7 +531,7 @@ void drive::DriveGeneric::setSTBufferWrite(bool bufWrite) { struct mtop m_mtCmd; m_mtCmd.mt_op = MTSETDRVBUFFER; m_mtCmd.mt_count = bufWrite ? (MT_ST_SETBOOLEANS | MT_ST_BUFFER_WRITES) : (MT_ST_CLEARBOOLEANS | MT_ST_BUFFER_WRITES); - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd), "Failed ST ioctl (MTSETDRVBUFFER) in DriveGeneric::setSTBufferWrite"); } @@ -549,7 +549,7 @@ void drive::DriveGeneric::spaceToEOM(void) { struct mtop m_mtCmd; m_mtCmd.mt_op = MTEOM; m_mtCmd.mt_count = 1; - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd), "Failed ST ioctl (MTEOM) in DriveGeneric::spaceToEOM"); } @@ -564,7 +564,7 @@ void drive::DriveGeneric::setSTFastMTEOM(bool fastMTEOM) { struct mtop m_mtCmd; m_mtCmd.mt_op = MTSETDRVBUFFER; m_mtCmd.mt_count = fastMTEOM ? (MT_ST_SETBOOLEANS | MT_ST_FAST_MTEOM) : (MT_ST_CLEARBOOLEANS | MT_ST_FAST_MTEOM); - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd), "Failed ST ioctl (MTSETDRVBUFFER) in DriveGeneric::setSTFastMTEOM"); } @@ -578,7 +578,7 @@ void drive::DriveGeneric::fastSpaceToEOM(void) { struct mtop m_mtCmd; m_mtCmd.mt_op = MTEOM; m_mtCmd.mt_count = 1; - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd), "Failed ST ioctl (MTEOM) in DriveGeneric::fastSpaceToEOM"); } @@ -590,7 +590,7 @@ void drive::DriveGeneric::rewind(void) { struct mtop m_mtCmd; m_mtCmd.mt_op = MTREW; m_mtCmd.mt_count = 1; - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd), "Failed ST ioctl (MTREW) in DriveGeneric::rewind"); } @@ -606,7 +606,7 @@ void drive::DriveGeneric::spaceFileMarksBackwards(size_t count) { while (tobeskipped > 0) { size_t c = (tobeskipped > 0x7FFFFF) ? 0x7FFFFF : tobeskipped; m_mtCmd.mt_count = (int)c; - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd), "Failed ST ioctl (MTBSF) in DriveGeneric::spaceFileMarksBackwards"); tobeskipped -= c; @@ -624,7 +624,7 @@ void drive::DriveGeneric::spaceFileMarksForward(size_t count) { while (tobeskipped > 0) { size_t c = (tobeskipped > 0x7FFFFF) ? 0x7FFFFF : tobeskipped; m_mtCmd.mt_count = (int)c; - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd), "Failed ST ioctl (MTFSF) in DriveGeneric::spaceFileMarksForward"); tobeskipped -= c; @@ -638,7 +638,7 @@ void drive::DriveGeneric::unloadTape(void) { struct mtop m_mtCmd; m_mtCmd.mt_op = MTUNLOAD; m_mtCmd.mt_count = 1; - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd), "Failed ST ioctl (MTUNLOAD) in DriveGeneric::unloadTape"); } @@ -653,7 +653,7 @@ void drive::DriveGeneric::flush(void) { // The following text is a quote from the SCSI Stream commands manual (SSC-3): // NOTE 25 Upon completion of any buffered write operation, the application client may issue a WRITE FILEMARKS(16) command with the IMMED bit set to zero and the FILEMARK COUNT field set to zero to perform a synchronize operation (see 4.2.10). m_mtCmd.mt_count = 0; - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd), "Failed ST ioctl (MTWEOF) in DriveGeneric::flush"); } @@ -667,7 +667,7 @@ void drive::DriveGeneric::writeSyncFileMarks(size_t count) { struct mtop m_mtCmd; m_mtCmd.mt_op = MTWEOF; m_mtCmd.mt_count = (int)count; - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd), "Failed ST ioctl (MTWEOF) in DriveGeneric::writeSyncFileMarks"); } @@ -681,7 +681,7 @@ void drive::DriveGeneric::writeImmediateFileMarks(size_t count) { struct mtop m_mtCmd; m_mtCmd.mt_op = MTWEOFI; //Undocumented in "man st" needs the mtio_add.hh header file (see above) m_mtCmd.mt_count = (int)count; - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCTOP, &m_mtCmd), "Failed ST ioctl (MTWEOFI) in DriveGeneric::writeImmediateFileMarks"); } @@ -709,14 +709,14 @@ void drive::DriveGeneric::writeBlock(const void * data, size_t count) { if (countWithCrc32c != count+SCSI::logicBlockProtectionMethod::CRC32CLength) { delete[] dataWithCrc32c; - castor::exception::Errnum::throwOnMinusOne(-1, + cta::exception::Errnum::throwOnMinusOne(-1, "Failed in DriveGeneric::writeBlock: incorrect length for block" " with crc32c"); } if (-1 == m_sysWrapper.write(m_tapeFD, dataWithCrc32c, countWithCrc32c)) { delete[] dataWithCrc32c; - castor::exception::Errnum::throwOnMinusOne(-1, + cta::exception::Errnum::throwOnMinusOne(-1, "Failed ST write in DriveGeneric::writeBlock"); } delete[] dataWithCrc32c; @@ -727,7 +727,7 @@ void drive::DriveGeneric::writeBlock(const void * data, size_t count) { "trying to write a block in CRC-readonly mode"); case lbpToUse::disabled: { - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.write(m_tapeFD, data, count), "Failed ST write in DriveGeneric::writeBlock"); break; @@ -758,7 +758,7 @@ ssize_t drive::DriveGeneric::readBlock(void * data, size_t count) { count+SCSI::logicBlockProtectionMethod::CRC32CLength); if ( -1 == res ) { delete[] dataWithCrc32c; - castor::exception::Errnum::throwOnMinusOne(res, + cta::exception::Errnum::throwOnMinusOne(res, "In DriveGeneric::readBlock: Failed ST read (with checksum)"); } if ( 0 == res ) { @@ -788,7 +788,7 @@ ssize_t drive::DriveGeneric::readBlock(void * data, size_t count) { case lbpToUse::disabled: { ssize_t res = m_sysWrapper.read(m_tapeFD, data, count); - castor::exception::Errnum::throwOnMinusOne(res, + cta::exception::Errnum::throwOnMinusOne(res, "In DriveGeneric::readBlock: Failed ST read"); return res; } @@ -826,7 +826,7 @@ void drive::DriveGeneric::readExactBlock(void * data, size_t count, std::string // Generic handling of other errors if (-1 == res) { delete[] dataWithCrc32c; - castor::exception::Errnum::throwOnMinusOne(res, + cta::exception::Errnum::throwOnMinusOne(res, context+": Failed ST read in DriveGeneric::readExactBlock"); } // Handle mismatch @@ -855,7 +855,7 @@ void drive::DriveGeneric::readExactBlock(void * data, size_t count, std::string if (-1 == res && ENOSPC == errno) throw UnexpectedSize(context); // Generic handling of other errors - castor::exception::Errnum::throwOnMinusOne(res, + cta::exception::Errnum::throwOnMinusOne(res, context+": Failed ST read in DriveGeneric::readExactBlock"); // Handle block too small if ((size_t) res != count) @@ -879,7 +879,7 @@ void drive::DriveGeneric::readFileMark(std::string context) { if (-1 == res && ENOSPC == errno) throw NotAFileMark(context); // Generic handling of other errors - castor::exception::Errnum::throwOnMinusOne(res, + cta::exception::Errnum::throwOnMinusOne(res, context+": Failed ST read in DriveGeneric::readFileMark"); // Handle the unlikely case when the block fits if (res) @@ -902,7 +902,7 @@ void drive::DriveGeneric::SCSI_inquiry() { sgh.setSenseBuffer(&senseBuff); sgh.setDataBuffer(dataBuff); sgh.dxfer_direction = SG_DXFER_FROM_DEV; - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl in DriveGeneric::SCSI_inquiry"); @@ -938,7 +938,7 @@ drive::compressionStats drive::DriveT10000::getCompression() { sgh.dxfer_direction = SG_DXFER_FROM_DEV; /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(this->m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl in DriveT10000::getCompression"); SCSI::ExceptionLauncher(sgh, "SCSI error in DriveT10000::getCompression:"); @@ -1025,7 +1025,7 @@ drive::compressionStats drive::DriveLTO::getCompression() { sgh.dxfer_direction = SG_DXFER_FROM_DEV; /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(this->m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl in DriveLTO::getCompression"); SCSI::ExceptionLauncher(sgh, "SCSI error in DriveLTO::getCompression:"); @@ -1099,7 +1099,7 @@ drive::compressionStats drive::DriveIBM3592::getCompression() { sgh.dxfer_direction = SG_DXFER_FROM_DEV; /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(this->m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl in DriveIBM3592::getCompression"); SCSI::ExceptionLauncher(sgh, "SCSI error in DriveIBM3592::getCompression:"); @@ -1149,7 +1149,7 @@ void drive::DriveGeneric::testUnitReady() const { sgh.dxfer_direction = SG_DXFER_NONE; /* Manage both system error and SCSI errors. */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, SG_IO, &sgh), "Failed SG_IO ioctl in DriveGeneric::testUnitReady"); @@ -1164,16 +1164,16 @@ void drive::DriveGeneric::waitUntilReady(const uint32_t timeoutSecond) { waitTestUnitReady(timeoutSecond); // we need to reopen the drive to update the GMT_ONLINE cache of the st driver - castor::exception::Errnum::throwOnMinusOne(m_sysWrapper.close(m_tapeFD), + cta::exception::Errnum::throwOnMinusOne(m_sysWrapper.close(m_tapeFD), std::string("Could not close device file: ") + m_SCSIInfo.nst_dev); - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_tapeFD = m_sysWrapper.open(m_SCSIInfo.nst_dev.c_str(), O_RDWR | O_NONBLOCK), std::string("Could not open device file: ") + m_SCSIInfo.nst_dev); struct mtget mtInfo; /* Read drive status */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCGET, &mtInfo), std::string("Could not read drive status: ") + m_SCSIInfo.nst_dev); diff --git a/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.hpp b/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.hpp index 55ca331555e737b1352a93be48f2dba8b50e1d5d..656b2f135c82adfe10581c744762014547ba133d 100644 --- a/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.hpp +++ b/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.hpp @@ -168,7 +168,7 @@ namespace drive { struct mtget mtInfo; /* Read drive status */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCGET, &mtInfo), std::string("Could not read drive status: ") + m_SCSIInfo.nst_dev); return GMT_DR_OPEN(mtInfo.mt_gstat) == 0; @@ -179,7 +179,7 @@ namespace drive { struct mtget mtInfo; /* Read drive status */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCGET, &mtInfo), std::string("Could not read drive status: ") + m_SCSIInfo.nst_dev); return GMT_WR_PROT(mtInfo.mt_gstat)!=0; @@ -190,7 +190,7 @@ namespace drive { struct mtget mtInfo; /* Read drive status */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCGET, &mtInfo), std::string("Could not read drive status: ") + m_SCSIInfo.nst_dev); @@ -202,7 +202,7 @@ namespace drive { struct mtget mtInfo; /* Read drive status */ - castor::exception::Errnum::throwOnMinusOne( + cta::exception::Errnum::throwOnMinusOne( m_sysWrapper.ioctl(m_tapeFD, MTIOCGET, &mtInfo), std::string("Could not read drive status: ") + m_SCSIInfo.nst_dev); return GMT_EOD(mtInfo.mt_gstat)!=0; diff --git a/tapeserver/castor/tape/tapeserver/drive/DriveInterface.hpp b/tapeserver/castor/tape/tapeserver/drive/DriveInterface.hpp index 671007766149f8071db780eb026444243330dcc7..3819955a00de9a53d67b26a0f22379507d163b0f 100644 --- a/tapeserver/castor/tape/tapeserver/drive/DriveInterface.hpp +++ b/tapeserver/castor/tape/tapeserver/drive/DriveInterface.hpp @@ -23,7 +23,7 @@ #pragma once -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include "castor/tape/tapeserver/daemon/DriveConfig.hpp" #include "castor/tape/tapeserver/drive/mtio_add.hpp" #include "castor/tape/tapeserver/SCSI/Device.hpp" diff --git a/tapeserver/castor/tape/tapeserver/drive/FakeDrive.cpp b/tapeserver/castor/tape/tapeserver/drive/FakeDrive.cpp index 113543c3c56f1b181c3cca4165fde28814dd2bfb..5922947fc8205062b8873a82623f9f0bc6cf8835 100644 --- a/tapeserver/castor/tape/tapeserver/drive/FakeDrive.cpp +++ b/tapeserver/castor/tape/tapeserver/drive/FakeDrive.cpp @@ -156,7 +156,7 @@ void castor::tape::tapeserver::drive::FakeDrive::spaceFileMarksForward(size_t co if(!m_tape[i].data.compare(filemark)) countdown--; } if(countdown) { - throw castor::exception::Errnum(EIO, "Failed FakeDrive::spaceFileMarksForward"); + throw cta::exception::Errnum(EIO, "Failed FakeDrive::spaceFileMarksForward"); } m_currentPosition = i; //EOT side of the filemark } @@ -165,7 +165,7 @@ void castor::tape::tapeserver::drive::FakeDrive::unloadTape(void) { void castor::tape::tapeserver::drive::FakeDrive::flush(void) { if (m_failureMoment == OnFlush) { if (m_tapeOverflow) { - throw castor::exception::Errnum(ENOSPC, "Error in castor::tape::tapeserver::drive::FakeDrive::flush"); + throw cta::exception::Errnum(ENOSPC, "Error in castor::tape::tapeserver::drive::FakeDrive::flush"); } } } @@ -196,7 +196,7 @@ void castor::tape::tapeserver::drive::FakeDrive::writeBlock(const void * data, s uint64_t remainingSpaceAfterBlock; if (count > getRemaingSpace(m_currentPosition)) { if (m_failureMoment == OnWrite) { - throw castor::exception::Errnum(ENOSPC, "Error in castor::tape::tapeserver::drive::FakeDrive::writeBlock"); + throw cta::exception::Errnum(ENOSPC, "Error in castor::tape::tapeserver::drive::FakeDrive::writeBlock"); } else { remainingSpaceAfterBlock = 0; m_tapeOverflow = true; diff --git a/tapeserver/castor/tape/tapeserver/file/DiskFile.cpp b/tapeserver/castor/tape/tapeserver/file/DiskFile.cpp index febbe163ae97720d97b32a6b6bfb7d91fc87ee22..e32c8b148ef3aec8847027e96251655eda1753a7 100644 --- a/tapeserver/castor/tape/tapeserver/file/DiskFile.cpp +++ b/tapeserver/castor/tape/tapeserver/file/DiskFile.cpp @@ -25,7 +25,7 @@ #include "castor/common/CastorConfiguration.hpp" #include "castor/tape/tapeserver/file/DiskFile.hpp" #include "castor/tape/tapeserver/file/DiskFileImplementations.hpp" -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include "castor/server/MutexLocker.hpp" #include <xrootd/XrdCl/XrdClFile.hh> #include <uuid/uuid.h> @@ -71,7 +71,7 @@ const CryptoPP::RSA::PrivateKey & DiskFileFactory::xrootPrivateKey() { std::ifstream keyFile(m_xrootPrivateKeyFile.c_str()); if (!keyFile) { // We should get the detailed error from errno. - throw castor::exception::Errnum( + throw cta::exception::Errnum( std::string("Failed to open xroot key file: ")+m_xrootPrivateKeyFile); } char buff[200]; @@ -228,7 +228,7 @@ LocalReadFile::LocalReadFile(const std::string &path) { m_fd = ::open64((char *)path.c_str(), O_RDONLY); m_URL = "file://"; m_URL += path; - castor::exception::Errnum::throwOnMinusOne(m_fd, + cta::exception::Errnum::throwOnMinusOne(m_fd, std::string("In diskFile::LocalReadFile::LocalReadFile failed open64() on ")+m_URL); } @@ -241,7 +241,7 @@ size_t LocalReadFile::size() const { //struct is mandatory here, because there is a function stat64 struct stat64 statbuf; int ret = ::fstat64(m_fd,&statbuf); - castor::exception::Errnum::throwOnMinusOne(ret, + cta::exception::Errnum::throwOnMinusOne(ret, std::string("In diskFile::LocalReadFile::LocalReadFile failed stat64() on ")+m_URL); return statbuf.st_size; @@ -259,7 +259,7 @@ LocalWriteFile::LocalWriteFile(const std::string &path): m_closeTried(false){ m_fd = ::open64((char *)path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666); m_URL = "file://"; m_URL += path; - castor::exception::Errnum::throwOnMinusOne(m_fd, + cta::exception::Errnum::throwOnMinusOne(m_fd, std::string("In LocalWriteFile::LocalWriteFile() failed to open64() on ") +m_URL); @@ -273,7 +273,7 @@ void LocalWriteFile::close() { // Multiple close protection if (m_closeTried) return; m_closeTried=true; - castor::exception::Errnum::throwOnMinusOne(::close(m_fd), + cta::exception::Errnum::throwOnMinusOne(::close(m_fd), std::string("In LocalWriteFile::close failed rfio_close() on ")+m_URL); } diff --git a/tapeserver/castor/tape/tapeserver/file/File.cpp b/tapeserver/castor/tape/tapeserver/file/File.cpp index b226029b524299905688aa2eeb92aa7db4867c9b..855a94e162a9c2d27f24235b99f011be009264af 100644 --- a/tapeserver/castor/tape/tapeserver/file/File.cpp +++ b/tapeserver/castor/tape/tapeserver/file/File.cpp @@ -22,7 +22,7 @@ *****************************************************************************/ #include "castor/tape/tapeserver/file/File.hpp" -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include "common/exception/InvalidArgument.hpp" #include <sstream> #include <iomanip> @@ -494,7 +494,7 @@ namespace castor { void WriteSession::setHostName() { char hostname_cstr[max_unix_hostname_length]; - castor::exception::Errnum::throwOnMinusOne(gethostname(hostname_cstr, max_unix_hostname_length), "Failed gethostname() in WriteFile::setHostName"); + cta::exception::Errnum::throwOnMinusOne(gethostname(hostname_cstr, max_unix_hostname_length), "Failed gethostname() in WriteFile::setHostName"); m_hostName = hostname_cstr; std::transform(m_hostName.begin(), m_hostName.end(), m_hostName.begin(), ::toupper); m_hostName = m_hostName.substr(0, m_hostName.find(".")); diff --git a/tapeserver/castor/tape/tapeserver/file/FileTest.cpp b/tapeserver/castor/tape/tapeserver/file/FileTest.cpp index 9434cde5545ccf7d0fddc02ab7346aed5be18361..676f039f829ad6a0a1da4b43a535fc78674b503f 100644 --- a/tapeserver/castor/tape/tapeserver/file/FileTest.cpp +++ b/tapeserver/castor/tape/tapeserver/file/FileTest.cpp @@ -27,7 +27,7 @@ #include "castor/tape/tapeserver/drive/FakeDrive.hpp" #include "castor/tape/tapeserver/file/File.hpp" #include "castor/tape/tapeserver/file/DiskFile.hpp" -#include "castor/exception/Errnum.hpp" +#include "common/exception/Errnum.hpp" #include "common/exception/Exception.hpp" #include "scheduler/ArchiveJob.hpp" #include "scheduler/RetrieveJob.hpp" @@ -241,7 +241,7 @@ namespace unitTests { TempFile() { char path[]="/tmp/testCTA-XXXXXX"; int fd=::mkstemp(path); - castor::exception::Errnum::throwOnMinusOne(fd, "In TempFile::TempFile: failed to mkstemp: "); + cta::exception::Errnum::throwOnMinusOne(fd, "In TempFile::TempFile: failed to mkstemp: "); ::close(fd); m_path=path; } diff --git a/tapeserver/castor/utils/CMakeLists.txt b/tapeserver/castor/utils/CMakeLists.txt index c547de49215bb59cbe99f14718b562ebab078c62..c6ea0568226fef1a45974685a5f28381e678c434 100644 --- a/tapeserver/castor/utils/CMakeLists.txt +++ b/tapeserver/castor/utils/CMakeLists.txt @@ -30,7 +30,6 @@ set (UTILS_LIB_SRC_FILES CRC.cpp utils.cpp ../common/CastorConfiguration.cpp - ../exception/Errnum.cpp ../BaseObject.cpp ../Services.cpp ../Factories.cpp