Skip to content

Commit

Permalink
[Server] Rationalize feature interactions to prevent inadvertent fail…
Browse files Browse the repository at this point in the history
…ures.
  • Loading branch information
abh3 committed Jun 19, 2020
1 parent 4d34764 commit 0676cc1
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 87 deletions.
22 changes: 12 additions & 10 deletions src/XrdOfs/XrdOfsConfig.cc
Expand Up @@ -262,6 +262,7 @@ int XrdOfs::Configure(XrdSysError &Eroute, XrdOucEnv *EnvInfo) {
if (!ofsConfig->Load(piOpts, EnvInfo)) NoGo = 1;
else {ofsConfig->Plugin(XrdOfsOss);
ossFeatures = XrdOfsOss->Features();
if (ossFeatures & XRDOSS_HASNOSF) FeatureSet |= XrdSfs::hasNOSF;
if (xrdEnv) xrdEnv->PutPtr("XrdOss*", XrdOfsOss);
ofsConfig->Plugin(Cks);
CksPfn = !ofsConfig->OssCks();
Expand Down Expand Up @@ -324,24 +325,25 @@ int XrdOfs::Configure(XrdSysError &Eroute, XrdOucEnv *EnvInfo) {
//
if (!NoGo && evsObject) NoGo = evsObject->Start(&Eroute);

// If POSC processing is enabled (as by default) do it. Warning! This must be
// the last item in the configuration list as we need a working filesystem.
// Note that in proxy mode we always disable posc!
//
if (getenv("XRDXROOTD_NOPOSC"))
{if (poscAuto != -1 && !NoGo)
Eroute.Say("Config POSC has been disabled by the osslib plugin.");
} else if (poscAuto != -1 && !NoGo) NoGo |= ConfigPosc(Eroute);

// If the OSS plugin is really a proxy. If it is, it will export its origin.
// We also suppress translating lfn to pfn (usually done via osslib +cksio).
// Note: consulting the ENVAR below is historic and remains for compatibility
//
if (getenv("XRDXROOTD_PROXY"))
if (ossFeatures & XRDOSS_HASPRXY || getenv("XRDXROOTD_PROXY"))
{OssIsProxy = 1;
CksPfn = false;
FeatureSet |= XrdSfs::hasPRXY;
}

// If POSC processing is enabled (as by default) do it. Warning! This must be
// the last item in the configuration list as we need a working filesystem.
// Note that in proxy mode we always disable posc!
//
if (OssIsProxy || getenv("XRDXROOTD_NOPOSC"))
{if (poscAuto != -1 && !NoGo)
Eroute.Say("Config POSC has been disabled by the osslib plugin.");
} else if (poscAuto != -1 && !NoGo) NoGo |= ConfigPosc(Eroute);

// Setup statistical monitoring
//
OfsStats.setRole(myRole);
Expand Down
7 changes: 4 additions & 3 deletions src/XrdOss/XrdOss.hh
Expand Up @@ -170,7 +170,7 @@ virtual int Ftruncate(unsigned long long) {return -EISDIR;}
//! returned. Note that zero length files cannot be memory mapped.
//-----------------------------------------------------------------------------

virtual off_t getMmap(void **) {return 0;}
virtual off_t getMmap(void **addr) {*addr = 0; return 0;}

//-----------------------------------------------------------------------------
//! Return file compression charectistics.
Expand All @@ -181,7 +181,7 @@ virtual off_t getMmap(void **) {return 0;}
//! zero is returned (file not compressed).
//-----------------------------------------------------------------------------

virtual int isCompressed(char *cxidp=0) {(void)cxidp; return -EISDIR;}
virtual int isCompressed(char *cxidp=0) {(void)cxidp; return 0;}

//-----------------------------------------------------------------------------
//! Open a file.
Expand Down Expand Up @@ -416,7 +416,7 @@ virtual int Fctl(int cmd, int alen, const char *args, char **resp=0);
//! @return -1 if there is no file descriptor or a non-negative FD number.
//-----------------------------------------------------------------------------

virtual int getFD() {return fd;}
virtual int getFD() {return -1;} // Must override to support sendfile()

//-----------------------------------------------------------------------------
//! Return trace identifier associated with this object.
Expand Down Expand Up @@ -468,6 +468,7 @@ short rsvd; // Reserved
#define XRDOSS_HASPGRW 0x0000000000000001ULL
#define XRDOSS_HASFSCS 0x0000000000000002ULL
#define XRDOSS_HASPRXY 0x0000000000000004ULL
#define XRDOSS_HASNOSF 0x0000000000000008ULL

// Options that can be passed to Stat()
//
Expand Down
41 changes: 1 addition & 40 deletions src/XrdPss/XrdPss.cc
Expand Up @@ -148,7 +148,7 @@ XrdOss *XrdOssGetStorageSystem2(XrdOss *native_oss,

XrdPssSys::XrdPssSys() : LocalRoot(0), theN2N(0), DirFlags(0),
myVersion(&XrdVERSIONINFOVAR(XrdOssGetStorageSystem2)),
myFeatures(XRDOSS_HASPRXY)
myFeatures(XRDOSS_HASPRXY|XRDOSS_HASNOSF)
{}

/******************************************************************************/
Expand Down Expand Up @@ -1035,45 +1035,6 @@ int XrdPssFile::Ftruncate(unsigned long long flen)

return (XrdPosixXrootd::Ftruncate(fd, flen) ? -errno : XrdOssOK);
}

/******************************************************************************/
/* g e t M m a p */
/******************************************************************************/

/*
Function: Indicate whether or not file is memory mapped.
Input: addr - Points to an address which will receive the location
memory where the file is mapped. If the address is
null, true is returned if a mapping exist.
Output: Returns the size of the file if it is memory mapped (see above).
Otherwise, zero is returned and addr is set to zero.
*/
off_t XrdPssFile::getMmap(void **addr) // Not Supported for proxies
{
if (addr) *addr = 0;
return 0;
}

/******************************************************************************/
/* i s C o m p r e s s e d */
/******************************************************************************/

/*
Function: Indicate whether or not file is compressed.
Input: cxidp - Points to a four byte buffer to hold the compression
algorithm used if the file is compressed or null.
Output: Returns the region size which is 0 if the file is not compressed.
If cxidp is not null, the algorithm is returned only if the file
is compressed.
*/
int XrdPssFile::isCompressed(char *cxidp) // Not supported for proxies
{
return 0;
}

/******************************************************************************/
/* P 2 D S T */
Expand Down
14 changes: 7 additions & 7 deletions src/XrdPss/XrdPss.hh
Expand Up @@ -53,10 +53,12 @@ int Opendir(const char *, XrdOucEnv &);
int Readdir(char *buff, int blen);

// Constructor and destructor
XrdPssDir(const char *tid) : tident(tid), myDir(0) {}
XrdPssDir(const char *tid)
: XrdOssDF(tid, XrdOssDF::DF_isDir|XrdOssDF::DF_isProxy),
myDir(0) {}

~XrdPssDir() {if (myDir) Close();}
private:
const char *tident;
DIR *myDir;
};

Expand All @@ -83,8 +85,6 @@ int Fstat(struct stat *);
int Fsync();
int Fsync(XrdSfsAio *aiop);
int Ftruncate(unsigned long long);
off_t getMmap(void **addr);
int isCompressed(char *cxidp=0);
ssize_t Read( off_t, size_t);
ssize_t Read( void *, off_t, size_t);
int Read(XrdSfsAio *aiop);
Expand All @@ -94,16 +94,16 @@ ssize_t Write(const void *, off_t, size_t);
int Write(XrdSfsAio *aiop);

// Constructor and destructor
XrdPssFile(const char *tid) : tident(tid), tpcPath(0), entity(0)
{fd = -1;}
XrdPssFile(const char *tid)
: XrdOssDF(tid, XrdOssDF::DF_isFile|XrdOssDF::DF_isProxy),
tpcPath(0), entity(0) {}

virtual ~XrdPssFile() {if (fd >= 0) Close();
if (tpcPath) free(tpcPath);
}

private:

const char *tident;
char *tpcPath;

const XrdSecEntity *entity;
Expand Down
3 changes: 3 additions & 0 deletions src/XrdSfs/XrdSfsFlags.hh
Expand Up @@ -66,6 +66,9 @@ static const uint64_t hasPRXY = 0x0000000000000080LL;

//! Feature: Supports SfsXio
static const uint64_t hasSXIO = 0x0000000000000100LL;

//! Feature: Supports no sendfile
static const uint64_t hasNOSF = 0x0000000000000200LL;
}

//-----------------------------------------------------------------------------
Expand Down
24 changes: 18 additions & 6 deletions src/XrdXrootd/XrdXrootdConfig.cc
Expand Up @@ -85,6 +85,7 @@

#include "Xrd/XrdBuffer.hh"
#include "Xrd/XrdInet.hh"
#include "Xrd/XrdLink.hh"

/******************************************************************************/
/* P r o t o c o l C o m m a n d L i n e O p t i o n s */
Expand Down Expand Up @@ -310,15 +311,26 @@ int XrdXrootdProtocol::Configure(char *parms, XrdProtocol_Config *pi)

// Initialiaze for AIO
//
if (getenv("XRDXROOTD_NOAIO")) as_noaio = 1;
else if (!as_noaio) XrdXrootdAioReq::Init(as_segsize, as_maxperreq, as_maxpersrv);
else eDest.Say("Config warning: asynchronous I/O has been disabled!");
if (!as_noaio) XrdXrootdAioReq::Init(as_segsize, as_maxperreq, as_maxpersrv);
else eDest.Say("Config asynchronous I/O has been disabled!");

// Create the file lock manager
// Establish final sendfile processing mode. This may be turned off by the
// link or by the SFS plugin usually because ot's a proxy.
//
const char *why = 0;
if (!as_nosf)
{if (fsFeatures & XrdSfs::hasNOSF) why = "file system plugin.";
else if (!XrdLink::sfOK) why = "OS kernel.";
if (why)
{as_nosf = 1;
eDest.Say("Config sendfile has been disabled by ", why);
}
}

// Create the file lock manager and initialize file handling
//
Locker = (XrdXrootdFileLock *)new XrdXrootdFileLock1();
XrdXrootdFile::Init(Locker, &eDest, as_nosf == 0);
if (as_nosf) eDest.Say("Config warning: sendfile I/O has been disabled!");

// Schedule protocol object cleanup (also advise the transit protocol)
//
Expand Down Expand Up @@ -567,7 +579,7 @@ int XrdXrootdProtocol::CheckTLS(const char *tlsProt)
// TLS authnetication based protocols should the login phase not have TLS.
//
if (tlsProt && !(tlsCap & Req_TLSLogin))
{eDest.Say("Config warning: Authentication protocol(s)", tlsProt,
{eDest.Say("Config Authentication protocol(s)", tlsProt,
" require TLS; login now requires TLS.");
myRole |= kXR_tlsLogin;
tlsCap |= Req_TLSLogin;
Expand Down
31 changes: 16 additions & 15 deletions src/XrdXrootd/XrdXrootdFile.cc
Expand Up @@ -79,32 +79,33 @@ static const unsigned long heldMask = ~1UL;
/******************************************************************************/

XrdXrootdFile::XrdXrootdFile(const char *id, const char *path, XrdSfsFile *fp,
char mode, bool async, int sfok, struct stat *sP)
char mode, bool async, struct stat *sP)
: XrdSfsp(fp), mmAddr(0), FileKey(strdup(path)),
FileMode(mode), AsyncMode(async), fhProc(0),
ID(id)
{
static XrdSysMutex seqMutex;
struct stat buf;
off_t mmSize;

XrdSfsp = fp;
FileKey = strdup(path);
mmAddr = 0;
FileMode = mode;
AsyncMode= (async ? 1 : 0);
fhProc = 0;
ID = id;

// Initialize statistical counters
//
Stats.Init();

// Get the file descriptor number (none if not a regular file)
// Get the file descriptor number for sendfile() processing
//
if (fp->fctl(SFS_FCTL_GETFD, 0, fp->error) != SFS_OK) fdNum = -1;
else fdNum = fp->error.getErrInfo();
sfEnabled = (sfOK && sfok && (fdNum >= 0||fdNum==(int)SFS_SFIO_FDVAL) ? 1:0);
if (!sfOK || fp->fctl(SFS_FCTL_GETFD, 0, fp->error) != SFS_OK)
{fdNum = -1;
sfEnabled = false;
} else {
fdNum = fp->error.getErrInfo();
sfEnabled = (fdNum >= 0 || fdNum == (int)SFS_SFIO_FDVAL);
}

// Determine if file is memory mapped
//
if (fp->getMmap((void **)&mmAddr, mmSize) != SFS_OK) isMMapped = 0;
else {isMMapped = (mmSize ? 1 : 0);
if (fp->getMmap((void **)&mmAddr, mmSize) != SFS_OK) isMMapped = false;
else {isMMapped = (mmSize ? true : false);
Stats.fSize = static_cast<long long>(mmSize);
}

Expand Down
9 changes: 4 additions & 5 deletions src/XrdXrootd/XrdXrootdFile.hh
Expand Up @@ -105,9 +105,9 @@ union {char *mmAddr; // Memory mapped location, if any
};
char *FileKey; // -> File hash name (actual file name now)
char FileMode; // 'r' or 'w'
char AsyncMode; // 1 -> if file in async r/w mode
char isMMapped; // 1 -> file is memory mapped
char sfEnabled; // 1 -> file is sendfile enabled
bool AsyncMode; // 1 -> if file in async r/w mode
bool isMMapped; // 1 -> file is memory mapped
bool sfEnabled; // 1 -> file is sendfile enabled
union {int fdNum; // File descriptor number if regular file
int fHandle; // The file handle upon close()
};
Expand All @@ -119,8 +119,7 @@ XrdXrootdFileStats Stats; // File access statistics
static void Init(XrdXrootdFileLock *lp, XrdSysError *erP, int sfok);

XrdXrootdFile(const char *id, const char *path, XrdSfsFile *fp,
char mode='r', bool async=false, int sfOK=0,
struct stat *sP=0);
char mode='r', bool async=false, struct stat *sP=0);
~XrdXrootdFile();

private:
Expand Down
2 changes: 1 addition & 1 deletion src/XrdXrootd/XrdXrootdXeq.cc
Expand Up @@ -1453,7 +1453,7 @@ int XrdXrootdProtocol::do_Open()

// Obtain a hyper file object
//
xp = new XrdXrootdFile(Link->ID,fn,fp,usage,isAsync,Link->sfOK,&statbuf);
xp = new XrdXrootdFile(Link->ID, fn, fp, usage, isAsync, &statbuf);
if (!xp)
{snprintf(ebuff, sizeof(ebuff)-1, "Insufficient memory to open %s", fn);
eDest.Emsg("Xeq", ebuff);
Expand Down

0 comments on commit 0676cc1

Please sign in to comment.