Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
XrdProofdProofServMgr.h
Go to the documentation of this file.
1// @(#)root/proofd:$Id$
2// Author: G. Ganis Jan 2008
3
4/*************************************************************************
5 * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_XrdProofdProofServMgr
13#define ROOT_XrdProofdProofServMgr
14
15//////////////////////////////////////////////////////////////////////////
16// //
17// XrdProofdProofServMgr //
18// //
19// Author: G. Ganis, CERN, 2008 //
20// //
21// Class managing proofserv sessions manager. //
22// //
23//////////////////////////////////////////////////////////////////////////
24
25#include <list>
26#include <map>
27
28#include "XpdSysPthread.h"
29
30#include "XrdProofdXrdVers.h"
31#ifndef ROOT_XrdFour
32# include <sys/types.h>
33# include <sys/socket.h>
34# include "XrdNet/XrdNetPeer.hh"
35#else
36# include "XrdNet/XrdNetAddr.hh"
37#endif
38#include "XrdOuc/XrdOucHash.hh"
39#include "XrdOuc/XrdOucString.hh"
40
41#include "XrdProofdConfig.h"
42#include "XrdProofdProofServ.h"
43
44class XrdOucStream;
45class XrdProtocol_Config;
47class XrdROOTMgr;
48class XrdSysLogger;
49
50#define PSMMAXCNTS 3
51#define PSMCNTOK(t) (t >= 0 && t < PSMMAXCNTS)
52
53// Security handle
54typedef int (*XrdSecCredsSaver_t)(XrdSecCredentials *, const char *fn, const XrdProofUI &ui);
55
56// Aux structure for session set env inputs
57typedef struct {
60 XrdOucString fCfg;
61 XrdOucString fLogFile;
62 XrdOucString fSessionTag;
63 XrdOucString fTopSessionTag;
64 XrdOucString fSessionDir;
65 XrdOucString fWrkDir;
66 bool fOld;
68
70public:
71 XrdSysRecMutex fMutex;
73 std::list<XrdProofdProofServ *> fProofServs;
75 int operator==(const XpdClientSessions c) { return (c.fClient == fClient) ? 1 : 0; }
76};
77
79public:
81 int fPid;
82 int fID;
86 XrdOucString fUser;
87 XrdOucString fGroup;
88 XrdOucString fUnixPath;
89 XrdOucString fTag;
90 XrdOucString fAlias;
91 XrdOucString fLogFile;
92 XrdOucString fOrdinal;
93 XrdOucString fUserEnvs;
94 XrdOucString fROOTTag;
95 XrdOucString fAdminPath;
97
100
102 int ReadFromFile(const char *file);
103 void Reset();
104 int SaveToFile(const char *file);
105};
106
107class XpdEnv {
108public:
109 XrdOucString fName;
110 XrdOucString fEnv;
111 XrdOucString fUsers;
112 XrdOucString fGroups;
117 XpdEnv(const char *n, const char *env, const char *usr = 0, const char *grp = 0,
118 int smi = -1, int smx = -1, int vmi = -1, int vmx = -1) :
119 fName(n), fEnv(env), fUsers(usr), fGroups(grp),
120 fSvnMin(smi), fSvnMax(smx), fVerMin(vmi), fVerMax(vmx) { }
121 void Reset(const char *n, const char *env, const char *usr = 0, const char *grp = 0,
122 int smi = -1, int smx = -1, int vmi = -1, int vmx = -1) {
123 fName = n; fEnv = env; fUsers = usr; fGroups = grp;
124 fSvnMin = smi; fSvnMax = smx; fVerMin = vmi; fVerMax = vmx; }
125 int Matches(const char *usr, const char *grp, int ver = -1);
126 void Print(const char *what);
127 static int ToVersCode(int ver, bool hex = 0);
128};
129
131
133 XrdSysRecMutex fMutex;
134 XrdSysRecMutex fRecoverMutex;
135 XrdSysRecMutex fEnvsMutex; // Protect usage of envs lists
136 XrdSysSemWait fForkSem; // To serialize fork requests
137 XrdSysSemWait fProcessSem; // To serialize process requests
138 XrdSysLogger *fLogger; // Error logger
139 int fInternalWait; // Timeout on replies from proofsrv
140 XrdOucString fProofPlugin; // String identifying the plug-in to be loaded, e.g. "condor:"
141 std::list<XpdEnv> fProofServEnvs; // Additional envs to be exported before proofserv
142 std::list<XpdEnv> fProofServRCs; // Additional rcs to be passed to proofserv
143
144 int fShutdownOpt; // What to do when a client disconnects
145 int fShutdownDelay; // Delay shutdown by this (if enabled)
146
148
157 bool fUseFork; // If true, use fork to start proofserv
158 XrdOucString fParentExecs; // List of possible 'proofserv' parent names
159
160 int fCounters[PSMMAXCNTS]; // Internal counters (see enum PSMCounters)
161 int fCurrentSessions; // Number of sessions (top masters)
162
163 unsigned int fSeqSessionN; // Sequential number for sessions created by this instance
164
165 int fNextSessionsCheck; // Time of next sessions check
166
167 XrdOucString fActiAdminPath; // Active sessions admin area
168 XrdOucString fTermAdminPath; // Terminated sessions admin area
169
170 XrdOucHash<XrdProofdProofServ> fSessions; // List of sessions
171 std::list<XrdProofdProofServ *> fActiveSessions; // List of active sessions (non-idle)
172 std::list<XpdClientSessions *> *fRecoverClients; // List of client potentially recovering
173
174 XrdSecCredsSaver_t fCredsSaver; // If defined, function to be used to save the credentials
175
176 std::map<XrdProofdProtocol*,int> fDestroyTimes; // Tracks destroyed sessions
177
178 int DoDirectiveProofServMgr(char *, XrdOucStream *, bool);
179 int DoDirectivePutEnv(char *, XrdOucStream *, bool);
180 int DoDirectivePutRc(char *, XrdOucStream *, bool);
181 int DoDirectiveShutdown(char *, XrdOucStream *, bool);
182 void ExtractEnv(char *, XrdOucStream *,
183 XrdOucString &users, XrdOucString &groups,
184 XrdOucString &rcval, XrdOucString &rcnam,
185 int &smi, int &smx, int &vmi, int &vmx, bool &hex);
186 void FillEnvList(std::list<XpdEnv> *el, const char *nam, const char *val,
187 const char *usrs = 0, const char *grps = 0,
188 int smi = -1, int smx = -1, int vmi = -1, int vmx = -1, bool hex = 0);
189 unsigned int GetSeqSessionN() { XrdSysMutexHelper mhp(fMutex); return ++fSeqSessionN; }
190
192 XrdProofdProtocol *p, int pid, XrdOucString &emsg);
194 unsigned int seq, XrdOucString &emsg);
195// int CreateFork(XrdProofdProtocol *p);
197 void *input, const char *envfn, const char *rcfn);
199 void *input, const char *rcfn);
200#ifndef ROOT_XrdFour
201 int SetupProtocol(XrdNetPeer &peerpsrv,
202#else
203 int SetupProtocol(XrdNetAddr &netaddr,
204#endif
205 XrdProofdProofServ *xps, XrdOucString &e);
207 XrdOucString &tag, XrdOucString &ord,
208 XrdOucString &cffile, XrdOucString &uenvs,
209 int &intwait);
211 XrdProofdResponse *r, unsigned short &sid);
213 int ResolveSession(const char *fpid);
214
215 void SendErrLog(const char *errlog, XrdProofdResponse *r);
216
217 // Session Admin path management
219 bool IsSessionSocket(const char *fpid);
220 int RmSession(const char *fpid);
221 int TouchSession(const char *fpid, const char *path = 0);
222 int VerifySession(const char *fpid, int to = -1, const char *path = 0);
223
224 void ResolveKeywords(XrdOucString &s, ProofServEnv_t *in);
225 int SetUserOwnerships(XrdProofdProtocol *p, const char *ord, const char *stag);
226
227public:
228 XrdProofdProofServMgr(XrdProofdManager *mgr, XrdProtocol_Config *pi, XrdSysError *e);
230
233
234 XrdSysRecMutex *Mutex() { return &fMutex; }
235
236 int Config(bool rcf = 0);
238 char *val, XrdOucStream *cfg, bool rcf);
239 void RegisterDirectives();
240
241 int CheckFrequency() const { return fCheckFrequency; }
242 int InternalWait() const { return fInternalWait; }
243 int VerifyTimeOut() const { return fVerifyTimeOut; }
244
245 inline int NextSessionsCheck()
246 { XrdSysMutexHelper mhp(fMutex); return fNextSessionsCheck; }
247 inline void SetNextSessionsCheck(int t)
248 { XrdSysMutexHelper mhp(fMutex); fNextSessionsCheck = t; }
249
250 bool IsReconnecting();
251 bool IsClientRecovering(const char *usr, const char *grp, int &deadline);
252 void SetReconnectTime(bool on = 1);
253
254 bool Alive(XrdProofdProtocol *p);
255
257 XrdSysSemWait *ProcessSem() { return &fProcessSem; }
258
259 int AcceptPeer(XrdProofdProofServ *xps, int to, XrdOucString &e);
264 int Recover(XpdClientSessions *cl);
265
266 void UpdateCounter(int t, int n) { if (PSMCNTOK(t)) {
267 XrdSysMutexHelper mhp(fMutex); fCounters[t] += n;
268 if (fCounters[t] < 0) fCounters[t] = 0;} }
269 int CheckCounter(int t) { int cnt = -1; if (PSMCNTOK(t)) {
270 XrdSysMutexHelper mhp(fMutex); cnt = fCounters[t];}
271 return cnt; }
272
275 int CurrentSessions(bool recalculate = 0);
276 void DisconnectFromProofServ(int pid);
277
278 std::list<XrdProofdProofServ *> *ActiveSessions() { return &fActiveSessions; }
280
281 int CleanupProofServ(bool all = 0, const char *usr = 0);
282
285 const char *sessiondir,
286 const char *extension,
287 XrdOucString &outfn);
288
289 void GetTagDirs(int opt, XrdProofdProtocol *p, XrdProofdProofServ *xps,
290 XrdOucString &sesstag, XrdOucString &topsesstag,
291 XrdOucString &sessiondir, XrdOucString &sesswrkdir);
292
293 int SetProofServEnv(XrdProofdProtocol *p, void *in);
294 int SetProofServEnvOld(XrdProofdProtocol *p, void *in);
296
298
299 inline XrdProofdPipe *Pipe() { return &fPipe; }
300
301 // Checks run periodically by the cron job
302 int DeleteFromSessions(const char *pid);
303 int MvSession(const char *fpid);
304 int CheckActiveSessions(bool verify = 1);
306 int CleanClientSessions(const char *usr, int srvtype);
309};
310
312public:
313 int fType;
316 { if (m && PSMCNTOK(t)) m->UpdateCounter(t,1); }
318};
319
321public:
322 int *fCnt;
323 XpdSrvMgrCreateGuard(int *c = 0) { Set(c); }
324 ~XpdSrvMgrCreateGuard() { if (fCnt) (*fCnt)--; }
325 void Set(int *c) { fCnt = c; if (fCnt) (*fCnt)++;}
326};
327
328#endif
ROOT::R::TRInterface & r
Definition Object.C:4
#define d(i)
Definition RSha256.hxx:102
#define c(i)
Definition RSha256.hxx:101
#define e(i)
Definition RSha256.hxx:103
#define PSMMAXCNTS
int(* XrdSecCredsSaver_t)(XrdSecCredentials *, const char *fn, const XrdProofUI &ui)
#define PSMCNTOK(t)
const char * extension
Definition civetweb.c:7793
XrdProofdClient * fClient
int operator==(const XpdClientSessions c)
std::list< XrdProofdProofServ * > fProofServs
XpdClientSessions(XrdProofdClient *c=0)
XrdOucString fGroups
XpdEnv(const char *n, const char *env, const char *usr=0, const char *grp=0, int smi=-1, int smx=-1, int vmi=-1, int vmx=-1)
int Matches(const char *usr, const char *grp, int ver=-1)
Check if this env applies to 'usr', 'grp, 'ver'.
void Print(const char *what)
Print the content of this env.
XrdOucString fName
XrdOucString fUsers
void Reset(const char *n, const char *env, const char *usr=0, const char *grp=0, int smi=-1, int smx=-1, int vmi=-1, int vmx=-1)
static int ToVersCode(int ver, bool hex=0)
Transform version number ver (format patch + 100*minor + 10000*maj, e.g.
XrdOucString fEnv
XpdSrvMgrCreateCnt(XrdProofdProofServMgr *m, int t)
XrdProofdProofServMgr * fMgr
void FillProofServ(XrdProofdProofServ &s, XrdROOTMgr *rmgr)
Fill 's' fields using the stored info.
XrdProofSessionInfo(const char *file)
int SaveToFile(const char *file)
Save content to 'file'.
void Reset()
Reset the content.
int ReadFromFile(const char *file)
Read content from 'file'.
XrdProofdProofServ * GetActiveSession(int pid)
Return active session with process ID pid, if any.
int Attach(XrdProofdProtocol *p)
Handle a request to attach to an existing session.
void UpdateCounter(int t, int n)
int Create(XrdProofdProtocol *p)
Handle a request to create a new session.
void BroadcastClusterInfo()
Broadcast cluster info to the active sessions.
XrdProofdProofServ * PrepareProofServ(XrdProofdProtocol *p, XrdProofdResponse *r, unsigned short &sid)
Allocate and prepare the XrdProofdProofServ object describing this session.
int SetUserEnvironment(XrdProofdProtocol *p)
Set user environment: set effective user and group ID of the process to the ones of the owner of this...
int Destroy(XrdProofdProtocol *p)
Handle a request to shutdown an existing session.
int CurrentSessions(bool recalculate=0)
Return the number of current sessions (top masters)
int DoDirectiveProofServMgr(char *, XrdOucStream *, bool)
Process 'proofswrvmgr' directive eg: xpd.proofswrvmgr checkfq:120 termto:100 verifyto:5 recoverto:20.
void ExtractEnv(char *, XrdOucStream *, XrdOucString &users, XrdOucString &groups, XrdOucString &rcval, XrdOucString &rcnam, int &smi, int &smx, int &vmi, int &vmx, bool &hex)
Extract env information from the stream 'cfg'.
int CheckTerminatedSessions()
Go through the terminated sessions admin path and make sure sessions they are gone.
int Detach(XrdProofdProtocol *p)
Handle a request to detach from an existing session.
int PrepareSessionRecovering()
Go through the active sessions admin path and prepare reconnection of those still alive.
int CleanupLostProofServ()
Cleanup (kill) all 'proofserv' processes which lost control from their creator or controller daemon.
int BroadcastPriorities()
Broadcast priorities to the active sessions.
int DoDirectivePutRc(char *, XrdOucStream *, bool)
Process 'putrc' directives.
int CleanupProofServ(bool all=0, const char *usr=0)
Cleanup (kill) all 'proofserv' processes from the process table.
void FillEnvList(std::list< XpdEnv > *el, const char *nam, const char *val, const char *usrs=0, const char *grps=0, int smi=-1, int smx=-1, int vmi=-1, int vmx=-1, bool hex=0)
Fill env entry(ies) in the relevant list.
int AcceptPeer(XrdProofdProofServ *xps, int to, XrdOucString &e)
Accept a callback from a starting-up server and setup the related protocol object.
void ParseCreateBuffer(XrdProofdProtocol *p, XrdProofdProofServ *xps, XrdOucString &tag, XrdOucString &ord, XrdOucString &cffile, XrdOucString &uenvs, int &intwait)
Extract relevant quantities from the buffer received during a create request.
bool IsClientRecovering(const char *usr, const char *grp, int &deadline)
Returns true (an the recovering deadline) if the client has sessions in recovering state; returns fal...
int MvSession(const char *fpid)
Move session file from the active to the terminated areas.
void FormFileNameInSessionDir(XrdProofdProtocol *p, XrdProofdProofServ *xps, const char *sessiondir, const char *extension, XrdOucString &outfn)
void DisconnectFromProofServ(int pid)
Change reconnecting status.
XrdOucHash< XrdProofdProofServ > fSessions
int SetProofServEnv(XrdProofdProtocol *p, void *in)
Set environment for proofserv.
int CreateSockPath(XrdProofdProofServ *xps, XrdProofdProtocol *p, unsigned int seq, XrdOucString &emsg)
Create the socket path for the starting session Return 0 on success, -1 on error (error message in 'e...
bool IsReconnecting()
Return true if in reconnection state, i.e.
int DoDirectiveShutdown(char *, XrdOucStream *, bool)
Process 'shutdown' directive.
XrdSecCredsSaver_t fCredsSaver
int RmSession(const char *fpid)
Remove session file from the terminated sessions area.
int SetProofServEnvOld(XrdProofdProtocol *p, void *in)
Set environment for proofserv; old version preparing the environment for proofserv protocol version <...
int CreateAdminPath(XrdProofdProofServ *xps, XrdProofdProtocol *p, int pid, XrdOucString &emsg)
Create the admin path for the starting session Return 0 on success, -1 on error (error message in 'em...
int DoDirective(XrdProofdDirective *d, char *val, XrdOucStream *cfg, bool rcf)
Update the priorities of the active sessions.
int CreateProofServEnvFile(XrdProofdProtocol *p, void *input, const char *envfn, const char *rcfn)
Create in 'rcfn' the rootrc file for the proofserv being created return 0 on success,...
std::list< XrdProofdProofServ * > fActiveSessions
int DoDirectivePutEnv(char *, XrdOucStream *, bool)
Process 'putenv' directives.
int RecoverActiveSessions()
Accept connections from sessions still alive.
int AddSession(XrdProofdProtocol *p, XrdProofdProofServ *s)
Add new active session.
std::map< XrdProofdProtocol *, int > fDestroyTimes
int CheckActiveSessions(bool verify=1)
Go through the active sessions admin path and make sure sessions are alive.
bool IsSessionSocket(const char *fpid)
Checks is fpid is the path of a session UNIX socket Returns TRUE is yes; cleans the socket if the ses...
int SetupProtocol(XrdNetPeer &peerpsrv, XrdProofdProofServ *xps, XrdOucString &e)
Setup the protocol object serving the peer described by 'peerpsrv'.
int SetUserOwnerships(XrdProofdProtocol *p, const char *ord, const char *stag)
Set user ownerships on some critical files or directories.
void GetTagDirs(int opt, XrdProofdProtocol *p, XrdProofdProofServ *xps, XrdOucString &sesstag, XrdOucString &topsesstag, XrdOucString &sessiondir, XrdOucString &sesswrkdir)
Determine the unique tag and relevant dirs for this session.
std::list< XpdClientSessions * > * fRecoverClients
void RegisterDirectives()
Register directives for configuration.
bool Alive(XrdProofdProtocol *p)
Check destroyed status.
int DeleteFromSessions(const char *pid)
Delete from the hash list the session with ID pid.
int Recover(XpdClientSessions *cl)
Handle a request to recover a session after stop&restart for a specific client.
std::list< XpdEnv > fProofServRCs
int TouchSession(const char *fpid, const char *path=0)
Update the access time for the session pid file to the current time.
void SendErrLog(const char *errlog, XrdProofdResponse *r)
Send content of errlog upstream asynchronously.
int Process(XrdProofdProtocol *p)
Process manager request.
int Config(bool rcf=0)
Run configuration and parse the entered config directives.
std::list< XrdProofdProofServ * > * ActiveSessions()
void SetReconnectTime(bool on=1)
Change reconnecting status.
int CreateProofServRootRc(XrdProofdProtocol *p, void *input, const char *rcfn)
Create in 'rcfn' the rootrc file for the proofserv being created return 0 on success,...
void ResolveKeywords(XrdOucString &s, ProofServEnv_t *in)
Resolve some keywords in 's' <logfileroot>, <user>, <rootsys>
int VerifySession(const char *fpid, int to=-1, const char *path=0)
Check if the session is alive, i.e.
int ResolveSession(const char *fpid)
Handle a request to recover a session after stop&restart.
std::list< XpdEnv > fProofServEnvs
int CleanClientSessions(const char *usr, int srvtype)
Go through the sessions admin path and clean all sessions belonging to 'usr'.
const Int_t n
Definition legend1.C:16
Definition file.py:1
static const char * what
Definition stlLoader.cc:6
XrdOucString fTopSessionTag
XrdProofdProofServ * fPS
auto * m
Definition textangle.C:8