XRootD
Loading...
Searching...
No Matches
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"
28#include "XrdCl/XrdClFile.hh"
35
36namespace 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 // Constructor
78 //----------------------------------------------------------------------------
79 File::File(const std::string &url, bool enablePlugIns): pPlugIn(0), pEnablePlugIns(enablePlugIns)
80 {
81 InitPlugin(url);
82 pImpl = new FileImpl(pPlugIn);
83 }
84
85 //----------------------------------------------------------------------------
86 // Destructor
87 //----------------------------------------------------------------------------
89 {
90 //--------------------------------------------------------------------------
91 // This, in principle, should never ever happen. Except for the case
92 // when we're interfaced with ROOT that may call this desctructor from
93 // its garbage collector, from its __cxa_finalize, ie. after the XrdCl lib
94 // has been finalized by the linker. So, if we don't have the log object
95 // at this point we just give up the hope.
96 // Also, make sure the PostMaster threads are running - if not the Close
97 // will hang forever (this could happen when Python interpreter exits).
98 //--------------------------------------------------------------------------
99 if ( DefaultEnv::GetLog() && DefaultEnv::GetPostMaster()->IsRunning() && IsOpen() )
100 XRootDStatus status = Close( nullptr, 0 );
101 delete pImpl;
102 delete pPlugIn;
103 }
104
105 void File::InitPlugin(const std::string &url) {
106
107 if (pEnablePlugIns && !pPlugIn) {
108 Log *log = DefaultEnv::GetLog();
110 if (fact) {
111 pPlugIn = fact->CreateFile(url);
112 if (!pPlugIn) {
113 log->Error(FileMsg,
114 "Plug-in factory failed to produce a plug-in "
115 "for %s, continuing without one",
116 url.c_str());
117 }
118 }
119 }
120 }
121
122 //----------------------------------------------------------------------------
123 // Open the file pointed to by the given URL - async
124 //----------------------------------------------------------------------------
125 XRootDStatus File::Open( const std::string &url,
126 OpenFlags::Flags flags,
127 Access::Mode mode,
128 ResponseHandler *handler,
129 time_t timeout )
130 {
131 // Check if we need to install and run a plug-in for this URL
132 InitPlugin(url);
133
134 if( (flags & OpenFlags::Dup) || (flags & OpenFlags::Samefs) )
136 "Dup or Samefs options require a file template to be specified" );
137
138 //--------------------------------------------------------------------------
139 // Open the file
140 //--------------------------------------------------------------------------
141 if( pPlugIn )
142 return pPlugIn->Open( url, flags, mode, handler, timeout );
143
144 return FileStateHandler::Open( pImpl->pStateHandler, url, flags, mode, handler, timeout );
145 }
146
147 //----------------------------------------------------------------------------
148 // Open the file pointed to by the given URL - async
149 // Alows one to specify template file. Required if using Dup or Samefs flags.
150 //----------------------------------------------------------------------------
152 const std::string &url,
153 OpenFlags::Flags flags,
154 Access::Mode mode,
155 ResponseHandler *handler,
156 time_t timeout )
157 {
158 // Check if we need to install and run a plug-in for this URL
159 InitPlugin(url);
160
161 //--------------------------------------------------------------------------
162 // Open the file
163 //--------------------------------------------------------------------------
164 if( pPlugIn )
165 return pPlugIn->OpenUsingTemplate( rfile.GetFileTemplate().get(), url,
166 flags, mode, handler, timeout );
167
168 return FileStateHandler::OpenUsingTemplate( pImpl->pStateHandler,
169 rfile.GetFileTemplate().get(), url, flags,
170 mode, handler, timeout );
171 }
172
173 //----------------------------------------------------------------------------
174 // Open the file pointed to by the given URL - sync
175 //----------------------------------------------------------------------------
176 XRootDStatus File::Open( const std::string &url,
177 OpenFlags::Flags flags,
178 Access::Mode mode,
179 time_t timeout )
180 {
181 SyncResponseHandler handler;
182 XRootDStatus st = Open( url, flags, mode, &handler, timeout );
183 if( !st.IsOK() )
184 return st;
185
186 return MessageUtils::WaitForStatus( &handler );
187 }
188
189 //----------------------------------------------------------------------------
190 // Open the file pointed to by the given URL - sync
191 // Alows one to specify template file. Required if using Dup or Samefs flags.
192 //----------------------------------------------------------------------------
194 const std::string &url,
195 OpenFlags::Flags flags,
196 Access::Mode mode,
197 time_t timeout )
198 {
199 SyncResponseHandler handler;
200 XRootDStatus st = OpenUsingTemplate( rfile, url, flags, mode, &handler, timeout );
201 if( !st.IsOK() )
202 return st;
203
204 return MessageUtils::WaitForStatus( &handler );
205 }
206
207 //----------------------------------------------------------------------------
208 // Close the file - async
209 //----------------------------------------------------------------------------
211 time_t timeout )
212 {
213 if( pPlugIn )
214 return pPlugIn->Close( handler, timeout );
215
216 return FileStateHandler::Close( pImpl->pStateHandler, handler, timeout );
217 }
218
219
220 //----------------------------------------------------------------------------
221 // Close the file
222 //----------------------------------------------------------------------------
223 XRootDStatus File::Close( time_t timeout )
224 {
225 SyncResponseHandler handler;
226 XRootDStatus st = Close( &handler, timeout );
227 if( !st.IsOK() || st.code == suAlreadyDone )
228 return st;
229
230 return MessageUtils::WaitForStatus( &handler );
231 }
232
233 //----------------------------------------------------------------------------
234 // Obtain status information for this file - async
235 //----------------------------------------------------------------------------
237 ResponseHandler *handler,
238 time_t timeout )
239 {
240 if( pPlugIn )
241 return pPlugIn->Stat( force, handler, timeout );
242
243 return FileStateHandler::Stat( pImpl->pStateHandler, force, handler, timeout );
244 }
245
246 //----------------------------------------------------------------------------
247 // Obtain status information for this file - sync
248 //----------------------------------------------------------------------------
250 StatInfo *&response,
251 time_t timeout )
252 {
253 SyncResponseHandler handler;
254 XRootDStatus st = Stat( force, &handler, timeout );
255 if( !st.IsOK() )
256 return st;
257
258 return MessageUtils::WaitForResponse( &handler, response );
259 }
260
261
262 //----------------------------------------------------------------------------
263 // Read a data chunk at a given offset - sync
264 //----------------------------------------------------------------------------
265 XRootDStatus File::Read( uint64_t offset,
266 uint32_t size,
267 void *buffer,
268 ResponseHandler *handler,
269 time_t timeout )
270 {
271 if( pPlugIn )
272 return pPlugIn->Read( offset, size, buffer, handler, timeout );
273
274 return FileStateHandler::Read( pImpl->pStateHandler, offset, size, buffer, handler, timeout );
275 }
276
277 //----------------------------------------------------------------------------
278 // Read a data chunk at a given offset - sync
279 //----------------------------------------------------------------------------
280 XRootDStatus File::Read( uint64_t offset,
281 uint32_t size,
282 void *buffer,
283 uint32_t &bytesRead,
284 time_t timeout )
285 {
286 SyncResponseHandler handler;
287 XRootDStatus st = Read( offset, size, buffer, &handler, timeout );
288 if( !st.IsOK() )
289 return st;
290
291 ChunkInfo *chunkInfo = 0;
292 XRootDStatus status = MessageUtils::WaitForResponse( &handler, chunkInfo );
293 if( status.IsOK() )
294 {
295 bytesRead = chunkInfo->length;
296 delete chunkInfo;
297 }
298 return status;
299 }
300
301 //------------------------------------------------------------------------
302 // Read number of pages at a given offset - async
303 //------------------------------------------------------------------------
304 XRootDStatus File::PgRead( uint64_t offset,
305 uint32_t size,
306 void *buffer,
307 ResponseHandler *handler,
308 time_t timeout )
309 {
310 if( pPlugIn )
311 return pPlugIn->PgRead( offset, size, buffer, handler, timeout );
312
313 return FileStateHandler::PgRead( pImpl->pStateHandler, offset, size, buffer, handler, timeout );
314 }
315
316 //------------------------------------------------------------------------
317 // Read number of pages at a given offset - async
318 //------------------------------------------------------------------------
319 XRootDStatus File::PgRead( uint64_t offset,
320 uint32_t size,
321 void *buffer,
322 std::vector<uint32_t> &cksums,
323 uint32_t &bytesRead,
324 time_t timeout )
325 {
326 SyncResponseHandler handler;
327 XRootDStatus st = PgRead( offset, size, buffer, &handler, timeout );
328 if( !st.IsOK() )
329 return st;
330
331 PageInfo *pageInfo = 0;
332 XRootDStatus status = MessageUtils::WaitForResponse( &handler, pageInfo );
333 if( status.IsOK() )
334 {
335 bytesRead = pageInfo->GetLength();
336 cksums = pageInfo->GetCksums();
337 delete pageInfo;
338 }
339 return status;
340 }
341
342 //----------------------------------------------------------------------------
343 // Write a data chunk at a given offset - async
344 //----------------------------------------------------------------------------
345 XRootDStatus File::Write( uint64_t offset,
346 uint32_t size,
347 const void *buffer,
348 ResponseHandler *handler,
349 time_t timeout )
350 {
351 if( pPlugIn )
352 return pPlugIn->Write( offset, size, buffer, handler, timeout );
353
354 return FileStateHandler::Write( pImpl->pStateHandler, offset, size, buffer, handler, timeout );
355 }
356
357 //----------------------------------------------------------------------------
358 // Write a data chunk at a given offset - sync
359 //----------------------------------------------------------------------------
360 XRootDStatus File::Write( uint64_t offset,
361 uint32_t size,
362 const void *buffer,
363 time_t timeout )
364 {
365 SyncResponseHandler handler;
366 XRootDStatus st = Write( offset, size, buffer, &handler, timeout );
367 if( !st.IsOK() )
368 return st;
369
370 XRootDStatus status = MessageUtils::WaitForStatus( &handler );
371 return status;
372 }
373
374
375 XRootDStatus File::Write( uint64_t offset,
376 Buffer &&buffer,
377 ResponseHandler *handler,
378 time_t timeout )
379 {
380 if( pPlugIn )
381 return pPlugIn->Write( offset, std::move( buffer ), handler, timeout );
382
383 return FileStateHandler::Write( pImpl->pStateHandler, offset, std::move( buffer ), handler, timeout );
384 }
385
386 //----------------------------------------------------------------------------
387 // Write a data chunk at a given offset - async
388 //----------------------------------------------------------------------------
389 XRootDStatus File::Write( uint64_t offset,
390 Buffer &&buffer,
391 time_t timeout )
392 {
393 SyncResponseHandler handler;
394 XRootDStatus st = Write( offset, std::move( buffer ), &handler, timeout );
395 if( !st.IsOK() )
396 return st;
397
398 XRootDStatus status = MessageUtils::WaitForStatus( &handler );
399 return status;
400 }
401
402 //------------------------------------------------------------------------
403 // Write a data from a given file descriptor at a given offset - async
404 //------------------------------------------------------------------------
405 XRootDStatus File::Write( uint64_t offset,
406 uint32_t size,
407 Optional<uint64_t> fdoff,
408 int fd,
409 ResponseHandler *handler,
410 time_t timeout )
411 {
412 if( pPlugIn )
413 return pPlugIn->Write( offset, size, fdoff, fd, handler, timeout );
414
415 return FileStateHandler::Write( pImpl->pStateHandler, offset, size, fdoff, fd, handler, timeout );
416 }
417
418 //------------------------------------------------------------------------
419 // Write a data from a given file descriptor at a given offset - sync
420 //------------------------------------------------------------------------
421 XRootDStatus File::Write( uint64_t offset,
422 uint32_t size,
423 Optional<uint64_t> fdoff,
424 int fd,
425 time_t timeout )
426 {
427 SyncResponseHandler handler;
428 XRootDStatus st = Write( offset, size, fdoff, fd, &handler, timeout );
429 if( !st.IsOK() )
430 return st;
431
432 XRootDStatus status = MessageUtils::WaitForStatus( &handler );
433 return status;
434 }
435
436 //------------------------------------------------------------------------
437 // Write number of pages at a given offset - async
438 //------------------------------------------------------------------------
439 XRootDStatus File::PgWrite( uint64_t offset,
440 uint32_t size,
441 const void *buffer,
442 std::vector<uint32_t> &cksums,
443 ResponseHandler *handler,
444 time_t timeout )
445 {
446 if( pPlugIn )
447 return pPlugIn->PgWrite( offset, size, buffer, cksums, handler, timeout );
448
449 return FileStateHandler::PgWrite( pImpl->pStateHandler, offset, size, buffer, cksums, handler, timeout );
450 }
451
452 //------------------------------------------------------------------------
453 // Write number of pages at a given offset - sync
454 //------------------------------------------------------------------------
455 XRootDStatus File::PgWrite( uint64_t offset,
456 uint32_t size,
457 const void *buffer,
458 std::vector<uint32_t> &cksums,
459 time_t timeout )
460 {
461 SyncResponseHandler handler;
462 XRootDStatus st = PgWrite( offset, size, buffer, cksums, &handler, timeout );
463 if( !st.IsOK() )
464 return st;
465
466 XRootDStatus status = MessageUtils::WaitForStatus( &handler );
467 return status;
468 }
469
470 //----------------------------------------------------------------------------
471 // Commit all pending disk writes - async
472 //----------------------------------------------------------------------------
474 time_t timeout )
475 {
476 if( pPlugIn )
477 return pPlugIn->Sync( handler, timeout );
478
479 return FileStateHandler::Sync( pImpl->pStateHandler, handler, timeout );
480 }
481
482 //----------------------------------------------------------------------------
483 // Commit all pending disk writes - sync
484 //----------------------------------------------------------------------------
485 XRootDStatus File::Sync( time_t timeout )
486 {
487 SyncResponseHandler handler;
488 XRootDStatus st = Sync( &handler, timeout );
489 if( !st.IsOK() )
490 return st;
491
492 XRootDStatus status = MessageUtils::WaitForStatus( &handler );
493 return status;
494 }
495
496 //----------------------------------------------------------------------------
497 // Truncate the file to a particular size - async
498 //----------------------------------------------------------------------------
500 ResponseHandler *handler,
501 time_t timeout )
502 {
503 if( pPlugIn )
504 return pPlugIn->Truncate( size, handler, timeout );
505
506 return FileStateHandler::Truncate( pImpl->pStateHandler, size, handler, timeout );
507 }
508
509
510 //----------------------------------------------------------------------------
511 // Truncate the file to a particular size - sync
512 //----------------------------------------------------------------------------
513 XRootDStatus File::Truncate( uint64_t size, time_t timeout )
514 {
515 SyncResponseHandler handler;
516 XRootDStatus st = Truncate( size, &handler, timeout );
517 if( !st.IsOK() )
518 return st;
519
520 XRootDStatus status = MessageUtils::WaitForStatus( &handler );
521 return status;
522 }
523
524 //----------------------------------------------------------------------------
525 // Preread scattered data tracts in one operation - async
526 //----------------------------------------------------------------------------
528 ResponseHandler *handler,
529 time_t timeout )
530 {
531 if( pPlugIn )
532 return pPlugIn->PreRead( tracts, handler, timeout );
533
534//** return FileStateHandler::PreRead( pImpl->pStateHandler, tracts, handler, timeout );
535 return XRootDStatus();
536 }
537
538 //----------------------------------------------------------------------------
539 // Preread scattered data tracts in one operation - sync
540 //----------------------------------------------------------------------------
542 time_t timeout )
543 {
544 SyncResponseHandler handler;
545 return PreRead( tracts, &handler, timeout );
546 }
547
548
549 //----------------------------------------------------------------------------
550 // Read scattered data chunks in one operation - async
551 //----------------------------------------------------------------------------
553 void *buffer,
554 ResponseHandler *handler,
555 time_t timeout )
556 {
557 if( pPlugIn )
558 return pPlugIn->VectorRead( chunks, buffer, handler, timeout );
559
560 return FileStateHandler::VectorRead( pImpl->pStateHandler, chunks, buffer, handler, timeout );
561 }
562
563 //----------------------------------------------------------------------------
564 // Read scattered data chunks in one operation - sync
565 //----------------------------------------------------------------------------
567 void *buffer,
568 VectorReadInfo *&vReadInfo,
569 time_t timeout )
570 {
571 SyncResponseHandler handler;
572 XRootDStatus st = VectorRead( chunks, buffer, &handler, timeout );
573 if( !st.IsOK() )
574 return st;
575
576 return MessageUtils::WaitForResponse( &handler, vReadInfo );
577 }
578
579 //------------------------------------------------------------------------
580 // Write scattered data chunks in one operation - async
581 //------------------------------------------------------------------------
583 ResponseHandler *handler,
584 time_t timeout )
585 {
586 if( pPlugIn )
587 return pPlugIn->VectorWrite( chunks, handler, timeout );
588
589 return FileStateHandler::VectorWrite( pImpl->pStateHandler, chunks, handler, timeout );
590 }
591
592 //------------------------------------------------------------------------
593 // Read scattered data chunks in one operation - sync
594 //------------------------------------------------------------------------
596 time_t timeout )
597 {
598 SyncResponseHandler handler;
599 XRootDStatus st = VectorWrite( chunks, &handler, timeout );
600 if( !st.IsOK() )
601 return st;
602
603 return MessageUtils::WaitForStatus( &handler );
604 }
605
606 //------------------------------------------------------------------------
607 // Write scattered buffers in one operation - async
608 //------------------------------------------------------------------------
609 XRootDStatus File::WriteV( uint64_t offset,
610 const struct iovec *iov,
611 int iovcnt,
612 ResponseHandler *handler,
613 time_t timeout )
614 {
615 if( pPlugIn )
616 return pPlugIn->WriteV( offset, iov, iovcnt, handler, timeout );
617
618 return FileStateHandler::WriteV( pImpl->pStateHandler, offset, iov, iovcnt, handler, timeout );
619 }
620
621 //------------------------------------------------------------------------
622 // Write scattered buffers in one operation - sync
623 //------------------------------------------------------------------------
624 XRootDStatus File::WriteV( uint64_t offset,
625 const struct iovec *iov,
626 int iovcnt,
627 time_t timeout )
628 {
629 SyncResponseHandler handler;
630 XRootDStatus st = WriteV( offset, iov, iovcnt, &handler, timeout );
631 if( !st.IsOK() )
632 return st;
633
634 XRootDStatus status = MessageUtils::WaitForStatus( &handler );
635 return status;
636 }
637
638 //------------------------------------------------------------------------
648 //------------------------------------------------------------------------
649 XRootDStatus File::ReadV( uint64_t offset,
650 struct iovec *iov,
651 int iovcnt,
652 ResponseHandler *handler,
653 time_t timeout )
654 {
655 return FileStateHandler::ReadV( pImpl->pStateHandler, offset, iov, iovcnt, handler, timeout );
656 }
657
658 //------------------------------------------------------------------------
668 //------------------------------------------------------------------------
669 XRootDStatus File::ReadV( uint64_t offset,
670 struct iovec *iov,
671 int iovcnt,
672 uint32_t &bytesRead,
673 time_t timeout )
674 {
675 SyncResponseHandler handler;
676 XRootDStatus st = ReadV( offset, iov, iovcnt, &handler, timeout );
677 if( !st.IsOK() )
678 return st;
679
680 VectorReadInfo *vrInfo = 0;
681 XRootDStatus status = MessageUtils::WaitForResponse( &handler, vrInfo );
682 if( status.IsOK() )
683 {
684 bytesRead = vrInfo->GetSize();
685 delete vrInfo;
686 }
687 return status;
688 }
689
690 //----------------------------------------------------------------------------
691 // Performs a custom operation on an open file, server implementation
692 // dependent - async
693 //----------------------------------------------------------------------------
695 ResponseHandler *handler,
696 time_t timeout )
697 {
698 if( pPlugIn )
699 return pPlugIn->Fcntl( arg, handler, timeout );
700
701 return FileStateHandler::Fcntl( pImpl->pStateHandler, QueryCode::Code::OpaqueQ, arg, handler, timeout );
702 }
703
704 //----------------------------------------------------------------------------
705 // Performs a custom operation on an open file, server implementation
706 // dependent - sync
707 //----------------------------------------------------------------------------
709 const Buffer &arg,
710 Buffer *&response,
711 time_t timeout )
712 {
713 SyncResponseHandler handler;
714 XRootDStatus st = Fcntl(queryCode, arg, &handler, timeout );
715 if( !st.IsOK() )
716 return st;
717
718 return MessageUtils::WaitForResponse( &handler, response );
719 }
720
721 //----------------------------------------------------------------------------
722 // Performs a custom operation on an open file, server implementation
723 // dependent - async
724 //----------------------------------------------------------------------------
726 const Buffer &arg,
727 ResponseHandler *handler,
728 time_t timeout )
729 {
730 if( pPlugIn )
731 return pPlugIn->Fcntl( queryCode, arg, handler, timeout );
732
733 return FileStateHandler::Fcntl(pImpl->pStateHandler, queryCode, arg, handler, timeout );
734 }
735
736 //----------------------------------------------------------------------------
737 // Performs a custom operation on an open file, server implementation
738 // dependent - sync
739 //----------------------------------------------------------------------------
741 Buffer *&response,
742 time_t timeout )
743 {
744 SyncResponseHandler handler;
745 XRootDStatus st = Fcntl( arg, &handler, timeout );
746 if( !st.IsOK() )
747 return st;
748
749 return MessageUtils::WaitForResponse( &handler, response );
750 }
751
752 //------------------------------------------------------------------------
754 //------------------------------------------------------------------------
756 time_t timeout )
757 {
758 if( pPlugIn )
759 return pPlugIn->Visa( handler, timeout );
760
761 return FileStateHandler::Visa( pImpl->pStateHandler, handler, timeout );
762 }
763
764 //----------------------------------------------------------------------------
765 // Get access token to a file - sync
766 //----------------------------------------------------------------------------
768 time_t timeout )
769 {
770 SyncResponseHandler handler;
771 XRootDStatus st = Visa( &handler, timeout );
772 if( !st.IsOK() )
773 return st;
774
775 return MessageUtils::WaitForResponse( &handler, visa );
776 }
777
778 //------------------------------------------------------------------------
779 // Set extended attributes - async
780 //------------------------------------------------------------------------
781 XRootDStatus File::SetXAttr( const std::vector<xattr_t> &attrs,
782 ResponseHandler *handler,
783 time_t timeout )
784 {
785 if( pPlugIn )
787
788 return FileStateHandler::SetXAttr( pImpl->pStateHandler, attrs, handler, timeout );
789 }
790
791 //------------------------------------------------------------------------
792 // Set extended attributes - sync
793 //------------------------------------------------------------------------
794 XRootDStatus File::SetXAttr( const std::vector<xattr_t> &attrs,
795 std::vector<XAttrStatus> &result,
796 time_t timeout )
797 {
798 SyncResponseHandler handler;
799 XRootDStatus st = SetXAttr( attrs, &handler, timeout );
800 if( !st.IsOK() )
801 return st;
802
803 std::vector<XAttrStatus> *resp = 0;
804 st = MessageUtils::WaitForResponse( &handler, resp );
805 if( resp ) result.swap( *resp );
806 delete resp;
807
808 return st;
809 }
810
811 //------------------------------------------------------------------------
812 // Get extended attributes - async
813 //------------------------------------------------------------------------
814 XRootDStatus File::GetXAttr( const std::vector<std::string> &attrs,
815 ResponseHandler *handler,
816 time_t timeout )
817 {
818 if( pPlugIn )
820
821 return FileStateHandler::GetXAttr( pImpl->pStateHandler, attrs, handler, timeout );
822 }
823
824 //------------------------------------------------------------------------
825 // Get extended attributes - sync
826 //------------------------------------------------------------------------
827 XRootDStatus File::GetXAttr( const std::vector<std::string> &attrs,
828 std::vector<XAttr> &result,
829 time_t timeout )
830 {
831 SyncResponseHandler handler;
832 XRootDStatus st = GetXAttr( attrs, &handler, timeout );
833 if( !st.IsOK() )
834 return st;
835
836 std::vector<XAttr> *resp = 0;
837 st = MessageUtils::WaitForResponse( &handler, resp );
838 if( resp ) result.swap( *resp );
839 delete resp;
840
841 return st;
842 }
843
844 //------------------------------------------------------------------------
845 // Delete extended attributes - async
846 //------------------------------------------------------------------------
847 XRootDStatus File::DelXAttr( const std::vector<std::string> &attrs,
848 ResponseHandler *handler,
849 time_t timeout )
850 {
851 if( pPlugIn )
853
854 return FileStateHandler::DelXAttr( pImpl->pStateHandler, attrs, handler, timeout );
855 }
856
857 //------------------------------------------------------------------------
858 // Delete extended attributes - sync
859 //------------------------------------------------------------------------
860 XRootDStatus File::DelXAttr( const std::vector<std::string> &attrs,
861 std::vector<XAttrStatus> &result,
862 time_t timeout )
863 {
864 SyncResponseHandler handler;
865 XRootDStatus st = DelXAttr( attrs, &handler, timeout );
866 if( !st.IsOK() )
867 return st;
868
869 std::vector<XAttrStatus> *resp = 0;
870 st = MessageUtils::WaitForResponse( &handler, resp );
871 if( resp ) result.swap( *resp );
872 delete resp;
873
874 return st;
875 }
876
877 //------------------------------------------------------------------------
878 // List extended attributes - async
879 //------------------------------------------------------------------------
881 time_t timeout )
882 {
883 if( pPlugIn )
885
886 return FileStateHandler::ListXAttr( pImpl->pStateHandler, handler, timeout );
887 }
888
889 //------------------------------------------------------------------------
890 // List extended attributes - sync
891 //------------------------------------------------------------------------
892 XRootDStatus File::ListXAttr( std::vector<XAttr> &result,
893 time_t timeout )
894 {
895 SyncResponseHandler handler;
896 XRootDStatus st = ListXAttr( &handler, timeout );
897 if( !st.IsOK() )
898 return st;
899
900 std::vector<XAttr> *resp = 0;
901 st = MessageUtils::WaitForResponse( &handler, resp );
902 if( resp ) result.swap( *resp );
903 delete resp;
904
905 return st;
906 }
907
908 //------------------------------------------------------------------------
909 // Create a checkpoint
910 //------------------------------------------------------------------------
911 XRootDStatus File::Checkpoint( kXR_char code,
912 ResponseHandler *handler,
913 time_t timeout )
914 {
915 if( pPlugIn )
917
918 return FileStateHandler::Checkpoint( pImpl->pStateHandler, code, handler, timeout );
919 }
920
921 //------------------------------------------------------------------------
923 //------------------------------------------------------------------------
924 XRootDStatus File::ChkptWrt( uint64_t offset,
925 uint32_t size,
926 const void *buffer,
927 ResponseHandler *handler,
928 time_t timeout )
929 {
930 if( pPlugIn )
931 return XRootDStatus( stError, errNotSupported );
932
933 return FileStateHandler::ChkptWrt( pImpl->pStateHandler, offset, size, buffer, handler, timeout );
934 }
935
936 //------------------------------------------------------------------------
938 //------------------------------------------------------------------------
939 XRootDStatus File::ChkptWrtV( uint64_t offset,
940 const struct iovec *iov,
941 int iovcnt,
942 ResponseHandler *handler,
943 time_t timeout )
944 {
945 if( pPlugIn )
946 return XRootDStatus( stError, errNotSupported );
947
948 return FileStateHandler::ChkptWrtV( pImpl->pStateHandler, offset, iov, iovcnt, handler, timeout );
949 }
950
951 //------------------------------------------------------------------------
952 // Try different data server
953 //------------------------------------------------------------------------
955 {
956 return FileStateHandler::TryOtherServer( pImpl->pStateHandler, timeout );
957 }
958
959 //----------------------------------------------------------------------------
960 // Check if the file is open
961 //----------------------------------------------------------------------------
962 bool File::IsOpen() const
963 {
964 if( pPlugIn )
965 return pPlugIn->IsOpen();
966
967 return pImpl->pStateHandler->IsOpen();
968 }
969
970 //------------------------------------------------------------------------
972 //------------------------------------------------------------------------
973 bool File::IsSecure() const
974 {
975 if( pPlugIn )
976 return false;
977 return pImpl->pStateHandler->IsSecure();
978 }
979
980 //----------------------------------------------------------------------------
981 // Set file property
982 //----------------------------------------------------------------------------
983 bool File::SetProperty( const std::string &name, const std::string &value )
984 {
985 if( pPlugIn )
986 return pPlugIn->SetProperty( name, value );
987
988 return pImpl->pStateHandler->SetProperty( name, value );
989 }
990
991 //----------------------------------------------------------------------------
992 // Get file property
993 //----------------------------------------------------------------------------
994 bool File::GetProperty( const std::string &name, std::string &value ) const
995 {
996 if( pPlugIn )
997 return pPlugIn->GetProperty( name, value );
998
999 return pImpl->pStateHandler->GetProperty( name, value );
1000 }
1001
1002 //----------------------------------------------------------------------------
1003 // Private method: gets the exported file template for use by open or clone
1004 //----------------------------------------------------------------------------
1005 std::unique_ptr<ExportedFileTemplate> File::GetFileTemplate() const
1006 {
1007 if( pPlugIn )
1008 return pPlugIn->ExportTemplate();
1009
1010 return pImpl->pStateHandler->ExportTemplate( pImpl->pStateHandler );
1011 }
1012
1013 //----------------------------------------------------------------------------
1014 // Clone ranges from one or more files
1015 //----------------------------------------------------------------------------
1016 XRootDStatus File::Clone( const CloneLocations &locs, ResponseHandler *handler, time_t timeout )
1017 {
1018 if( pPlugIn )
1019 return pPlugIn->Clone( locs, handler, timeout );
1020
1021 return pImpl->pStateHandler->Clone( pImpl->pStateHandler, locs, handler, timeout );
1022 }
1023
1024 //----------------------------------------------------------------------------
1025 // Clone ranges from one or more files
1026 //----------------------------------------------------------------------------
1027 XRootDStatus File::Clone( const CloneLocations &locs, time_t timeout )
1028 {
1029 SyncResponseHandler handler;
1030 XRootDStatus st = Clone( locs, &handler, timeout );
1031 if( !st.IsOK() )
1032 return st;
1033
1034 return MessageUtils::WaitForStatus( &handler );
1035 }
1036
1037}
unsigned char kXR_char
Definition XPtypes.hh:65
struct stat Stat
Definition XrdCks.cc:49
Binary blob representation.
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 std::unique_ptr< ExportedFileTemplate > ExportTemplate() const
Handle the stateful operations.
static XRootDStatus TryOtherServer(std::shared_ptr< FileStateHandler > &self, time_t timeout)
Try other data server.
static XRootDStatus Read(std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus SetXAttr(std::shared_ptr< FileStateHandler > &self, const std::vector< xattr_t > &attrs, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus Visa(std::shared_ptr< FileStateHandler > &self, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus Fcntl(std::shared_ptr< FileStateHandler > &self, QueryCode::Code queryCode, const Buffer &arg, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus ListXAttr(std::shared_ptr< FileStateHandler > &self, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus Truncate(std::shared_ptr< FileStateHandler > &self, uint64_t size, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus Checkpoint(std::shared_ptr< FileStateHandler > &self, kXR_char code, ResponseHandler *handler, time_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, time_t timeout=0)
static XRootDStatus Stat(std::shared_ptr< FileStateHandler > &self, bool force, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus ChkptWrt(std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus Write(std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus Close(std::shared_ptr< FileStateHandler > &self, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus ReadV(std::shared_ptr< FileStateHandler > &self, uint64_t offset, struct iovec *iov, int iovcnt, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus DelXAttr(std::shared_ptr< FileStateHandler > &self, const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus Open(std::shared_ptr< FileStateHandler > &self, const std::string &url, OpenFlags::Flags flags, uint16_t mode, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus PgRead(std::shared_ptr< FileStateHandler > &self, uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus OpenUsingTemplate(std::shared_ptr< FileStateHandler > &self, ExportedFileTemplate *templ, const std::string &url, OpenFlags::Flags flags, uint16_t mode, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus Sync(std::shared_ptr< FileStateHandler > &self, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus ChkptWrtV(std::shared_ptr< FileStateHandler > &self, uint64_t offset, const struct iovec *iov, int iovcnt, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus GetXAttr(std::shared_ptr< FileStateHandler > &self, const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus WriteV(std::shared_ptr< FileStateHandler > &self, uint64_t offset, const struct iovec *iov, int iovcnt, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus VectorRead(std::shared_ptr< FileStateHandler > &self, const ChunkList &chunks, void *buffer, ResponseHandler *handler, time_t timeout=0)
static XRootDStatus VectorWrite(std::shared_ptr< FileStateHandler > &self, const ChunkList &chunks, ResponseHandler *handler, time_t timeout=0)
bool IsSecure() const
Check if the file is using an encrypted connection.
Definition XrdClFile.cc:973
XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:125
XRootDStatus ReadV(uint64_t offset, struct iovec *iov, int iovcnt, ResponseHandler *handler, time_t timeout=0)
Definition XrdClFile.cc:649
friend struct CloneLocations
Definition XrdClFile.hh:54
XRootDStatus VectorRead(const ChunkList &chunks, void *buffer, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:552
@ EnableVirtRedirect
Definition XrdClFile.hh:58
XRootDStatus PgRead(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:304
XRootDStatus Sync(ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:473
XRootDStatus WriteV(uint64_t offset, const struct iovec *iov, int iovcnt, ResponseHandler *handler, time_t timeout=0)
Definition XrdClFile.cc:609
bool IsOpen() const
Check if the file is open.
Definition XrdClFile.cc:962
XRootDStatus Fcntl(const Buffer &arg, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:694
XRootDStatus Clone(const CloneLocations &locs, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
XRootDStatus OpenUsingTemplate(const File &rfile, const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:151
XRootDStatus Visa(ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Get access token to a file - async.
Definition XrdClFile.cc:755
XRootDStatus TryOtherServer(time_t timeout=0)
Definition XrdClFile.cc:954
XRootDStatus Truncate(uint64_t size, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:499
XRootDStatus SetXAttr(const std::vector< xattr_t > &attrs, ResponseHandler *handler, time_t timeout=0)
Definition XrdClFile.cc:781
bool GetProperty(const std::string &name, std::string &value) const
Definition XrdClFile.cc:994
XRootDStatus ListXAttr(ResponseHandler *handler, time_t timeout=0)
Definition XrdClFile.cc:880
XRootDStatus PreRead(const TractList &tracts, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:527
File(bool enablePlugIns=true)
Definition XrdClFile.cc:59
XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:265
XRootDStatus GetXAttr(const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout=0)
Definition XrdClFile.cc:814
virtual ~File()
Destructor.
Definition XrdClFile.cc:88
XRootDStatus Close(ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:210
bool SetProperty(const std::string &name, const std::string &value)
Definition XrdClFile.cc:983
XRootDStatus Stat(bool force, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:236
XRootDStatus PgWrite(uint64_t offset, uint32_t size, const void *buffer, std::vector< uint32_t > &cksums, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:439
XRootDStatus VectorWrite(const ChunkList &chunks, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:582
XRootDStatus DelXAttr(const std::vector< std::string > &attrs, ResponseHandler *handler, time_t timeout=0)
Definition XrdClFile.cc:847
XRootDStatus Write(uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, time_t timeout=0) XRD_WARN_UNUSED_RESULT
Definition XrdClFile.cc:345
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.
const uint64_t FileMsg
FcntlImpl< false > Fcntl
VisaImpl< false > Visa
const uint16_t suAlreadyDone
std::vector< TractInfo > TractList
List of Tracts.
const uint16_t errInvalidArgs
std::vector< ChunkInfo > ChunkList
List of chunks.
const uint16_t errNotSupported
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.
@ Samefs
Open file on the same filesystem as another.
@ Dup
Open file duplicating content from another.
std::vector< uint32_t > & GetCksums()
Get the checksums.
uint32_t GetLength() const
Get the data length.
Code
XRootD query request codes.
@ OpaqueQ
Implementation dependent.
uint16_t code
Error type, or additional hints on what to do.
bool IsOK() const
We're fine.