xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdClFileOperations.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2017 by European Organization for Nuclear Research (CERN)
3 // Author: Krzysztof Jamrog <krzysztof.piotr.jamrog@cern.ch>,
4 // Michal Simon <michal.simon@cern.ch>
5 //------------------------------------------------------------------------------
6 // This file is part of the XRootD software suite.
7 //
8 // XRootD is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Lesser General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // XRootD is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public License
19 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
20 //
21 // In applying this licence, CERN does not waive the privileges and immunities
22 // granted to it by virtue of its status as an Intergovernmental Organization
23 // or submit itself to any jurisdiction.
24 //------------------------------------------------------------------------------
25 
26 #ifndef __XRD_CL_FILE_OPERATIONS_HH__
27 #define __XRD_CL_FILE_OPERATIONS_HH__
28 
29 #include "XrdCl/XrdClFile.hh"
30 #include "XrdCl/XrdClOperations.hh"
32 #include "XrdCl/XrdClCtx.hh"
33 
34 namespace XrdCl
35 {
36 
37  //----------------------------------------------------------------------------
43  //----------------------------------------------------------------------------
44  template<template<bool> class Derived, bool HasHndl, typename Response, typename ... Arguments>
45  class FileOperation: public ConcreteOperation<Derived, HasHndl, Response, Arguments...>
46  {
47 
48  template<template<bool> class, bool, typename, typename ...> friend class FileOperation;
49 
50  public:
51  //------------------------------------------------------------------------
56  //------------------------------------------------------------------------
57  FileOperation( Ctx<File> f, Arguments... args): ConcreteOperation<Derived, false, Response, Arguments...>( std::move( args )... ), file( std::move( f ) )
58  {
59  }
60 
61  //------------------------------------------------------------------------
67  //------------------------------------------------------------------------
68  template<bool from>
70  ConcreteOperation<Derived, HasHndl, Response, Arguments...>( std::move( op ) ), file( op.file )
71  {
72 
73  }
74 
75  //------------------------------------------------------------------------
77  //------------------------------------------------------------------------
78  virtual ~FileOperation()
79  {
80 
81  }
82 
83  protected:
84 
85  //------------------------------------------------------------------------
87  //------------------------------------------------------------------------
89  };
90 
91  //----------------------------------------------------------------------------
93  //----------------------------------------------------------------------------
94  template<bool HasHndl>
97  {
98  //------------------------------------------------------------------------
104  //------------------------------------------------------------------------
105  struct ExResp : public Resp<void>
106  {
107  //--------------------------------------------------------------------
111  //--------------------------------------------------------------------
112  ExResp( const Ctx<File> &file ): file( file )
113  {
114  }
115 
116  //--------------------------------------------------------------------
121  //--------------------------------------------------------------------
122  inline ResponseHandler* Create( std::function<void( XRootDStatus&,
123  StatInfo& )> func )
124  {
125  return new ExOpenFuncWrapper( this->file, func );
126  }
127 
128  //--------------------------------------------------------------------
130  //--------------------------------------------------------------------
131  using Resp<void>::Create;
132 
133  //--------------------------------------------------------------------
135  //--------------------------------------------------------------------
137  };
138 
139  public:
140 
141  //------------------------------------------------------------------------
143  //------------------------------------------------------------------------
146  FileOperation<OpenImpl, HasHndl, Resp<void>, Arg<std::string>, Arg<OpenFlags::Flags>,
147  Arg<Access::Mode>>( std::move( f ), std::move( url ), std::move( flags ),
148  std::move( mode ) )
149  {
150  }
151 
152  //------------------------------------------------------------------------
158  //------------------------------------------------------------------------
159  template<bool from>
161  FileOperation<OpenImpl, HasHndl, Resp<void>, Arg<std::string>, Arg<OpenFlags::Flags>,
162  Arg<Access::Mode>>( std::move( open ) )
163  {
164  }
165 
166 
167  //------------------------------------------------------------------------
169  //------------------------------------------------------------------------
170  enum { UrlArg, FlagsArg, ModeArg };
171 
172  //------------------------------------------------------------------------
177  //------------------------------------------------------------------------
178  template<typename Hdlr>
179  OpenImpl<true> operator>>( Hdlr &&hdlr )
180  {
181  ExResp factory( *this->file );
182  return this->StreamImpl( factory.Create( hdlr ) );
183  }
184 
185  //------------------------------------------------------------------------
187  //------------------------------------------------------------------------
188  std::string ToString()
189  {
190  return "Open";
191  }
192 
193  protected:
194 
195  //------------------------------------------------------------------------
200  //------------------------------------------------------------------------
201  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
202  {
203  const std::string &url = std::get<UrlArg>( this->args );
204  OpenFlags::Flags flags = std::get<FlagsArg>( this->args );
205  Access::Mode mode = std::get<ModeArg>( this->args );
206  uint16_t timeout = pipelineTimeout < this->timeout ?
207  pipelineTimeout : this->timeout;
208  return this->file->Open( url, flags, mode, handler, timeout );
209  }
210  };
212 
213  //----------------------------------------------------------------------------
215  //----------------------------------------------------------------------------
216  template<bool HasHndl>
217  class ReadImpl: public FileOperation<ReadImpl, HasHndl, Resp<ChunkInfo>,
218  Arg<uint64_t>, Arg<uint32_t>, Arg<void*>>
219  {
220  public:
221 
222  //------------------------------------------------------------------------
224  //------------------------------------------------------------------------
227 
228  //------------------------------------------------------------------------
230  //------------------------------------------------------------------------
232 
233  //------------------------------------------------------------------------
235  //------------------------------------------------------------------------
236  std::string ToString()
237  {
238  return "Read";
239  }
240 
241  protected:
242 
243  //------------------------------------------------------------------------
249  //------------------------------------------------------------------------
250  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
251  {
252  uint64_t offset = std::get<OffsetArg>( this->args ).Get();
253  uint32_t size = std::get<SizeArg>( this->args ).Get();
254  void *buffer = std::get<BufferArg>( this->args ).Get();
255  uint16_t timeout = pipelineTimeout < this->timeout ?
256  pipelineTimeout : this->timeout;
257  return this->file->Read( offset, size, buffer, handler, timeout );
258  }
259  };
260 
261  //----------------------------------------------------------------------------
263  //----------------------------------------------------------------------------
265  Arg<void*> buffer, uint16_t timeout = 0 )
266  {
267  return ReadImpl<false>( std::move( file ), std::move( offset ), std::move( size ),
268  std::move( buffer ) ).Timeout( timeout );
269  }
270 
271  //----------------------------------------------------------------------------
273  //----------------------------------------------------------------------------
274  template<bool HasHndl>
275  class PgReadImpl: public FileOperation<PgReadImpl, HasHndl, Resp<PageInfo>,
276  Arg<uint64_t>, Arg<uint32_t>, Arg<void*>>
277  {
278  public:
279 
280  //------------------------------------------------------------------------
282  //------------------------------------------------------------------------
285 
286  //------------------------------------------------------------------------
288  //------------------------------------------------------------------------
290 
291  //------------------------------------------------------------------------
293  //------------------------------------------------------------------------
294  std::string ToString()
295  {
296  return "PgRead";
297  }
298 
299  protected:
300 
301  //------------------------------------------------------------------------
307  //------------------------------------------------------------------------
308  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
309  {
310  uint64_t offset = std::get<OffsetArg>( this->args ).Get();
311  uint32_t size = std::get<SizeArg>( this->args ).Get();
312  void *buffer = std::get<BufferArg>( this->args ).Get();
313  uint16_t timeout = pipelineTimeout < this->timeout ?
314  pipelineTimeout : this->timeout;
315  return this->file->PgRead( offset, size, buffer, handler, timeout );
316  }
317  };
318 
319  //----------------------------------------------------------------------------
321  //----------------------------------------------------------------------------
323  Arg<uint32_t> size, Arg<void*> buffer,
324  uint16_t timeout = 0 )
325  {
326  return PgReadImpl<false>( std::move( file ), std::move( offset ), std::move( size ),
327  std::move( buffer ) ).Timeout( timeout );
328  }
329 
330  //----------------------------------------------------------------------------
332  //----------------------------------------------------------------------------
333  template<typename RSP> struct ReadTrait { };
334 
335  template<> struct ReadTrait<ChunkInfo> { using RET = ReadImpl<false>; };
336 
337  template<> struct ReadTrait<PageInfo> { using RET = PgReadImpl<false>; };
338 
339  template<typename RSP> inline typename ReadTrait<RSP>::RET
340  RdWithRsp( Ctx<File> file, Arg<uint64_t> offset, Arg<uint32_t> size,
341  Arg<void*> buffer, uint16_t timeout = 0 );
342 
343  template<> inline ReadImpl<false>
345  Arg<void*> buffer, uint16_t timeout )
346  {
347  return Read( std::move( file ), std::move( offset ), std::move( size ),
348  std::move( buffer ), timeout );
349  }
350 
351  template<> inline PgReadImpl<false>
353  Arg<void*> buffer, uint16_t timeout )
354  {
355  return PgRead( std::move( file ), std::move( offset ), std::move( size ),
356  std::move( buffer ), timeout );
357  }
358 
359  //----------------------------------------------------------------------------
361  //----------------------------------------------------------------------------
362  template<bool HasHndl>
363  class CloseImpl: public FileOperation<CloseImpl, HasHndl, Resp<void>>
364  {
365  public:
366 
367  //------------------------------------------------------------------------
369  //------------------------------------------------------------------------
371 
372  //------------------------------------------------------------------------
374  //------------------------------------------------------------------------
375  std::string ToString()
376  {
377  return "Close";
378  }
379 
380  protected:
381 
382  //------------------------------------------------------------------------
388  //------------------------------------------------------------------------
389  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
390  {
391  uint16_t timeout = pipelineTimeout < this->timeout ?
392  pipelineTimeout : this->timeout;
393  return this->file->Close( handler, timeout );
394  }
395  };
397 
398  //----------------------------------------------------------------------------
400  //----------------------------------------------------------------------------
401  template<bool HasHndl>
402  class StatImpl: public FileOperation<StatImpl, HasHndl, Resp<StatInfo>, Arg<bool>>
403  {
404  public:
405 
406  //------------------------------------------------------------------------
408  //------------------------------------------------------------------------
410 
411  //------------------------------------------------------------------------
413  //------------------------------------------------------------------------
414  enum { ForceArg };
415 
416  //------------------------------------------------------------------------
418  //------------------------------------------------------------------------
419  std::string ToString()
420  {
421  return "Stat";
422  }
423 
424  protected:
425 
426  //------------------------------------------------------------------------
432  //------------------------------------------------------------------------
433  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
434  {
435  bool force = std::get<ForceArg>( this->args ).Get();
436  uint16_t timeout = pipelineTimeout < this->timeout ?
437  pipelineTimeout : this->timeout;
438  return this->file->Stat( force, handler, timeout );
439  }
440  };
441 
442  //----------------------------------------------------------------------------
445  //----------------------------------------------------------------------------
446  inline StatImpl<false> Stat( Ctx<File> file, Arg<bool> force, uint16_t timeout = 0 )
447  {
448  return StatImpl<false>( std::move( file ), std::move( force ) ).Timeout( timeout );
449  }
450 
451  //----------------------------------------------------------------------------
453  //----------------------------------------------------------------------------
454  template<bool HasHndl>
455  class WriteImpl: public FileOperation<WriteImpl, HasHndl, Resp<void>, Arg<uint64_t>,
456  Arg<uint32_t>, Arg<const void*>>
457  {
458  public:
459 
460  //------------------------------------------------------------------------
462  //------------------------------------------------------------------------
465 
466  //------------------------------------------------------------------------
468  //------------------------------------------------------------------------
470 
471  //------------------------------------------------------------------------
473  //------------------------------------------------------------------------
474  std::string ToString()
475  {
476  return "Write";
477  }
478 
479  protected:
480 
481  //------------------------------------------------------------------------
487  //------------------------------------------------------------------------
488  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
489  {
490  uint64_t offset = std::get<OffsetArg>( this->args ).Get();
491  uint32_t size = std::get<SizeArg>( this->args ).Get();
492  const void *buffer = std::get<BufferArg>( this->args ).Get();
493  uint16_t timeout = pipelineTimeout < this->timeout ?
494  pipelineTimeout : this->timeout;
495  return this->file->Write( offset, size, buffer, handler, timeout );
496  }
497  };
498 
499  //----------------------------------------------------------------------------
501  //----------------------------------------------------------------------------
503  Arg<const void*> buffer, uint16_t timeout = 0 )
504  {
505  return WriteImpl<false>( std::move( file ), std::move( offset ), std::move( size ),
506  std::move( buffer ) ).Timeout( timeout );
507  }
508 
509  //----------------------------------------------------------------------------
511  //----------------------------------------------------------------------------
512  template<bool HasHndl>
513  class SyncImpl: public FileOperation<SyncImpl, HasHndl, Resp<void>>
514  {
515  public:
516 
517  //------------------------------------------------------------------------
519  //------------------------------------------------------------------------
521 
522  //------------------------------------------------------------------------
524  //------------------------------------------------------------------------
525  std::string ToString()
526  {
527  return "Sync";
528  }
529 
530  protected:
531 
532  //------------------------------------------------------------------------
538  //------------------------------------------------------------------------
539  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
540  {
541  uint16_t timeout = pipelineTimeout < this->timeout ?
542  pipelineTimeout : this->timeout;
543  return this->file->Sync( handler, timeout );
544  }
545  };
547 
548  //----------------------------------------------------------------------------
550  //----------------------------------------------------------------------------
551  template<bool HasHndl>
552  class TruncateImpl: public FileOperation<TruncateImpl, HasHndl, Resp<void>, Arg<uint64_t>>
553  {
554  public:
555 
556  //------------------------------------------------------------------------
558  //------------------------------------------------------------------------
560 
561  //------------------------------------------------------------------------
563  //------------------------------------------------------------------------
564  enum { SizeArg };
565 
566  //------------------------------------------------------------------------
568  //------------------------------------------------------------------------
569  std::string ToString()
570  {
571  return "Truncate";
572  }
573 
574  protected:
575 
576  //------------------------------------------------------------------------
582  //------------------------------------------------------------------------
583  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
584  {
585  uint64_t size = std::get<SizeArg>( this->args ).Get();
586  uint16_t timeout = pipelineTimeout < this->timeout ?
587  pipelineTimeout : this->timeout;
588  return this->file->Truncate( size, handler, timeout );
589  }
590  };
591 
592  //----------------------------------------------------------------------------
595  //----------------------------------------------------------------------------
597  {
598  return TruncateImpl<false>( std::move( file ), std::move( size ) );
599  }
600 
601  //----------------------------------------------------------------------------
603  //----------------------------------------------------------------------------
604  template<bool HasHndl>
605  class VectorReadImpl: public FileOperation<VectorReadImpl, HasHndl,
606  Resp<VectorReadInfo>, Arg<ChunkList>, Arg<void*>>
607  {
608  public:
609 
610  //------------------------------------------------------------------------
612  //------------------------------------------------------------------------
615 
616  //------------------------------------------------------------------------
618  //------------------------------------------------------------------------
619  enum { ChunksArg, BufferArg };
620 
621  //------------------------------------------------------------------------
623  //------------------------------------------------------------------------
624  std::string ToString()
625  {
626  return "VectorRead";
627  }
628 
629  protected:
630 
631  //------------------------------------------------------------------------
637  //------------------------------------------------------------------------
638  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
639  {
640  ChunkList &chunks = std::get<ChunksArg>( this->args ).Get();
641  void *buffer = std::get<BufferArg>( this->args ).Get();
642  uint16_t timeout = pipelineTimeout < this->timeout ?
643  pipelineTimeout : this->timeout;
644  return this->file->VectorRead( chunks, buffer, handler, timeout );
645  }
646  };
648 
649  //----------------------------------------------------------------------------
651  //----------------------------------------------------------------------------
652  template<bool HasHndl>
653  class VectorWriteImpl: public FileOperation<VectorWriteImpl, HasHndl, Resp<void>,
654  Arg<ChunkList>>
655  {
656  public:
657 
658  //------------------------------------------------------------------------
660  //------------------------------------------------------------------------
662 
663  //------------------------------------------------------------------------
665  //------------------------------------------------------------------------
666  enum { ChunksArg };
667 
668  //------------------------------------------------------------------------
670  //------------------------------------------------------------------------
671  std::string ToString()
672  {
673  return "VectorWrite";
674  }
675 
676  protected:
677 
678  //------------------------------------------------------------------------
684  //------------------------------------------------------------------------
685  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
686  {
687  const ChunkList &chunks = std::get<ChunksArg>( this->args ).Get();
688  uint16_t timeout = pipelineTimeout < this->timeout ?
689  pipelineTimeout : this->timeout;
690  return this->file->VectorWrite( chunks, handler, timeout );
691  }
692  };
694 
695  //----------------------------------------------------------------------------
697  //----------------------------------------------------------------------------
698  template<bool HasHndl>
699  class WriteVImpl: public FileOperation<WriteVImpl, HasHndl, Resp<void>, Arg<uint64_t>,
700  Arg<std::vector<iovec>>>
701  {
702  public:
703 
704  //------------------------------------------------------------------------
706  //------------------------------------------------------------------------
709 
710  //------------------------------------------------------------------------
712  //------------------------------------------------------------------------
713  enum { OffsetArg, IovArg };
714 
715  //------------------------------------------------------------------------
717  //------------------------------------------------------------------------
718  std::string ToString()
719  {
720  return "WriteV";
721  }
722 
723  protected:
724 
725  //------------------------------------------------------------------------
731  //------------------------------------------------------------------------
732  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
733  {
734  uint64_t offset = std::get<OffsetArg>( this->args ).Get();
735  std::vector<iovec> &stdiov = std::get<IovArg>( this->args ).Get();
736  uint16_t timeout = pipelineTimeout < this->timeout ?
737  pipelineTimeout : this->timeout;
738 
739  int iovcnt = stdiov.size();
740  iovec iov[iovcnt];
741  for( size_t i = 0; i < stdiov.size(); ++i )
742  {
743  iov[i].iov_base = stdiov[i].iov_base;
744  iov[i].iov_len = stdiov[i].iov_len;
745  }
746 
747  return this->file->WriteV( offset, iov, iovcnt, handler, timeout );
748  }
749  };
750 
751  //----------------------------------------------------------------------------
753  //----------------------------------------------------------------------------
755  Arg<std::vector<iovec>> iov, uint16_t timeout = 0 )
756  {
757  return WriteVImpl<false>( std::move( file ), std::move( offset ),
758  std::move( iov ) ).Timeout( timeout );
759  }
760 
761  //----------------------------------------------------------------------------
763  //----------------------------------------------------------------------------
764  template<bool HasHndl>
765  class FcntlImpl: public FileOperation<FcntlImpl, HasHndl, Resp<Buffer>, Arg<Buffer>>
766  {
767  public:
768 
769  //------------------------------------------------------------------------
771  //------------------------------------------------------------------------
773 
774  //------------------------------------------------------------------------
776  //------------------------------------------------------------------------
777  enum { BufferArg };
778 
779  //------------------------------------------------------------------------
781  //------------------------------------------------------------------------
782  std::string ToString()
783  {
784  return "Fcntl";
785  }
786 
787  protected:
788 
789  //------------------------------------------------------------------------
795  //------------------------------------------------------------------------
796  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
797  {
798  Buffer &arg = std::get<BufferArg>( this->args ).Get();
799  uint16_t timeout = pipelineTimeout < this->timeout ?
800  pipelineTimeout : this->timeout;
801  return this->file->Fcntl( arg, handler, timeout );
802  }
803  };
805 
806  //----------------------------------------------------------------------------
808  //----------------------------------------------------------------------------
809  template<bool HasHndl>
810  class VisaImpl: public FileOperation<VisaImpl, HasHndl, Resp<Buffer>>
811  {
812  public:
813 
814  //------------------------------------------------------------------------
816  //------------------------------------------------------------------------
818 
819  //------------------------------------------------------------------------
821  //------------------------------------------------------------------------
822  std::string ToString()
823  {
824  return "Visa";
825  }
826 
827  protected:
828 
829  //------------------------------------------------------------------------
835  //------------------------------------------------------------------------
836  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
837  {
838  uint16_t timeout = pipelineTimeout < this->timeout ?
839  pipelineTimeout : this->timeout;
840  return this->file->Visa( handler, timeout );
841  }
842  };
844 
845  //----------------------------------------------------------------------------
847  //----------------------------------------------------------------------------
848  template<bool HasHndl>
849  class SetXAttrImpl: public FileOperation<SetXAttrImpl, HasHndl, Resp<void>,
850  Arg<std::string>, Arg<std::string>>
851  {
852  public:
853 
854  //------------------------------------------------------------------------
856  //------------------------------------------------------------------------
859 
860  //------------------------------------------------------------------------
862  //------------------------------------------------------------------------
863  enum { NameArg, ValueArg };
864 
865  //------------------------------------------------------------------------
867  //------------------------------------------------------------------------
868  std::string ToString()
869  {
870  return "SetXAttrImpl";
871  }
872 
873  protected:
874 
875  //------------------------------------------------------------------------
881  //------------------------------------------------------------------------
882  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
883  {
884  std::string &name = std::get<NameArg>( this->args ).Get();
885  std::string &value = std::get<ValueArg>( this->args ).Get();
886  // wrap the arguments with a vector
887  std::vector<xattr_t> attrs;
888  attrs.push_back( xattr_t( name, value ) );
889  // wrap the PipelineHandler so the response gets unpacked properly
890  UnpackXAttrStatus *h = new UnpackXAttrStatus( handler );
891  uint16_t timeout = pipelineTimeout < this->timeout ?
892  pipelineTimeout : this->timeout;
893  XRootDStatus st = this->file->SetXAttr( attrs, h, timeout );
894  if( !st.IsOK() ) delete h;
895  return st;
896  }
897  };
898 
899  //----------------------------------------------------------------------------
902  //----------------------------------------------------------------------------
904  {
905  return SetXAttrImpl<false>( std::move( file ), std::move( name ), std::move( value ) );
906  }
907 
908  //----------------------------------------------------------------------------
910  //----------------------------------------------------------------------------
911  template<bool HasHndl>
912  class SetXAttrBulkImpl: public FileOperation<SetXAttrBulkImpl, HasHndl,
913  Resp<std::vector<XAttrStatus>>, Arg<std::vector<xattr_t>>>
914  {
915  public:
916 
917  //------------------------------------------------------------------------
919  //------------------------------------------------------------------------
922 
923  //------------------------------------------------------------------------
925  //------------------------------------------------------------------------
926  enum { AttrsArg };
927 
928  //------------------------------------------------------------------------
930  //------------------------------------------------------------------------
931  std::string ToString()
932  {
933  return "SetXAttrBulkImpl";
934  }
935 
936 
937  protected:
938 
939  //------------------------------------------------------------------------
945  //------------------------------------------------------------------------
946  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
947  {
948  std::vector<xattr_t> &attrs = std::get<AttrsArg>( this->args ).Get();
949  uint16_t timeout = pipelineTimeout < this->timeout ?
950  pipelineTimeout : this->timeout;
951  return this->file->SetXAttr( attrs, handler, timeout );
952  }
953  };
954 
955  //----------------------------------------------------------------------------
958  //----------------------------------------------------------------------------
959  inline SetXAttrBulkImpl<false> SetXAttr( Ctx<File> file, Arg<std::vector<xattr_t>> attrs )
960  {
961  return SetXAttrBulkImpl<false>( std::move( file ), std::move( attrs ) );
962  }
963 
964  //----------------------------------------------------------------------------
966  //----------------------------------------------------------------------------
967  template<bool HasHndl>
968  class GetXAttrImpl: public FileOperation<GetXAttrImpl, HasHndl, Resp<std::string>,
969  Arg<std::string>>
970  {
971  public:
972 
973  //------------------------------------------------------------------------
975  //------------------------------------------------------------------------
978 
979  //------------------------------------------------------------------------
981  //------------------------------------------------------------------------
982  enum { NameArg };
983 
984  //------------------------------------------------------------------------
986  //------------------------------------------------------------------------
987  std::string ToString()
988  {
989  return "GetXAttrImpl";
990  }
991 
992  protected:
993 
994  //------------------------------------------------------------------------
1000  //------------------------------------------------------------------------
1001  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
1002  {
1003  std::string &name = std::get<NameArg>( this->args ).Get();
1004  // wrap the argument with a vector
1005  std::vector<std::string> attrs;
1006  attrs.push_back( name );
1007  // wrap the PipelineHandler so the response gets unpacked properly
1008  UnpackXAttr *h = new UnpackXAttr( handler );
1009  uint16_t timeout = pipelineTimeout < this->timeout ?
1010  pipelineTimeout : this->timeout;
1011  XRootDStatus st = this->file->GetXAttr( attrs, h, timeout );
1012  if( !st.IsOK() ) delete h;
1013  return st;
1014  }
1015  };
1016 
1017  //----------------------------------------------------------------------------
1020  //----------------------------------------------------------------------------
1022  {
1023  return GetXAttrImpl<false>( std::move( file ), std::move( name ) );
1024  }
1025 
1026  //----------------------------------------------------------------------------
1028  //----------------------------------------------------------------------------
1029  template<bool HasHndl>
1030  class GetXAttrBulkImpl: public FileOperation<GetXAttrBulkImpl, HasHndl, Resp<std::vector<XAttr>>,
1031  Arg<std::vector<std::string>>>
1032  {
1033  public:
1034 
1035  //------------------------------------------------------------------------
1037  //------------------------------------------------------------------------
1040 
1041  //------------------------------------------------------------------------
1043  //------------------------------------------------------------------------
1044  enum { NamesArg };
1045 
1046  //------------------------------------------------------------------------
1048  //------------------------------------------------------------------------
1049  std::string ToString()
1050  {
1051  return "GetXAttrBulkImpl";
1052  }
1053 
1054 
1055  protected:
1056 
1057  //------------------------------------------------------------------------
1063  //------------------------------------------------------------------------
1064  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
1065  {
1066  std::vector<std::string> &attrs = std::get<NamesArg>( this->args ).Get();
1067  uint16_t timeout = pipelineTimeout < this->timeout ?
1068  pipelineTimeout : this->timeout;
1069  return this->file->GetXAttr( attrs, handler, timeout );
1070  }
1071  };
1072 
1073  //----------------------------------------------------------------------------
1076  //----------------------------------------------------------------------------
1077  inline GetXAttrBulkImpl<false> GetXAttr( Ctx<File> file, Arg<std::vector<std::string>> attrs )
1078  {
1079  return GetXAttrBulkImpl<false>( std::move( file ), std::move( attrs ) );
1080  }
1081 
1082  //----------------------------------------------------------------------------
1084  //----------------------------------------------------------------------------
1085  template<bool HasHndl>
1086  class DelXAttrImpl: public FileOperation<DelXAttrImpl, HasHndl, Resp<void>,
1087  Arg<std::string>>
1088  {
1089  public:
1090 
1091  //------------------------------------------------------------------------
1093  //------------------------------------------------------------------------
1095 
1096  //------------------------------------------------------------------------
1098  //------------------------------------------------------------------------
1099  enum { NameArg };
1100 
1101  //------------------------------------------------------------------------
1103  //------------------------------------------------------------------------
1104  std::string ToString()
1105  {
1106  return "DelXAttrImpl";
1107  }
1108 
1109  protected:
1110 
1111  //------------------------------------------------------------------------
1117  //------------------------------------------------------------------------
1118  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
1119  {
1120  std::string &name = std::get<NameArg>( this->args ).Get();
1121  // wrap the argument with a vector
1122  std::vector<std::string> attrs;
1123  attrs.push_back( name );
1124  // wrap the PipelineHandler so the response gets unpacked properly
1125  UnpackXAttrStatus *h = new UnpackXAttrStatus( handler );
1126  uint16_t timeout = pipelineTimeout < this->timeout ?
1127  pipelineTimeout : this->timeout;
1128  XRootDStatus st = this->file->DelXAttr( attrs, h, timeout );
1129  if( !st.IsOK() ) delete h;
1130  return st;
1131  }
1132  };
1133 
1134  //----------------------------------------------------------------------------
1137  //----------------------------------------------------------------------------
1139  {
1140  return DelXAttrImpl<false>( std::move( file ), std::move( name ) );
1141  }
1142 
1143  //----------------------------------------------------------------------------
1145  //----------------------------------------------------------------------------
1146  template<bool HasHndl>
1147  class DelXAttrBulkImpl: public FileOperation<DelXAttrBulkImpl, HasHndl,
1148  Resp<std::vector<XAttrStatus>>, Arg<std::vector<std::string>>>
1149  {
1150  public:
1151 
1152  //------------------------------------------------------------------------
1154  //------------------------------------------------------------------------
1157 
1158  //------------------------------------------------------------------------
1160  //------------------------------------------------------------------------
1161  enum { NamesArg };
1162 
1163  //------------------------------------------------------------------------
1165  //------------------------------------------------------------------------
1166  std::string ToString()
1167  {
1168  return "DelXAttrBulkImpl";
1169  }
1170 
1171 
1172  protected:
1173 
1174  //------------------------------------------------------------------------
1180  //------------------------------------------------------------------------
1181  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
1182  {
1183  std::vector<std::string> &attrs = std::get<NamesArg>( this->args ).Get();
1184  uint16_t timeout = pipelineTimeout < this->timeout ?
1185  pipelineTimeout : this->timeout;
1186  return this->file->DelXAttr( attrs, handler, timeout );
1187  }
1188  };
1189 
1190  //----------------------------------------------------------------------------
1193  //----------------------------------------------------------------------------
1194  inline DelXAttrBulkImpl<false> DelXAttr( Ctx<File> file, Arg<std::vector<std::string>> attrs )
1195  {
1196  return DelXAttrBulkImpl<false>( std::move( file ), std::move( attrs ) );
1197  }
1198 
1199  //----------------------------------------------------------------------------
1201  //----------------------------------------------------------------------------
1202  template<bool HasHndl>
1203  class ListXAttrImpl: public FileOperation<ListXAttrImpl, HasHndl,
1204  Resp<std::vector<XAttr>>>
1205  {
1206  public:
1207 
1208  //------------------------------------------------------------------------
1210  //------------------------------------------------------------------------
1212 
1213  //------------------------------------------------------------------------
1215  //------------------------------------------------------------------------
1216  std::string ToString()
1217  {
1218  return "ListXAttrImpl";
1219  }
1220 
1221 
1222  protected:
1223 
1224  //------------------------------------------------------------------------
1230  //------------------------------------------------------------------------
1231  XRootDStatus RunImpl( PipelineHandler *handler, uint16_t pipelineTimeout )
1232  {
1233  uint16_t timeout = pipelineTimeout < this->timeout ?
1234  pipelineTimeout : this->timeout;
1235  return this->file->ListXAttr( handler, timeout );
1236  }
1237  };
1238 
1239  //----------------------------------------------------------------------------
1242  //----------------------------------------------------------------------------
1244  {
1245  return ListXAttrImpl<false>( std::move( file ) );
1246  }
1247 }
1248 
1249 #endif // __XRD_CL_FILE_OPERATIONS_HH__
1250 
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:308
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:946
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:882
PgReadImpl< false > RdWithRsp< PageInfo >(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout)
Definition: XrdClFileOperations.hh:352
ListXAttrImpl< false > ListXAttr(Ctx< File > file)
Definition: XrdClFileOperations.hh:1243
std::string ToString()
Definition: XrdClFileOperations.hh:718
CloseImpl< false > Close
Definition: XrdClFileOperations.hh:396
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:1064
std::string ToString()
Definition: XrdClFileOperations.hh:868
FileOperation(FileOperation< Derived, from, Response, Arguments...> &&op)
Definition: XrdClFileOperations.hh:69
Close operation (.
Definition: XrdClFileOperations.hh:363
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:1181
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:1118
SetXAttrImpl< false > SetXAttr(Ctx< File > file, Arg< std::string > name, Arg< std::string > value)
Definition: XrdClFileOperations.hh:903
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:488
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:1231
ReadTrait< RSP >::RET RdWithRsp(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout=0)
Utility class for storing a pointer to operation context.
Definition: XrdClCtx.hh:37
std::vector< ChunkInfo > ChunkList
List of chunks.
Definition: XrdClXRootDResponses.hh:1046
VectorReadImpl< false > VectorRead
Definition: XrdClFileOperations.hh:647
VectorRead operation (.
Definition: XrdClFileOperations.hh:605
FcntlImpl< false > Fcntl
Definition: XrdClFileOperations.hh:804
std::string ToString()
Definition: XrdClFileOperations.hh:931
Object stat info.
Definition: XrdClXRootDResponses.hh:399
std::string ToString()
Definition: XrdClFileOperations.hh:375
std::string ToString()
Definition: XrdClFileOperations.hh:188
Definition: XrdClOperationTimeout.hh:19
std::string ToString()
Definition: XrdClFileOperations.hh:1166
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:638
Definition: XrdClXRootDResponses.hh:946
Ctx< File > file
The underlying XrdCl::File object.
Definition: XrdClFileOperations.hh:136
Definition: XrdClFileOperations.hh:619
DelXAttr bulk operation (.
Definition: XrdClFileOperations.hh:1147
Definition: XrdClFileOperations.hh:1044
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:539
VectorWrite operation (.
Definition: XrdClFileOperations.hh:653
uint16_t timeout
Operation timeout.
Definition: XrdClOperations.hh:766
Fcntl operation (.
Definition: XrdClFileOperations.hh:765
DelXAttrImpl< false > DelXAttr(Ctx< File > file, Arg< std::string > name)
Definition: XrdClFileOperations.hh:1138
SyncImpl< false > Sync
Definition: XrdClFileOperations.hh:546
PgReadImpl< false > PgRead(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout=0)
Factory for creating PgReadImpl objects.
Definition: XrdClFileOperations.hh:322
Definition: XrdClFileOperations.hh:713
SetXAttr operation (.
Definition: XrdClFileOperations.hh:849
std::string ToString()
Definition: XrdClFileOperations.hh:474
Visa operation (.
Definition: XrdClFileOperations.hh:810
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:796
FileOperation(Ctx< File > f, Arguments...args)
Definition: XrdClFileOperations.hh:57
ReadImpl< false > Read(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout=0)
Factory for creating ReadImpl objects.
Definition: XrdClFileOperations.hh:264
std::string ToString()
Definition: XrdClFileOperations.hh:569
Access mode.
Definition: XrdClFileSystem.hh:116
Definition: XrdClFileOperations.hh:713
GetXAttr operation (.
Definition: XrdClFileOperations.hh:968
std::string ToString()
Definition: XrdClFileOperations.hh:525
Definition: XrdClFileOperations.hh:231
Read operation (.
Definition: XrdClFileOperations.hh:217
std::string ToString()
Definition: XrdClFileOperations.hh:671
std::string ToString()
Definition: XrdClFileOperations.hh:782
Definition: XrdClFileOperations.hh:666
std::string ToString()
Definition: XrdClFileOperations.hh:236
OpenImpl< true > operator>>(Hdlr &&hdlr)
Definition: XrdClFileOperations.hh:179
std::string ToString()
Definition: XrdClFileOperations.hh:1216
Definition: XrdClFileOperations.hh:289
GetXAttrImpl< false > GetXAttr(Ctx< File > file, Arg< std::string > name)
Definition: XrdClFileOperations.hh:1021
Definition: XrdClFileOperations.hh:170
TruncateImpl< false > Truncate(Ctx< File > file, Arg< uint64_t > size)
Definition: XrdClFileOperations.hh:596
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:836
Definition: XrdClFileOperations.hh:982
VectorWriteImpl< false > VectorWrite
Definition: XrdClFileOperations.hh:693
ListXAttr bulk operation (.
Definition: XrdClFileOperations.hh:1203
std::string ToString()
Definition: XrdClFileOperations.hh:822
Definition: XrdClOperationHandlers.hh:623
Definition: XrdClFileOperations.hh:289
Truncate operation (.
Definition: XrdClFileOperations.hh:552
Definition: XrdClFileOperations.hh:469
WriteV operation (.
Definition: XrdClFileOperations.hh:699
Open flags, may be or&#39;d when appropriate.
Definition: XrdClFileSystem.hh:70
Definition: XrdClFileOperations.hh:469
Definition: XrdClFileOperations.hh:231
Definition: XrdOucIOVec.hh:65
std::string ToString()
Definition: XrdClFileOperations.hh:419
WriteImpl< false > Write(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< const void * > buffer, uint16_t timeout=0)
Factory for creating WriteImpl objects.
Definition: XrdClFileOperations.hh:502
Definition: XrdClFileOperations.hh:863
virtual ~FileOperation()
Destructor.
Definition: XrdClFileOperations.hh:78
SetXAttr bulk operation (.
Definition: XrdClFileOperations.hh:912
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:732
Definition: XrdClFileOperations.hh:469
Helper class for unpacking single XAttr from bulk response.
Definition: XrdClOperationHandlers.hh:76
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:201
std::tuple< Args...> args
Operation arguments.
Definition: XrdClOperations.hh:761
Definition: XrdClFileOperations.hh:619
Definition: XrdClArg.hh:232
Definition: XrdClFileOperations.hh:105
Definition: XrdClArg.hh:294
Stat operation (.
Definition: XrdClFileOperations.hh:402
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:583
Describe a data chunk for vector read.
Definition: XrdClXRootDResponses.hh:907
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:1001
Request status.
Definition: XrdClXRootDResponses.hh:218
StatImpl< false > Stat(Ctx< File > file, Arg< bool > force, uint16_t timeout=0)
Definition: XrdClFileOperations.hh:446
Definition: XrdClFileOperations.hh:231
GetXAttr bulk operation (.
Definition: XrdClFileOperations.hh:1030
Definition: XrdClFileOperations.hh:926
Sync operation (.
Definition: XrdClFileOperations.hh:513
std::string ToString()
Definition: XrdClFileOperations.hh:987
j template void())
Definition: XrdOucJson.hh:4121
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:250
Definition: XrdClOperations.hh:58
Lambda wrapper.
Definition: XrdClOperationHandlers.hh:311
OpenImpl(OpenImpl< from > &&open)
Definition: XrdClFileOperations.hh:160
Definition: XrdClFileOperations.hh:45
Handle an async response.
Definition: XrdClXRootDResponses.hh:1116
Definition: XrdClFileSystem.hh:123
Helper class for unpacking single XAttrStatus from bulk response.
Definition: XrdClOperationHandlers.hh:41
PgRead operation (.
Definition: XrdClFileOperations.hh:275
std::string ToString()
Definition: XrdClFileOperations.hh:624
Definition: XrdClFileOperations.hh:289
OpenImpl< false > Open
Definition: XrdClFileOperations.hh:211
Definition: XrdClFileOperations.hh:1099
friend class FileOperation
Definition: XrdClFileOperations.hh:48
ResponseHandler * Create(std::function< void(XRootDStatus &, StatInfo &)> func)
Definition: XrdClFileOperations.hh:122
Open operation (.
Definition: XrdClFileOperations.hh:95
Definition: XrdClFileOperations.hh:414
Mode
Access mode.
Definition: XrdClFileSystem.hh:121
std::string ToString()
Definition: XrdClFileOperations.hh:1104
Definition: XrdClFileOperations.hh:564
#define open
Definition: XrdPosix.hh:71
RdWithRsp: factory for creating ReadImpl/PgReadImpl objects.
Definition: XrdClFileOperations.hh:333
VisaImpl< false > Visa
Definition: XrdClFileOperations.hh:843
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:433
Definition: XrdClFileOperations.hh:1161
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:685
WriteVImpl< false > WriteV(Ctx< File > file, Arg< uint64_t > offset, Arg< std::vector< iovec >> iov, uint16_t timeout=0)
Factory for creating WriteVImpl objects.
Definition: XrdClFileOperations.hh:754
XRootDStatus RunImpl(PipelineHandler *handler, uint16_t pipelineTimeout)
Definition: XrdClFileOperations.hh:389
Flags
Open flags, may be or&#39;d when appropriate.
Definition: XrdClFileSystem.hh:75
std::tuple< std::string, std::string > xattr_t
Extended attribute key - value pair.
Definition: XrdClXRootDResponses.hh:289
bool IsOK() const
We&#39;re fine.
Definition: XrdClStatus.hh:123
Ctx< File > file
The file object itself.
Definition: XrdClFileOperations.hh:88
Write operation (.
Definition: XrdClFileOperations.hh:455
std::string ToString()
Definition: XrdClFileOperations.hh:1049
ExResp(const Ctx< File > &file)
Definition: XrdClFileOperations.hh:112
std::unique_ptr< PipelineHandler > handler
Operation handler.
Definition: XrdClOperations.hh:304
Definition: XrdClFileOperations.hh:863
OpenImpl(Ctx< File > f, Arg< std::string > url, Arg< OpenFlags::Flags > flags, Arg< Access::Mode > mode=Access::None)
Constructor (.
Definition: XrdClFileOperations.hh:144
std::string ToString()
Definition: XrdClFileOperations.hh:294
Binary blob representation.
Definition: XrdClBuffer.hh:33
DelXAttr operation (.
Definition: XrdClFileOperations.hh:1086
Definition: XrdClOperations.hh:541
Definition: XrdClFileOperations.hh:777
ReadImpl< false > RdWithRsp< ChunkInfo >(Ctx< File > file, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout)
Definition: XrdClFileOperations.hh:344