XRootD
XrdCmsAdmin Class Reference

#include <XrdCmsAdmin.hh>

+ Collaboration diagram for XrdCmsAdmin:

Public Member Functions

 XrdCmsAdmin ()
 
 ~XrdCmsAdmin ()
 
void Login (int socknum)
 
void MonAds ()
 
void * Notes (XrdNetSocket *AdminSock)
 
void Send (const char *Req, XrdCmsRRData &Data)
 
void * Start (XrdNetSocket *AdminSock)
 

Static Public Member Functions

static bool InitAREvents (void *arFunc)
 
static void Relay (int setSock, int newSock)
 
static void RelayAREvent ()
 
static void setSync (XrdSysSemaphore *sync)
 

Detailed Description

Definition at line 45 of file XrdCmsAdmin.hh.

Constructor & Destructor Documentation

◆ XrdCmsAdmin()

XrdCmsAdmin::XrdCmsAdmin ( )
inline

Definition at line 67 of file XrdCmsAdmin.hh.

67 {Sname = 0; Stype = "Server"; Primary = 0;}

◆ ~XrdCmsAdmin()

XrdCmsAdmin::~XrdCmsAdmin ( )
inline

Definition at line 68 of file XrdCmsAdmin.hh.

68 {if (Sname) free(Sname);}

Member Function Documentation

◆ InitAREvents()

bool XrdCmsAdmin::InitAREvents ( void *  arFunc)
static

Definition at line 176 of file XrdCmsAdmin.cc.

177 {
178  pthread_t tid;
179 
180 // Record the function we will be using
181 //
182  areFunc = (XrdOssStatInfo2_t)arFunc;
183 
184 // Start the event relay
185 //
186  if (XrdSysThread::Run(&tid, AdminMonARE, (void *)0))
187  {Say.Emsg("InitAREvents", errno, "start arevent relay");
188  return false;
189  }
190 
191 // All done
192 //
193  return true;
194 }
int(* XrdOssStatInfo2_t)(const char *path, struct stat *buff, int opts, XrdOucEnv *envP, const char *lfn)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
XrdSysError Say

References XrdSysError::Emsg(), XrdSysThread::Run(), and XrdCms::Say.

+ Here is the call graph for this function:

◆ Login()

void XrdCmsAdmin::Login ( int  socknum)

Definition at line 200 of file XrdCmsAdmin.cc.

201 {
202  const char *epname = "Admin_Login";
203  const char *sMsg[2] = {"temporary suspend requested by",
204  "long-term suspend requested by"};
205  char *request, *tp;
206  int sPerm;
207 
208 // Attach the socket FD to a stream
209 //
210  Stream.Attach(socknum);
211 
212 // The first request better be "login"
213 //
214  if ((request = Stream.GetLine()))
215  {DEBUG("initial request: '" <<request <<"'");
216  if (!(tp = Stream.GetToken()) || strcmp("login", tp) || !do_Login())
217  {Say.Emsg(epname, "Invalid admin login sequence");
218  return;
219  }
220  } else {Say.Emsg(epname, "No admin login specified");
221  return;
222  }
223 
224 // Start receiving requests on this stream
225 //
226  while((request = Stream.GetLine()))
227  {DEBUG("received request: '" <<request <<"'");
228  if ((tp = Stream.GetToken()))
229  { if (!strcmp("resume", tp))
230  {if ((tp = Stream.GetToken()) && *tp == 't') sPerm = 0;
231  else sPerm = 1;
233  }
234  else if (!strcmp("rmdid", tp)) do_RmDid(); // via lfn
235  else if (!strcmp("newfn", tp)) do_RmDud(); // via lfn
236  else if (!strcmp("perf", tp)) do_Perf();
237  else if (!strcmp("PERF", tp)) do_Perf(true);
238  else if (!strcmp("suspend", tp))
239  {if ((tp = Stream.GetToken()) && *tp == 't') sPerm = 0;
240  else sPerm = 1;
242  Say.Emsg("Login", sMsg[sPerm], Stype, Sname);
243  }
244  else Say.Emsg(epname, "invalid admin request,", tp);
245  }
246  }
247 
248 // The socket disconnected
249 //
250  Say.Emsg("Login", Stype, Sname, "logged out");
251 
252 // If this is a primary, we must suspend but do not record this event!
253 //
254  if (Primary)
256  myMutex.Lock();
257  POnline = 0;
258  Relay(1,-1);
259  myMutex.UnLock();
260  }
261  return;
262 }
#define DEBUG(x)
Definition: XrdBwmTrace.hh:54
static void Relay(int setSock, int newSock)
Definition: XrdCmsAdmin.cc:344
void Update(StateType StateT, int ActivVal, int StageVal=0)
Definition: XrdCmsState.cc:258
char * GetLine()
int Attach(int FileDescriptor, int bsz=2047)
char * GetToken(int lowcase=0)
XrdCmsState CmsState
Definition: XrdCmsState.cc:55

