xrootd
XrdCmsClient.hh
Go to the documentation of this file.
1 #ifndef __CMS_CLIENT__
2 #define __CMS_CLIENT__
3 /******************************************************************************/
4 /* */
5 /* X r d C m s C l i e n t . h h */
6 /* */
7 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 class XrdOucEnv;
14 class XrdOucErrInfo;
15 class XrdOucLogger;
16 class XrdOucTList;
17 struct XrdSfsPrep;
18 
19 /******************************************************************************/
20 /* R e t u r n C o n v e n t i o n s */
21 /******************************************************************************/
22 
23 /* The following return conventions are use by Forward(), Locate(), & Prepare()
24  Return Val Resp.errcode Resp.errtext
25  --------- ------------------- --------
26  SFS_DATA Length of data. Data to be returned to caller.
27  Action: Caller is provided data as successful response.
28 
29  SFS_ERROR errno Error message text.
30  Action: Caller given error response.
31 
32  SFS_REDIRECT port (0 for default) Host name
33  Action: Caller is redirected to <host>:<port>
34 
35  SFS_STARTED Expected seconds n/a
36  Action: Caller is told to wait for the "expected seconds" for a
37  callback with the result. A callback must follow.
38  See how to do callbacks below.
39 
40  > 0 Wait time (= retval) Reason for wait
41  Action: Caller told to wait retval seconds and retry request.
42 
43  < 0 Error number Error message
44  Action: Same as SFS_ERROR. You should *always* use SFS_ERROR.
45 
46  = 0 Not applicable Not applicable (see below)
47  Action: Forward() -> Return success; request forwarded.
48  Locate() -> Redirection does not apply, operation
49  should be done against local file system.
50  Prepare() -> Return success, request submitted.
51 */
52 
53 /******************************************************************************/
54 /* C a l l b a c k C o n v e n t i o n s */
55 /******************************************************************************/
56 
57 /* Most operations allow you to return SFS_STARTED to setup a callback.
58  Callback information is contained in the XrdOucErrInfo object passed to
59  Forward(), Locate() and Prepare(); the only methods that can apply callbacks.
60  Use a callback when the operation will take at least several seconds so as
61  to not occupy the calling thread for an excessive amount of time.
62 
63  The actual mechanics of a callback are rather complicated because callbacks
64  are subject to non-causaility if not correctly handled. In order to avoid
65  such issues, you should use the XrdOucCallBack object (see XrdOucCallBack.hh)
66  to test for applicability, setup, and effect a callback.
67 
68  When calling back, you return the same information you would have returned
69  had the execution path been synchronous. From that standpoint callbacks are
70  relatively easy to understand. All you are doing is defering the return of
71  information without occupying a thread while waiting to do so.
72 
73  A typical scenario, using Resp and the original ErrInfo object, would be....
74 
75  XrdOucCallBack cbObject; // Must be persistent for the callback duration
76 
77  if (XrdOucCallBack::Allowed(Resp))
78  {cbObject.Init(Resp);
79  <hand off the cbObject to a thread that will perform the work>
80  Resp.setErrCode(<seconds end-point should wait>);
81  return SFS_STARTED; // Effect callback response!
82  }
83 
84  Once the thread doing the work has a result, send it via a callback as if
85  the work was done in a synchronous fashion.
86 
87  cbObject->Reply(retValue, ErrCodeValue, ErrTextValue);
88 */
89 
90 /******************************************************************************/
91 /* C l a s s X r d C m s C l i e n t */
92 /******************************************************************************/
93 
95 {
96 public:
97 
98 // Added() notifies the cms of a newly added file or a file whose state has
99 // changed. It is only used on data server nodes. When Pend is true,
100 // the file is scheduled to be present in the future (e.g. copied in).
101 //
102 virtual void Added(const char *path, int Pend=0) {}
103 
104 // Configue() is called to configure the client. If the client is obtained via
105 // a plug-in then Parms are whether parameters were specified after
106 // cmslib path. It is zero if no parameters exist.
107 // Return: If successful, true must be returned; otherise, false/
108 //
109 virtual int Configure(const char *cfn, char *Parms, XrdOucEnv *EnvInfo) = 0;
110 
111 // Forward() relays a meta-operation to all nodes in the cluster. It is only
112 // used on manager nodes and is enabled by the ofs.forward directive.
113 // The 'cmd" specified what command is must be forwarded (see table).
114 // If it starts with a '+' then a response (2way) is needed.
115 // Otherwise, a best-effort is all that is all that is required and
116 // success can always be returned. The "Env" arguments provide
117 // associated environmental information. For instance, opaque data
118 // can be retrieved by Env->Env(<len>). The following is passed:
119 
120 // cmd arg1 arg2 cmd arg1 arg2
121 // -------- ------ ------ -------- ------ ------
122 // [+]chmod <path> <mode %o> [+]rmdir <path> 0
123 // [+]mkdir <path> <mode %o> [+]mv <oldp> <newp>
124 // [+]mkpath <path> <mode %o> [+]trunc <path> <size %lld>
125 // [+]rm <path> 0
126 
127 // Return: As explained under "return conventions".
128 //
129 virtual int Forward(XrdOucErrInfo &Resp, const char *cmd,
130  const char *arg1=0, const char *arg2=0,
131  XrdOucEnv *Env1=0, XrdOucEnv *Env2=0) {return 0;}
132 
133 // isRemote() returns true of this client is configured for a manager node.
134 //
135 virtual int isRemote() {return myPersona == XrdCmsClient::amRemote;}
136 
137 // Locate() is called to retrieve file location information. It is only used
138 // on a manager node. This can be the list of servers that have a
139 // file or the single server that the client should be sent to. The
140 // "flags" indicate what is required and how to process the request.
141 
142 // SFS_O_LOCATE - return the list of servers that have the file.
143 // Otherwise, redirect to the best server for the file.
144 // SFS_O_NOWAIT - w/ SFS_O_LOCATE return readily available info.
145 // Otherwise, select online files only.
146 // SFS_O_CREAT - file will be created.
147 // SFS_O_NOWAIT - select server if file is online.
148 // SFS_O_REPLICA - a replica of the file will be made.
149 // SFS_O_STAT - only stat() information wanted.
150 // SFS_O_TRUNC - file will be truncated.
151 
152 // For any the the above, additional flags are passed:
153 // SFS_O_META - data will not change (inode operation only)
154 // SFS_O_RESET - reset cached info and recaculate the location(s).
155 // SFS_O_WRONLY - file will be only written (o/w RDWR or RDONLY).
156 // SFS_O_RDWR - file may be read and written (o/w WRONLY or RDONLY).
157 
158 // Return: As explained under "return conventions".
159 //
160 virtual int Locate(XrdOucErrInfo &Resp, const char *path, int flags,
161  XrdOucEnv *Info=0) = 0;
162 
163 // Managers() is called to obtain the list of cmsd's being used by a manager
164 // node along with their associated index numbers, origin 1.
165 // This is used by the monitoring systems to report who redirected.
166 // The list is considered permanent and is not deleted.
167 
168 // Return: A list of managers or null if none exist.
169 //
170 virtual
171 XrdOucTList *Managers() {return 0;}
172 
173 // Prepare() is called to start the preparation of a file for future processing.
174 // It is only used on a manager node.
175 
176 // Return: As explained under "return conventions".
177 //
178 virtual int Prepare(XrdOucErrInfo &Resp, XrdSfsPrep &pargs,
179  XrdOucEnv *Info=0) {return 0;}
180 
181 // Removed() is called when a file or directory has been deleted. It is only
182 // called on a data server node.
183 //
184 virtual void Removed(const char *path) {}
185 
186 // Resume() and Suspend() server complimentary functions and, by default,
187 // persist across server restarts. A temporary suspend/resume may be
188 // requested by passing a value of 0. Suspend() informs cluster
189 // managers that data services are suspended. Resume() re-enables
190 // data services. The default implementation performs nothing.
191 //
192 virtual void Resume (int Perm=1) {}
193 virtual void Suspend(int Perm=1) {}
194 
195 // The following set of functions can be used to control whether or not clients
196 // are dispatched to this data server based on a virtual resource. The default
197 // implementations do nothing.
198 //
199 // Resource() should be called first and enables the Reserve() & Release()
200 // methods. It's argument a positive integer that specifies the
201 // amount of resource units that are available. It may be called
202 // at any time (though usually it is not) and returns the previous
203 // value. This first call will return 0.
204 // Reserve() decreases the amount of resources available by the value passed
205 // as the argument (default is 1). When the available resources
206 // becomes non-positive, a temporary suspend is activated preventing
207 // additional clients from being dispatched to this data server.
208 // Reserve() returns the amount of resource left.
209 // Release() increases the amount of resource available by the value passed
210 // as the argument (default 1). The total amount is capped by the
211 // amount specified by Resource(). When a transition is made from
212 // a non-positive to a positive amount, resume is activated that
213 // allows additional clients to be dispatched to this data server.
214 // Release() returns the amount of resource left.
215 //
216 virtual int Resource(int n) {return 0;}
217 virtual int Reserve (int n=1) {return 0;}
218 virtual int Release (int n=1) {return 0;}
219 
220 // Space() is called to obtain the overall space usage of a cluster. It is
221 // only called on manager nodes.
222 
223 // Return: Space information as defined by the response to kYR_statfs. Fo a
224 // typical implementation see XrdCmsNode::do_StatFS().
225 //
226 virtual int Space(XrdOucErrInfo &Resp, const char *path,
227  XrdOucEnv *Info=0) = 0;
228 
230 
231  XrdCmsClient(Persona acting) : myPersona(acting) {}
232 virtual ~XrdCmsClient() {}
233 
234 protected:
235 
237 };
238 
239 /******************************************************************************/
240 /* I n s t a n t i a t i o n M o d e F l a g s */
241 /******************************************************************************/
242 
243 // The following instantiation mode flags are passed to the instantiator. They
244 // may be or'd together, depending on which mode the client should operate.
245 // They are defined as follows:
246 
247 namespace XrdCms
248 {
249 enum {IsProxy = 1, // The role is proxy <one or more of the below>
250  IsRedir = 2, // The role is manager and will redirect users
251  IsTarget = 4, // The role is server and will be a redirection target
252  IsMeta = 8 // The role is meta <one or more of the above>
253  };
254 }
255 
256 /******************************************************************************/
257 /* C M S C l i e n t I n s t a n t i a t o r */
258 /******************************************************************************/
259 
260 // This function is called to obtain an instance of a configured XrdCmsClient
261 // Object. This is only used of the client is an actual plug-in as identified
262 // by the ofs.cmslib directive.
263 
264 // There are two general types of clients, Redir and Target. The plug-in must
265 // provide an instance of each whether or not they actually do anything.
266 
267 // Redir clients are anything other than a data provider (i.e., data servers).
268 // These clients are expected to locate files and redirect a requestor
269 // to an actual data server.
270 
271 // Target clients are typically data providers (i.e., data servers) but may
272 // actually do other functions are are allowed to redirect as well.
273 
274 // The instantiator is passed the operational mode (opMode) as defined by the
275 // enum above. The returned object must provide suitable functions for the mode.
276 
277 // If successful, the instantiator must return a pointer to the appropriate
278 // object. Otherwise, a null pointer should be returned upon which server
279 // initialization fails.
280 
281 // As this is a plug-in, the plug-in loader searches the cmslib for the
282 // following extern symbol which must be a "C" type symbol. Once the object
283 // is obtained, its Configure() method is called to initialize the object.
284 
285 /*
286 extern "C"
287 {
288 XrdCmsClient *XrdCmsGetClient(XrdSysLogger *Logger, // Where messages go
289  int opMode, // Operational mode
290  int myPort, // Server's port number
291  XrdOss *theSS); // Storage System I/F
292 }
293 */
294 #endif