00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_XrdProofdProofServ
00013 #define ROOT_XrdProofdProofServ
00014
00015 #include <string.h>
00016 #include <unistd.h>
00017 #include <sys/uio.h>
00018 #if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__APPLE__)
00019 #include <sched.h>
00020 #endif
00021
00022
00023
00024 #include <vector>
00025
00026 #ifdef OLDXRDOUC
00027 # include "XrdSysToOuc.h"
00028 # include "XrdOuc/XrdOucPthread.hh"
00029 # include "XrdOuc/XrdOucSemWait.hh"
00030 #else
00031 # include "XrdSys/XrdSysPthread.hh"
00032 # include "XrdSys/XrdSysSemWait.hh"
00033 #endif
00034
00035 #include "Xrd/XrdLink.hh"
00036 #include "XrdOuc/XrdOucHash.hh"
00037
00038 #include "XProofProtocol.h"
00039 #include "XrdProofdClient.h"
00040 #include "XrdProofWorker.h"
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 class XrdSrvBuffer {
00053 public:
00054 int fSize;
00055 char *fBuff;
00056
00057 XrdSrvBuffer(char *bp=0, int sz=0, bool dup=0) {
00058 if (dup && bp && sz > 0) {
00059 fMembuf = (char *)malloc(sz);
00060 if (fMembuf) {
00061 memcpy(fMembuf, bp, sz);
00062 fBuff = fMembuf;
00063 fSize = sz;
00064 }
00065 } else {
00066 fBuff = fMembuf = bp;
00067 fSize = sz;
00068 }}
00069 ~XrdSrvBuffer() {if (fMembuf) free(fMembuf);}
00070
00071 private:
00072 char *fMembuf;
00073 };
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 class XrdProofQuery
00084 {
00085 XrdOucString fTag;
00086 XrdOucString fDSName;
00087 long fDSSize;
00088 public:
00089 XrdProofQuery(const char *t, const char *n = "", long s = 0) : fTag(t), fDSName(n), fDSSize(s) { }
00090
00091 const char *GetTag() { return fTag.c_str(); }
00092 const char *GetDSName() { return fDSName.c_str(); }
00093 long GetDSSize() { return fDSSize; }
00094 };
00095
00096
00097 class XrdROOT;
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 #define kXPROOFSRVTAGMAX 64
00109 #define kXPROOFSRVALIASMAX 256
00110
00111 class XrdProofGroup;
00112 class XrdSysSemWait;
00113
00114 class XrdProofdProofServ
00115 {
00116
00117 public:
00118 XrdProofdProofServ();
00119 ~XrdProofdProofServ();
00120
00121 void AddWorker(const char *o, XrdProofWorker *w);
00122 inline const char *AdminPath() const { XrdSysMutexHelper mhp(fMutex); return fAdminPath.c_str(); }
00123 inline const char *Alias() const { XrdSysMutexHelper mhp(fMutex); return fAlias.c_str(); }
00124 void Broadcast(const char *msg, int type = kXPD_srvmsg);
00125 int BroadcastPriority(int priority);
00126 inline const char *Client() const { XrdSysMutexHelper mhp(fMutex); return fClient.c_str(); }
00127 int CheckSession(bool oldvers, bool isrec,
00128 int shutopt, int shutdel, bool changeown, int &nc);
00129 XrdProofQuery *CurrentQuery() { XrdSysMutexHelper mhp(fMutex); return (fQueries.empty()? 0 : fQueries.front()); }
00130 void DeleteStartMsg()
00131 { XrdSysMutexHelper mhp(fMutex); if (fStartMsg) delete fStartMsg; fStartMsg = 0;}
00132 int DisconnectTime();
00133 void DumpQueries();
00134 int Enqueue(XrdProofQuery *q) { XrdSysMutexHelper mhp(fMutex);
00135 if (q) { fQueries.push_back(q); }; return fQueries.size(); }
00136 void ExportBuf(XrdOucString &buf);
00137 void ExportWorkers(XrdOucString &wrks);
00138 inline const char *Fileout() const { XrdSysMutexHelper mhp(fMutex); return fFileout.c_str(); }
00139 int FreeClientID(int pid);
00140 XrdClientID *GetClientID(int cid);
00141 int GetNClients(bool check);
00142 XrdProofQuery *GetQuery(const char *tag);
00143 inline const char *Group() const { XrdSysMutexHelper mhp(fMutex); return fGroup.c_str(); }
00144 int IdleTime();
00145 inline short int ID() const { XrdSysMutexHelper mhp(fMutex); return fID; }
00146 inline bool IsShutdown() const { XrdSysMutexHelper mhp(fMutex); return fIsShutdown; }
00147 inline bool IsValid() const { XrdSysMutexHelper mhp(fMutex); return fIsValid; }
00148 inline bool Match(short int id) const { XrdSysMutexHelper mhp(fMutex); return (id == fID); }
00149 inline const char *Ordinal() const { XrdSysMutexHelper mhp(fMutex); return fOrdinal.c_str(); }
00150 inline XrdClientID *Parent() const { XrdSysMutexHelper mhp(fMutex); return fParent; }
00151 inline void PingSem() const { XrdSysMutexHelper mhp(fMutex); if (fPingSem) fPingSem->Post(); }
00152 inline XrdProofdProtocol *Protocol() const { XrdSysMutexHelper mhp(fMutex); return fProtocol; }
00153 inline std::list<XrdProofQuery *> *Queries() const
00154 { return (std::list<XrdProofQuery *> *)&fQueries; }
00155 void RemoveQuery(const char *tag);
00156 void RemoveWorker(const char *o);
00157 void Reset();
00158 int Reset(const char *msg, int type);
00159 int Resume();
00160
00161 inline XrdROOT *ROOT() const { XrdSysMutexHelper mhp(fMutex); return fROOT; }
00162 inline XrdProofdResponse *Response() const { XrdSysMutexHelper mhp(fMutex); return fResponse; }
00163 int SendData(int cid, void *buff, int len);
00164 int SendDataN(void *buff, int len);
00165 void SendClusterInfo(int nsess, int nacti);
00166 int SetAdminPath(const char *a, bool assert);
00167 void SetAlias(const char *a) { XrdSysMutexHelper mhp(fMutex); fAlias = a; }
00168 void SetClient(const char *c) { XrdSysMutexHelper mhp(fMutex); fClient = c; }
00169 inline void SetConnection(XrdProofdResponse *r) { XrdSysMutexHelper mhp(fMutex); fResponse = r;}
00170
00171 void SetFileout(const char *f) { XrdSysMutexHelper mhp(fMutex); fFileout = f; }
00172 inline void SetGroup(const char *g) { XrdSysMutexHelper mhp(fMutex); fGroup = g; }
00173 void SetIdle();
00174 inline void SetID(short int id) { XrdSysMutexHelper mhp(fMutex); fID = id;}
00175 void SetOrdinal(const char *o) { XrdSysMutexHelper mhp(fMutex); fOrdinal = o; }
00176 inline void SetParent(XrdClientID *cid) { XrdSysMutexHelper mhp(fMutex); fParent = cid; }
00177 inline void SetProtocol(XrdProofdProtocol *p) { XrdSysMutexHelper mhp(fMutex); fProtocol = p; }
00178 inline void SetProtVer(int pv) { XrdSysMutexHelper mhp(fMutex); fProtVer = pv; }
00179 inline void SetROOT(XrdROOT *r) { XrdSysMutexHelper mhp(fMutex); fROOT = r; }
00180 void SetRunning();
00181 inline void SetShutdown() { XrdSysMutexHelper mhp(fMutex); fIsShutdown = true; }
00182 inline void SetSkipCheck() { XrdSysMutexHelper mhp(fMutex); fSkipCheck = true; }
00183 void SetSrvPID(int pid) { XrdSysMutexHelper mhp(fMutex); fSrvPID = pid; }
00184 inline void SetSrvType(int id) { XrdSysMutexHelper mhp(fMutex); fSrvType = id; }
00185 inline void SetStartMsg(XrdSrvBuffer *sm) { XrdSysMutexHelper mhp(fMutex); delete fStartMsg; fStartMsg = sm; }
00186 inline void SetStatus(int st) { XrdSysMutexHelper mhp(fMutex); fStatus = st; }
00187 void SetTag(const char *t) { XrdSysMutexHelper mhp(fMutex); fTag = t; }
00188 void SetUNIXSockPath(const char *s) { XrdSysMutexHelper mhp(fMutex); fUNIXSockPath = s; };
00189 void SetUserEnvs(const char *t) { XrdSysMutexHelper mhp(fMutex); fUserEnvs = t; }
00190 inline void SetValid(bool valid = 1) { XrdSysMutexHelper mhp(fMutex); fIsValid = valid; }
00191 bool SkipCheck();
00192 inline int SrvPID() const { XrdSysMutexHelper mhp(fMutex); return fSrvPID; }
00193 inline int SrvType() const { XrdSysMutexHelper mhp(fMutex); return fSrvType; }
00194 inline XrdSrvBuffer *StartMsg() const { XrdSysMutexHelper mhp(fMutex); return fStartMsg; }
00195 inline int Status() const { XrdSysMutexHelper mhp(fMutex); return fStatus;}
00196 inline const char *Tag() const { XrdSysMutexHelper mhp(fMutex); return fTag.c_str(); }
00197 int TerminateProofServ(bool changeown);
00198 inline const char *UserEnvs() const { XrdSysMutexHelper mhp(fMutex); return fUserEnvs.c_str(); }
00199 int VerifyProofServ(bool fw);
00200 inline XrdOucHash<XrdProofWorker> *Workers() const
00201 { XrdSysMutexHelper mhp(fMutex); return (XrdOucHash<XrdProofWorker> *)&fWorkers; }
00202
00203
00204 int CreateUNIXSock(XrdSysError *edest);
00205 void DeleteUNIXSock();
00206 XrdNet *UNIXSock() const { return fUNIXSock; }
00207 const char *UNIXSockPath() const { return fUNIXSockPath.c_str(); }
00208
00209 private:
00210
00211 XrdSysRecMutex *fMutex;
00212 XrdProofdProtocol *fProtocol;
00213 XrdProofdResponse *fResponse;
00214
00215 XrdClientID *fParent;
00216 int fNClients;
00217 std::vector<XrdClientID *> fClients;
00218 XrdOucHash<XrdProofWorker> fWorkers;
00219
00220 XrdSysSemWait *fPingSem;
00221
00222 XrdSrvBuffer *fStartMsg;
00223
00224 time_t fDisconnectTime;
00225 time_t fSetIdleTime;
00226
00227 int fStatus;
00228 int fSrvPID;
00229 int fSrvType;
00230 short int fID;
00231 char fProtVer;
00232 XrdOucString fFileout;
00233
00234 XrdNet *fUNIXSock;
00235 XrdOucString fUNIXSockPath;
00236
00237 bool fIsShutdown;
00238 bool fIsValid;
00239 bool fSkipCheck;
00240
00241 XrdOucString fAlias;
00242 XrdOucString fClient;
00243 XrdOucString fTag;
00244 XrdOucString fOrdinal;
00245 XrdOucString fUserEnvs;
00246 XrdOucString fAdminPath;
00247
00248 XrdROOT *fROOT;
00249
00250 XrdOucString fGroup;
00251
00252 void ClearWorkers();
00253
00254 void CreatePingSem()
00255 { XrdSysMutexHelper mhp(fMutex); fPingSem = new XrdSysSemWait(0);}
00256 void DeletePingSem()
00257 { XrdSysMutexHelper mhp(fMutex); if (fPingSem) delete fPingSem; fPingSem = 0;}
00258 std::list<XrdProofQuery *> fQueries;
00259 };
00260 #endif