References XrdCmsState::Active, XrdCms::CmsState, DEBUG, XrdSysError::Emsg(), XrdCmsState::FrontEnd, XrdCms::Say, and XrdCmsState::Update().

Referenced by XrdXrootdLoginAdmin().

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

◆ MonAds()

void XrdCmsAdmin::MonAds ( )

Definition at line 268 of file XrdCmsAdmin.cc.

269 {
270  const char *epname = "MonAds";
271  int sFD, rc;
272  char buff[256], pname[64];
273 
274 // Indicate what we are doing
275 //
276  sprintf(pname, "'altds@localhost:%d'.", Config.adsPort);
277  Say.Emsg(epname, "Monitoring", pname);
278 
279 // Create a socket and to connect to the alternate data server then monitor it
280 // draining any data that might be sent.
281 //
282 do{sFD = Con2Ads(pname);
283 
284  do {do {rc = read(sFD, buff, sizeof(buff));} while(rc > 0);
285  } while(rc < 0 && errno == EINTR);
286 
287  if (rc < 0) Say.Emsg(epname, errno, "maintain contact with", pname);
288  else Say.Emsg(epname,"Lost contact with", pname);
289 
291  close(sFD);
293 
294  } while(1);
295 }
ssize_t read(int fildes, void *buf, size_t nbyte)
#define close(a)
Definition: XrdPosix.hh:43
static void Snooze(int seconds)
Definition: XrdSysTimer.cc:168
XrdCmsConfig Config

References XrdCmsConfig::adsPort, close, XrdCms::CmsState, XrdCms::Config, XrdSysError::Emsg(), XrdCmsState::FrontEnd, read(), XrdCms::Say, XrdSysTimer::Snooze(), and XrdCmsState::Update().

+ Here is the call graph for this function:

◆ Notes()

void * XrdCmsAdmin::Notes ( XrdNetSocket AdminSock)

Definition at line 301 of file XrdCmsAdmin.cc.

302 {
303  const char *epname = "Notes";
304  char *request, *tp;
305  int rc;
306 
307 // Bind the udp socket to a stream
308 //
309  Stream.Attach(AnoteSock->Detach());
310  Sname = strdup("anon");
311 
312 // Accept notifications in an endless loop
313 //
314  do {while((request = Stream.GetLine()))
315  {DEBUG("received notification: '" <<request <<"'");
316  if ((tp = Stream.GetToken()))
317  { if (!strcmp("gone", tp)) do_RmDid(1); // via pfn
318  else if (!strcmp("rmdid", tp)) do_RmDid(0); // via lfn
319  else if (!strcmp("have", tp)) do_RmDud(1); // via pfn
320  else if (!strcmp("newfn", tp)) do_RmDud(0); // via lfn
321  else if (!strcmp("nostage", tp))
323  Say.Emsg("Notes","nostage requested by",Stype,Sname);
324  }
325  else if (!strcmp("stage", tp))
327  else Say.Emsg(epname, "invalid notification,", tp);
328  }
329  }
330  if ((rc = Stream.LastError())) break;
331  rc = Stream.Detach(); Stream.Attach(rc);
332  } while(1);
333 
334 // We should never get here
335 //
336  Say.Emsg(epname, rc, "accept notification");
337  return (void *)0;
338 }

