Skip to content

Commit

Permalink
XrdApps::JCache fix OSX/clang build problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Peters committed Jul 26, 2024
1 parent 1e59561 commit 3361eb6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 30 deletions.
25 changes: 16 additions & 9 deletions src/XrdApps.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#-------------------------------------------------------------------------------
# Modules
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -210,10 +208,16 @@ add_executable(
xrdclcacheclean
XrdApps/XrdClJCachePlugin/app/XrdClCacheCleaner.cc )

target_link_libraries(
xrdclcacheclean
stdc++fs
)
if ( MacOSX )
target_link_libraries(
xrdclcacheclean
)
else()
target_link_libraries(
xrdclcacheclean
stdc++fs
)
endif()

#-------------------------------------------------------------------------------
# XrdClJCachePlugin library
Expand All @@ -237,10 +241,13 @@ add_library(
XrdApps/XrdClJCachePlugin/cleaner/Cleaner.hh
)

target_include_directories( ${LIB_XRDCL_JCACHE_PLUGIN} PRIVATE "${CMAKE_SOURCE_DIR}/src/XrdApps/XrdClJCachePlugin/" )
target_include_directories( ${LIB_XRDCL_JCACHE_PLUGIN} PRIVATE "${CMAKE_SOURCE_DIR}/src/XrdApps/XrdClJCachePlugin/" )

target_link_libraries(${LIB_XRDCL_JCACHE_PLUGIN} PRIVATE XrdCl stdc++fs)

if ( MacOSX )
target_link_libraries(${LIB_XRDCL_JCACHE_PLUGIN} PRIVATE XrdCl OpenSSL::SSL)
else ()
target_link_libraries(${LIB_XRDCL_JCACHE_PLUGIN} PRIVATE XrdCl stdc++fs OpenSSL::SSL)
endif ()

#-------------------------------------------------------------------------------
# Install
Expand Down
14 changes: 12 additions & 2 deletions src/XrdApps/XrdClJCachePlugin/cache/Journal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
#include <unistd.h>
/*----------------------------------------------------------------------------*/

#ifdef __APPLE__
#include <sys/uio.h>
#define pread64 pread
#define pwrite64 pwrite
#endif

//------------------------------------------------------------------------------
//! Journal Constructor
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -96,7 +102,7 @@ void Journal::read_jheader() {
if (jheader.mtime) {
if (exists) {
// we only compare if there was a header in the journal
if ((abs(fheader.mtime - jheader.mtime) > 1) ||
if ((abs((int)(fheader.mtime - jheader.mtime)) > 1) ||
(fheader.mtime_nsec != jheader.mtime_nsec) ||
(jheader.filesize && (fheader.filesize != jheader.filesize))) {
std::cerr << "warning: remote file change detected - purging path:"
Expand Down Expand Up @@ -183,7 +189,7 @@ int Journal::attach(const std::string &lpath, uint64_t mtime,
}
}
}
if ((fd == -1)) {
if (fd == -1) {
// need to open the file
size_t tries = 0;

Expand Down Expand Up @@ -462,7 +468,11 @@ int Journal::sync() {
if (fd < 0) {
return -1;
}
#ifdef __APPLE__
return ::fsync(fd);
#else
return ::fdatasync(fd);
#endif
}

//------------------------------------------------------------------------------
Expand Down
22 changes: 17 additions & 5 deletions src/XrdApps/XrdClJCachePlugin/cleaner/Cleaner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/*----------------------------------------------------------------------------*/
#include "cleaner/Cleaner.hh"
#include <sys/statfs.h>
#include <sys/statvfs.h>
/*----------------------------------------------------------------------------*/

namespace fs = std::filesystem;
Expand Down Expand Up @@ -64,13 +64,25 @@ long long Cleaner::getDirectorySize(const fs::path &directory, bool scan) {
}
}
} else {
struct statfs stat;
struct statvfs fs_info;

if (statfs(directory.c_str(), &stat) != 0) {
if (statvfs(directory.c_str(), &fs_info) != 0) {
mLog->Error(1,
"JCache:Cleaner: failed to get directory size using statfs.");
"JCache:Cleaner: failed to get directory size using statvfs.");
return 0;
}
// Calculate total space in bytes
unsigned long long total_blocks = fs_info.f_blocks;
unsigned long long block_size = fs_info.f_bsize;
unsigned long long total_space = total_blocks * block_size;

// Calculate free space in bytes
unsigned long long free_blocks = fs_info.f_bfree;
unsigned long long free_space = free_blocks * block_size;

// Calculate used space in bytes
unsigned long long used_space = total_space - free_space;
totalSize = used_space;
}
return totalSize;
}
Expand Down Expand Up @@ -143,4 +155,4 @@ void Cleaner::cleanDirectory(const fs::path &directory, long long highWatermark,
}
}
}
} // namespace JCache
} // namespace JCache
2 changes: 1 addition & 1 deletion src/XrdApps/XrdClJCachePlugin/file/Art.hh
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public:
<< runtime << "s ]" << std::endl;
}

