diff --git a/src/XrdPosix/XrdPosixFile.hh b/src/XrdPosix/XrdPosixFile.hh index d9e2adf052c..116c52ac536 100644 --- a/src/XrdPosix/XrdPosixFile.hh +++ b/src/XrdPosix/XrdPosixFile.hh @@ -97,6 +97,10 @@ static void DelayedDestroy(XrdPosixFile *fp); void isOpen(); + void updLock() {updMutex.Lock();} + + void updUnLock() {updMutex.UnLock();} + long long Offset() {AtomicRet(updMutex, currOffset);} const char *Path() {return fPath;} diff --git a/src/XrdPosix/XrdPosixObjGaurd.hh b/src/XrdPosix/XrdPosixObjGaurd.hh index b9b9b1d3012..75a293b81d7 100644 --- a/src/XrdPosix/XrdPosixObjGaurd.hh +++ b/src/XrdPosix/XrdPosixObjGaurd.hh @@ -30,24 +30,24 @@ /* specific prior written permission of the institution or contributor. */ /******************************************************************************/ -#include "XrdPosix/XrdPosixObject.hh" +#include "XrdPosix/XrdPosixFile.hh" class XrdPosixObjGaurd { public: -void Init(XrdPosixObject *oP, bool rw=true) - {if (objP) Release(); - objP = oP; - objP->Lock(rw); +void Init(XrdPosixFile *fP) + {if (gaurdP) gaurdP->updUnLock(); + gaurdP = fP; + gaurdP->updLock(); } -void Release() {if (objP) {objP->UnLock(); objP = 0;}} +void Release() {if (gaurdP) {gaurdP->updUnLock(); gaurdP = 0;}} - XrdPosixObjGaurd(XrdPosixObject *oP, bool rw=true) {Init(oP, rw);} + XrdPosixObjGaurd(XrdPosixFile *fP) {Init(fP);} ~XrdPosixObjGaurd() {Release();} private: -XrdPosixObject *objP; +XrdPosixFile *gaurdP; }; #endif diff --git a/src/XrdPosix/XrdPosixPrepIO.cc b/src/XrdPosix/XrdPosixPrepIO.cc index 754d35b57c5..ab10e4ad280 100644 --- a/src/XrdPosix/XrdPosixPrepIO.cc +++ b/src/XrdPosix/XrdPosixPrepIO.cc @@ -49,7 +49,7 @@ extern bool psxDBG; bool XrdPosixPrepIO::Init(XrdOucCacheIOCB *iocbP) { - XrdPosixObjGaurd objGaurd((XrdPosixObject *)fileP); + XrdPosixObjGaurd objGaurd(fileP); XrdCl::XRootDStatus Status; static int maxCalls = 64; diff --git a/src/XrdPosix/XrdPosixPrepIO.hh b/src/XrdPosix/XrdPosixPrepIO.hh index 18c51019e67..ff3f7402113 100644 --- a/src/XrdPosix/XrdPosixPrepIO.hh +++ b/src/XrdPosix/XrdPosixPrepIO.hh @@ -41,43 +41,43 @@ XrdOucCacheIO *Base() {return this;} // Already defined XrdOucCacheIO *Detach() {return this;} // Already defined -long long FSize() {return (Init() ? FSize() : openRC);} +long long FSize() {return (Init() ? fileP->FSize() : openRC);} bool ioActive() { return false; } // Already defined const char *Path() {return fileP->Path();} int Read (char *Buffer, long long Offset, int Length) - {return (Init() ? Read(Buffer, Offset, Length) : openRC);} + {return (Init() ? fileP->Read(Buffer, Offset, Length) : openRC);} void Read (XrdOucCacheIOCB &iocb, char *buff, long long offs, int rlen) - {if (Init(&iocb)) Read(iocb, buff, offs, rlen); + {if (Init(&iocb)) fileP->Read(iocb, buff, offs, rlen); else iocb.Done(openRC); } int ReadV(const XrdOucIOVec *readV, int n) - {return (Init() ? ReadV(readV, n) : openRC);} + {return (Init() ? fileP->ReadV(readV, n) : openRC);} void ReadV(XrdOucCacheIOCB &iocb, const XrdOucIOVec *readV, int rnum) - {if (Init(&iocb)) ReadV(iocb, readV, rnum); + {if (Init(&iocb)) fileP->ReadV(iocb, readV, rnum); else iocb.Done(openRC); } -int Sync() {return (Init() ? Sync() : openRC);} +int Sync() {return (Init() ? fileP->Sync() : openRC);} void Sync(XrdOucCacheIOCB &iocb) - {if (Init(&iocb)) Sync(iocb); + {if (Init(&iocb)) fileP->Sync(iocb); else iocb.Done(openRC); } int Trunc(long long Offset) - {return (Init() ? Trunc(Offset) : openRC);} + {return (Init() ? fileP->Trunc(Offset) : openRC);} int Write(char *Buffer, long long Offset, int Length) - {return (Init() ? Write(Buffer, Offset, Length) : openRC);} + {return (Init() ? fileP->Write(Buffer,Offset,Length) : openRC);} void Write(XrdOucCacheIOCB &iocb, char *buff, long long offs, int wlen) - {if (Init(&iocb)) Write(iocb, buff, offs, wlen); + {if (Init(&iocb)) fileP->Write(iocb, buff, offs, wlen); else iocb.Done(openRC); } diff --git a/src/XrdPosix/XrdPosixXrootd.cc b/src/XrdPosix/XrdPosixXrootd.cc index 84b94dbecfc..77f83299a4d 100644 --- a/src/XrdPosix/XrdPosixXrootd.cc +++ b/src/XrdPosix/XrdPosixXrootd.cc @@ -294,15 +294,42 @@ int XrdPosixXrootd::endPoint(int FD, char *Buff, int Blen) int XrdPosixXrootd::Fstat(int fildes, struct stat *buf) { XrdPosixFile *fp; + long long theSize; // Find the file object // if (!(fp = XrdPosixObject::File(fildes))) return -1; -// Return what little we can +// First initialize the stat buffer // initStat(buf); - buf->st_size = fp->FSize(); + +// Check if we can get the stat information from the cache. +// + if (myCache2) + {int rc = myCache2->Stat(fp->Path(), *buf); + if (rc <= 0) + {fp->UnLock(); + if (!rc) return 0; + errno = -rc; + return -1; + } + } + +// We need to trat getting the size separately as this file may still not be +// open. This gets resolved via the cache layer. +// + theSize = fp->XCio->FSize(); + if (theSize < 0) + {fp->UnLock(); + errno = static_cast(-theSize); + return -1; + } + + +// Return what little we can +// + buf->st_size = theSize; buf->st_atime = buf->st_mtime = buf->st_ctime = fp->myMtime; buf->st_blocks = buf->st_size/512+1; buf->st_ino = fp->myInode; @@ -1009,9 +1036,13 @@ int XrdPosixXrootd::Stat(const char *path, struct stat *buf) // Make sure the admin is OK // - if (!admin.isOK()) return -1; + if (!admin.isOK()) return -1; -// Check if we can get the stat informat directly +// Initialize the stat buffer +// + initStat(buf); + +// Check if we can get the stat informatation from the cache // if (myCache2) {std::string urlp = admin.Url.GetPathWithParams(); @@ -1026,7 +1057,6 @@ int XrdPosixXrootd::Stat(const char *path, struct stat *buf) // Return what little we can // - initStat(buf); buf->st_size = stSize; buf->st_blocks = stSize/512+1; buf->st_atime = buf->st_mtime = buf->st_ctime = stMtime;