References XrdCms::CmsState, DEBUG, XrdNetSocket::Detach(), XrdSysError::Emsg(), XrdCms::Say, XrdCmsState::Stage, and XrdCmsState::Update().

Referenced by XrdCmsStartAnote().

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

◆ Relay()

void XrdCmsAdmin::Relay ( int  setSock,
int  newSock 
)
static

Definition at line 344 of file XrdCmsAdmin.cc.

345 {
346  const char *epname = "Admin_Relay";
347  static const int HdrSz = sizeof(CmsRRHdr);
348  static XrdSysMutex SMutex;
349  static XrdSysSemaphore SReady(0);
350  static int curSock = -1;
351  AdminReq *arP;
352  int retc, mySock = -1;
353 
354 // Set socket for writing (called from admin thread when pimary logs on)
355  if (setSock)
356  {SMutex.Lock();
357  if (curSock >= 0) close(curSock);
358  else if (newSock >= 0) SReady.Post();
359  if (newSock < 0) curSock = -1;
360  else {curSock = dup(newSock); XrdNetSocket::setOpts(curSock, 0);}
361  SMutex.UnLock();
362  return;
363  }
364 
365 // This is just an endless loop
366 //
367  do {while(mySock < 0)
368  {SMutex.Lock();
369  if (curSock < 0) {SMutex.UnLock(); SReady.Wait(); SMutex.Lock();}
370  mySock = curSock; curSock = -1;
371  SMutex.UnLock();
372  }
373 
374  do {arP = AdminReq::getReq();
375 
376  if ((retc = write(mySock, &arP->Hdr, HdrSz)) != HdrSz
377  || (retc = write(mySock, arP->Data, arP->Dlen)) != arP->Dlen)
378  retc = (retc < 0 ? errno : ECANCELED);
379  else {DEBUG("sent " <<arP->Req <<' ' <<arP->Path);
380  delete arP; retc = 0;
381  }
382  } while(retc == 0);
383 
384  if (retc) Say.Emsg("AdminRelay", retc, "relay", arP->Req);
385  arP->Requeue();
386  close(mySock);
387  mySock = -1;
388  } while(1);
389 }
ssize_t write(int fildes, const void *buf, size_t nbyte)
const char * Req
Definition: XrdCmsAdmin.cc:70
const char * Path
Definition: XrdCmsAdmin.cc:71
static int setOpts(int fd, int options, XrdSysError *eDest=0)

References close, XrdCms::AdminReq::Data, DEBUG, XrdCms::AdminReq::Dlen, XrdSysError::Emsg(), XrdCms::AdminReq::getReq(), XrdCms::AdminReq::Hdr, XrdSysMutex::Lock(), XrdCms::AdminReq::Path, XrdSysSemaphore::Post(), XrdCms::AdminReq::Req, XrdCms::AdminReq::Requeue(), XrdCms::Say, XrdNetSocket::setOpts(), XrdSysMutex::UnLock(), XrdSysSemaphore::Wait(), and write().

+ Here is the call graph for this function:

◆ RelayAREvent()

void XrdCmsAdmin::RelayAREvent ( )
static

Definition at line 395 of file XrdCmsAdmin.cc.

