diff --git a/nameserver/CMakeLists.txt b/nameserver/CMakeLists.txt index abcc71e30cf7cd8b4d5805a8035f566147244bce..9b627433898e834319e8d9612dda0e0a5a82582d 100644 --- a/nameserver/CMakeLists.txt +++ b/nameserver/CMakeLists.txt @@ -23,3 +23,6 @@ add_library (ctanameserverunittests SHARED target_link_libraries(ctanameserverunittests ctanameserver) + +add_executable(makeMockNameServerBasePath mockNS/makeMockNameServerBasePath.cpp) +target_link_libraries(makeMockNameServerBasePath ctacommon) \ No newline at end of file diff --git a/nameserver/mockNS/MockNameServer.cpp b/nameserver/mockNS/MockNameServer.cpp index b1f8b1e625463411f24970684a0c5d87dadb9a5f..f788a869ed4b26a38c493c0301f0a391c78831d9 100644 --- a/nameserver/mockNS/MockNameServer.cpp +++ b/nameserver/mockNS/MockNameServer.cpp @@ -304,6 +304,15 @@ cta::MockNameServer::MockNameServer(): m_fileIdCounter(0) { setOwner(initialRequester, "/", initialOwner); } +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +cta::MockNameServer::MockNameServer(const std::string &path): m_fileIdCounter(0) { + Utils::assertAbsolutePathSyntax(path); + assertFsDirExists(path); + m_fsDir = path; +} + //------------------------------------------------------------------------------ // destructor //------------------------------------------------------------------------------ diff --git a/nameserver/mockNS/MockNameServer.hpp b/nameserver/mockNS/MockNameServer.hpp index d21e0a8a6a35a76f4fe5dae299e159e74e3417b7..e003090af79d687aac9de5503dd8a0fdea20e16e 100644 --- a/nameserver/mockNS/MockNameServer.hpp +++ b/nameserver/mockNS/MockNameServer.hpp @@ -41,6 +41,13 @@ public: * Constructor. */ MockNameServer(); + + /** + * Constructor for an already existing mock name server temporary directory + * + * @param path The already existing mock name server temporary directory + */ + MockNameServer(const std::string &path); /** * Destructor. diff --git a/nameserver/mockNS/makeMockNameServerBasePath.cpp b/nameserver/mockNS/makeMockNameServerBasePath.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c88c68a239a35b3fa13925d7230baf58dade6b4e --- /dev/null +++ b/nameserver/mockNS/makeMockNameServerBasePath.cpp @@ -0,0 +1,68 @@ +/* + * The CERN Tape Archive (CTA) project + * Copyright (C) 2015 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +/** + * This program will create a new directory for the mock name server + */ + +#include <iostream> +#include <string.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <attr/xattr.h> + +#include "common/exception/Errnum.hpp" +#include "common/exception/Exception.hpp" +#include "common/Utils.hpp" + +//------------------------------------------------------------------------------ +// setXattr +//------------------------------------------------------------------------------ +void setXattr(const std::string &path, const std::string &name, const std::string &value) { + if(setxattr(path.c_str(), name.c_str(), value.c_str(), value.length(), 0)) { + const int savedErrno = errno; + std::ostringstream msg; + msg << "Call to setxattr() failed: path=" << path << " name=" << name << " value=" << value << ": " << cta::Utils::errnoToString(savedErrno); + throw cta::exception::Exception(msg.str()); + } +} + +//------------------------------------------------------------------------------ +// main +//------------------------------------------------------------------------------ +int main(void) { + try { + umask(0); + char path[100]; + strncpy(path, "/tmp/CTAMockNSXXXXXX", 100); + cta::exception::Errnum::throwOnNull(mkdtemp(path), "MockNameServer() - Failed to create temporary directory"); + std::string pathString(path); + pathString+="/"; + setXattr(pathString.c_str(), "user.CTAStorageClass", ""); + setXattr(pathString.c_str(), "user.uid", "0"); + setXattr(pathString.c_str(), "user.gid", "0"); + std::cout << "New mock name server path: " << pathString << std::endl; + } catch (cta::exception::Exception & e) { + std::cerr << "Failed to create a new directory for the mock name server. CTA Exception: " << e.getMessageValue() << std::endl; + } catch (std::exception & e) { + std::cerr << "Failed to create a new directory for the mock name server. STD Exception: " << e.what() << std::endl; + } catch (...) { + std::cerr << "Failed to create a new directory for the mock name server. Unknown Exception!" << std::endl; + } +} + diff --git a/tapeserver/castor/castor.conf b/tapeserver/castor/castor.conf index 0167982e9063dd629bcab65f4246f4bd0d3614ba..ae8096e8e183cd50b1d32e82f38766a5b8241cb4 100644 --- a/tapeserver/castor/castor.conf +++ b/tapeserver/castor/castor.conf @@ -651,6 +651,12 @@ # directory recursively readable and writable by stage:st. #TapeServer ObjectStoreBackendPath /tmp/jobStoreVFS9r236q +# This is the location of the mock name server base path. If you want to create +# a local empty mock name server base dir you may use the +# makeMockNameServerBasePath binary (takes no argument), which returns the newly +# created path. +#TapeServer MockNameServerPath /tmp/CTAMockNS9r236q + ## Tape Bridge Clients: dumptp, readtp and writetp ############################# # The inclusive low port of the tapebridge client callback port number range. diff --git a/xroot_plugins/XrdCtaFilesystem.cpp b/xroot_plugins/XrdCtaFilesystem.cpp index 0a8abe868ae9145ed9334947cdd7dd865e53ef10..2a6675165edaa34d3c4577f2d3b1762f9a2c504e 100644 --- a/xroot_plugins/XrdCtaFilesystem.cpp +++ b/xroot_plugins/XrdCtaFilesystem.cpp @@ -255,6 +255,7 @@ void XrdProFilesystem::EnvInfo(XrdOucEnv *envP) // constructor //------------------------------------------------------------------------------ XrdProFilesystem::XrdProFilesystem(): + m_ns(castor::common::CastorConfiguration::getConfig().getConfEntString("TapeServer", "MockNameServerPath")), m_remoteStorage("localhost:1094"), m_backend(castor::common::CastorConfiguration::getConfig().getConfEntString("TapeServer", "ObjectStoreBackendPath")), m_backendPopulator(m_backend), diff --git a/xroot_plugins/XrdCtaFilesystem.hpp b/xroot_plugins/XrdCtaFilesystem.hpp index e4e3ffb17b5e345084581e304c7fee069b2b88eb..cc1787d229ed06da05a84b15eded7c2c72619ed3 100644 --- a/xroot_plugins/XrdCtaFilesystem.hpp +++ b/xroot_plugins/XrdCtaFilesystem.hpp @@ -62,7 +62,7 @@ protected: /** * The CTA nameserver */ - cta::CastorNameServer m_ns; + cta::MockNameServer m_ns; /** * The remote file storage system (typically EOS)