No Matches
Go to the documentation of this file.
1#ifndef __CMS_NODE__H
2#define __CMS_NODE__H
4/* */
5/* X r d C m s N o d e . h h */
6/* */
7/* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */
8/* All Rights Reserved */
9/* Produced by Andrew Hanushevsky for Stanford University under contract */
10/* DE-AC02-76-SFO0515 with the Department of Energy */
11/* */
12/* This file is part of the XRootD software suite. */
13/* */
14/* XRootD is free software: you can redistribute it and/or modify it under */
15/* the terms of the GNU Lesser General Public License as published by the */
16/* Free Software Foundation, either version 3 of the License, or (at your */
17/* option) any later version. */
18/* */
19/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22/* License for more details. */
23/* */
24/* You should have received a copy of the GNU Lesser General Public License */
25/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27/* */
28/* The copyright holder's institutional names and contributor's names may not */
29/* be used to endorse or promote products derived from this software without */
30/* specific prior written permission of the institution or contributor. */
33#include <cstring>
34#include <unistd.h>
35#include <netinet/in.h>
36#include <sys/uio.h>
38#include "Xrd/XrdLink.hh"
39#include "XrdCms/XrdCmsTypes.hh"
40#include "XrdCms/XrdCmsRRQ.hh"
41#include "XrdNet/XrdNetIF.hh"
42#include "XrdNet/XrdNetAddr.hh"
46class XrdCmsBaseFR;
47class XrdCmsBaseFS;
48class XrdCmsClustID;
49class XrdCmsDrop;
50class XrdCmsManager;
51class XrdCmsPrepArgs;
52class XrdCmsRRData;
53class XrdCmsSelect;
54class XrdCmsSelected;
55class XrdOucProg;
59friend class XrdCmsCluster;
61 char *Ident = 0; // -> role hostname
62 char hasNet = 0; //0 Network selection mask
63 char isBad = 0; //1 Set on an event that makes it unselectable
64 char isOffline; //2 Set when a link failure occurs (constructor)
65 char isRW = 0; //3 Set when node can write or stage data
66 char isNoStage = 0; //4 Set upon a nostage event
67 char isMan = 0; //5 Set when node acts as manager
68 char isPeer = 0; //6 Set when node acts as peer manager
69 char isBound = 0; //7 Set when node is in the configuration
70 char isKnown = 0; //0 Set when we have recieved a "state"
71 char isConn = 0; //1 Set when node is network connected
72 char isGone = 0; //2 Set when node must be deleted
73 char isPerm = 0; //3 Set when node is permanently bound
74 char rsvd = 0; //4 Reserved
75 char RoleID = 0; //5 The converted XrdCmsRole::RoleID
76 char TimeZone = 0; //6 Time zone in +UTC-
77 char TZValid = 0; //7 Time zone has been set
79static const char isBlisted = 0x01; // in isBad -> Node is black listed
80static const char isDisabled = 0x02; // in isBad -> Node is disable (internal)
81static const char isSuspend = 0x04; // in isBad -> Node is suspended via event
82static const char isDoomed = 0x08; // in isBad -> Node socket must be closed
84static const char allowsRW = 0x01; // in isRW -> Server allows r/w access
85static const char allowsSS = 0x02; // in isRW -> Server can stage data
87unsigned int DiskTotal = 0;// Total disk space in GB
88 int DiskNums = 0;// Number of file systems
89 int DiskMinF = 0;// Minimum MB needed for selection
90 int DiskFree = 0;// Largest free MB
91 int DiskUtil = 0;// Total disk utilization
92unsigned int ConfigID = 0;// Configuration identifier
94const char *do_Avail(XrdCmsRRData &Arg);
95const char *do_Chmod(XrdCmsRRData &Arg);
96const char *do_Disc(XrdCmsRRData &Arg);
97const char *do_Gone(XrdCmsRRData &Arg);
98const char *do_Have(XrdCmsRRData &Arg);
99const char *do_Load(XrdCmsRRData &Arg);
100const char *do_Locate(XrdCmsRRData &Arg);
101static int do_LocFmt(char *buff, XrdCmsSelected *sP,
102 SMask_t pf, SMask_t wf,
103 bool lsall=false, bool lsuniq=false);
104const char *do_Mkdir(XrdCmsRRData &Arg);
105const char *do_Mkpath(XrdCmsRRData &Arg);
106const char *do_Mv(XrdCmsRRData &Arg);
107const char *do_Ping(XrdCmsRRData &Arg);
108const char *do_Pong(XrdCmsRRData &Arg);
109const char *do_PrepAdd(XrdCmsRRData &Arg);
110const char *do_PrepDel(XrdCmsRRData &Arg);
111const char *do_Rm(XrdCmsRRData &Arg);
112const char *do_Rmdir(XrdCmsRRData &Arg);
114 char *Avoid, bool &doRedir);
115const char *do_Select(XrdCmsRRData &Arg);
116static int do_SelPrep(XrdCmsPrepArgs &Arg);
117const char *do_Space(XrdCmsRRData &Arg);
118const char *do_State(XrdCmsRRData &Arg);
119static void do_StateDFS(XrdCmsBaseFR *rP, int rc);
121const char *do_StatFS(XrdCmsRRData &Arg);
122const char *do_Stats(XrdCmsRRData &Arg);
123const char *do_Status(XrdCmsRRData &Arg);
124const char *do_Trunc(XrdCmsRRData &Arg);
125const char *do_Try(XrdCmsRRData &Arg);
126const char *do_Update(XrdCmsRRData &Arg);
127const char *do_Usage(XrdCmsRRData &Arg);
129 void Delete(XrdSysRWLock &gMutex)
130 {XrdSysFusedMutex gMeld(gMutex); Delete(gMeld);}
132 void Delete(XrdSysMutex &gMutex)
133 {XrdSysFusedMutex gMeld(gMutex); Delete(gMeld);}
137 void Disc(const char *reason=0, int needLock=1);
139inline int ID(int &INum) {INum = Instance; return NodeID;}
141inline int Inst() {return Instance;}
143 bool inDomain() {return netIF.InDomain(&netID);}
145inline int isNode(SMask_t smask) {return (smask & NodeMask) != 0;}
147inline int isNode(const XrdNetAddr *addr) // Only for avoid processing!
148 {return netID.Same(addr);}
150inline int isNode(XrdLink *lp, const char *nid, int port)
151 {if (nid)
152 {if (strcmp(myNID, nid)) return 0;
153 if (*nid == '*') return 1;
154 }
155 return netID.Same(lp->NetAddr()) && port == netIF.Port();
156 }
158inline char *Name() {return (myName ? myName : (char *)"?");}
160inline SMask_t Mask() {return NodeMask;}
162inline void g2nLock(XrdSysRWLock &gMutex)
163 {refCnt++; // Keep node alive during transition
164 gMutex.UnLock(); // The lock must have ben held
165 nodeMutex.Lock(); // Downgrade to node lock
166 }
168inline void n2gLock(XrdSysRWLock &gMutex, bool rdlock=false)
169 {nodeMutex.UnLock(); // Release this node
170 refCnt--; // OK for node to go away
171 if (rdlock) gMutex.ReadLock();
172 else gMutex.WriteLock();
173 }
175inline void Lock() {refCnt++; nodeMutex.Lock();}
177inline void UnLock() {nodeMutex.UnLock(); refCnt--;}
179inline void Ref() {refCnt++;} // Must have global or node locked!
180inline void unRef() {refCnt--;}
182static void Report_Usage(XrdLink *lp);
184inline int Send(const char *buff, int blen=0)
185 {return (isOffline ? -1 : Link->Send(buff, blen));}
186inline int Send(const struct iovec *iov, int iovcnt, int iotot=0)
187 {return (isOffline ? -1 : Link->Send(iov, iovcnt, iotot));}
191 void setName(XrdLink *lnkp, const char *theIF, int port);
193 void setShare(int shrval)
194 {if (shrval > 99) Shrem = Shrip = Share = 0;
195 else {Shrem = Share = shrval; Shrip = 100 - shrval;}
196 }
198 int setTZone(int tZone)
199 {TimeZone = tZone & 0x0f;
200 if (tZone & 0x10) TimeZone = -TimeZone;
201 TZValid = (tZone != 0);
202 return TimeZone;
203 }
205 void setVersion(unsigned short vnum) {myVersion = vnum;}
207inline void setSlot(short rslot) {RSlot = rslot;}
208inline short getSlot() {return RSlot;}
210inline void ShowIF() {netIF.Display("=====> ");}
212 void SyncSpace();
214 XrdCmsNode(XrdLink *lnkp, const char *theIF=0, const char *sid=0,
215 int port=0, int lvl=0, int id=-1);
219static const int fsL2PFail1 = 999991;
220static const int fsL2PFail2 = 999992;
222 void DeleteWarn(unsigned int lkVal);
223 int fsExec(XrdOucProg *Prog, char *Arg1, char *Arg2=0);
224const char *fsFail(const char *Who, const char *What, const char *Path, int rc);
225 int getMode(const char *theMode, mode_t &Mode);
226 int getSize(const char *theSize, long long &Size);
227 void setHash(XrdCmsSelect &Sel, int acount);
230RAtomic_uint refCnt{0}; // Tracks references to this onnject
232XrdLink *Link; // Constructor
233XrdNetAddr netID; // Constructor
234XrdNetIF netIF; // Constructor
236time_t DropTime = 0;
237XrdCmsDrop *DropJob = 0;
244short subsPort = 0; // Subscription port number
245unsigned short myVersion; // Constructor
246char *myCID; // Constructor
247char *myNID; // Constructor
248char *myName = 0;
249int myNlen = 0;
252int myCost = 0; // Overall cost (determined by location)
253int myLoad = 0; // Overall load
254int myMass = 0; // Overall load including space utilization
255RAtomic_int RefW{0}; // Number of times used for writing
256RAtomic_int RefTotW{0}; // Actual total w/o share adjustments
257RAtomic_int RefR{0}; // Number of times used for redirection
258RAtomic_int RefTotR{0}; // Actual total w/o share adjustments
259short RSlot = 0;
260char Share = 0; // Share of requests for this node (0 -> n/a)
261RAtomic_char Shrem{0}; // Share of requests left
262RAtomic_char Shrin{0}; // Share intervals used
263char Shrip = 0; // Share of requests to skip (set once)
264char Rsvd[3];
266// The following fields are used to keep the supervisor's free space value
269static int LastFree;
unsigned long long SMask_t
Definition XrdCmsTypes.hh:33
Definition XrdCmsBaseFS.hh:49
Definition XrdCmsBaseFS.hh:88
Definition XrdCmsClustID.hh:41
Definition XrdCmsCluster.hh:115
Definition XrdCmsManager.hh:56
Definition XrdCmsNode.hh:58
char * myNID
Definition XrdCmsNode.hh:247
const char * do_PrepDel(XrdCmsRRData &Arg)
char isPerm
Definition XrdCmsNode.hh:73
void setManager(XrdCmsManager *mP)
Definition XrdCmsNode.hh:189
static int do_SelPrep(XrdCmsPrepArgs &Arg)
int do_StateFWD(XrdCmsRRData &Arg)
const char * do_Gone(XrdCmsRRData &Arg)
const char * do_Locate(XrdCmsRRData &Arg)
XrdNetIF netIF
Definition XrdCmsNode.hh:234
XrdSysMutex nodeMutex
Definition XrdCmsNode.hh:229
int DiskMinF
Definition XrdCmsNode.hh:89
int DiskFree
Definition XrdCmsNode.hh:90
const char * do_Update(XrdCmsRRData &Arg)
static const char allowsRW
Definition XrdCmsNode.hh:84
const char * do_Try(XrdCmsRRData &Arg)
char * Ident
Definition XrdCmsNode.hh:61
const char * fsFail(const char *Who, const char *What, const char *Path, int rc)
int Instance
Definition XrdCmsNode.hh:242
const char * do_State(XrdCmsRRData &Arg)
void setShare(int shrval)
Definition XrdCmsNode.hh:193
int isNode(XrdLink *lp, const char *nid, int port)
Definition XrdCmsNode.hh:150
int DiskNums
Definition XrdCmsNode.hh:88
void Ref()
Definition XrdCmsNode.hh:179
char isKnown
Definition XrdCmsNode.hh:70
unsigned int ConfigID
Definition XrdCmsNode.hh:92
int myLoad
Definition XrdCmsNode.hh:253
char isConn
Definition XrdCmsNode.hh:71
XrdCmsDrop * DropJob
Definition XrdCmsNode.hh:237
char TZValid
Definition XrdCmsNode.hh:77
void Delete(XrdSysRWLock &gMutex)
Definition XrdCmsNode.hh:129
void n2gLock(XrdSysRWLock &gMutex, bool rdlock=false)
Definition XrdCmsNode.hh:168
const char * do_Space(XrdCmsRRData &Arg)
RAtomic_int RefTotR
Definition XrdCmsNode.hh:258
int Send(const char *buff, int blen=0)
Definition XrdCmsNode.hh:184
static const char allowsSS
Definition XrdCmsNode.hh:85
char isGone
Definition XrdCmsNode.hh:72
int DiskUtil
Definition XrdCmsNode.hh:91
int do_SelAvoid(XrdCmsRRData &Arg, XrdCmsSelect &Sel, char *Avoid, bool &doRedir)
void unRef()
Definition XrdCmsNode.hh:180
RAtomic_int RefTotW
Definition XrdCmsNode.hh:256
const char * do_Select(XrdCmsRRData &Arg)
const char * do_Mv(XrdCmsRRData &Arg)
const char * do_Trunc(XrdCmsRRData &Arg)
int setTZone(int tZone)
Definition XrdCmsNode.hh:198
const char * do_Usage(XrdCmsRRData &Arg)
time_t DropTime
Definition XrdCmsNode.hh:236
RAtomic_int RefR
Definition XrdCmsNode.hh:257
void DeleteWarn(unsigned int lkVal)
char Share
Definition XrdCmsNode.hh:260
int Inst()
Definition XrdCmsNode.hh:141
const char * do_Chmod(XrdCmsRRData &Arg)
unsigned short myVersion
Definition XrdCmsNode.hh:245
char TimeZone
Definition XrdCmsNode.hh:76
char isPeer
Definition XrdCmsNode.hh:68
void SyncSpace()
void setVersion(unsigned short vnum)
Definition XrdCmsNode.hh:205
short subsPort
Definition XrdCmsNode.hh:244
short RSlot
Definition XrdCmsNode.hh:259
char Rsvd[3]
Definition XrdCmsNode.hh:264
void Lock()
Definition XrdCmsNode.hh:175
int isNode(const XrdNetAddr *addr)
Definition XrdCmsNode.hh:147
static const char isDisabled
Definition XrdCmsNode.hh:80
char RoleID
Definition XrdCmsNode.hh:75
const char * do_Load(XrdCmsRRData &Arg)
int myNlen
Definition XrdCmsNode.hh:249
int isNode(SMask_t smask)
Definition XrdCmsNode.hh:145
SMask_t Mask()
Definition XrdCmsNode.hh:160
int Send(const struct iovec *iov, int iovcnt, int iotot=0)
Definition XrdCmsNode.hh:186
int getSize(const char *theSize, long long &Size)
char * Name()
Definition XrdCmsNode.hh:158
RAtomic_uint refCnt
Definition XrdCmsNode.hh:230
RAtomic_int RefW
Definition XrdCmsNode.hh:255
char isBad
Definition XrdCmsNode.hh:63
const char * do_Rm(XrdCmsRRData &Arg)
char isOffline
Definition XrdCmsNode.hh:64
const char * do_PrepAdd(XrdCmsRRData &Arg)
char * myCID
Definition XrdCmsNode.hh:246
void g2nLock(XrdSysRWLock &gMutex)
Definition XrdCmsNode.hh:162
static void Report_Usage(XrdLink *lp)
const char * do_Ping(XrdCmsRRData &Arg)
const char * do_Have(XrdCmsRRData &Arg)
static void do_StateDFS(XrdCmsBaseFR *rP, int rc)
static const char isSuspend
Definition XrdCmsNode.hh:81
const char * do_Stats(XrdCmsRRData &Arg)
XrdCmsClustID * cidP
Definition XrdCmsNode.hh:239
const char * do_Disc(XrdCmsRRData &Arg)
const char * do_Avail(XrdCmsRRData &Arg)
unsigned int DiskTotal
Definition XrdCmsNode.hh:87
int ID(int &INum)
Definition XrdCmsNode.hh:139
int myMass
Definition XrdCmsNode.hh:254
static XrdSysMutex mlMutex
Definition XrdCmsNode.hh:268
char * myName
Definition XrdCmsNode.hh:248
char isNoStage
Definition XrdCmsNode.hh:66
void Disc(const char *reason=0, int needLock=1)
char Shrip
Definition XrdCmsNode.hh:263
int getMode(const char *theMode, mode_t &Mode)
const char * do_Mkpath(XrdCmsRRData &Arg)
int logload
Definition XrdCmsNode.hh:251
char isMan
Definition XrdCmsNode.hh:67
int myCost
Definition XrdCmsNode.hh:252
void setSlot(short rslot)
Definition XrdCmsNode.hh:207
XrdCmsNode(XrdLink *lnkp, const char *theIF=0, const char *sid=0, int port=0, int lvl=0, int id=-1)
void UnLock()
Definition XrdCmsNode.hh:177
const char * do_Pong(XrdCmsRRData &Arg)
XrdNetAddr netID
Definition XrdCmsNode.hh:233
void ShowIF()
Definition XrdCmsNode.hh:210
RAtomic_char Shrem
Definition XrdCmsNode.hh:261
static int do_LocFmt(char *buff, XrdCmsSelected *sP, SMask_t pf, SMask_t wf, bool lsall=false, bool lsuniq=false)
void setName(XrdLink *lnkp, const char *theIF, int port)
const char * do_Mkdir(XrdCmsRRData &Arg)
int myLevel
Definition XrdCmsNode.hh:243
static const int fsL2PFail1
Definition XrdCmsNode.hh:219
int fsExec(XrdOucProg *Prog, char *Arg1, char *Arg2=0)
XrdCmsManager * Manager
Definition XrdCmsNode.hh:235
const char * do_StatFS(XrdCmsRRData &Arg)
char isBound
Definition XrdCmsNode.hh:69
const char * do_Rmdir(XrdCmsRRData &Arg)
void Delete(XrdSysFusedMutex &gMutex)
static const char isDoomed
Definition XrdCmsNode.hh:82
int NodeID
Definition XrdCmsNode.hh:241
void setHash(XrdCmsSelect &Sel, int acount)
char rsvd
Definition XrdCmsNode.hh:74
bool inDomain()
Definition XrdCmsNode.hh:143
static const int fsL2PFail2
Definition XrdCmsNode.hh:220
short getSlot()
Definition XrdCmsNode.hh:208
void Delete(XrdSysMutex &gMutex)
Definition XrdCmsNode.hh:132
XrdLink * Link
Definition XrdCmsNode.hh:232
static const char isBlisted
Definition XrdCmsNode.hh:79
char isRW
Definition XrdCmsNode.hh:65
const char * do_Status(XrdCmsRRData &Arg)
SMask_t NodeMask
Definition XrdCmsNode.hh:240
RAtomic_char Shrin
Definition XrdCmsNode.hh:262
static int LastFree
Definition XrdCmsNode.hh:269
char hasNet
Definition XrdCmsNode.hh:62
Definition XrdCmsPrepArgs.hh:41
Definition XrdCmsRRData.hh:52
Definition XrdCmsSelect.hh:44
Definition XrdCmsSelect.hh:105
int Same(const XrdNetAddrInfo *ipAddr, bool plusPort=false)
Definition XrdNetAddr.hh:42
Definition XrdNetIF.hh:49
void Display(const char *pfx="=====> ")
int Port()
Definition XrdNetIF.hh:276
static bool InDomain(XrdNetAddrInfo *epaddr)
Definition XrdOucProg.hh:38
Definition XrdSysPthread.hh:434
Definition XrdSysPthread.hh:165
void Lock()
Definition XrdSysPthread.hh:222
void UnLock()
Definition XrdSysPthread.hh:224
Definition XrdSysPthread.hh:330
void ReadLock()
Definition XrdSysPthread.hh:342
void WriteLock()
Definition XrdSysPthread.hh:343
void UnLock()
Definition XrdSysPthread.hh:348
Definition XrdOucIOVec.hh:65