Skip to content

Commit

Permalink
[Server] Add default implementation for pgRead and pgWrite.
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 authored and simonmichal committed Oct 16, 2019
1 parent 51dfc11 commit 814bb28
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 13 deletions.
75 changes: 67 additions & 8 deletions src/XrdSfs/XrdSfsInterface.cc
Expand Up @@ -27,9 +27,19 @@
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/

#include "XrdOuc/XrdOucCRC.hh"
#include "XrdSfs/XrdSfsAio.hh"
#include "XrdSfs/XrdSfsInterface.hh"

/******************************************************************************/
/* S t a t i c S y m b o l s */
/******************************************************************************/

namespace
{
static const XrdSfsFileOffset pgSize = XrdSfsPageSize;
}

/******************************************************************************/
/* p g R e a d */
/******************************************************************************/
Expand All @@ -39,10 +49,29 @@ XrdSfsXferSize XrdSfsFile::pgRead(XrdSfsFileOffset offset,
XrdSfsXferSize rdlen,
uint32_t *csvec,
bool verify)
{(void)offset; (void)buffer; (void)rdlen;
(void)csvec; (void)verify;
error.setErrInfo(ENOTSUP, "Not supported.");
return SFS_ERROR;
{
XrdSfsXferSize bytes;

// Make sure the offset is on a 4K boundary and the size if a multiple of
// 4k as well (we use simple and for this).
//
if ((offset & ~pgSize) || (rdlen & ~XrdSfsPageSize))
{error.setErrInfo(EINVAL,"Offset or readlen not a multiple of pagesize.");
return SFS_ERROR;
}

// Read the data into the buffer
//
bytes = read(offset, buffer, rdlen);

// Calculate checksums if so wanted
//
if (bytes > 0 && csvec)
XrdOucCRC::Calc32C((void *)buffer, rdlen, csvec, XrdSfsPageSize);

// All done
//
return bytes;
}

/******************************************************************************/
Expand All @@ -66,10 +95,40 @@ XrdSfsXferSize XrdSfsFile::pgWrite(XrdSfsFileOffset offset,
XrdSfsXferSize wrlen,
uint32_t *csvec,
bool verify)
{(void)offset; (void)buffer; (void)wrlen;
(void)csvec; (void)verify;
error.setErrInfo(ENOTSUP, "Not supported.");
return SFS_ERROR;
{
// Make sure the offset is on a 4K boundary
//
if (offset & ~pgSize)
{error.setErrInfo(EINVAL,"Offset or readlen not a multiple of pagesize.");
return SFS_ERROR;
}

// If a virtual end of file marker is set, make sure we are not trying to
// write past it.
//
if (pgwrEOF && (offset+wrlen) > pgwrEOF)
{error.setErrInfo(ESPIPE,"Attempt to write past virtual EOF.");
return SFS_ERROR;
}

// If this is a short write then establish the virtual eof
//
if (wrlen & ~XrdSfsPageSize) pgwrEOF = (offset + wrlen) & ~pgSize;

// If we have a checksum vector and verify is on, make sure the data
// in the buffer corresponds to he checksums.
//
if (csvec && verify)
{int pgErr;
if (!XrdOucCRC::Ver32C((void *)buffer,wrlen,csvec,XrdSfsPageSize,pgErr))
{error.setErrInfo(EDOM,"Checksum error.");
return SFS_ERROR;
}
}

// Now just return the result of a plain write
//
return write(offset, buffer, wrlen);
}

/******************************************************************************/
Expand Down
10 changes: 5 additions & 5 deletions src/XrdSfs/XrdSfsInterface.hh
Expand Up @@ -738,7 +738,7 @@ virtual void setXio(XrdSfsXio *xioP) { (void)xioP; }

XrdSfsFile(const char *user=0, int MonID=0)
: error(*(new XrdOucErrInfo(user, MonID)))
{lclEI = &error;}
{lclEI = &error; pgwrEOF = 0;}

//-----------------------------------------------------------------------------
//! Constructor for plugins that wrap another SFS plugin. This constructor
Expand All @@ -749,7 +749,7 @@ virtual void setXio(XrdSfsXio *xioP) { (void)xioP; }
//-----------------------------------------------------------------------------

XrdSfsFile(XrdSfsFile &wrapF)
: error(wrapF.error), lclEI(0) {}
: error(wrapF.error), lclEI(0), pgwrEOF(0) {}

//-----------------------------------------------------------------------------
//! Constructor for base plugins that predefined an error object. This is a
Expand All @@ -759,7 +759,7 @@ virtual void setXio(XrdSfsXio *xioP) { (void)xioP; }
//-----------------------------------------------------------------------------

XrdSfsFile(XrdOucErrInfo &eInfo)
: error(eInfo), lclEI(0) {}
: error(eInfo), lclEI(0), pgwrEOF(0) {}

//-----------------------------------------------------------------------------
//! Destructor
Expand All @@ -768,8 +768,8 @@ virtual void setXio(XrdSfsXio *xioP) { (void)xioP; }
virtual ~XrdSfsFile() {if (lclEI) delete lclEI;}

private:
XrdOucErrInfo* lclEI;

XrdOucErrInfo* lclEI;
XrdSfsFileOffset pgwrEOF;
}; // class XrdSfsFile

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

0 comments on commit 814bb28

Please sign in to comment.