XRootD
XrdXrootdTransit.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d X r o o t d T r a n s i t . c c */
4 /* */
5 /* (c) 2012 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 <cstring>
32 #include <unistd.h>
33 #include <sys/uio.h>
34 
35 #include "XProtocol/XProtocol.hh"
36 
37 #include "XrdSec/XrdSecEntity.hh"
38 
39 #include "Xrd/XrdBuffer.hh"
40 #include "Xrd/XrdLink.hh"
41 #include "XrdOuc/XrdOucErrInfo.hh"
42 #include "XrdOuc/XrdOucUtils.hh"
44 #include "XrdSys/XrdSysAtomics.hh"
50 
51 /******************************************************************************/
52 /* C l o b a l S y m b o l s */
53 /******************************************************************************/
54 
56 
57 #undef TRACELINK
58 #define TRACELINK Link
59 
60 #define XRD_GETNUM(x)\
61  ntohl(*(static_cast<unsigned int *>(static_cast<void *>(x))))
62 
63 /******************************************************************************/
64 /* S t a t i c M e m b e r s */
65 /******************************************************************************/
66 
67 const char *XrdXrootdTransit::reqTab = XrdXrootdTransit::ReqTable();
68 
70  XrdXrootdTransit::TranStack("TranStack",
71  "transit protocol anchor");
72 
73 /******************************************************************************/
74 /* A l l o c */
75 /******************************************************************************/
76 
78  XrdLink *linkP,
79  XrdSecEntity *seceP,
80  const char *nameP,
81  const char *protP
82  )
83 {
84  XrdXrootdTransit *xp;
85 
86 // Simply return a new transit object masquerading as a bridge
87 //
88  if (!(xp = TranStack.Pop())) xp = new XrdXrootdTransit();
89  xp->Init(rsltP, linkP, seceP, nameP, protP);
90  return xp;
91 }
92 
93 /******************************************************************************/
94 /* A t t n */
95 /******************************************************************************/
96 
97 int XrdXrootdTransit::Attn(XrdLink *lP, short *theSID, int rcode,
98  const struct iovec *ioV, int ioN, int ioL)
99 {
100  XrdXrootdTransPend *tP;
101 
102 // Find the request
103 //
104  if (!(tP = XrdXrootdTransPend::Remove(lP, *theSID)))
105  {TRACE(REQ, "Unable to find request for " <<lP->ID <<" sid=" <<*theSID);
106  return 0;
107  }
108 
109 // Resume the request as we have been waiting for the response.
110 //
111  return tP->bridge->AttnCont(tP, rcode, ioV, ioN, ioL);
112 }
113 
114 /******************************************************************************/
115 /* A t t n C o n t */
116 /******************************************************************************/
117 
118 int XrdXrootdTransit::AttnCont(XrdXrootdTransPend *tP, int rcode,
119  const struct iovec *ioV, int ioN, int ioL)
120 {
121  int rc;
122 
123 // Refresh the request structure
124 //
125  memcpy(&Request, &(tP->Pend.Request), sizeof(Request));
126  delete tP;
127  runWait = 0;
128 
129 // Reissue the request if it's a wait 0 response.
130 //
131  if (rcode==kXR_wait
132  && (!ioN || XRD_GETNUM(ioV[0].iov_base) == 0))
133  {Sched->Schedule((XrdJob *)&waitJob);
134  return 0;
135  }
136 
137 // Send off the deferred response
138 //
139  rc = Send(rcode, ioV, ioN, ioL);
140 
141 // Handle end based on current state
142 //
143  if (rc >= 0 && !runWait)
144  {if (runDone)
145  {AtomicBeg(runMutex);
146  AtomicZAP(runStatus);
147  AtomicEnd(runMutex);
148  }
149  if (reInvoke) Sched->Schedule((XrdJob *)&respJob);
150  else Link->Enable();
151  }
152 
153 // All done
154 //
155  return rc;
156 }
157 
158 /******************************************************************************/
159 /* D i s c */
160 /******************************************************************************/
161 
163 {
164  char buff[128];
165  int rc;
166 
167 // We do not allow disconnection while we are active
168 //
169  AtomicBeg(runMutex);
170  rc = AtomicInc(runStatus);
171  AtomicEnd(runMutex);
172  if (rc) return false;
173 
174 // Reconnect original protocol to the link
175 //
176  Link->setProtocol(realProt);
177 
178 // Now we need to recycle our xrootd part
179 //
180  sprintf(buff, "%s disconnection", pName);
181  XrdXrootdProtocol::Recycle(Link, time(0)-cTime, buff);
182 
183 // Now just free up our object.
184 //
185  TranStack.Push(&TranLink);
186  return true;
187 }
188 
189 /******************************************************************************/
190 /* Private: F a i l */
191 /******************************************************************************/
192 
193 bool XrdXrootdTransit::Fail(int ecode, const char *etext)
194 {
195  runError = ecode;
196  runEText = etext;
197  return true;
198 }
199 
200 /******************************************************************************/
201 /* F a t a l */
202 /******************************************************************************/
203 
204 int XrdXrootdTransit::Fatal(int rc)
205 {
208 
209  return (respObj->Error(rInfo, runError, runEText) ? rc : -1);
210 }
211 
212 /******************************************************************************/
213 /* I n i t */
214 /******************************************************************************/
215 
216 void XrdXrootdTransit::Init(XrdScheduler *schedP, int qMax, int qTTL)
217 {
218  TranStack.Set(schedP, &XrdXrootdTrace, TRACE_MEM);
219  TranStack.Set(qMax, qTTL);
220 }
221 
222 /******************************************************************************/
223 
225  XrdLink *linkP,
226  XrdSecEntity *seceP,
227  const char *nameP,
228  const char *protP
229  )
230 {
231  XrdNetAddrInfo *addrP;
232  const char *who;
233  char uname[sizeof(Request.login.username)+1];
234 
235 // Set standard stuff
236 //
237  runArgs = 0;
238  runALen = 0;
239  runABsz = 0;
240  runError = 0;
241  runStatus = 0;
242  runWait = 0;
243  runWTot = 0;
244  runWMax = 3600;
245  runWCall = false;
246  runDone = false;
247  reInvoke = false;
248  wBuff = 0;
249  wBLen = 0;
250  respObj = respP;
251  pName = protP;
252  mySID = getSID();
253 
254 // Bind the protocol to the link
255 //
256  SI->Bump(SI->Count);
257  Link = linkP;
258  Response.Set(linkP);
259  Response.Set(this);
260  strcpy(Entity.prot, "host");
261  Entity.host = (char *)linkP->Host();
262 
263 // Develop a trace identifier
264 //
265  strncpy(uname, nameP, sizeof(uname)-1);
266  uname[sizeof(uname)-1] = 0;
267  XrdOucUtils::Sanitize(uname);
268  linkP->setID(uname, mySID);
269 
270 // Place trace identifier everywhere is should be located
271 
272 // Indicate that this brige supports asynchronous responses
273 //
275 
276 // Mark the client as IPv4 if they came in as IPv4 or mapped IPv4. Note
277 // there is no way we can figure out if this is a dual-stack client.
278 //
279  addrP = Link->AddrInfo();
280  if (addrP->isIPType(XrdNetAddrInfo::IPv4) || addrP->isMapped())
282 
283 // Mark the client as being on a private net if the address is private
284 //
285  if (addrP->isPrivate()) {clientPV |= XrdOucEI::uPrip; rdType = 1;}
286  else rdType = 0;
287 
288 // Now tie the security information
289 //
290  Client = (seceP ? seceP : &Entity);
291  Client->ueid = mySID;
292  Client->tident = Client->pident = Link->ID;
293  Client->addrInfo = addrP;
294 
295 // Allocate a monitoring object, if needed for this connection and record login
296 //
297  if (Monitor.Ready())
298  {Monitor.Register(linkP->ID, linkP->Host(), protP);
299  if (Monitor.Logins())
300  {if (Monitor.Auths() && seceP) MonAuth();
301  else Monitor.Report(Monitor.Auths() ? "" : 0);
302  }
303  }
304 
305 // Complete the request ID object
306 //
307  ReqID.setID(Request.header.streamid, linkP->FDnum(), linkP->Inst());
308 
309 // Substitute our protocol for the existing one
310 //
311  realProt = linkP->setProtocol(this);
312  linkP->setProtName(protP);
313  linkP->armBridge();
314 
315 // Document this login
316 //
317  who = (seceP && seceP->name ? seceP->name : "nobody");
318  eDest.Log(SYS_LOG_01, "Bridge", Link->ID, "login as", who);
319 
320 // All done, indicate we are logged in
321 //
323  cTime = time(0);
324 
325 // Propogate a connect through the whole system
326 //
327  osFS->Connect(Client);
328 }
329 
330 /******************************************************************************/
331 /* P r o c e e d */
332 /******************************************************************************/
333 
335 {
336  int rc;
337 
338 // If we were interrupted in a reinvoke state, resume that state.
339 //
340  if (reInvoke) rc = Process(Link);
341  else rc = 0;
342 
343 // Handle ending status
344 //
345  if (rc >= 0) Link->Enable();
346  else if (rc != -EINPROGRESS) Link->Close();
347 }
348 
349 /******************************************************************************/
350 /* P r o c e s s */
351 /******************************************************************************/
352 
354 {
355  int rc;
356 
357 // This entry is serialized via link processing and data is now available.
358 // One of the following will be returned.
359 //
360 // < 0 -> Stop getting requests,
361 // -EINPROGRESS leave link disabled but otherwise all is well
362 // -n Error, disable and close the link
363 // = 0 -> OK, get next request, if allowed, o/w enable the link
364 // > 0 -> Slow link, stop getting requests and enable the link
365 //
366 
367 // Reflect data is present to the underlying protocol and if Run() has been
368 // called we need to dispatch that request. This may be iterative.
369 //
370 do{rc = realProt->Process((reInvoke ? 0 : lp));
371  if (rc >= 0 && runStatus)
372  {reInvoke = (rc == 0);
373  if (runError) rc = Fatal(rc);
374  else {runDone = false;
375  rc = (Resume ? XrdXrootdProtocol::Process(lp) : Process2());
376  if (rc >= 0)
377  {if (runWait) rc = -EINPROGRESS;
378  if (!runDone) return rc;
379  AtomicBeg(runMutex);
380  AtomicZAP(runStatus);
381  AtomicEnd(runMutex);
382  }
383  }
384  } else reInvoke = false;
385  } while(rc >= 0 && reInvoke);
386 
387 // Make sure that we indicate that we are no longer active
388 //
389  if (runStatus)
390  {AtomicBeg(runMutex);
391  AtomicZAP(runStatus);
392  AtomicEnd(runMutex);
393  }
394 
395 // All done
396 //
397  return (rc ? rc : 1);
398 }
399 
400 /******************************************************************************/
401 /* R e c y c l e */
402 /******************************************************************************/
403 
404 void XrdXrootdTransit::Recycle(XrdLink *lp, int consec, const char *reason)
405 {
406 
407 // Set ourselves as active so we can't get more requests
408 //
409  AtomicBeg(runMutex);
410  AtomicInc(runStatus);
411  AtomicEnd(runMutex);
412 
413 // If we were active then we will need to quiesce before dismantling ourselves.
414 // Note that Recycle() can only be called if the link is enabled. So, this bit
415 // of code is improbable but we check it anyway.
416 //
417  if (runWait > 0) Sched->Cancel(&waitJob);
418 
419 // First we need to recycle the real protocol
420 //
421  if (realProt) realProt->Recycle(lp, consec, reason);
422 
423 // Now we need to recycle our xrootd part
424 //
425  XrdXrootdProtocol::Recycle(lp, consec, reason);
426 
427 // Release the argument buffer
428 //
429  if (runArgs) {free(runArgs); runArgs = 0;}
430 
431 // Delete all pending requests
432 //
434 
435 // Now just free up our object.
436 //
437  TranStack.Push(&TranLink);
438 }
439 
440 /******************************************************************************/
441 /* R e d r i v e */
442 /******************************************************************************/
443 
445 {
446  static int eCode = htonl(kXR_NoMemory);
447  static char eText[] = "Insufficent memory to re-issue request";
448  static struct iovec ioV[] = {{(char *)&eCode,sizeof(eCode)},
449  {(char *)&eText,sizeof(eText)}};
450  int rc;
451 
452 // Update wait statistics
453 //
454  runWTot += runWait;
455  runWait = 0;
456 
457 // While we are running asynchronously, there is no way that this object can
458 // be deleted while a timer is outstanding as the link has been disabled. So,
459 // we can reissue the request with little worry.
460 //
461  if (!runALen || RunCopy(runArgs, runALen)) {
462  do{rc = Process2();
463  if (rc == 0) {
464  rc = realProt->Process(NULL);
465  }
466  if (runStatus)
467  {AtomicBeg(runMutex);
468  AtomicZAP(runStatus);
469  AtomicEnd(runMutex);
470  }
471  } while((rc == 0) && !runError && !runWait);
472  }
473  else rc = Send(kXR_error, ioV, 2, 0);
474 
475 // Defer the request if need be
476 //
477  if (rc >= 0 && runWait) return;
478  runWTot = 0;
479 
480 // Indicate we are no longer active
481 //
482  if (runStatus)
483  {AtomicBeg(runMutex);
484  AtomicZAP(runStatus);
485  AtomicEnd(runMutex);
486  }
487 
488 // If the link needs to be terminated, terminate the link. Otherwise, we can
489 // enable the link for new requests at this point.
490 //
491  if (rc < 0) Link->Close();
492  else Link->Enable();
493 }
494 
495 /******************************************************************************/
496 /* R e q T a b l e */
497 /******************************************************************************/
498 
499 #define KXR_INDEX(x) x-kXR_auth
500 
502 {
503  static char rTab[kXR_truncate-kXR_auth+1];
504 
505 // Initialize the table
506 //
507  memset(rTab, 0, sizeof(rTab));
508  rTab[KXR_INDEX(kXR_chmod)] = 1;
509  rTab[KXR_INDEX(kXR_close)] = 1;
510  rTab[KXR_INDEX(kXR_dirlist)] = 1;
511  rTab[KXR_INDEX(kXR_locate)] = 1;
512  rTab[KXR_INDEX(kXR_mkdir)] = 1;
513  rTab[KXR_INDEX(kXR_mv)] = 1;
514  rTab[KXR_INDEX(kXR_open)] = 1;
515  rTab[KXR_INDEX(kXR_prepare)] = 1;
516  rTab[KXR_INDEX(kXR_protocol)] = 1;
517  rTab[KXR_INDEX(kXR_query)] = 1;
518  rTab[KXR_INDEX(kXR_read)] = 2;
519  rTab[KXR_INDEX(kXR_readv)] = 2;
520  rTab[KXR_INDEX(kXR_rm)] = 1;
521  rTab[KXR_INDEX(kXR_rmdir)] = 1;
522  rTab[KXR_INDEX(kXR_set)] = 1;
523  rTab[KXR_INDEX(kXR_stat)] = 1;
524  rTab[KXR_INDEX(kXR_statx)] = 1;
525  rTab[KXR_INDEX(kXR_sync)] = 1;
526  rTab[KXR_INDEX(kXR_truncate)] = 1;
527  rTab[KXR_INDEX(kXR_write)] = 2;
528 
529 // Now return the address
530 //
531  return rTab;
532 }
533 
534 /******************************************************************************/
535 /* Private: R e q W r i t e */
536 /******************************************************************************/
537 
538 bool XrdXrootdTransit::ReqWrite(char *xdataP, int xdataL)
539 {
540 
541 // Make sure we always transit to the resume point
542 //
543  myBlen = 0;
544 
545 // If nothing was read, then this is a straight-up write
546 //
547  if (!xdataL || !xdataP || !Request.header.dlen)
548  {Resume = 0; wBuff = xdataP; wBLen = xdataL;
549  return true;
550  }
551 
552 // Partial data was read, we may have to split this between a direct write
553 // and a network read/write -- somewhat complicated.
554 //
555  myBuff = wBuff = xdataP;
556  myBlast = wBLen = xdataL;
558  return true;
559 }
560 
561 /******************************************************************************/
562 /* R u n */
563 /******************************************************************************/
564 
565 bool XrdXrootdTransit::Run(const char *xreqP, char *xdataP, int xdataL)
566 {
567  int movLen, rc;
568 
569 // We do not allow re-entry if we are curently processing a request.
570 // It will be reset, as need, when a response is effected.
571 //
572  AtomicBeg(runMutex);
573  rc = AtomicInc(runStatus);
574  AtomicEnd(runMutex);
575  if (rc)
576  {TRACEP(REQ, "Bridge request failed due to re-entry");
577  return false;
578  }
579 
580 // Copy the request header
581 //
582  memcpy((void *)&Request, (void *)xreqP, sizeof(Request));
583 
584 // Validate that we can actually handle this request
585 //
587  if (Request.header.requestid & 0x8000
588  || Request.header.requestid > static_cast<kXR_unt16>(kXR_truncate)
589  || !reqTab[Request.header.requestid - kXR_auth])
590  {TRACEP(REQ, "Unsupported bridge request");
591  return Fail(kXR_Unsupported, "Unsupported bridge request");
592  }
593 
594 // Validate the data length
595 //
597  if (Request.header.dlen < 0)
598  {TRACEP(REQ, "Invalid request data length");
599  return Fail(kXR_ArgInvalid, "Invalid request data length");
600  }
601 
602 // Copy the stream id and trace this request
603 //
605  TRACEP(REQ, "Bridge req=" <<Request.header.requestid
606  <<" dlen=" <<Request.header.dlen <<" blen=" <<xdataL);
607 
608 // If this is a write request, we will need to do a lot more
609 //
610  if (Request.header.requestid == kXR_write) return ReqWrite(xdataP, xdataL);
611 
612 // Obtain any needed buffer and handle any existing data arguments. Also, we
613 // need to keep a shadow copy of the request arguments should we get a wait
614 // and will need to re-issue the request (the server mangles the args).
615 //
616  if (Request.header.dlen)
617  {movLen = (xdataL < Request.header.dlen ? xdataL : Request.header.dlen);
618  if (!RunCopy(xdataP, movLen)) return true;
619  if (!runArgs || movLen > runABsz)
620  {if (runArgs) free(runArgs);
621  if (!(runArgs = (char *)malloc(movLen)))
622  {TRACEP(REQ, "Failed to allocate memory");
623  return Fail(kXR_NoMemory, "Insufficient memory");
624  }
625  runABsz = movLen;
626  }
627  memcpy(runArgs, xdataP, movLen); runALen = movLen;
628  if ((myBlen = Request.header.dlen - movLen))
629  {myBuff = argp->buff + movLen;
631  return true;
632  }
633  } else runALen = 0;
634 
635 // If we have all the data, indicate request accepted.
636 //
637  runError = 0;
638  Resume = 0;
639  return true;
640 }
641 
642 /******************************************************************************/
643 /* Privae: R u n C o p y */
644 /******************************************************************************/
645 
646 bool XrdXrootdTransit::RunCopy(char *buffP, int buffL)
647 {
648 
649 // Allocate a buffer if we do not have one or it is too small
650 //
651  if (!argp || Request.header.dlen+1 > argp->bsize)
652  {if (argp) BPool->Release(argp);
653  if (!(argp = BPool->Obtain(Request.header.dlen+1)))
654  {Fail(kXR_ArgTooLong, "Request argument too long"); return false;}
655  hcNow = hcPrev; halfBSize = argp->bsize >> 1;
656  }
657 
658 // Copy the arguments to the buffer
659 //
660  memcpy(argp->buff, buffP, buffL);
661  argp->buff[buffL] = 0;
662  return true;
663 }
664 
665 /******************************************************************************/
666 /* S e n d */
667 /******************************************************************************/
668 
669 int XrdXrootdTransit::Send(int rcode, const struct iovec *ioV, int ioN, int ioL)
670 {
673  const char *eMsg;
674  int rc;
675  bool aOK;
676 
677 // Invoke the result object (we initially assume this is the final result)
678 //
679  runDone = true;
680  switch(rcode)
681  {case kXR_error:
682  rc = XRD_GETNUM(ioV[0].iov_base);
683  eMsg = (ioN < 2 ? "" : (const char *)ioV[1].iov_base);
684  if (wBuff) respObj->Free(rInfo, wBuff, wBLen);
685  aOK = respObj->Error(rInfo, rc, eMsg);
686  break;
687  case kXR_ok:
688  if (wBuff) respObj->Free(rInfo, wBuff, wBLen);
689  aOK = (ioN ? respObj->Data(rInfo, ioV, ioN, ioL, true)
690  : respObj->Done(rInfo));
691  break;
692  case kXR_oksofar:
693  aOK = respObj->Data(rInfo, ioV, ioN, ioL, false);
694  runDone = false;
695  break;
696  case kXR_redirect:
697  if (wBuff) respObj->Free(rInfo, wBuff, wBLen);
698  rc = XRD_GETNUM(ioV[0].iov_base);
699  aOK = respObj->Redir(rInfo,rc,(const char *)ioV[1].iov_base);
700  break;
701  case kXR_wait:
702  return Wait(rInfo, ioV, ioN, ioL);
703  break;
704  case kXR_waitresp:
705  runDone = false;
706  return WaitResp(rInfo, ioV, ioN, ioL);
707  break;
708  default: if (wBuff) respObj->Free(rInfo, wBuff, wBLen);
709  aOK = respObj->Error(rInfo, kXR_ServerError,
710  "internal logic error");
711  break;
712  };
713 
714 // All done
715 //
716  return (aOK ? 0 : -1);
717 }
718 
719 /******************************************************************************/
720 
721 int XrdXrootdTransit::Send(long long offset, int dlen, int fdnum)
722 {
725  offset, dlen, fdnum);
726 
727 // Effect callback (this is always a final result)
728 //
729  runDone = true;
730  return (respObj->File(sfInfo, dlen) ? 0 : -1);
731 }
732 
733 /******************************************************************************/
734 
735 int XrdXrootdTransit::Send(XrdOucSFVec *sfvec, int sfvnum, int dlen)
736 {
739  sfvec, sfvnum, dlen);
740 
741 // Effect callback (this is always a final result)
742 //
743  runDone = true;
744  return (respObj->File(sfInfo, dlen) ? 0 : -1);
745 }
746 
747 /******************************************************************************/
748 /* Private: W a i t */
749 /******************************************************************************/
750 
751 int XrdXrootdTransit::Wait(XrdXrootd::Bridge::Context &rInfo,
752  const struct iovec *ioV, int ioN, int ioL)
753 {
754  const char *eMsg;
755 
756 // Trace this request if need be
757 //
758  runWait = XRD_GETNUM(ioV[0].iov_base);
759  eMsg = (ioN < 2 ? "reason unknown" : (const char *)ioV[1].iov_base);
760 
761 // Check if the protocol wants to handle all waits
762 //
763  if (runWMax <= 0)
764  {int wtime = runWait;
765  runWait = 0;
766  return (respObj->Wait(rInfo, wtime, eMsg) ? 0 : -1);
767  }
768 
769 // Check if we have exceeded the maximum wait time
770 //
771  if (runWTot >= runWMax)
772  {runDone = true;
773  runWait = 0;
774  return (respObj->Error(rInfo, kXR_Cancelled, eMsg) ? 0 : -1);
775  }
776 
777 // Readjust wait time
778 //
779  if (runWait > runWMax) runWait = runWMax;
780 
781 // Check if the protocol wants a wait notification
782 //
783  if (runWCall && !(respObj->Wait(rInfo, runWait, eMsg))) return -1;
784 
785 // All done, schedule the wait
786 //
787  TRACEP(REQ, "Bridge delaying request " <<runWait <<" sec (" <<eMsg <<")");
788  Sched->Schedule((XrdJob *)&waitJob, time(0)+runWait);
789  return 0;
790 }
791 
792 /******************************************************************************/
793 /* Private: W a i t R e s p */
794 /******************************************************************************/
795 
796 int XrdXrootdTransit::WaitResp(XrdXrootd::Bridge::Context &rInfo,
797  const struct iovec *ioV, int ioN, int ioL)
798 {
799  XrdXrootdTransPend *trP;
800  const char *eMsg;
801  int wTime;
802 
803 // Trace this request if need be
804 //
805  wTime = XRD_GETNUM(ioV[0].iov_base);
806  eMsg = (ioN < 2 ? "reason unknown" : (const char *)ioV[1].iov_base);
807  TRACEP(REQ, "Bridge waiting for resp; sid=" <<rInfo.sID.num
808  <<" wt=" <<wTime <<" (" <<eMsg <<")");
809 
810 // We would issue callback to see how we should handle this. However, we can't
811 // predictably handle a waitresp. So that means we will just wait for a resp.
812 //
813 // XrdXrootd::Bridge::Result *newCBP = respObj->WaitResp(rInfo, runWait, eMsg);
814 
815 // Save the current state
816 //
817  trP = new XrdXrootdTransPend(Link, this, &Request);
818  trP->Queue();
819 
820 // Effect a wait
821 //
822  runWait = -1;
823  return 0;
824 }
@ kXR_ArgInvalid
Definition: XProtocol.hh:990
@ kXR_Unsupported
Definition: XProtocol.hh:1003
@ kXR_Cancelled
Definition: XProtocol.hh:1007
@ kXR_ServerError
Definition: XProtocol.hh:1002
@ kXR_ArgTooLong
Definition: XProtocol.hh:992
@ kXR_NoMemory
Definition: XProtocol.hh:998
kXR_char streamid[2]
Definition: XProtocol.hh:156
kXR_char username[8]
Definition: XProtocol.hh:396
@ kXR_waitresp
Definition: XProtocol.hh:906
@ kXR_redirect
Definition: XProtocol.hh:904
@ kXR_oksofar
Definition: XProtocol.hh:900
@ kXR_ok
Definition: XProtocol.hh:899
@ kXR_wait
Definition: XProtocol.hh:905
@ kXR_error
Definition: XProtocol.hh:903
struct ClientRequestHdr header
Definition: XProtocol.hh:846
struct ClientLoginRequest login
Definition: XProtocol.hh:857
kXR_unt16 requestid
Definition: XProtocol.hh:157
@ kXR_read
Definition: XProtocol.hh:125
@ kXR_open
Definition: XProtocol.hh:122
@ kXR_readv
Definition: XProtocol.hh:137
@ kXR_mkdir
Definition: XProtocol.hh:120
@ kXR_sync
Definition: XProtocol.hh:128
@ kXR_chmod
Definition: XProtocol.hh:114
@ kXR_dirlist
Definition: XProtocol.hh:116
@ kXR_rm
Definition: XProtocol.hh:126
@ kXR_query
Definition: XProtocol.hh:113
@ kXR_write
Definition: XProtocol.hh:131
@ kXR_auth
Definition: XProtocol.hh:112
@ kXR_set
Definition: XProtocol.hh:130
@ kXR_rmdir
Definition: XProtocol.hh:127
@ kXR_statx
Definition: XProtocol.hh:134
@ kXR_truncate
Definition: XProtocol.hh:140
@ kXR_protocol
Definition: XProtocol.hh:118
@ kXR_mv
Definition: XProtocol.hh:121
@ kXR_stat
Definition: XProtocol.hh:129
@ kXR_locate
Definition: XProtocol.hh:139
@ kXR_close
Definition: XProtocol.hh:115
@ kXR_prepare
Definition: XProtocol.hh:133
@ kXR_asyncap
Definition: XProtocol.hh:378
@ kXR_ver002
Definition: XProtocol.hh:386
kXR_int32 dlen
Definition: XProtocol.hh:159
unsigned short kXR_unt16
Definition: XPtypes.hh:67
#define eMsg(x)
#define AtomicInc(x)
#define AtomicBeg(Mtx)
#define AtomicZAP(x)
#define AtomicEnd(Mtx)
const int SYS_LOG_01
Definition: XrdSysError.hh:72
#define TRACE_MEM
Definition: XrdTrace.hh:38
#define TRACE(act, x)
Definition: XrdTrace.hh:63
#define XRD_LOGGEDIN
#define TRACEP(act, x)
XrdSysTrace XrdXrootdTrace
#define XRD_GETNUM(x)
#define KXR_INDEX(x)
void Release(XrdBuffer *bp)
Definition: XrdBuffer.cc:221
XrdBuffer * Obtain(int bsz)
Definition: XrdBuffer.cc:140
int bsize
Definition: XrdBuffer.hh:46
char * buff
Definition: XrdBuffer.hh:45
Definition: XrdJob.hh:43
bool isMapped() const
bool isIPType(IPType ipType) const
void Set(int inQMax, time_t agemax=1800)
Definition: XrdObject.icc:90
void Push(XrdObject< T > *Node)
Definition: XrdObject.hh:101
T * Pop()
Definition: XrdObject.hh:93
void Bump(int &val)
Definition: XrdOucStats.hh:47
static void Sanitize(char *instr, char subc='_')
virtual void Recycle(XrdLink *lp=0, int consec=0, const char *reason=0)=0
virtual int Process(XrdLink *lp)=0
void Schedule(XrdJob *jp)
void Cancel(XrdJob *jp)
const char * pident
Trace identifier (originator)
Definition: XrdSecEntity.hh:82
XrdNetAddrInfo * addrInfo
Entity's connection details.
Definition: XrdSecEntity.hh:80
const char * tident
Trace identifier always preset.
Definition: XrdSecEntity.hh:81
char prot[XrdSecPROTOIDSIZE]
Auth protocol used (e.g. krb5)
Definition: XrdSecEntity.hh:67
char * name
Entity's name.
Definition: XrdSecEntity.hh:69
unsigned int ueid
Unique ID of entity instance.
Definition: XrdSecEntity.hh:79
char * host
Entity's host name dnr dependent.
Definition: XrdSecEntity.hh:70
virtual void Connect(const XrdSecEntity *client=0)
void Log(int mask, const char *esfx, const char *text1, const char *text2=0, const char *text3=0)
Definition: XrdSysError.hh:133
void Register(const char *Uname, const char *Hname, const char *Pname, unsigned int xSID=0)
void Report(const char *Info)
static XrdXrootdStats * SI
XrdSecEntity * Client
static XrdSysError & eDest
static unsigned int getSID()
XrdXrootdMonitor::User Monitor
int(XrdXrootdProtocol::* Resume)()
static XrdScheduler * Sched
int Process(XrdLink *lp) override
void Recycle(XrdLink *lp, int consec, const char *reason) override
XrdXrootdResponse Response
static XrdBuffManager * BPool
XrdXrootdReqID ReqID
static XrdSfsFileSystem * osFS
void setID(unsigned long long id)
void Set(XrdLink *lp)
static XrdXrootdTransPend * Remove(XrdLink *lP, short sid)
union XrdXrootdTransPend::@189 Pend
XrdXrootdTransit * bridge
static void Clear(XrdXrootdTransit *trP)
bool Run(const char *xreqP, char *xdataP=0, int xdataL=0)
Inject an xrootd request into the protocol stack.
static const char * ReqTable()
Initialize the valid request table.
void Redrive()
Redrive a request after a wait.
int Send(int rcode, const struct iovec *ioVec, int ioNum, int ioLen)
Handle request data response.
void Recycle(XrdLink *lp, int consec, const char *reason)
Handle link shutdown.
static void Init(XrdScheduler *schedP, int qMax, int qTTL)
Perform one-time initialization.
static XrdXrootdTransit * Alloc(XrdXrootd::Bridge::Result *respP, XrdLink *linkP, XrdSecEntity *seceP, const char *nameP, const char *protP)
Get a new transit object.
static int Attn(XrdLink *lP, short *theSID, int rcode, const struct iovec *ioVec, int ioNum, int ioLen)
Handle attention response (i.e. async response)
XrdXrootdTransit()
Constructor & Destructor.
void Proceed()
Resume processing after a waitresp completion.
bool Disc()
Handle dismantlement.
int Process(XrdLink *lp)
Handle link activation (replaces parent activation).
union XrdXrootd::Bridge::Context::@162 sID
associated request stream ID
virtual int File(Bridge::Context &info, int dlen)=0
virtual bool Data(Bridge::Context &info, const struct iovec *iovP, int iovN, int iovL, bool final)=0
virtual bool Error(Bridge::Context &info, int ecode, const char *etext)=0
virtual bool Done(Bridge::Context &info)=0
the result context
virtual bool Redir(Bridge::Context &info, int port, const char *hname)=0
virtual bool Wait(Bridge::Context &info, int wtime, const char *wtext)
virtual void Free(Bridge::Context &info, char *buffP, int buffL)
XrdScheduler * schedP
static const int uIPv4
ucap: Supports read redirects
static const int uPrip