Commit a1ee6f3e authored by Daniele Kruse's avatar Daniele Kruse
Browse files

Added virtual directory to allow EOS to get the list of file IDs given a specific instance

parent fadcff19
......@@ -7,7 +7,7 @@ include_directories(${XROOTD_INCLUDE_DIR} ${XROOTD_PRIVATE_INCLUDE_DIR})
include_directories(${CMAKE_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/tapeserver)
add_library (XrdCtaOfs MODULE XrdCtaFilesystem.cpp XrdCtaFile.cpp)
add_library (XrdCtaOfs MODULE XrdCtaFilesystem.cpp XrdCtaFile.cpp XrdCtaDir.cpp)
target_link_libraries (XrdCtaOfs ctacatalogue ctascheduler ctacommon ctaremotens protobuf ctaobjectstore cryptopp)
INSTALL (TARGETS XrdCtaOfs DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
......
/*
* 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 <iostream>
#include "XrdSec/XrdSecEntity.hh"
#include "catalogue/ArchiveFileSearchCriteria.hpp"
#include "xroot_plugins/XrdCtaDir.hpp"
namespace cta { namespace xrootPlugins {
//------------------------------------------------------------------------------
// checkClient
//------------------------------------------------------------------------------
void XrdCtaDir::checkClient(const XrdSecEntity *client) {
if(client==NULL || client->name==NULL || client->host==NULL) {
throw cta::exception::Exception(std::string(__FUNCTION__)+": [ERROR] XrdSecEntity from xroot contains invalid information (NULL pointer detected!)");
}
std::cout << "DIR Request received from client. Username: " << client->name << " Host: " << client->host << std::endl;
m_cliIdentity.username=client->name;
m_cliIdentity.host=client->host;
}
//------------------------------------------------------------------------------
// open
//------------------------------------------------------------------------------
int XrdCtaDir::open(const char *path, const XrdSecEntity *client, const char *opaque) {
try {
checkClient(client);
if(!path || strlen(path)<1){
throw cta::exception::Exception(std::string(__FUNCTION__)+": [ERROR] invalid virtual directory path");
}
cta::catalogue::ArchiveFileSearchCriteria searchCriteria;
searchCriteria.diskInstance = path; //the path will be the disk instance that we want the disk id's of
m_itor = m_catalogue->getArchiveFileItor(searchCriteria);
std::list<log::Param> params;
params.push_back(log::Param("USERNAME", m_cliIdentity.username));
params.push_back(log::Param("HOST", m_cliIdentity.host));
params.push_back(log::Param("DIRPATH", path));
m_log(log::INFO, "Successful Request", params);
return SFS_OK;
} catch (cta::exception::Exception &ex) {
std::list<log::Param> params;
params.push_back(log::Param("USERNAME", m_cliIdentity.username));
params.push_back(log::Param("HOST", m_cliIdentity.host));
if(path && strlen(path)) {
params.push_back(log::Param("DIRPATH", path));
}
params.push_back(log::Param("ERROR", ex.getMessageValue()));
m_log(log::ERR, "Unsuccessful Request", params);
error.setErrInfo(ENOTSUP, ex.getMessageValue().c_str());
return SFS_ERROR;
} catch (std::exception &ex) {
std::list<log::Param> params;
params.push_back(log::Param("USERNAME", m_cliIdentity.username));
params.push_back(log::Param("HOST", m_cliIdentity.host));
if(path && strlen(path)) {
params.push_back(log::Param("DIRPATH", path));
}
params.push_back(log::Param("ERROR", ex.what()));
m_log(log::ERR, "Unsuccessful Request", params);
error.setErrInfo(ENOTSUP, ex.what());
return SFS_ERROR;
} catch (...) {
std::list<log::Param> params;
params.push_back(log::Param("USERNAME", m_cliIdentity.username));
params.push_back(log::Param("HOST", m_cliIdentity.host));
if(path && strlen(path)) {
params.push_back(log::Param("DIRPATH", path));
}
params.push_back(log::Param("ERROR", "Unknown exception caught!"));
m_log(log::ERR, "Unsuccessful Request", params);
error.setErrInfo(ENOTSUP, "Unknown exception caught!");
return SFS_ERROR;
}
}
//------------------------------------------------------------------------------
// nextEntry
//------------------------------------------------------------------------------
const char* XrdCtaDir::nextEntry() {
if(!(m_itor->hasMore())) {
return NULL;
}
return m_itor->next().diskFileId.c_str();
}
//------------------------------------------------------------------------------
// close
//------------------------------------------------------------------------------
int XrdCtaDir::close() {
return SFS_OK;
}
//------------------------------------------------------------------------------
// FName
//------------------------------------------------------------------------------
const char* XrdCtaDir::FName() {
error.setErrInfo(ENOTSUP, "Not supported.");
return NULL;
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
XrdCtaDir::XrdCtaDir(cta::catalogue::Catalogue *catalogue, cta::log::Logger *log, const char *user, int MonID) : error(user, MonID), m_catalogue(catalogue), m_log(*log) {
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
XrdCtaDir::~XrdCtaDir() {
}
}}
/*
* 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 "catalogue/Catalogue.hpp"
#include "common/log/SyslogLogger.hpp"
#include "XrdSfs/XrdSfsInterface.hh"
#include <string>
#include <vector>
namespace cta { namespace xrootPlugins {
/**
* This class is used exclusively by EOS to get the list of EOS id's for a specific instance
*/
class XrdCtaDir : public XrdSfsDirectory {
public:
XrdOucErrInfo error;
virtual int open(const char *path, const XrdSecEntity *client = 0, const char *opaque = 0);
virtual const char *nextEntry();
virtual int close();
virtual const char *FName();
XrdCtaDir(cta::catalogue::Catalogue *catalogue, cta::log::Logger *log, const char *user=0, int MonID=0);
virtual ~XrdCtaDir();
protected:
/**
* The catalogue object pointer.
*/
cta::catalogue::Catalogue *m_catalogue;
/**
* The scheduler object pointer
*/
cta::log::Logger &m_log;
/**
* The archive file iterator used loop over catalogue results
*/
std::unique_ptr<cta::catalogue::ArchiveFileItor> m_itor;
/**
* The client identity info: username and host
*/
cta::common::dataStructures::SecurityIdentity m_cliIdentity;
/**
* Checks whether client has correct permissions and fills the corresponding SecurityIdentity structure
*
* @param client The client security entity
*/
void checkClient(const XrdSecEntity *client);
};
}}
......@@ -44,31 +44,7 @@ void XrdCtaFile::checkClient(const XrdSecEntity *client) {
if(client==NULL || client->name==NULL || client->host==NULL) {
throw cta::exception::Exception(std::string(__FUNCTION__)+": [ERROR] XrdSecEntity from xroot contains invalid information (NULL pointer detected!)");
}
struct passwd pwd;
struct passwd *result;
long bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
if (bufsize == -1)
{
bufsize = 16384;
}
std::unique_ptr<char> buf((char *)malloc((size_t)bufsize));
if(buf.get() == NULL)
{
throw cta::exception::Exception(std::string(__FUNCTION__)+": [ERROR] malloc of the buffer failed");
}
int rc = getpwnam_r(client->name, &pwd, buf.get(), bufsize, &result);
if(result == NULL)
{
if (rc == 0)
{
throw cta::exception::Exception(std::string(__FUNCTION__)+": [ERROR] User "+client->name+" not found");
}
else
{
throw cta::exception::Exception(std::string(__FUNCTION__)+": [ERROR] getpwnam_r failed");
}
}
std::cout << "Request received from client. Username: " << client->name << " uid: " << pwd.pw_uid << " gid: " << pwd.pw_gid << std::endl;
std::cout << "FILE Request received from client. Username: " << client->name << " Host: " << client->host << std::endl;
m_cliIdentity.username=client->name;
m_cliIdentity.host=client->host;
}
......
......@@ -36,6 +36,7 @@
#include "XrdVersion.hh"
#include "xroot_plugins/XrdCtaFilesystem.hpp"
#include "xroot_plugins/XrdCtaFile.hpp"
#include "XrdCtaDir.hpp"
#include <memory>
#include <iostream>
......@@ -89,8 +90,7 @@ XrdSfsFile * XrdCtaFilesystem::newFile(char *user, int MonID)
//------------------------------------------------------------------------------
XrdSfsDirectory * XrdCtaFilesystem::newDir(char *user, int MonID)
{
(void)user; (void)MonID;
return NULL;
return new cta::xrootPlugins::XrdCtaDir(m_catalogue.get(), m_log.get(), user, MonID);;
}
//------------------------------------------------------------------------------
......
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