Skip to content

Commit

Permalink
Delete XrdPosixFile in a separate task if attached cache is IO active.
Browse files Browse the repository at this point in the history
  • Loading branch information
alja committed Mar 26, 2014
1 parent cd280d6 commit 7ebdd66
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/XrdOuc/XrdOucCache.hh
Expand Up @@ -244,6 +244,12 @@ virtual XrdOucCacheIO *Base() {return this;}
//
virtual XrdOucCacheIO *Detach() {return this;}


// ioActive() returns true if there is any ongoing IO operation. The function is
// used in XrdPosixXrootd::Close() to check if destruction od PosixFile
// has to be done in a separate task.
virtual bool ioActive() { return false; }

// Preread() places Length bytes into the cache from a data source at Offset.
// When there is no cache or the associated cache does not support or
// allow pre-reads, it's a no-op. Cache placement limits do not apply.
Expand Down
28 changes: 27 additions & 1 deletion src/XrdPosix/XrdPosixFile.cc
Expand Up @@ -91,7 +91,22 @@ XrdPosixFile::~XrdPosixFile()
//
if (fPath) free(fPath);
}


/******************************************************************************/
/* D e l a y e d D e s t r o y */
/******************************************************************************/

void* XrdPosixFile::DelayedDestroy(void* vpf)
{
// Static function.
// Called within a dedicated thread if XrdOucCacheIO is io-active.

XrdPosixFile* pf = (XrdPosixFile*)vpf;
delete pf;

return 0;
}

/******************************************************************************/
/* C l o s e */
/******************************************************************************/
Expand Down Expand Up @@ -250,3 +265,14 @@ bool XrdPosixFile::Stat(XrdCl::XRootDStatus &Status, bool force)
delete sInfo;
return true;
}

/******************************************************************************/
/* D o I t */
/******************************************************************************/
void XrdPosixFile::DoIt()
{
// Virtual function of XrdJob.
// Called from XrdPosixXrootd::Close if the file is still IO active.

delete this;
}
10 changes: 8 additions & 2 deletions src/XrdPosix/XrdPosixFile.hh
Expand Up @@ -47,6 +47,7 @@
#include "XrdPosix/XrdPosixMap.hh"
#include "XrdPosix/XrdPosixObject.hh"

#include "Xrd/XrdJob.hh"
/******************************************************************************/
/* X r d P o s i x F i l e C l a s s */
/******************************************************************************/
Expand All @@ -55,10 +56,11 @@ class XrdPosixCallBack;

class XrdPosixFile : public XrdPosixObject,
public XrdOucCacheIO,
public XrdCl::ResponseHandler
public XrdCl::ResponseHandler,
public XrdJob
{
public:

XrdOucCacheIO *XCio;
XrdCl::File clFile;

Expand All @@ -71,6 +73,8 @@ XrdCl::File clFile;

static XrdPosixFile *Alloc(const char *path, XrdPosixCallBack *cbP, int Opts);

static void* DelayedDestroy(void*);

bool Close(XrdCl::XRootDStatus &Status);

bool Finalize(XrdCl::XRootDStatus &Status);
Expand Down Expand Up @@ -112,6 +116,8 @@ static XrdPosixFile *Alloc(const char *path, XrdPosixCallBack *cbP, int Opts);
(uint32_t)Len, Buff));
}

void DoIt();

size_t mySize;
time_t myMtime;
ino_t myInode;
Expand Down
23 changes: 19 additions & 4 deletions src/XrdPosix/XrdPosixXrootd.cc
Expand Up @@ -146,11 +146,26 @@ int XrdPosixXrootd::Close(int fildes)
int ret;

if (!(fP = XrdPosixObject::ReleaseFile(fildes)))
{errno = EBADF; return -1;}
{errno = EBADF; return -1;}

ret = fP->Close(Status);
delete fP;
return (ret ? 0 : XrdPosixMap::Result(Status));
if (fP->XCio->ioActive())
{
if (XrdPosixGlobals::schedP )
{
XrdPosixGlobals::schedP->Schedule(fP);
}
else {
pthread_t tid;
XrdSysThread::Run(&tid, XrdPosixFile::DelayedDestroy, fP, 0, "PosixFileDestroy");
}
return 0;
}
else
{
ret = fP->Close(Status);
delete fP;
return (ret ? 0 : XrdPosixMap::Result(Status));
}
}

/******************************************************************************/
Expand Down

0 comments on commit 7ebdd66

Please sign in to comment.