Skip to content

Commit

Permalink
XrdApps: add new JCache client plug-in with a pure pass-through imple…
Browse files Browse the repository at this point in the history
…mentation
  • Loading branch information
apeters1971 committed May 31, 2024
1 parent 619e93f commit 60603a3
Show file tree
Hide file tree
Showing 7 changed files with 656 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/XrdApps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#-------------------------------------------------------------------------------
set( LIB_XRDCL_PROXY_PLUGIN XrdClProxyPlugin-${PLUGIN_VERSION} )
set( LIB_XRDCL_RECORDER_PLUGIN XrdClRecorder-${PLUGIN_VERSION} )
set( LIB_XRDCL_JCACHE_PLUGIN XrdClJCachePlugin-${PLUGIN_VERSION} )

#-------------------------------------------------------------------------------
# Shared library version
Expand Down Expand Up @@ -202,11 +203,23 @@ target_link_libraries(
XrdCl
XrdUtils )

#-------------------------------------------------------------------------------
# XrdClJCachePlugin library
#-------------------------------------------------------------------------------
add_library(
${LIB_XRDCL_JCACHE_PLUGIN}
MODULE
XrdApps/XrdClJCachePlugin/XrdClJCachePlugin.cc
XrdApps/XrdClJCachePlugin/XrdClJCacheFile.cc)

target_link_libraries(${LIB_XRDCL_JCACHE_PLUGIN} PRIVATE XrdCl)


#-------------------------------------------------------------------------------
# Install
#-------------------------------------------------------------------------------
install(
TARGETS XrdAppUtils ${LIB_XRDCL_PROXY_PLUGIN} ${LIB_XRDCL_RECORDER_PLUGIN}
TARGETS XrdAppUtils ${LIB_XRDCL_PROXY_PLUGIN} ${LIB_XRDCL_RECORDER_PLUGIN} ${LIB_XRDCL_JCACHE_PLUGIN}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )

Expand Down
37 changes: 37 additions & 0 deletions src/XrdApps/XrdClJCachePlugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//------------------------------------------------------------------------------
// Copyright (c) 2024 by European Organization for Nuclear Research (CERN)
// Author: Andreas-Joachim Peters <[email protected]>
//------------------------------------------------------------------------------
// This file is part of the XRootD software suite.
//
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD 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 Lesser General Public License
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
//
// 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.

add_library(XrdClJCacheClient MODULE
XrdCLJCachePlugin.cc XrdClJCachePlugin.hh
XrdClJCacheFile.cc XrdClJCacheFile.hh)

set_target_properties(XrdClJCacheClient PROPERTIES
VERSION ${VERSION}
SOVERSION ${VERSION_MAJOR}
MACOSX_RPATH TRUE)

install(TARGETS XrdClJCacheClient
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})

311 changes: 311 additions & 0 deletions src/XrdApps/XrdClJCachePlugin/XrdClJCacheFile.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
//------------------------------------------------------------------------------
// Copyright (c) 2024 by European Organization for Nuclear Research (CERN)
// Author: Andreas-Joachim Peters <[email protected]>
//------------------------------------------------------------------------------
// This file is part of the XRootD software suite.
//
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD 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 Lesser General Public License
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
//
// 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 "XrdClJCacheFile.hh"
/*----------------------------------------------------------------------------*/

std::string JCacheFile::sCachePath="";

//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
JCacheFile::JCacheFile():
mIsOpen(false),
pFile(0)
{
}


//------------------------------------------------------------------------------
// Destructor
//------------------------------------------------------------------------------
JCacheFile::~JCacheFile()
{

if (pFile) {
delete pFile;
}
}


//------------------------------------------------------------------------------
// Open
//------------------------------------------------------------------------------
XRootDStatus
JCacheFile::Open(const std::string& url,
OpenFlags::Flags flags,
Access::Mode mode,
ResponseHandler* handler,
uint16_t timeout)
{
XRootDStatus st;

if (mIsOpen) {
st = XRootDStatus(stError, errInvalidOp);
return st;
}

pFile = new XrdCl::File(false);
st = pFile->Open(url, flags, mode, handler, timeout);

if (st.IsOK()) {
mIsOpen = true;
}


if ((flags & OpenFlags::Flags::Read) == OpenFlags::Flags::Read) {
// attach to a cache
}

return st;
}


