Skip to content

Commit

Permalink
Implement async Posix I/O and deferred file open.
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 committed Mar 18, 2016
1 parent c4dd4d8 commit d89de8d
Show file tree
Hide file tree
Showing 23 changed files with 1,456 additions and 150 deletions.
27 changes: 27 additions & 0 deletions src/XrdOuc/XrdOucCache.hh
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,33 @@ private:
XrdSysMutex sMutex;
};

/******************************************************************************/
/* X r d O u c C a c h e I O C B */
/******************************************************************************/

//-----------------------------------------------------------------------------
//! The XrdOucCacheIOCB defines a callback object that must be used to handle
//! asynchronous I/O operations.
//-----------------------------------------------------------------------------

class XrdOucCacheIOCB
{
public:

//------------------------------------------------------------------------------
//! Handle result from a previous async operation.
//!
//! @param result is result from a previous operation. Successful results are
//! always values >= 0 while errors are negative values and are
//! always '-errno' indicate the reason for the error.
//------------------------------------------------------------------------------
virtual
void Done(int result) = 0;

XrdOucCacheIOCB() {}
virtual ~XrdOucCacheIOCB() {}
};

/******************************************************************************/
/* C l a s s X r d O u c C a c h e I O */
/******************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions src/XrdPlugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_library(
${LIB_XRD_PSS}
MODULE
XrdPss/XrdPssAio.cc
XrdPss/XrdPssAioCB.cc XrdPss/XrdPssAioCB.hh
XrdPss/XrdPss.cc XrdPss/XrdPss.hh
XrdPss/XrdPssCks.cc XrdPss/XrdPssCks.hh
XrdPss/XrdPssConfig.cc )
Expand Down
6 changes: 5 additions & 1 deletion src/XrdPosix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ add_library(
XrdPosix
SHARED
XrdPosix/XrdPosixAdmin.cc XrdPosix/XrdPosixAdmin.hh
XrdPosix/XrdPosixCacheBC.hh
XrdPosix/XrdPosixCallBack.cc XrdPosix/XrdPosixCallBack.hh
XrdPosix/XrdPosixDir.cc XrdPosix/XrdPosixDir.hh
XrdPosix/XrdPosixFile.cc XrdPosix/XrdPosixFile.hh
XrdPosix/XrdPosixFileRH.cc XrdPosix/XrdPosixFileRH.hh
XrdPosix/XrdPosixMap.cc XrdPosix/XrdPosixMap.hh
XrdPosix/XrdPosixObject.cc XrdPosix/XrdPosixObject.hh
XrdPosix/XrdPosixObjGaurd.hh
XrdPosix/XrdPosixPrepIO.cc XrdPosix/XrdPosixPrepIO.hh
XrdPosix/XrdPosixXrootd.cc XrdPosix/XrdPosixXrootd.hh
XrdPosix/XrdPosixXrootdPath.cc XrdPosix/XrdPosixXrootdPath.hh
XrdPosix/XrdPosixCallBack.hh
XrdPosix/XrdPosixOsDep.hh )

target_link_libraries(
Expand Down
119 changes: 119 additions & 0 deletions src/XrdPosix/XrdPosixCacheBC.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#ifndef __XRDPOSIXCACHEBC_HH__
#define __XRDPOSIXCACHEBC_HH__
/******************************************************************************/
/* */
/* X r d P o s i x C a c h e B C . h h */
/* */
/* (c) 2016 by the Board of Trustees of the Leland Stanford, Jr., University */
/* All Rights Reserved */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/

#include "XrdOuc/XrdOucCache2.hh"

/******************************************************************************/
/* X r d P o s i x C a c h e B C I O */
/******************************************************************************/

class XrdPosixCacheBCIO : public XrdOucCacheIO2
{
public:

virtual
XrdOucCacheIO2 *Base() {return cacheIO2;}

virtual
XrdOucCacheIO2 *Detach() {XrdOucCacheIO2 *theCIO = cacheIO2;
cacheIO1->Detach();
delete this;
return theCIO;
}

virtual
long long FSize() {return cacheIO1->FSize();}

virtual
const char *Path() {return cacheIO1->Path();}

virtual int Read (char *Buffer, long long Offset, int Length)
{return cacheIO1->Read(Buffer, Offset, Length);}

virtual int ReadV(const XrdOucIOVec *readV, int n)
{return cacheIO1->ReadV(readV, n);}

virtual int Sync() {return cacheIO1->Sync();}

virtual int Trunc(long long Offset) {return cacheIO1->Trunc(Offset);}

virtual int Write(char *Buffer, long long Offset, int Length)
{return cacheIO1->Write(Buffer, Offset, Length);}

virtual bool ioActive() { return cacheIO1->ioActive();}

virtual void Preread (long long Offset, int Length, int Opts=0)
{return cacheIO1->Preread(Offset, Length, Opts);}

virtual void Preread(aprParms &Parms) { cacheIO1->Preread(Parms);}

XrdPosixCacheBCIO(XrdOucCacheIO *urCIO, XrdOucCacheIO2 *myCIO)
: cacheIO1(urCIO), cacheIO2(myCIO) {}
virtual ~XrdPosixCacheBCIO() {}

private:
XrdOucCacheIO *cacheIO1;
XrdOucCacheIO2 *cacheIO2;
};

