From 6a74b69e25ad9d69424528816348e3b93becdacd Mon Sep 17 00:00:00 2001 From: Jorge Camarero Vera <jorge.camarero@cern.ch> Date: Thu, 30 Jun 2022 19:08:54 +0200 Subject: [PATCH] Creation of OSM FileReader/Session classes --- ReleaseNotes.md | 2 + common/dataStructures/LabelFormat.hpp | 4 +- .../tape/tapeserver/file/CMakeLists.txt | 2 + .../tapeserver/file/FileReaderFactory.cpp | 5 ++ .../castor/tape/tapeserver/file/FileTest.cpp | 4 +- .../tape/tapeserver/file/OsmFileReader.cpp | 52 +++++++++++++++++ .../tape/tapeserver/file/OsmFileReader.hpp | 57 +++++++++++++++++++ .../tape/tapeserver/file/OsmReadSession.cpp | 38 +++++++++++++ .../tape/tapeserver/file/OsmReadSession.hpp | 55 ++++++++++++++++++ .../tapeserver/file/ReadSessionFactory.cpp | 3 + 10 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 tapeserver/castor/tape/tapeserver/file/OsmFileReader.cpp create mode 100644 tapeserver/castor/tape/tapeserver/file/OsmFileReader.hpp create mode 100644 tapeserver/castor/tape/tapeserver/file/OsmReadSession.cpp create mode 100644 tapeserver/castor/tape/tapeserver/file/OsmReadSession.hpp diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 0aee4dc1a2..d668fe5948 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -2,8 +2,10 @@ ## Summary ### Features +- cta/CTA#1239 - Add support to CTA for multiple tape label formats - cta/CTA#1257 - Refactor CTA/tapeserver/castor/tape/tapeserver/file/File.cpp - cta/CTA#1263 - Abstract ReadSession and FileReader +- cta/CTA#1265 - Create base of the dCache OSM label format ### Bug fixes ### Building and Packaging diff --git a/common/dataStructures/LabelFormat.hpp b/common/dataStructures/LabelFormat.hpp index 4c1400ce84..cf6e7d8b13 100644 --- a/common/dataStructures/LabelFormat.hpp +++ b/common/dataStructures/LabelFormat.hpp @@ -30,7 +30,8 @@ namespace dataStructures { struct Label { enum class Format : std::uint8_t { - CTA = 0x00 + CTA = 0x00, + OSM = 0x01 }; static Format validateFormat(const std::optional<std::uint8_t>& ouiFormat, const std::string& strContext) { @@ -41,6 +42,7 @@ struct Label { Format format = static_cast<Format>(uiFormat); switch (format) { case Format::CTA: + case Format::OSM: return format; default: { diff --git a/tapeserver/castor/tape/tapeserver/file/CMakeLists.txt b/tapeserver/castor/tape/tapeserver/file/CMakeLists.txt index 94b65b8d33..32c00a1819 100644 --- a/tapeserver/castor/tape/tapeserver/file/CMakeLists.txt +++ b/tapeserver/castor/tape/tapeserver/file/CMakeLists.txt @@ -28,6 +28,8 @@ set(TAPESERVER_FILE_LIBRARY_SRCS FileWriter.cpp HeaderChecker.cpp LabelSession.cpp + OsmFileReader.cpp + OsmReadSession.cpp ReadSession.cpp ReadSessionFactory.cpp Structures.cpp diff --git a/tapeserver/castor/tape/tapeserver/file/FileReaderFactory.cpp b/tapeserver/castor/tape/tapeserver/file/FileReaderFactory.cpp index e6bce456fb..53e54c8db4 100644 --- a/tapeserver/castor/tape/tapeserver/file/FileReaderFactory.cpp +++ b/tapeserver/castor/tape/tapeserver/file/FileReaderFactory.cpp @@ -20,6 +20,7 @@ #include "castor/tape/tapeserver/file/CtaFileReader.hpp" #include "castor/tape/tapeserver/file/FileReaderFactory.hpp" +#include "castor/tape/tapeserver/file/OsmFileReader.hpp" #include "castor/tape/tapeserver/file/ReadSession.hpp" #include "common/dataStructures/LabelFormat.hpp" @@ -37,6 +38,10 @@ std::unique_ptr<FileReader> FileReaderFactory::create(const std::unique_ptr<Read reader = std::make_unique<CtaFileReader>(readSession, fileToRecall); break; } + case LabelFormat::OSM: { + reader = std::make_unique<OsmFileReader>(readSession, fileToRecall); + break; + } default: { std::ostringstream ossLabelFormat; ossLabelFormat << std::showbase << std::internal << std::setfill('0') << std::hex << std::setw(4) diff --git a/tapeserver/castor/tape/tapeserver/file/FileTest.cpp b/tapeserver/castor/tape/tapeserver/file/FileTest.cpp index 11c440fa61..3c4efa5cc0 100644 --- a/tapeserver/castor/tape/tapeserver/file/FileTest.cpp +++ b/tapeserver/castor/tape/tapeserver/file/FileTest.cpp @@ -248,7 +248,9 @@ TEST_F(castorTapeFileTest, tapeSessionThrowsOnWrongSequence) { } INSTANTIATE_TEST_CASE_P(FormatLabelsParam, castorTapeFileTest, - ::testing::Values(cta::common::dataStructures::Label::Format::CTA)); + ::testing::Values(cta::common::dataStructures::Label::Format::CTA + // , cta::common::dataStructures::Label::Format::OSM +)); // Class creating a temporary file of 1kB and deleting it // automatically diff --git a/tapeserver/castor/tape/tapeserver/file/OsmFileReader.cpp b/tapeserver/castor/tape/tapeserver/file/OsmFileReader.cpp new file mode 100644 index 0000000000..3b17997d57 --- /dev/null +++ b/tapeserver/castor/tape/tapeserver/file/OsmFileReader.cpp @@ -0,0 +1,52 @@ +/* + * @project The CERN Tape Archive (CTA) + * @copyright Copyright © 2022 CERN + * @license This program is free software, distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". You can + * redistribute it and/or modify it under the terms of the GPL Version 3, 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. + * + * In applying this licence, CERN does not waive the privileges and immunities + * granted to it by virtue of its status as an Intergovernmental Organization or + * submit itself to any jurisdiction. + */ + +#include <limits> +#include <memory> +#include <sstream> +#include <string> + +#include "castor/tape/tapeserver/drive/DriveInterface.hpp" +#include "castor/tape/tapeserver/file/HeaderChecker.hpp" +#include "castor/tape/tapeserver/file/OsmFileReader.hpp" +#include "castor/tape/tapeserver/file/CtaReadSession.hpp" +#include "castor/tape/tapeserver/file/Structures.hpp" +#include "scheduler/RetrieveJob.hpp" + +namespace castor { +namespace tape { +namespace tapeFile { + +OsmFileReader::OsmFileReader(const std::unique_ptr<ReadSession> &rs, const cta::RetrieveJob &fileToRecall) + : FileReader(rs, fileToRecall) { +} + +void OsmFileReader::positionByFseq(const cta::RetrieveJob &fileToRecall) { + throw NotImplemented("OsmFileReader::positionByFseq() needs to be implemented"); +} + +void OsmFileReader::positionByBlockID(const cta::RetrieveJob &fileToRecall) { + throw NotImplemented("OsmFileReader::positionByBlockID() needs to be implemented"); +} + +size_t OsmFileReader::readNextDataBlock(void *data, const size_t size) { + throw NotImplemented("OsmFileReader::readNextDataBlock() needs to be implemented"); +} + +} // namespace tapeFile +} // namespace tape +} // namespace castor diff --git a/tapeserver/castor/tape/tapeserver/file/OsmFileReader.hpp b/tapeserver/castor/tape/tapeserver/file/OsmFileReader.hpp new file mode 100644 index 0000000000..aec29a6402 --- /dev/null +++ b/tapeserver/castor/tape/tapeserver/file/OsmFileReader.hpp @@ -0,0 +1,57 @@ +/* + * @project The CERN Tape Archive (CTA) + * @copyright Copyright © 2022 CERN + * @license This program is free software, distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". You can + * redistribute it and/or modify it under the terms of the GPL Version 3, 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. + * + * In applying this licence, CERN does not waive the privileges and immunities + * granted to it by virtue of its status as an Intergovernmental Organization or + * submit itself to any jurisdiction. + */ + +#pragma once + +#include <memory> + +#include "castor/tape/tapeserver/file/OsmFileReader.hpp" +#include "castor/tape/tapeserver/file/FileReader.hpp" + +namespace castor { +namespace tape { +namespace tapeFile { + +class UHL1; + +class OsmFileReader : public FileReader { +public: + CTA_GENERATE_EXCEPTION_CLASS(NotImplemented); + /** + * Constructor of the FileReader. It will bind itself to an existing read session + * and position the tape right at the beginning of the file + * @param rs: session to be bound to + * @param fileInfo: information about the file we would like to read + * @param positioningMode: method used when positioning (see the PositioningMode enum) + */ + OsmFileReader(const std::unique_ptr<ReadSession> &rs, const cta::RetrieveJob &fileToRecall); + + /** + * Destructor of the FileReader. It will release the lock on the read session. + */ + ~OsmFileReader() override = default; + + size_t readNextDataBlock(void *data, const size_t size) override; + +private: + void positionByFseq(const cta::RetrieveJob &fileToRecall) override; + void positionByBlockID(const cta::RetrieveJob &fileToRecall) override; +}; + +} // namespace tapeFile +} // namespace tape +} // namespace castor diff --git a/tapeserver/castor/tape/tapeserver/file/OsmReadSession.cpp b/tapeserver/castor/tape/tapeserver/file/OsmReadSession.cpp new file mode 100644 index 0000000000..52836213bd --- /dev/null +++ b/tapeserver/castor/tape/tapeserver/file/OsmReadSession.cpp @@ -0,0 +1,38 @@ +/* + * @project The CERN Tape Archive (CTA) + * @copyright Copyright © 2022 CERN + * @license This program is free software, distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". You can + * redistribute it and/or modify it under the terms of the GPL Version 3, 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. + * + * In applying this licence, CERN does not waive the privileges and immunities + * granted to it by virtue of its status as an Intergovernmental Organization or + * submit itself to any jurisdiction. + */ + +#include <memory> +#include <string> + +#include "castor/tape/tapeserver/file/Exceptions.hpp" +#include "castor/tape/tapeserver/file/HeaderChecker.hpp" +#include "castor/tape/tapeserver/file/OsmReadSession.hpp" +#include "castor/tape/tapeserver/file/Structures.hpp" + +namespace castor { +namespace tape { +namespace tapeFile { + +OsmReadSession::OsmReadSession(tapeserver::drive::DriveInterface &drive, + const tapeserver::daemon::VolumeInfo &volInfo, const bool useLbp) + : ReadSession(drive, volInfo, useLbp) { + throw NotImplemented("Constructor not implemented"); +} + +} // namespace tapeFile +} // namespace tape +} // namespace castor diff --git a/tapeserver/castor/tape/tapeserver/file/OsmReadSession.hpp b/tapeserver/castor/tape/tapeserver/file/OsmReadSession.hpp new file mode 100644 index 0000000000..ee7d591f85 --- /dev/null +++ b/tapeserver/castor/tape/tapeserver/file/OsmReadSession.hpp @@ -0,0 +1,55 @@ +/* + * @project The CERN Tape Archive (CTA) + * @copyright Copyright © 2022 CERN + * @license This program is free software, distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". You can + * redistribute it and/or modify it under the terms of the GPL Version 3, 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. + * + * In applying this licence, CERN does not waive the privileges and immunities + * granted to it by virtue of its status as an Intergovernmental Organization or + * submit itself to any jurisdiction. + */ + +#pragma once + +#include <memory> +#include <string> + +#include "castor/tape/tapeserver/daemon/VolumeInfo.hpp" +#include "castor/tape/tapeserver/file/ReadSession.hpp" + +namespace castor { +namespace tape { +namespace tapeFile { + +/** + * Class keeping track of a whole tape read session over an AUL formatted + * tape. The session will keep track of the overall coherency of the session + * and check for everything to be coherent. The tape should be mounted in + * the drive before the AULReadSession is started (i.e. constructed). + * Likewise, tape unmount is the business of the user. + */ +class OsmReadSession : public ReadSession { +public: + CTA_GENERATE_EXCEPTION_CLASS(NotImplemented); + /** + * Constructor of the OsmReadSession. It will rewind the tape, and check the + * volId value. Throws an exception in case of mismatch. + * @param drive: drive object to which we bind the session + * @param vid: volume name of the tape we would like to read from + * @param useLbp: castor.conf option to use or not to use LBP in tapeserverd + */ + OsmReadSession(tapeserver::drive::DriveInterface &drive, const tapeserver::daemon::VolumeInfo &volInfo, + const bool useLbp); + + ~OsmReadSession() override = default; +}; + +} // namespace tapeFile +} // namespace tape +} // namespace castor diff --git a/tapeserver/castor/tape/tapeserver/file/ReadSessionFactory.cpp b/tapeserver/castor/tape/tapeserver/file/ReadSessionFactory.cpp index dde98b7201..171e04ed7f 100644 --- a/tapeserver/castor/tape/tapeserver/file/ReadSessionFactory.cpp +++ b/tapeserver/castor/tape/tapeserver/file/ReadSessionFactory.cpp @@ -19,6 +19,7 @@ #include <sstream> #include "castor/tape/tapeserver/file/CtaReadSession.hpp" +#include "castor/tape/tapeserver/file/OsmReadSession.hpp" #include "castor/tape/tapeserver/file/ReadSessionFactory.hpp" #include "common/dataStructures/LabelFormat.hpp" @@ -33,6 +34,8 @@ std::unique_ptr<ReadSession> ReadSessionFactory::create(tapeserver::drive::Drive switch (labelFormat) { case LabelFormat::CTA: return std::make_unique<CtaReadSession>(drive, volInfo, useLbp); + case LabelFormat::OSM: + return std::make_unique<OsmReadSession>(drive, volInfo, useLbp); default: { std::ostringstream ossLabelFormat; ossLabelFormat << std::showbase << std::internal << std::setfill('0') << std::hex << std::setw(4) -- GitLab