Skip to content

Commit

Permalink
Allow query of current role and dynamic cms state via kXR_query.
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 committed Nov 21, 2013
1 parent 7acd791 commit 95b1441
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 91 deletions.
2 changes: 2 additions & 0 deletions src/XrdCms/XrdCmsClientMan.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ XrdCmsClientMan *nextManager() {return Next;}
char *Name() {return Host;}
char *NPfx() {return HPfx;}

int manPort() {return Port;}

int Send(char *msg, int mlen=0);
int Send(const struct iovec *iov, int iovcnt, int iotot=0);

Expand Down
5 changes: 3 additions & 2 deletions src/XrdCms/XrdCmsConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,10 @@ int XrdCmsConfig::Configure1(int argc, char **argv, char *cfn)
myRoleID = static_cast<int>(rid);
}

// Export the role IN basic form
// Export the role IN basic form and expanded form
//
XrdOucEnv::Export("XRDROLE", XrdCmsRole::Type(myRType));
XrdOucEnv::Export("XRDROLE", myRole);
XrdOucEnv::Export("XRDROLETYPE", myRType);

// For managers, make sure that we have a well designated port.
// For servers or supervisors, force an ephemeral port to be used.
Expand Down
105 changes: 104 additions & 1 deletion src/XrdCms/XrdCmsFinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

#include "XrdOss/XrdOss.hh"

#include "XrdOuc/XrdOucBuffer.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdOuc/XrdOucErrInfo.hh"
#include "XrdOuc/XrdOucReqID.hh"
Expand Down Expand Up @@ -337,7 +338,8 @@ int XrdCmsFinderRMT::Locate(XrdOucErrInfo &Resp, const char *path, int flags,
// Set options and command
//
if (flags & SFS_O_LOCATE)
{Data.Request.rrCode = kYR_locate;
{if (flags & SFS_O_LOCAL) return LocLocal(Resp, Env);
Data.Request.rrCode = kYR_locate;
Data.Opts = (flags & SFS_O_NOWAIT ? CmsLocateRequest::kYR_asap : 0)
| (flags & SFS_O_RESET ? CmsSelectRequest::kYR_refresh : 0);
if (Resp.getUCap() & XrdOucEI::uIPv4)
Expand Down Expand Up @@ -387,6 +389,79 @@ int XrdCmsFinderRMT::Locate(XrdOucErrInfo &Resp, const char *path, int flags,
return send2Man(Resp, path, xmsg, iovcnt+1);
}

/******************************************************************************/
/* L o c L o c a l */
/******************************************************************************/

int XrdCmsFinderRMT::LocLocal(XrdOucErrInfo &Resp, XrdOucEnv *Env)
{
XrdCmsClientMan *Womp, *Manp;
XrdOucBuffer *xBuff = 0;
char *mBeg, *mBuff, mStat;
int mBlen, n;

// If we have no managers or no role, we are not clustered
//
if (!myManagers)
{Resp.setErrInfo(0, "");
return SFS_DATA;
}

// Get where to start and where to put the information
//
Womp = Manp = myManagers;
mBeg = mBuff = Resp.getMsgBuff(mBlen);

// Check if we can use the internal buffer or need to get an external buffer
//
n = 8 + (myManCount * (256+6+2));
if (n > mBlen)
{mBeg = mBuff = (char *)malloc(n);
if (!mBeg)
{Resp.setErrInfo(ENOMEM, "Insufficient memory.");
return SFS_ERROR;
}
xBuff = new XrdOucBuffer(mBeg, n);
mBlen = n;
}

// Make sure we have enough space to continue
//
if (mBlen < 1024)
{Resp.setErrInfo(EINVAL, "Invalid role.");
return SFS_ERROR;
}

// List the status of each manager
//
do {if (Manp->isActive()) mStat = (Manp->Suspended() ? 's' : 'c');
else mStat = 'd';
n = snprintf(mBuff, mBlen, "%s:%d/%c ",
Manp->Name(), Manp->manPort(), mStat);
mBuff += n; mBlen -= n;
} while((Manp = Manp->nextManager()) != Womp && mBlen > 0);

// We should not have overrun the buffer; if we did declare failure
//
if (mBlen < 0)
{Resp.setErrInfo(EINVAL, "Internal processing error.");
if (xBuff) xBuff->Recycle();
return SFS_ERROR;
}

// Set the final result
//
n = mBuff - mBeg;
if (!xBuff) Resp.setErrCode(n);
else {xBuff->SetLen(n);
Resp.setErrInfo(n, xBuff);
}

// All done
//
return SFS_DATA;
}

/******************************************************************************/
/* P r e p a r e */
/******************************************************************************/
Expand Down Expand Up @@ -828,6 +903,34 @@ int XrdCmsFinderTRG::Configure(const char *cfn, char *Ags, XrdOucEnv *envP)
return RunAdmin(config.CMSPath);
}

/******************************************************************************/
/* L o c a t e */
/******************************************************************************/

int XrdCmsFinderTRG::Locate(XrdOucErrInfo &Resp, const char *path, int flags,
XrdOucEnv *Env)
{
char *mBuff;
int mBlen, n;

// We only support locate on the local configuration
//
if (!(flags & SFS_O_LOCATE) || !(flags & SFS_O_LOCAL))
{Resp.setErrInfo(EINVAL, "Invalid locate option for target config.");
return SFS_ERROR;
}

// Get the buffer for the result
//
mBuff = Resp.getMsgBuff(mBlen);

// Return information
//
n = snprintf(mBuff, mBlen, "localhost:0/%c", (Active ? 'a' : 'd'));
Resp.setErrCode(n);
return SFS_DATA;
}

/******************************************************************************/
/* R e m o v e d */
/******************************************************************************/
Expand Down
3 changes: 2 additions & 1 deletion src/XrdCms/XrdCmsFinder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ static const int MaxMan = 15;
private:
int Decode(char **resp);
void Inform(XrdCmsClientMan *xman, struct iovec xmsg[], int xnum);
int LocLocal(XrdOucErrInfo &Resp, XrdOucEnv *Env);
XrdCmsClientMan *SelectManager(XrdOucErrInfo &Resp, const char *path);
void SelectManFail(XrdOucErrInfo &Resp);
int send2Man(XrdOucErrInfo &, const char *, struct iovec *, int);
Expand Down Expand Up @@ -124,7 +125,7 @@ public:
int Configure(const char *cfn, char *Args, XrdOucEnv *EnvInfo);

int Locate(XrdOucErrInfo &Resp, const char *path, int flags,
XrdOucEnv *Info=0) {return 0;}
XrdOucEnv *Info=0);

int Prepare(XrdOucErrInfo &Resp, XrdSfsPrep &pargs,
XrdOucEnv *Info=0) {return 0;}
Expand Down
13 changes: 5 additions & 8 deletions src/XrdCms/XrdCmsRole.hh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ static RoleID Convert(const char *Tok1, const char *Tok2)
{if (!Tok2)
{if (!strcmp( Tok1, "server")) return Server;
if (!strcmp( Tok1, "supervisor")) return Supervisor;
if (!strcmp( Tok1, "peer")) return Peer;
return (strcmp(Tok1, "manager") ? noRole:Manager);
}
if (!strcmp( Tok1, "proxy"))
Expand All @@ -58,20 +57,18 @@ static RoleID Convert(const char *Tok1, const char *Tok2)
}
if (!strcmp( Tok1, "meta"))
return (strcmp(Tok2, "manager") ? noRole:MetaManager);
if (!strcmp( Tok1, "peer"))
return (strcmp(Tok2, "manager") ? noRole:Peer);
return noRole;
}

