xrootd
XrdCmsNode.hh
Go to the documentation of this file.
1 #ifndef __CMS_NODE__H
2 #define __CMS_NODE__H
3 /******************************************************************************/
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. */
31 /******************************************************************************/
32 
33 #include <string.h>
34 #include <unistd.h>
35 #include <sys/uio.h>
36 
37 #include "Xrd/XrdLink.hh"
38 #include "XrdCms/XrdCmsTypes.hh"
39 #include "XrdCms/XrdCmsRRQ.hh"
40 #include "XrdSys/XrdSysPthread.hh"
41 
42 class XrdCmsBaseFR;
43 class XrdCmsBaseFS;
44 class XrdCmsDrop;
45 class XrdCmsPrepArgs;
46 class XrdCmsRRData;
47 class XrdCmsSelected;
48 class XrdOucProg;
49 
51 {
52 friend class XrdCmsCluster;
53 public:
54  char *Ident; // -> role hostname
55  char isDisable; //0 Set via admin command to temporarily remove node
56  char isOffline; //1 Set when a link failure occurs
57  char isNoStage; //2 Set upon a nostage event
58  char isMan; //3 Set when node acts as manager
59  char isPeer; //4 Set when node acts as peer manager
60  char isProxy; //5 Set when node acts as a proxy
61  char isSuspend; //6 Set upon a suspend event
62  char isBound; //7 Set when node is in the configuration
63  char isRW; //0 Set when node can write or stage data
64  char isKnown; //1 Set when we have recieved a "state"
65  char isConn; //2 Set when node is network connected
66  char isGone; //3 Set when node must be deleted
67  char isPerm; //4 Set when node is permanently bound
68  char isReserved[2];
69  char RoleID; // The converted XrdCmsRole::RoleID
70  char TimeZone; // Time zone in +UTC-
71  char TZValid; // Time zone has been set
72 
73 static const char allowsRW = 0x01; // in isRW -> Server allows r/w access
74 static const char allowsSS = 0x02; // in isRW -> Server can stage data
75 
76 unsigned int DiskTotal; // Total disk space in GB
77  int DiskNums; // Number of file systems
78  int DiskMinF; // Minimum MB needed for selection
79  int DiskFree; // Largest free MB
80  int DiskUtil; // Total disk utilization
81 unsigned int ConfigID; // Configuration identifier
82 
83 const char *do_Avail(XrdCmsRRData &Arg);
84 const char *do_Chmod(XrdCmsRRData &Arg);
85 const char *do_Disc(XrdCmsRRData &Arg);
86 const char *do_Gone(XrdCmsRRData &Arg);
87 const char *do_Have(XrdCmsRRData &Arg);
88 const char *do_Load(XrdCmsRRData &Arg);
89 const char *do_Locate(XrdCmsRRData &Arg);
90 static int do_LocFmt(char *buff, XrdCmsSelected *sP, SMask_t pf, SMask_t wf);
91 const char *do_Mkdir(XrdCmsRRData &Arg);
92 const char *do_Mkpath(XrdCmsRRData &Arg);
93 const char *do_Mv(XrdCmsRRData &Arg);
94 const char *do_Ping(XrdCmsRRData &Arg);
95 const char *do_Pong(XrdCmsRRData &Arg);
96 const char *do_PrepAdd(XrdCmsRRData &Arg);
97 const char *do_PrepDel(XrdCmsRRData &Arg);
98 const char *do_Rm(XrdCmsRRData &Arg);
99 const char *do_Rmdir(XrdCmsRRData &Arg);
100 const char *do_Select(XrdCmsRRData &Arg);
101 static int do_SelPrep(XrdCmsPrepArgs &Arg);
102 const char *do_Space(XrdCmsRRData &Arg);
103 const char *do_State(XrdCmsRRData &Arg);
104 static void do_StateDFS(XrdCmsBaseFR *rP, int rc);
105  int do_StateFWD(XrdCmsRRData &Arg);
106 const char *do_StatFS(XrdCmsRRData &Arg);
107 const char *do_Stats(XrdCmsRRData &Arg);
108 const char *do_Status(XrdCmsRRData &Arg);
109 const char *do_Trunc(XrdCmsRRData &Arg);
110 const char *do_Try(XrdCmsRRData &Arg);
111 const char *do_Update(XrdCmsRRData &Arg);
112 const char *do_Usage(XrdCmsRRData &Arg);
113 
114  void Disc(const char *reason=0, int needLock=1);
115 
116 inline int ID(int &INum) {INum = Instance; return NodeID;}
117 
118 inline int Inst() {return Instance;}
119 
120 inline int isNode(SMask_t smask) {return (smask & NodeMask) != 0;}
121 inline int isNode(const char *hn)
122  {return Link && !strcmp(Link->Host(), hn);}
123 inline int isNode(unsigned int ipa)
124  {return ipa == IPAddr;}
125 inline int isNode(unsigned int ipa, const char *nid)
126  {return ipa == IPAddr && (nid ? !strcmp(myNID, nid) : 1);}
127 inline char *Name() {return (myName ? myName : (char *)"?");}
128 
129 inline char *Name(int &len, int &port)
130  {len = myNlen; port = Port; return myName;}
131 
132 inline SMask_t Mask() {return NodeMask;}
133 
134 inline void Lock() {myMutex.Lock(); isLocked = 1;}
135 inline void UnLock() {isLocked = 0; myMutex.UnLock();}
136 
137 static void Report_Usage(XrdLink *lp);
138 
139 inline int Send(const char *buff, int blen=0)
140  {return (isOffline ? -1 : Link->Send(buff, blen));}
141 inline int Send(const struct iovec *iov, int iovcnt, int iotot=0)
142  {return (isOffline ? -1 : Link->Send(iov, iovcnt, iotot));}
143 
144  void setName(XrdLink *lnkp, int port);
145 
146  void setShare(int shrval)
147  {if (shrval > 99) Shrem = Shrip = Share = 0;
148  else {Shrem = Share = shrval; Shrip = 100 - shrval;}
149  }
150 
151  int setTZone(int tZone)
152  {TimeZone = tZone & 0x0f;
153  if (tZone & 0x10) TimeZone = -TimeZone;
154  TZValid = (tZone != 0);
155  return TimeZone;
156  }
157 
158 inline void setSlot(short rslot) {RSlot = rslot;}
159 inline short getSlot() {return RSlot;}
160 
161  void SyncSpace();
162 
163  XrdCmsNode(XrdLink *lnkp, int port=0,
164  const char *sid=0, int lvl=0, int id=-1);
165  ~XrdCmsNode();
166 
167 private:
168 static const int fsL2PFail1 = 999991;
169 static const int fsL2PFail2 = 999992;
170 
171  int fsExec(XrdOucProg *Prog, char *Arg1, char *Arg2=0);
172 const char *fsFail(const char *Who, const char *What, const char *Path, int rc);
173  int getMode(const char *theMode, mode_t &Mode);
174  int getSize(const char *theSize, long long &Size);
175 
178 unsigned int IPAddr;
180 time_t DropTime;
182 int IPV6Len; // 12345678901234567890123456
183 char IPV6[28]; // [::123.123.123.123]:123456
184 
186 int NodeID;
188 int Port;
190 int myCNUM;
191 char *myCID;
192 char *myNID;
193 char *myName;
194 int myNlen;
195 
197 int myCost; // Overall cost (determined by location)
198 int myLoad; // Overall load
199 int myMass; // Overall load including space utilization
200 int RefW; // Number of times used for writing
202 int RefR; // Number of times used for redirection
204 short RSlot;
205 char isLocked;
206 char Share; // Share of requests for this node (0 -> n/a)
207 char Shrem; // Share of requests left
208 char Shrip; // Share of requests to skip
209 char Rsvd[2];
210 int Shrin; // Share intervals used
211 
212 // The following fields are used to keep the supervisor's free space value
213 //
215 static int LastFree;
216 };
217 #endif