XrdCmsXmi.hh

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

Generated on Tue Jul 5 14:46:32 2011 for ROOT_528-00b_version by  doxygen 1.5.1