Skip to content

Commit

Permalink
More fixes to defered open.
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 committed Mar 24, 2016
1 parent 163d6c5 commit d6b4168
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 24 deletions.
4 changes: 4 additions & 0 deletions src/XrdPosix/XrdPosixFile.hh
Expand Up @@ -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;}
Expand Down
16 changes: 8 additions & 8 deletions src/XrdPosix/XrdPosixObjGaurd.hh
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/XrdPosix/XrdPosixPrepIO.cc
Expand Up @@ -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;

Expand Down
20 changes: 10 additions & 10 deletions src/XrdPosix/XrdPosixPrepIO.hh
Expand Up @@ -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);
}

Expand Down
40 changes: 35 additions & 5 deletions src/XrdPosix/XrdPosixXrootd.cc
Expand Up @@ -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<int>(-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;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit d6b4168

Please sign in to comment.