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_POSC 0x0100000 // persist on successful close 00051 #define SFS_O_FORCE 0x0200000 // used for locate only 00052 #define SFS_O_HNAME 0x0400000 // used for locate only 00053 #define SFS_O_LOCAL 0x0800000 // used for locate only (local cmd) 00054 #define SFS_O_NOWAIT 0x01000000 // do not impose operational delays 00055 #define SFS_O_RAWIO 0x02000000 // allow client-side decompression 00056 #define SFS_O_RESET 0x04000000 // Reset any cached information 00057 #define SFS_O_REPLICA 0x08000000 // Open for replication 00058 00059 // The following flag may be set in the access mode arg for open() & mkdir() 00060 // Note that on some systems mode_t is 16-bits so we use a careful value! 00061 // 00062 #define SFS_O_MKPTH 0x00004000 // Make directory path if missing 00063 00064 // The following options are here to provide a uniform clustering interface. 00065 // They may be passed through open/locate/stat, as applicable. 00066 // 00067 #define SFS_O_LOCATE 0x10000000 // This request generated by locate() 00068 #define SFS_O_STAT 0x20000000 // This request generated by stat() 00069 #define SFS_O_META 0x40000000 // This request generated by metaop 00070 00071 /******************************************************************************/ 00072 /* D e f i n e s */ 00073 /******************************************************************************/ 00074 00075 // Common fctl command values (0 to 255) 00076 // 00077 #define SFS_FCTL_GETFD 1 // Return file descriptor if possible 00078 #define SFS_FCTL_STATV 2 // Return visa information 00079 #define SFS_FCTL_SPEC1 3 // Return implementation defined information 00080 00081 #define SFS_SFIO_FDVAL 0x80000000 // Use SendData() method GETFD response value 00082 00083 // Common fsctl command values (0 to 255) 00084 // 00085 #define SFS_FSCTL_CMD 255 00086 00087 #define SFS_FSCTL_LOCATE 1 // Locate a file 00088 #define SFS_FSCTL_STATFS 2 // Return FS data 00089 #define SFS_FSCTL_STATLS 3 // Return LS data 00090 #define SFS_FSCTL_STATXA 4 // Return XA data 00091 #define SFS_FSCTL_STATCC 5 // Return Cluster Config status 00092 #define SFS_FSCTL_PLUGIN 8 // Return Implementation Dependent Data 00093 #define SFS_FSCTL_PLUGIO 16 // Return Implementation Dependent Data 00094 00095 // Return values for integer & XrdSfsXferSize returning XrdSfs methods 00096 // 00097 #define SFS_STALL 1 // Return value -> Seconds to stall client 00098 #define SFS_OK 0 // ErrInfo code -> All is well 00099 #define SFS_ERROR -1 // ErrInfo code -> Error occurred 00100 #define SFS_REDIRECT -256 // ErrInfo code -> Port number to redirect to 00101 #define SFS_STARTED -512 // ErrInfo code -> Estimated seconds to completion 00102 #define SFS_DATA -1024 // ErrInfo code -> Length of data 00103 00104 // The following macros are used for dealing with special local paths 00105 // 00106 #define SFS_LCLPRFX "/=/" 00107 #define SFS_LCLPLEN 3 00108 #define SFS_LCLPATH(x) !strncmp(x, SFS_LCLPRFX, SFS_LCLPLEN) 00109 #define SFS_LCLPRFY "/=" 00110 #define SFS_LCLROOT(x) !strncmp(x, SFS_LCLPRFX, SFS_LCLPLEN-1) \ 00111 && (*(x+SFS_LCLPLEN-1) == '/' || *(x+SFS_LCLPLEN-1) == 0) 00112 00113 /******************************************************************************/ 00114 /* S t r u c t u r e s & T y p e d e f s */ 00115 /******************************************************************************/ 00116 00117 typedef long long XrdSfsFileOffset; 00118 typedef int XrdSfsFileOpenMode; 00119 typedef int XrdSfsMode; 00120 typedef int XrdSfsXferSize; 00121 00122 enum XrdSfsFileExistence 00123 { 00124 XrdSfsFileExistNo, 00125 XrdSfsFileExistIsFile, 00126 XrdSfsFileExistIsDirectory, 00127 XrdSfsFileExistIsOffline, 00128 XrdSfsFileExistIsOther 00129 }; 00130 //------------------------------------------------ 00131 00132 #define Prep_PRTY0 0 00133 #define Prep_PRTY1 1 00134 #define Prep_PRTY2 2 00135 #define Prep_PRTY3 3 00136 #define Prep_PMASK 3 00137 #define Prep_SENDAOK 4 00138 #define Prep_SENDERR 8 00139 #define Prep_SENDACK 12 00140 #define Prep_WMODE 16 00141 #define Prep_STAGE 32 00142 #define Prep_COLOC 64 00143 #define Prep_FRESH 128 00144 00145 class XrdOucTList; 00146 00147 struct XrdSfsFSctl 00148 { 00149 const char *Arg1; 00150 int Arg1Len; 00151 int Arg2Len; 00152 const char *Arg2; 00153 }; 00154 00155 struct XrdSfsPrep 00156 { 00157 char *reqid; 00158 char *notify; 00159 int opts; 00160 XrdOucTList *paths; 00161 XrdOucTList *oinfo; 00162 }; 00163 00164 /******************************************************************************/ 00165 /* A b s t r a c t C l a s s e s */ 00166 /******************************************************************************/ 00167 00168 class XrdSfsFile; 00169 class XrdSfsDirectory; 00170 class XrdOucEnv; 00171 class XrdOucTList; 00172 class XrdSecEntity; 00173 00174 /******************************************************************************/ 00175 /* X r d S f s F i l e S y s t e m */ 00176 /******************************************************************************/ 00177 00178 //----------------------------------------------------------------------------- 00202 //----------------------------------------------------------------------------- 00203 00204 class XrdSfsFileSystem 00205 { 00206 public: 00207 00208 //----------------------------------------------------------------------------- 00218 //----------------------------------------------------------------------------- 00219 00220 virtual XrdSfsDirectory *newDir(char *user=0, int MonID=0) = 0; 00221 00222 //----------------------------------------------------------------------------- 00232 //----------------------------------------------------------------------------- 00233 00234 virtual XrdSfsFile *newFile(char *user=0, int MonID=0) = 0; 00235 00236 //----------------------------------------------------------------------------- 00255 //----------------------------------------------------------------------------- 00256 00257 enum csFunc {csCalc = 0, csGet, csSize}; 00258 00259 virtual int chksum( csFunc Func, 00260 const char *csName, 00261 const char *path, 00262 XrdOucErrInfo &eInfo, 00263 const XrdSecEntity *client = 0, 00264 const char *opaque = 0) 00265 { 00266 (void)Func; (void)csName; (void)path; (void)eInfo; (void)client; 00267 (void)opaque; 00268 eInfo.setErrInfo(ENOTSUP, "Not supported."); 00269 return SFS_ERROR; 00270 } 00271 00272 //----------------------------------------------------------------------------- 00282 //----------------------------------------------------------------------------- 00283 00284 virtual int chmod(const char *path, 00285 XrdSfsMode mode, 00286 XrdOucErrInfo &eInfo, 00287 const XrdSecEntity *client = 0, 00288 const char *opaque = 0) = 0; 00289 00290 //----------------------------------------------------------------------------- 00294 //----------------------------------------------------------------------------- 00295 00296 virtual void Disc(const XrdSecEntity *client = 0) 00297 { 00298 (void)client; 00299 } 00300 00301 //----------------------------------------------------------------------------- 00306 //----------------------------------------------------------------------------- 00307 00308 virtual void EnvInfo(XrdOucEnv *envP) 00309 { 00310 (void)envP; 00311 } 00312 00313 //----------------------------------------------------------------------------- 00341 //----------------------------------------------------------------------------- 00342 00343 virtual int FSctl(const int cmd, 00344 XrdSfsFSctl &args, 00345 XrdOucErrInfo &eInfo, 00346 const XrdSecEntity *client = 0) 00347 { 00348 (void)cmd; (void)args; (void)eInfo; (void)client; 00349 return SFS_OK; 00350 } 00351 00352 //----------------------------------------------------------------------------- 00368 //----------------------------------------------------------------------------- 00369 00370 virtual int fsctl(const int cmd, 00371 const char *args, 00372 XrdOucErrInfo &eInfo, 00373 const XrdSecEntity *client = 0) = 0; 00374 00375 //----------------------------------------------------------------------------- 00385 //----------------------------------------------------------------------------- 00386 00387 virtual int getStats(char *buff, int blen) = 0; 00388 00389 //----------------------------------------------------------------------------- 00393 //----------------------------------------------------------------------------- 00394 00395 virtual const char *getVersion() = 0; 00396 00397 //----------------------------------------------------------------------------- 00413 //----------------------------------------------------------------------------- 00414 00415 virtual int exists(const char *path, 00416 XrdSfsFileExistence &eFlag, 00417 XrdOucErrInfo &eInfo, 00418 const XrdSecEntity *client = 0, 00419 const char *opaque = 0) = 0; 00420 00421 //----------------------------------------------------------------------------- 00431 //----------------------------------------------------------------------------- 00432 00433 virtual int mkdir(const char *path, 00434 XrdSfsMode mode, 00435 XrdOucErrInfo &eInfo, 00436 const XrdSecEntity *client = 0, 00437 const char *opaque = 0) = 0; 00438 00439 //----------------------------------------------------------------------------- 00447 //----------------------------------------------------------------------------- 00448 00449 virtual int prepare( XrdSfsPrep &pargs, 00450 XrdOucErrInfo &eInfo, 00451 const XrdSecEntity *client = 0) = 0; 00452 00453 //----------------------------------------------------------------------------- 00462 //----------------------------------------------------------------------------- 00463 00464 virtual int rem(const char *path, 00465 XrdOucErrInfo &eInfo, 00466 const XrdSecEntity *client = 0, 00467 const char *opaque = 0) = 0; 00468 00469 //----------------------------------------------------------------------------- 00478 //----------------------------------------------------------------------------- 00479 00480 virtual int remdir(const char *path, 00481 XrdOucErrInfo &eInfo, 00482 const XrdSecEntity *client = 0, 00483 const char *opaque = 0) = 0; 00484 00485 //----------------------------------------------------------------------------- 00496 //----------------------------------------------------------------------------- 00497 00498 virtual int rename(const char *oPath, 00499 const char *nPath, 00500 XrdOucErrInfo &eInfo, 00501 const XrdSecEntity *client = 0, 00502 const char *opaqueO = 0, 00503 const char *opaqueN = 0) = 0; 00504 00505 //----------------------------------------------------------------------------- 00516 //----------------------------------------------------------------------------- 00517 00518 virtual int stat(const char *Name, 00519 struct stat *buf, 00520 XrdOucErrInfo &eInfo, 00521 const XrdSecEntity *client = 0, 00522 const char *opaque = 0) = 0; 00523 00524 //----------------------------------------------------------------------------- 00536 //----------------------------------------------------------------------------- 00537 00538 virtual int stat(const char *path, 00539 mode_t &mode, 00540 XrdOucErrInfo &eInfo, 00541 const XrdSecEntity *client = 0, 00542 const char *opaque = 0) = 0; 00543 00544 //----------------------------------------------------------------------------- 00554 //----------------------------------------------------------------------------- 00555 00556 virtual int truncate(const char *path, 00557 XrdSfsFileOffset fsize, 00558 XrdOucErrInfo &eInfo, 00559 const XrdSecEntity *client = 0, 00560 const char *opaque = 0) = 0; 00561 00562 //----------------------------------------------------------------------------- 00564 //----------------------------------------------------------------------------- 00565 00566 XrdSfsFileSystem() {} 00567 virtual ~XrdSfsFileSystem() {} 00568 }; 00569 00570 /******************************************************************************/ 00571 /* F i l e S y s t e m I n s t a n t i a t o r */ 00572 /******************************************************************************/ 00573 00574 //----------------------------------------------------------------------------- 00608 typedef XrdSfsFileSystem *(*XrdSfsFileSystem_t) (XrdSfsFileSystem *nativeFS, 00609 XrdSysLogger *Logger, 00610 const char *configFn); 00611 00612 typedef XrdSfsFileSystem *(*XrdSfsFileSystem2_t)(XrdSfsFileSystem *nativeFS, 00613 XrdSysLogger *Logger, 00614 const char *configFn, 00615 XrdOucEnv *envP); 00616 00617 //----------------------------------------------------------------------------- 00618 00619 //------------------------------------------------------------------------------ 00631 //------------------------------------------------------------------------------ 00632 00633 /******************************************************************************/ 00634 /* X r d S f s F i l e */ 00635 /******************************************************************************/ 00636 00637 //------------------------------------------------------------------------------ 00640 //------------------------------------------------------------------------------ 00641 00642 class XrdSfsAio; 00643 class XrdSfsDio; 00644 class XrdSfsXio; 00645 00646 class XrdSfsFile 00647 { 00648 public: 00649 00650 //----------------------------------------------------------------------------- 00653 //----------------------------------------------------------------------------- 00654 00655 XrdOucErrInfo error; 00656 00657 //----------------------------------------------------------------------------- 00678 //----------------------------------------------------------------------------- 00679 00680 virtual int open(const char *fileName, 00681 XrdSfsFileOpenMode openMode, 00682 mode_t createMode, 00683 const XrdSecEntity *client = 0, 00684 const char *opaque = 0) = 0; 00685 00686 //----------------------------------------------------------------------------- 00690 //----------------------------------------------------------------------------- 00691 00692 virtual int close() = 0; 00693 00694 //----------------------------------------------------------------------------- 00711 //----------------------------------------------------------------------------- 00712 00713 virtual int fctl(const int cmd, 00714 const char *args, 00715 XrdOucErrInfo &eInfo) = 0; 00716 00717 //----------------------------------------------------------------------------- 00730 //----------------------------------------------------------------------------- 00731 00732 virtual int fctl(const int cmd, 00733 int alen, 00734 const char *args, 00735 const XrdSecEntity *client = 0) 00736 { 00737 (void)cmd; (void)alen; (void)args; (void)client; 00738 return SFS_OK; 00739 } 00740 00741 //----------------------------------------------------------------------------- 00745 //----------------------------------------------------------------------------- 00746 00747 virtual const char *FName() = 0; 00748 00749 00750 //----------------------------------------------------------------------------- 00757 //----------------------------------------------------------------------------- 00758 00759 virtual int getMmap(void **Addr, off_t &Size) = 0; 00760 00761 //----------------------------------------------------------------------------- 00769 //----------------------------------------------------------------------------- 00770 00771 virtual XrdSfsXferSize read(XrdSfsFileOffset offset, 00772 XrdSfsXferSize size) = 0; 00773 00774 //----------------------------------------------------------------------------- 00783 //----------------------------------------------------------------------------- 00784 00785 virtual XrdSfsXferSize read(XrdSfsFileOffset offset, 00786 char *buffer, 00787 XrdSfsXferSize size) = 0; 00788 00789 //----------------------------------------------------------------------------- 00796 //----------------------------------------------------------------------------- 00797 00798 virtual XrdSfsXferSize read(XrdSfsAio *aioparm) = 0; 00799 00800 //----------------------------------------------------------------------------- 00810 //----------------------------------------------------------------------------- 00811 00812 virtual XrdSfsXferSize readv(XrdOucIOVec *readV, 00813 int rdvCnt) 00814 {XrdSfsXferSize rdsz, totbytes = 0; 00815 for (int i = 0; i < rdvCnt; i++) 00816 {rdsz = read(readV[i].offset, 00817 readV[i].data, readV[i].size); 00818 if (rdsz != readV[i].size) 00819 {if (rdsz < 0) return rdsz; 00820 error.setErrInfo(ESPIPE,"read past eof"); 00821 return SFS_ERROR; 00822 } 00823 totbytes += rdsz; 00824 } 00825 return totbytes; 00826 } 00827 00828 //----------------------------------------------------------------------------- 00838 //----------------------------------------------------------------------------- 00839 00840 virtual int SendData(XrdSfsDio *sfDio, 00841 XrdSfsFileOffset offset, 00842 XrdSfsXferSize size) 00843 { 00844 (void)sfDio; (void)offset; (void)size; 00845 return SFS_OK; 00846 } 00847 00848 //----------------------------------------------------------------------------- 00857 //----------------------------------------------------------------------------- 00858 00859 virtual XrdSfsXferSize write(XrdSfsFileOffset offset, 00860 const char *buffer, 00861 XrdSfsXferSize size) = 0; 00862 00863 //----------------------------------------------------------------------------- 00870 //----------------------------------------------------------------------------- 00871 00872 virtual int write(XrdSfsAio *aioparm) = 0; 00873 00874 //----------------------------------------------------------------------------- 00884 //----------------------------------------------------------------------------- 00885 00886 virtual XrdSfsXferSize writev(XrdOucIOVec *writeV, 00887 int wdvCnt) 00888 {XrdSfsXferSize wrsz, totbytes = 0; 00889 for (int i = 0; i < wdvCnt; i++) 00890 {wrsz = write(writeV[i].offset, 00891 writeV[i].data, writeV[i].size); 00892 if (wrsz != writeV[i].size) 00893 {if (wrsz < 0) return wrsz; 00894 error.setErrInfo(ESPIPE,"write past eof"); 00895 return SFS_ERROR; 00896 } 00897 totbytes += wrsz; 00898 } 00899 return totbytes; 00900 } 00901 00902 //----------------------------------------------------------------------------- 00909 //----------------------------------------------------------------------------- 00910 00911 virtual int stat(struct stat *buf) = 0; 00912 00913 //----------------------------------------------------------------------------- 00917 //----------------------------------------------------------------------------- 00918 00919 virtual int sync() = 0; 00920 00921 //----------------------------------------------------------------------------- 00926 //----------------------------------------------------------------------------- 00927 00928 virtual int sync(XrdSfsAio *aiop) = 0; 00929 00930 //----------------------------------------------------------------------------- 00936 //----------------------------------------------------------------------------- 00937 00938 virtual int truncate(XrdSfsFileOffset fsize) = 0; 00939 00940 //----------------------------------------------------------------------------- 00948 //----------------------------------------------------------------------------- 00949 00950 virtual int getCXinfo(char cxtype[4], int &cxrsz) = 0; 00951 00952 //----------------------------------------------------------------------------- 00956 //----------------------------------------------------------------------------- 00957 00958 virtual void setXio(XrdSfsXio *xioP) { (void)xioP; } 00959 00960 //----------------------------------------------------------------------------- 00967 //----------------------------------------------------------------------------- 00968 00969 XrdSfsFile(const char *user=0, int MonID=0) 00970 : error(user, MonID) {} 00971 00972 //----------------------------------------------------------------------------- 00974 //----------------------------------------------------------------------------- 00975 00976 virtual ~XrdSfsFile() {} 00977 00978 }; // class XrdSfsFile 00979 00980 /******************************************************************************/ 00981 /* X r d S f s D i r e c t o r y */ 00982 /******************************************************************************/ 00983 00984 //------------------------------------------------------------------------------ 00987 //------------------------------------------------------------------------------ 00988 00989 class XrdSfsDirectory 00990 { 00991 public: 00992 00993 //----------------------------------------------------------------------------- 00996 //----------------------------------------------------------------------------- 00997 00998 XrdOucErrInfo error; 00999 01000 //----------------------------------------------------------------------------- 01008 //----------------------------------------------------------------------------- 01009 01010 virtual int open(const char *path, 01011 const XrdSecEntity *client = 0, 01012 const char *opaque = 0) = 0; 01013 01014 //----------------------------------------------------------------------------- 01022 //----------------------------------------------------------------------------- 01023 01024 virtual const char *nextEntry() = 0; 01025 01026 //----------------------------------------------------------------------------- 01030 //----------------------------------------------------------------------------- 01031 01032 virtual int close() = 0; 01033 01034 //----------------------------------------------------------------------------- 01038 //----------------------------------------------------------------------------- 01039 01040 virtual const char *FName() = 0; 01041 01042 //----------------------------------------------------------------------------- 01048 //----------------------------------------------------------------------------- 01049 01050 virtual int autoStat(struct stat *buf) 01051 {(void)buf; 01052 error.setErrInfo(ENOTSUP, "Not supported."); 01053 return SFS_ERROR; 01054 } 01055 01056 //----------------------------------------------------------------------------- 01063 //----------------------------------------------------------------------------- 01064 01065 XrdSfsDirectory(const char *user=0, int MonID=0) 01066 : error(user, MonID) {} 01067 01068 //----------------------------------------------------------------------------- 01070 //----------------------------------------------------------------------------- 01071 01072 virtual ~XrdSfsDirectory() {} 01073 01074 }; // class XrdSfsDirectory 01075 #endif