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_POSC 0x0100000 // persist on successful close
51 #define SFS_O_FORCE 0x0200000 // used for locate only
52 #define SFS_O_HNAME 0x0400000 // used for locate only
53 #define SFS_O_LOCAL 0x0800000 // used for locate only (local cmd)
54 #define SFS_O_NOWAIT 0x01000000 // do not impose operational delays
55 #define SFS_O_RAWIO 0x02000000 // allow client-side decompression
56 #define SFS_O_RESET 0x04000000 // Reset any cached information
57 #define SFS_O_REPLICA 0x08000000 // Open for replication
58 
59 // The following flag may be set in the access mode arg for open() & mkdir()
60 // Note that on some systems mode_t is 16-bits so we use a careful value!
61 //
62 #define SFS_O_MKPTH 0x00004000 // Make directory path if missing
63 
64 // The following options are here to provide a uniform clustering interface.
65 // They may be passed through open/locate/stat, as applicable.
66 //
67 #define SFS_O_LOCATE 0x10000000 // This request generated by locate()
68 #define SFS_O_STAT 0x20000000 // This request generated by stat()
69 #define SFS_O_META 0x40000000 // This request generated by metaop
70 
71 /******************************************************************************/
72 /* D e f i n e s */
73 /******************************************************************************/
74 
75 // Common fctl command values (0 to 255)
76 //
77 #define SFS_FCTL_GETFD 1 // Return file descriptor if possible
78 #define SFS_FCTL_STATV 2 // Return visa information
79 #define SFS_FCTL_SPEC1 3 // Return implementation defined information
80 
81 #define SFS_SFIO_FDVAL 0x80000000 // Use SendData() method GETFD response value
82 
83 // Common fsctl command values (0 to 255)
84 //
85 #define SFS_FSCTL_CMD 255
86 
87 #define SFS_FSCTL_LOCATE 1 // Locate a file
88 #define SFS_FSCTL_STATFS 2 // Return FS data
89 #define SFS_FSCTL_STATLS 3 // Return LS data
90 #define SFS_FSCTL_STATXA 4 // Return XA data
91 #define SFS_FSCTL_STATCC 5 // Return Cluster Config status
92 #define SFS_FSCTL_PLUGIN 8 // Return Implementation Dependent Data
93 #define SFS_FSCTL_PLUGIO 16 // Return Implementation Dependent Data
94 
95 // Return values for integer & XrdSfsXferSize returning XrdSfs methods
96 //
97 #define SFS_STALL 1 // Return value -> Seconds to stall client
98 #define SFS_OK 0 // ErrInfo code -> All is well
99 #define SFS_ERROR -1 // ErrInfo code -> Error occurred
100 #define SFS_REDIRECT -256 // ErrInfo code -> Port number to redirect to
101 #define SFS_STARTED -512 // ErrInfo code -> Estimated seconds to completion
102 #define SFS_DATA -1024 // ErrInfo code -> Length of data
103 
104 // The following macros are used for dealing with special local paths
105 //
106 #define SFS_LCLPRFX "/=/"
107 #define SFS_LCLPLEN 3
108 #define SFS_LCLPATH(x) !strncmp(x, SFS_LCLPRFX, SFS_LCLPLEN)
109 #define SFS_LCLPRFY "/="
110 #define SFS_LCLROOT(x) !strncmp(x, SFS_LCLPRFX, SFS_LCLPLEN-1) \
111  && (*(x+SFS_LCLPLEN-1) == '/' || *(x+SFS_LCLPLEN-1) == 0)
112 
113 /******************************************************************************/
114 /* S t r u c t u r e s & T y p e d e f s */
115 /******************************************************************************/
116 
117 typedef long long XrdSfsFileOffset;
118 typedef int XrdSfsFileOpenMode;
119 typedef int XrdSfsMode;
120 typedef int XrdSfsXferSize;
121 
123 {
129 };
130 //------------------------------------------------
131 
132 #define Prep_PRTY0 0
133 #define Prep_PRTY1 1
134 #define Prep_PRTY2 2
135 #define Prep_PRTY3 3
136 #define Prep_PMASK 3
137 #define Prep_SENDAOK 4
138 #define Prep_SENDERR 8
139 #define Prep_SENDACK 12
140 #define Prep_WMODE 16
141 #define Prep_STAGE 32
142 #define Prep_COLOC 64
143 #define Prep_FRESH 128
144 
145 class XrdOucTList;
146 
147 struct XrdSfsFSctl
148 {
149  const char *Arg1;
150  int Arg1Len;
151  int Arg2Len;
152  const char *Arg2;
153 };
154 
155 struct XrdSfsPrep
156 {
157  char *reqid;
158  char *notify;
159  int opts;
162 };
163 
164 /******************************************************************************/
165 /* A b s t r a c t C l a s s e s */
166 /******************************************************************************/
167 
168 class XrdSfsFile;
169 class XrdSfsDirectory;
170 class XrdOucEnv;
171 class XrdOucTList;
172 class XrdSecEntity;
173 
174 /******************************************************************************/
175 /* X r d S f s F i l e S y s t e m */
176 /******************************************************************************/
177 
178 //-----------------------------------------------------------------------------
202 //-----------------------------------------------------------------------------
203 
204 class XrdSfsFileSystem
205 {
206 public:
207 
208 //-----------------------------------------------------------------------------
218 //-----------------------------------------------------------------------------
219 
220 virtual XrdSfsDirectory *newDir(char *user=0, int MonID=0) = 0;
221 
222 //-----------------------------------------------------------------------------
232 //-----------------------------------------------------------------------------
233 
234 virtual XrdSfsFile *newFile(char *user=0, int MonID=0) = 0;
235 
236 //-----------------------------------------------------------------------------
255 //-----------------------------------------------------------------------------
256 
257 enum csFunc {csCalc = 0, csGet, csSize};
258 
259 virtual int chksum( csFunc Func,
260  const char *csName,
261  const char *path,
262  XrdOucErrInfo &eInfo,
263  const XrdSecEntity *client = 0,
264  const char *opaque = 0)
265 {
266  (void)Func; (void)csName; (void)path; (void)eInfo; (void)client;
267  (void)opaque;
268  eInfo.setErrInfo(ENOTSUP, "Not supported.");
269  return SFS_ERROR;
270 }
271 
272 //-----------------------------------------------------------------------------
282 //-----------------------------------------------------------------------------
283 
284 virtual int chmod(const char *path,
285  XrdSfsMode mode,
286  XrdOucErrInfo &eInfo,
287  const XrdSecEntity *client = 0,
288  const char *opaque = 0) = 0;
289 
290 //-----------------------------------------------------------------------------
294 //-----------------------------------------------------------------------------
295 
296 virtual void Disc(const XrdSecEntity *client = 0)
297 {
298  (void)client;
299 }
300 
301 //-----------------------------------------------------------------------------
306 //-----------------------------------------------------------------------------
307 
308 virtual void EnvInfo(XrdOucEnv *envP)
309 {
310  (void)envP;
311 }
312 
313 //-----------------------------------------------------------------------------
341 //-----------------------------------------------------------------------------
342 
343 virtual int FSctl(const int cmd,
344  XrdSfsFSctl &args,
345  XrdOucErrInfo &eInfo,
346  const XrdSecEntity *client = 0)
347 {
348  (void)cmd; (void)args; (void)eInfo; (void)client;
349  return SFS_OK;
350 }
351 
352 //-----------------------------------------------------------------------------
368 //-----------------------------------------------------------------------------
369 
370 virtual int fsctl(const int cmd,
371  const char *args,
372  XrdOucErrInfo &eInfo,
373  const XrdSecEntity *client = 0) = 0;
374 
375 //-----------------------------------------------------------------------------
385 //-----------------------------------------------------------------------------
386 
387 virtual int getStats(char *buff, int blen) = 0;
388 
389 //-----------------------------------------------------------------------------
393 //-----------------------------------------------------------------------------
394 
395 virtual const char *getVersion() = 0;
396 
397 //-----------------------------------------------------------------------------
413 //-----------------------------------------------------------------------------
414 
415 virtual int exists(const char *path,
416  XrdSfsFileExistence &eFlag,
417  XrdOucErrInfo &eInfo,
418  const XrdSecEntity *client = 0,
419  const char *opaque = 0) = 0;
420 
421 //-----------------------------------------------------------------------------
431 //-----------------------------------------------------------------------------
432 
433 virtual int mkdir(const char *path,
434  XrdSfsMode mode,
435  XrdOucErrInfo &eInfo,
436  const XrdSecEntity *client = 0,
437  const char *opaque = 0) = 0;
438 
439 //-----------------------------------------------------------------------------
447 //-----------------------------------------------------------------------------
448 
449 virtual int prepare( XrdSfsPrep &pargs,
450  XrdOucErrInfo &eInfo,
451  const XrdSecEntity *client = 0) = 0;
452 
453 //-----------------------------------------------------------------------------
462 //-----------------------------------------------------------------------------
463 
464 virtual int rem(const char *path,
465  XrdOucErrInfo &eInfo,
466  const XrdSecEntity *client = 0,
467  const char *opaque = 0) = 0;
468 
469 //-----------------------------------------------------------------------------
478 //-----------------------------------------------------------------------------
479 
480 virtual int remdir(const char *path,
481  XrdOucErrInfo &eInfo,
482  const XrdSecEntity *client = 0,
483  const char *opaque = 0) = 0;
484 
485 //-----------------------------------------------------------------------------
496 //-----------------------------------------------------------------------------
497 
498 virtual int rename(const char *oPath,
499  const char *nPath,
500  XrdOucErrInfo &eInfo,
501  const XrdSecEntity *client = 0,
502  const char *opaqueO = 0,
503  const char *opaqueN = 0) = 0;
504 
505 //-----------------------------------------------------------------------------
516 //-----------------------------------------------------------------------------
517 
518 virtual int stat(const char *Name,
519  struct stat *buf,
520  XrdOucErrInfo &eInfo,
521  const XrdSecEntity *client = 0,
522  const char *opaque = 0) = 0;
523 
524 //-----------------------------------------------------------------------------
536 //-----------------------------------------------------------------------------
537 
538 virtual int stat(const char *path,
539  mode_t &mode,
540  XrdOucErrInfo &eInfo,
541  const XrdSecEntity *client = 0,
542  const char *opaque = 0) = 0;
543 
544 //-----------------------------------------------------------------------------
554 //-----------------------------------------------------------------------------
555 
556 virtual int truncate(const char *path,
557  XrdSfsFileOffset fsize,
558  XrdOucErrInfo &eInfo,
559  const XrdSecEntity *client = 0,
560  const char *opaque = 0) = 0;
561 
562 //-----------------------------------------------------------------------------
564 //-----------------------------------------------------------------------------
565 
566  XrdSfsFileSystem() {}
567 virtual ~XrdSfsFileSystem() {}
568 };
569 
570 /******************************************************************************/
571 /* F i l e S y s t e m I n s t a n t i a t o r */
572 /******************************************************************************/
573 
574 //-----------------------------------------------------------------------------
593 //-----------------------------------------------------------------------------
594 
595 //------------------------------------------------------------------------------
607 //------------------------------------------------------------------------------
608 
609 /******************************************************************************/
610 /* X r d S f s F i l e */
611 /******************************************************************************/
612 
613 //------------------------------------------------------------------------------
616 //------------------------------------------------------------------------------
617 
618 class XrdSfsAio;
619 class XrdSfsDio;
620 class XrdSfsXio;
621 
622 class XrdSfsFile
623 {
624 public:
625 
626 //-----------------------------------------------------------------------------
629 //-----------------------------------------------------------------------------
630 
631  XrdOucErrInfo error;
632 
633 //-----------------------------------------------------------------------------
654 //-----------------------------------------------------------------------------
655 
656 virtual int open(const char *fileName,
657  XrdSfsFileOpenMode openMode,
658  mode_t createMode,
659  const XrdSecEntity *client = 0,
660  const char *opaque = 0) = 0;
661 
662 //-----------------------------------------------------------------------------
666 //-----------------------------------------------------------------------------
667 
668 virtual int close() = 0;
669 
670 //-----------------------------------------------------------------------------
687 //-----------------------------------------------------------------------------
688 
689 virtual int fctl(const int cmd,
690  const char *args,
691  XrdOucErrInfo &eInfo) = 0;
692 
693 //-----------------------------------------------------------------------------
706 //-----------------------------------------------------------------------------
707 
708 virtual int fctl(const int cmd,
709  int alen,
710  const char *args,
711  const XrdSecEntity *client = 0)
712 {
713  (void)cmd; (void)alen; (void)args; (void)client;
714  return SFS_OK;
715 }
716 
717 //-----------------------------------------------------------------------------
721 //-----------------------------------------------------------------------------
722 
723 virtual const char *FName() = 0;
724 
725 
726 //-----------------------------------------------------------------------------
733 //-----------------------------------------------------------------------------
734 
735 virtual int getMmap(void **Addr, off_t &Size) = 0;
736 
737 //-----------------------------------------------------------------------------
745 //-----------------------------------------------------------------------------
746 
747 virtual XrdSfsXferSize read(XrdSfsFileOffset offset,
748  XrdSfsXferSize size) = 0;
749 
750 //-----------------------------------------------------------------------------
759 //-----------------------------------------------------------------------------
760 
761 virtual XrdSfsXferSize read(XrdSfsFileOffset offset,
762  char *buffer,
763  XrdSfsXferSize size) = 0;
764 
765 //-----------------------------------------------------------------------------
772 //-----------------------------------------------------------------------------
773 
774 virtual XrdSfsXferSize read(XrdSfsAio *aioparm) = 0;
775 
776 //-----------------------------------------------------------------------------
786 //-----------------------------------------------------------------------------
787 
788 virtual XrdSfsXferSize readv(XrdOucIOVec *readV,
789  int rdvCnt)
790  {XrdSfsXferSize rdsz, totbytes = 0;
791  for (int i = 0; i < rdvCnt; i++)
792  {rdsz = read(readV[i].offset,
793  readV[i].data, readV[i].size);
794  if (rdsz != readV[i].size)
795  {if (rdsz < 0) return rdsz;
796  error.setErrInfo(ESPIPE,"read past eof");
797  return SFS_ERROR;
798  }
799  totbytes += rdsz;
800  }
801  return totbytes;
802  }
803 
804 //-----------------------------------------------------------------------------
814 //-----------------------------------------------------------------------------
815 
816 virtual int SendData(XrdSfsDio *sfDio,
817  XrdSfsFileOffset offset,
818  XrdSfsXferSize size)
819 {
820  (void)sfDio; (void)offset; (void)size;
821  return SFS_OK;
822 }
823 
824 //-----------------------------------------------------------------------------
833 //-----------------------------------------------------------------------------
834 
835 virtual XrdSfsXferSize write(XrdSfsFileOffset offset,
836  const char *buffer,
837  XrdSfsXferSize size) = 0;
838 
839 //-----------------------------------------------------------------------------
846 //-----------------------------------------------------------------------------
847 
848 virtual int write(XrdSfsAio *aioparm) = 0;
849 
850 //-----------------------------------------------------------------------------
860 //-----------------------------------------------------------------------------
861 
862 virtual XrdSfsXferSize writev(XrdOucIOVec *writeV,
863  int wdvCnt)
864  {XrdSfsXferSize wrsz, totbytes = 0;
865  for (int i = 0; i < wdvCnt; i++)
866  {wrsz = write(writeV[i].offset,
867  writeV[i].data, writeV[i].size);
868  if (wrsz != writeV[i].size)
869  {if (wrsz < 0) return wrsz;
870  error.setErrInfo(ESPIPE,"write past eof");
871  return SFS_ERROR;
872  }
873  totbytes += wrsz;
874  }
875  return totbytes;
876  }
877 
878 //-----------------------------------------------------------------------------
885 //-----------------------------------------------------------------------------
886 
887 virtual int stat(struct stat *buf) = 0;
888 
889 //-----------------------------------------------------------------------------
893 //-----------------------------------------------------------------------------
894 
895 virtual int sync() = 0;
896 
897 //-----------------------------------------------------------------------------
902 //-----------------------------------------------------------------------------
903 
904 virtual int sync(XrdSfsAio *aiop) = 0;
905 
906 //-----------------------------------------------------------------------------
912 //-----------------------------------------------------------------------------
913 
914 virtual int truncate(XrdSfsFileOffset fsize) = 0;
915 
916 //-----------------------------------------------------------------------------
924 //-----------------------------------------------------------------------------
925 
926 virtual int getCXinfo(char cxtype[4], int &cxrsz) = 0;
927 
928 //-----------------------------------------------------------------------------
932 //-----------------------------------------------------------------------------
933 
934 virtual void setXio(XrdSfsXio *xioP) { (void)xioP; }
935 
936 //-----------------------------------------------------------------------------
943 //-----------------------------------------------------------------------------
944 
945  XrdSfsFile(const char *user=0, int MonID=0)
946  : error(user, MonID) {}
947 
948 //-----------------------------------------------------------------------------
950 //-----------------------------------------------------------------------------
951 
952 virtual ~XrdSfsFile() {}
953 
954 }; // class XrdSfsFile
955 
956 /******************************************************************************/
957 /* X r d S f s D i r e c t o r y */
958 /******************************************************************************/
959 
960 //------------------------------------------------------------------------------
963 //------------------------------------------------------------------------------
964 
965 class XrdSfsDirectory
966 {
967 public:
968 
969 //-----------------------------------------------------------------------------
972 //-----------------------------------------------------------------------------
973 
974  XrdOucErrInfo error;
975 
976 //-----------------------------------------------------------------------------
984 //-----------------------------------------------------------------------------
985 
986 virtual int open(const char *path,
987  const XrdSecEntity *client = 0,
988  const char *opaque = 0) = 0;
989 
990 //-----------------------------------------------------------------------------
998 //-----------------------------------------------------------------------------
999 
1000 virtual const char *nextEntry() = 0;
1001 
1002 //-----------------------------------------------------------------------------
1006 //-----------------------------------------------------------------------------
1007 
1008 virtual int close() = 0;
1009 
1010 //-----------------------------------------------------------------------------
1014 //-----------------------------------------------------------------------------
1015 
1016 virtual const char *FName() = 0;
1017 
1018 //-----------------------------------------------------------------------------
1024 //-----------------------------------------------------------------------------
1025 
1026 virtual int autoStat(struct stat *buf)
1027  {(void)buf;
1028  error.setErrInfo(ENOTSUP, "Not supported.");
1029  return SFS_ERROR;
1030  }
1031 
1032 //-----------------------------------------------------------------------------
1039 //-----------------------------------------------------------------------------
1040 
1041  XrdSfsDirectory(const char *user=0, int MonID=0)
1042  : error(user, MonID) {}
1043 
1044 //-----------------------------------------------------------------------------
1046 //-----------------------------------------------------------------------------
1047 
1048 virtual ~XrdSfsDirectory() {}
1049 
1050 }; // class XrdSfsDirectory
1051 #endif
int opts
Prep_xxx.
Definition: XrdSfsInterface.hh:159
XrdOucTList * oinfo
1-to-1 correspondence of opaque info
Definition: XrdSfsInterface.hh:161
#define SFS_OK
Definition: XrdSfsInterface.hh:98
const char * Arg1
PLUGIO &amp; PLUGIN.
Definition: XrdSfsInterface.hh:149
int XrdSfsXferSize
Definition: XrdSfsInterface.hh:120
char * notify
Notification path or 0.
Definition: XrdSfsInterface.hh:158
XrdSfsFileExistence
Definition: XrdSfsInterface.hh:122
long long XrdSfsFileOffset
Definition: XrdSfsInterface.hh:117
int Arg1Len
Length.
Definition: XrdSfsInterface.hh:150
Definition: XrdSfsInterface.hh:124
&lt; SFS_FSCTL_PLUGIN/PLUGIO parameters
Definition: XrdSfsInterface.hh:147
Definition: XrdOucErrInfo.hh:97
Definition: XrdSfsInterface.hh:125
Definition: XrdSfsInterface.hh:127
#define SFS_ERROR
Definition: XrdSfsInterface.hh:99
Definition: XrdOucEnv.hh:41
Definition: XrdOucIOVec.hh:40
const char * Arg2
PLUGIN opaque string.
Definition: XrdSfsInterface.hh:152
Definition: XrdOucTList.hh:37
XrdOucTList * paths
List of paths.
Definition: XrdSfsInterface.hh:160
char * reqid
Request ID.
Definition: XrdSfsInterface.hh:157
int XrdSfsMode
Definition: XrdSfsInterface.hh:119
int Arg2Len
Length.
Definition: XrdSfsInterface.hh:151
Definition: XrdSecEntity.hh:51
Definition: XrdSfsInterface.hh:128
Definition: XrdSfsAio.hh:57
&lt; Prepare parameters
Definition: XrdSfsInterface.hh:155
int XrdSfsFileOpenMode
Definition: XrdSfsInterface.hh:118
int setErrInfo(int code, const char *emsg)
Definition: XrdOucErrInfo.hh:144
Definition: XrdSfsInterface.hh:126