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