From de7a96ae227c7dc1e51f9a3f25912b2730c4c637 Mon Sep 17 00:00:00 2001 From: Alja Mrak-Tadel Date: Wed, 14 Jan 2015 10:51:37 -0800 Subject: [PATCH 1/2] Use oss consistently -- replace statvfs with XrdOssSys::StatVS. --- src/XrdFileCache/XrdFileCacheFactory.cc | 28 +++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/XrdFileCache/XrdFileCacheFactory.cc b/src/XrdFileCache/XrdFileCacheFactory.cc index 533165e3145..90ab7742113 100644 --- a/src/XrdFileCache/XrdFileCacheFactory.cc +++ b/src/XrdFileCache/XrdFileCacheFactory.cc @@ -29,6 +29,7 @@ #include "XrdSys/XrdSysError.hh" #include "XrdSys/XrdSysLogger.hh" #include "XrdOuc/XrdOucEnv.hh" +#include "XrdOss/XrdOssCache.hh" #include "XrdOuc/XrdOucPinLoader.hh" #include "XrdOuc/XrdOucStream.hh" #include "XrdOuc/XrdOuca2x.hh" @@ -244,7 +245,11 @@ bool Factory::Config(XrdSysLogger *logger, const char *config_filename, const ch if (retval) { - if (ofsCfg->Load(XrdOfsConfigPI::theOssLib)) ofsCfg->Plugin(m_output_fs); + if (ofsCfg->Load(XrdOfsConfigPI::theOssLib)) { + ofsCfg->Plugin(m_output_fs); + XrdOssCache_FS* ocfs = XrdOssCache::Find("public"); + ocfs->Add(m_configuration.m_cache_dir.c_str()); + } else { clLog()->Error(XrdCl::AppMsg, "Factory::Config() Unable to create an OSS object"); @@ -423,24 +428,25 @@ void Factory::CacheDirCleanup() XrdOss* oss = Factory::GetInstance().GetOss(); XrdOssDF* dh = oss->newDir(m_configuration.m_username.c_str()); + XrdOssVSInfo sP; + while (1) { // get amount of space to erase long long bytesToRemove = 0; - struct statvfs fsstat; - if(statvfs(m_configuration.m_cache_dir.c_str(), &fsstat) < 0 ) + if( oss->StatVS(&sP, "public", 1) < 0 ) { - clLog()->Error(XrdCl::AppMsg, "Factory::CacheDirCleanup() can't get statvfs for dir [%s] \n", m_configuration.m_cache_dir.c_str()); + clLog()->Error(XrdCl::AppMsg, "Factory::CacheDirCleanup() can't get statvs for dir [%s] \n", m_configuration.m_cache_dir.c_str()); exit(1); } else { - float oc = 1 - float(fsstat.f_bfree)/fsstat.f_blocks; + float oc = 1 - float(sP.Free)/(sP.Total); clLog()->Debug(XrdCl::AppMsg, "Factory::CacheDirCleanup() occupates disk space == %f", oc); if (oc > m_configuration.m_hwm) { long long bytesToRemoveLong = static_cast ((oc - m_configuration.m_lwm) * static_cast(s_diskSpacePrecisionFactor)); - bytesToRemove = (fsstat.f_bsize * fsstat.f_blocks * bytesToRemoveLong) / s_diskSpacePrecisionFactor; + bytesToRemove = (sP.Total * bytesToRemoveLong) / s_diskSpacePrecisionFactor; clLog()->Info(XrdCl::AppMsg, "Factory::CacheDirCleanup() need space for %lld bytes", bytesToRemove); } } @@ -494,17 +500,17 @@ bool Factory::CheckFileForDiskSpace(const char* path, long long fsize) inQueue += i->second; - long long availableSpace = 0;; - struct statvfs fsstat; + XrdOssVSInfo sP; + long long availableSpace = 0; - if(statvfs(m_configuration.m_cache_dir.c_str(), &fsstat) < 0 ) { + if(m_output_fs->StatVS(&sP, "public", 1) < 0 ) { clLog()->Error(XrdCl::AppMsg, "Factory:::CheckFileForDiskSpace can't get statvfs for dir [%s] \n", m_configuration.m_cache_dir.c_str()); exit(1); } - float oc = 1 - float(fsstat.f_bfree)/fsstat.f_blocks; + float oc = 1 - float(sP.Free)/sP.Total; long long availableSpaceLong = static_cast((m_configuration.m_hwm -oc)* static_cast(s_diskSpacePrecisionFactor)); if (oc < m_configuration.m_hwm) { - availableSpace = (fsstat.f_bsize * fsstat.f_blocks * availableSpaceLong) / s_diskSpacePrecisionFactor; + availableSpace = (sP.Free * availableSpaceLong) / s_diskSpacePrecisionFactor; if (availableSpace > fsize) { m_filesInQueue[path] = fsize; From e1a9eceea2a54094b568cf9bfcc5fef29e0e90a5 Mon Sep 17 00:00:00 2001 From: Alja Mrak-Tadel Date: Wed, 14 Jan 2015 13:35:15 -0800 Subject: [PATCH 2/2] Fix bug in removing purged file within lwm and hwm limits. --- src/XrdFileCache/XrdFileCacheFactory.cc | 8 ++++---- src/XrdFileCache/XrdFileCacheInfo.cc | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/XrdFileCache/XrdFileCacheFactory.cc b/src/XrdFileCache/XrdFileCacheFactory.cc index 90ab7742113..975a62c3c7b 100644 --- a/src/XrdFileCache/XrdFileCacheFactory.cc +++ b/src/XrdFileCache/XrdFileCacheFactory.cc @@ -366,16 +366,16 @@ bool Factory::ConfigParameters(std::string part, XrdOucStream& config ) //______________________________________________________________________________ -void FillFileMapRecurse( XrdOssDF* df, const std::string& path, std::map& fcmap) +void FillFileMapRecurse( XrdOssDF* iOssDF, const std::string& path, std::map& fcmap) { char buff[256]; XrdOucEnv env; int rdr; - const size_t InfoExtLen = sizeof(XrdFileCache::Info::m_infoExtension); // cached var + const size_t InfoExtLen = strlen(XrdFileCache::Info::m_infoExtension); // cached var XrdCl::Log *log = XrdCl::DefaultEnv::GetLog(); Factory& factory = Factory::GetInstance(); - while ( (rdr = df->Readdir(&buff[0], 256)) >= 0) + while ( (rdr = iOssDF->Readdir(&buff[0], 256)) >= 0) { // printf("readdir [%s]\n", buff); std::string np = path + "/" + std::string(buff); @@ -413,7 +413,7 @@ void FillFileMapRecurse( XrdOssDF* df, const std::string& path, std::mapRead(&stat, off, sizeof(AStat)); + res = fp->Read(&stat, off, sizeof(AStat)); if (res == sizeof(AStat)) { t = stat.DetachTime;