Skip to content

Commit

Permalink
Add Location() method to CacheIO2 to get file location.
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 committed Jun 30, 2016
1 parent ef7dc5a commit 104ef69
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/XrdOuc/XrdOucCache2.hh
Expand Up @@ -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).
//!
Expand Down
3 changes: 3 additions & 0 deletions src/XrdPosix/XrdPosixCacheBC.hh
Expand Up @@ -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();}

Expand Down
31 changes: 29 additions & 2 deletions src/XrdPosix/XrdPosixFile.cc
Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
}

/******************************************************************************/
Expand Down Expand Up @@ -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 */
/******************************************************************************/
Expand Down
5 changes: 4 additions & 1 deletion src/XrdPosix/XrdPosixFile.hh
Expand Up @@ -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*);

Expand All @@ -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);

Expand Down Expand Up @@ -180,6 +182,7 @@ union {long long currOffset;
};

char *fPath;
char *fLoc;
union {int cOpt; int numTries;};
char isStream;
};
Expand Down

0 comments on commit 104ef69

Please sign in to comment.