xrootd
XrdSfsInterface.hh
Go to the documentation of this file.
1 #ifndef __SFS_INTERFACE_H__
2 #define __SFS_INTERFACE_H__
3 /******************************************************************************/
4 /* */
5 /* X r d S f s I n t e r f a c e . h h */
6 /* */
7 /* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include <string.h> // For strlcpy()
33 #include <errno.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 
37 #include "XrdOuc/XrdOucErrInfo.hh"
38 #include "XrdOuc/XrdOucIOVec.hh"
39 #include "XrdOuc/XrdOucSFVec.hh"
40 
41 /******************************************************************************/
42 /* O p e n M o d e s */
43 /******************************************************************************/
44 
45 #define SFS_O_RDONLY 0 // open read/only
46 #define SFS_O_WRONLY 1 // open write/only
47 #define SFS_O_RDWR 2 // open read/write
48 #define SFS_O_CREAT 0x100 // used for file creation
49 #define SFS_O_TRUNC 0x200 // used for file truncation
50 #define SFS_O_MULTIW 0x400 // used for multi-write locations
51 #define SFS_O_POSC 0x0100000 // persist on successful close
52 #define SFS_O_FORCE 0x0200000 // used for locate only
53 #define SFS_O_HNAME 0x0400000 // used for locate only
54 #define SFS_O_LOCAL 0x0800000 // used for locate only (local cmd)
55 #define SFS_O_NOWAIT 0x01000000 // do not impose operational delays
56 #define SFS_O_RAWIO 0x02000000 // allow client-side decompression
57 #define SFS_O_RESET 0x04000000 // Reset any cached information
58 #define SFS_O_REPLICA 0x08000000 // Open for replication
59 
60 // The following flag may be set in the access mode arg for open() & mkdir()
61 // Note that on some systems mode_t is 16-bits so we use a careful value!
62 //
63 #define SFS_O_MKPTH 0x00004000 // Make directory path if missing
64 
65 // The following options are here to provide a uniform clustering interface.
66 // They may be passed through open/locate/stat, as applicable.
67 //
68 #define SFS_O_LOCATE 0x10000000 // This request generated by locate()
69 #define SFS_O_STAT 0x20000000 // This request generated by stat()
70 #define SFS_O_META 0x40000000 // This request generated by metaop
71 
72 /******************************************************************************/
73 /* D e f i n e s */
74 /******************************************************************************/
75 
76 // Common fctl command values (0 to 255)
77 //
78 #define SFS_FCTL_GETFD 1 // Return file descriptor if possible
79 #define SFS_FCTL_STATV 2 // Return visa information
80 #define SFS_FCTL_SPEC1 3 // Return implementation defined information
81 
82 #define SFS_SFIO_FDVAL 0x80000000 // Use SendData() method GETFD response value
83 
84 // Common fsctl command values (0 to 255)
85 //
86 #define SFS_FSCTL_CMD 255
87 
88 #define SFS_FSCTL_LOCATE 1 // Locate a file
89 #define SFS_FSCTL_STATFS 2 // Return FS data
90 #define SFS_FSCTL_STATLS 3 // Return LS data
91 #define SFS_FSCTL_STATXA 4 // Return XA data
92 #define SFS_FSCTL_STATCC 5 // Return Cluster Config status
93 #define SFS_FSCTL_PLUGIN 8 // Return Implementation Dependent Data
94 #define SFS_FSCTL_PLUGIO 16 // Return Implementation Dependent Data
95 
96 // Return values for integer & XrdSfsXferSize returning XrdSfs methods
97 //
98 #define SFS_STALL 1 // Return value -> Seconds to stall client
99 #define SFS_OK 0 // ErrInfo code -> All is well
100 #define SFS_ERROR -1 // ErrInfo code -> Error occurred
101 #define SFS_REDIRECT -256 // ErrInfo code -> Port number to redirect to
102 #define SFS_STARTED -512 // ErrInfo code -> Estimated seconds to completion
103 #define SFS_DATA -1024 // ErrInfo code -> Length of data
104 #define SFS_DATAVEC -2048 // ErrInfo code -> Num iovec elements in msgbuff
105 
106 // The following macros are used for dealing with special local paths
107 //
108 #define SFS_LCLPRFX "/=/"
109 #define SFS_LCLPLEN 3
110 #define SFS_LCLPATH(x) !strncmp(x, SFS_LCLPRFX, SFS_LCLPLEN)
111 #define SFS_LCLPRFY "/="
112 #define SFS_LCLROOT(x) !strncmp(x, SFS_LCLPRFX, SFS_LCLPLEN-1) \
113  && (*(x+SFS_LCLPLEN-1) == '/' || *(x+SFS_LCLPLEN-1) == 0)
114 
115 /******************************************************************************/
116 /* S t r u c t u r e s & T y p e d e f s */
117 /******************************************************************************/
118 
119 typedef long long XrdSfsFileOffset;
120 typedef int XrdSfsFileOpenMode;
121 typedef int XrdSfsMode;
122 typedef int XrdSfsXferSize;
123 
125 {
131 };
132 //------------------------------------------------
133 
134 #define Prep_PRTY0 0
135 #define Prep_PRTY1 1
136 #define Prep_PRTY2 2
137 #define Prep_PRTY3 3
138 #define Prep_PMASK 3
139 #define Prep_SENDAOK 4
140 #define Prep_SENDERR 8
141 #define Prep_SENDACK 12
142 #define Prep_WMODE 16
143 #define Prep_STAGE 32
144 #define Prep_COLOC 64
145 #define Prep_FRESH 128
146 
147 class XrdOucTList;
148 
149 struct XrdSfsFSctl
150 {
151  const char *Arg1;
152  int Arg1Len;
153  int Arg2Len;
154  const char *Arg2;
155 };
156 
157 struct XrdSfsPrep
158 {
159  char *reqid;
160  char *notify;
161  int opts;
164 };
165 
166 /******************************************************************************/
167 /* A b s t r a c t C l a s s e s */
168 /******************************************************************************/
169 
170 class XrdSfsFile;
171 class XrdSfsDirectory;
172 class XrdOucEnv;
173 class XrdOucTList;
174 class XrdSecEntity;
175 
176 /******************************************************************************/
177 /* X r d S f s F i l e S y s t e m */
178 /******************************************************************************/
179 
180 //-----------------------------------------------------------------------------
204 //-----------------------------------------------------------------------------
205 
206 class XrdSfsFileSystem
207 {
208 public:
209 
210 //-----------------------------------------------------------------------------
220 //-----------------------------------------------------------------------------
221 
222 virtual XrdSfsDirectory *newDir(char *user=0, int MonID=0) = 0;
223 
224 //-----------------------------------------------------------------------------
234 //-----------------------------------------------------------------------------
235 
236 virtual XrdSfsFile *newFile(char *user=0, int MonID=0) = 0;
237 
238 //-----------------------------------------------------------------------------
257 //-----------------------------------------------------------------------------
258 
259 enum csFunc {csCalc = 0, csGet, csSize};
260 
261 virtual int chksum( csFunc Func,
262  const char *csName,
263  const char *path,
264  XrdOucErrInfo &eInfo,
265  const XrdSecEntity *client = 0,
266  const char *opaque = 0)
267 {
268  (void)Func; (void)csName; (void)path; (void)eInfo; (void)client;
269  (void)opaque;
270  eInfo.setErrInfo(ENOTSUP, "Not supported.");
271  return SFS_ERROR;
272 }
273 
274 //-----------------------------------------------------------------------------
284 //-----------------------------------------------------------------------------
285 
286 virtual int chmod(const char *path,
287  XrdSfsMode mode,
288  XrdOucErrInfo &eInfo,
289  const XrdSecEntity *client = 0,
290  const char *opaque = 0) = 0;
291 
292 //-----------------------------------------------------------------------------
296 //-----------------------------------------------------------------------------
297 
298 virtual void Disc(const XrdSecEntity *client = 0)
299 {
300  (void)client;
301 }
302 
303 //-----------------------------------------------------------------------------
308 //-----------------------------------------------------------------------------
309 
310 virtual void EnvInfo(XrdOucEnv *envP)
311 {
312  (void)envP;
313 }
314 
315 //-----------------------------------------------------------------------------
343 //-----------------------------------------------------------------------------
344 
345 virtual int FSctl(const int cmd,
346  XrdSfsFSctl &args,
347  XrdOucErrInfo &eInfo,
348  const XrdSecEntity *client = 0)
349 {
350  (void)cmd; (void)args; (void)eInfo; (void)client;
351  return SFS_OK;
352 }
353 
354 //-----------------------------------------------------------------------------
370 //-----------------------------------------------------------------------------
371 
372 virtual int fsctl(const int cmd,
373  const char *args,
374  XrdOucErrInfo &eInfo,
375  const XrdSecEntity *client = 0) = 0;
376 
377 //-----------------------------------------------------------------------------
387 //-----------------------------------------------------------------------------
388 
389 virtual int getStats(char *buff, int blen) = 0;
390 
391 //-----------------------------------------------------------------------------
395 //-----------------------------------------------------------------------------
396 
397 virtual const char *getVersion() = 0;
398 
399 //-----------------------------------------------------------------------------
415 //-----------------------------------------------------------------------------
416 
417 virtual int exists(const char *path,
418  XrdSfsFileExistence &eFlag,
419  XrdOucErrInfo &eInfo,
420  const XrdSecEntity *client = 0,
421  const char *opaque = 0) = 0;
422 
423 //-----------------------------------------------------------------------------
433 //-----------------------------------------------------------------------------
434 
435 virtual int mkdir(const char *path,
436  XrdSfsMode mode,
437  XrdOucErrInfo &eInfo,
438  const XrdSecEntity *client = 0,
439  const char *opaque = 0) = 0;
440 
441 //-----------------------------------------------------------------------------
449 //-----------------------------------------------------------------------------
450 
451 virtual int prepare( XrdSfsPrep &pargs,
452  XrdOucErrInfo &eInfo,
453  const XrdSecEntity *client = 0) = 0;
454 
455 //-----------------------------------------------------------------------------
464 //-----------------------------------------------------------------------------
465 
466 virtual int rem(const char *path,
467  XrdOucErrInfo &eInfo,
468  const XrdSecEntity *client = 0,
469  const char *opaque = 0) = 0;
470 
471 //-----------------------------------------------------------------------------
480 //-----------------------------------------------------------------------------
481 
482 virtual int remdir(const char *path,
483  XrdOucErrInfo &eInfo,
484  const XrdSecEntity *client = 0,
485  const char *opaque = 0) = 0;
486 
487 //-----------------------------------------------------------------------------
498 //-----------------------------------------------------------------------------
499 
500 virtual int rename(const char *oPath,
501  const char *nPath,
502  XrdOucErrInfo &eInfo,
503  const XrdSecEntity *client = 0,
504  const char *opaqueO = 0,
505  const char *opaqueN = 0) = 0;
506 
507 //-----------------------------------------------------------------------------
518 //-----------------------------------------------------------------------------
519 
520 virtual int stat(const char *Name,
521  struct stat *buf,
522  XrdOucErrInfo &eInfo,
523  const XrdSecEntity *client = 0,
524  const char *opaque = 0) = 0;
525 
526 //-----------------------------------------------------------------------------
538 //-----------------------------------------------------------------------------
539 
540 virtual int stat(const char *path,
541  mode_t &mode,
542  XrdOucErrInfo &eInfo,
543  const XrdSecEntity *client = 0,
544  const char *opaque = 0) = 0;
545 
546 //-----------------------------------------------------------------------------
556 //-----------------------------------------------------------------------------
557 
558 virtual int truncate(const char *path,
559  XrdSfsFileOffset fsize,
560  XrdOucErrInfo &eInfo,
561  const XrdSecEntity *client = 0,
562  const char *opaque = 0) = 0;
563 
564 //-----------------------------------------------------------------------------
566 //-----------------------------------------------------------------------------
567 
568  XrdSfsFileSystem() {}
569 virtual ~XrdSfsFileSystem() {}
570 };
571 
572 /******************************************************************************/
573 /* F i l e S y s t e m I n s t a n t i a t o r */
574 /******************************************************************************/
575 
576 //-----------------------------------------------------------------------------
610 typedef XrdSfsFileSystem *(*XrdSfsFileSystem_t) (XrdSfsFileSystem *nativeFS,
611  XrdSysLogger *Logger,
612  const char *configFn);
613 
614 typedef XrdSfsFileSystem *(*XrdSfsFileSystem2_t)(XrdSfsFileSystem *nativeFS,
615  XrdSysLogger *Logger,
616  const char *configFn,
617  XrdOucEnv *envP);
618 
619 //-----------------------------------------------------------------------------
620 
621 //------------------------------------------------------------------------------
633 //------------------------------------------------------------------------------
634 
635 /******************************************************************************/
636 /* X r d S f s F i l e */
637 /******************************************************************************/
638 
639 //------------------------------------------------------------------------------
642 //------------------------------------------------------------------------------
643 
644 class XrdSfsAio;
645 class XrdSfsDio;
646 class XrdSfsXio;
647 
648 class XrdSfsFile
649 {
650 public:
651 
652 //-----------------------------------------------------------------------------
655 //-----------------------------------------------------------------------------
656 
657  XrdOucErrInfo error;
658 
659 //-----------------------------------------------------------------------------
680 //-----------------------------------------------------------------------------
681 
682 virtual int open(const char *fileName,
683  XrdSfsFileOpenMode openMode,
684  mode_t createMode,
685  const XrdSecEntity *client = 0,
686  const char *opaque = 0) = 0;
687 
688 //-----------------------------------------------------------------------------
692 //-----------------------------------------------------------------------------
693 
694 virtual int close() = 0;
695 
696 //-----------------------------------------------------------------------------
713 //-----------------------------------------------------------------------------
714 
715 virtual int fctl(const int cmd,
716  const char *args,
717  XrdOucErrInfo &eInfo) = 0;
718 
719 //-----------------------------------------------------------------------------
732 //-----------------------------------------------------------------------------
733 
734 virtual int fctl(const int cmd,
735  int alen,
736  const char *args,
737  const XrdSecEntity *client = 0)
738 {
739  (void)cmd; (void)alen; (void)args; (void)client;
740  return SFS_OK;
741 }
742 
743 //-----------------------------------------------------------------------------
747 //-----------------------------------------------------------------------------
748 
749 virtual const char *FName() = 0;
750 
751 
752 //-----------------------------------------------------------------------------
759 //-----------------------------------------------------------------------------
760 
761 virtual int getMmap(void **Addr, off_t &Size) = 0;
762 
763 //-----------------------------------------------------------------------------
771 //-----------------------------------------------------------------------------
772 
773 virtual XrdSfsXferSize read(XrdSfsFileOffset offset,
774  XrdSfsXferSize size) = 0;
775 
776 //-----------------------------------------------------------------------------
785 //-----------------------------------------------------------------------------
786 
787 virtual XrdSfsXferSize read(XrdSfsFileOffset offset,
788  char *buffer,
789  XrdSfsXferSize size) = 0;
790 
791 //-----------------------------------------------------------------------------
798 //-----------------------------------------------------------------------------
799 
800 virtual XrdSfsXferSize read(XrdSfsAio *aioparm) = 0;
801 
802 //-----------------------------------------------------------------------------
812 //-----------------------------------------------------------------------------
813 
814 virtual XrdSfsXferSize readv(XrdOucIOVec *readV,
815  int rdvCnt)
816  {XrdSfsXferSize rdsz, totbytes = 0;
817  for (int i = 0; i < rdvCnt; i++)
818  {rdsz = read(readV[i].offset,
819  readV[i].data, readV[i].size);
820  if (rdsz != readV[i].size)
821  {if (rdsz < 0) return rdsz;
822  error.setErrInfo(ESPIPE,"read past eof");
823  return SFS_ERROR;
824  }
825  totbytes += rdsz;
826  }
827  return totbytes;
828  }
829 
830 //-----------------------------------------------------------------------------
840 //-----------------------------------------------------------------------------
841 
842 virtual int SendData(XrdSfsDio *sfDio,
843  XrdSfsFileOffset offset,
844  XrdSfsXferSize size)
845 {
846  (void)sfDio; (void)offset; (void)size;
847  return SFS_OK;
848 }
849 
850 //-----------------------------------------------------------------------------
859 //-----------------------------------------------------------------------------
860 
861 virtual XrdSfsXferSize write(XrdSfsFileOffset offset,
862  const char *buffer,
863  XrdSfsXferSize size) = 0;
864 
865 //-----------------------------------------------------------------------------
872 //-----------------------------------------------------------------------------
873 
874 virtual int write(XrdSfsAio *aioparm) = 0;
875 
876 //-----------------------------------------------------------------------------
886 //-----------------------------------------------------------------------------
887 
888 virtual XrdSfsXferSize writev(XrdOucIOVec *writeV,
889  int wdvCnt)
890  {XrdSfsXferSize wrsz, totbytes = 0;
891  for (int i = 0; i < wdvCnt; i++)
892  {wrsz = write(writeV[i].offset,
893  writeV[i].data, writeV[i].size);
894  if (wrsz != writeV[i].size)
895  {if (wrsz < 0) return wrsz;
896  error.setErrInfo(ESPIPE,"write past eof");
897  return SFS_ERROR;
898  }
899  totbytes += wrsz;
900  }
901  return totbytes;
902  }
903 
904 //-----------------------------------------------------------------------------
911 //-----------------------------------------------------------------------------
912 
913 virtual int stat(struct stat *buf) = 0;
914 
915 //-----------------------------------------------------------------------------
919 //-----------------------------------------------------------------------------
920 
921 virtual int sync() = 0;
922 
923 //-----------------------------------------------------------------------------
928 //-----------------------------------------------------------------------------
929 
930 virtual int sync(XrdSfsAio *aiop) = 0;
931 
932 //-----------------------------------------------------------------------------
938 //-----------------------------------------------------------------------------
939 
940 virtual int truncate(XrdSfsFileOffset fsize) = 0;
941 
942 //-----------------------------------------------------------------------------
950 //-----------------------------------------------------------------------------
951 
952 virtual int getCXinfo(char cxtype[4], int &cxrsz) = 0;
953 
954 //-----------------------------------------------------------------------------
958 //-----------------------------------------------------------------------------
959 
960 virtual void setXio(XrdSfsXio *xioP) { (void)xioP; }
961 
962 //-----------------------------------------------------------------------------
969 //-----------------------------------------------------------------------------
970 
971  XrdSfsFile(const char *user=0, int MonID=0)
972  : error(user, MonID) {}
973 
974 //-----------------------------------------------------------------------------
976 //-----------------------------------------------------------------------------
977 
978 virtual ~XrdSfsFile() {}
979 
980 }; // class XrdSfsFile
981 
982 /******************************************************************************/
983 /* X r d S f s D i r e c t o r y */
984 /******************************************************************************/
985 
986 //------------------------------------------------------------------------------
989 //------------------------------------------------------------------------------
990 
991 class XrdSfsDirectory
992 {
993 public:
994 
995 //-----------------------------------------------------------------------------
998 //-----------------------------------------------------------------------------
999 
1000  XrdOucErrInfo error;
1001 
1002 //-----------------------------------------------------------------------------
1010 //-----------------------------------------------------------------------------
1011 
1012 virtual int open(const char *path,
1013  const XrdSecEntity *client = 0,
1014  const char *opaque = 0) = 0;
1015 
1016 //-----------------------------------------------------------------------------
1024 //-----------------------------------------------------------------------------
1025 
1026 virtual const char *nextEntry() = 0;
1027 
1028 //-----------------------------------------------------------------------------
1032 //-----------------------------------------------------------------------------
1033 
1034 virtual int close() = 0;
1035 
1036 //-----------------------------------------------------------------------------
1040 //-----------------------------------------------------------------------------
1041 
1042 virtual const char *FName() = 0;
1043 
1044 //-----------------------------------------------------------------------------
1050 //-----------------------------------------------------------------------------
1051 
1052 virtual int autoStat(struct stat *buf)
1053  {(void)buf;
1054  error.setErrInfo(ENOTSUP, "Not supported.");
1055  return SFS_ERROR;
1056  }
1057 
1058 //-----------------------------------------------------------------------------
1065 //-----------------------------------------------------------------------------
1066 
1067  XrdSfsDirectory(const char *user=0, int MonID=0)
1068  : error(user, MonID) {}
1069 
1070 //-----------------------------------------------------------------------------
1072 //-----------------------------------------------------------------------------
1073 
1074 virtual ~XrdSfsDirectory() {}
1075 
1076 }; // class XrdSfsDirectory
1077 #endif
int opts
Prep_xxx.
Definition: XrdSfsInterface.hh:161
XrdOucTList * oinfo
1-to-1 correspondence of opaque info
Definition: XrdSfsInterface.hh:163
#define SFS_OK
Definition: XrdSfsInterface.hh:99
const char * Arg1
PLUGIO &amp; PLUGIN.
Definition: XrdSfsInterface.hh:151
int XrdSfsXferSize
Definition: XrdSfsInterface.hh:122
char * notify
Notification path or 0.
Definition: XrdSfsInterface.hh:160
XrdSfsFileExistence
Definition: XrdSfsInterface.hh:124
long long XrdSfsFileOffset
Definition: XrdSfsInterface.hh:119
int Arg1Len
Length.
Definition: XrdSfsInterface.hh:152
Definition: XrdSfsInterface.hh:126
&lt; SFS_FSCTL_PLUGIN/PLUGIO parameters
Definition: XrdSfsInterface.hh:149
Definition: XrdOucErrInfo.hh:97
Definition: XrdSfsInterface.hh:127
Definition: XrdSfsInterface.hh:129
#define SFS_ERROR
Definition: XrdSfsInterface.hh:100
Definition: XrdOucEnv.hh:41
Definition: XrdOucIOVec.hh:40
const char * Arg2
PLUGIN opaque string.
Definition: XrdSfsInterface.hh:154
Definition: XrdOucTList.hh:41
XrdOucTList * paths
List of paths.
Definition: XrdSfsInterface.hh:162
Definition: XrdSysLogger.hh:52
char * reqid
Request ID.
Definition: XrdSfsInterface.hh:159
int XrdSfsMode
Definition: XrdSfsInterface.hh:121
int Arg2Len
Length.
Definition: XrdSfsInterface.hh:153
Definition: XrdSecEntity.hh:51
Definition: XrdSfsInterface.hh:130
Definition: XrdSfsAio.hh:57
&lt; Prepare parameters
Definition: XrdSfsInterface.hh:157
int XrdSfsFileOpenMode
Definition: XrdSfsInterface.hh:120
int setErrInfo(int code, const char *emsg)
Definition: XrdOucErrInfo.hh:144
Definition: XrdSfsInterface.hh:128