Skip to content

Commit

Permalink
[Server] Allow xrootd.fslib plugin to be generally stacked.
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 committed Oct 20, 2019
1 parent 7825076 commit 4f983e8
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 77 deletions.
160 changes: 113 additions & 47 deletions src/XrdXrootd/XrdXrootdConfig.cc
Expand Up @@ -30,11 +30,13 @@
#include <unistd.h>
#include <ctype.h>
#include <fcntl.h>
#include <string>
#include <string.h>
#include <stdio.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <vector>

#ifdef __solaris__
#include <sys/isa_defs.h>
Expand Down Expand Up @@ -115,6 +117,30 @@ extern XrdOucTrace *XrdXrootdTrace;

int XrdXrootdPort;

extern XrdSfsFileSystem *XrdXrootdloadFileSystem(XrdSysError *,
XrdSfsFileSystem *,
const char *,
const char *, XrdOucEnv *);
extern XrdSfsFileSystem *XrdSfsGetDefaultFileSystem
(XrdSfsFileSystem *nativeFS,
XrdSysLogger *Logger,
const char *configFn,
XrdOucEnv *EnvInfo);

/******************************************************************************/
/* L o c a l S t a t i c s */
/******************************************************************************/

namespace
{
char *digParm = 0;
char *FSLib[2] = {0,0};
std::vector<std::string> FSLPath;
char *gpfLib = 0;// Normally zero for default
char *gpfParm = 0;
char *SecLib;
}

/******************************************************************************/
/* C o n f i g u r e */
/******************************************************************************/
Expand All @@ -128,16 +154,7 @@ int XrdXrootdProtocol::Configure(char *parms, XrdProtocol_Config *pi)
Output: 0 upon success or !0 otherwise.
*/
extern XrdSfsFileSystem *XrdSfsGetDefaultFileSystem
(XrdSfsFileSystem *nativeFS,
XrdSysLogger *Logger,
const char *configFn,
XrdOucEnv *EnvInfo);

extern XrdSfsFileSystem *XrdXrootdloadFileSystem(XrdSysError *,
XrdSfsFileSystem *,
char *, int,
const char *, XrdOucEnv *);
extern XrdSfsFileSystem *XrdDigGetFS
(XrdSfsFileSystem *nativeFS,
XrdSysLogger *Logger,
Expand Down Expand Up @@ -283,34 +300,10 @@ int XrdXrootdProtocol::Configure(char *parms, XrdProtocol_Config *pi)
//
ConfigGStream(myEnv);

// Get the filesystem to be used
//
if (FSLib[0])
{TRACE(DEBUG, "Loading base filesystem library " <<FSLib[0]);
osFS = XrdXrootdloadFileSystem(&eDest, 0, FSLib[0], FSLvn[0],
pi->ConfigFN, &myEnv);
} else {
osFS = XrdSfsGetDefaultFileSystem(0,eDest.logger(),pi->ConfigFN,&myEnv);
}
if (!osFS)
{eDest.Emsg("Config", "Unable to load file system.");
return 0;
} else {
SI->setFS(osFS);
if (FSLib[0]) osFS->EnvInfo(&myEnv);
}

// Check if we have a wrapper library
// Get the filesystem to be used and its features
//
if (FSLib[1])
{TRACE(DEBUG, "Loading wrapper filesystem library " <<FSLib[1]);
osFS = XrdXrootdloadFileSystem(&eDest, osFS, FSLib[1], FSLvn[1],
pi->ConfigFN, &myEnv);
if (!osFS)
{eDest.Emsg("Config", "Unable to load file system wrapper.");
return 0;
} else osFS->EnvInfo(&myEnv);
}
if (!ConfigFS(myEnv, pi->ConfigFN)) return 0;
fsFeatures = osFS->Features();

// Check if the file system includes a custom prepare handler as this will
// affect how we handle prepare requests.
Expand Down Expand Up @@ -572,6 +565,71 @@ void XrdXrootdProtocol::PidFile()
if (xop) eDest.Emsg("Config", errno, xop, pidFN);
}

/******************************************************************************/
/* C o n f i g F S */
/******************************************************************************/

bool XrdXrootdProtocol::ConfigFS(XrdOucEnv &xEnv, const char *cfn)
{
const char *fsLoc;
int n;

// Get the filesystem to be used
//
if (FSLib[0])
{TRACE(DEBUG, "Loading base filesystem library " <<FSLib[0]);
osFS = XrdXrootdloadFileSystem(&eDest, 0, FSLib[0], cfn, &xEnv);
fsLoc = FSLib[0];
} else {
osFS = XrdSfsGetDefaultFileSystem(0, eDest.logger(), cfn, &xEnv);
fsLoc = "default";
}

// Make sure we have loaded something
//
if (!osFS)
{eDest.Emsg("Config", "Unable to load base file system using", fsLoc);
return false;
}
if (FSLib[0]) osFS->EnvInfo(&xEnv);

// If there is an old style wrapper, load it now.
//
if (FSLib[1] && !ConfigFS(FSLib[1], xEnv, cfn)) return false;

// Run through any other pushdowns
//
if ((n = FSLPath.size()))
for (int i = 0; i < n; i++)
{if (!ConfigFS(FSLPath[i].c_str(), xEnv, cfn)) return false;}

// Inform the statistics object which filesystem to use
//
SI->setFS(osFS);

// All done here
//
return true;
}

/******************************************************************************/

bool XrdXrootdProtocol::ConfigFS(const char *path, XrdOucEnv &xEnv,
const char *cfn)
{

// Try to load this wrapper library
//
TRACE(DEBUG, "Loading wrapper filesystem library " <<path);
osFS = XrdXrootdloadFileSystem(&eDest, osFS, path, cfn, &xEnv);
if (!osFS)
{eDest.Emsg("Config", "Unable to load file system wrapper from", path);
return false;
}
osFS->EnvInfo(&xEnv);
return true;
}

/******************************************************************************/
/* C o n f i g G S t r e a m */
/******************************************************************************/
Expand Down Expand Up @@ -984,9 +1042,11 @@ int XrdXrootdProtocol::xexpdo(char *path, int popt)
Purpose: To parse the directive: fslib [throttle | [-2] <fspath2>]
{default | [-2] <fspath1>}
| ++ <fspath2>
-2 Uses version2 of the plugin initializer.
This is ignored now because it's always done.
++ Pushes a wrapper onto the library stack.
throttle load libXrdThrottle.so as the head interface.
<fspath2> load the named library as the head interface.
default load libXrdOfs.so ro libXrdPss.so as the tail
Expand All @@ -1000,17 +1060,26 @@ int XrdXrootdProtocol::xfsl(XrdOucStream &Config)
{
char *val;

// Clear storage pointers
//
if (FSLib[0]) {free(FSLib[0]); FSLib[0] = 0;}
if (FSLib[1]) {free(FSLib[1]); FSLib[1] = 0;}
FSLvn[0] = FSLvn[1] = 0;

// Get the path
//
if (!(val = Config.GetWord()))
{eDest.Emsg("Config", "fslib not specified"); return 1;}

// First check for a psuhdown
//
if (!strcmp("++", val))
{if (!(val = Config.GetWord()))
{eDest.Emsg("Config", "fslib wrapper not specified"); return 1;}
if (strcmp("throttle", val)) FSLPath.push_back((std::string)val);
else FSLPath.push_back("libXrdThrottle.so");
return 0;
}

// Clear storage pointers
//
if (FSLib[0]) {free(FSLib[0]); FSLib[0] = 0;}
if (FSLib[1]) {free(FSLib[1]); FSLib[1] = 0;}

// Check if this is "thottle"
//
if (!strcmp("throttle", val))
Expand All @@ -1031,7 +1100,6 @@ int XrdXrootdProtocol::xfsl(XrdOucStream &Config)
//
if (!(val = Config.GetWord()))
{FSLib[0] = FSLib[1]; FSLib[1] = 0;
FSLvn[0] = FSLvn[1]; FSLvn[1] = 0;
return 0;
}

Expand All @@ -1045,13 +1113,11 @@ int XrdXrootdProtocol::xfsl(XrdOucStream &Config)
int XrdXrootdProtocol::xfsL(XrdOucStream &Config, char *val, int lix)
{
char *Slash;
int lvn = 0;

// Check if this is a version token
//
if (!strcmp(val, "-2"))
{lvn = 2;
if (!(val = Config.GetWord()))
{if (!(val = Config.GetWord()))
{eDest.Emsg("Config", "fslib not specified"); return 1;}
}

Expand All @@ -1067,7 +1133,7 @@ int XrdXrootdProtocol::xfsL(XrdOucStream &Config, char *val, int lix)
else Slash++;
if (!strcmp(Slash, "libXrdOfs.so"))
eDest.Say("Config warning: 'fslib libXrdOfs.so' is actually built-in.");
else {FSLib[lix] = strdup(val); FSLvn[lix] = lvn;}
else FSLib[lix] = strdup(val);
return 0;
}

Expand Down
23 changes: 7 additions & 16 deletions src/XrdXrootd/XrdXrootdLoadLib.cc
Expand Up @@ -42,41 +42,32 @@

XrdSfsFileSystem *XrdXrootdloadFileSystem(XrdSysError *eDest,
XrdSfsFileSystem *prevFS,
char *fslib, int fsver,
const char *fslib,
const char *cfn, XrdOucEnv *envP)
{
static XrdVERSIONINFODEF(myVersion, XrdOfsLoader, XrdVNUMBER, XrdVERSION);
XrdOucPinLoader ofsLib(eDest, &myVersion, "fslib", fslib);
XrdSfsFileSystem_t ep;
XrdSfsFileSystem2_t ep2;
XrdSfsFileSystem *FS = 0;
const char *epname = "XrdSfsGetFileSystem";
char epbuff[64];

// Record the library path in the environment
//
if (!prevFS) XrdOucEnv::Export("XRDOFSLIB", fslib);

// If a different version is to used for initialization, generate the name
// Get the file system object creator and the object (we preferntially try
// to find the version 2 of the plugin).
//
if (fsver)
{sprintf(epbuff, "XrdSfsGetFileSystem%d", fsver); // Always fits
epname = epbuff;
}

// Get the file system object creator and the object
//
if (fsver)
{if ((ep2 = (XrdSfsFileSystem2_t)ofsLib.Resolve(epname)))
FS = (*ep2)(prevFS, eDest->logger(), cfn, envP);
if ((ep2 = (XrdSfsFileSystem2_t)ofsLib.Resolve("?XrdSfsGetFileSystem2")))
{ FS = (*ep2)(prevFS, eDest->logger(), cfn, envP);
} else {
if ((ep = (XrdSfsFileSystem_t )ofsLib.Resolve(epname)))
if ((ep = (XrdSfsFileSystem_t )ofsLib.Resolve("XrdSfsGetFileSystem")))
FS = (*ep) (prevFS, eDest->logger(), cfn);
}

// Issue message if we could not load it
//
if (!FS) eDest->Emsg("Config","Unable to create file system object via",fslib);
if (!FS) eDest->Emsg("Config", "Unable to load file system via", fslib);

// All done
//
Expand Down
8 changes: 1 addition & 7 deletions src/XrdXrootd/XrdXrootdProtocol.cc
Expand Up @@ -62,17 +62,10 @@ XrdXrootdXPath XrdXrootdProtocol::RQList;
XrdXrootdXPath XrdXrootdProtocol::XPList;
XrdSfsFileSystem *XrdXrootdProtocol::osFS;
XrdSfsFileSystem *XrdXrootdProtocol::digFS = 0;
char *XrdXrootdProtocol::FSLib[2] = {0, 0};
int XrdXrootdProtocol::FSLvn[2] = {0, 0};
char *XrdXrootdProtocol::digLib = 0;
char *XrdXrootdProtocol::gpfParm = 0;
char *XrdXrootdProtocol::gpfLib = 0;
char *XrdXrootdProtocol::digParm = 0;
XrdXrootdFileLock *XrdXrootdProtocol::Locker;
XrdSecService *XrdXrootdProtocol::CIA = 0;
XrdSecProtector *XrdXrootdProtocol::DHS = 0;
XrdTlsContext *XrdXrootdProtocol::tlsCtx = 0;
char *XrdXrootdProtocol::SecLib = 0;
char *XrdXrootdProtocol::pidPath = strdup("/tmp");
XrdScheduler *XrdXrootdProtocol::Sched;
XrdBuffManager *XrdXrootdProtocol::BPool;
Expand All @@ -82,6 +75,7 @@ XrdXrootdJob *XrdXrootdProtocol::JobCKS = 0;
char *XrdXrootdProtocol::JobCKT = 0;
XrdOucTList *XrdXrootdProtocol::JobCKTLST= 0;
XrdOucReqID *XrdXrootdProtocol::PrepID = 0;
uint64_t XrdXrootdProtocol::fsFeatures = 0;

char *XrdXrootdProtocol::Notify = 0;
const char *XrdXrootdProtocol::myCName= 0;
Expand Down
10 changes: 3 additions & 7 deletions src/XrdXrootd/XrdXrootdProtocol.hh
Expand Up @@ -204,6 +204,8 @@ static void PidFile();
static int rpCheck(char *fn, char **opaque);
int rpEmsg(const char *op, char *fn);
int vpEmsg(const char *op, char *fn);
static bool ConfigFS(XrdOucEnv &xEnv, const char *cfn);
static bool ConfigFS(const char *path, XrdOucEnv &xEnv, const char *cfn);
static void ConfigGStream(XrdOucEnv &myEnv);
static int Squash(char *);
int StatGen(struct stat &buf, char *xxBuff, int xxLen, bool xa=false);
Expand Down Expand Up @@ -285,13 +287,6 @@ static int readWait;
static int Port;
static int Window;
static int tlsPort;
static char *SecLib;
static char *FSLib[2];
static int FSLvn[2];
static char *digLib; // Normally zero for now
static char *digParm;
static char *gpfLib; // Normally zero for default
static char *gpfParm;
static char *Notify;
static const char *myCName;
static int myCNlen;
Expand All @@ -302,6 +297,7 @@ static XrdXrootdJob *JobCKS;
static char *JobCKT;
static XrdOucTList *JobCKTLST;
static XrdOucReqID *PrepID;
static uint64_t fsFeatures;

// Static redirection
//
Expand Down

0 comments on commit 4f983e8

Please sign in to comment.