From dd1441453d1d0e1588773e015b7ff7fc82825a66 Mon Sep 17 00:00:00 2001 From: Alja Mrak-Tadel Date: Wed, 30 Mar 2016 14:41:17 -0700 Subject: [PATCH] Implement virtual ouc-cache Prepare(). --- src/XrdFileCache/XrdFileCache.cc | 39 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/XrdFileCache/XrdFileCache.cc b/src/XrdFileCache/XrdFileCache.cc index 383579cb59b..b460ebc3cd1 100644 --- a/src/XrdFileCache/XrdFileCache.cc +++ b/src/XrdFileCache/XrdFileCache.cc @@ -336,11 +336,31 @@ Cache::GetNextFileToPrefetch() } //______________________________________________________________________________ +//! Preapare the cache for a file open request. This method is called prior to +//! actually opening a file. This method is meant to allow defering an open +//! request or implementing the full I/O stack in the cache layer. +//! @return <0 Error has occurred, return value is -errno; fail open request. +//! =0 Continue with open() request. +//! >0 Defer open but treat the file as actually being open. Use the +//! XrdOucCacheIO2::Open() method to open the file at a later time. +//------------------------------------------------------------------------------ int Cache::Prepare(const char *url, int oflags, mode_t mode) { - return 1; + std::string curl(url); + XrdCl::URL xx(curl); + const std::string& spath = xx.GetPath(); + + struct stat buf; + int res = m_output_fs->Stat(spath.c_str(), &buf); + if (res == 0) { + XrdCl::DefaultEnv::GetLog()->Dump(XrdCl::AppMsg, "Cache::Prefetch defer open %s", spath.c_str()); + return 1; + } + else { + return 0; + } } //______________________________________________________________________________ @@ -348,22 +368,7 @@ Cache::Prepare(const char *url, int oflags, mode_t mode) int Cache::Stat(const char *curl, struct stat &sbuff) { - XrdCl::URL url(curl); - std::string fname = Cache::GetInstance().RefConfiguration().m_cache_dir + url.GetPath(); - fname += ".cinfo"; - - XrdOucEnv myEnv; - XrdOssDF* df = m_output_fs->newFile(Cache::GetInstance().RefConfiguration().m_username.c_str()); - int res = df->Open(fname.c_str(), O_RDONLY, 0600, myEnv); - if (res != 0) - return 1; - - df->Fstat(&sbuff); - - Info cinfo(0); - cinfo.Read(df); - sbuff.st_size = cinfo.GetSizeInBits(); - delete df; + assert(0 && "Cache::Stat() should not be called."); return 0; }