Commit 4e5a106c authored by Daniele Kruse's avatar Daniele Kruse
Browse files

Refactored the xroot plugin load code: it shouldn't core dump in case of missing castor.conf option

parent 28e0ee92
......@@ -117,7 +117,8 @@ void cta::CastorNameServer::addTapeFile(
std::list<cta::NameServerTapeFile> cta::CastorNameServer::getTapeFiles(
const SecurityIdentity &requester,
const std::string &path) const {
throw exception::Exception(std::string(__FUNCTION__) + " not implemented");
std::list<cta::NameServerTapeFile> emptyList; //not implemented yet, still wanted to return the empty list not to cause exception during listing
return emptyList;
}
//------------------------------------------------------------------------------
......
/*
* 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/>.
*/
#include "objectstore/BackendVFS.hpp"
#include "objectstore/RootEntry.hpp"
#include "xroot_plugins/BackendPopulator.hpp"
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
BackendPopulator::BackendPopulator(cta::objectstore::Backend & be): m_backend(be), m_agent(m_backend) {
cta::objectstore::RootEntry re(m_backend);
cta::objectstore::ScopedExclusiveLock rel(re);
re.fetch();
m_agent.generateName("OStoreDBFactory");
m_agent.initialize();
cta::objectstore::CreationLog cl(cta::UserIdentity(1111, 1111), "systemhost", time(NULL), "Initial creation of the object store structures");
re.addOrGetAgentRegisterPointerAndCommit(m_agent,cl);
rel.release();
m_agent.insertAndRegisterSelf();
rel.lock(re);
re.addOrGetDriveRegisterPointerAndCommit(m_agent, cl);
rel.release();
}
//------------------------------------------------------------------------------
// Destructor
//------------------------------------------------------------------------------
BackendPopulator::~BackendPopulator() throw() {
cta::objectstore::ScopedExclusiveLock agl(m_agent);
m_agent.fetch();
m_agent.removeAndUnregisterSelf();
}
//------------------------------------------------------------------------------
// getAgent
//------------------------------------------------------------------------------
cta::objectstore::Agent & BackendPopulator::getAgent() {
return m_agent;
}
\ No newline at end of file
/*
* 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/>.
*/
#pragma once
#include "objectstore/Agent.hpp"
#include "objectstore/Backend.hpp"
class BackendPopulator {
public:
/**
* Constructor
*
* @param be The objectstore backend
*/
BackendPopulator(cta::objectstore::Backend & be);
/**
* Destructor
*/
virtual ~BackendPopulator() throw();
/**
* Returns the agent
*
* @return the agent
*/
cta::objectstore::Agent & getAgent();
private:
/**
* The objectstore backend
*/
cta::objectstore::Backend & m_backend;
/**
* The agent
*/
cta::objectstore::Agent m_agent;
};
\ No newline at end of file
......@@ -7,5 +7,5 @@ include_directories(${XROOTD_INCLUDE_DIR} ${XROOTD_PRIVATE_INCLUDE_DIR})
include_directories(${CMAKE_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/tapeserver)
add_library (XrdProFst MODULE XrdProFilesystem.cpp XrdProFile.cpp)
add_library (XrdProFst MODULE XrdProFilesystem.cpp XrdProFile.cpp OStoreDBWithAgent.cpp BackendPopulator.cpp)
target_link_libraries (XrdProFst ctascheduler ctacommon ctanameserver ctaremotens ctaOStoreSchedulerDB protobuf CTAObjectStore cryptopp)
/*
* 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/>.
*/
#include "xroot_plugins/OStoreDBWithAgent.hpp"
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
OStoreDBWithAgent::OStoreDBWithAgent(cta::objectstore::Backend & be, cta::objectstore::Agent & ag): cta::OStoreDB(be) {
cta::OStoreDB::setAgent(ag);
}
//------------------------------------------------------------------------------
// Destructor
//------------------------------------------------------------------------------
OStoreDBWithAgent::~OStoreDBWithAgent() throw () {
cta::OStoreDB::setAgent(*((cta::objectstore::Agent *)NULL));
}
\ No newline at end of file
/*
* 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/>.
*/
#pragma once
#include "objectstore/Agent.hpp"
#include "objectstore/Backend.hpp"
#include "scheduler/OStoreDB/OStoreDB.hpp"
class OStoreDBWithAgent: public cta::OStoreDB {
public:
/**
* Constructor
*
* @param be The objectstore backend
* @param ag The agent
*/
OStoreDBWithAgent(cta::objectstore::Backend & be, cta::objectstore::Agent & ag);
/**
* Destructor
*/
virtual ~OStoreDBWithAgent() throw ();
};
\ No newline at end of file
......@@ -28,7 +28,6 @@
#include "scheduler/ArchiveToTapeCopyRequest.hpp"
#include "scheduler/LogicalLibrary.hpp"
#include "scheduler/OStoreDB/OStoreDB.hpp"
//#include "scheduler/mockDB/MockSchedulerDatabase.hpp"
#include "scheduler/RetrieveRequestDump.hpp"
#include "common/archiveNS/StorageClass.hpp"
#include "scheduler/SchedulerDatabase.hpp"
......@@ -39,9 +38,7 @@
#include "XrdOuc/XrdOucString.hh"
#include "XrdSec/XrdSecEntity.hh"
#include "XrdVersion.hh"
#include "objectstore/BackendVFS.hpp"
#include "objectstore/RootEntry.hpp"
#include "remotens/EosNS.hpp"
#include <memory>
#include <iostream>
......@@ -51,67 +48,22 @@
XrdVERSIONINFO(XrdSfsGetFileSystem,XrdPro)
//BEGIN: boilerplate code to prepare the objectstoreDB object
cta::objectstore::BackendVFS g_backend(castor::common::CastorConfiguration::getConfig().getConfEntString("TapeServer", "ObjectStoreBackendPath"));
class BackendPopulator {
public:
BackendPopulator(cta::objectstore::Backend & be): m_backend(be),
m_agent(m_backend) {
// We need to populate the root entry before using.
cta::objectstore::RootEntry re(m_backend);
cta::objectstore::ScopedExclusiveLock rel(re);
re.fetch();
m_agent.generateName("OStoreDBFactory");
m_agent.initialize();
cta::objectstore::CreationLog cl(cta::UserIdentity(1111, 1111), "systemhost",
time(NULL), "Initial creation of the object store structures");
re.addOrGetAgentRegisterPointerAndCommit(m_agent,cl);
rel.release();
m_agent.insertAndRegisterSelf();
rel.lock(re);
re.addOrGetDriveRegisterPointerAndCommit(m_agent, cl);
rel.release();
}
virtual ~BackendPopulator() throw() {
cta::objectstore::ScopedExclusiveLock agl(m_agent);
m_agent.fetch();
m_agent.removeAndUnregisterSelf();
}
cta::objectstore::Agent & getAgent() { return m_agent; }
private:
cta::objectstore::Backend & m_backend;
cta::objectstore::Agent m_agent;
} g_backendPopulator(g_backend);
class OStoreDBWithAgent: public cta::OStoreDB {
public:
OStoreDBWithAgent(cta::objectstore::Backend & be, cta::objectstore::Agent & ag):
cta::OStoreDB(be) {
cta::OStoreDB::setAgent(ag);
}
virtual ~OStoreDBWithAgent() throw () {
cta::OStoreDB::setAgent(*((cta::objectstore::Agent *)NULL));
}
} g_OStoreDB(g_backend, g_backendPopulator.getAgent());
//END: boilerplate code to prepare the objectstoreDB object
cta::EosNS g_eosNs("localhost:1094");
cta::CastorNameServer g_castorNs;
extern "C"
{
XrdSfsFileSystem *XrdSfsGetFileSystem (XrdSfsFileSystem* native_fs, XrdSysLogger* lp, const char* configfn)
{
g_backend.noDeleteOnExit();
return new XrdProFilesystem(
&g_castorNs,
&g_OStoreDB,
&g_eosNs);
try {
return new XrdProFilesystem();
} catch (cta::exception::Exception &ex) {
std::cout << "[ERROR] Could not load the CTA xroot plugin. CTA exception caught: " << ex.getMessageValue() << "\n";
return NULL;
} catch (std::exception &ex) {
std::cout << "[ERROR] Could not load the CTA xroot plugin. Exception caught: " << ex.what() << "\n";
return NULL;
} catch (...) {
std::cout << "[ERROR] Could not load the CTA xroot plugin. Unknown exception caught!" << "\n";
return NULL;
}
}
}
......@@ -130,7 +82,7 @@ int XrdProFilesystem::FSctl(const int cmd, XrdSfsFSctl &args, XrdOucErrInfo &eIn
//------------------------------------------------------------------------------
XrdSfsFile * XrdProFilesystem::newFile(char *user, int MonID)
{
return new XrdProFile(m_scheduler, user, MonID);
return new XrdProFile(&m_scheduler, user, MonID);
}
//------------------------------------------------------------------------------
......@@ -302,25 +254,29 @@ void XrdProFilesystem::EnvInfo(XrdOucEnv *envP)
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
XrdProFilesystem::XrdProFilesystem(
cta::NameServer *ns,
cta::SchedulerDatabase *scheddb,
cta::RemoteNS *remoteStorage):
m_ns(ns),
m_scheddb(scheddb),
m_remoteStorage(remoteStorage),
m_scheduler(new cta::Scheduler(*ns, *scheddb, *remoteStorage)) {
XrdProFilesystem::XrdProFilesystem():
m_remoteStorage("localhost:1094"),
m_backend(castor::common::CastorConfiguration::getConfig().getConfEntString("TapeServer", "ObjectStoreBackendPath")),
m_backendPopulator(m_backend),
m_scheddb(m_backend, m_backendPopulator.getAgent()),
m_scheduler(m_ns, m_scheddb, m_remoteStorage)
{
m_backend.noDeleteOnExit();
const cta::SecurityIdentity bootstrap_requester;
m_scheduler->createAdminUserWithoutAuthorizingRequester(bootstrap_requester,
cta::UserIdentity(getuid(),getgid()), "Bootstrap operator");
m_scheduler->createAdminHostWithoutAuthorizingRequester(bootstrap_requester,
"localhost", "Bootstrap operator host");
try {
m_scheduler.createAdminUserWithoutAuthorizingRequester(bootstrap_requester, cta::UserIdentity(getuid(),getgid()), "Bootstrap operator");
m_scheduler.createAdminHostWithoutAuthorizingRequester(bootstrap_requester, "localhost", "Bootstrap operator host");
} catch (cta::exception::Exception &ex) {
std::cout << "[WARNING] Could not create the admin user and admin host. CTA exception caught: " << ex.getMessageValue() << "\n";
} catch (std::exception &ex) {
std::cout << "[WARNING] Could not create the admin user and admin host. Exception caught: " << ex.what() << "\n";
} catch (...) {
std::cout << "[WARNING] Could not create the admin user and admin host. Unknown exception caught!" << "\n";
}
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
XrdProFilesystem::~XrdProFilesystem() {
delete m_scheduler;
delete m_ns;
}
......@@ -19,8 +19,12 @@
#pragma once
#include "nameserver/mockNS/MockNameServer.hpp"
#include "objectstore/BackendVFS.hpp"
#include "remotens/EosNS.hpp"
#include "remotens/RemoteNS.hpp"
#include "scheduler/Scheduler.hpp"
#include "xroot_plugins/BackendPopulator.hpp"
#include "xroot_plugins/OStoreDBWithAgent.hpp"
#include "XrdSfs/XrdSfsInterface.hh"
......@@ -50,7 +54,7 @@ public:
virtual int stat(const char *Name, struct stat *buf, XrdOucErrInfo &eInfo, const XrdSecEntity *client = 0,const char *opaque = 0);
virtual int stat(const char *path, mode_t &mode, XrdOucErrInfo &eInfo, const XrdSecEntity *client = 0, const char *opaque = 0);
virtual int truncate(const char *path, XrdSfsFileOffset fsize, XrdOucErrInfo &eInfo, const XrdSecEntity *client = 0, const char *opaque = 0);
XrdProFilesystem(cta::NameServer *ns, cta::SchedulerDatabase *scheddb, cta::RemoteNS *remoteStorage);
XrdProFilesystem();
~XrdProFilesystem();
protected:
......@@ -58,20 +62,30 @@ protected:
/**
* The CTA nameserver
*/
cta::NameServer *m_ns;
cta::CastorNameServer m_ns;
/**
* The remote file storage system (typically EOS)
*/
cta::EosNS m_remoteStorage;
/**
* The database or object store holding all CTA persistent objects
* The VFS backend for the objectstore DB
*/
cta::SchedulerDatabase *m_scheddb;
cta::objectstore::BackendVFS m_backend;
/**
* The remote file storage system (typically EOS)
* The object used to populate the backend
*/
BackendPopulator m_backendPopulator;
/**
* The database or object store holding all CTA persistent objects
*/
cta::RemoteNS *m_remoteStorage;
OStoreDBWithAgent m_scheddb;
/**
* The scheduler.
*/
cta::Scheduler *m_scheduler;
cta::Scheduler m_scheduler;
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment