XRootD
XrdCmsRedirLocal Class Reference

#include <XrdCmsRedirLocal.hh>

+ Inheritance diagram for XrdCmsRedirLocal:
+ Collaboration diagram for XrdCmsRedirLocal:

Public Member Functions

 XrdCmsRedirLocal (XrdSysLogger *Logger, int opMode, int myPort, XrdOss *theSS)
 Constructor. More...
 
 ~XrdCmsRedirLocal ()
 Destructor. More...
 
void Added (const char *path, int Pend=0)
 
int Configure (const char *cfn, char *Parms, XrdOucEnv *EnvInfo)
 Configure the nativeCmsFinder. More...
 
int Forward (XrdOucErrInfo &Resp, const char *cmd, const char *arg1=0, const char *arg2=0, XrdOucEnv *Env1=0, XrdOucEnv *Env2=0)
 
int isRemote ()
 
void loadConfig (const char *filename)
 
int Locate (XrdOucErrInfo &Resp, const char *path, int flags, XrdOucEnv *EnvInfo)
 
XrdOucTListManagers ()
 
int Prepare (XrdOucErrInfo &Resp, XrdSfsPrep &pargs, XrdOucEnv *Info=0)
 
int Release (int n=1)
 
void Removed (const char *path)
 
int Reserve (int n=1)
 
int Resource (int n)
 
void Resume (int Perm=1)
 
int Space (XrdOucErrInfo &Resp, const char *path, XrdOucEnv *EnvInfo)
 
void Suspend (int Perm=1)
 
- Public Member Functions inherited from XrdCmsClient
 XrdCmsClient (Persona acting)
 
virtual ~XrdCmsClient ()
 Destructor. More...
 
virtual void Utilization (unsigned int util, bool alert=false)
 

Public Attributes

bool httpRedirect
 
std::string localroot
 
XrdCmsClientnativeCmsFinder
 used to forward requests to CmsFinder with regular implementation More...
 
bool readOnlyredirect
 
XrdSysError Say
 

Additional Inherited Members

- Public Types inherited from XrdCmsClient
enum  Persona {
  amLocal ,
  amRemote ,
  amTarget
}
 
- Protected Attributes inherited from XrdCmsClient
Persona myPersona
 

Detailed Description

Definition at line 44 of file XrdCmsRedirLocal.hh.

Constructor & Destructor Documentation

◆ XrdCmsRedirLocal()

XrdCmsRedirLocal::XrdCmsRedirLocal ( XrdSysLogger Logger,
int  opMode,
int  myPort,
XrdOss theSS 
)

Constructor.

Definition at line 34 of file XrdCmsRedirLocal.cc.

36  nativeCmsFinder(new XrdCmsFinderRMT(Logger, opMode, myPort)),
37  readOnlyredirect(true),
38  httpRedirect(false),
39  Say(0,"cms_") {
40  Say.logger(Logger);
41 }
XrdCmsClient(Persona acting)
@ amLocal
Not affiliated with a cluster.
XrdCmsClient * nativeCmsFinder
used to forward requests to CmsFinder with regular implementation
XrdSysLogger * logger(XrdSysLogger *lp=0)
Definition: XrdSysError.hh:141
XrdSysLogger Logger
Definition: XrdGlobals.cc:47

References XrdGlobal::Logger, XrdSysError::logger(), and Say.

+ Here is the call graph for this function:

◆ ~XrdCmsRedirLocal()

XrdCmsRedirLocal::~XrdCmsRedirLocal ( )

Destructor.

Definition at line 45 of file XrdCmsRedirLocal.cc.

45 { delete nativeCmsFinder; }

References nativeCmsFinder.

Member Function Documentation

◆ Added()

void XrdCmsRedirLocal::Added ( const char *  path,
int  Pend = 0 
)
inlinevirtual

Notify the cms of a newly added file or a file whose state has changed on a data server node.

Parameters
pathThe logical file name.
PendWhen true, the file is scheduled to be present in the future (e.g. copied in).

Reimplemented from XrdCmsClient.

Definition at line 54 of file XrdCmsRedirLocal.hh.

54  {
55  nativeCmsFinder->Added(path, Pend);
56  }
virtual void Added(const char *path, int Pend=0)

References XrdCmsClient::Added(), and nativeCmsFinder.

+ Here is the call graph for this function:

◆ Configure()

int XrdCmsRedirLocal::Configure ( const char *  cfn,
char *  Parms,
XrdOucEnv EnvInfo 
)
virtual

Configure the nativeCmsFinder.

Implements XrdCmsClient.

Definition at line 50 of file XrdCmsRedirLocal.cc.

50  {
51  loadConfig(cfn);
52  if(localroot.empty())
53  {
54  Say.Emsg("RedirLocal", "oss.localroot (replaced by xrdcmsredirlocal for localredirect) " \
55  "and xrdcmsredirlocal.localroot are undefined, define xrdcmsredirlocal.localroot");
56  return 0;
57  }
58  if(localroot[0] != '/')
59  {
60  Say.Emsg("RedirLocal", "oss.localroot or xrdcmsredirlocal.localroot needs to be an absolute path");
61  return 0;
62  }
63  if (nativeCmsFinder)
64  return nativeCmsFinder->Configure(cfn, Parms, EnvInfo);
65  return 0; // means false
66 }
virtual int Configure(const char *cfn, char *Parms, XrdOucEnv *EnvInfo)=0
void loadConfig(const char *filename)
std::string localroot
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95

References XrdCmsClient::Configure(), XrdSysError::Emsg(), loadConfig(), localroot, nativeCmsFinder, and Say.

+ Here is the call graph for this function:

◆ Forward()

int XrdCmsRedirLocal::Forward ( XrdOucErrInfo Resp,
const char *  cmd,
const char *  arg1 = 0,
const char *  arg2 = 0,
XrdOucEnv Env1 = 0,
XrdOucEnv Env2 = 0 
)
inlinevirtual

Relay a meta-operation to all nodes in the cluster.

This method is only used on manager nodes and is enabled by the ofs.forward directive.

Parameters
RespObject where messages are to be returned.
cmdThe operation being performed (see table below). If it starts with a '+' then a response (2way) is needed. Otherwise, a best-effort is all that is all that is required and success can always be returned.
arg11st argument to cmd.
arg22nd argument to cmd, which may be null if none exists.
Env1Associated environmental information for arg1 (e.g., cgi info which can be retrieved by Env1->Env(<len>)).
Env2Associated environmental information for arg2 (e.g., cgi info which can be retrieved by Env1->Env(<len>)).
     cmd       arg1    arg2           cmd       arg1    arg2
     --------  ------  ------         --------  ------  ------
     [+]chmod  <path>  <mode %o>      [+]rmdir  <path>  0
     [+]mkdir  <path>  <mode %o>      [+]mv     <oldp>  <newp>
     [+]mkpath <path>  <mode %o>      [+]trunc  <path>  <size %lld>
     [+]rm     <path>  0
Returns
As explained under "return conventions".

Reimplemented from XrdCmsClient.

Definition at line 57 of file XrdCmsRedirLocal.hh.

58  {
59  return nativeCmsFinder->Forward(Resp, cmd, arg1, arg2, Env1, Env2);
60  }
virtual int Forward(XrdOucErrInfo &Resp, const char *cmd, const char *arg1=0, const char *arg2=0, XrdOucEnv *Env1=0, XrdOucEnv *Env2=0)

References XrdCmsClient::Forward(), and nativeCmsFinder.

+ Here is the call graph for this function:

◆ isRemote()

int XrdCmsRedirLocal::isRemote ( )
inlinevirtual

Check if this client is configured for a manager node.

Returns
!0 Yes, configured as a manager. =0 No.

Reimplemented from XrdCmsClient.

Definition at line 61 of file XrdCmsRedirLocal.hh.

61 { return nativeCmsFinder->isRemote(); }
virtual int isRemote()

References XrdCmsClient::isRemote(), and nativeCmsFinder.

+ Here is the call graph for this function:

◆ loadConfig()

void XrdCmsRedirLocal::loadConfig ( const char *  filename)

Definition at line 68 of file XrdCmsRedirLocal.cc.

68  {
70  int cfgFD;
71  char *word;
72 
73  if ((cfgFD = open(filename, O_RDONLY, 0)) < 0) {
74  return;
75  }
76  Config.Attach(cfgFD);
77  while ((word = Config.GetFirstWord(true))) { //get word in lower case
78  // search for readonlyredirect,
79  // which only allows read calls to be redirected to local
80  if (strcmp(word, "xrdcmsredirlocal.readonlyredirect") == 0){
81  readOnlyredirect = std::string(Config.GetWord(true)).find("true") != std::string::npos;
82  }
83  // search for httpredirect,
84  // which allows http(s) calls to be redirected to local
85  else if (strcmp(word, "xrdcmsredirlocal.httpredirect") == 0){
86  httpRedirect = std::string(Config.GetWord(true)).find("true") != std::string::npos;
87  }
88  // search for newer localroot, overwrite given oss.localroot if defined,
89  // which manually sets localroot to prepend
90  else if (strcmp(word, "xrdcmsredirlocal.localroot") == 0){
91  localroot = std::string(Config.GetWord(false));
92  }
93  // search for oss.localroot,
94  // which manually sets localroot to prepend
95  else if (strcmp(word, "oss.localroot") == 0 && localroot.empty()){
96  localroot = std::string(Config.GetWord(false));
97  }
98  }
99  Config.Close();
100 }
int open(const char *path, int oflag,...)
XrdCmsConfig Config

References XrdCms::Config, httpRedirect, localroot, open(), and readOnlyredirect.

Referenced by Configure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Locate()

int XrdCmsRedirLocal::Locate ( XrdOucErrInfo Resp,
const char *  path,
int  flags,
XrdOucEnv EnvInfo 
)
virtual

Preconditions: Writing must be enabled via xrdcmsredirlocal.readonlyredirect false Client has urlRedirSupport Client has localredirect capability Flag is one of: SFS_O_RDONLY, SFS_O_RDWR, SFS_O_WRONLY, SFS_O_CREAT, SFS_O_TRUNC [Only HTTP] Flag may also be SFS_O_STAT in case of read access [Only HTTP] xrdcmsredirlocal.httpRedirect is true in the config Locate the file, get Client IP and target IP. 1) If both are private, redirect to local does apply. set ErrInfo of param Resp and return SFS_REDIRECT. 2) Not both are private, redirect to local does NOT apply. return nativeCmsFinder->Locate, for normal redirection procedure

@Param Resp: Either set manually here or passed to nativeCmsFinder->Locate @Param path: The path of the file, passed to nativeCmsFinder->Locate @Param flags: The open flags, passed to nativeCmsFinder->Locate @Param EnvInfo: Contains the secEnv, which contains the addressInfo of the Client. Checked to see if redirect to local conditions apply

Implements XrdCmsClient.

Definition at line 122 of file XrdCmsRedirLocal.cc.

123  {
124  int rcode = 0;
125  if (nativeCmsFinder) {
126  // check if path contains localroot to know if potential redirection loop
127  // is happening. If yes, remove localroot from path, then rerun default
128  // locate with regular path and return to client
129  // localroot must be larger than 1 to avoid always being triggered by "/"
130  if (localroot.size() > 1 && strncmp(path, localroot.c_str(), localroot.size()) == 0)
131  {
132  // now check if localhost was tried before, to make sure we're handling
133  // the redirection loop
134  int param = 0; // need it to get Env
135  //EnvInfo->Env(param) gets already tried hosts
136  if(strstr(EnvInfo->Env(param), "tried=localhost") != nullptr)
137  {
138  std::string newPath(path);
139  // remove localroot
140  newPath = "//" + newPath.substr(localroot.size());
141  // get regular target host
142  rcode = nativeCmsFinder->Locate(Resp, newPath.c_str(), flags, EnvInfo);
143  // set new error message to full url:port//newPath
144  const std::string errText { std::string(Resp.getErrText()) + ':' + std::to_string(Resp.getErrInfo()) + newPath};
145  Resp.setErrInfo(0, errText.c_str());
146  // now have normal redirection to dataserver at url:port
147  return rcode;
148  }
149  }
150  std::string dialect = EnvInfo->secEnv()->addrInfo->Dialect();
151  // get regular target host
152  rcode = nativeCmsFinder->Locate(Resp, path, flags, EnvInfo);
153 
154  // check if http redirect to local filesystem is allowed
155  if (strncmp(dialect.c_str(), "http", 4) == 0 && !httpRedirect)
156  return rcode;
157 
158  // define target host from locate result
159  XrdNetAddr target(-1); // port is necessary, but can be any
160  target.Set(Resp.getErrText());
161  // does the target host have a private IP?
162  if (!target.isPrivate())
163  return rcode;
164  // does the client host have a private IP?
165  if (!EnvInfo->secEnv()->addrInfo->isPrivate())
166  return rcode;
167 
168  // as we can't rely on the flags from http clients, we do not perform the below
169  if (strncmp(dialect.c_str(), "http", 4) != 0)
170  {
171  // get client url redirect capability
172  int urlRedirSupport = Resp.getUCap();
173  urlRedirSupport &= XrdOucEI::uUrlOK;
174  if (!urlRedirSupport)
175  return rcode;
176 
177  // get client localredirect capability
178  int clientLRedirSupport = Resp.getUCap();
179  clientLRedirSupport &= XrdOucEI::uLclF;
180  if (!clientLRedirSupport)
181  return rcode;
182  }
183 
184  // http gets SFS_O_STAT flag when opening to read, instead of SFS_O_RDONLY
185  // in case of http dialect and stat, we do not perform the checks below
186  if (!(strncmp(dialect.c_str(), "http", 4) == 0 && flags == 0x20000000))
187  {
188  // only allow simple (but most prominent) operations to avoid complications
189  // RDONLY, WRONLY, RDWR, CREAT, TRUNC are allowed
190  if (flags > 0x202)
191  return rcode;
192  // always use native function if readOnlyredirect is configured and a
193  // non readonly flag is passed
194  if (readOnlyredirect && !(flags == SFS_O_RDONLY))
195  return rcode;
196  }
197  // passed all checks, now to actual business
198  // prepend manually configured localroot
199  std::string ppath = "file://" + localroot + path;
200  if (strncmp(dialect.c_str(), "http", 4) == 0)
201  {
202  // set info which will be sent to client
203  // eliminate the resource name so it is not doubled in XrdHttpReq::Redir.
204  Resp.setErrInfo(-1, ppath.substr(0, ppath.find(path)).c_str());
205  }
206  else{
207  // set info which will be sent to client
208  Resp.setErrInfo(-1, ppath.c_str());
209  }
210  return SFS_REDIRECT;
211  }
212  return rcode;
213 }
#define SFS_REDIRECT
#define SFS_O_RDONLY
virtual int Locate(XrdOucErrInfo &Resp, const char *path, int flags, XrdOucEnv *Info=0)=0
const char * Dialect()
const XrdSecEntity * secEnv() const
Definition: XrdOucEnv.hh:107
char * Env(int &envlen)
Definition: XrdOucEnv.hh:48
const char * getErrText()
int setErrInfo(int code, const char *emsg)
XrdNetAddrInfo * addrInfo
Entity's connection details.
Definition: XrdSecEntity.hh:80
static const int uUrlOK
ucap: Supports async responses
static const int uLclF
ucap: Client is on a private net

References XrdSecEntity::addrInfo, XrdNetAddrInfo::Dialect(), XrdOucEnv::Env(), XrdOucErrInfo::getErrInfo(), XrdOucErrInfo::getErrText(), XrdOucErrInfo::getUCap(), httpRedirect, XrdNetAddrInfo::isPrivate(), localroot, XrdCmsClient::Locate(), nativeCmsFinder, readOnlyredirect, XrdOucEnv::secEnv(), XrdNetAddr::Set(), XrdOucErrInfo::setErrInfo(), SFS_O_RDONLY, SFS_REDIRECT, XrdOucEI::uLclF, and XrdOucEI::uUrlOK.

+ Here is the call graph for this function:

◆ Managers()

XrdOucTList* XrdCmsRedirLocal::Managers ( )
inlinevirtual

Obtain the list of cmsd's being used by a manager node along with their associated index numbers, origin 1.

Returns
The list of cmsd's being used. The list is considered permanent and is not deleted.

Reimplemented from XrdCmsClient.

Definition at line 62 of file XrdCmsRedirLocal.hh.

62 { return nativeCmsFinder->Managers(); }
virtual XrdOucTList * Managers()

References XrdCmsClient::Managers(), and nativeCmsFinder.

+ Here is the call graph for this function:

◆ Prepare()

int XrdCmsRedirLocal::Prepare ( XrdOucErrInfo Resp,
XrdSfsPrep pargs,
XrdOucEnv Info = 0 
)
inlinevirtual

Start the preparation of a file for future processing.

Parameters
RespObject where message or response is to be returned.
pargsInformation on which and how to prepare the file.
InfoAssociated environmental information.
Returns
As explained under "return conventions".

Reimplemented from XrdCmsClient.

Definition at line 63 of file XrdCmsRedirLocal.hh.

63  {
64  return nativeCmsFinder->Prepare(Resp, pargs, Info);
65  }
@ Info
virtual int Prepare(XrdOucErrInfo &Resp, XrdSfsPrep &pargs, XrdOucEnv *Info=0)

References Info, nativeCmsFinder, and XrdCmsClient::Prepare().

+ Here is the call graph for this function:

◆ Release()

int XrdCmsRedirLocal::Release ( int  n = 1)
inlinevirtual

Increases the amount of resource available. When transitioning from a a non-positive to a positive resource amount, perform a resume so that additional clients may be dispatched to this data server.

Parameters
nThe value to add to the resources available (default 1). The total amount is capped by the amount specified by Resource().
Returns
The amount of resource left.

Reimplemented from XrdCmsClient.

Definition at line 71 of file XrdCmsRedirLocal.hh.

71 { return nativeCmsFinder->Release(n); }
virtual int Release(int n=1)

References nativeCmsFinder, and XrdCmsClient::Release().

+ Here is the call graph for this function:

◆ Removed()

void XrdCmsRedirLocal::Removed ( const char *  path)
inlinevirtual

Notify the cmsd that a file or directory has been deleted. It is only called called on a data server node.

Parameters
pathThe logical file name that was removed.

Reimplemented from XrdCmsClient.

Definition at line 66 of file XrdCmsRedirLocal.hh.

66 { return nativeCmsFinder->Removed(path); }
virtual void Removed(const char *path)

References nativeCmsFinder, and XrdCmsClient::Removed().

+ Here is the call graph for this function:

◆ Reserve()

int XrdCmsRedirLocal::Reserve ( int  n = 1)
inlinevirtual

Decreases the amount of resources available. When the available resources becomes non-positive, perform a temporary suspend to prevent additional clients from being dispatched to this data server.

Parameters
nThe value by which resources are decreased (default 1).
Returns
The amount of resource left.

Reimplemented from XrdCmsClient.

Definition at line 70 of file XrdCmsRedirLocal.hh.

70 { return nativeCmsFinder->Reserve(n); }
virtual int Reserve(int n=1)

References nativeCmsFinder, and XrdCmsClient::Reserve().

+ Here is the call graph for this function:

◆ Resource()

int XrdCmsRedirLocal::Resource ( int  n)
inlinevirtual

Enables the Reserve() & Release() methods.

Parameters
na positive integer that specifies the amount of resource units that are available. It may be reset at any time.
Returns
The previous resource value. This first call returns 0.

Reimplemented from XrdCmsClient.

Definition at line 69 of file XrdCmsRedirLocal.hh.

69 { return nativeCmsFinder->Resource(n); }
virtual int Resource(int n)

References nativeCmsFinder, and XrdCmsClient::Resource().

+ Here is the call graph for this function:

◆ Resume()

void XrdCmsRedirLocal::Resume ( int  Perm = 1)
inlinevirtual

Resume service after a suspension.

Parameters
PermWhen true the resume persist across server restarts. Otherwise, it is treated as a temporary request.

Reimplemented from XrdCmsClient.

Definition at line 67 of file XrdCmsRedirLocal.hh.

67 { nativeCmsFinder->Resume(Perm); }
virtual void Resume(int Perm=1)

References nativeCmsFinder, and XrdCmsClient::Resume().

+ Here is the call graph for this function:

◆ Space()

int XrdCmsRedirLocal::Space ( XrdOucErrInfo Resp,
const char *  path,
XrdOucEnv EnvInfo 
)
virtual

Space Calls nativeCmsFinder->Space

Implements XrdCmsClient.

Definition at line 219 of file XrdCmsRedirLocal.cc.

220  {
221  if (nativeCmsFinder)
222  return nativeCmsFinder->Space(Resp, path, EnvInfo);
223  return 0;
224 }
virtual int Space(XrdOucErrInfo &Resp, const char *path, XrdOucEnv *Info=0)=0

References nativeCmsFinder, and XrdCmsClient::Space().

+ Here is the call graph for this function:

◆ Suspend()

void XrdCmsRedirLocal::Suspend ( int  Perm = 1)
inlinevirtual

Suspend service.

Parameters
PermWhen true the suspend persist across server restarts. Otherwise, it is treated as a temporary request.

Reimplemented from XrdCmsClient.

Definition at line 68 of file XrdCmsRedirLocal.hh.

68 { nativeCmsFinder->Suspend(Perm); }
virtual void Suspend(int Perm=1)

References nativeCmsFinder, and XrdCmsClient::Suspend().

+ Here is the call graph for this function:

Member Data Documentation

◆ httpRedirect

bool XrdCmsRedirLocal::httpRedirect

Definition at line 78 of file XrdCmsRedirLocal.hh.

Referenced by loadConfig(), and Locate().

◆ localroot

std::string XrdCmsRedirLocal::localroot

Definition at line 79 of file XrdCmsRedirLocal.hh.

Referenced by Configure(), loadConfig(), and Locate().

◆ nativeCmsFinder

XrdCmsClient* XrdCmsRedirLocal::nativeCmsFinder

used to forward requests to CmsFinder with regular implementation

Definition at line 76 of file XrdCmsRedirLocal.hh.

Referenced by ~XrdCmsRedirLocal(), Added(), Configure(), Forward(), isRemote(), Locate(), Managers(), Prepare(), Release(), Removed(), Reserve(), Resource(), Resume(), Space(), and Suspend().

◆ readOnlyredirect

bool XrdCmsRedirLocal::readOnlyredirect

Definition at line 77 of file XrdCmsRedirLocal.hh.

Referenced by loadConfig(), and Locate().

◆ Say

XrdSysError XrdCmsRedirLocal::Say

Definition at line 80 of file XrdCmsRedirLocal.hh.

Referenced by XrdCmsRedirLocal(), and Configure().


The documentation for this class was generated from the following files: