Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-08 10:33:37

0001 #ifndef __CMS_CLIENT__
0002 #define __CMS_CLIENT__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                       X r d C m s C l i e n t . h h                        */
0006 /*                                                                            */
0007 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*                            All Rights Reserved                             */
0009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0011 /*                                                                            */
0012 /* This file is part of the XRootD software suite.                            */
0013 /*                                                                            */
0014 /* XRootD is free software: you can redistribute it and/or modify it under    */
0015 /* the terms of the GNU Lesser General Public License as published by the     */
0016 /* Free Software Foundation, either version 3 of the License, or (at your     */
0017 /* option) any later version.                                                 */
0018 /*                                                                            */
0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0022 /* License for more details.                                                  */
0023 /*                                                                            */
0024 /* You should have received a copy of the GNU Lesser General Public License   */
0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0027 /*                                                                            */
0028 /* The copyright holder's institutional names and contributor's names may not */
0029 /* be used to endorse or promote products derived from this software without  */
0030 /* specific prior written permission of the institution or contributor.       */
0031 /******************************************************************************/
0032 
0033 class  XrdOucEnv;
0034 class  XrdOucErrInfo;
0035 class  XrdOucLogger;
0036 class  XrdOucTList;
0037 struct XrdSfsPrep;
0038 class  XrdSysLogger;
0039 
0040 /******************************************************************************/
0041 /*                    R e t u r n   C o n v e n t i o n s                     */
0042 /******************************************************************************/
0043   
0044 /* The following return conventions are use by Forward(), Locate(), & Prepare()
0045    Return Val   Resp.errcode          Resp.errtext
0046    ---------    -------------------   --------
0047    SFS_DATA     Length of data.       Data to be returned to caller.
0048                 Action: Caller is provided data as successful response.
0049 
0050    SFS_ERROR    errno                 Error message text.
0051                 Action: Caller given error response.
0052 
0053    SFS_REDIRECT port (0 for default)  Host name
0054                 Action: Caller is redirected to <host>:<port>
0055 
0056    SFS_STARTED  Expected seconds      n/a
0057                 Action: Caller is told to wait for the "expected seconds" for a
0058                         callback with the result. A callback must follow.
0059                         See how to do callbacks below.
0060 
0061    > 0          Wait time (= retval)  Reason for wait
0062                 Action: Caller told to wait retval seconds and retry request.
0063 
0064    < 0          Error number          Error message
0065                 Action: Same as SFS_ERROR. You should *always* use SFS_ERROR.
0066 
0067    = 0          Not applicable        Not applicable (see below)
0068                 Action: Forward() -> Return success; request forwarded.
0069                         Locate()  -> Redirection does not apply, operation
0070                                      should be done against local file system.
0071                         Prepare() -> Return success, request submitted.
0072 */
0073 
0074 /******************************************************************************/
0075 /*                  C a l l b a c k   C o n v e n t i o n s                   */
0076 /******************************************************************************/
0077   
0078 /* Most operations allow you to return SFS_STARTED to setup a callback.
0079    Callback information is contained in the XrdOucErrInfo object passed to
0080    Forward(), Locate() and Prepare(); the only methods that can apply callbacks.
0081    Use a callback when the operation will take at least several seconds so as
0082    to not occupy the calling thread for an excessive amount of time.
0083 
0084    The actual mechanics of a callback are rather complicated because callbacks
0085    are subject to non-causaility if not correctly handled. In order to avoid
0086    such issues, you should use the XrdOucCallBack object (see XrdOucCallBack.hh)
0087    to test for applicability, setup, and effect a callback.
0088 
0089    When calling back, you return the same information you would have returned
0090    had the execution path been synchronous. From that standpoint callbacks are
0091    relatively easy to understand. All you are doing is defering the return of
0092    information without occupying a thread while waiting to do so.
0093 
0094    A typical scenario, using Resp and the original ErrInfo object, would be....
0095 
0096    XrdOucCallBack cbObject;  // Must be persistent for the callback duration
0097 
0098    if (XrdOucCallBack::Allowed(Resp))
0099       {cbObject.Init(Resp);
0100        <hand off the cbObject to a thread that will perform the work>
0101        Resp.setErrCode(<seconds end-point should wait>);
0102        return SFS_STARTED; // Effect callback response!
0103       }
0104 
0105    Once the thread doing the work has a result, send it via a callback as if
0106    the work was done in a synchronous fashion.
0107 
0108    cbObject->Reply(retValue, ErrCodeValue, ErrTextValue);
0109 */
0110 
0111 /******************************************************************************/
0112 /*                    C l a s s   X r d C m s C l i e n t                     */
0113 /******************************************************************************/
0114   
0115 class XrdCmsClient
0116 {
0117 public:
0118 
0119 //------------------------------------------------------------------------------
0120 //! Notify the cms of a newly added file or a file whose state has changed on
0121 //! a data server node.
0122 //!
0123 //! @param  path  The logical file name.
0124 //! @param  Pend  When true, the file is scheduled to be present in the future
0125 //!               (e.g. copied in).
0126 //------------------------------------------------------------------------------
0127 
0128 virtual void   Added(const char *path, int Pend=0) { (void)path; (void)Pend; }
0129 
0130 //------------------------------------------------------------------------------
0131 //! Configure the client object.
0132 //!
0133 //! @param  cfn     The configuration file name.
0134 //! @param  Parms   Any parameters specified in the cmslib directive. If none,
0135 //!                 the pointer may be null.
0136 //! @param  EnvInfo Environmental information of the caller.
0137 //!
0138 //! @return Success !0
0139 //!         Failure =0
0140 //------------------------------------------------------------------------------
0141 
0142 virtual int    Configure(const char *cfn, char *Parms, XrdOucEnv *EnvInfo) = 0;
0143 
0144 //------------------------------------------------------------------------------
0145 //! Relay a meta-operation to all nodes in the cluster.
0146 //!
0147 //! This method is only used on manager nodes and is enabled by the ofs.forward
0148 //! directive.
0149 //!
0150 //! @param   Resp Object where messages are to be returned.
0151 //! @param   cmd  The operation being performed (see table below).
0152 //!               If it starts with a '+' then a response (2way) is needed.
0153 //!               Otherwise, a best-effort is all that is all that is required
0154 //!               and success can always be returned.
0155 //! @param   arg1 1st argument to cmd.
0156 //! @param   arg2 2nd argument to cmd, which may be null if none exists.
0157 //! @param   Env1 Associated environmental information for arg1 (e.g., cgi info
0158 //!               which can be retrieved by Env1->Env(<len>)).
0159 //! @param   Env2 Associated environmental information for arg2 (e.g., cgi info
0160 //!               which can be retrieved by Env1->Env(<len>)).
0161 //!
0162 //!
0163 //!          cmd       arg1    arg2           cmd       arg1    arg2
0164 //!          --------  ------  ------         --------  ------  ------
0165 //!          [+]chmod  <path>  <mode %o>      [+]rmdir  <path>  0
0166 //!          [+]mkdir  <path>  <mode %o>      [+]mv     <oldp>  <newp>
0167 //!          [+]mkpath <path>  <mode %o>      [+]trunc  <path>  <size %lld>
0168 //!          [+]rm     <path>  0
0169 //!
0170 //! @return  As explained under "return conventions".
0171 //------------------------------------------------------------------------------
0172 
0173 virtual int    Forward(XrdOucErrInfo &Resp,   const char *cmd,
0174                        const char    *arg1=0, const char *arg2=0,
0175                        XrdOucEnv     *Env1=0, XrdOucEnv  *Env2=0)
0176 {
0177   (void)Resp; (void)cmd; (void)arg1; (void)arg2; (void)Env1; (void)Env2;
0178   return 0;
0179 }
0180 
0181 //------------------------------------------------------------------------------
0182 //! Check if this client is configured for a manager node.
0183 //!
0184 //! @return !0 Yes, configured as a manager.
0185 //!         =0 No.
0186 //------------------------------------------------------------------------------
0187 
0188 virtual int    isRemote() {return myPersona == XrdCmsClient::amRemote;}
0189 
0190 //------------------------------------------------------------------------------
0191 //! Retrieve file location information.
0192 //!
0193 //! @param   Resp  Object where message or response is to be returned.
0194 //! @param   path  The logical path whise location is wanted.
0195 //! @param   flags One or more of the following:
0196 //!
0197 //!          SFS_O_LOCATE  - return the list of servers that have the file.
0198 //!                          Otherwise, redirect to the best server for the file.
0199 //!          SFS_O_NOWAIT  - w/ SFS_O_LOCATE return readily available info.
0200 //!                          Otherwise, select online files only.
0201 //!          SFS_O_CREAT   - file will be created.
0202 //!          SFS_O_NOWAIT  - select server if file is online.
0203 //!          SFS_O_REPLICA - a replica of the file will be made.
0204 //!          SFS_O_STAT    - only stat() information wanted.
0205 //!          SFS_O_TRUNC   - file will be truncated.
0206 //!
0207 //!          For any the the above, additional flags are passed:
0208 //!          SFS_O_META    - data will not change (inode operation only)
0209 //!          SFS_O_RESET   - reset cached info and recaculate the location(s).
0210 //!          SFS_O_WRONLY  - file will be only written    (o/w RDWR   or RDONLY).
0211 //!          SFS_O_RDWR    - file may be read and written (o/w WRONLY or RDONLY).
0212 //!
0213 //! @param   Info Associated environmental information for arg2 (e.g., cgi info
0214 //!               which can be retrieved by Env1->Env(<len>)).
0215 //!
0216 //! @return  As explained under "return conventions".
0217 //------------------------------------------------------------------------------
0218 
0219 virtual int    Locate(XrdOucErrInfo &Resp, const char *path, int flags,
0220                       XrdOucEnv  *Info=0) = 0;
0221 
0222 //------------------------------------------------------------------------------
0223 //! Obtain the list of cmsd's being used by a manager node along with their
0224 //! associated index numbers, origin 1.
0225 //!
0226 //! @return The list of cmsd's being used. The list is considered permanent
0227 //!         and is not deleted.
0228 // Return:    A list of managers or null if none exist.
0229 //------------------------------------------------------------------------------
0230 
0231 virtual
0232 XrdOucTList   *Managers() {return 0;}
0233 
0234 //------------------------------------------------------------------------------
0235 //! Start the preparation of a file for future processing.
0236 //!
0237 //! @param   Resp  Object where message or response is to be returned.
0238 //! @param   pargs Information on which and how to prepare the file.
0239 //! @param   Info  Associated environmental information.
0240 //!
0241 //! @return  As explained under "return conventions".
0242 //------------------------------------------------------------------------------
0243 
0244 virtual int    Prepare(XrdOucErrInfo &Resp, XrdSfsPrep &pargs,
0245                        XrdOucEnv  *Info=0)
0246 {
0247   (void)Resp; (void)pargs; (void)Info;
0248   return 0;
0249 }
0250 
0251 //------------------------------------------------------------------------------
0252 //! Notify the cmsd that a file or directory has been deleted. It is only called
0253 //! called on a data server node.
0254 //!
0255 //! @param  path The logical file name that was removed.
0256 //------------------------------------------------------------------------------
0257 
0258 virtual void   Removed(const char *path) { (void)path; }
0259 
0260 //------------------------------------------------------------------------------
0261 //! Resume service after a suspension.
0262 //!
0263 //! @param  Perm When true the resume persist across server restarts. Otherwise,
0264 //!              it is treated as a temporary request.
0265 //------------------------------------------------------------------------------
0266 
0267 virtual void   Resume (int Perm=1) { (void)Perm; }
0268 
0269 //------------------------------------------------------------------------------
0270 //! Suspend service.
0271 //!
0272 //! @param  Perm When true the suspend persist across server restarts.
0273 //!              Otherwise, it is treated as a temporary request.
0274 //------------------------------------------------------------------------------
0275 
0276 virtual void   Suspend(int Perm=1) { (void)Perm; }
0277 
0278 // The following set of functions can be used to control whether or not clients
0279 // are dispatched to this data server based on a virtual resource. The default
0280 // implementations do nothing.
0281 //
0282 //------------------------------------------------------------------------------
0283 //! Enables the Reserve() & Release() methods.
0284 //!
0285 //! @param  n  a positive integer that specifies the amount of resource units
0286 //!            that are available. It may be reset at any time.
0287 //!
0288 //! @return The previous resource value. This first call returns 0.
0289 //------------------------------------------------------------------------------
0290 
0291 virtual int    Resource(int n)   { (void)n; return 0;}
0292 
0293 //------------------------------------------------------------------------------
0294 //! Decreases the amount of resources available. When the available resources
0295 //! becomes non-positive, perform a temporary suspend to prevent additional
0296 //! clients from being dispatched to this data server.
0297 //!
0298 //! @param  n  The value by which resources are decreased (default 1).
0299 //!
0300 //! @return The amount of resource left.
0301 //------------------------------------------------------------------------------
0302 
0303 virtual int    Reserve (int n=1) { (void)n; return 0;}
0304 
0305 //------------------------------------------------------------------------------
0306 //! Increases the amount of resource available. When transitioning from a
0307 //! a non-positive to a positive resource amount, perform a resume so that
0308 //! additional clients may be dispatched to this data server.
0309 //!
0310 //! @param  n  The value to add to the resources available (default 1). The
0311 //!            total amount is capped by the amount specified by Resource().
0312 //!
0313 //! @return The amount of resource left.
0314 //------------------------------------------------------------------------------
0315 
0316 virtual int    Release (int n=1) { (void)n; return 0;}
0317 
0318 //------------------------------------------------------------------------------
0319 //! Obtain the overall space usage of a cluster. Called only on manager nodes.
0320 //!
0321 //! @param  Resp  Object to hold response or error message.
0322 //! @param  path  Associated logical path for the space request.
0323 //! @param  Info  Associated cgi information for path.
0324 //!
0325 //! @return Space information as defined by the response to kYR_statfs. For a
0326 //!               typical implementation see XrdCmsNode::do_StatFS().
0327 //------------------------------------------------------------------------------
0328 
0329 virtual int    Space(XrdOucErrInfo &Resp, const char *path,
0330                      XrdOucEnv  *Info=0) = 0;
0331 
0332 //------------------------------------------------------------------------------
0333 //! Report utilization of this server. This may be used in lieu of general
0334 //! performance metric reporting. For consistent results use only one method.
0335 //!
0336 //! @param  util  A value from 0 to 100 representing utilization. Values
0337 //!               greater than 100 are set to be 100.
0338 //! @param  alert When true the utilization is forcibly report to the
0339 //!               cluster managers. Otherwise, reporting is done only when
0340 //!               it will significantly change server selection.
0341 //------------------------------------------------------------------------------
0342 
0343 virtual void   Utilization(unsigned int util, bool alert=false)
0344                           {(void)util; (void)alert;}
0345 
0346 //------------------------------------------------------------------------------
0347 //! Constructor
0348 //!
0349 //! @param  acting  The type of function this object is performing.
0350 //------------------------------------------------------------------------------
0351 
0352         enum   Persona {amLocal,  //!< Not affiliated with a cluster
0353                         amRemote, //!< Am a manager and issue redirects
0354                         amTarget  //!< Am a server  and field redirects
0355                        };
0356 
0357                XrdCmsClient(Persona acting) : myPersona(acting) {}
0358 
0359 //------------------------------------------------------------------------------
0360 //! Destructor
0361 //------------------------------------------------------------------------------
0362 
0363 virtual       ~XrdCmsClient() {}
0364 
0365 protected:
0366 
0367 Persona        myPersona;
0368 };
0369 
0370 /******************************************************************************/
0371 /*              I n s t a n t i a t i o n   M o d e   F l a g s               */
0372 /******************************************************************************/
0373   
0374 /*! The following instantiation mode flags are passed to the instantiator (see
0375     comments that follow). They may be or'd together, depending on which mode
0376     the cms client should operate. They are defined as follows:
0377 */
0378 namespace XrdCms
0379 {
0380 enum  {IsProxy  = 1, //!< The role is proxy  {plus one or more of the below}
0381        IsRedir  = 2, //!< The role is manager and will redirect users
0382        IsTarget = 4, //!< The role is server  and will be a redirection target
0383        IsMeta   = 8  //!< The role is meta   {plus one or more of the above}
0384       };
0385 }
0386 
0387 /******************************************************************************/
0388 /*               C M S   C l i e n t   I n s t a n t i a t o r                */
0389 /******************************************************************************/
0390 
0391 //------------------------------------------------------------------------------
0392 //! Obtain an instance of a configured XrdCmsClient.
0393 //!
0394 //! The following extern "C" function is called to obtain an instance of the
0395 //! XrdCmsClient object. This is only used if the client is an actual plug-in
0396 //! as identified by the ofs.cmslib directive. Once the XrdCmsClient object
0397 //! is obtained, its Configure() method is called to initialize the object.
0398 //!
0399 //! @param  logger -> XrdSysLogger to be tied to an XrdSysError object for
0400 //!                   any messages.
0401 //! @param  opMode -> The operational mode as defined by the enum above. There
0402 //!                   are two general types of clients, IsRedir and IsTarget.
0403 //!                   The IsProxy and IsMeta modes are specialization of these
0404 //!                   two basic types. The plug-in must provide an instance of
0405 //!                   the one asked for whether or not they actually do anything.
0406 //!
0407 //!                   IsRedir  clients are anything other than a data provider
0408 //!                            (i.e., data servers). These clients are expected
0409 //!                            to locate files and redirect a requestor to an
0410 //!                            actual data server.
0411 //!
0412 //!                   IsTarget clients are typically data providers (i.e., data
0413 //!                            servers) but may actually do other functions are
0414 //!                            are allowed to redirect as well.
0415 //!
0416 //! @param  myPort -> The server's port number.
0417 //! @param  theSS  -> The object that implements he underlying storage system.
0418 //!                   This object may be passed for historic reasons.
0419 //!
0420 //! @return Success: a pointer to the appropriate object (IsRedir or IsTarget).
0421 //!
0422 //!         Failure: a null pointer which causes initialization to fail.
0423 //------------------------------------------------------------------------------
0424 
0425 class XrdOss;
0426 
0427 typedef XrdCmsClient *(*XrdCmsClient_t)(XrdSysLogger *, int, int, XrdOss *);
0428 
0429 /*! extern "C" XrdCmsClient *XrdCmsGetClient(XrdSysLogger *Logger,
0430                                              int           opMode,
0431                                              int           myPort
0432                                              XrdOss       *theSS);
0433 */
0434 
0435 //------------------------------------------------------------------------------
0436 //! Obtain an instance of a default unconfigured XrdCmsClient.
0437 //!
0438 //! The following function may be called to obtain an instance of the default
0439 //! XrdCmsClient object. The Configure() method is *not* called before the
0440 //! object is returned. The parameters are the same as those for the function
0441 //! XrdCmsGetClient(), above. Note that you need not supply a pointer to the
0442 //! underlying storage system, as this is historic in nature.
0443 //!
0444 //! @return Success: a pointer to the appropriate object (IsRedir or IsTarget).
0445 //!
0446 //!         Failure: a null pointer, neither ISRedir nor IsTarget has been
0447 //!                  specified or there is insufficient memory.
0448 //------------------------------------------------------------------------------
0449 
0450 namespace XrdCms
0451 {
0452           XrdCmsClient *GetDefaultClient(XrdSysLogger *Logger,
0453                                          int           opMode,
0454                                          int           myPort
0455                                         );
0456 }
0457 
0458 //------------------------------------------------------------------------------
0459 //! Declare compilation version.
0460 //!
0461 //! Additionally, you *should* declare the xrootd version you used to compile
0462 //! your plug-in.
0463 //------------------------------------------------------------------------------
0464 
0465 /*! #include "XrdVersion.hh"
0466     XrdVERSIONINFO(XrdCmsGetClient,<name>);
0467 
0468 */
0469 #endif