Logo ROOT   6.07/09
Reference Guide
TDavixFile.cxx
Go to the documentation of this file.
1 // @(#)root/net:$Id$
2 // Author: Adrien Devresse and Tigran Mkrtchyan
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2013, 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 // TDavixFile //
15 // //
16 // A TDavixFile is like a normal TFile except that it uses //
17 // libdavix to read/write remote files. //
18 // It supports HTTP and HTTPS in a number of dialects and options //
19 // e.g. S3 is one of them //
20 // Other caracteristics come from the full support of Davix, //
21 // e.g. full redirection support in any circumstance //
22 // //
23 // Authors: Adrien Devresse (CERN IT/SDC) //
24 // Tigran Mkrtchyan (DESY) //
25 // //
26 // Checks and ROOT5 porting: //
27 // Fabrizio Furano (CERN IT/SDC) //
28 // //
29 // September 2013 //
30 // //
31 //////////////////////////////////////////////////////////////////////////
32 
33 
34 #include "TDavixFile.h"
35 #include "TROOT.h"
36 #include "TSocket.h"
37 #include "Bytes.h"
38 #include "TError.h"
39 #include "TSystem.h"
40 #include "TEnv.h"
41 #include "TBase64.h"
42 #include "TVirtualPerfStats.h"
43 #include "TDavixFileInternal.h"
44 #include "TSocket.h"
45 
46 #include <errno.h>
47 #include <stdlib.h>
48 #include <unistd.h>
49 #include <fcntl.h>
50 #include <davix.hpp>
51 #include <sstream>
52 #include <string>
53 #include <cstring>
54 
55 
56 static const std::string VERSION = "0.2.0";
57 
58 static const std::string gUserAgent = "ROOT/" + std::string(gROOT->GetVersion()) +
59 " TDavixFile/" + VERSION + " davix/" + Davix::version();
60 
61 // The prefix that is used to find the variables in the gEnv
62 #define ENVPFX "Davix."
63 
65 
66 using namespace Davix;
67 
68 const char* grid_mode_opt = "grid_mode=yes";
69 const char* ca_check_opt = "ca_check=no";
70 const char* s3_seckey_opt = "s3seckey=";
71 const char* s3_acckey_opt = "s3acckey=";
72 const char* s3_region_opt = "s3region=";
73 const char* s3_token_opt = "s3token=";
74 const char* open_mode_read = "READ";
75 const char* open_mode_create = "CREATE";
76 const char* open_mode_new = "NEW";
77 const char* open_mode_update = "UPDATE";
78 
81 
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 
85 bool isno(const char *str)
86 {
87  if (!str) return false;
88 
89  if (!strcmp(str, "n") || !strcmp(str, "no") || !strcmp(str, "0") || !strcmp(str, "false")) return true;
90 
91  return false;
92 
93 }
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 
97 int configure_open_flag(const std::string &str, int old_flag)
98 {
99  if (strcasecmp(str.c_str(), open_mode_read) == 0)
100  old_flag |= O_RDONLY;
101  if ((strcasecmp(str.c_str(), open_mode_create) == 0)
102  || (strcasecmp(str.c_str(), open_mode_new) == 0)) {
103  old_flag |= (O_CREAT | O_WRONLY | O_TRUNC);
104  }
105  if ((strcasecmp(str.c_str(), open_mode_update) == 0)) {
106  old_flag |= (O_RDWR);
107  }
108  return old_flag;
109 }
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 
114 {
115  Int_t log_level = (gEnv) ? gEnv->GetValue("Davix.Debug", 0) : 0;
116 
117  switch (log_level) {
118  case 0:
119  davix_set_log_level(0);
120  break;
121  case 1:
122  davix_set_log_level(DAVIX_LOG_WARNING);
123  break;
124  case 2:
125  davix_set_log_level(DAVIX_LOG_VERBOSE);
126  break;
127  case 3:
128  davix_set_log_level(DAVIX_LOG_DEBUG);
129  break;
130  default:
131  davix_set_log_level(DAVIX_LOG_ALL);
132  break;
133  }
134 }
135 
136 ///////////////////////////////////////////////////////////////////
137 // Authn implementation, Locate and get VOMS cred if exist
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 
141 static void TDavixFile_http_get_ucert(std::string &ucert, std::string &ukey)
142 {
143  char default_proxy[64];
144  const char *genvvar = 0, *genvvar1 = 0;
145  // The gEnv has higher priority, let's look for a proxy cert
146  genvvar = gEnv->GetValue("Davix.GSI.UserProxy", (const char *) NULL);
147  if (genvvar) {
148  ucert = ukey = genvvar;
149  if (gDebug > 0)
150  Info("TDavixFile_http_get_ucert", "Found proxy in gEnv");
151  return;
152  }
153 
154  // Try explicit environment for proxy
155  if (getenv("X509_USER_PROXY")) {
156  if (gDebug > 0)
157  Info("TDavixFile_http_get_ucert", "Found proxy in X509_USER_PROXY");
158  ucert = ukey = getenv("X509_USER_PROXY");
159  return;
160  }
161 
162  // Try with default location
163  snprintf(default_proxy, sizeof(default_proxy), "/tmp/x509up_u%d",
164  geteuid());
165 
166  if (access(default_proxy, R_OK) == 0) {
167  if (gDebug > 0)
168  Info("TDavixFile_http_get_ucert", "Found proxy in /tmp");
169  ucert = ukey = default_proxy;
170  return;
171  }
172 
173  // It seems we got no proxy, let's try to gather the keys
174  genvvar = gEnv->GetValue("Davix.GSI.UserCert", (const char *) NULL);
175  genvvar1 = gEnv->GetValue("Davix.GSI.UserKey", (const char *) NULL);
176  if (genvvar || genvvar1) {
177  if (gDebug > 0)
178  Info("TDavixFile_http_get_ucert", "Found cert and key in gEnv");
179 
180  ucert = genvvar;
181  ukey = genvvar1;
182  return;
183  }
184 
185  // try with X509_* environment
186  if (getenv("X509_USER_CERT"))
187  ucert = getenv("X509_USER_CERT");
188  if (getenv("X509_USER_KEY"))
189  ukey = getenv("X509_USER_KEY");
190 
191  if ((ucert.size() > 0) || (ukey.size() > 0)) {
192  if (gDebug > 0)
193  Info("TDavixFile_http_get_ucert", "Found cert and key in gEnv");
194  }
195  return;
196 
197 }
198 
199 ////////////////////////////////////////////////////////////////////////////////
200 
201 static int TDavixFile_http_authn_cert_X509(void *userdata, const Davix::SessionInfo &info,
202  Davix::X509Credential *cert, Davix::DavixError **err)
203 {
204  (void) userdata; // keep quiete compilation warnings
205  (void) info;
206  std::string ucert, ukey;
207  TDavixFile_http_get_ucert(ucert, ukey);
208 
209  if (ucert.empty() || ukey.empty()) {
210  Davix::DavixError::setupError(err, "TDavixFile",
211  Davix::StatusCode::AuthentificationError,
212  "Could not set the user's proxy or certificate");
213  return -1;
214  }
215  return cert->loadFromFilePEM(ukey, ucert, "", err);
216 }
217 /////////////////////////////////////////////////////////////////////////////////////////////
218 
219 ////////////////////////////////////////////////////////////////////////////////
220 
222 {
223  delete davixPosix;
224  delete davixParam;
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 
230 {
231  if (davix_context_s == NULL) {
232  TLockGuard guard(&createLock);
233  if (davix_context_s == NULL) {
234  davix_context_s = new Context();
235  }
236  }
237  return davix_context_s;
238 }
239 
240 ////////////////////////////////////////////////////////////////////////////////
241 
243 {
244  DavixError *davixErr = NULL;
245  Davix_fd *fd = davixPosix->open(davixParam, fUrl.GetUrl(), oflags, &davixErr);
246  if (fd == NULL) {
247  Error("DavixOpen", "can not open file with davix: %s (%d)",
248  davixErr->getErrMsg().c_str(), davixErr->getStatus());
249  DavixError::clearError(&davixErr);
250  } else {
251  // setup ROOT style read
252  davixPosix->fadvise(fd, 0, 300, Davix::AdviseRandom);
253  }
254 
255  return fd;
256 }
257 
258 ////////////////////////////////////////////////////////////////////////////////
259 
261 {
262  DavixError *davixErr = NULL;
263  if (davixFd != NULL && davixPosix->close(davixFd, &davixErr)) {
264  Error("DavixClose", "can not to close file with davix: %s (%d)",
265  davixErr->getErrMsg().c_str(), davixErr->getStatus());
266  DavixError::clearError(&davixErr);
267  }
268 }
269 
270 ////////////////////////////////////////////////////////////////////////////////
271 
273 {
274  const char *env_var = NULL;
275 
276  if (gDebug > 1)
277  Info("enableGridMode", " grid mode enabled !");
278 
279  if( ( env_var = getenv("X509_CERT_DIR")) == NULL){
280  env_var= "/etc/grid-security/certificates/";
281  }
282  davixParam->addCertificateAuthorityPath(env_var);
283  if (gDebug > 0)
284  Info("enableGridMode", "Adding CAdir %s", env_var);
285 }
286 
287 ////////////////////////////////////////////////////////////////////////////////
288 
289 void TDavixFileInternal::setS3Auth(const std::string &secret, const std::string &access,
290  const std::string &region, const std::string &token)
291 {
292  if (gDebug > 1) {
293  Info("setS3Auth", " Aws S3 tokens configured");
294  if (!region.empty()) Info("setS3Auth", " Aws region configured - using v4 signatures");
295  if (!token.empty()) Info("setS3Auth", " Aws STS token was provided");
296  }
297  davixParam->setAwsAuthorizationKeys(secret, access);
298  davixParam->setProtocol(RequestProtocol::AwsS3);
299 
300  davixParam->setAwsRegion(region);
301  davixParam->setAwsToken(token);
302 }
303 
304 ////////////////////////////////////////////////////////////////////////////////
305 
307 {
308  const char *env_var = NULL, *env_var2 = NULL;
309  // default opts
310  davixParam->setTransparentRedirectionSupport(true);
311  davixParam->setClientCertCallbackX509(&TDavixFile_http_authn_cert_X509, NULL);
312 
313  // setup CADIR
314  env_var = gEnv->GetValue("Davix.GSI.CAdir", (const char *) NULL);
315  if (env_var) {
316  davixParam->addCertificateAuthorityPath(env_var);
317  if (gDebug > 0)
318  Info("parseConfig", "Add CAdir: %s", env_var);
319  }
320  // CA Check
321  bool ca_check_local = !isno(gEnv->GetValue("Davix.GSI.CACheck", (const char *)"y"));
322  davixParam->setSSLCAcheck(ca_check_local);
323  if (gDebug > 0)
324  Info("parseConfig", "Setting CAcheck to %s", ((ca_check_local) ? ("true") : ("false")));
325 
326  // S3 Auth
327  if (((env_var = gEnv->GetValue("Davix.S3.SecretKey", getenv("S3_SECRET_KEY"))) != NULL)
328  && ((env_var2 = gEnv->GetValue("Davix.S3.AccessKey", getenv("S3_ACCESS_KEY"))) != NULL)) {
329  Info("parseConfig", "Setting S3 SecretKey and AccessKey. Access Key : %s ", env_var2);
330  davixParam->setAwsAuthorizationKeys(env_var, env_var2);
331 
332  // need to set region?
333  if ( (env_var = gEnv->GetValue("Davix.S3.Region", getenv("S3_REGION"))) != NULL) {
334  Info("parseConfig", "Setting S3 Region to '%s' - v4 signature will be used", env_var);
335  davixParam->setAwsRegion(env_var);
336  }
337  // need to set STS token?
338  if( (env_var = gEnv->GetValue("Davix.S3.Token", getenv("S3_TOKEN"))) != NULL) {
339  Info("parseConfig", "Setting S3 STS temporary credentials");
340  davixParam->setAwsToken(env_var);
341  }
342  }
343 
344  env_var = gEnv->GetValue("Davix.GSI.GridMode", (const char *)"y");
345  if (!isno(env_var))
346  enableGridMode();
347 }
348 
349 ////////////////////////////////////////////////////////////////////////////////
350 /// intput params
351 
353 {
354  std::stringstream ss(option);
355  std::string item;
356  std::vector<std::string> parsed_options;
357  // parameters
358  std::string s3seckey, s3acckey, s3region, s3token;
359 
360  while (std::getline(ss, item, ' ')) {
361  parsed_options.push_back(item);
362  }
363 
364  for (std::vector<std::string>::iterator it = parsed_options.begin(); it < parsed_options.end(); ++it) {
365  // grid mode option
366  if ((strcasecmp(it->c_str(), grid_mode_opt)) == 0) {
367  enableGridMode();
368  }
369  // ca check option
370  if ((strcasecmp(it->c_str(), ca_check_opt)) == 0) {
371  davixParam->setSSLCAcheck(false);
372  }
373  // s3 sec key
374  if (strncasecmp(it->c_str(), s3_seckey_opt, strlen(s3_seckey_opt)) == 0) {
375  s3seckey = std::string(it->c_str() + strlen(s3_seckey_opt));
376  }
377  // s3 access key
378  if (strncasecmp(it->c_str(), s3_acckey_opt, strlen(s3_acckey_opt)) == 0) {
379  s3acckey = std::string(it->c_str() + strlen(s3_acckey_opt));
380  }
381  // s3 region
382  if (strncasecmp(it->c_str(), s3_region_opt, strlen(s3_region_opt)) == 0) {
383  s3region = std::string(it->c_str() + strlen(s3_region_opt));
384  }
385  // s3 sts token
386  if (strncasecmp(it->c_str(), s3_token_opt, strlen(s3_token_opt)) == 0) {
387  s3token = std::string(it->c_str() + strlen(s3_token_opt));
388  }
389  // open mods
390  oflags = configure_open_flag(*it, oflags);
391  }
392 
393  if (s3seckey.size() > 0) {
394  setS3Auth(s3seckey, s3acckey, s3region, s3token);
395  }
396 
397  if (oflags == 0) // default open mode
398  oflags = O_RDONLY;
399 }
400 
401 ////////////////////////////////////////////////////////////////////////////////
402 
404 {
405  davixPosix = new DavPosix(davixContext);
406  davixParam = new RequestParams();
407  davixParam->setUserAgent(gUserAgent);
409  parseConfig();
410  parseParams(opt);
411 }
412 
413 ////////////////////////////////////////////////////////////////////////////////
414 
415 Int_t TDavixFileInternal::DavixStat(const char *url, struct stat *st)
416 {
417  DavixError *davixErr = NULL;
418 
419  if (davixPosix->stat(davixParam, url, st, &davixErr) < 0) {
420 
421  Error("DavixStat", "can not stat the file with davix: %s (%d)",
422  davixErr->getErrMsg().c_str(), davixErr->getStatus());
423  DavixError::clearError(&davixErr);
424  return 0;
425  }
426  return 1;
427 }
428 
429 /////////////////////////////////////////////////////////////////////////////////////////////
430 
431 ////////////////////////////////////////////////////////////////////////////////
432 
433 TDavixFile::TDavixFile(const char *url, Option_t *opt, const char *ftitle, Int_t compress) : TFile(url, "WEB"),
434  d_ptr(new TDavixFileInternal(fUrl, opt))
435 {
436  (void) ftitle;
437  (void) compress;
438  Init(kFALSE);
439 }
440 
441 ////////////////////////////////////////////////////////////////////////////////
442 
444 {
445  d_ptr->Close();
446  delete d_ptr;
447 }
448 
449 ////////////////////////////////////////////////////////////////////////////////
450 
452 {
453  (void) init;
454  //initialize davix
455  d_ptr->init();
456  // pre-open file
457  if ((d_ptr->getDavixFileInstance()) == NULL){
458  MakeZombie();
459  gDirectory = gROOT;
460  return;
461  }
463  fOffset = 0;
464  fD = -2; // so TFile::IsOpen() will return true when in TFile::~TFi */
465 }
466 
467 ////////////////////////////////////////////////////////////////////////////////
468 /// Set position from where to start reading.
469 
471 {
472  TLockGuard guard(&(d_ptr->positionLock));
473  switch (pos) {
474  case kBeg:
475  fOffset = offset + fArchiveOffset;
476  break;
477  case kCur:
478  fOffset += offset;
479  break;
480  case kEnd:
481  // this option is not used currently in the ROOT code
482  if (fArchiveOffset)
483  Error("Seek", "seeking from end in archive is not (yet) supported");
484  fOffset = fEND - offset; // is fEND really EOF or logical EOF?
485  break;
486  }
487 
488  if (gDebug > 1)
489  Info("Seek", " move cursor to %lld"
490  , fOffset);
491 }
492 
493 ////////////////////////////////////////////////////////////////////////////////
494 /// Read specified byte range from remote file via HTTP.
495 /// Returns kTRUE in case of error.
496 
498 {
499  TLockGuard guard(&(d_ptr->positionLock));
500  Davix_fd *fd;
501  if ((fd = d_ptr->getDavixFileInstance()) == NULL)
502  return kTRUE;
503  Long64_t ret = DavixReadBuffer(fd, buf, len);
504  if (ret < 0)
505  return kTRUE;
506 
507  if (gDebug > 1)
508  Info("ReadBuffer", "%lld bytes of data read sequentially"
509  " (%d requested)", ret, len);
510 
511  return kFALSE;
512 }
513 
514 ////////////////////////////////////////////////////////////////////////////////
515 
517 {
518  Davix_fd *fd;
519  if ((fd = d_ptr->getDavixFileInstance()) == NULL)
520  return kTRUE;
521 
522  Long64_t ret = DavixPReadBuffer(fd, buf, pos, len);
523  if (ret < 0)
524  return kTRUE;
525 
526  if (gDebug > 1)
527  Info("ReadBuffer", "%lld bytes of data read from offset"
528  " %lld (%d requested)", ret, pos, len);
529  return kFALSE;
530 }
531 
532 ////////////////////////////////////////////////////////////////////////////////
533 
535 {
536  Davix_fd *fd;
537  if ((fd = d_ptr->getDavixFileInstance()) == NULL)
538  return kFALSE;
539 
540  d_ptr->davixPosix->fadvise(fd, static_cast<dav_off_t>(offs), static_cast<dav_size_t>(len), Davix::AdviseRandom);
541 
542  if (gDebug > 1)
543  Info("ReadBufferAsync", "%d bytes of data prefected from offset"
544  " %lld ", len, offs);
545  return kFALSE;
546 }
547 
548 ////////////////////////////////////////////////////////////////////////////////
549 
550 Bool_t TDavixFile::ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
551 {
552  Davix_fd *fd;
553  if ((fd = d_ptr->getDavixFileInstance()) == NULL)
554  return kTRUE;
555 
556  Long64_t ret = DavixReadBuffers(fd, buf, pos, len, nbuf);
557  if (ret < 0)
558  return kTRUE;
559 
560  if (gDebug > 1)
561  Info("ReadBuffers", "%lld bytes of data read from a list of %d buffers",
562  ret, nbuf);
563 
564  return kFALSE;
565 }
566 
567 ////////////////////////////////////////////////////////////////////////////////
568 
569 Bool_t TDavixFile::WriteBuffer(const char *buf, Int_t len)
570 {
571  Davix_fd *fd;
572  if ((fd = d_ptr->getDavixFileInstance()) == NULL)
573  return kTRUE;
574 
575  Long64_t ret = DavixWriteBuffer(fd, buf, len);
576  if (ret < 0)
577  return kTRUE;
578 
579  if (gDebug > 1)
580  Info("WriteBuffer", "%lld bytes of data write"
581  " %d requested", ret, len);
582  return kFALSE;
583 }
584 
585 ////////////////////////////////////////////////////////////////////////////////
586 
588 {
589  d_ptr->davixParam->setSSLCAcheck((bool)check);
590 }
591 
592 ////////////////////////////////////////////////////////////////////////////////
593 
595 {
597 }
598 
599 ////////////////////////////////////////////////////////////////////////////////
600 
602 {
603  TLockGuard l(&(openLock));
604  std::vector<void *>::iterator f = std::find(dirdVec.begin(), dirdVec.end(), fd);
605  return (f != dirdVec.end());
606 }
607 
608 ////////////////////////////////////////////////////////////////////////////////
609 
611 {
612  TLockGuard l(&(openLock));
613  dirdVec.push_back(fd);
614 }
615 
616 ////////////////////////////////////////////////////////////////////////////////
617 
619 {
620  TLockGuard l(&(openLock));
621  std::vector<void *>::iterator f = std::find(dirdVec.begin(), dirdVec.end(), fd);
622  if (f != dirdVec.end())
623  dirdVec.erase(f);
624 }
625 
626 ////////////////////////////////////////////////////////////////////////////////
627 
629 {
630  struct stat st;
631  Int_t ret = d_ptr->DavixStat(fUrl.GetUrl(), &st);
632  if (ret) {
633  if (gDebug > 1)
634  Info("GetSize", "file size requested: %lld", (Long64_t)st.st_size);
635  return st.st_size;
636  }
637  return -1;
638 }
639 
640 ////////////////////////////////////////////////////////////////////////////////
641 
643 {
644  if (gPerfStats)
645  return TTimeStamp();
646  return 0;
647 }
648 
649 ////////////////////////////////////////////////////////////////////////////////
650 /// set TFile state info
651 
653 {
654  fBytesRead += len;
655  fReadCalls += 1;
656 
657  if (gPerfStats)
658  gPerfStats->FileReadEvent(this, (Int_t) len, t_start);
659 }
660 
661 ////////////////////////////////////////////////////////////////////////////////
662 
663 Long64_t TDavixFile::DavixReadBuffer(Davix_fd *fd, char *buf, Int_t len)
664 {
665  DavixError *davixErr = NULL;
666  Double_t start_time = eventStart();
667 
668  Long64_t ret = d_ptr->davixPosix->pread(fd, buf, len, fOffset, &davixErr);
669  if (ret < 0) {
670  Error("DavixReadBuffer", "can not read data with davix: %s (%d)",
671  davixErr->getErrMsg().c_str(), davixErr->getStatus());
672  DavixError::clearError(&davixErr);
673  } else {
674  fOffset += ret;
675  eventStop(start_time, ret);
676  }
677 
678  return ret;
679 }
680 
681 ////////////////////////////////////////////////////////////////////////////////
682 
683 Long64_t TDavixFile::DavixWriteBuffer(Davix_fd *fd, const char *buf, Int_t len)
684 {
685  DavixError *davixErr = NULL;
686  Double_t start_time = eventStart();
687 
688  Long64_t ret = d_ptr->davixPosix->pwrite(fd, buf, len, fOffset, &davixErr);
689  if (ret < 0) {
690  Error("DavixWriteBuffer", "can not write data with davix: %s (%d)",
691  davixErr->getErrMsg().c_str(), davixErr->getStatus());
692  DavixError::clearError(&davixErr);
693  } else {
694  fOffset += ret;
695  eventStop(start_time, ret);
696  }
697 
698  return ret;
699 }
700 
701 ////////////////////////////////////////////////////////////////////////////////
702 
703 Long64_t TDavixFile::DavixPReadBuffer(Davix_fd *fd, char *buf, Long64_t pos, Int_t len)
704 {
705  DavixError *davixErr = NULL;
706  Double_t start_time = eventStart();
707 
708  Long64_t ret = d_ptr->davixPosix->pread(fd, buf, len, pos, &davixErr);
709  if (ret < 0) {
710  Error("DavixPReadBuffer", "can not read data with davix: %s (%d)",
711  davixErr->getErrMsg().c_str(), davixErr->getStatus());
712  DavixError::clearError(&davixErr);
713  } else {
714  eventStop(start_time, ret);
715  }
716 
717 
718  return ret;
719 }
720 
721 ////////////////////////////////////////////////////////////////////////////////
722 
723 Long64_t TDavixFile::DavixReadBuffers(Davix_fd *fd, char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
724 {
725  DavixError *davixErr = NULL;
726  Double_t start_time = eventStart();
727  DavIOVecInput in[nbuf];
728  DavIOVecOuput out[nbuf];
729 
730  int lastPos = 0;
731  for (Int_t i = 0; i < nbuf; ++i) {
732  in[i].diov_buffer = &buf[lastPos];
733  in[i].diov_offset = pos[i];
734  in[i].diov_size = len[i];
735  lastPos += len[i];
736  }
737 
738  Long64_t ret = d_ptr->davixPosix->preadVec(fd, in, out, nbuf, &davixErr);
739  if (ret < 0) {
740  Error("DavixReadBuffers", "can not read data with davix: %s (%d)",
741  davixErr->getErrMsg().c_str(), davixErr->getStatus());
742  DavixError::clearError(&davixErr);
743  } else {
744  eventStop(start_time, ret);
745  }
746 
747  return ret;
748 }
749 
static void ConfigureDavixLogLevel()
Definition: TDavixFile.cxx:113
Definition: TMutex.h:34
static const std::string gUserAgent
Definition: TDavixFile.cxx:58
const char * s3_seckey_opt
Definition: TDavixFile.cxx:70
long long Long64_t
Definition: RtypesCore.h:69
const char * open_mode_read
Definition: TDavixFile.cxx:74
const char * open_mode_update
Definition: TDavixFile.cxx:77
void Init(Bool_t init)
Initialize a TFile object.
Definition: TDavixFile.cxx:451
const char Option_t
Definition: RtypesCore.h:62
static void TDavixFile_http_get_ucert(std::string &ucert, std::string &ukey)
Definition: TDavixFile.cxx:141
void setS3Auth(const std::string &secret, const std::string &access, const std::string &region, const std::string &token)
Definition: TDavixFile.cxx:289
Davix::RequestParams * davixParam
Small helper to keep current directory context.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:899
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
Davix_fd * Open()
Definition: TDavixFile.cxx:242
virtual Bool_t ReadBuffer(char *buf, Int_t len)
Read specified byte range from remote file via HTTP.
Definition: TDavixFile.cxx:497
#define gROOT
Definition: TROOT.h:364
void addDird(void *fd)
Definition: TDavixFile.cxx:610
Double_t eventStart()
Definition: TDavixFile.cxx:642
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TDavixFileInternal * d_ptr
Definition: TDavixFile.h:68
const Bool_t kFALSE
Definition: Rtypes.h:92
Long64_t DavixReadBuffer(Davix_fd *fd, char *buf, Int_t len)
Definition: TDavixFile.cxx:663
ERelativeTo
Definition: TFile.h:169
Int_t fReadCalls
Number of read calls ( not counting the cache calls )
Definition: TFile.h:81
virtual Bool_t WriteBuffer(const char *buffer, Int_t bufferLength)
Write a buffer to the file.
Definition: TDavixFile.cxx:569
void eventStop(Double_t t, Long64_t len)
set TFile state info
Definition: TDavixFile.cxx:652
Davix_fd * getDavixFileInstance()
const char * open_mode_create
Definition: TDavixFile.cxx:75
Long64_t DavixReadBuffers(Davix_fd *fd, char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Definition: TDavixFile.cxx:723
TUrl fUrl
!URL of file
Definition: TFile.h:102
Int_t fD
File descriptor.
Definition: TFile.h:74
Davix::DavPosix * davixPosix
virtual void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
Definition: TDavixFile.cxx:470
virtual Long64_t GetSize() const
Returns the current file size.
Definition: TDavixFile.cxx:628
void Info(const char *location, const char *msgfmt,...)
static TMutex createLock
Definition: TDavixFile.cxx:79
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
void Error(const char *location, const char *msgfmt,...)
Int_t DavixStat(const char *url, struct stat *st)
Definition: TDavixFile.cxx:415
static Context * davix_context_s
Definition: TDavixFile.cxx:80
Long64_t DavixWriteBuffer(Davix_fd *fd, const char *buf, Int_t len)
Definition: TDavixFile.cxx:683
Long64_t fEND
Last used byte in file.
Definition: TFile.h:71
virtual Bool_t ReadBufferAsync(Long64_t offs, Int_t len)
Definition: TDavixFile.cxx:534
const char * s3_token_opt
Definition: TDavixFile.cxx:73
static Davix::Context * getDavixInstance()
Definition: TDavixFile.cxx:229
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:496
void removeDird(void *fd)
Definition: TDavixFile.cxx:618
bool isMyDird(void *fd)
Definition: TDavixFile.cxx:601
TLine * l
Definition: textangle.C:4
bool isno(const char *str)
Definition: TDavixFile.cxx:85
virtual void Init(Bool_t create)
Initialize a TFile object.
Definition: TFile.cxx:584
virtual Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Read the nbuf blocks described in arrays pos and len.
Definition: TDavixFile.cxx:550
#define gPerfStats
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:387
const char * grid_mode_opt
Definition: TDavixFile.cxx:68
static const std::string VERSION
Definition: TDavixFile.cxx:56
#define ClassImp(name)
Definition: Rtypes.h:279
double f(double x)
static Int_t init()
double Double_t
Definition: RtypesCore.h:55
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition: TTimeStamp.h:76
const char * s3_acckey_opt
Definition: TDavixFile.cxx:71
int configure_open_flag(const std::string &str, int old_flag)
Definition: TDavixFile.cxx:97
const char * s3_region_opt
Definition: TDavixFile.cxx:72
void enableGridMode()
Enable the grid mode The grid Mode configure automatically all grid-CA path, VOMS authentication and ...
Definition: TDavixFile.cxx:594
typedef void((*Func_t)())
const char * ca_check_opt
Definition: TDavixFile.cxx:69
void MakeZombie()
Definition: TObject.h:54
#define NULL
Definition: Rtypes.h:82
#define snprintf
Definition: civetweb.c:822
static int TDavixFile_http_authn_cert_X509(void *userdata, const Davix::SessionInfo &info, Davix::X509Credential *cert, Davix::DavixError **err)
Definition: TDavixFile.cxx:201
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
Long64_t fArchiveOffset
!Offset at which file starts in archive
Definition: TFile.h:93
#define gDirectory
Definition: TDirectory.h:221
TDavixFile(const char *url, Option_t *option="", const char *ftitle="", Int_t compress=1)
Open function for TDavixFile.
Definition: TDavixFile.cxx:433
Long64_t fOffset
!Seek offset cache
Definition: TFile.h:88
const Bool_t kTRUE
Definition: Rtypes.h:91
Long64_t DavixPReadBuffer(Davix_fd *fd, char *buf, Long64_t pos, Int_t len)
Definition: TDavixFile.cxx:703
void setCACheck(Bool_t check)
Enable or disable certificate authority check.
Definition: TDavixFile.cxx:587
void parseParams(Option_t *option)
intput params
Definition: TDavixFile.cxx:352
Long64_t fBytesRead
Number of bytes read from this file.
Definition: TFile.h:68
Davix::Context * davixContext
const char * open_mode_new
Definition: TDavixFile.cxx:76