/******************************************************************************/
/* X r d P o s i x C a c h e B C */
/******************************************************************************/

class XrdPosixCacheBC : public XrdOucCache2
{
public:
virtual
XrdOucCacheIO2 *Attach(XrdOucCacheIO2 *ioP, int opts=0)
{XrdOucCacheIO *newIOP = v1Cache->Attach(ioP, opts);
if (newIOP == (XrdOucCacheIO *)newIOP) return ioP;
return new XrdPosixCacheBCIO(newIOP, ioP);
}

virtual int isAttached() {return v1Cache->isAttached();}

virtual int Rmdir(const char* path) {return v1Cache->Rmdir(path);}

virtual int Rename(const char* pathO, const char* pathN)
{return v1Cache->Rename(pathO, pathN);}

virtual int Truncate(const char* path, off_t size)
{return v1Cache->Truncate(path, size);}

virtual int Unlink(const char* path) {return v1Cache->Unlink(path);}

XrdPosixCacheBC(XrdOucCache *cP) : v1Cache(cP) {}
virtual ~XrdPosixCacheBC() {}
private:
XrdOucCache *v1Cache;
};
#endif
53 changes: 53 additions & 0 deletions src/XrdPosix/XrdPosixCallBack.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/******************************************************************************/
/* */
/* X r d P o s i x C a l l B a c k . c c */
/* */
/* (c) 2016 by the Board of Trustees of the Leland Stanford, Jr., University */
/* All Rights Reserved */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/

#include <errno.h>

#include "XrdPosix/XrdPosixCallBack.hh"
#include "XrdPosix/XrdPosixFile.hh"

/******************************************************************************/
/* D o n e */
/******************************************************************************/

void XrdPosixCallBackIO::Done(int result)
{
// Unreference the file so that the callback is able to close it.
//
theFile->unRef();

// Diagnose the problem here, if there is a problem
//
if (result < 0) {errno = -result; result = -1;}

// Invoke the callback
//
Complete((ssize_t)result);
}
66 changes: 49 additions & 17 deletions src/XrdPosix/XrdPosixCallBack.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* */
/* X r d P o s i x C a l l B a c k . h h */
/* */
/* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University */
/* (c) 2016 by the Board of Trustees of the Leland Stanford, Jr., University */
/* All Rights Reserved */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
Expand All @@ -30,22 +30,23 @@
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/

// This abstract class defines the callback interface for file open() calls.
// It is passed when using the XrdPosixXrootd::Open() call. When passed, the
// open request will be done in the background. When a callback object is
// supplied, Open() will *always* return -1. However, if started successfully,
// Open() will return -1 with errno set to EINPROGRESS. Otherwise, errno will
// contain the reason the Open() request immediately failed. Upon completion,
// the callback's Compete() method is invoked. The Result parameter will either
// be a non-negative file descriptor or -errno indicating that the Open()
// failed. Note that the caller is responsible for deleting the callback object
// after it has been invoked. Note that callbacks will be executed in a
// separate thread unless open() is called with O_SYNC or maxThreads is zero.
// WARNING: If O_SYNC or maxThreads is zero, then the callback must *not*
// issue any filesystem calls using the supplied file descriptor.
// Ignoring this will produce undetermined results including possible
// deadlock. Synchrnous callbacks are only meant to support private
// thread management.
#include "XrdOuc/XrdOucCache.hh"

//-----------------------------------------------------------------------------
//! @brief An abstract class to define a callback for Open() call.
//!
//! This abstract class defines the callback interface for Open() calls.
//! When passed, the request is done in the background. When a callback
//! object is supplied, the method *always* return -1. However, if started
//! successfully, the method sets errno to EINPROGRESS. Otherwise, errno
//! contain the reason the request immediately failed. Upon completion, the
//! the callback's Compete() method is invoked. The Result parameter contains
//! what the method would have returned if it were executed synchronously:
//! for succsessful Open() it is a non-negative file descriptor but on failure
//! -1 with errno indicating why Open() failed. The caller is responsible for
//! deleting the callback object after it has been invoked. Callbacks are
//! executed in a separate thread.
//-----------------------------------------------------------------------------

class XrdPosixCallBack
{
Expand All @@ -56,4 +57,35 @@ virtual void Complete(int Result) = 0;
XrdPosixCallBack() {}
virtual ~XrdPosixCallBack() {}
};

//-----------------------------------------------------------------------------
//! @brief An abstract class to define a callback for open file requests.
//!
//! This abstract class defines the callback interface for Fsync(), Pread(),
//! Pwrite(), and VRead(). Async I/O is not supported for Read(), Readv(),
//! Write(), and Writev() as these update the file offset associated with the
//! file descriptor and cannot be made async safe. All results are return via
//! the callback object. For immediate errors, the callback is invoked on the
//! calling thread. Any locks held by the calling thread that are obtained by
//! the callback must be recursive locks in order to avoid a deadlock.
//-----------------------------------------------------------------------------

class XrdPosixFile;

class XrdPosixCallBackIO : public XrdOucCacheIOCB
{
public:
friend class XrdPosixXrootd;

virtual void Complete(ssize_t Result) = 0;

XrdPosixCallBackIO() : theFile(0) {}
virtual ~XrdPosixCallBackIO() {}

private:

void Done(int result);

XrdPosixFile *theFile;
};
#endif
Loading

0 comments on commit d89de8d

Please sign in to comment.