Logo ROOT   6.12/07
Reference Guide
TXNetSystem.cxx
Go to the documentation of this file.
1 // @(#)root/netx:$Id$
2 // Author: Frank Winklmeier, Fabrizio Furano
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2016, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 
13 //////////////////////////////////////////////////////////////////////////
14 // //
15 // TXNetSystem //
16 // //
17 // Authors: Frank Winklmeier, Fabrizio Furano //
18 // INFN Padova, 2005 //
19 // //
20 // TXNetSystem is an extension of TNetSystem able to deal with new //
21 // xrootd servers. The class detects the nature of the server and //
22 // redirects the calls to TNetSystem in case of a rootd server. //
23 // //
24 //////////////////////////////////////////////////////////////////////////
25 
26 #include "TEnv.h"
27 #include "TFileStager.h"
28 #include "TObjString.h"
29 #include "TROOT.h"
30 #include "TSocket.h"
31 #include "TString.h"
32 #include "TUrl.h"
33 #include "TVirtualMutex.h"
34 #include "TXNetFile.h"
35 #include "TXNetSystem.h"
36 
37 #include "XrdOuc/XrdOucString.hh"
39 #include "XrdClient/XrdClientAdmin.hh"
43 #include "XProtocol/XProtocol.hh"
44 
45 #include "XrdProofdXrdVers.h"
46 
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// PluginManager creation function
50 
51 TSystem* ROOT_Plugin_TXNetSystem(const char *url, Bool_t owner) {
52  return new TXNetSystem(url, owner);
53 }
54 
55 
57 
62 
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// Create system management class without connecting to server.
67 
68 TXNetSystem::TXNetSystem(Bool_t owner) : TNetSystem(owner), fDirList(0)
69 {
70  SetTitle("(x)rootd system administration");
71  fIsRootd = kFALSE;
72  fIsXRootd = kFALSE;
73  fDir = "";
74  fDirp = 0;
75  fUrl = "";
76 }
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// Create system management class and connect to server specified by url.
80 
81 TXNetSystem::TXNetSystem(const char *url, Bool_t owner) : TNetSystem(owner), fDirList(0)
82 {
83  SetTitle("(x)rootd system administration");
84  fIsRootd = kFALSE;
85  fIsXRootd = kFALSE;
86  fDir = "";
87  fDirp = 0;
88  fUrl = url;
89 
92 
93  // Set debug level
94  EnvPutInt(NAME_DEBUG, gEnv->GetValue("XNet.Debug", -1));
95 
96  // The first time do some global initialization
97  if (!fgInitDone)
98  InitXrdClient();
99 
100  // Fill in user, host, port
102 
103  TXNetSystemConnectGuard cguard(this, url);
104  if (!cguard.IsValid() && !fIsRootd)
105  Error("TXNetSystem","fatal error: connection creation failed.");
106 
107  return;
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Init a connection to the server.
112 /// Returns a pointer to the appropriate instance of XrdClientAdmin or 0
113 /// in case of failure.
114 
115 XrdClientAdmin *TXNetSystem::Connect(const char *url)
116 {
117  // We need a dummy filename after the server url to connect
118  TString dummy = url;
119  dummy += "/dummy";
120 
121  XrdClientAdmin *cadm = TXNetSystem::GetClientAdmin(dummy);
122 
123  if (!cadm) {
124  Error("Connect","fatal error: new object creation failed.");
125  return cadm;
126  }
127 
128  // Do not block: restore old value after
130 
131  // Try to connect to the server
132  gEnv->SetValue("XNet.FirstConnectMaxCnt", 1);
134  if (cadm->Connect()) {
135  fIsXRootd = kTRUE;
137  } else {
139  if (fgRootdBC) {
140  Bool_t isRootd =
141  (cadm->GetClientConn()->GetServerType() == kSTRootd);
142  Int_t sd = cadm->GetClientConn()->GetOpenSockFD();
143  if (isRootd && sd > -1) {
144  //
145  // Create a TSocket on the open connection
146  TSocket *s = new TSocket(sd);
147 
148  // We will clean it by ourselves
150  gROOT->GetListOfSockets()->Remove(s);
151 
152  s->SetOption(kNoBlock, 0);
153 
154  // Find out the remote protocol (send the client protocol first)
156  if (rproto < 0) {
157  Error("TXNetSystem", "getting protocol of the rootd server");
158  cadm = 0;
159  return 0;
160  }
161  // Finalize TSocket initialization
162  s->SetRemoteProtocol(rproto);
163  TUrl uut((cadm->GetClientConn()
164  ->GetCurrentUrl()).GetUrl().c_str());
165  TString uu;
166  TXNetFile::FormUrl(uut,uu);
167  if (gDebug > 2)
168  Info("Connect"," url: %s",uu.Data());
169 
170  s->SetUrl(uu.Data());
171  s->SetService("rootd");
173  //
174  // Now we can check if we can create a TNetFile on the
175  // open connection
176  if (rproto > 13) {
177  //
178  // Remote support for reuse of open connection
179  TNetSystem::Create(uu, s);
180  } else {
181  //
182  // Open connection has been closed because could
183  // not be reused; TNetSystem will open a new connection
184  TNetSystem::Create(uu);
185  }
186 
187  // Type of server
188  fIsRootd = kTRUE;
189  cadm = 0;
190 
191  } else {
192  Error("Connect", "some severe error occurred while opening"
193  " the connection at %s - exit", url);
194  if (cadm && cadm->LastServerError())
195  Printf(" '%s'", cadm->LastServerError()->errmsg);
196  else
197  Printf(" (error message not available)");
198  cadm = 0;
199  return cadm;
200  }
201  } else {
202  Error("Connect",
203  "while opening the connection at %s - exit", url);
204  cadm = 0;
205  return cadm;
206  }
207  }
208 
209  return cadm;
210 }
211 
212 ////////////////////////////////////////////////////////////////////////////////
213 /// One-time initialization of some communication variables for xrootd protocol
214 
216 {
217  // Init vars with default debug level -1, so we do not get warnings
219 
220  // Only once
221  fgInitDone = kTRUE;
222 
223  // Print the tag, if required (only once)
224  if (gEnv->GetValue("XNet.PrintTAG",0) == 1)
225  Info("TXNetFile","(C) 2005 SLAC TXNetSystem (eXtended TNetSystem) %s",
226  gROOT->GetVersion());
227 }
228 
229 ////////////////////////////////////////////////////////////////////////////////
230 /// Open a directory. Returns a non-zero pointer (with no special
231 /// purpose) in case of success, 0 in case of error.
232 
233 void* TXNetSystem::OpenDirectory(const char* dir)
234 {
235  if (fIsXRootd) {
236  // Check if the directory exists
237  TXNetSystemConnectGuard cg(this, dir);
238  if (cg.IsValid()) {
239  fUrl = dir;
240  // Extract the directory name
241  fDir = TUrl(dir).GetFile();
242  fDirp = (void*)&fDir; // serves as directory pointer
243 
244  vecString dirs;
245  vecBool existDirs;
246  XrdOucString s(fDir.Data());
247  dirs.Push_back(s);
248  cg.ClientAdmin()->ExistDirs(dirs, existDirs);
249  cg.ClientAdmin()->GoBackToRedirector();
250  if (existDirs.GetSize()>0 && existDirs[0])
251  return fDirp;
252  else
253  cg.NotifyLastError();
254  }
255  return 0;
256  }
257 
258  if (gDebug > 1)
259  Info("OpenDirectory", "calling TNetSystem::OpenDirectory");
260  return TNetSystem::OpenDirectory(dir); // for a rootd
261 }
262 
263 ////////////////////////////////////////////////////////////////////////////////
264 /// Free(Close) the directory referenced by dirp
265 
267 {
268  if (fIsXRootd) {
269  if (dirp != fDirp) {
270  Error("FreeDirectory","invalid directory pointer (%p, %p)", dirp, fDirp);
271  return;
272  }
273  fDir = "";
274  fDirp = 0;
275  fDirEntry = "";
276  if (fDirList) {
277  ((VecString_t*)fDirList)->Clear();
278  delete ((VecString_t*)fDirList);
279  fDirList = 0;
280  }
281  return;
282  }
283 
284  if (gDebug > 1)
285  Info("FreeDirectory","calling TNetSystem::FreeDirectory");
286  return TNetSystem::FreeDirectory(dirp); // for a rootd
287 }
288 
289 ////////////////////////////////////////////////////////////////////////////////
290 /// Create a directory. Return 0 on success, -1 otherwise.
291 
293 {
294  if (fIsXRootd) {
295  TXNetSystemConnectGuard cg(this, dir);
296  if (cg.IsValid()) {
297  // use default permissions 755 to create directory
298  Bool_t ok = cg.ClientAdmin()->Mkdir(TUrl(dir).GetFile(),7,5,5);
299  cg.ClientAdmin()->GoBackToRedirector();
300  if (ok) {
301  return 0;
302  } else {
303  cg.NotifyLastError();
304  return -1;
305  }
306  }
307  }
308 
309  if (gDebug > 1)
310  Info("MakeDirectory","Calling TNetSystem::MakeDirectory");
311  return TNetSystem::MakeDirectory(dir); // for a rootd
312 }
313 
314 ////////////////////////////////////////////////////////////////////////////////
315 /// Get directory entry for directory referenced by dirp.
316 /// Returns 0 in case there are no more entries.
317 
318 const char* TXNetSystem::GetDirEntry(void *dirp)
319 {
320  if (fIsXRootd) {
321  if (dirp != fDirp) {
322  Error("GetDirEntry","invalid directory pointer");
323  return 0;
324  }
325 
326  // Only request new directory listing the first time called
327  if (!fDirList) {
328  TXNetSystemConnectGuard cg(this, fUrl);
329  if (cg.IsValid()) {
330  fDirList = new VecString_t;
331  Bool_t ok = cg.ClientAdmin()->DirList(fDir, *(VecString_t*)fDirList);
332  cg.ClientAdmin()->GoBackToRedirector();
333  if (!ok) {
334  cg.NotifyLastError();
335  delete (VecString_t*)fDirList;
336  fDirList = 0;
337  return 0;
338  }
339  }
340  }
341 
342  // Return entries one by one with each call of method
343  if (fDirList && ((VecString_t*)fDirList)->GetSize() > 0) {
344  fDirEntry = ((VecString_t*)fDirList)->Pop_front().c_str();
345  return fDirEntry.Data();
346  }
347  return 0; // until all of them have been returned
348  }
349 
350  if (gDebug > 1) Info("GetDirEntry","Calling TNetSystem::GetDirEntry");
351  return TNetSystem::GetDirEntry(dirp); // for a rootd
352 }
353 
354 ////////////////////////////////////////////////////////////////////////////////
355 /// Get info about a file. Info is returned in the form of a FileStat_t
356 /// structure (see TSystem.h).
357 /// The function returns 0 in case of success and 1 if the file could
358 /// not be stat'ed.
359 /// NOTICE: Not all information is available with an xrootd server.
360 
362 {
363  if (fIsXRootd) {
364  TXNetSystemConnectGuard cg(this, path);
365  if (cg.IsValid()) {
366 
367  Long_t id;
368  Long64_t size;
369  Long_t flags;
370  Long_t modtime;
371 
372  // Issue the request
373  TUrl urlpath(path);
374  Bool_t ok = cg.ClientAdmin()->Stat(urlpath.GetFile(),id,size,flags,modtime);
375  if (ok) {
376  // Save the endpoint path
377  urlpath.SetProtocol(cg.ClientAdmin()->GetCurrentUrl().Proto.c_str());
378  urlpath.SetHost(cg.ClientAdmin()->GetCurrentUrl().Host.c_str());
379  urlpath.SetPort(cg.ClientAdmin()->GetCurrentUrl().Port);
380  buf.fUrl = urlpath.GetUrl();
381  }
382  cg.ClientAdmin()->GoBackToRedirector();
383 
384  // Flag offline files
385  if (flags & kXR_offline) {
386  buf.fMode = kS_IFOFF;
387  } else if (ok) {
388  buf.fDev = (id >> 24);
389  buf.fIno = (id & 0x00FFFFFF);
390  buf.fUid = -1; // not all information available in xrootd
391  buf.fGid = -1; // not available
392  buf.fSize = size;
393  buf.fMtime = modtime;
394 
395  if (flags == 0) buf.fMode = kS_IFREG;
396  if (flags & kXR_xset) buf.fMode = (kS_IFREG|kS_IXUSR|kS_IXGRP|kS_IXOTH);
397  if (flags & kXR_isDir) buf.fMode = kS_IFDIR;
398  if (flags & kXR_other) buf.fMode = kS_IFSOCK;
399  if (flags & kXR_readable) buf.fMode |= kS_IRUSR;
400  if (flags & kXR_writable) buf.fMode |= kS_IWUSR;
401 
402  buf.fIsLink = 0; // not available
403  return 0;
404  } else {
405  if (gDebug > 0)
406  cg.NotifyLastError();
407  }
408  }
409  return 1;
410  }
411 
412  if (gDebug > 1)
413  Info("GetPathInfo","Calling TNetSystem::GetPathInfo");
414  return TNetSystem::GetPathInfo(path,buf); // for a rootd
415 }
416 
417 ////////////////////////////////////////////////////////////////////////////////
418 /// Check consistency of this helper with the one required
419 /// by 'path' or 'dirptr'.
420 
421 Bool_t TXNetSystem::ConsistentWith(const char *path, void *dirptr)
422 {
423  if (gDebug > 1)
424  Info("ConsistentWith",
425  "calling for path: %s, dir: %p", path, dirptr);
426 
427  return TNetSystem::ConsistentWith(path,dirptr); // for a rootd
428 }
429 
430 ////////////////////////////////////////////////////////////////////////////////
431 /// Returns FALSE if one can access a file using the specified access mode.
432 /// NB: for the time being mode is ignored for XROOTD (just checks existence
433 /// of the file or directory).
434 /// Mode is the same as for the Unix access(2) function.
435 /// Attention, bizarre convention of return value!!
436 
438 {
439  if (fIsXRootd) {
440  // Check only if the file or directory exists and
441  FileStat_t buf;
442  if (GetPathInfo(path, buf) == 0)
443  if (buf.fMode != kS_IFSOCK)
444  return kFALSE;
445  // The file could not be stated
446  return kTRUE;
447  }
448 
449  if (gDebug > 1)
450  Info("AccessPathName", "calling TNetSystem::AccessPathName");
451  return TNetSystem::AccessPathName(path,mode); // for a rootd
452 }
453 
454 ////////////////////////////////////////////////////////////////////////////////
455 /// Unlink 'path' on the remote server system.
456 /// Returns 0 on success, -1 otherwise.
457 
458 int TXNetSystem::Unlink(const char *path)
459 {
460  if (fIsXRootd) {
461 
462  TXNetSystemConnectGuard cg(this, path);
463  if (cg.IsValid()) {
464 
465  Long_t id;
466  Long64_t size;
467  Long_t flags;
468  Long_t modtime;
469 
470  // Extract the directory name
471  TString edir = TUrl(path).GetFile();
472  Bool_t ok = cg.ClientAdmin()->Stat(edir.Data(), id, size, flags, modtime);
473 
474  // Flag offline files
475  if (ok && !(flags & kXR_offline)) {
476  if (flags & kXR_isDir)
477  ok = cg.ClientAdmin()->Rmdir(edir.Data());
478  else
479  ok = cg.ClientAdmin()->Rm(edir.Data());
480  cg.ClientAdmin()->GoBackToRedirector();
481 
482  // Done
483  return ((ok) ? 0 : -1);
484  } else if (!ok) {
485  cg.ClientAdmin()->GoBackToRedirector();
486  cg.NotifyLastError();
487  }
488  }
489  }
490 
491  if (gDebug > 1)
492  Info("Unlink", "calling TNetSystem::Unlink");
493  return -1; // not implemented for rootd
494 }
495 
496 ////////////////////////////////////////////////////////////////////////////////
497 /// Check if the file defined by 'path' is ready to be used
498 
499 Bool_t TXNetSystem::IsOnline(const char *path)
500 {
501  // This is most efficiently done using GetPathInfo
502  FileStat_t st;
503  if (GetPathInfo(path, st) != 0) {
504  if (gDebug > 0)
505  Info("IsOnline", "path '%s' cannot be stat'ed", path);
506  return kFALSE;
507  }
508  if (R_ISOFF(st.fMode)) {
509  if (gDebug > 0)
510  Info("IsOnline", "path '%s' is offline", path);
511  return kFALSE;
512  }
513  // Done
514  return kTRUE;
515 }
516 
517 ////////////////////////////////////////////////////////////////////////////////
518 /// Issue a prepare request for file defined by 'path'
519 
520 Bool_t TXNetSystem::Prepare(const char *path, UChar_t option, UChar_t priority)
521 {
522  TXNetSystemConnectGuard cg(this, path);
523  if (cg.IsValid()) {
524  XrdOucString pathname = TUrl(path).GetFileAndOptions();
525  vecString vs;
526  vs.Push_back(pathname);
527  cg.ClientAdmin()->Prepare(vs, (kXR_char)option, (kXR_char)priority);
528  cg.ClientAdmin()->GoBackToRedirector();
529  if (gDebug >0)
530  Info("Prepare", "Got Status %d for %s",
531  cg.ClientAdmin()->LastServerResp()->status, pathname.c_str());
532  if (!(cg.ClientAdmin()->LastServerResp()->status)){
533  return kTRUE;
534  }
535  cg.NotifyLastError();
536  }
537 
538  // Done
539  return kFALSE;
540 }
541 
542 ////////////////////////////////////////////////////////////////////////////////
543 /// Issue a prepare request for a list of files defined by 'paths', which must
544 /// be of one of the following types: TFileInfo, TUrl, TObjString.
545 /// On output, bufout, if defined, points to a buffer form that can be used
546 /// with GetPathsInfo.
547 /// Return the number of paths found or -1 if any error occured.
548 
550  UChar_t opt, UChar_t prio, TString *bufout)
551 {
552  if (!paths) {
553  Warning("Prepare", "input list is empty!");
554  return -1;
555  }
556 
557  Int_t npaths = 0;
558 
559  TXNetSystemConnectGuard cg(this, "");
560  if (cg.IsValid()) {
561 
562  TString *buf = (bufout) ? bufout : new TString();
563 
564  // Prepare the buffer
565  TObject *o = 0;
566  TUrl u;
567  TString path;
568  TIter nxt(paths);
569  while ((o = nxt())) {
570  // Extract the path name from the allowed object types
571  TString pn = TFileStager::GetPathName(o);
572  if (pn == "") {
573  Warning("Prepare", "object is of unexpected type %s - ignoring", o->ClassName());
574  continue;
575  }
576  u.SetUrl(pn);
577  // The path
578  path = u.GetFileAndOptions();
579  path.ReplaceAll("\n","\r");
580  npaths++;
581  *buf += Form("%s\n", path.Data());
582  }
583 
584  Info("Prepare","buffer ready: issuing prepare (opt=%d, prio=%d) ...",
585  opt, prio);
586  cg.ClientAdmin()->Prepare(buf->Data(), (kXR_char)opt, (kXR_char)prio);
587  cg.ClientAdmin()->GoBackToRedirector();
588  if (!bufout)
589  delete buf;
590  if (gDebug >0)
591  Info("Prepare", "Got Status %d",
592  cg.ClientAdmin()->LastServerResp()->status);
593  if (!(cg.ClientAdmin()->LastServerResp()->status)){
594  return npaths;
595  }
596  cg.NotifyLastError();
597  }
598 
599  // Done
600  return -1;
601 }
602 
603 ////////////////////////////////////////////////////////////////////////////////
604 /// Retrieve status of a '\n'-separated list of files in 'paths'.
605 /// The information is returned as one UChar_t per file in 'info';
606 /// 'info' must be allocated by the caller.
607 
608 Bool_t TXNetSystem::GetPathsInfo(const char *paths, UChar_t *info)
609 {
610  if (!paths) {
611  Warning("GetPathsInfo", "input list is empty!");
612  return kFALSE;
613  }
614 
615  TXNetSystemConnectGuard cg(this, "");
616  if (cg.IsValid()) {
617  cg.ClientAdmin()->SysStatX(paths, info);
618  cg.ClientAdmin()->GoBackToRedirector();
619  if (gDebug >0)
620  Info("GetPathsInfo", "Got Status %d",
621  cg.ClientAdmin()->LastServerResp()->status);
622  if (!(cg.ClientAdmin()->LastServerResp()->status)){
623  return kTRUE;
624  }
625  cg.NotifyLastError();
626  }
627 
628  // Done
629  return kFALSE;
630 }
631 
632 ////////////////////////////////////////////////////////////////////////////////
633 /// Returns TRUE if the url in 'path' points to the local file system.
634 /// This is used to avoid going through the NIC card for local operations.
635 
637 {
638  if (fIsXRootd) {
639  TXNetSystemConnectGuard cg(this, path);
640  if (cg.IsValid()) {
641  if (cg.ClientAdmin()->GetClientConn()->GetServerType() != kSTDataXrootd) {
642  // Not an end point data server: cannot assert locality
643  return kFALSE;
644  }
645  }
646  }
647  // Either an end-point data server or 'rootd': check for locality
648  return TSystem::IsPathLocal(path);
649 }
650 
651 ////////////////////////////////////////////////////////////////////////////////
652 /// Get end-point url of a file. Info is returned in eurl.
653 /// The function returns 0 in case of success and 1 if the file could
654 /// not be stat'ed.
655 
656 Int_t TXNetSystem::Locate(const char *path, TString &eurl)
657 {
658  if (fIsXRootd) {
659  TXNetSystemConnectGuard cg(this, path);
660  if (cg.IsValid()) {
661 
662  // Extract the directory name
663  XrdClientLocate_Info li;
664  TString edir = TUrl(path).GetFile();
665 
666  if (cg.ClientAdmin()->Locate((kXR_char *)edir.Data(), li)) {
667  TUrl u(path);
668  XrdClientUrlInfo ui((const char *)&li.Location[0]);
669  // We got the IP address but we need the FQDN: if we did not resolve
670  // it yet do it and cache the result
671  TNamed *hn = 0;
672  if (fgAddrFQDN.GetSize() <= 0 ||
673  !(hn = dynamic_cast<TNamed *>(fgAddrFQDN.FindObject(ui.Host.c_str())))) {
674  TInetAddress a(gSystem->GetHostByName(ui.Host.c_str()));
675  if (strlen(a.GetHostName()) > 0)
676  hn = new TNamed(ui.Host.c_str(), a.GetHostName());
677  else
678  hn = new TNamed(ui.Host.c_str(), ui.Host.c_str());
679  fgAddrFQDN.Add(hn);
680  if (gDebug > 0)
681  Info("Locate","caching host name: %s", hn->GetTitle());
682  }
683  if (hn)
684  u.SetHost(hn->GetTitle());
685  else
686  u.SetHost(ui.Host.c_str());
687  u.SetPort(ui.Port);
688  eurl = u.GetUrl();
689  return 0;
690  }
691  cg.NotifyLastError();
692  }
693  return 1;
694  }
695 
696  // Not implemented
697  if (gDebug > 0) Info("Locate", "server not Xrootd: method not implemented!");
698  return -1;
699 }
700 
701 ////////////////////////////////////////////////////////////////////////////////
702 /// Checks if an admin for 'url' exists already.
703 /// Avoid duplications.
704 
705 XrdClientAdmin *TXNetSystem::GetClientAdmin(const char *url)
706 {
707  XrdClientAdmin *ca = 0;
708 
709  // ID key
710  TString key = TXNetSystem::GetKey(url);
711 
712  // If we have one for 'key', just use it
713  TXrdClientAdminWrapper *caw = 0;
714  if (fgAdminHash.GetSize() > 0 &&
715  (caw = dynamic_cast<TXrdClientAdminWrapper *>(fgAdminHash.FindObject(key.Data()))))
716  return caw->fXCA;
717 
718  // Create one and save the reference in the hash table
719  ca = new XrdClientAdmin(url);
720  fgAdminHash.Add(new TXrdClientAdminWrapper(key, ca));
721 
722  // Done
723  return ca;
724 }
725 
726 ////////////////////////////////////////////////////////////////////////////////
727 /// Build from uu a unique ID key used in hash tables
728 
729 TString TXNetSystem::GetKey(const char *url)
730 {
731  TUrl u(url);
732  TString key(u.GetUser());
733  if (!key.IsNull())
734  key += "@";
735  key += u.GetHost();
736  if (u.GetPort() > 0) {
737  key += ":";
738  key += u.GetPort();
739  }
740 
741  // Done
742  return key;
743 }
744 
745 //
746 // Wrapper class
747 //
748 ////////////////////////////////////////////////////////////////////////////////
749 /// Destructor: destroy the instance
750 
752 {
753  SafeDelete(fXCA);
754 }
755 
756 //
757 // Guard methods
758 //
759 ////////////////////////////////////////////////////////////////////////////////
760 /// Construct a guard object
761 
763  : fClientAdmin(0)
764 {
765  if (xn)
766  // Connect
767  fClientAdmin = (url && strlen(url) > 0) ? xn->Connect(url)
768  : xn->Connect(xn->fUrl);
769 }
770 
771 ////////////////////////////////////////////////////////////////////////////////
772 /// Destructor: close the connection
773 
775 {
776  fClientAdmin = 0;
777 }
778 
779 ////////////////////////////////////////////////////////////////////////////////
780 /// Print message about last occured error
781 
783 {
784  if (fClientAdmin)
785  if (fClientAdmin->GetClientConn())
786  Printf("Srv err: %s", fClientAdmin->GetClientConn()->LastServerError.errmsg);
787 }
const char * GetDirEntry(void *dirp=0)
Get directory entry via rootd. Returns 0 in case no more entries.
Definition: TNetFile.cxx:1057
TSystem * ROOT_Plugin_TXNetSystem(const char *url, Bool_t owner)
PluginManager creation function.
Definition: TXNetSystem.cxx:51
Bool_t AccessPathName(const char *path, EAccessMode mode)
Returns FALSE if one can access a file using the specified access mode.
Definition: TNetFile.cxx:1105
void NotifyLastError()
Print message about last occured error.
void SetRemoteProtocol(Int_t rproto)
Definition: TSocket.h:170
TString fUrl
Definition: TXNetSystem.h:60
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
void SetPort(Int_t port)
Definition: TUrl.h:91
static TString GetPathName(TObject *o)
Return the path name contained in object &#39;o&#39; allowing for TUrl, TObjString or TFileInfo.
virtual Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in &#39;path&#39; points to the local file system.
Definition: TSystem.cxx:1285
long long Long64_t
Definition: RtypesCore.h:69
virtual int Unlink(const char *path)
Unlink &#39;path&#39; on the remote server system.
void SetProtocol(const char *proto, Bool_t setDefaultPort=kFALSE)
Set protocol and, optionally, change the port accordingly.
Definition: TUrl.cxx:520
Bool_t IsOnline(const char *path)
Check if the file defined by &#39;path&#39; is ready to be used.
const char * GetHostName() const
Definition: TInetAddress.h:71
virtual Int_t SetOption(ESockOptions opt, Int_t val)
Set socket options.
Definition: TSocket.cxx:1017
This class represents a WWW compatible URL.
Definition: TUrl.h:35
Int_t fUid
Definition: TSystem.h:129
virtual Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in &#39;path&#39; points to the local file system.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
void SetUrl(const char *url, Bool_t defaultIsFile=kFALSE)
Parse url character string and split in its different subcomponents.
Definition: TUrl.cxx:110
This class represents an Internet Protocol (IP) address.
Definition: TInetAddress.h:36
Bool_t AccessPathName(const char *path, EAccessMode mode)
Returns FALSE if one can access a file using the specified access mode.
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Definition: TUrl.cxx:501
VecStringVP_t fDirList
Definition: TXNetSystem.h:58
#define gROOT
Definition: TROOT.h:402
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:57
static Int_t GetRootdProtocol(TSocket *s)
Find out the remote rootd protocol version.
Definition: TXNetFile.cxx:421
Long_t fMtime
Definition: TSystem.h:132
void Create(const char *url, TSocket *sock=0)
Create a TNetSystem object.
Definition: TNetFile.cxx:874
static TString GetKey(const char *url)
Build from uu a unique ID key used in hash tables.
static THashList fgAdminHash
Definition: TXNetSystem.h:70
#define NAME_DEBUG
#define NAME_FIRSTCONNECTMAXCNT
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:262
Long64_t fSize
Definition: TSystem.h:131
Int_t GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
Definition: TNetFile.cxx:1081
static THashList fgAddrFQDN
Definition: TXNetSystem.h:69
TXNetSystem(Bool_t owner=kTRUE)
Create system management class without connecting to server.
Definition: TXNetSystem.cxx:68
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:387
XrdClientVector< XrdOucString > VecString_t
Definition: TXNetSystem.cxx:63
void SetServType(Int_t st)
Definition: TSocket.h:173
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=0)
Set the value of a resource or create a new resource.
Definition: TEnv.cxx:736
Int_t fMode
Definition: TSystem.h:128
#define EnvGetLong(x)
Definition: XrdClientEnv.hh:44
const char * GetFile() const
Definition: TUrl.h:72
TXNetSystemConnectGuard(TXNetSystem *xn, const char *url)
Construct a guard object.
const char * GetHost() const
Definition: TUrl.h:70
#define SafeDelete(p)
Definition: RConfig.h:509
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:34
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual Bool_t ConsistentWith(const char *path, void *dirptr)
Check consistency of this helper with the one required by &#39;path&#39; or &#39;dirptr&#39;.
void * fDirp
Definition: TXNetSystem.h:57
static XrdClientAdmin * GetClientAdmin(const char *url)
Checks if an admin for &#39;url&#39; exists already.
TString fUrl
Definition: TSystem.h:134
#define EnvPutInt(name, val)
Definition: XrdClientEnv.hh:47
virtual ~TXrdClientAdminWrapper()
Destructor: destroy the instance.
virtual Int_t Locate(const char *path, TString &endurl)
Get end-point url of a file.
XFontStruct * id
Definition: TGX11.cxx:108
static void SetEnv()
Set the relevant environment variables.
Definition: TXNetFile.cxx:1201
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
Definition: TSystem.cxx:2320
XrdClientAdmin * fXCA
Definition: TXNetSystem.h:46
Int_t fGid
Definition: TSystem.h:130
TString fDirEntry
Definition: TXNetSystem.h:59
XrdClientAdmin * Connect(const char *url)
Init a connection to the server.
const char * GetUser() const
Definition: TUrl.h:68
Bool_t fIsXRootd
Definition: TXNetSystem.h:55
Bool_t GetPathsInfo(const char *paths, UChar_t *info)
Retrieve status of a &#39; &#39;-separated list of files in &#39;paths&#39;.
~TXNetSystemConnectGuard()
Destructor: close the connection.
Bool_t fIsLink
Definition: TSystem.h:133
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
auto * a
Definition: textangle.C:12
static void FormUrl(TUrl uut, TString &uu)
Form url for rootd socket.
Definition: TXNetFile.cxx:170
virtual const char * GetDirEntry(void *dirp)
Get directory entry for directory referenced by dirp.
Collection abstract base class.
Definition: TCollection.h:63
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
char * Form(const char *fmt,...)
static Bool_t fgRootdBC
Definition: TXNetSystem.h:63
void * OpenDirectory(const char *name)
Open a directory via rfiod.
Definition: TNetFile.cxx:998
Int_t MakeDirectory(const char *name)
Make a directory via rootd.
Definition: TNetFile.cxx:976
Bool_t fIsRootd
Definition: TXNetSystem.h:54
#define Printf
Definition: TGeoToOCC.h:18
virtual void * OpenDirectory(const char *dir)
Open a directory.
XrdClientAdmin * fClientAdmin
Definition: TXNetSystem.h:106
const Bool_t kFALSE
Definition: RtypesCore.h:88
Bool_t Prepare(const char *path, UChar_t opt=8, UChar_t prio=0)
Issue a prepare request for file defined by &#39;path&#39;.
void SetHost(const char *host)
Definition: TUrl.h:87
long Long_t
Definition: RtypesCore.h:50
#define ClassImp(name)
Definition: Rtypes.h:359
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
TNamed()
Definition: TNamed.h:36
void InitXrdClient()
One-time initialization of some communication variables for xrootd protocol.
static RooMathCoreReg dummy
static constexpr double s
#define R__LOCKGUARD(mutex)
EAccessMode
Definition: TSystem.h:44
Int_t GetPort() const
Definition: TUrl.h:81
Mother of all ROOT objects.
Definition: TObject.h:37
Bool_t ConsistentWith(const char *path, void *dirptr)
Check consistency of this helper with the one required by &#39;path&#39; or &#39;dirptr&#39;.
Definition: TNetFile.cxx:1127
virtual void FreeDirectory(void *dirp)
Free(Close) the directory referenced by dirp.
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual Int_t MakeDirectory(const char *dir)
Create a directory. Return 0 on success, -1 otherwise.
static Bool_t fgInitDone
Definition: TXNetSystem.h:62
Long_t fIno
Definition: TSystem.h:127
R__EXTERN Int_t gDebug
Definition: Rtypes.h:86
virtual Int_t GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
void SetUrl(const char *url)
Definition: TSocket.h:174
TString fDir
Definition: TXNetSystem.h:56
unsigned char UChar_t
Definition: RtypesCore.h:34
void SetService(const char *service)
Definition: TSocket.h:172
Long_t fDev
Definition: TSystem.h:126
virtual Int_t GetSize() const
Definition: TCollection.h:180
Abstract base class defining a generic interface to the underlying Operating System.
Definition: TSystem.h:248
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
const Bool_t kTRUE
Definition: RtypesCore.h:87
void InitRemoteEntity(const char *url)
Parse and save coordinates of the remote entity (user, host, port, ...)
Definition: TNetFile.cxx:850
XrdClientAdmin * ClientAdmin() const
Definition: TXNetSystem.h:114
void FreeDirectory(void *dirp=0)
Free directory via rootd.
Definition: TNetFile.cxx:1032
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:866
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
Bool_t R_ISOFF(Int_t mode)
Definition: TSystem.h:123