xrootd
XrdCmsXmi.hh
Go to the documentation of this file.
1 #ifndef __XRDCMSXMI_H__
2 #define __XRDCMSXMI_H__
3 /******************************************************************************/
4 /* */
5 /* X r d C m s X m i . 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 // $Id$
14 
15 #include <sys/types.h>
16 
17 #include "XrdCms/XrdCmsReq.hh"
18 
19 /*
20  The XrdCmsXmi class defines the interface the cmsd uses to an external
21  manager. When the cms.xmilib directive is specified, the cmsd loads the
22  plugin using XrdCmsgetXmi() to instantiate the plugin objects, as explained
23  after the definition of the abstract class. The cmsd then uses the Xmi
24  defined methods to process certain requests instead of it's own default
25  methods. As the Xmi interface runs synchronously with respect to being called,
26  it should dispatch any long work to another thread to allow the next request
27  to be processed by the plugin. You should use the thread scheduler passed
28  via the XrdCmsXmiEnv structure (see below).
29 
30  Each method (other that Prep(), see below) is passed an XrdCmsReq object.
31  This object must be used to send a reply to the client (only one reply is
32  allowed). A reply is *mandatory* if the function returns TRUE; even if that
33  reply is merely an indication that everything succeeded. A reply must *not*
34  be sent if the function returns FALSE; as a reply will be sent by the driver.
35  Refer to XrdCmsReq.hh on the description of how replies are effected.
36 
37  The mv, rm, and rmdir methods may be called in an advisory way. This occurs
38  during cross-cache synchronization when more than one redirector is deployed.
39  Use the XrdCmsReq::Advisory() method in determine if this is an action call
40  or an advisory call.
41 
42  The Prep() method is a background function and the client never expects a
43  reply. Therefore, no request object is passed since no reply is possible.
44  Instead, the first parameter is a request ID that is used to tag the
45  request. This ID may be passed later with XMI_CANCEL set to cancel and
46  path passed as a null string. All preparation for files tagged with request
47  ID should be stopped, if possible.
48 
49  The Xmi methods may be called in one of two modes, DIRECT or INDIRECT.
50  The modes are indicated by XeqMode(). In DIRECT mode the Xmi methods are
51  called synchronously. In INDIRECT mode, the Xmi methods are given thread as
52  well as client isolation by the cmsd using an asynchronous encapsulated
53  callback mechanism. Normally, INDIRECT mode should be used. The
54  implementation is not particularly relevant as the protocol details are
55  handled by the Xmi driver and the request object.
56 
57  Each method must return either true (1) or false (0). However, the action
58  taken based on the return value depends on the calling mode.
59 
60  TRUE (1) -> The function was processed and a reply was sent.
61  Action: INDIRECT: Normal processing continues, the request was done.
62  DIRECT: Same as above.
63  FALSE (0) -> The function was *not* processed and *no* reply was sent.
64  Action: INDIRECT: An error reply is sent and processing continues.
65  DIRECT: Processing continues as if the Xmi was not present.
66 
67  See the description of XeqMode() on how to indicate which methods are to
68  be called and which mode each method requires.
69 */
70 
71 /******************************************************************************/
72 /* X r d C m s X m i E n v */
73 /******************************************************************************/
74 
75 /* The XrdCmsXmiEnv structure is passed to XrdCmsgetXmi() and contains
76  information that may be relevant to the Xmi object. The information is
77  static in that it persists during the execution of the program.
78 */
79 
80 class XrdSysError;
81 class XrdInet;
82 class XrdScheduler;
83 class XrdOucName2Name;
84 class XrdOucTrace;
85 
87 {
88 const char *Role; // Manager | Peer | Proxy | Supervisor | Server
89 const char *ConfigFN; // -> Config file name
90 const char *Parms; // -> Optional parms from xmilib directive
91 XrdSysError *eDest; // -> Error message handler
92 XrdInet *iNet; // -> Network object
93 XrdScheduler *Sched; // -> Thread scheduler
94 XrdOucTrace *Trace; // -> Trace handler
95 XrdOucName2Name *Name2Name; // -> lfn to xxx mapper (may be null)
96 };
97 
98 /******************************************************************************/
99 /* X r d C m s X m i */
100 /******************************************************************************/
101 
102 class XrdCmsPrepArgs;
103 
104 // Flags passed to Prep(): XMI_RW, XMI_CANCEL
105 // Flags passed to Select(): XMI_RW, XMI_NEW, XMI_TRUNC, XMI_LOCATE
106 //
107 #define XMI_RW 0x0001
108 #define XMI_NEW 0x0002
109 #define XMI_TRUNC 0x0004
110 #define XMI_CANCEL 0x0008
111 #define XMI_LOCATE 0x0010
112 
113 // Flags to be passed back by XeqMode()
114 //
115 #define XMI_CHMOD 0x00000001
116 #define XMI_LOAD 0x00000002
117 #define XMI_MKDIR 0x00000004
118 #define XMI_MKPATH 0x00000008
119 #define XMI_PREP 0x00000010
120 #define XMI_RENAME 0x00000020
121 #define XMI_REMDIR 0x00000040
122 #define XMI_REMOVE 0x00000080
123 #define XMI_SELECT 0x00000100
124 #define XMI_SPACE 0x00000200
125 #define XMI_STAT 0x00000400
126 #define XMI_ALL 0x000007ff
127 
129 {
130 public:
131 
132 // Called when trying to change the mode of a file; opaque may be a nil ptr.
133 //
134 virtual int Chmod ( XrdCmsReq *Request,
135  mode_t mode,
136  const char *path,
137  const char *opaque) = 0;
138 
139 // Called when trying to determine the load on this host (not yet implemented)
140 //
141 virtual int Load ( XrdCmsReq *Request) {return 0;} // Server only
142 
143 // Called to make a directory; opaque may be a nil ptr.
144 //
145 virtual int Mkdir ( XrdCmsReq *Request,
146  mode_t mode,
147  const char *path,
148  const char *opaque) = 0;
149 
150 // Called to make a directory path; opaque may be a nil ptr.
151 //
152 virtual int Mkpath( XrdCmsReq *Request,
153  mode_t mode,
154  const char *path,
155  const char *opaque) = 0;
156 
157 // Called to prepare future access to a file; opaque may be a nil ptr.
158 //
159 virtual int Prep (const char *ReqID,
160  int Opts,
161  const char *Path,
162  const char *Opaque) = 0;
163 
164 // Called to rename a file or directory; oldopaque/newopaque may be a nil ptrs.
165 //
166 virtual int Rename( XrdCmsReq *Request,
167  const char *oldpath,
168  const char *oldopaque,
169  const char *newpath,
170  const char *newopaque) = 0;
171 
172 // Called to remove a directory; opaque may be a nil ptr.
173 //
174 virtual int Remdir( XrdCmsReq *Request,
175  const char *path,
176  const char *opaque) = 0;
177 
178 // Called to remove a file; opaque may be a nil ptr.
179 //
180 virtual int Remove( XrdCmsReq *Request,
181  const char *path,
182  const char *opaque) = 0;
183 
184 // Called when a client attempts to locate or open a file. The opts indicate
185 // how the file will used and whether it is to be created. The opaque may be
186 // a nil ptr.
187 //
188 virtual int Select( XrdCmsReq *Request, // See description above
189  int opts,
190  const char *path,
191  const char *opaque) = 0;
192 
193 // Called to determine how much space exists in this server (not implemented)
194 //
195 virtual int Space ( XrdCmsReq *Request) {return 0;} // Server Only
196 
197 // Called to get information about a file; opaque may be a nil ptr.
198 //
199 virtual int Stat ( XrdCmsReq *Request,
200  const char *path,
201  const char *opaque) = 0;
202 
203 // Called after the plugin is loaded to determine which and how the above
204 // methods are to be called.
205 //
206 virtual void XeqMode(unsigned int &isNormal,
207  unsigned int &isDirect)
208  {isNormal = XMI_LOAD | XMI_SPACE; isDirect = 0;}
209 
211 virtual ~XrdCmsXmi() {}
212 };
213 
214 /*
215  The XrdCmsXmi object is intended to be supplied as a plugin from a shared
216  library. This library is identified by the "cms.xmilib" directive. When
217  the library is loaded the following extern "C" function is called to obtain
218  an instance of the XrdCmsXmi object that will be used for request processing.
219  The function is passed the command line arguments (xrd options stripped) and
220  a pointer to the XrdCmsXmiEnv structure. If the function returns a null
221  pointer, the cmsd exits with an error.
222 
223  After the object is obtained, XeqMode() is called to determine how each
224  method is to operate by default. A value must be set in each provided mask
225  for each method, as applicable. Two mask are supplied:
226 
227  isNormal When the XMI_func bit is set in this mask, the corresponding
228  method is executed in the normal way the cmsd would
229  have done it had the plugin not existed. Otherwise,
230  you will have to indicate this at run-time for each call
231  which can only be done in direct calling mode.
232 
233  isDirect When the XMI_func bit is set in this mask, the corresponding
234  method is called directly without thread isolation. Use
235  this mode if the processing is immediate (e.g., you will
236  be imediately redirecting the client). By default, the
237  client is told to wait for a defered response and the
238  request is queued for a thread running the Xmi plugin.
239  Three threads are used to drive the Xmi:
240  1) A thread to feed Prep()
241  2) A thread to feed Select()
242  3) A thread to feed everything else.
243  Warning! The three thread model obviously affects how
244  objects can be shared!
245 */
246 
247 extern "C"
248 {
249 XrdCmsXmi *XrdCmsgetXmi(int argc, char **argv, XrdCmsXmiEnv *XmiEnv);
250 }
251 #endif