void drawCurve(const std::vector<long unsigned int> &data, double interval,
void drawCurve(const std::vector<uint64_t> &data, double interval,
double runtime) {
std::vector<double> newdata;
if (interval == 0) {
Expand Down
26 changes: 13 additions & 13 deletions src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ public:
//----------------------------------------------------------------------------
virtual XRootDStatus Open(const std::string &url, OpenFlags::Flags flags,
Access::Mode mode, ResponseHandler *handler,
uint16_t timeout);
uint16_t timeout) override;

//----------------------------------------------------------------------------
//! @brief Close a file
//! @param handler Response handler
//! @param timeout Timeout in seconds
//----------------------------------------------------------------------------
virtual XRootDStatus Close(ResponseHandler *handler, uint16_t timeout);
virtual XRootDStatus Close(ResponseHandler *handler, uint16_t timeout) override;

//----------------------------------------------------------------------------
//! @brief Stat a file
Expand All @@ -98,7 +98,7 @@ public:
//! @param timeout Timeout in seconds
//----------------------------------------------------------------------------
virtual XRootDStatus Stat(bool force, ResponseHandler *handler,
uint16_t timeout);
uint16_t timeout) override;

//----------------------------------------------------------------------------
//! @brief Read
Expand All @@ -109,7 +109,7 @@ public:
//! @param timeout Timeout in seconds
//----------------------------------------------------------------------------
virtual XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer,
ResponseHandler *handler, uint16_t timeout);
ResponseHandler *handler, uint16_t timeout) override;

//----------------------------------------------------------------------------
//! @brief Write
Expand All @@ -120,14 +120,14 @@ public:
//! @param timeout Timeout in seconds
//----------------------------------------------------------------------------
virtual XRootDStatus Write(uint64_t offset, uint32_t size, const void *buffer,
ResponseHandler *handler, uint16_t timeout);
ResponseHandler *handler, uint16_t timeout) override;

//----------------------------------------------------------------------------
//! @brief Sync
//! @param handler Response handler
//! @param timeout Timeout in seconds
//----------------------------------------------------------------------------
virtual XRootDStatus Sync(ResponseHandler *handler, uint16_t timeout);
virtual XRootDStatus Sync(ResponseHandler *handler, uint16_t timeout) override;

//----------------------------------------------------------------------------
//! @brief Truncate
Expand All @@ -136,7 +136,7 @@ public:
//! @param timeout Timeout in seconds
//----------------------------------------------------------------------------
virtual XRootDStatus Truncate(uint64_t size, ResponseHandler *handler,
uint16_t timeout);
uint16_t timeout) override;

//----------------------------------------------------------------------------
//! @brief VectorRead
Expand All @@ -146,7 +146,7 @@ public:
//! @param timeout Timeout in seconds
//----------------------------------------------------------------------------
virtual XRootDStatus VectorRead(const ChunkList &chunks, void *buffer,
ResponseHandler *handler, uint16_t timeout);
ResponseHandler *handler, uint16_t timeout) override;

//------------------------------------------------------------------------
//! @brief PgRead
Expand Down Expand Up @@ -181,29 +181,29 @@ public:
//! @param timeout Timeout in seconds
//------------------------------------------------------------------------
virtual XRootDStatus Fcntl(const Buffer &arg, ResponseHandler *handler,
uint16_t timeout);
uint16_t timeout) override;

//----------------------------------------------------------------------------
//! @brief Visa
//! @param handler Response handler
//! @param timeout Timeout in seconds
//----------------------------------------------------------------------------
virtual XRootDStatus Visa(ResponseHandler *handler, uint16_t timeout);
virtual XRootDStatus Visa(ResponseHandler *handler, uint16_t timeout) override;

//----------------------------------------------------------------------------
//! @brief check if file is open
//----------------------------------------------------------------------------
virtual bool IsOpen() const;
virtual bool IsOpen() const override;

//----------------------------------------------------------------------------
//! @see XrdCl::File::SetProperty
//----------------------------------------------------------------------------
virtual bool SetProperty(const std::string &name, const std::string &value);
virtual bool SetProperty(const std::string &name, const std::string &value) override;

//----------------------------------------------------------------------------
//! @see XrdCl::File::GetProperty
//----------------------------------------------------------------------------
virtual bool GetProperty(const std::string &name, std::string &value) const;
virtual bool GetProperty(const std::string &name, std::string &value) const override;

//----------------------------------------------------------------------------
//! @brief validate the local cache
Expand Down

0 comments on commit 3361eb6

Please sign in to comment.