XRootD
XrdClFile.cc
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // This file is part of the XRootD software suite.
6 //
7 // XRootD is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // XRootD is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // In applying this licence, CERN does not waive the privileges and immunities
21 // granted to it by virtue of its status as an Intergovernmental Organization
22 // or submit itself to any jurisdiction.
23 //------------------------------------------------------------------------------
24 
25 #include "XrdCl/XrdClLog.hh"
26 #include "XrdCl/XrdClUtils.hh"
27 #include "XrdCl/XrdClConstants.hh"
28 #include "XrdCl/XrdClFile.hh"
31 #include "XrdCl/XrdClDefaultEnv.hh"
34 #include "XrdCl/XrdClDefaultEnv.hh"
35 
36 namespace XrdCl
37 {
38  //----------------------------------------------------------------------------
39  // The implementation
40  //----------------------------------------------------------------------------
41  struct FileImpl
42  {
43  FileImpl( FilePlugIn *plugin ) :
44  pStateHandler( std::make_shared<FileStateHandler>( plugin ) )
45  {
46  }
47 
48  FileImpl( bool useVirtRedirector, FilePlugIn *plugin ) :
49  pStateHandler( std::make_shared<FileStateHandler>( useVirtRedirector, plugin ) )
50  {
51  }
52 
53  std::shared_ptr<FileStateHandler> pStateHandler;
54  };
55 
56  //----------------------------------------------------------------------------
57  // Constructor
58  //----------------------------------------------------------------------------
59  File::File( bool enablePlugIns ):
60  pPlugIn(0),
61  pEnablePlugIns( enablePlugIns )
62  {
63  pImpl = new FileImpl( pPlugIn );
64  }
65 
66  //----------------------------------------------------------------------------
67  // Constructor
68  //----------------------------------------------------------------------------
69  File::File( VirtRedirect virtRedirect, bool enablePlugIns ):
70  pPlugIn(0),
71  pEnablePlugIns( enablePlugIns )
72  {
73  pImpl = new FileImpl( virtRedirect == EnableVirtRedirect, pPlugIn );
74  }
75 
76  //----------------------------------------------------------------------------
77  // Destructor
78  //----------------------------------------------------------------------------
80  {
81  //--------------------------------------------------------------------------
82  // This, in principle, should never ever happen. Except for the case
83  // when we're interfaced with ROOT that may call this desctructor from
84  // its garbage collector, from its __cxa_finalize, ie. after the XrdCl lib
85  // has been finalized by the linker. So, if we don't have the log object
86  // at this point we just give up the hope.
87  // Also, make sure the PostMaster threads are running - if not the Close
88  // will hang forever (this could happen when Python interpreter exits).
89  //--------------------------------------------------------------------------
90  if ( DefaultEnv::GetLog() && DefaultEnv::GetPostMaster()->IsRunning() && IsOpen() )
91  XRootDStatus status = Close( nullptr, 0 );
92  delete pImpl;
93  delete pPlugIn;
94  }
95 
96  //----------------------------------------------------------------------------
97  // Open the file pointed to by the given URL - async
98  //----------------------------------------------------------------------------
99  XRootDStatus File::Open( const std::string &url,
100  OpenFlags::Flags flags,
101  Access::Mode mode,
102  ResponseHandler *handler,
103  uint16_t timeout )
104  {
105  //--------------------------------------------------------------------------
106  // Check if we need to install and run a plug-in for this URL
107  //--------------------------------------------------------------------------
108  if( pEnablePlugIns && !pPlugIn )
109  {
110  Log *log = DefaultEnv::GetLog();
112  if( fact )
113  {
114  pPlugIn = fact->CreateFile( url );
115  if( !pPlugIn )
116  {
117  log->Error( FileMsg, "Plug-in factory failed to produce a plug-in "
118  "for %s, continuing without one", url.c_str() );
119  }
120  }
121  }
122 
123  //--------------------------------------------------------------------------
124  // Open the file
125  //--------------------------------------------------------------------------
126  if( pPlugIn )
127  return pPlugIn->Open( url, flags, mode, handler, timeout );
128 
129  return FileStateHandler::Open( pImpl->pStateHandler, url, flags, mode, handler, timeout );
130  }
131 
132  //----------------------------------------------------------------------------
133  // Open the file pointed to by the given URL - sync
134  //----------------------------------------------------------------------------
135  XRootDStatus File::Open( const std::string &url,
136  OpenFlags::Flags flags,
137  Access::Mode mode,
138  uint16_t timeout )
139  {
140  SyncResponseHandler handler;
141  XRootDStatus st = Open( url, flags, mode, &handler, timeout );
142  if( !st.IsOK() )
143  return st;
144 
145  return MessageUtils::WaitForStatus( &handler );
146  }
147 
148  //----------------------------------------------------------------------------
149  // Close the file - async
150  //----------------------------------------------------------------------------
152  uint16_t timeout )
153  {
154  if( pPlugIn )
155  return pPlugIn->Close( handler, timeout );
156 
157  return FileStateHandler::Close( pImpl->pStateHandler, handler, timeout );
158  }
159 
160 
161  //----------------------------------------------------------------------------
162  // Close the file
163  //----------------------------------------------------------------------------
164  XRootDStatus File::Close( uint16_t timeout )
165  {
166  SyncResponseHandler handler;
167  XRootDStatus st = Close( &handler, timeout );
168  if( !st.IsOK() || st.code == suAlreadyDone )
169  return st;
170 
171  return MessageUtils::WaitForStatus( &handler );
172  }
173 
174  //----------------------------------------------------------------------------
175  // Obtain status information for this file - async
176  //----------------------------------------------------------------------------
178  ResponseHandler *handler,
179  uint16_t timeout )
180  {
181  if( pPlugIn )
182  return pPlugIn->Stat( force, handler, timeout );
183 
184  return FileStateHandler::Stat( pImpl->pStateHandler, force, handler, timeout );
185  }
186 
187  //----------------------------------------------------------------------------
188  // Obtain status information for this file - sync
189  //----------------------------------------------------------------------------
191  StatInfo *&response,
192  uint16_t timeout )
193  {
194  SyncResponseHandler handler;
195  XRootDStatus st = Stat( force, &handler, timeout );
196  if( !st.IsOK() )
197  return st;
198 
199  return MessageUtils::WaitForResponse( &handler, response );
200  }
201 
202 
203  //----------------------------------------------------------------------------
204  // Read a data chunk at a given offset - sync
205  //----------------------------------------------------------------------------
206  XRootDStatus File::Read( uint64_t offset,
207  uint32_t size,
208  void *buffer,
209  ResponseHandler *handler,
210  uint16_t timeout )
211  {
212  if( pPlugIn )
213  return pPlugIn->Read( offset, size, buffer, handler, timeout );
214 
215  return FileStateHandler::Read( pImpl->pStateHandler, offset, size, buffer, handler, timeout );
216  }
217 
218  //----------------------------------------------------------------------------
219  // Read a data chunk at a given offset - sync
220  //----------------------------------------------------------------------------
221  XRootDStatus File::Read( uint64_t offset,
222  uint32_t size,
223  void *buffer,
224  uint32_t &bytesRead,
225  uint16_t timeout )
226  {
227  SyncResponseHandler handler;
228  XRootDStatus st = Read( offset, size, buffer, &handler, timeout );
229  if( !st.IsOK() )
230  return st;
231 
232  ChunkInfo *chunkInfo = 0;
233  XRootDStatus status = MessageUtils::WaitForResponse( &handler, chunkInfo );
234  if( status.IsOK() )
235  {
236  bytesRead = chunkInfo->length;
237  delete chunkInfo;
238  }
239  return status;
240  }
241 
242  //------------------------------------------------------------------------
243  // Read number of pages at a given offset - async
244  //------------------------------------------------------------------------
245  XRootDStatus File::PgRead( uint64_t offset,
246  uint32_t size,
247  void *buffer,
248  ResponseHandler *handler,
249  uint16_t timeout )
250  {
251  if( pPlugIn )
252  return pPlugIn->PgRead( offset, size, buffer, handler, timeout );
253 
254  return FileStateHandler::PgRead( pImpl->pStateHandler, offset, size, buffer, handler, timeout );
255  }
256 
257  //------------------------------------------------------------------------
258  // Read number of pages at a given offset - async
259  //------------------------------------------------------------------------
260  XRootDStatus File::PgRead( uint64_t offset,
261  uint32_t size,
262  void *buffer,
263  std::vector<uint32_t> &cksums,
264  uint32_t &bytesRead,
265  uint16_t timeout )
266  {
267  SyncResponseHandler handler;
268  XRootDStatus st = PgRead( offset, size, buffer, &handler, timeout );
269  if( !st.IsOK() )
270  return st;
271 
272  PageInfo *pageInfo = 0;
273  XRootDStatus status = MessageUtils::WaitForResponse( &handler, pageInfo );
274  if( status.IsOK() )
275  {
276  bytesRead = pageInfo->GetLength();
277  cksums = pageInfo->GetCksums();
278  delete pageInfo;
279  }
280  return status;
281  }
282 
283  //----------------------------------------------------------------------------
284  // Write a data chunk at a given offset - async
285  //----------------------------------------------------------------------------
286  XRootDStatus File::Write( uint64_t offset,
287  uint32_t size,
288  const void *buffer,
289  ResponseHandler *handler,
290  uint16_t timeout )
291  {
292  if( pPlugIn )
293  return pPlugIn->Write( offset, size, buffer, handler, timeout );
294 
295  return FileStateHandler::Write( pImpl->pStateHandler, offset, size, buffer, handler, timeout );
296  }
297 
298  //----------------------------------------------------------------------------
299  // Write a data chunk at a given offset - sync
300  //----------------------------------------------------------------------------
301  XRootDStatus File::Write( uint64_t offset,
302  uint32_t size,
303  const void *buffer,
304  uint16_t timeout )
305  {
306  SyncResponseHandler handler;
307  XRootDStatus st = Write( offset, size, buffer, &handler, timeout );
308  if( !st.IsOK() )
309  return st;
310 
311  XRootDStatus status = MessageUtils::WaitForStatus( &handler );
312  return status;
313  }
314 
315 
316  XRootDStatus File::Write( uint64_t offset,
317  Buffer &&buffer,
318  ResponseHandler *handler,
319  uint16_t timeout )
320  {
321  if( pPlugIn )
322  return pPlugIn->Write( offset, std::move( buffer ), handler, timeout );
323 
324  return FileStateHandler::Write( pImpl->pStateHandler, offset, std::move( buffer ), handler, timeout );
325  }
326 
327  //----------------------------------------------------------------------------
328  // Write a data chunk at a given offset - async
329  //----------------------------------------------------------------------------
330  XRootDStatus File::Write( uint64_t offset,
331  Buffer &&buffer,
332  uint16_t timeout )
333  {
334  SyncResponseHandler handler;
335  XRootDStatus st = Write( offset, std::move( buffer ), &handler, timeout );
336  if( !st.IsOK() )
337  return st;
338 
339  XRootDStatus status = MessageUtils::WaitForStatus( &handler );
340  return status;
341  }
342 
343  //------------------------------------------------------------------------
344  // Write a data from a given file descriptor at a given offset - async
345  //------------------------------------------------------------------------
346  XRootDStatus File::Write( uint64_t offset,
347  uint32_t size,
348  Optional<uint64_t> fdoff,
349  int fd,
350  ResponseHandler *handler,
351  uint16_t timeout )
352  {
353  if( pPlugIn )
354  return pPlugIn->Write( offset, size, fdoff, fd, handler, timeout );
355 
356  return FileStateHandler::Write( pImpl->pStateHandler, offset, size, fdoff, fd, handler, timeout );
357  }
358 
359  //------------------------------------------------------------------------
360  // Write a data from a given file descriptor at a given offset - sync
361  //------------------------------------------------------------------------
362  XRootDStatus File::Write( uint64_t offset,
363  uint32_t size,
364  Optional<uint64_t> fdoff,
365  int fd,
366  uint16_t timeout )
367  {
368  SyncResponseHandler handler;
369  XRootDStatus st = Write( offset, size, fdoff, fd, &handler, timeout );
370  if( !st.IsOK() )
371  return st;
372 
373  XRootDStatus status = MessageUtils::WaitForStatus( &handler );
374  return status;
375  }
376 
377  //------------------------------------------------------------------------
378  // Write number of pages at a given offset - async
379  //------------------------------------------------------------------------
380  XRootDStatus File::PgWrite( uint64_t offset,
381  uint32_t size,
382  const void *buffer,
383  std::vector<uint32_t> &cksums,
384  ResponseHandler *handler,
385  uint16_t timeout )
386  {
387  if( pPlugIn )
388  return pPlugIn->PgWrite( offset, size, buffer, cksums, handler, timeout );
389 
390  return FileStateHandler::PgWrite( pImpl->pStateHandler, offset, size, buffer, cksums, handler, timeout );
391  }
392 
393  //------------------------------------------------------------------------
394  // Write number of pages at a given offset - sync
395  //------------------------------------------------------------------------
396  XRootDStatus File::PgWrite( uint64_t offset,
397  uint32_t size,
398  const void *buffer,
399  std::vector<uint32_t> &cksums,
400  uint16_t timeout )
401  {
402  SyncResponseHandler handler;
403  XRootDStatus st = PgWrite( offset, size, buffer, cksums, &handler, timeout );
404  if( !st.IsOK() )
405  return st;
406 
407  XRootDStatus status = MessageUtils::WaitForStatus( &handler );
408  return status;
409  }
410 
411  //----------------------------------------------------------------------------
412  // Commit all pending disk writes - async
413  //----------------------------------------------------------------------------
415  uint16_t timeout )
416  {
417  if( pPlugIn )
418  return pPlugIn->Sync( handler, timeout );
419 
420  return FileStateHandler::Sync( pImpl->pStateHandler, handler, timeout );
421  }
422 
423  //----------------------------------------------------------------------------
424  // Commit all pending disk writes - sync
425  //----------------------------------------------------------------------------
426  XRootDStatus File::Sync( uint16_t timeout )
427  {
428  SyncResponseHandler handler;
429  XRootDStatus st = Sync( &handler, timeout );
430  if( !st.IsOK() )
431  return st;
432 
433  XRootDStatus status = MessageUtils::WaitForStatus( &handler );
434  return status;
435  }
436 
437  //----------------------------------------------------------------------------
438  // Truncate the file to a particular size - async
439  //----------------------------------------------------------------------------
440  XRootDStatus File::Truncate( uint64_t size,
441  ResponseHandler *handler,
442  uint16_t timeout )
443  {
444  if( pPlugIn )
445  return pPlugIn->Truncate( size, handler, timeout );
446 
447  return FileStateHandler::Truncate( pImpl->pStateHandler, size, handler, timeout );
448  }
449 
450 
451  //----------------------------------------------------------------------------
452  // Truncate the file to a particular size - sync
453  //----------------------------------------------------------------------------
454  XRootDStatus File::Truncate( uint64_t size, uint16_t timeout )
455  {
456  SyncResponseHandler handler;
457  XRootDStatus st = Truncate( size, &handler, timeout );
458  if( !st.IsOK() )
459  return st;
460 
461  XRootDStatus status = MessageUtils::WaitForStatus( &handler );
462  return status;
463  }
464 
465  //----------------------------------------------------------------------------
466  // Read scattered data chunks in one operation - async
467  //----------------------------------------------------------------------------
469  void *buffer,
470  ResponseHandler *handler,
471  uint16_t timeout )
472  {
473  if( pPlugIn )
474  return pPlugIn->VectorRead( chunks, buffer, handler, timeout );
475 
476  return FileStateHandler::VectorRead( pImpl->pStateHandler, chunks, buffer, handler, timeout );
477  }
478 
479  //----------------------------------------------------------------------------
480  // Read scattered data chunks in one operation - sync
481  //----------------------------------------------------------------------------
483  void *buffer,
484  VectorReadInfo *&vReadInfo,
485  uint16_t timeout )
486  {
487  SyncResponseHandler handler;
488  XRootDStatus st = VectorRead( chunks, buffer, &handler, timeout );
489  if( !st.IsOK() )
490  return st;
491 
492  return MessageUtils::WaitForResponse( &handler, vReadInfo );
493  }
494 
495  //------------------------------------------------------------------------
496  // Write scattered data chunks in one operation - async
497  //------------------------------------------------------------------------
499  ResponseHandler *handler,
500  uint16_t timeout )
501  {
502  if( pPlugIn )
503  return pPlugIn->VectorWrite( chunks, handler, timeout );
504 
505  return FileStateHandler::VectorWrite( pImpl->pStateHandler, chunks, handler, timeout );
506  }
507 
508  //------------------------------------------------------------------------
509  // Read scattered data chunks in one operation - sync
510  //------------------------------------------------------------------------
512  uint16_t timeout )
513  {
514  SyncResponseHandler handler;
515  XRootDStatus st = VectorWrite( chunks, &handler, timeout );
516  if( !st.IsOK() )
517  return st;
518 
519  return MessageUtils::WaitForStatus( &handler );
520  }
521 
522  //------------------------------------------------------------------------
523  // Write scattered buffers in one operation - async
524  //------------------------------------------------------------------------
525  XRootDStatus File::WriteV( uint64_t offset,
526  const struct iovec *iov,
527  int iovcnt,
528  ResponseHandler *handler,
529  uint16_t timeout )
530  {
531  if( pPlugIn )
532  return pPlugIn->WriteV( offset, iov, iovcnt, handler, timeout );
533 
534  return FileStateHandler::WriteV( pImpl->pStateHandler, offset, iov, iovcnt, handler, timeout );
535  }
536 
537  //------------------------------------------------------------------------
538  // Write scattered buffers in one operation - sync
539  //------------------------------------------------------------------------
540  XRootDStatus File::WriteV( uint64_t offset,
541  const struct iovec *iov,
542  int iovcnt,
543  uint16_t timeout )
544  {
545  SyncResponseHandler handler;
546  XRootDStatus st = WriteV( offset, iov, iovcnt, &handler, timeout );
547  if( !st.IsOK() )
548  return st;
549 
550  XRootDStatus status = MessageUtils::WaitForStatus( &handler );
551  return status;
552  }
553 
554  //------------------------------------------------------------------------
564  //------------------------------------------------------------------------
565  XRootDStatus File::ReadV( uint64_t offset,
566  struct iovec *iov,
567  int iovcnt,
568  ResponseHandler *handler,
569  uint16_t timeout )
570  {
571  return FileStateHandler::ReadV( pImpl->pStateHandler, offset, iov, iovcnt, handler, timeout );
572  }
573 
574  //------------------------------------------------------------------------
584  //------------------------------------------------------------------------
585  XRootDStatus File::ReadV( uint64_t offset,
586  struct iovec *iov,
587  int iovcnt,
588  uint32_t &bytesRead,
589  uint16_t timeout )
590  {
591  SyncResponseHandler handler;
592  XRootDStatus st = ReadV( offset, iov, iovcnt, &handler, timeout );
593  if( !st.IsOK() )
594  return st;
595 
596  VectorReadInfo *vrInfo = 0;
597  XRootDStatus status = MessageUtils::WaitForResponse( &handler, vrInfo );
598  if( status.IsOK() )
599  {
600  bytesRead = vrInfo->GetSize();
601  delete vrInfo;
602  }
603  return status;
604  }
605 
606  //----------------------------------------------------------------------------
607  // Performs a custom operation on an open file, server implementation
608  // dependent - async
609  //----------------------------------------------------------------------------
611  ResponseHandler *handler,
612  uint16_t timeout )
613  {
614  if( pPlugIn )
615  return pPlugIn->Fcntl( arg, handler, timeout );
616 
617  return FileStateHandler::Fcntl( pImpl->pStateHandler, arg, handler, timeout );
618  }
619 
620  //----------------------------------------------------------------------------
621  // Performs a custom operation on an open file, server implementation
622  // dependent - sync
623  //----------------------------------------------------------------------------
625  Buffer *&response,
626  uint16_t timeout )
627  {
628  SyncResponseHandler handler;
629  XRootDStatus st = Fcntl( arg, &handler, timeout );
630  if( !st.IsOK() )
631  return st;
632 
633  return MessageUtils::WaitForResponse( &handler, response );
634  }
635 
636  //------------------------------------------------------------------------
638  //------------------------------------------------------------------------
640  uint16_t timeout )
641  {
642  if( pPlugIn )
643  return pPlugIn->Visa( handler, timeout );
644 
645  return FileStateHandler::Visa( pImpl->pStateHandler, handler, timeout );
646  }
647 
648  //----------------------------------------------------------------------------
649  // Get access token to a file - sync
650  //----------------------------------------------------------------------------
652  uint16_t timeout )
653  {
654  SyncResponseHandler handler;
655  XRootDStatus st = Visa( &handler, timeout );
656  if( !st.IsOK() )
657  return st;
658 
659  return MessageUtils::WaitForResponse( &handler, visa );
660  }
661 
662  //------------------------------------------------------------------------
663  // Set extended attributes - async
664  //------------------------------------------------------------------------
665  XRootDStatus File::SetXAttr( const std::vector<xattr_t> &attrs,
666  ResponseHandler *handler,
667  uint16_t timeout )
668  {
669  if( pPlugIn )
671 
672  return FileStateHandler::SetXAttr( pImpl->pStateHandler, attrs, handler, timeout );
673  }
674 
675  //------------------------------------------------------------------------
676  // Set extended attributes - sync
677  //------------------------------------------------------------------------
678  XRootDStatus File::SetXAttr( const std::vector<xattr_t> &attrs,
679  std::vector<XAttrStatus> &result,
680  uint16_t timeout )
681  {
682  SyncResponseHandler handler;
683  XRootDStatus st = SetXAttr( attrs, &handler, timeout );
684  if( !st.IsOK() )
685  return st;
686 
687  std::vector<XAttrStatus> *resp = 0;
688  st = MessageUtils::WaitForResponse( &handler, resp );
689  if( resp ) result.swap( *resp );
690  delete resp;
691 
692  return st;
693  }
694 
695  //------------------------------------------------------------------------
696  // Get extended attributes - async
697  //------------------------------------------------------------------------
698  XRootDStatus File::GetXAttr( const std::vector<std::string> &attrs,
699  ResponseHandler *handler,
700  uint16_t timeout )
701  {
702  if( pPlugIn )
704 
705  return FileStateHandler::GetXAttr( pImpl->pStateHandler, attrs, handler, timeout );
706  }
707 
708  //------------------------------------------------------------------------
709  // Get extended attributes - sync
710  //------------------------------------------------------------------------
711  XRootDStatus File::GetXAttr( const std::vector<std::string> &attrs,
712  std::vector<XAttr> &result,
713  uint16_t timeout )
714  {
715  SyncResponseHandler handler;
716  XRootDStatus st = GetXAttr( attrs, &handler, timeout );
717  if( !st.IsOK() )
718  return st;
719 
720  std::vector<XAttr> *resp = 0;
721  st = MessageUtils::WaitForResponse( &handler, resp );
722  if( resp ) result.swap( *resp );
723  delete resp;
724 
725  return st;
726  }
727 
728  //------------------------------------------------------------------------
729  // Delete extended attributes - async
730  //------------------------------------------------------------------------
731  XRootDStatus File::DelXAttr( const std::vector<std::string> &attrs,
732  ResponseHandler *handler,
733  uint16_t timeout )
734  {
735  if( pPlugIn )
737 
738  return FileStateHandler::DelXAttr( pImpl->pStateHandler, attrs, handler, timeout );
739  }
740 
741  //------------------------------------------------------------------------
742  // Delete extended attributes - sync
743  //------------------------------------------------------------------------
744  XRootDStatus File::DelXAttr( const std::vector<std::string> &attrs,
745  std::vector<XAttrStatus> &result,
746  uint16_t timeout )
747  {
748  SyncResponseHandler handler;
749  XRootDStatus st = DelXAttr( attrs, &handler, timeout );
750  if( !st.IsOK() )
751  return st;
752 
753  std::vector<XAttrStatus> *resp = 0;
754  st = MessageUtils::WaitForResponse( &handler, resp );
755  if( resp ) result.swap( *resp );
756  delete resp;
757 
758  return st;
759  }
760 
761  //------------------------------------------------------------------------
762  // List extended attributes - async
763  //------------------------------------------------------------------------
765  uint16_t timeout )
766  {
767  if( pPlugIn )
769 
770  return FileStateHandler::ListXAttr( pImpl->pStateHandler, handler, timeout );
771  }
772 
773  //------------------------------------------------------------------------
774  // List extended attributes - sync
775  //------------------------------------------------------------------------
776  XRootDStatus File::ListXAttr( std::vector<XAttr> &result,
777  uint16_t timeout )
778  {
779  SyncResponseHandler handler;
780  XRootDStatus st = ListXAttr( &handler, timeout );
781  if( !st.IsOK() )
782  return st;
783 
784  std::vector<XAttr> *resp = 0;
785  st = MessageUtils::WaitForResponse( &handler, resp );
786  if( resp ) result.swap( *resp );
787  delete resp;
788 
789  return st;
790  }
791 
792  //------------------------------------------------------------------------
793  // Create a checkpoint
794  //------------------------------------------------------------------------
795  XRootDStatus File::Checkpoint( kXR_char code,
796  ResponseHandler *handler,
797  uint16_t timeout )
798  {
799  if( pPlugIn )
801 
802  return FileStateHandler::Checkpoint( pImpl->pStateHandler, code, handler, timeout );
803  }
804 
805  //------------------------------------------------------------------------
807  //------------------------------------------------------------------------
808  XRootDStatus File::ChkptWrt( uint64_t offset,
809  uint32_t size,
810  const void *buffer,
811  ResponseHandler *handler,
812  uint16_t timeout )
813  {
814  if( pPlugIn )
815  return XRootDStatus( stError, errNotSupported );
816 
817  return FileStateHandler::ChkptWrt( pImpl->pStateHandler, offset, size, buffer, handler, timeout );
818  }
819 
820  //------------------------------------------------------------------------
822  //------------------------------------------------------------------------
823  XRootDStatus File::ChkptWrtV( uint64_t offset,
824  const struct iovec *iov,
825  int iovcnt,
826  ResponseHandler *handler,
827  uint16_t timeout )
828  {
829  if( pPlugIn )
830  return XRootDStatus( stError, errNotSupported );
831 
832  return FileStateHandler::ChkptWrtV( pImpl->pStateHandler, offset, iov, iovcnt, handler, timeout );
833  }
834 
835  //------------------------------------------------------------------------
836  // Try different data server
837  //------------------------------------------------------------------------
838  XRootDStatus File::TryOtherServer( uint16_t timeout )
839  {
840  return FileStateHandler::TryOtherServer( pImpl->pStateHandler, timeout );
841  }
842 
843  //----------------------------------------------------------------------------
844  // Check if the file is open
845  //----------------------------------------------------------------------------
846  bool File::IsOpen() const
847  {
848  if( pPlugIn )
849  return pPlugIn->IsOpen();
850 
851  return pImpl->pStateHandler->IsOpen();
852  }
853 
854  //------------------------------------------------------------------------
856  //------------------------------------------------------------------------
857  bool File::IsSecure() const
858  {
859  if( pPlugIn )
860  return false;
861  return pImpl->pStateHandler->IsSecure();
862  }
863 
864  //----------------------------------------------------------------------------
865  // Set file property
866  //----------------------------------------------------------------------------
867  bool File::SetProperty( const std::string &name, const std::string &value )
868  {
869  if( pPlugIn )
870  return pPlugIn->SetProperty( name, value );
871 
872  return pImpl->pStateHandler->SetProperty( name, value );
873  }
874 
875  //----------------------------------------------------------------------------
876  // Get file property
877  //----------------------------------------------------------------------------
878  bool File::GetProperty( const std::string &name, std::string &value ) const
879  {
880  if( pPlugIn )
881  return pPlugIn->GetProperty( name, value );
882 
883  return pImpl->pStateHandler->GetProperty( name, value );
884  }
885 }
unsigned char kXR_char
Definition: XPtypes.hh:65
Binary blob representation.
Definition: XrdClBuffer.hh:34
static PlugInManager * GetPlugInManager()
Get plug-in manager.
static Log * GetLog()
Get default log.
static PostMaster * GetPostMaster()
Get default post master.
An interface for file plug-ins.
virtual XRootDStatus Fcntl(const Buffer &arg, ResponseHandler *handler, uint16_t timeout)
virtual XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout)
virtual XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, uint16_t timeout)
virtual XRootDStatus Sync(ResponseHandler *handler, uint16_t timeout)
virtual bool IsOpen() const
virtual XRootDStatus Close(ResponseHandler *handler, uint16_t timeout)
virtual XRootDStatus WriteV(uint64_t offset, const struct iovec *iov, int iovcnt, ResponseHandler *handler, uint16_t timeout=0)
virtual bool GetProperty(const std::string &name, std::string &value) const
virtual XRootDStatus VectorRead(const ChunkList &chunks, void *buffer, ResponseHandler *handler, uint16_t timeout)
virtual XRootDStatus PgRead(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout)
virtual XRootDStatus Truncate(uint64_t size, ResponseHandler *handler, uint16_t timeout)
virtual XRootDStatus Visa(ResponseHandler *handler, uint16_t timeout)
virtual XRootDStatus Stat(bool force, ResponseHandler *handler, uint16_t timeout)
virtual bool SetProperty(const std::string &name, const std::string &value)
virtual XRootDStatus Write(uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout)
virtual XRootDStatus VectorWrite(const ChunkList &chunks, ResponseHandler *handler, uint16_t timeout=0)
virtual XRootDStatus PgWrite(uint64_t offset, uint32_t nbpgs, const void *buffer, std::vector< uint32_t > &cksums, ResponseHandler *handler, uint16_t timeout)
Handle the stateful operations.
static XRootDStatus Stat(std::shared_ptr< FileStateHandler > &self, bool force, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus Sync(std::shared_ptr< FileStateHandler > &self, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus DelXAttr(std::shared_ptr< FileStateHandler > &self, const std::vector< std::string > &attrs, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus GetXAttr(std::shared_ptr< FileStateHandler > &self, const std::vector< std::string > &attrs, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus ListXAttr(std::shared_ptr< FileStateHandler > &self, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus SetXAttr(std::shared_ptr< FileStateHandler > &self, const std::vector< xattr_t > &attrs, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus ReadV(std::shared_ptr< FileStateHandler > &self, uint64_t offset, struct iovec *iov, int iovcnt, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus ChkptWrt(std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus Read(std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus Fcntl(std::shared_ptr< FileStateHandler > &self, const Buffer &arg, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus Truncate(std::shared_ptr< FileStateHandler > &self, uint64_t size, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus Close(std::shared_ptr< FileStateHandler > &self, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus ChkptWrtV(std::shared_ptr< FileStateHandler > &self, uint64_t offset, const struct iovec *iov, int iovcnt, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus PgWrite(std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, const void *buffer, std::vector< uint32_t > &cksums, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus PgRead(std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus VectorWrite(std::shared_ptr< FileStateHandler > &self, const ChunkList &chunks, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus WriteV(std::shared_ptr< FileStateHandler > &self, uint64_t offset, const struct iovec *iov, int iovcnt, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus Visa(std::shared_ptr< FileStateHandler > &self, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus Open(std::shared_ptr< FileStateHandler > &self, const std::string &url, uint16_t flags, uint16_t mode, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus VectorRead(std::shared_ptr< FileStateHandler > &self, const ChunkList &chunks, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus Write(std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus Checkpoint(std::shared_ptr< FileStateHandler > &self, kXR_char code, ResponseHandler *handler, uint16_t timeout=0)
static XRootDStatus TryOtherServer(std::shared_ptr< FileStateHandler > &self, uint16_t timeout)
Try other data server.
XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:206
XRootDStatus Close(ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:151
XRootDStatus ListXAttr(ResponseHandler *handler, uint16_t timeout=0)
Definition: XrdClFile.cc:764
bool IsSecure() const
Check if the file is using an encrypted connection.
Definition: XrdClFile.cc:857
@ EnableVirtRedirect
Definition: XrdClFile.hh:51
bool IsOpen() const
Check if the file is open.
Definition: XrdClFile.cc:846
XRootDStatus Truncate(uint64_t size, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:440
XRootDStatus SetXAttr(const std::vector< xattr_t > &attrs, ResponseHandler *handler, uint16_t timeout=0)
Definition: XrdClFile.cc:665
XRootDStatus VectorRead(const ChunkList &chunks, void *buffer, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:468
XRootDStatus Fcntl(const Buffer &arg, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:610
XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:99
bool GetProperty(const std::string &name, std::string &value) const
Definition: XrdClFile.cc:878
XRootDStatus GetXAttr(const std::vector< std::string > &attrs, ResponseHandler *handler, uint16_t timeout=0)
Definition: XrdClFile.cc:698
XRootDStatus DelXAttr(const std::vector< std::string > &attrs, ResponseHandler *handler, uint16_t timeout=0)
Definition: XrdClFile.cc:731
File(bool enablePlugIns=true)
Constructor.
Definition: XrdClFile.cc:59
XRootDStatus WriteV(uint64_t offset, const struct iovec *iov, int iovcnt, ResponseHandler *handler, uint16_t timeout=0)
Definition: XrdClFile.cc:525
XRootDStatus Visa(ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Get access token to a file - async.
Definition: XrdClFile.cc:639
XRootDStatus Write(uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:286
XRootDStatus PgRead(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:245
XRootDStatus Stat(bool force, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:177
virtual ~File()
Destructor.
Definition: XrdClFile.cc:79
bool SetProperty(const std::string &name, const std::string &value)
Definition: XrdClFile.cc:867
XRootDStatus Sync(ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:414
XRootDStatus TryOtherServer(uint16_t timeout=0)
Definition: XrdClFile.cc:838
XRootDStatus PgWrite(uint64_t offset, uint32_t size, const void *buffer, std::vector< uint32_t > &cksums, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:380
XRootDStatus ReadV(uint64_t offset, struct iovec *iov, int iovcnt, ResponseHandler *handler, uint16_t timeout=0)
Definition: XrdClFile.cc:565
XRootDStatus VectorWrite(const ChunkList &chunks, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition: XrdClFile.cc:498
Handle diagnostics.
Definition: XrdClLog.hh:101
void Error(uint64_t topic, const char *format,...)
Report an error.
Definition: XrdClLog.cc:231
static XrdCl::XRootDStatus WaitForResponse(SyncResponseHandler *handler, Type *&response)
Wait for the response.
static XRootDStatus WaitForStatus(SyncResponseHandler *handler)
Wait and return the status of the query.
virtual FilePlugIn * CreateFile(const std::string &url)=0
Create a file plug-in for the given URL.
PlugInFactory * GetFactory(const std::string url)
Handle an async response.
Object stat info.
Synchronize the response.
uint32_t GetSize() const
Get Size.
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
const uint64_t FileMsg
const uint16_t suAlreadyDone
Definition: XrdClStatus.hh:42
std::vector< ChunkInfo > ChunkList
List of chunks.
const uint16_t errNotSupported
Definition: XrdClStatus.hh:62
Mode
Access mode.
Describe a data chunk for vector read.
uint32_t length
offset in the file
FileImpl(FilePlugIn *plugin)
Definition: XrdClFile.cc:43
FileImpl(bool useVirtRedirector, FilePlugIn *plugin)
Definition: XrdClFile.cc:48
std::shared_ptr< FileStateHandler > pStateHandler
Definition: XrdClFile.cc:53
Flags
Open flags, may be or'd when appropriate.
std::vector< uint32_t > & GetCksums()
Get the checksums.
uint32_t GetLength() const
Get the data length.
uint16_t code
Error type, or additional hints on what to do.
Definition: XrdClStatus.hh:147
bool IsOK() const
We're fine.
Definition: XrdClStatus.hh:124