36 #include <sys/types.h>
37 #include <netinet/in.h>
60 #define SINGLETON(dlvar, theitem)\
61 theitem ->dlvar .next == theitem
63 #define INSERT(dlvar, curitem, newitem) \
64 newitem ->dlvar .next = curitem; \
65 newitem ->dlvar .prev = curitem ->dlvar .prev; \
66 curitem ->dlvar .prev-> dlvar .next = newitem; \
67 curitem ->dlvar .prev = newitem
69 #define REMOVE(dlbase, dlvar, curitem) \
70 if (dlbase == curitem) dlbase = (SINGLETON(dlvar,curitem) \
71 ? 0 : curitem ->dlvar .next);\
72 curitem ->dlvar .prev-> dlvar .next = curitem ->dlvar .next;\
73 curitem ->dlvar .next-> dlvar .prev = curitem ->dlvar .prev;\
74 curitem ->dlvar .next = curitem;\
75 curitem ->dlvar .prev = curitem
83 std::string dsProperty(
"DataServer");
86 Atomic(uint32_t) sidVal(0);
107 class CleanUp :
public XrdJob
111 void DoIt() {sessP->Lock();
112 sessP->Unprovision();
132 if (resKey) free(resKey);
133 if (sessName) free(sessName);
134 if (sessNode) free(sessNode);
136 while((tP = freeTask)) {freeTask = tP->
attList.
next;
delete tP;}
144 int uent,
bool hold,
bool newSID)
157 if (resKey) {free(resKey); resKey = 0;}
158 if (sessName) free(sessName);
159 sessName = (sName ? strdup(sName) : 0);
160 if (sessNode) free(sessNode);
163 {
if (servP == 0) sessID = 0xffffffff;
168 DEBUG(
"new sess for "<<sName<<
" uent="<<uent<<
" hold="<<hold);
171 DEBUG(
"reuse sess for "<<sName<<
" uent="<<uent<<
" hold="<<hold);
206 DEBUG(
"New task=" <<tP <<
" id=" <<tP->
ID());
210 if ((ptP = attBase)) {
INSERT(attList, ptP, tP);}
238 DEBUG(
"Provisioning " <<epURL);
239 epStatus = epFile.Open((
const std::string)epURL, oFlags,
247 if (!epStatus.
IsOK())
272 DEBUG((isHeld ?
"Recycling":
"Deleting")<<
" task="<<tP<<
" id=" <<tP->
ID());
276 if (!isHeld)
delete tP;
294 if (noReuse)
return false;
306 if (!inOpen && tP && !tP->
SendRequest(sessNode)) noReuse =
true;
322 while((tP = ntP)) {ntP = tP->
attList.
next;
delete tP;}
327 if (onClose && !epStatus.
IsOK())
331 snprintf(mBuff,
sizeof(mBuff),
"Unprovision: %s@%s error; %d",
332 sessName, sessNode, eNum);
333 Log.
Emsg(
"Shutdown", mBuff, eText.c_str());
335 myService->Recycle(
this,
false);
337 if (sessName) {free(sessName); sessName = 0;}
338 if (sessNode) {free(sessNode); sessNode = 0;}
340 myService->Recycle(
this, !noReuse);
358 {
REMOVE(attBase, attList, tP);}
375 {
if (!isHeld && !attBase) Unprovision();
376 else sessMutex.UnLock();
378 DEBUG(
"Unprovision deferred for " <<sessName);
393 if (isHeld && resKey && myService) myService->StopReuse(resKey);
415 DEBUG(
"Closing " <<sessName);
421 if (!epFile.IsOpen()) {Shutdown(uStat,
false);
return false;}
423 if (!uStat.
IsOK()) {Shutdown(uStat,
true);
return false;}
424 else sessMutex.UnLock();
446 {Shutdown(*status,
true);
454 noReuse = !status->
IsOK();
464 if (!status->
IsOK()) Shutdown(*status,
false);
465 else {
if (!isHeld)
return (Unprovision() ? 1 : -1);
466 else sessMutex.UnLock();
479 while(tP != attBase);
486 std::string currNode;
487 if (epFile.GetProperty(dsProperty, currNode))
488 {
if (sessNode) free(sessNode);
489 sessNode = strdup(currNode.c_str());
490 }
else sessNode = strdup(
"Unknown!");
int DoIt(int argpnt, int argc, char **argv, bool singleshot)
#define REMOVE(dlbase, dlvar, curitem)
#define INSERT(dlvar, curitem, newitem)
Handle an async response.
void Schedule(XrdJob *jp)
static void SetMutex(XrdSsiRequest *rP, XrdSsiMutex *mP)
static bool isaRetry(XrdSsiRequest *rP, bool reset=false)
static const unsigned int idMax
void BindRequest(XrdSsiRequest &rqstR)
void InitSession(XrdSsiServReal *servP, const char *sName, int uent, bool hold, bool newSID=false)
bool Provision(XrdSsiRequest *reqP, const char *epURL)
bool Run(XrdSsiRequest *reqP)
int XeqEvent(XrdCl::XRootDStatus *status, XrdCl::AnyObject **respP)
void UnHold(bool cleanup=true)
void TaskFinished(XrdSsiTaskReal *tP)
void Init(XrdSsiRequest *rP, unsigned short tmo=0)
void SchedError(XrdSsiErrInfo *eInfo=0)
bool SendRequest(const char *node)
void SetTaskID(uint32_t tid, uint32_t sid)
static int GetErr(XrdCl::XRootDStatus &Status, std::string &eText)
static void RetErr(XrdSsiRequest &reqP, const char *eTxt, int eNum)
static void SetErr(XrdCl::XRootDStatus &Status, XrdSsiErrInfo &eInfo)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Flags
Open flags, may be or'd when appropriate.
@ Read
Open only for reading.
bool IsOK() const
We're fine.