diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index b078d74c24018f5fe914fd57fe37d1b4c5c00bf4..e6905747662e0df7745cf33c1c54c7062f05d939 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -23,6 +23,8 @@ find_package (libuuid REQUIRED) add_subdirectory (exception) +set_source_files_properties(CRC.cpp PROPERTIES COMPILE_FLAGS -O2) + set (COMMON_LIB_SRC_FILES dataStructures/AdminHost.cpp dataStructures/AdminUser.cpp @@ -102,6 +104,7 @@ set (COMMON_LIB_SRC_FILES remoteFS/RemotePath.cpp remoteFS/RemotePathAndStatus.cpp SmartFd.cpp + CRC.cpp threading/ChildProcess.cpp threading/Daemon.cpp threading/Mutex.cpp @@ -141,6 +144,7 @@ set (COMMON_UNIT_TESTS_LIB_SRC_FILES log/StringLoggerTest.cpp remoteFS/RemotePathTest.cpp SmartFdTest.cpp + CRCTest.cpp threading/DaemonTest.cpp threading/SocketPairTest.cpp threading/ThreadingBlockingQTests.cpp diff --git a/tapeserver/castor/utils/CRC.cpp b/common/CRC.cpp similarity index 90% rename from tapeserver/castor/utils/CRC.cpp rename to common/CRC.cpp index 21b26c393aaf1cb666d2c90afd0ce67ce2b6086a..2736e5d669fe72b5b4dea9b399057e452b852e63 100644 --- a/tapeserver/castor/utils/CRC.cpp +++ b/common/CRC.cpp @@ -1,32 +1,31 @@ -/****************************************************************************** +/* + * The CERN Tape Archive (CTA) project + * Copyright (C) 2015 CERN * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor + * 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 3 of the License, or + * (at your option) any later version. * - * 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 - *****************************************************************************/ + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ -#include "castor/utils/CRC.hpp" +#include "common/CRC.hpp" #include <stdint.h> +namespace cta { + //----------------------------------------------------------------------------- // crcRS_sw //----------------------------------------------------------------------------- -uint32_t castor::utils::CRC::crcRS_sw (const uint32_t crcInit, +uint32_t crcRS_sw (const uint32_t crcInit, const uint32_t cnt, const void *const start) { static const uint32_t crcTable[256] = { 0x00000000, 0x38CF3801, 0x70837002, 0x484C4803, 0xE01BE004, 0xD8D4D805, @@ -87,7 +86,7 @@ uint32_t castor::utils::CRC::crcRS_sw (const uint32_t crcInit, //----------------------------------------------------------------------------- // crc32c_sw //----------------------------------------------------------------------------- -uint32_t castor::utils::CRC::crc32c_sw (const uint32_t crcInit, +uint32_t crc32c_sw (const uint32_t crcInit, const uint32_t cnt, const void *const start) { static const uint32_t crcTable[256] = { @@ -194,7 +193,7 @@ uint32_t crc32c_intel_le_hw_64b(const uint32_t crcInit, //----------------------------------------------------------------------------- // crc32c_hw //----------------------------------------------------------------------------- -uint32_t castor::utils::CRC::crc32c_hw (const uint32_t crcInit, +uint32_t crc32c_hw (const uint32_t crcInit, const uint32_t cnt, const void *const start) { /* Do CPU 64 instruction */ @@ -217,7 +216,7 @@ uint32_t castor::utils::CRC::crc32c_hw (const uint32_t crcInit, //----------------------------------------------------------------------------- // crc32c //----------------------------------------------------------------------------- -uint32_t castor::utils::CRC::crc32c(const uint32_t crcInit, const uint32_t cnt, +uint32_t crc32c(const uint32_t crcInit, const uint32_t cnt, const void *const start) { int sse42; @@ -228,7 +227,7 @@ uint32_t castor::utils::CRC::crc32c(const uint32_t crcInit, const uint32_t cnt, //----------------------------------------------------------------------------- // addCrc32cToMemoryBlock //----------------------------------------------------------------------------- -uint32_t castor::utils::CRC::addCrc32cToMemoryBlock(const uint32_t crcInit, +uint32_t addCrc32cToMemoryBlock(const uint32_t crcInit, const uint32_t cnt, uint8_t *start ) { if (cnt == 0) return 0; //no such thing as a zero length block in SSC (write NOP) @@ -245,7 +244,7 @@ uint32_t castor::utils::CRC::addCrc32cToMemoryBlock(const uint32_t crcInit, //----------------------------------------------------------------------------- // verifyCrc32cForMemoryBlockWithCrc32c //----------------------------------------------------------------------------- -bool castor::utils::CRC::verifyCrc32cForMemoryBlockWithCrc32c( +bool verifyCrc32cForMemoryBlockWithCrc32c( const uint32_t crcInit, const uint32_t cnt, const uint8_t *start) { if (cnt <= 4) return false; //block is too small to be valid, cannot check CRC @@ -260,3 +259,5 @@ bool castor::utils::CRC::verifyCrc32cForMemoryBlockWithCrc32c( return false; //block CRC is incorrect return true; } + +} // namespace cta \ No newline at end of file diff --git a/tapeserver/castor/utils/CRC.hpp b/common/CRC.hpp similarity index 83% rename from tapeserver/castor/utils/CRC.hpp rename to common/CRC.hpp index a67f3f7519476c38f0673a73d50407598e17766b..8655195d1527e71c2104a56fd700ccf613e71dcd 100644 --- a/tapeserver/castor/utils/CRC.hpp +++ b/common/CRC.hpp @@ -1,34 +1,27 @@ -/****************************************************************************** +/* + * The CERN Tape Archive (CTA) project + * Copyright (C) 2015 CERN * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor + * 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 3 of the License, or + * (at your option) any later version. * - * 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 - *****************************************************************************/ + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ #pragma once #include <stdint.h> -namespace castor { -namespace utils { -namespace CRC { +namespace cta { + /** * Set of CRC functions. */ @@ -130,6 +123,5 @@ uint32_t addCrc32cToMemoryBlock(const uint32_t crcInit, bool verifyCrc32cForMemoryBlockWithCrc32c( const uint32_t crcInit, const uint32_t cnt, const uint8_t *start); -} // namespace CRC -} // namespace utils -} // namespace castor + +} // namespace cta diff --git a/tapeserver/castor/utils/CRCTest.cpp b/common/CRCTest.cpp similarity index 76% rename from tapeserver/castor/utils/CRCTest.cpp rename to common/CRCTest.cpp index 0e4fd77cbfca12ef01428122e2c43757952a3f41..76ad5453e47c04bef9f675e735c5b35aa440a11b 100644 --- a/tapeserver/castor/utils/CRCTest.cpp +++ b/common/CRCTest.cpp @@ -1,27 +1,22 @@ -/****************************************************************************** +/* + * The CERN Tape Archive (CTA) project + * Copyright (C) 2015 CERN * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor + * 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 3 of the License, or + * (at your option) any later version. * - * 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 - *****************************************************************************/ + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ -#include "castor/utils/CRC.hpp" +#include "common/CRC.hpp" #include <gtest/gtest.h> @@ -29,7 +24,7 @@ namespace unitTests { -class castor_CRC : public ::testing::Test { +class cta_CRC : public ::testing::Test { protected: virtual void SetUp() { @@ -39,8 +34,8 @@ protected: } }; -TEST_F(castor_CRC, testCRCRS_sw) { - using namespace castor::utils::CRC; +TEST_F(cta_CRC, testCRCRS_sw) { + using namespace cta; const uint8_t block1[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, @@ -59,8 +54,8 @@ TEST_F(castor_CRC, testCRCRS_sw) { ASSERT_EQ(computedCRC3, 0x754ED37E); } -TEST_F(castor_CRC, testCRC32C_sw) { - using namespace castor::utils::CRC; +TEST_F(cta_CRC, testCRC32C_sw) { + using namespace cta; const uint8_t block1[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, @@ -78,8 +73,8 @@ TEST_F(castor_CRC, testCRC32C_sw) { ASSERT_EQ(computedCRC2, 0x56DAB0A6); ASSERT_EQ(computedCRC3, 0x56DAB0A6); } -TEST_F(castor_CRC, testCRC32C_hw) { - using namespace castor::utils::CRC; +TEST_F(cta_CRC, testCRC32C_hw) { + using namespace cta; /* check if we have SSE4_2 to test hardware CRC32C */ int sse42; @@ -103,8 +98,8 @@ TEST_F(castor_CRC, testCRC32C_hw) { ASSERT_EQ(computedCRC3, 0x56DAB0A6); } } -TEST_F(castor_CRC, testCRC32C) { - using namespace castor::utils::CRC; +TEST_F(cta_CRC, testCRC32C) { + using namespace cta; const uint8_t block1[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, diff --git a/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp b/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp index 4d134f0972d6de63d373889f8a36bc2b44bbf76d..92068ae98debcf806a3b6944edfc4b78ed29e05f 100644 --- a/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp +++ b/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp @@ -26,7 +26,7 @@ #include "castor/tape/tapeserver/drive/DriveGeneric.hpp" #include "castor/utils/Timer.hpp" -#include "castor/utils/CRC.hpp" +#include "common/CRC.hpp" #include "common/exception/MemException.hpp" namespace castor { @@ -703,7 +703,7 @@ void drive::DriveGeneric::writeBlock(const void * data, size_t count) { } memcpy(dataWithCrc32c, data, count); const size_t countWithCrc32c = - castor::utils::CRC::addCrc32cToMemoryBlock( + cta::addCrc32cToMemoryBlock( SCSI::logicBlockProtectionMethod::CRC32CSeed, count, dataWithCrc32c); if (countWithCrc32c != @@ -771,7 +771,7 @@ ssize_t drive::DriveGeneric::readBlock(void * data, size_t count) { delete[] dataWithCrc32c; throw cta::exception::Exception("In DriveGeneric::readBlock: wrong data block size, checksum cannot fit"); } - if (castor::utils::CRC::verifyCrc32cForMemoryBlockWithCrc32c( + if (cta::verifyCrc32cForMemoryBlockWithCrc32c( SCSI::logicBlockProtectionMethod::CRC32CSeed, res, dataWithCrc32c)) { // everything is fine here do mem copy @@ -835,7 +835,7 @@ void drive::DriveGeneric::readExactBlock(void * data, size_t count, std::string delete[] dataWithCrc32c; throw UnexpectedSize(context); } - if (castor::utils::CRC::verifyCrc32cForMemoryBlockWithCrc32c( + if (cta::verifyCrc32cForMemoryBlockWithCrc32c( SCSI::logicBlockProtectionMethod::CRC32CSeed, res, dataWithCrc32c)) { // everything is fine here do mem copy diff --git a/tapeserver/castor/utils/CMakeLists.txt b/tapeserver/castor/utils/CMakeLists.txt index 267c836b41455ef0f784da60e2ab43ae48c25c34..48fc17e1fc4f2d4d9773789ec550e3dc2a6054ad 100644 --- a/tapeserver/castor/utils/CMakeLists.txt +++ b/tapeserver/castor/utils/CMakeLists.txt @@ -22,11 +22,9 @@ cmake_minimum_required (VERSION 2.6) include_directories(/usr/include/shift) include_directories(${PROJECT_SOURCE_DIR}/tapeserver) -set_source_files_properties(CRC.cpp PROPERTIES COMPILE_FLAGS -O2) set (UTILS_LIB_SRC_FILES SmartFILEPtr.cpp Timer.cpp - CRC.cpp utils.cpp ../common/CastorConfiguration.cpp ../System.cpp