00001 #ifndef __CMS_CLUSTER__H
00002 #define __CMS_CLUSTER__H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include <strings.h>
00036 #include <netinet/in.h>
00037
00038 #include "XrdCms/XrdCmsTypes.hh"
00039 #include "XrdOuc/XrdOucTList.hh"
00040 #include "XrdOuc/XrdOucEnum.hh"
00041 #include "XrdSys/XrdSysPthread.hh"
00042
00043 class XrdLink;
00044 class XrdCmsDrop;
00045 class XrdCmsNode;
00046 class XrdCmsSelect;
00047 class XrdCmsSelector;
00048 class XrdNetAddr;
00049
00050 namespace XrdCms
00051 {
00052 struct CmsRRHdr;
00053 }
00054
00055
00056
00057
00058
00059 namespace XrdCms
00060 {
00061
00062
00063
00064 static const int CMS_noStage = 1;
00065 static const int CMS_Suspend = 2;
00066 static const int CMS_Perm = 4;
00067 static const int CMS_isMan = 8;
00068 static const int CMS_Lost = 16;
00069 static const int CMS_isPeer = 32;
00070 static const int CMS_isProxy = 64;
00071 static const int CMS_noSpace =128;
00072 static const int CMS_isSuper =256;
00073
00074 static const int CMS_isVers3 =0x01000000;
00075
00076 static const int CMS_notServ =CMS_isMan|CMS_isPeer|CMS_isSuper;
00077 static const int CMS_hasAlts =CMS_isMan|CMS_isPeer;
00078
00079
00080
00081 class SpaceData
00082 {
00083 public:
00084
00085 long long Total;
00086 long long TotFr;
00087 int wMinF;
00088 int wFree;
00089 int wNum;
00090 int wUtil;
00091 int sFree;
00092 int sNum;
00093 int sUtil;
00094
00095 SpaceData() : Total(0), TotFr(0),wMinF(0),
00096 wFree(0), wNum(0), wUtil(0),
00097 sFree(0), sNum(0), sUtil(0) {}
00098 ~SpaceData() {}
00099 };
00100 }
00101
00102
00103
00104
00105
00106
00107
00108 class XrdCmsBaseFR;
00109 class XrdCmsClustID;
00110 class XrdCmsSelected;
00111 class XrdOucTList;
00112
00113 class XrdCmsCluster
00114 {
00115 public:
00116 friend class XrdCmsDrop;
00117
00118 int NodeCnt;
00119
00120
00121
00122 XrdCmsNode *Add(XrdLink *lp, int dport, int Status,
00123 int sport, const char *theNID, const char *theIF);
00124
00125
00126
00127 virtual void BlackList(XrdOucTList *blP);
00128
00129
00130
00131 SMask_t Broadcast(SMask_t, const struct iovec *, int, int tot=0);
00132
00133 SMask_t Broadcast(SMask_t smask, XrdCms::CmsRRHdr &Hdr,
00134 char *Data, int Dlen=0);
00135
00136 SMask_t Broadcast(SMask_t smask, XrdCms::CmsRRHdr &Hdr,
00137 void *Data, int Dlen);
00138
00139
00140
00141 int Broadsend(SMask_t smask, XrdCms::CmsRRHdr &Hdr,
00142 void *Data, int Dlen);
00143
00144
00145
00146 SMask_t getMask(const XrdNetAddr *addr);
00147
00148
00149
00150 SMask_t getMask(const char *Cid);
00151
00152
00153
00154 enum CmsLSOpts {LS_NULL=0, LS_IPO=0x0100, LS_IDNT=0x0200,
00155 LS_ANY =0x0400, LS_IFMASK = 0x0f};
00156
00157 XrdCmsSelected *List(SMask_t mask, CmsLSOpts opts, bool &oksel);
00158
00159
00160
00161 int Locate(XrdCmsSelect &Sel);
00162
00163
00164
00165 void *MonPerf();
00166
00167
00168
00169 void *MonRefs();
00170
00171
00172
00173 long long Refs() {return SelWcnt+SelWtot+SelRcnt+SelRtot;}
00174
00175
00176
00177 void Remove(XrdCmsNode *theNode);
00178
00179 void Remove(const char *reason, XrdCmsNode *theNode, int immed=0);
00180
00181
00182
00183 void ResetRef(SMask_t smask, bool isLocked=false);
00184
00185
00186
00187 static const int NotFound = -1;
00188 static const int Wait4CBk = -2;
00189 static const int RetryErr = -3;
00190 static const int EReplete = -4;
00191
00192 int Select(XrdCmsSelect &Sel);
00193
00194 int Select(SMask_t pmask, int &port, char *hbuff, int &hlen,
00195 int isrw, int isMulti, int ifWant);
00196
00197
00198
00199 void SLock(bool dolock)
00200 {if (dolock) STMutex.Lock();
00201 else STMutex.UnLock();
00202 }
00203
00204
00205
00206 void Space(XrdCms::SpaceData &sData, SMask_t smask);
00207
00208
00209
00210 int Stats(char *bfr, int bln);
00211 int Statt(char *bfr, int bln);
00212
00213 XrdCmsCluster();
00214 virtual ~XrdCmsCluster() {}
00215
00216 private:
00217 XrdCmsNode *AddAlt(XrdCmsClustID *cidP, XrdLink *lp, int port, int Status,
00218 int sport, const char *theNID, const char *theIF);
00219 XrdCmsNode *calcDelay(XrdCmsSelector &selR);
00220 int Drop(int sent, int sinst, XrdCmsDrop *djp=0);
00221 void Record(char *path, const char *reason, bool force=false);
00222 bool maxBits(SMask_t mVec, int mbits);
00223 int Multiple(SMask_t mVec);
00224 enum {eExists, eDups, eROfs, eNoRep, eNoSel, eNoEnt};
00225 int SelFail(XrdCmsSelect &Sel, int rc);
00226 int SelNode(XrdCmsSelect &Sel, SMask_t pmask, SMask_t amask);
00227 XrdCmsNode *SelbyCost(SMask_t, XrdCmsSelector &selR);
00228 XrdCmsNode *SelbyLoad(SMask_t, XrdCmsSelector &selR);
00229 XrdCmsNode *SelbyRef (SMask_t, XrdCmsSelector &selR);
00230 int SelDFS(XrdCmsSelect &Sel, SMask_t amask,
00231 SMask_t &pmask, SMask_t &smask, int isRW);
00232 void sendAList(XrdLink *lp);
00233 void setAltMan(int snum, XrdLink *lp, int port);
00234 int Unreachable(XrdCmsSelect &Sel, bool none);
00235 int Unuseable(XrdCmsSelect &Sel);
00236
00237
00238
00239 static const int AltSize = 254;
00240
00241 XrdSysMutex XXMutex;
00242 XrdSysMutex STMutex;
00243 XrdCmsNode *NodeTab[STMax];
00244
00245 int STHi;
00246 int Reserved;
00247 long long SelWcnt;
00248 long long SelWtot;
00249 long long SelRcnt;
00250 long long SelRtot;
00251 long long SelTcnt;
00252
00253
00254
00255
00256
00257 char AltMans[STMax*AltSize];
00258 char *AltMend;
00259 int AltMent;
00260
00261
00262
00263 SMask_t peerHost;
00264 SMask_t peerMask;
00265 };
00266
00267 XRDOUC_ENUM_OPERATORS(XrdCmsCluster::CmsLSOpts)
00268
00269 namespace XrdCms
00270 {
00271 extern XrdCmsCluster Cluster;
00272 }
00273 #endif