00001 //------------------------------------------------------------------------------ 00002 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN) 00003 // Author: Lukasz Janyst <ljanyst@cern.ch> 00004 //------------------------------------------------------------------------------ 00005 // This file is part of the XRootD software suite. 00006 // 00007 // XRootD is free software: you can redistribute it and/or modify 00008 // it under the terms of the GNU Lesser General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // XRootD is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public License 00018 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 00019 // 00020 // In applying this licence, CERN does not waive the privileges and immunities 00021 // granted to it by virtue of its status as an Intergovernmental Organization 00022 // or submit itself to any jurisdiction. 00023 //------------------------------------------------------------------------------ 00024 00025 #ifndef __XRD_CL_FILE_SYSTEM_HH__ 00026 #define __XRD_CL_FILE_SYSTEM_HH__ 00027 00028 #include "XrdCl/XrdClURL.hh" 00029 #include "XrdCl/XrdClStatus.hh" 00030 #include "XrdOuc/XrdOucEnum.hh" 00031 #include "XrdCl/XrdClXRootDResponses.hh" 00032 #include "XrdSys/XrdSysPthread.hh" 00033 #include "XProtocol/XProtocol.hh" 00034 #include <string> 00035 #include <vector> 00036 00037 namespace XrdCl 00038 { 00039 class PostMaster; 00040 class Message; 00041 class FileSystemPlugIn; 00042 struct MessageSendParams; 00043 00044 //---------------------------------------------------------------------------- 00046 //---------------------------------------------------------------------------- 00047 struct QueryCode 00048 { 00049 //-------------------------------------------------------------------------- 00051 //-------------------------------------------------------------------------- 00052 enum Code 00053 { 00054 Config = kXR_Qconfig, 00055 ChecksumCancel = kXR_Qckscan, 00056 Checksum = kXR_Qcksum, 00057 Opaque = kXR_Qopaque, 00058 OpaqueFile = kXR_Qopaquf, 00059 Prepare = kXR_QPrep, 00060 Space = kXR_Qspace, 00061 Stats = kXR_QStats, 00062 Visa = kXR_Qvisa, 00063 XAttr = kXR_Qxattr 00064 }; 00065 }; 00066 00067 //---------------------------------------------------------------------------- 00069 //---------------------------------------------------------------------------- 00070 struct OpenFlags 00071 { 00072 //-------------------------------------------------------------------------- 00074 //-------------------------------------------------------------------------- 00075 enum Flags 00076 { 00077 None = 0, 00078 Delete = kXR_delete, 00079 00080 Force = kXR_force, 00081 00082 MakePath = kXR_mkpath, 00083 00084 New = kXR_new, 00085 00086 NoWait = kXR_nowait, 00087 00088 00089 00090 00091 00092 Append = kXR_open_apnd, 00093 Read = kXR_open_read, 00094 Update = kXR_open_updt, 00095 Write = kXR_open_wrto, 00096 POSC = kXR_posc, 00097 00098 Refresh = kXR_refresh, 00099 00100 Replica = kXR_replica, 00101 00102 SeqIO = kXR_seqio, 00103 PrefName = kXR_prefname 00104 00105 }; 00106 }; 00107 XRDOUC_ENUM_OPERATORS( OpenFlags::Flags ) 00108 00109 //---------------------------------------------------------------------------- 00111 //---------------------------------------------------------------------------- 00112 struct Access 00113 { 00114 //-------------------------------------------------------------------------- 00116 //-------------------------------------------------------------------------- 00117 enum Mode 00118 { 00119 None = 0, 00120 UR = kXR_ur, 00121 UW = kXR_uw, 00122 UX = kXR_ux, 00123 GR = kXR_gr, 00124 GW = kXR_gw, 00125 GX = kXR_gx, 00126 OR = kXR_or, 00127 OW = kXR_ow, 00128 OX = kXR_ox 00129 }; 00130 }; 00131 XRDOUC_ENUM_OPERATORS( Access::Mode ) 00132 00133 //---------------------------------------------------------------------------- 00135 //---------------------------------------------------------------------------- 00136 struct MkDirFlags 00137 { 00138 enum Flags 00139 { 00140 None = 0, 00141 MakePath = 1 00142 }; 00143 }; 00144 XRDOUC_ENUM_OPERATORS( MkDirFlags::Flags ) 00145 00146 //---------------------------------------------------------------------------- 00148 //---------------------------------------------------------------------------- 00149 struct DirListFlags 00150 { 00151 enum Flags 00152 { 00153 None = 0, 00154 Stat = 1, 00155 Locate = 2 00156 00157 }; 00158 }; 00159 XRDOUC_ENUM_OPERATORS( DirListFlags::Flags ) 00160 00161 //---------------------------------------------------------------------------- 00163 //---------------------------------------------------------------------------- 00164 struct PrepareFlags 00165 { 00166 enum Flags 00167 { 00168 None = 0, 00169 Colocate = kXR_coloc, 00170 Fresh = kXR_fresh, 00171 00172 Stage = kXR_stage, 00173 00174 WriteMode = kXR_wmode 00175 00176 }; 00177 }; 00178 XRDOUC_ENUM_OPERATORS( PrepareFlags::Flags ) 00179 00180 //---------------------------------------------------------------------------- 00182 //---------------------------------------------------------------------------- 00183 class FileSystem 00184 { 00185 friend class AssignLBHandler; 00186 friend class ForkHandler; 00187 00188 public: 00189 typedef std::vector<LocationInfo> LocationList; 00190 00191 //------------------------------------------------------------------------ 00196 //------------------------------------------------------------------------ 00197 FileSystem( const URL &url, bool enablePlugIns = true ); 00198 00199 //------------------------------------------------------------------------ 00201 //------------------------------------------------------------------------ 00202 ~FileSystem(); 00203 00204 //------------------------------------------------------------------------ 00215 //------------------------------------------------------------------------ 00216 XRootDStatus Locate( const std::string &path, 00217 OpenFlags::Flags flags, 00218 ResponseHandler *handler, 00219 uint16_t timeout = 0 ); 00220 00221 //------------------------------------------------------------------------ 00230 //------------------------------------------------------------------------ 00231 XRootDStatus Locate( const std::string &path, 00232 OpenFlags::Flags flags, 00233 LocationInfo *&response, 00234 uint16_t timeout = 0 ); 00235 00236 //------------------------------------------------------------------------ 00247 //------------------------------------------------------------------------ 00248 XRootDStatus DeepLocate( const std::string &path, 00249 OpenFlags::Flags flags, 00250 ResponseHandler *handler, 00251 uint16_t timeout = 0 ); 00252 00253 //------------------------------------------------------------------------ 00262 //------------------------------------------------------------------------ 00263 XRootDStatus DeepLocate( const std::string &path, 00264 OpenFlags::Flags flags, 00265 LocationInfo *&response, 00266 uint16_t timeout = 0 ); 00267 00268 //------------------------------------------------------------------------ 00277 //------------------------------------------------------------------------ 00278 XRootDStatus Mv( const std::string &source, 00279 const std::string &dest, 00280 ResponseHandler *handler, 00281 uint16_t timeout = 0 ); 00282 00283 //------------------------------------------------------------------------ 00291 //------------------------------------------------------------------------ 00292 XRootDStatus Mv( const std::string &source, 00293 const std::string &dest, 00294 uint16_t timeout = 0 ); 00295 00296 //------------------------------------------------------------------------ 00307 //------------------------------------------------------------------------ 00308 XRootDStatus Query( QueryCode::Code queryCode, 00309 const Buffer &arg, 00310 ResponseHandler *handler, 00311 uint16_t timeout = 0 ); 00312 00313 //------------------------------------------------------------------------ 00322 //------------------------------------------------------------------------ 00323 XRootDStatus Query( QueryCode::Code queryCode, 00324 const Buffer &arg, 00325 Buffer *&response, 00326 uint16_t timeout = 0 ); 00327 00328 //------------------------------------------------------------------------ 00337 //------------------------------------------------------------------------ 00338 XRootDStatus Truncate( const std::string &path, 00339 uint64_t size, 00340 ResponseHandler *handler, 00341 uint16_t timeout = 0 ); 00342 00343 //------------------------------------------------------------------------ 00351 //------------------------------------------------------------------------ 00352 XRootDStatus Truncate( const std::string &path, 00353 uint64_t size, 00354 uint16_t timeout = 0 ); 00355 00356 //------------------------------------------------------------------------ 00364 //------------------------------------------------------------------------ 00365 XRootDStatus Rm( const std::string &path, 00366 ResponseHandler *handler, 00367 uint16_t timeout = 0 ); 00368 00369 //------------------------------------------------------------------------ 00376 //------------------------------------------------------------------------ 00377 XRootDStatus Rm( const std::string &path, 00378 uint16_t timeout = 0 ); 00379 00380 //------------------------------------------------------------------------ 00390 //------------------------------------------------------------------------ 00391 XRootDStatus MkDir( const std::string &path, 00392 MkDirFlags::Flags flags, 00393 Access::Mode mode, 00394 ResponseHandler *handler, 00395 uint16_t timeout = 0 ); 00396 00397 //------------------------------------------------------------------------ 00406 //------------------------------------------------------------------------ 00407 XRootDStatus MkDir( const std::string &path, 00408 MkDirFlags::Flags flags, 00409 Access::Mode mode, 00410 uint16_t timeout = 0 ); 00411 00412 //------------------------------------------------------------------------ 00420 //------------------------------------------------------------------------ 00421 XRootDStatus RmDir( const std::string &path, 00422 ResponseHandler *handler, 00423 uint16_t timeout = 0 ); 00424 00425 //------------------------------------------------------------------------ 00432 //------------------------------------------------------------------------ 00433 XRootDStatus RmDir( const std::string &path, 00434 uint16_t timeout = 0 ); 00435 00436 //------------------------------------------------------------------------ 00445 //------------------------------------------------------------------------ 00446 XRootDStatus ChMod( const std::string &path, 00447 Access::Mode mode, 00448 ResponseHandler *handler, 00449 uint16_t timeout = 0 ); 00450 00451 //------------------------------------------------------------------------ 00459 //------------------------------------------------------------------------ 00460 XRootDStatus ChMod( const std::string &path, 00461 Access::Mode mode, 00462 uint16_t timeout = 0 ); 00463 00464 //------------------------------------------------------------------------ 00471 //------------------------------------------------------------------------ 00472 XRootDStatus Ping( ResponseHandler *handler, 00473 uint16_t timeout = 0 ); 00474 00475 //------------------------------------------------------------------------ 00481 //------------------------------------------------------------------------ 00482 XRootDStatus Ping( uint16_t timeout = 0 ); 00483 00484 //------------------------------------------------------------------------ 00494 //------------------------------------------------------------------------ 00495 XRootDStatus Stat( const std::string &path, 00496 ResponseHandler *handler, 00497 uint16_t timeout = 0 ); 00498 00499 //------------------------------------------------------------------------ 00507 //------------------------------------------------------------------------ 00508 XRootDStatus Stat( const std::string &path, 00509 StatInfo *&response, 00510 uint16_t timeout = 0 ); 00511 00512 //------------------------------------------------------------------------ 00522 //------------------------------------------------------------------------ 00523 XRootDStatus StatVFS( const std::string &path, 00524 ResponseHandler *handler, 00525 uint16_t timeout = 0 ); 00526 00527 //------------------------------------------------------------------------ 00535 //------------------------------------------------------------------------ 00536 XRootDStatus StatVFS( const std::string &path, 00537 StatInfoVFS *&response, 00538 uint16_t timeout = 0 ); 00539 00540 //------------------------------------------------------------------------ 00549 //------------------------------------------------------------------------ 00550 XRootDStatus Protocol( ResponseHandler *handler, 00551 uint16_t timeout = 0 ); 00552 00553 //------------------------------------------------------------------------ 00560 //------------------------------------------------------------------------ 00561 XRootDStatus Protocol( ProtocolInfo *&response, 00562 uint16_t timeout = 0 ); 00563 00564 //------------------------------------------------------------------------ 00575 //------------------------------------------------------------------------ 00576 XRootDStatus DirList( const std::string &path, 00577 DirListFlags::Flags flags, 00578 ResponseHandler *handler, 00579 uint16_t timeout = 0 ); 00580 00581 //------------------------------------------------------------------------ 00590 //------------------------------------------------------------------------ 00591 XRootDStatus DirList( const std::string &path, 00592 DirListFlags::Flags flags, 00593 DirectoryList *&response, 00594 uint16_t timeout = 0 ); 00595 00596 //------------------------------------------------------------------------ 00606 //------------------------------------------------------------------------ 00607 XRootDStatus SendInfo( const std::string &info, 00608 ResponseHandler *handler, 00609 uint16_t timeout = 0 ); 00610 00611 //------------------------------------------------------------------------ 00619 //------------------------------------------------------------------------ 00620 XRootDStatus SendInfo( const std::string &info, 00621 Buffer *&response, 00622 uint16_t timeout = 0 ); 00623 00624 //------------------------------------------------------------------------ 00636 //------------------------------------------------------------------------ 00637 XRootDStatus Prepare( const std::vector<std::string> &fileList, 00638 PrepareFlags::Flags flags, 00639 uint8_t priority, 00640 ResponseHandler *handler, 00641 uint16_t timeout = 0 ); 00642 00643 //------------------------------------------------------------------------ 00653 //------------------------------------------------------------------------ 00654 XRootDStatus Prepare( const std::vector<std::string> &fileList, 00655 PrepareFlags::Flags flags, 00656 uint8_t priority, 00657 Buffer *&response, 00658 uint16_t timeout = 0 ); 00659 00660 //------------------------------------------------------------------------ 00665 //------------------------------------------------------------------------ 00666 bool SetProperty( const std::string &name, const std::string &value ); 00667 00668 //------------------------------------------------------------------------ 00672 //------------------------------------------------------------------------ 00673 bool GetProperty( const std::string &name, std::string &value ) const; 00674 00675 private: 00676 00677 //------------------------------------------------------------------------ 00678 // Send a message in a locked environment 00679 //------------------------------------------------------------------------ 00680 Status Send( Message *msg, 00681 ResponseHandler *handler, 00682 MessageSendParams ¶ms ); 00683 00684 //------------------------------------------------------------------------ 00685 // Assign a load balancer if it has not already been assigned 00686 //------------------------------------------------------------------------ 00687 void AssignLoadBalancer( const URL &url ); 00688 00689 //------------------------------------------------------------------------ 00690 // Lock the internal lock 00691 //------------------------------------------------------------------------ 00692 void Lock() 00693 { 00694 pMutex.Lock(); 00695 } 00696 00697 //------------------------------------------------------------------------ 00698 // Unlock the internal lock 00699 //------------------------------------------------------------------------ 00700 void UnLock() 00701 { 00702 pMutex.UnLock(); 00703 } 00704 00705 XrdSysMutex pMutex; 00706 bool pLoadBalancerLookupDone; 00707 bool pFollowRedirects; 00708 URL *pUrl; 00709 FileSystemPlugIn *pPlugIn; 00710 }; 00711 } 00712 00713 #endif // __XRD_CL_FILE_SYSTEM_HH__