//------------------------------------------------------------------------------
// Close
//------------------------------------------------------------------------------
XRootDStatus
JCacheFile::Close(ResponseHandler* handler,
uint16_t timeout)
{
XRootDStatus st;

if (mIsOpen) {
mIsOpen = false;

if (pFile) {
st = pFile->Close(handler, timeout);
}
} else {
// File already closed
st = XRootDStatus(stError, errInvalidOp);
XRootDStatus* ret_st = new XRootDStatus(st);
handler->HandleResponse(ret_st, 0);
}

return st;
}


//------------------------------------------------------------------------------
// Stat
//------------------------------------------------------------------------------
XRootDStatus
JCacheFile::Stat(bool force,
ResponseHandler* handler,
uint16_t timeout)
{
XRootDStatus st;

if (pFile) {
st = pFile->Stat(force, handler, timeout);
} else {
st = XRootDStatus(stError, errInvalidOp);
}

return st;
}


//------------------------------------------------------------------------------
// Read
//------------------------------------------------------------------------------
XRootDStatus
JCacheFile::Read(uint64_t offset,
uint32_t size,
void* buffer,
ResponseHandler* handler,
uint16_t timeout)
{
XRootDStatus st;

if (pFile) {
st = pFile->Read(offset, size, buffer, handler, timeout);
} else {
st = XRootDStatus(stError, errInvalidOp);
}
return st;
}


//------------------------------------------------------------------------------
// Write
//------------------------------------------------------------------------------
XRootDStatus
JCacheFile::Write(uint64_t offset,
uint32_t size,
const void* buffer,
ResponseHandler* handler,
uint16_t timeout)
{
XRootDStatus st;

if (pFile) {
st = pFile->Write(offset, size, buffer, handler, timeout);
} else {
st = XRootDStatus(stError, errInvalidOp);
}

return st;
}


//------------------------------------------------------------------------------
// Sync
//------------------------------------------------------------------------------
XRootDStatus
JCacheFile::Sync(ResponseHandler* handler,
uint16_t timeout)
{
XRootDStatus st;

if (pFile) {
st = pFile->Sync(handler, timeout);
} else {
st = XRootDStatus(stError, errInvalidOp);
}

return st;
}


//------------------------------------------------------------------------------
// Truncate
//------------------------------------------------------------------------------
XRootDStatus
JCacheFile::Truncate(uint64_t size,
ResponseHandler* handler,
uint16_t timeout)
{
XRootDStatus st;

if (pFile) {
st = pFile->Truncate(size, handler, timeout);
} else {
st = XRootDStatus(stError, errInvalidOp);
}

return st;
}


//------------------------------------------------------------------------------
// VectorRead
//------------------------------------------------------------------------------
XRootDStatus
JCacheFile::VectorRead(const ChunkList& chunks,
void* buffer,
ResponseHandler* handler,
uint16_t timeout)
{
XRootDStatus st;

if (pFile) {
st = pFile->VectorRead(chunks, buffer, handler, timeout);
} else {
st = XRootDStatus(stError, errInvalidOp);
}

return st;
}


//------------------------------------------------------------------------------
// Fcntl
//------------------------------------------------------------------------------
XRootDStatus
JCacheFile::Fcntl(const XrdCl::Buffer& arg,
ResponseHandler* handler,
uint16_t timeout)
{
XRootDStatus st;

if (pFile) {
st = pFile->Fcntl(arg, handler, timeout);
} else {
st = XRootDStatus(stError, errInvalidOp);
}

return st;
}


//------------------------------------------------------------------------------
// Visa
//------------------------------------------------------------------------------
XRootDStatus
JCacheFile::Visa(ResponseHandler* handler,
uint16_t timeout)
{
XRootDStatus st;

if (pFile) {
st = pFile->Visa(handler, timeout);
} else {
st = XRootDStatus(stError, errInvalidOp);
}

return st;
}


//------------------------------------------------------------------------------
// IsOpen
//------------------------------------------------------------------------------
bool
JCacheFile::IsOpen() const
{
return mIsOpen;
}


//------------------------------------------------------------------------------
// @see XrdCl::File::SetProperty
//------------------------------------------------------------------------------
bool
JCacheFile::SetProperty(const std::string& name,
const std::string& value)
{
if (pFile) {
return pFile->SetProperty(name, value);
} else {
return false;
}
}


//------------------------------------------------------------------------------
// @see XrdCl::File::GetProperty
//------------------------------------------------------------------------------
bool
JCacheFile::GetProperty(const std::string& name,
std::string& value) const
{
if (pFile) {
return pFile->GetProperty(name, value);
} else {
return false;
}
}

Loading

0 comments on commit 60603a3

Please sign in to comment.