00001 #ifndef __SFS_INTERFACE_H__ 00002 #define __SFS_INTERFACE_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d S f s I n t e r f a c e . h h */ 00006 /* */ 00007 /* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00009 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00010 /* */ 00011 /* This file is part of the XRootD software suite. */ 00012 /* */ 00013 /* XRootD is free software: you can redistribute it and/or modify it under */ 00014 /* the terms of the GNU Lesser General Public License as published by the */ 00015 /* Free Software Foundation, either version 3 of the License, or (at your */ 00016 /* option) any later version. */ 00017 /* */ 00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00021 /* License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU Lesser General Public License */ 00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00026 /* */ 00027 /* The copyright holder's institutional names and contributor's names may not */ 00028 /* be used to endorse or promote products derived from this software without */ 00029 /* specific prior written permission of the institution or contributor. */ 00030 /******************************************************************************/ 00031 00032 #include <string.h> // For strlcpy() 00033 #include <errno.h> 00034 #include <sys/types.h> 00035 #include <sys/stat.h> 00036 00037 #include "XrdOuc/XrdOucErrInfo.hh" 00038 #include "XrdOuc/XrdOucIOVec.hh" 00039 #include "XrdOuc/XrdOucSFVec.hh" 00040 00041 /******************************************************************************/ 00042 /* O p e n M o d e s */ 00043 /******************************************************************************/ 00044 00045 #define SFS_O_RDONLY 0 // open read/only 00046 #define SFS_O_WRONLY 1 // open write/only 00047 #define SFS_O_RDWR 2 // open read/write 00048 #define SFS_O_CREAT 0x100 // used for file creation 00049 #define SFS_O_TRUNC 0x200 // used for file truncation 00050 #define SFS_O_MULTIW 0x400 // used for multi-write locations 00051 #define SFS_O_POSC 0x0100000 // persist on successful close 00052 #define SFS_O_FORCE 0x0200000 // used for locate only 00053 #define SFS_O_HNAME 0x0400000 // used for locate only 00054 #define SFS_O_LOCAL 0x0800000 // used for locate only (local cmd) 00055 #define SFS_O_NOWAIT 0x01000000 // do not impose operational delays 00056 #define SFS_O_RAWIO 0x02000000 // allow client-side decompression 00057 #define SFS_O_RESET 0x04000000 // Reset any cached information 00058 #define SFS_O_REPLICA 0x08000000 // Open for replication 00059 00060 // The following flag may be set in the access mode arg for open() & mkdir() 00061 // Note that on some systems mode_t is 16-bits so we use a careful value! 00062 // 00063 #define SFS_O_MKPTH 0x00004000 // Make directory path if missing 00064 00065 // The following options are here to provide a uniform clustering interface. 00066 // They may be passed through open/locate/stat, as applicable. 00067 // 00068 #define SFS_O_LOCATE 0x10000000 // This request generated by locate() 00069 #define SFS_O_STAT 0x20000000 // This request generated by stat() 00070 #define SFS_O_META 0x40000000 // This request generated by metaop 00071 00072 /******************************************************************************/ 00073 /* D e f i n e s */ 00074 /******************************************************************************/ 00075 00076 // Common fctl command values (0 to 255) 00077 // 00078 #define SFS_FCTL_GETFD 1 // Return file descriptor if possible 00079 #define SFS_FCTL_STATV 2 // Return visa information 00080 #define SFS_FCTL_SPEC1 3 // Return implementation defined information 00081 00082 #define SFS_SFIO_FDVAL 0x80000000 // Use SendData() method GETFD response value 00083 00084 // Common fsctl command values (0 to 255) 00085 // 00086 #define SFS_FSCTL_CMD 255 00087 00088 #define SFS_FSCTL_LOCATE 1 // Locate a file 00089 #define SFS_FSCTL_STATFS 2 // Return FS data 00090 #define SFS_FSCTL_STATLS 3 // Return LS data 00091 #define SFS_FSCTL_STATXA 4 // Return XA data 00092 #define SFS_FSCTL_STATCC 5 // Return Cluster Config status 00093 #define SFS_FSCTL_PLUGIN 8 // Return Implementation Dependent Data 00094 #define SFS_FSCTL_PLUGIO 16 // Return Implementation Dependent Data 00095 00096 // Return values for integer & XrdSfsXferSize returning XrdSfs methods 00097 // 00098 #define SFS_STALL 1 // Return value -> Seconds to stall client 00099 #define SFS_OK 0 // ErrInfo code -> All is well 00100 #define SFS_ERROR -1 // ErrInfo code -> Error occurred 00101 #define SFS_REDIRECT -256 // ErrInfo code -> Port number to redirect to 00102 #define SFS_STARTED -512 // ErrInfo code -> Estimated seconds to completion 00103 #define SFS_DATA -1024 // ErrInfo code -> Length of data 00104 #define SFS_DATAVEC -2048 // ErrInfo code -> Num iovec elements in msgbuff 00105 00106 // The following macros are used for dealing with special local paths 00107 // 00108 #define SFS_LCLPRFX "/=/" 00109 #define SFS_LCLPLEN 3 00110 #define SFS_LCLPATH(x) !strncmp(x, SFS_LCLPRFX, SFS_LCLPLEN) 00111 #define SFS_LCLPRFY "/=" 00112 #define SFS_LCLROOT(x) !strncmp(x, SFS_LCLPRFX, SFS_LCLPLEN-1) \ 00113 && (*(x+SFS_LCLPLEN-1) == '/' || *(x+SFS_LCLPLEN-1) == 0) 00114 00115 /******************************************************************************/ 00116 /* S t r u c t u r e s & T y p e d e f s */ 00117 /******************************************************************************/ 00118 00119 typedef long long XrdSfsFileOffset; 00120 typedef int XrdSfsFileOpenMode; 00121 typedef int XrdSfsMode; 00122 typedef int XrdSfsXferSize; 00123 00124 enum XrdSfsFileExistence 00125 { 00126 XrdSfsFileExistNo, 00127 XrdSfsFileExistIsFile, 00128 XrdSfsFileExistIsDirectory, 00129 XrdSfsFileExistIsOffline, 00130 XrdSfsFileExistIsOther 00131 }; 00132 //------------------------------------------------ 00133 00134 #define Prep_PRTY0 0 00135 #define Prep_PRTY1 1 00136 #define Prep_PRTY2 2 00137 #define Prep_PRTY3 3 00138 #define Prep_PMASK 3 00139 #define Prep_SENDAOK 4 00140 #define Prep_SENDERR 8 00141 #define Prep_SENDACK 12 00142 #define Prep_WMODE 16 00143 #define Prep_STAGE 32 00144 #define Prep_COLOC 64 00145 #define Prep_FRESH 128 00146 00147 class XrdOucTList; 00148 00149 struct XrdSfsFSctl 00150 { 00151 const char *Arg1; 00152 int Arg1Len; 00153 int Arg2Len; 00154 const char *Arg2; 00155 }; 00156 00157 struct XrdSfsPrep 00158 { 00159 char *reqid; 00160 char *notify; 00161 int opts; 00162 XrdOucTList *paths; 00163 XrdOucTList *oinfo; 00164 }; 00165 00166 /******************************************************************************/ 00167 /* A b s t r a c t C l a s s e s */ 00168 /******************************************************************************/ 00169 00170 class XrdSfsFile; 00171 class XrdSfsDirectory; 00172 class XrdOucEnv; 00173 class XrdOucTList; 00174 class XrdSecEntity; 00175 00176 /******************************************************************************/ 00177 /* X r d S f s F i l e S y s t e m */ 00178 /******************************************************************************/ 00179 00180 //----------------------------------------------------------------------------- 00204 //----------------------------------------------------------------------------- 00205 00206 class XrdSfsFileSystem 00207 { 00208 public: 00209 00210 //----------------------------------------------------------------------------- 00220 //----------------------------------------------------------------------------- 00221 00222 virtual XrdSfsDirectory *newDir(char *user=0, int MonID=0) = 0; 00223 00224 //----------------------------------------------------------------------------- 00234 //----------------------------------------------------------------------------- 00235 00236 virtual XrdSfsFile *newFile(char *user=0, int MonID=0) = 0; 00237 00238 //----------------------------------------------------------------------------- 00257 //----------------------------------------------------------------------------- 00258 00259 enum csFunc {csCalc = 0, csGet, csSize}; 00260 00261 virtual int chksum( csFunc Func, 00262 const char *csName, 00263 const char *path, 00264 XrdOucErrInfo &eInfo, 00265 const XrdSecEntity *client = 0, 00266 const char *opaque = 0) 00267 { 00268 (void)Func; (void)csName; (void)path; (void)eInfo; (void)client; 00269 (void)opaque; 00270 eInfo.setErrInfo(ENOTSUP, "Not supported."); 00271 return SFS_ERROR; 00272 } 00273 00274 //----------------------------------------------------------------------------- 00284 //----------------------------------------------------------------------------- 00285 00286 virtual int chmod(const char *path, 00287 XrdSfsMode mode, 00288 XrdOucErrInfo &eInfo, 00289 const XrdSecEntity *client = 0, 00290 const char *opaque = 0) = 0; 00291 00292 //----------------------------------------------------------------------------- 00296 //----------------------------------------------------------------------------- 00297 00298 virtual void Disc(const XrdSecEntity *client = 0) 00299 { 00300 (void)client; 00301 } 00302 00303 //----------------------------------------------------------------------------- 00308 //----------------------------------------------------------------------------- 00309 00310 virtual void EnvInfo(XrdOucEnv *envP) 00311 { 00312 (void)envP; 00313 } 00314 00315 //----------------------------------------------------------------------------- 00343 //----------------------------------------------------------------------------- 00344 00345 virtual int FSctl(const int cmd, 00346 XrdSfsFSctl &args, 00347 XrdOucErrInfo &eInfo, 00348 const XrdSecEntity *client = 0) 00349 { 00350 (void)cmd; (void)args; (void)eInfo; (void)client; 00351 return SFS_OK; 00352 } 00353 00354 //----------------------------------------------------------------------------- 00370 //----------------------------------------------------------------------------- 00371 00372 virtual int fsctl(const int cmd, 00373 const char *args, 00374 XrdOucErrInfo &eInfo, 00375 const XrdSecEntity *client = 0) = 0; 00376 00377 //----------------------------------------------------------------------------- 00387 //----------------------------------------------------------------------------- 00388 00389 virtual int getStats(char *buff, int blen) = 0; 00390 00391 //----------------------------------------------------------------------------- 00395 //----------------------------------------------------------------------------- 00396 00397 virtual const char *getVersion() = 0; 00398 00399 //----------------------------------------------------------------------------- 00415 //----------------------------------------------------------------------------- 00416 00417 virtual int exists(const char *path, 00418 XrdSfsFileExistence &eFlag, 00419 XrdOucErrInfo &eInfo, 00420 const XrdSecEntity *client = 0, 00421 const char *opaque = 0) = 0; 00422 00423 //----------------------------------------------------------------------------- 00433 //----------------------------------------------------------------------------- 00434 00435 virtual int mkdir(const char *path, 00436 XrdSfsMode mode, 00437 XrdOucErrInfo &eInfo, 00438 const XrdSecEntity *client = 0, 00439 const char *opaque = 0) = 0; 00440 00441 //----------------------------------------------------------------------------- 00449 //----------------------------------------------------------------------------- 00450 00451 virtual int prepare( XrdSfsPrep &pargs, 00452 XrdOucErrInfo &eInfo, 00453 const XrdSecEntity *client = 0) = 0; 00454 00455 //----------------------------------------------------------------------------- 00464 //----------------------------------------------------------------------------- 00465 00466 virtual int rem(const char *path, 00467 XrdOucErrInfo &eInfo, 00468 const XrdSecEntity *client = 0, 00469 const char *opaque = 0) = 0; 00470 00471 //----------------------------------------------------------------------------- 00480 //----------------------------------------------------------------------------- 00481 00482 virtual int remdir(const char *path, 00483 XrdOucErrInfo &eInfo, 00484 const XrdSecEntity *client = 0, 00485 const char *opaque = 0) = 0; 00486 00487 //----------------------------------------------------------------------------- 00498 //----------------------------------------------------------------------------- 00499 00500 virtual int rename(const char *oPath, 00501 const char *nPath, 00502 XrdOucErrInfo &eInfo, 00503 const XrdSecEntity *client = 0, 00504 const char *opaqueO = 0, 00505 const char *opaqueN = 0) = 0; 00506 00507 //----------------------------------------------------------------------------- 00518 //----------------------------------------------------------------------------- 00519 00520 virtual int stat(const char *Name, 00521 struct stat *buf, 00522 XrdOucErrInfo &eInfo, 00523 const XrdSecEntity *client = 0, 00524 const char *opaque = 0) = 0; 00525 00526 //----------------------------------------------------------------------------- 00538 //----------------------------------------------------------------------------- 00539 00540 virtual int stat(const char *path, 00541 mode_t &mode, 00542 XrdOucErrInfo &eInfo, 00543 const XrdSecEntity *client = 0, 00544 const char *opaque = 0) = 0; 00545 00546 //----------------------------------------------------------------------------- 00556 //----------------------------------------------------------------------------- 00557 00558 virtual int truncate(const char *path, 00559 XrdSfsFileOffset fsize, 00560 XrdOucErrInfo &eInfo, 00561 const XrdSecEntity *client = 0, 00562 const char *opaque = 0) = 0; 00563 00564 //----------------------------------------------------------------------------- 00566 //----------------------------------------------------------------------------- 00567 00568 XrdSfsFileSystem() {} 00569 virtual ~XrdSfsFileSystem() {} 00570 }; 00571 00572 /******************************************************************************/ 00573 /* F i l e S y s t e m I n s t a n t i a t o r */ 00574 /******************************************************************************/ 00575 00576 //----------------------------------------------------------------------------- 00610 typedef XrdSfsFileSystem *(*XrdSfsFileSystem_t) (XrdSfsFileSystem *nativeFS, 00611 XrdSysLogger *Logger, 00612 const char *configFn); 00613 00614 typedef XrdSfsFileSystem *(*XrdSfsFileSystem2_t)(XrdSfsFileSystem *nativeFS, 00615 XrdSysLogger *Logger, 00616 const char *configFn, 00617 XrdOucEnv *envP); 00618 00619 //----------------------------------------------------------------------------- 00620 00621 //------------------------------------------------------------------------------ 00633 //------------------------------------------------------------------------------ 00634 00635 /******************************************************************************/ 00636 /* X r d S f s F i l e */ 00637 /******************************************************************************/ 00638 00639 //------------------------------------------------------------------------------ 00642 //------------------------------------------------------------------------------ 00643 00644 class XrdSfsAio; 00645 class XrdSfsDio; 00646 class XrdSfsXio; 00647 00648 class XrdSfsFile 00649 { 00650 public: 00651 00652 //----------------------------------------------------------------------------- 00655 //----------------------------------------------------------------------------- 00656 00657 XrdOucErrInfo error; 00658 00659 //----------------------------------------------------------------------------- 00680 //----------------------------------------------------------------------------- 00681 00682 virtual int open(const char *fileName, 00683 XrdSfsFileOpenMode openMode, 00684 mode_t createMode, 00685 const XrdSecEntity *client = 0, 00686 const char *opaque = 0) = 0; 00687 00688 //----------------------------------------------------------------------------- 00692 //----------------------------------------------------------------------------- 00693 00694 virtual int close() = 0; 00695 00696 //----------------------------------------------------------------------------- 00713 //----------------------------------------------------------------------------- 00714 00715 virtual int fctl(const int cmd, 00716 const char *args, 00717 XrdOucErrInfo &eInfo) = 0; 00718 00719 //----------------------------------------------------------------------------- 00732 //----------------------------------------------------------------------------- 00733 00734 virtual int fctl(const int cmd, 00735 int alen, 00736 const char *args, 00737 const XrdSecEntity *client = 0) 00738 { 00739 (void)cmd; (void)alen; (void)args; (void)client; 00740 return SFS_OK; 00741 } 00742 00743 //----------------------------------------------------------------------------- 00747 //----------------------------------------------------------------------------- 00748 00749 virtual const char *FName() = 0; 00750 00751 00752 //----------------------------------------------------------------------------- 00759 //----------------------------------------------------------------------------- 00760 00761 virtual int getMmap(void **Addr, off_t &Size) = 0; 00762 00763 //----------------------------------------------------------------------------- 00771 //----------------------------------------------------------------------------- 00772 00773 virtual XrdSfsXferSize read(XrdSfsFileOffset offset, 00774 XrdSfsXferSize size) = 0; 00775 00776 //----------------------------------------------------------------------------- 00785 //----------------------------------------------------------------------------- 00786 00787 virtual XrdSfsXferSize read(XrdSfsFileOffset offset, 00788 char *buffer, 00789 XrdSfsXferSize size) = 0; 00790 00791 //----------------------------------------------------------------------------- 00798 //----------------------------------------------------------------------------- 00799 00800 virtual XrdSfsXferSize read(XrdSfsAio *aioparm) = 0; 00801 00802 //----------------------------------------------------------------------------- 00812 //----------------------------------------------------------------------------- 00813 00814 virtual XrdSfsXferSize readv(XrdOucIOVec *readV, 00815 int rdvCnt) 00816 {XrdSfsXferSize rdsz, totbytes = 0; 00817 for (int i = 0; i < rdvCnt; i++) 00818 {rdsz = read(readV[i].offset, 00819 readV[i].data, readV[i].size); 00820 if (rdsz != readV[i].size) 00821 {if (rdsz < 0) return rdsz; 00822 error.setErrInfo(ESPIPE,"read past eof"); 00823 return SFS_ERROR; 00824 } 00825 totbytes += rdsz; 00826 } 00827 return totbytes; 00828 } 00829 00830 //----------------------------------------------------------------------------- 00840 //----------------------------------------------------------------------------- 00841 00842 virtual int SendData(XrdSfsDio *sfDio, 00843 XrdSfsFileOffset offset, 00844 XrdSfsXferSize size) 00845 { 00846 (void)sfDio; (void)offset; (void)size; 00847 return SFS_OK; 00848 } 00849 00850 //----------------------------------------------------------------------------- 00859 //----------------------------------------------------------------------------- 00860 00861 virtual XrdSfsXferSize write(XrdSfsFileOffset offset, 00862 const char *buffer, 00863 XrdSfsXferSize size) = 0; 00864 00865 //----------------------------------------------------------------------------- 00872 //----------------------------------------------------------------------------- 00873 00874 virtual int write(XrdSfsAio *aioparm) = 0; 00875 00876 //----------------------------------------------------------------------------- 00886 //----------------------------------------------------------------------------- 00887 00888 virtual XrdSfsXferSize writev(XrdOucIOVec *writeV, 00889 int wdvCnt) 00890 {XrdSfsXferSize wrsz, totbytes = 0; 00891 for (int i = 0; i < wdvCnt; i++) 00892 {wrsz = write(writeV[i].offset, 00893 writeV[i].data, writeV[i].size); 00894 if (wrsz != writeV[i].size) 00895 {if (wrsz < 0) return wrsz; 00896 error.setErrInfo(ESPIPE,"write past eof"); 00897 return SFS_ERROR; 00898 } 00899 totbytes += wrsz; 00900 } 00901 return totbytes; 00902 } 00903 00904 //----------------------------------------------------------------------------- 00911 //----------------------------------------------------------------------------- 00912 00913 virtual int stat(struct stat *buf) = 0; 00914 00915 //----------------------------------------------------------------------------- 00919 //----------------------------------------------------------------------------- 00920 00921 virtual int sync() = 0; 00922 00923 //----------------------------------------------------------------------------- 00928 //----------------------------------------------------------------------------- 00929 00930 virtual int sync(XrdSfsAio *aiop) = 0; 00931 00932 //----------------------------------------------------------------------------- 00938 //----------------------------------------------------------------------------- 00939 00940 virtual int truncate(XrdSfsFileOffset fsize) = 0; 00941 00942 //----------------------------------------------------------------------------- 00950 //----------------------------------------------------------------------------- 00951 00952 virtual int getCXinfo(char cxtype[4], int &cxrsz) = 0; 00953 00954 //----------------------------------------------------------------------------- 00958 //----------------------------------------------------------------------------- 00959 00960 virtual void setXio(XrdSfsXio *xioP) { (void)xioP; } 00961 00962 //----------------------------------------------------------------------------- 00969 //----------------------------------------------------------------------------- 00970 00971 XrdSfsFile(const char *user=0, int MonID=0) 00972 : error(user, MonID) {} 00973 00974 //----------------------------------------------------------------------------- 00976 //----------------------------------------------------------------------------- 00977 00978 virtual ~XrdSfsFile() {} 00979 00980 }; // class XrdSfsFile 00981 00982 /******************************************************************************/ 00983 /* X r d S f s D i r e c t o r y */ 00984 /******************************************************************************/ 00985 00986 //------------------------------------------------------------------------------ 00989 //------------------------------------------------------------------------------ 00990 00991 class XrdSfsDirectory 00992 { 00993 public: 00994 00995 //----------------------------------------------------------------------------- 00998 //----------------------------------------------------------------------------- 00999 01000 XrdOucErrInfo error; 01001 01002 //----------------------------------------------------------------------------- 01010 //----------------------------------------------------------------------------- 01011 01012 virtual int open(const char *path, 01013 const XrdSecEntity *client = 0, 01014 const char *opaque = 0) = 0; 01015 01016 //----------------------------------------------------------------------------- 01024 //----------------------------------------------------------------------------- 01025 01026 virtual const char *nextEntry() = 0; 01027 01028 //----------------------------------------------------------------------------- 01032 //----------------------------------------------------------------------------- 01033 01034 virtual int close() = 0; 01035 01036 //----------------------------------------------------------------------------- 01040 //----------------------------------------------------------------------------- 01041 01042 virtual const char *FName() = 0; 01043 01044 //----------------------------------------------------------------------------- 01050 //----------------------------------------------------------------------------- 01051 01052 virtual int autoStat(struct stat *buf) 01053 {(void)buf; 01054 error.setErrInfo(ENOTSUP, "Not supported."); 01055 return SFS_ERROR; 01056 } 01057 01058 //----------------------------------------------------------------------------- 01065 //----------------------------------------------------------------------------- 01066 01067 XrdSfsDirectory(const char *user=0, int MonID=0) 01068 : error(user, MonID) {} 01069 01070 //----------------------------------------------------------------------------- 01072 //----------------------------------------------------------------------------- 01073 01074 virtual ~XrdSfsDirectory() {} 01075 01076 }; // class XrdSfsDirectory 01077 #endif