XRootD
XrdCmsPrepArgs.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d C m s P r e p A r g s . c c */
4 /* */
5 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Andrew Hanushevsky for Stanford University under contract */
8 /* DE-AC02-76-SFO0515 with the Department of Energy */
9 /* */
10 /* This file is part of the XRootD software suite. */
11 /* */
12 /* XRootD is free software: you can redistribute it and/or modify it under */
13 /* the terms of the GNU Lesser General Public License as published by the */
14 /* Free Software Foundation, either version 3 of the License, or (at your */
15 /* option) any later version. */
16 /* */
17 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20 /* License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25 /* */
26 /* The copyright holder's institutional names and contributor's names may not */
27 /* be used to endorse or promote products derived from this software without */
28 /* specific prior written permission of the institution or contributor. */
29 /******************************************************************************/
30 
31 #include <unistd.h>
32 #include <cstdlib>
33 #include <sys/types.h>
34 
35 #include "XrdCms/XrdCmsConfig.hh"
36 #include "XrdCms/XrdCmsPrepare.hh"
37 #include "XrdCms/XrdCmsPrepArgs.hh"
38 
39 using namespace XrdCms;
40 
41 /******************************************************************************/
42 /* S t a t i c V a r i a b l e s */
43 /******************************************************************************/
44 
45 XrdSysMutex XrdCmsPrepArgs::PAQueue;
46 XrdSysSemaphore XrdCmsPrepArgs::PAReady(0);
47 
48 XrdCmsPrepArgs *XrdCmsPrepArgs::First = 0;
49 XrdCmsPrepArgs *XrdCmsPrepArgs::Last = 0;
50 int XrdCmsPrepArgs::isIdle= 1;
51 
52 /******************************************************************************/
53 /* C o n s t r u c t o r */
54 /******************************************************************************/
55 
57 {
58 
59 // Copy variable pointers and steal the data buffer behind them
60 //
61  Request = Arg.Request; Request.streamid = 0;
62  Ident = Arg.Ident;
63  reqid = Arg.Reqid;
64  notify = Arg.Notify;
65  prty = Arg.Prty;
66  mode = Arg.Mode;
67  path = Arg.Path;
68  pathlen = Arg.PathLen;
69  opaque = Arg.Opaque;
70  options = Arg.Request.modifier;
71  Data = Arg.Buff; Arg.Buff = 0; Arg.Blen = 0;
72 
73 // Fill out co-location information
74 //
75  if (options & CmsPrepAddRequest::kYR_stage
76  && options & CmsPrepAddRequest::kYR_coloc && prty)
77  {clPath = prty;
78  while(*clPath && *clPath != '/') clPath++;
79  if (*clPath != '/') clPath = 0;
80  } else clPath = 0;
81 
82 // Fill out the iovec
83 //
84  ioV[0].iov_base = (char *)&Request;
85  ioV[0].iov_len = sizeof(Request);
86  ioV[1].iov_base = Data;
87  ioV[1].iov_len = Arg.Dlen;
88 }
89 
90 /******************************************************************************/
91 /* g e t R e q u e s t */
92 /******************************************************************************/
93 
95 {
96  XrdCmsPrepArgs *parg;
97 
98 // Wait for a request
99 //
100  do {PAQueue.Lock();
101  if ((parg = First))
102  if (parg == Last) First = Last = 0;
103  else First = parg->Next;
104  else {isIdle = 1; PAQueue.UnLock(); PAReady.Wait();}
105  } while(parg == 0);
106  isIdle = 0;
107  PAQueue.UnLock();
108  return parg;
109 }
110 
111 /******************************************************************************/
112 /* P r o c e s s */
113 /*****************************************************************************/
114 
115 // This static entry is started on a thread during configuration
116 //
118 {
119  XrdCmsPrepArgs *aP;
120 
121 // Process all queued prepare arguments. If we have data then we do this
122 // for real. Otherwise, simply do a server selection and, if need be, tell
123 // the server to stage the file.
124 //
125  if (Config.DiskOK)
126  do {aP = getRequest();
127  PrepQ.Prepare(aP);
128  delete aP;
129  } while(1);
130  else
131  do {getRequest()->DoIt();
132  } while(1);
133 }
134 
135 /******************************************************************************/
136 /* Q u e u e */
137 /******************************************************************************/
138 
140 {
141 
142 // Lock the queue and add the element and post the waiter
143 //
144  PAQueue.Lock();
145  if (First) Last->Next = this;
146  else First = this;
147  Last = this;
148  if (isIdle) PAReady.Post();
149  PAQueue.UnLock();
150 }
static void Process()
struct iovec ioV[iovNum]
XrdCms::CmsRRHdr Request
XrdCmsPrepArgs(XrdCmsRRData &Arg)
static XrdCmsPrepArgs * getRequest()
void Prepare(XrdCmsPrepArgs *pargs)
XrdCms::CmsRRHdr Request
Definition: XrdCmsRRData.hh:54
Definition: XrdJob.hh:43
kXR_char modifier
Definition: YProtocol.hh:85
XrdCmsPrepare PrepQ
kXR_unt32 streamid
Definition: YProtocol.hh:83
XrdCmsConfig Config