396 {
397  EPNAME("RelayAREvent");
398  const char *evWhat;
399  XrdOucTList *evP;
400  int evType, mod;
401 
402 // Endless loop relaying events
403 //
404 do{areMutex.Lock();
405  while((evP = areFirst))
406  {if (evP == areLast) areFirst = areLast = 0;
407  else areFirst = evP->next;
408  areMutex.UnLock();
409  XrdCms::CmsReqCode reqCode = static_cast<CmsReqCode>(evP->ival[0]);
410  mod = evP->ival[1];
411  if (reqCode == kYR_have)
412  {if (mod & CmsHaveRequest::Pending)
413  {evType = XrdOssStatEvent::PendAdded;
414  evWhat = "pend ";
415  } else {
417  evWhat = "have ";
418  }
419  } else {
421  evWhat = "gone ";
422  }
423  (*areFunc)(evP->text, 0, evType, 0, evP->text);
424  DEBUG("sending managers " <<evWhat <<evP->text);
425  XrdCmsManager::Inform(reqCode, mod, evP->text, strlen(evP->text)+1);
426  delete evP;
427  areMutex.Lock();
428  }
429  arePost = true;
430  areMutex.UnLock();
431  areSem.Wait();
432  } while(true);
433 }
#define EPNAME(x)
Definition: XrdBwmTrace.hh:56
static void Inform(const char *What, const char *Data, int Dlen)
XrdOucTList * next
Definition: XrdOucTList.hh:45
char * text
Definition: XrdOucTList.hh:46
CmsReqCode
Definition: YProtocol.hh:90
@ kYR_have
Definition: YProtocol.hh:105
static const int PendAdded
Path has been added in pending mode.
static const int FileRemoved
Path has been removed.
static const int FileAdded
Path has been added.

References DEBUG, EPNAME, XrdOssStatEvent::FileAdded, XrdOssStatEvent::FileRemoved, XrdCmsManager::Inform(), XrdCms::kYR_have, XrdOucTList::next, XrdOssStatEvent::PendAdded, XrdCms::CmsHaveRequest::Pending, and XrdOucTList::text.

+ Here is the call graph for this function:

◆ Send()

void XrdCmsAdmin::Send ( const char *  Req,
XrdCmsRRData Data 
)

Definition at line 439 of file XrdCmsAdmin.cc.

440 {
441 // AdminReq *arP;
442 
443  if (AdminReq::numinQ < AdminReq::maxinQ) new AdminReq(Req, Data);
444  else Say.Emsg("Send", "Queue full; ignoring", Req, Data.Path);
445 }

References XrdSysError::Emsg(), XrdCms::AdminReq::maxinQ, XrdCms::AdminReq::numinQ, XrdCmsRRData::Path, and XrdCms::Say.

+ Here is the call graph for this function:

◆ setSync()

static void XrdCmsAdmin::setSync ( XrdSysSemaphore sync)
inlinestatic

Definition at line 55 of file XrdCmsAdmin.hh.

55 {SyncUp = sync;}

Referenced by XrdCmsConfig::DoIt().

+ Here is the caller graph for this function:

◆ Start()

void * XrdCmsAdmin::Start ( XrdNetSocket AdminSock)

Definition at line 451 of file XrdCmsAdmin.cc.

452 {
453  const char *epname = "Start";
454  int InSock;
455  pthread_t tid;
456 
457 // Start the relay thread
458 //
459  if (XrdSysThread::Run(&tid, AdminSend, (void *)0))
460  Say.Emsg(epname, errno, "start admin relay");
461 
462 // If we are in independent mode then let the caller continue
463 //
464  if (Config.doWait)
465  {if (Config.adsPort) BegAds();
466  {char dest[512];
467  AdminSock->SockName(dest, sizeof(dest));
468  Say.Emsg(epname, "Waiting for primary server to login via", dest);
469  }
470  }
471  else if (SyncUp) {SyncUp->Post(); SyncUp = 0;}
472 
473 // Accept connections in an endless loop
474 //
475  while(1) if ((InSock = AdminSock->Accept()) >= 0)
476  {XrdNetSocket::setOpts(InSock, 0);
477  if (XrdSysThread::Run(&tid, AdminLogin, (void *)&InSock))
478  {Say.Emsg(epname, errno, "start admin");
479  close(InSock);
480  }
481  } else Say.Emsg(epname, errno, "accept connection");
482  return (void *)0;
483 }
int SockName(char *buff, int blen)
int Accept(int ms=-1)
Definition: XrdNetSocket.cc:99

References XrdNetSocket::Accept(), XrdCmsConfig::adsPort, close, XrdCms::Config, XrdCmsConfig::doWait, XrdSysError::Emsg(), XrdSysThread::Run(), XrdCms::Say, XrdNetSocket::setOpts(), and XrdNetSocket::SockName().

Referenced by XrdCmsStartAdmin(), and XrdXrootdInitAdmin().

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

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