static const char *Name(RoleID rid)
{static const char *rName[] = {"metamanager", // MetaMan
{static const char *rName[] = {"meta manager", // MetaMan
"manager", // Manager
"supervisor", // Super
"server", // Server
"proxy-manager", // ProxyMan
"proxy-super", // ProxySuper
"proxy-server", // ProxyServ
"peer-manager", // PeerMan
"proxy manager", // ProxyMan
"proxy supervisor",
"proxy server", // ProxyServ
"peer manager", // PeerMan
"peer" // Peer
};
if (rid >= MetaManager && rid < noRole) return rName[rid];
Expand Down
13 changes: 13 additions & 0 deletions src/XrdOfs/XrdOfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,7 @@ int XrdOfs::fsctl(const int cmd,
Input: cmd - Operation command (currently supported):
SFS_FSCTL_LOCATE - locate file
SFS_FSCTL_STATCC - return cluster config status
SFS_FSCTL_STATFS - return file system info (physical)
SFS_FSCTL_STATLS - return file system info (logical)
SFS_FSCTL_STATXA - return file extended attributes
Expand Down Expand Up @@ -1646,6 +1647,18 @@ int XrdOfs::fsctl(const int cmd,
return SFS_DATA;
}

// Process the STATCC request (this should always succeed)
//
if (opcode == SFS_FSCTL_STATCC)
{static const int lcc_flag = SFS_O_LOCATE | SFS_O_LOCAL;
XrdOucEnv lcc_Env(0,0,client);
if (Finder) retc = Finder ->Locate(einfo,".",lcc_flag,&lcc_Env);
else if (Balancer) retc = Balancer->Locate(einfo,".",lcc_flag,&lcc_Env);
else retc = SFS_ERROR;
if (retc != SFS_DATA) einfo.setErrInfo(5, "none|");
return fsError(einfo, SFS_DATA);
}

// Operation is not supported
//
return XrdOfsFS->Emsg(epname, einfo, ENOTSUP, "fsctl", args);
Expand Down
2 changes: 2 additions & 0 deletions src/XrdOfs/XrdOfs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ XrdCksConfig *CksConfig; // Checksum configurator
XrdCks *Cks; // Checksum manager
int CksRdsz; // Checksum read size

char myRType[4]; // Role type for consistency with the cms

XrdVersionInfo *myVersion; // Version number compiled against

static XrdOfsHandle *dummyHandle;
Expand Down

0 comments on commit 95b1441

Please sign in to comment.