From 9118903f75457239f23afdf6ed4207fff0a9c559 Mon Sep 17 00:00:00 2001 From: Andrew Hanushevsky Date: Thu, 16 Jun 2016 03:20:10 -0700 Subject: [PATCH] Add Location() method to CacheIO2 to get file location. --- src/XrdOuc/XrdOucCache2.hh | 9 +++++++++ src/XrdPosix/XrdPosixCacheBC.hh | 3 +++ src/XrdPosix/XrdPosixFile.cc | 31 +++++++++++++++++++++++++++++-- src/XrdPosix/XrdPosixFile.hh | 5 ++++- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/XrdOuc/XrdOucCache2.hh b/src/XrdOuc/XrdOucCache2.hh index a27396f5e28..f7487056df1 100644 --- a/src/XrdOuc/XrdOucCache2.hh +++ b/src/XrdOuc/XrdOucCache2.hh @@ -76,6 +76,15 @@ public: virtual int Fstat(struct stat &sbuff) {(void)sbuff; return 1;} +//----------------------------------------------------------------------------- +//! Get the file's location (i.e. endpoint hostname and port) +//! +//! @return A pointer to the file's location. It remains valid until the file +//! is closed. A null string means the file is not open or is unknown. +//----------------------------------------------------------------------------- +virtual +const char *Location() {return "";} + //------------------------------------------------------------------------------ //! Perform an asynchronous read (defaults to synchrnous). //! diff --git a/src/XrdPosix/XrdPosixCacheBC.hh b/src/XrdPosix/XrdPosixCacheBC.hh index 54d05125876..20b65ff88d6 100644 --- a/src/XrdPosix/XrdPosixCacheBC.hh +++ b/src/XrdPosix/XrdPosixCacheBC.hh @@ -55,6 +55,9 @@ long long FSize() {return cacheIO1->FSize();} virtual int Fstat(struct stat &buf) {return cacheIO2->Fstat(buf);} +virtual +const char *Location() {return cacheIO2->Location();} + virtual const char *Path() {return cacheIO1->Path();} diff --git a/src/XrdPosix/XrdPosixFile.cc b/src/XrdPosix/XrdPosixFile.cc index 988af11d8e3..cf245f3f6a7 100644 --- a/src/XrdPosix/XrdPosixFile.cc +++ b/src/XrdPosix/XrdPosixFile.cc @@ -59,6 +59,8 @@ pthread_t tid; XrdSysThread::Run(&tid, XrdPosixFile::DelayedDestroy, 0, 0, "PosixFileDestroy"); return (XrdPosixFile *)0; } + +std::string dsProperty("DataServer"); }; XrdSysSemaphore XrdPosixFile::ddSem(0); @@ -77,7 +79,7 @@ XrdPosixFile::XrdPosixFile(const char *path, XrdPosixCallBack *cbP, int Opts) : XCio((XrdOucCacheIO2 *)this), PrepIO(0), mySize(0), myMtime(0), myInode(0), myMode(0), theCB(cbP), - fPath(strdup(path)), + fPath(strdup(path)), fLoc(0), cOpt(0), isStream(Opts & isStrm ? 1 : 0) { @@ -113,9 +115,10 @@ XrdPosixFile::~XrdPosixFile() // if (PrepIO) delete PrepIO; -// Free the path +// Free the path and location information // if (fPath) free(fPath); + if (fLoc) free(fLoc); } /******************************************************************************/ @@ -300,6 +303,30 @@ void XrdPosixFile::HandleResponse(XrdCl::XRootDStatus *status, if (rc) delete this; } +/******************************************************************************/ +/* L o c a t i o n */ +/******************************************************************************/ + +const char *XrdPosixFile::Location() +{ + +// If the file is not open, then we have no location +// + if (!clFile.IsOpen()) return 0; + +// If we have no location info, get it +// + if (!fLoc) + {std::string currNode; + if (clFile.GetProperty(dsProperty, currNode)) + fLoc = strdup(currNode.c_str()); + } + +// Return location information +// + return fLoc; +} + /******************************************************************************/ /* R e a d */ /******************************************************************************/ diff --git a/src/XrdPosix/XrdPosixFile.hh b/src/XrdPosix/XrdPosixFile.hh index 1f12025494b..6116b147def 100644 --- a/src/XrdPosix/XrdPosixFile.hh +++ b/src/XrdPosix/XrdPosixFile.hh @@ -76,7 +76,7 @@ XrdCl::File clFile; return retOffset; } -static XrdPosixFile *Alloc(const char *path, XrdPosixCallBack *cbP, int Opts); +//atic XrdPosixFile *Alloc(const char *path, XrdPosixCallBack *cbP, int Opts); static void* DelayedDestroy(void*); @@ -94,6 +94,8 @@ static void DelayedDestroy(XrdPosixFile *fp); int Fstat(struct stat &buf); + const char *Location(); + void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response); @@ -180,6 +182,7 @@ union {long long currOffset; }; char *fPath; +char *fLoc; union {int cOpt; int numTries;}; char isStream; };