XrdCmsPrepArgs.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                     X r d C m s P r e p A r g s . c c                      */
00004 /*                                                                            */
00005 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*                            All Rights Reserved                             */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010 
00011 //         $Id: XrdCmsPrepArgs.cc 25932 2008-10-23 10:58:11Z ganis $
00012 
00013 // Original Version: 1.2 2007/07/26 15:18:24 ganis
00014 
00015 const char *XrdCmsPrepargsCVSID = "$Id: XrdCmsPrepArgs.cc 25932 2008-10-23 10:58:11Z ganis $";
00016   
00017 #include <unistd.h>
00018 #include <stdlib.h>
00019 #include <sys/types.h>
00020 
00021 #include "XrdCms/XrdCmsConfig.hh"
00022 #include "XrdCms/XrdCmsPrepare.hh"
00023 #include "XrdCms/XrdCmsPrepArgs.hh"
00024 
00025 using namespace XrdCms;
00026 
00027 /******************************************************************************/
00028 /*                      S t a t i c   V a r i a b l e s                       */
00029 /******************************************************************************/
00030 
00031 XrdSysMutex     XrdCmsPrepArgs::PAQueue;
00032 XrdSysSemaphore XrdCmsPrepArgs::PAReady(0);
00033 
00034 XrdCmsPrepArgs *XrdCmsPrepArgs::First = 0;
00035 XrdCmsPrepArgs *XrdCmsPrepArgs::Last  = 0;
00036 int             XrdCmsPrepArgs::isIdle= 1;
00037   
00038 /******************************************************************************/
00039 /*                           C o n s t r u c t o r                            */
00040 /******************************************************************************/
00041   
00042 XrdCmsPrepArgs::XrdCmsPrepArgs(XrdCmsRRData &Arg) : XrdJob("prepare")
00043 {
00044 
00045 // Copy variable pointers and steal teh data buffer behind them
00046 //
00047    Request = Arg.Request; Request.streamid = 0;
00048    Ident   = Arg.Ident;
00049    reqid   = Arg.Reqid;
00050    notify  = Arg.Notify;
00051    prty    = Arg.Prty;
00052    mode    = Arg.Mode;
00053    path    = Arg.Path;
00054    pathlen = Arg.PathLen;
00055    opaque  = Arg.Opaque;
00056    options = Arg.Request.modifier;
00057    Data    = Arg.Buff; Arg.Buff = 0; Arg.Blen = 0;
00058 
00059 // Fill out co-location information
00060 //
00061    if (options & CmsPrepAddRequest::kYR_stage
00062    &&  options & CmsPrepAddRequest::kYR_coloc && prty)
00063       {clPath = prty;
00064        while(*clPath && *clPath != '/') clPath++;
00065        if (*clPath != '/') clPath = 0;
00066       } else clPath = 0;
00067 
00068 // Fill out the iovec
00069 //
00070    ioV[0].iov_base = (char *)&Request;
00071    ioV[0].iov_len  = sizeof(Request);
00072    ioV[1].iov_base = Data;
00073    ioV[1].iov_len  = Arg.Dlen;
00074 }
00075 
00076 /******************************************************************************/
00077 /*                            g e t R e q u e s t                             */
00078 /******************************************************************************/
00079   
00080 XrdCmsPrepArgs *XrdCmsPrepArgs::getRequest() // Static
00081 {
00082    XrdCmsPrepArgs *parg;
00083 
00084 // Wait for a request
00085 //
00086    do {PAQueue.Lock();
00087        if ((parg = First))
00088           if (parg == Last) First = Last = 0;
00089              else           First = parg->Next;
00090           else {isIdle = 1; PAQueue.UnLock(); PAReady.Wait();}
00091       } while(parg == 0);
00092    isIdle = 0;
00093    PAQueue.UnLock();
00094    return parg;
00095 }
00096 
00097 /******************************************************************************/
00098 /*                               P r o c e s s                                */
00099 /*****************************************************************************/
00100 
00101 // This static entry is started on a thread during configuration
00102 //
00103 void XrdCmsPrepArgs::Process()
00104 {
00105    XrdCmsPrepArgs *aP;
00106 
00107 // Process all queued prepare arguments. If we have data then we do this
00108 // for real. Otherwise, simply do a server selection and, if need be, tell 
00109 // the server to stage the file.
00110 //
00111    if (Config.DiskOK)
00112       do {aP = getRequest();
00113           PrepQ.Prepare(aP);
00114           delete aP;
00115          } while(1);
00116       else
00117       do {getRequest()->DoIt();
00118          } while(1);
00119 }
00120   
00121 /******************************************************************************/
00122 /*                                 Q u e u e                                  */
00123 /******************************************************************************/
00124   
00125 void XrdCmsPrepArgs::Queue()
00126 {
00127 
00128 // Lock the queue and add the element and post the waiter
00129 //
00130    PAQueue.Lock();
00131    if (First) Last->Next = this;
00132       else    First      = this;
00133    Last = this;
00134    if (isIdle) PAReady.Post();
00135    PAQueue.UnLock();
00136 }

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