XRootD
XrdSsiFileSess.hh
Go to the documentation of this file.
1 #ifndef __SSI_FILESESS_H__
2 #define __SSI_FILESESS_H__
3 /******************************************************************************/
4 /* */
5 /* X r d S s i F i l e S e s s . h h */
6 /* */
7 /* (c) 2016 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 <cstring>
33 #include <sys/types.h>
34 
36 #include "XrdSfs/XrdSfsXio.hh"
37 #include "XrdSsi/XrdSsiBVec.hh"
38 #include "XrdSsi/XrdSsiFileReq.hh"
40 #include "XrdSsi/XrdSsiRRTable.hh"
41 #include "XrdSys/XrdSysPthread.hh"
42 
43 class XrdOucEnv;
44 struct XrdSsiRespInfo;
45 
47 {
48 public:
49 
50 static XrdSsiFileSess *Alloc(XrdOucErrInfo &einfo, const char *user);
51 
52  bool AttnInfo( XrdOucErrInfo &eInfo,
53  const XrdSsiRespInfo *respP,
54  unsigned int reqID);
55 
56  bool DeferFinalize(XrdSsiFileReq *req,uint64_t itemID)
57  {return rTab.DeferFinalize(req,itemID);}
58 
59  void DeferredFinalizeDone(XrdSsiFileReq *req, uint64_t itemID)
60  {return rTab.DeferredFinalizeDone(req, itemID);}
61 
62  XrdOucErrInfo *errInfo() {return eInfo;}
63 
64  int close(bool viaDel=false);
65 
66  int fctl(const int cmd,
67  int alen,
68  const char *args,
69  const XrdSecEntity *client);
70 
71  const char *FName() {return gigID;}
72 
73  int open(const char *fileName,
75  XrdSfsFileOpenMode openMode);
76 
78  char *buffer,
79  XrdSfsXferSize buffer_size);
80 
81  void Recycle();
82 
83 XrdSsiFileResource &Resource() {return fileResource;}
84 
85  int SendData(XrdSfsDio *sfDio,
86  XrdSfsFileOffset offset,
87  XrdSfsXferSize size);
88 
89 static void SetAuthDNS() {authDNS = true;}
90 
91  void setXio(XrdSfsXio *xP) {xioP = xP;}
92 
93  int truncate(XrdSfsFileOffset fileOffset);
94 
96  const char *buffer,
97  XrdSfsXferSize buffer_size);
98 
99 private:
100 
101 // Constructor (via Alloc()) and destructor (via Recycle())
102 //
103  XrdSsiFileSess(XrdOucErrInfo &einfo, const char *user)
104  {Init(einfo, user, false);}
105  ~XrdSsiFileSess() {} // Recycle() calls Reset()
106 
107 // Callback to keep a request object from an rable lookup referenced
108 // until the callback completes
109 //
110 class reqItemCB : public XrdOucEICB
111 {
112 public:
113 
114  reqItemCB() { }
115 virtual ~reqItemCB() { }
116 
117 void Done(int &Result, XrdOucErrInfo *cbInfo,
118  const char *path=0)
119  {rqstP->Done(Result,cbInfo,path); rqstP.reset();}
120 
121 int Same(unsigned long long arg1, unsigned long long arg2)
122  {return 0;}
123 
124 void setReq(XrdSsiRRTableItem<XrdSsiFileReq> &&r) { rqstP = std::move(r); }
125 
127 };
128 
129 void Init(XrdOucErrInfo &einfo, const char *user, bool forReuse);
130 bool NewRequest(unsigned int reqid, XrdOucBuffer *oP,
131  XrdSfsXioHandle bR, int rSz);
132 void Reset();
133 XrdSfsXferSize writeAdd(const char *buff, XrdSfsXferSize blen,
134  unsigned int rid);
135 
136 static XrdSysMutex arMutex; // Alloc and Recycle protector
137 static XrdSsiFileSess *freeList;
138 static int freeNum;
139 static int freeNew;
140 static int freeMax;
141 static int freeAbs;
142 static bool authDNS;
143 
144 XrdSsiFileResource fileResource;
145 char *tident;
146 XrdOucErrInfo *eInfo;
147 char *gigID;
148 char *fsUser;
149 XrdSysMutex myMutex;
150 XrdSfsXio *xioP;
151 XrdOucBuffer *oucBuff;
152 XrdSsiFileSess *nextFree;
153 int reqSize;
154 int reqLeft;
155 bool isOpen;
156 bool inProg;
157 
158 XrdSsiBVec eofVec;
160 reqItemCB fctlCallBack;
161 reqItemCB attnFinCallBack;
162 };
163 #endif
int XrdSfsFileOpenMode
long long XrdSfsFileOffset
int XrdSfsXferSize
class XrdBuffer * XrdSfsXioHandle
Definition: XrdSfsXio.hh:46
virtual void Done(int &Result, XrdOucErrInfo *eInfo, const char *Path=0)=0
void setXio(XrdSfsXio *xP)
int fctl(const int cmd, int alen, const char *args, const XrdSecEntity *client)
int open(const char *fileName, XrdOucEnv &theEnv, XrdSfsFileOpenMode openMode)
bool DeferFinalize(XrdSsiFileReq *req, uint64_t itemID)
XrdOucErrInfo * errInfo()
XrdSsiFileResource & Resource()
int close(bool viaDel=false)
XrdSfsXferSize write(XrdSfsFileOffset fileOffset, const char *buffer, XrdSfsXferSize buffer_size)
void DeferredFinalizeDone(XrdSsiFileReq *req, uint64_t itemID)
bool AttnInfo(XrdOucErrInfo &eInfo, const XrdSsiRespInfo *respP, unsigned int reqID)
static void SetAuthDNS()
XrdSfsXferSize read(XrdSfsFileOffset fileOffset, char *buffer, XrdSfsXferSize buffer_size)
const char * FName()
int truncate(XrdSfsFileOffset fileOffset)
int SendData(XrdSfsDio *sfDio, XrdSfsFileOffset offset, XrdSfsXferSize size)
static XrdSsiFileSess * Alloc(XrdOucErrInfo &einfo, const char *user)
bool DeferFinalize(T *item, uint64_t itemID)
void DeferredFinalizeDone(T *item, uint64_t itemID)
XrdOucEnv theEnv