|
xrootd
|
00001 #ifndef __XRDCMSXMI_H__ 00002 #define __XRDCMSXMI_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d C m s X m i . h h */ 00006 /* */ 00007 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 #include <sys/types.h> 00034 00035 #include "XrdCms/XrdCmsReq.hh" 00036 00037 /* 00038 The XrdCmsXmi class defines the interface the cmsd uses to an external 00039 manager. When the cms.xmilib directive is specified, the cmsd loads the 00040 plugin using XrdCmsgetXmi() to instantiate the plugin objects, as explained 00041 after the definition of the abstract class. The cmsd then uses the Xmi 00042 defined methods to process certain requests instead of it's own default 00043 methods. As the Xmi interface runs synchronously with respect to being called, 00044 it should dispatch any long work to another thread to allow the next request 00045 to be processed by the plugin. You should use the thread scheduler passed 00046 via the XrdCmsXmiEnv structure (see below). 00047 00048 Each method (other that Prep(), see below) is passed an XrdCmsReq object. 00049 This object must be used to send a reply to the client (only one reply is 00050 allowed). A reply is *mandatory* if the function returns TRUE; even if that 00051 reply is merely an indication that everything succeeded. A reply must *not* 00052 be sent if the function returns FALSE; as a reply will be sent by the driver. 00053 Refer to XrdCmsReq.hh on the description of how replies are effected. 00054 00055 The mv, rm, and rmdir methods may be called in an advisory way. This occurs 00056 during cross-cache synchronization when more than one redirector is deployed. 00057 Use the XrdCmsReq::Advisory() method in determine if this is an action call 00058 or an advisory call. 00059 00060 The Prep() method is a background function and the client never expects a 00061 reply. Therefore, no request object is passed since no reply is possible. 00062 Instead, the first parameter is a request ID that is used to tag the 00063 request. This ID may be passed later with XMI_CANCEL set to cancel and 00064 path passed as a null string. All preparation for files tagged with request 00065 ID should be stopped, if possible. 00066 00067 The Xmi methods may be called in one of two modes, DIRECT or INDIRECT. 00068 The modes are indicated by XeqMode(). In DIRECT mode the Xmi methods are 00069 called synchronously. In INDIRECT mode, the Xmi methods are given thread as 00070 well as client isolation by the cmsd using an asynchronous encapsulated 00071 callback mechanism. Normally, INDIRECT mode should be used. The 00072 implementation is not particularly relevant as the protocol details are 00073 handled by the Xmi driver and the request object. 00074 00075 Each method must return either true (1) or false (0). However, the action 00076 taken based on the return value depends on the calling mode. 00077 00078 TRUE (1) -> The function was processed and a reply was sent. 00079 Action: INDIRECT: Normal processing continues, the request was done. 00080 DIRECT: Same as above. 00081 FALSE (0) -> The function was *not* processed and *no* reply was sent. 00082 Action: INDIRECT: An error reply is sent and processing continues. 00083 DIRECT: Processing continues as if the Xmi was not present. 00084 00085 See the description of XeqMode() on how to indicate which methods are to 00086 be called and which mode each method requires. 00087 */ 00088 00089 /******************************************************************************/ 00090 /* X r d C m s X m i E n v */ 00091 /******************************************************************************/ 00092 00093 /* The XrdCmsXmiEnv structure is passed to XrdCmsgetXmi() and contains 00094 information that may be relevant to the Xmi object. The information is 00095 static in that it persists during the execution of the program. 00096 */ 00097 00098 class XrdSysError; 00099 class XrdInet; 00100 class XrdScheduler; 00101 class XrdOucName2Name; 00102 class XrdOucTrace; 00103 00104 struct XrdCmsXmiEnv 00105 { 00106 const char *Role; // Manager | Peer | Proxy | Supervisor | Server 00107 const char *ConfigFN; // -> Config file name 00108 const char *Parms; // -> Optional parms from xmilib directive 00109 XrdSysError *eDest; // -> Error message handler 00110 XrdInet *iNet; // -> Network object 00111 XrdScheduler *Sched; // -> Thread scheduler 00112 XrdOucTrace *Trace; // -> Trace handler 00113 XrdOucName2Name *Name2Name; // -> lfn to xxx mapper (may be null) 00114 }; 00115 00116 /******************************************************************************/ 00117 /* X r d C m s X m i */ 00118 /******************************************************************************/ 00119 00120 class XrdCmsPrepArgs; 00121 00122 // Flags passed to Prep(): XMI_RW, XMI_CANCEL 00123 // Flags passed to Select(): XMI_RW, XMI_NEW, XMI_TRUNC, XMI_LOCATE 00124 // 00125 #define XMI_RW 0x0001 00126 #define XMI_NEW 0x0002 00127 #define XMI_TRUNC 0x0004 00128 #define XMI_CANCEL 0x0008 00129 #define XMI_LOCATE 0x0010 00130 00131 // Flags to be passed back by XeqMode() 00132 // 00133 #define XMI_CHMOD 0x00000001 00134 #define XMI_LOAD 0x00000002 00135 #define XMI_MKDIR 0x00000004 00136 #define XMI_MKPATH 0x00000008 00137 #define XMI_PREP 0x00000010 00138 #define XMI_RENAME 0x00000020 00139 #define XMI_REMDIR 0x00000040 00140 #define XMI_REMOVE 0x00000080 00141 #define XMI_SELECT 0x00000100 00142 #define XMI_SPACE 0x00000200 00143 #define XMI_STAT 0x00000400 00144 #define XMI_ALL 0x000007ff 00145 00146 class XrdCmsXmi 00147 { 00148 public: 00149 00150 // Called when trying to change the mode of a file; opaque may be a nil ptr. 00151 // 00152 virtual int Chmod ( XrdCmsReq *Request, 00153 mode_t mode, 00154 const char *path, 00155 const char *opaque) = 0; 00156 00157 // Called when trying to determine the load on this host (not yet implemented) 00158 // 00159 virtual int Load ( XrdCmsReq *Request) {return 0;} // Server only 00160 00161 // Called to make a directory; opaque may be a nil ptr. 00162 // 00163 virtual int Mkdir ( XrdCmsReq *Request, 00164 mode_t mode, 00165 const char *path, 00166 const char *opaque) = 0; 00167 00168 // Called to make a directory path; opaque may be a nil ptr. 00169 // 00170 virtual int Mkpath( XrdCmsReq *Request, 00171 mode_t mode, 00172 const char *path, 00173 const char *opaque) = 0; 00174 00175 // Called to prepare future access to a file; opaque may be a nil ptr. 00176 // 00177 virtual int Prep (const char *ReqID, 00178 int Opts, 00179 const char *Path, 00180 const char *Opaque) = 0; 00181 00182 // Called to rename a file or directory; oldopaque/newopaque may be a nil ptrs. 00183 // 00184 virtual int Rename( XrdCmsReq *Request, 00185 const char *oldpath, 00186 const char *oldopaque, 00187 const char *newpath, 00188 const char *newopaque) = 0; 00189 00190 // Called to remove a directory; opaque may be a nil ptr. 00191 // 00192 virtual int Remdir( XrdCmsReq *Request, 00193 const char *path, 00194 const char *opaque) = 0; 00195 00196 // Called to remove a file; opaque may be a nil ptr. 00197 // 00198 virtual int Remove( XrdCmsReq *Request, 00199 const char *path, 00200 const char *opaque) = 0; 00201 00202 // Called when a client attempts to locate or open a file. The opts indicate 00203 // how the file will used and whether it is to be created. The opaque may be 00204 // a nil ptr. 00205 // 00206 virtual int Select( XrdCmsReq *Request, // See description above 00207 int opts, 00208 const char *path, 00209 const char *opaque) = 0; 00210 00211 // Called to determine how much space exists in this server (not implemented) 00212 // 00213 virtual int Space ( XrdCmsReq *Request) {return 0;} // Server Only 00214 00215 // Called to get information about a file; opaque may be a nil ptr. 00216 // 00217 virtual int Stat ( XrdCmsReq *Request, 00218 const char *path, 00219 const char *opaque) = 0; 00220 00221 // Called after the plugin is loaded to determine which and how the above 00222 // methods are to be called. 00223 // 00224 virtual void XeqMode(unsigned int &isNormal, 00225 unsigned int &isDirect) 00226 {isNormal = XMI_LOAD | XMI_SPACE; isDirect = 0;} 00227 00228 XrdCmsXmi() {} 00229 virtual ~XrdCmsXmi() {} 00230 }; 00231 00232 /* 00233 The XrdCmsXmi object is intended to be supplied as a plugin from a shared 00234 library. This library is identified by the "cms.xmilib" directive. When 00235 the library is loaded the following extern "C" function is called to obtain 00236 an instance of the XrdCmsXmi object that will be used for request processing. 00237 The function is passed the command line arguments (xrd options stripped) and 00238 a pointer to the XrdCmsXmiEnv structure. If the function returns a null 00239 pointer, the cmsd exits with an error. 00240 00241 After the object is obtained, XeqMode() is called to determine how each 00242 method is to operate by default. A value must be set in each provided mask 00243 for each method, as applicable. Two mask are supplied: 00244 00245 isNormal When the XMI_func bit is set in this mask, the corresponding 00246 method is executed in the normal way the cmsd would 00247 have done it had the plugin not existed. Otherwise, 00248 you will have to indicate this at run-time for each call 00249 which can only be done in direct calling mode. 00250 00251 isDirect When the XMI_func bit is set in this mask, the corresponding 00252 method is called directly without thread isolation. Use 00253 this mode if the processing is immediate (e.g., you will 00254 be imediately redirecting the client). By default, the 00255 client is told to wait for a defered response and the 00256 request is queued for a thread running the Xmi plugin. 00257 Three threads are used to drive the Xmi: 00258 1) A thread to feed Prep() 00259 2) A thread to feed Select() 00260 3) A thread to feed everything else. 00261 Warning! The three thread model obviously affects how 00262 objects can be shared! 00263 */ 00264 00265 extern "C" 00266 { 00267 XrdCmsXmi *XrdCmsgetXmi(int argc, char **argv, XrdCmsXmiEnv *XmiEnv); 00268 } 00269 #endif
1.7.6.1