/
XrdCmsNode.cc
1931 lines (1663 loc) · 66.4 KB
/
XrdCmsNode.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***********************************************************************************************/
/* */
/* X r d C m s N o d e . c c */
/* */
/* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */
/* All Rights Reserved */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/
#include <limits.h>
#include <cstdio>
#include <ctime>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "Xrd/XrdJob.hh"
#include "Xrd/XrdLink.hh"
#include "XProtocol/YProtocol.hh"
#include "XrdCms/XrdCmsBaseFS.hh"
#include "XrdCms/XrdCmsCache.hh"
#include "XrdCms/XrdCmsCluster.hh"
#include "XrdCms/XrdCmsClustID.hh"
#include "XrdCms/XrdCmsConfig.hh"
#include "XrdCms/XrdCmsManager.hh"
#include "XrdCms/XrdCmsManList.hh"
#include "XrdCms/XrdCmsMeter.hh"
#include "XrdCms/XrdCmsPList.hh"
#include "XrdCms/XrdCmsPrepare.hh"
#include "XrdCms/XrdCmsRRData.hh"
#include "XrdCms/XrdCmsNode.hh"
#include "XrdCms/XrdCmsSelect.hh"
#include "XrdCms/XrdCmsState.hh"
#include "XrdCms/XrdCmsTrace.hh"
#include "XrdOss/XrdOss.hh"
#include "XrdOuc/XrdOucCRC.hh"
#include "XrdOuc/XrdOucName2Name.hh"
#include "XrdOuc/XrdOucProg.hh"
#include "XrdOuc/XrdOucPup.hh"
#include "XrdOuc/XrdOucUtils.hh"
#include "XrdNet/XrdNetUtils.hh"
#include "XrdSys/XrdSysE2T.hh"
#include "XrdSys/XrdSysPlatform.hh"
#include "XrdSys/XrdSysTimer.hh"
using namespace XrdCms;
/******************************************************************************/
/* S t a t i c O b j e c t s */
/******************************************************************************/
XrdSysMutex XrdCmsNode::mlMutex;
int XrdCmsNode::LastFree = 0;
namespace
{
XrdNetIF::ifType ifVec[4] = {XrdNetIF::PublicV4, XrdNetIF::Public46,
XrdNetIF::PublicV6, XrdNetIF::Public64};
const char *msrcmsg = "Cluster does not support multi-source access.";
int msrclen = strlen(msrcmsg)+1;
const char *mtrymsg = "Cluster retry limit exceeded.";
int mtrylen = strlen(mtrymsg)+1;
};
/******************************************************************************/
/* C o n s t r u c t o r */
/******************************************************************************/
XrdCmsNode::XrdCmsNode(XrdLink *lnkp, const char *theIF, const char *nid,
int port, int lvl, int id)
{
static XrdSysMutex iMutex;
static const SMask_t smask_1(1);
static int iNum = 1;
Link = lnkp;
NodeMask = (id < 0 ? 0 : smask_1 << id);
NodeID = id;
isOffline= (lnkp == 0);
logload = Config.LogPerf;
myNID = strdup(nid ? nid : "?");
if ((myCID = index(myNID, ' '))) myCID++;
else myCID = myNID;
myLevel = lvl;
myVersion= kYR_Version;
// setName() will set the node identification information
//
setName(lnkp, theIF, (nid ? port : 0));
iMutex.Lock();
Instance = iNum++;
iMutex.UnLock();
}
/******************************************************************************/
/* D e s t r u c t o r */
/******************************************************************************/
XrdCmsNode::~XrdCmsNode()
{
isOffline = 1; // STMutex not needed here
// Delete other appendages
//
if (cidP) {cidP->RemNode(this); cidP = 0;}
if (Ident) free(Ident);
if (myNID) free(myNID);
if (myName)free(myName);
}
/******************************************************************************/
/* s e t N a m e */
/******************************************************************************/
void XrdCmsNode::setName(XrdLink *lnkp, const char *theIF, int port)
{
char buff[512];
const char *hname = lnkp->Host();
// Check if this is a duplicate. Note that we check for strict equivalence.
//
if (myName)
{if (!strcmp(myName,hname) && port == netIF.Port()
&& netID.Same(lnkp->NetAddr())) return;
free(myName);
}
// Get our address information but substitute data port for actual port
//
netID = *(lnkp->NetAddr());
// Set the network interface. Note that out of domain nodes are not allowed
// to specify interface addresses as this does not make global sense.
//
if (theIF && !netIF.InDomain(&netID)) theIF = 0;
netIF.SetIF(&netID, theIF, port);
hasNet = netIF.Mask();
// Construct our identification
//
myName = strdup(hname);
myNlen = strlen(hname);
if (!port) strcpy(buff, lnkp->ID);
else sprintf(buff, "%s:%d", lnkp->ID, port);
if (Ident) free(Ident);
Ident = strdup(buff);
}
/******************************************************************************/
/* D e l e t e */
/******************************************************************************/
void XrdCmsNode::Delete(XrdSysFusedMutex &gMutex)
{
EPNAME("Delete");
static const int warnIntvl = 60;
int totWait = 0, tmoWarn = 60;
int tmoWait (Config.DELDelay < 3 ? Config.DELDelay : 3);
bool doDel = true;
// We need to make sure there are no references to this object. This is true
// when the refCnt is zero but only when we hold a global write lock that has
// been passed to us. As this node has been removed from all global tables
// at this point, we just need to make sure than no threads are poised to
// increase it. That can't happen if we obrtain a write lock. To start,
// get the node lock and do some debugging. Set the isGone flag even though it
// should be set. Note that we need to serialize with the refCnt as some
// threads may still be holding a reference to the node.
//
nodeMutex.Lock();
isGone = 1;
nodeMutex.UnLock();
DEBUG(Ident <<" refs=" <<refCnt);
// Now wait for things to simmer down. We wait for an appropriate time because
// we don't want to occupy this thread forever.
//
gMutex.WriteLock();
while(refCnt)
{if (totWait >= Config.DELDelay) {doDel = false; break;}
gMutex.UnLock();
if (totWait >= tmoWarn)
{unsigned int theCnt = refCnt;
DeleteWarn(theCnt);
tmoWarn += warnIntvl;
}
XrdSysTimer::Snooze(tmoWait);
totWait += tmoWait;
gMutex.WriteLock();
}
gMutex.UnLock();
// We can now safely delete this node
//
if (doDel) delete this;
else {char eBuff[256];
snprintf(eBuff, sizeof(eBuff),
" (%p) delete timeout; node object lost!", this);
Say.Emsg("Delete", Ident, eBuff);
}
}
/******************************************************************************/
/* Private: D e l e t e W a r n */
/******************************************************************************/
void XrdCmsNode::DeleteWarn(unsigned int lkVal)
{
// Print warning
//
if (lkVal)
{char eBuff[256];
snprintf(eBuff, sizeof(eBuff), "delete sync stall; refs = %u", lkVal);
Say.Emsg("Delete", Ident, eBuff);
}
}
/******************************************************************************/
/* D i s c */
/******************************************************************************/
void XrdCmsNode::Disc(const char *reason, int needLock)
{
// Indicate we are offline. If a lock is not need then we only need to set the
// offline flag as it's already properly protected. Otherwise, set the flag
// after we get the lock. This is indeed messy.
//
if (needLock) nodeMutex.Lock();
isOffline = 1; // STMutex is already held if needed
// If we are still connected, initiate a teardown. This may be done async as
// we are asking for a deferred close which will be followed by a full close.
//
if (isConn)
{Link->setEtext(reason);
Link->Close(1);
isConn = 0;
}
// Unlock ourselves if we locked ourselves
//
if (needLock) nodeMutex.UnLock();
}
/******************************************************************************/
/* d o _ A v a i l */
/******************************************************************************/
// Node responses to space usage requests from a manager are localized to the
// cell and need not be propopagated in any direction.
//
const char *XrdCmsNode::do_Avail(XrdCmsRRData &Arg)
{
EPNAME("do_Avail")
// Process: avail <fsdsk> <util>
//
DiskFree = Arg.dskFree;
DiskUtil = static_cast<int>(Arg.dskUtil);
// Do some debugging
//
DEBUGR(DiskFree <<"MB free; " <<DiskUtil <<"% util");
return 0;
}
/******************************************************************************/
/* d o _ C h m o d */
/******************************************************************************/
// Chmod requests are forwarded to all subscribers
//
const char *XrdCmsNode::do_Chmod(XrdCmsRRData &Arg)
{
EPNAME("do_Chmod")
mode_t mode = 0;
int rc;
// Do some debugging
//
DEBUGR("mode " <<Arg.Mode <<' ' <<Arg.Path);
// We are don here if we have no data; otherwise convert the mode if we
// haven't done so already.
//
if (!Config.DiskOK) return 0;
if (!mode && !getMode(Arg.Mode, mode)) return "invalid mode";
// Attempt to change the mode either via call-out or the oss plug-in
//
if (Config.ProgCH) rc = fsExec(Config.ProgCH, Arg.Mode, Arg.Path);
else rc = Config.ossFS->Chmod(Arg.Path, mode);
// Return appropriate result
//
return (rc ? fsFail(Arg.Ident, "chmod", Arg.Path, rc) : 0);
}
/******************************************************************************/
/* d o _ D i s c */
/******************************************************************************/
// When a manager receives a disc response from a node it sends a disc request
// and then closes the connection.
// When a node receives a disc request it simply closes the connection.
const char *XrdCmsNode::do_Disc(XrdCmsRRData &Arg)
{
// Indicate we have received a disconnect
//
Say.Emsg("Node", Link->Name(), "requested a disconnect");
// If we must send a disc request, do so now
//
if (Config.asManager()) Link->Send((char *)&Arg.Request,sizeof(Arg.Request));
// Close the link and return an error
//
isOffline = 1; // STMutex not needed here
Link->Close(1);
return "."; // Signal disconnect
}
/******************************************************************************/
/* d o _ G o n e */
/******************************************************************************/
// When a manager receives a gone request it is propogated if we are subscribed
// and we have not sent a gone request in the immediate past.
//
const char *XrdCmsNode::do_Gone(XrdCmsRRData &Arg)
{
EPNAME("do_Gone")
static const SMask_t allNodes(~0);
int newgone;
// Do some debugging
//
TRACER(Files,Arg.Path);
// Update path information and delete this from the prep queue if we are a
// staging node. We can also be called via the admin end-point interface
// In this case, we have no cache and simply forward up the request.
//
if (Config.asManager())
{XrdCmsSelect Sel(XrdCmsSelect::Advisory, Arg.Path, Arg.PathLen-1);
newgone = Cache.DelFile(Sel, baseFS.isDFS() ? allNodes : NodeMask);
} else {
newgone = 1;
if (Config.DiskSS) PrepQ.Gone(Arg.Path);
}
// If we have no managers and we still have the file or never had it, return
//
if (!XrdCmsManager::Present() || !newgone) return 0;
// Back-propogate the gone to all of our managers
//
XrdCmsManager::Inform(Arg.Request, Arg.Buff, Arg.Dlen);
// All done
//
return 0;
}
/******************************************************************************/
/* d o _ H a v e */
/******************************************************************************/
// When a manager receives a have request it is propogated if we are subscribed
// and we have not sent a have request in the immediate past.
//
const char *XrdCmsNode::do_Have(XrdCmsRRData &Arg)
{
EPNAME("do_Have")
static const SMask_t allNodes(~0);
XrdCmsPInfo pinfo;
int isnew, Opts;
// Do some debugging
//
TRACER(Files, (Arg.Request.modifier&CmsHaveRequest::Pending ? "P ":"")
<<Arg.Path);
// Find if we can handle the file in r/w mode and if staging is present
//
Opts = (Cache.Paths.Find(Arg.Path, pinfo) && (pinfo.rwvec & NodeMask)
? XrdCmsSelect::Write : 0);
if (Arg.Request.modifier & CmsHaveRequest::Pending)
Opts |= XrdCmsSelect::Pending;
// Update path information. If we are exporting a shared-everything file system
// then we need to also provide the cache the current list of nodes and how
// they export the path in question for fast redispatch processing.
//
if (!Config.asManager()) isnew = 1;
else {XrdCmsSelect Sel(XrdCmsSelect::Advisory|Opts,Arg.Path,Arg.PathLen-1);
Sel.Path.Hash = Arg.Request.streamid;
if (baseFS.isDFS())
{Sel.Vec.hf = pinfo.rovec; Sel.Vec.wf = pinfo.rwvec;
isnew = Cache.AddFile(Sel, allNodes);
} else isnew = Cache.AddFile(Sel, NodeMask);
}
// Return if we have no managers or we already informed the managers
//
if (!XrdCmsManager::Present() || !isnew) return 0;
// Back-propogate the have to all of our managers
//
XrdCmsManager::Inform(Arg.Request, Arg.Buff, Arg.Dlen);
// All done
//
return 0;
}
/******************************************************************************/
/* d o _ L o a d */
/******************************************************************************/
// Responses to usage requests are local to the cell and never propagated.
//
const char *XrdCmsNode::do_Load(XrdCmsRRData &Arg)
{
EPNAME("do_Load")
uint32_t pcpu, pnet, pxeq, pmem, ppag, pdsk;
int temp;
// Process: load <cpu> <io> <load> <mem> <pag> <util> <rsvd> <dskFree>
// 0 1 2 3 4 5 6
pcpu = static_cast<uint32_t>(Arg.Opaque[CmsLoadRequest::cpuLoad]);
pnet = static_cast<uint32_t>(Arg.Opaque[CmsLoadRequest::netLoad]);
pxeq = static_cast<uint32_t>(Arg.Opaque[CmsLoadRequest::xeqLoad]);
pmem = static_cast<uint32_t>(Arg.Opaque[CmsLoadRequest::memLoad]);
ppag = static_cast<uint32_t>(Arg.Opaque[CmsLoadRequest::pagLoad]);
pdsk = static_cast<uint32_t>(Arg.Opaque[CmsLoadRequest::dskLoad]);
// Compute actual load value. Note that the update is not thread-kosher as we
// do not obtain a write lock. However, the values below use the single writer
// principal so other threads will eventually see a coherent picture. This is
// good enough for what these values are used for.
//
myLoad = Meter.calcLoad(pcpu, pnet, pxeq, pmem, ppag);
myMass = Meter.calcLoad(myLoad, pdsk);
DiskFree = Arg.dskFree;
DiskUtil = pdsk;
// Do some debugging
//
DEBUGR("cpu=" <<pcpu <<" net=" <<pnet <<" xeq=" <<pxeq
<<" mem=" <<pmem <<" pag=" <<ppag <<" dsk=" <<pdsk
<<"% " <<DiskFree <<"MB load=" <<myLoad <<" mass=" <<myMass);
// If we are also a manager then use this load figure to come up with
// an overall load to report when asked. If we get free space, then we
// must report that now so that we can be selected for allocation.
//
if (Config.asManager())
{Meter.Record(pcpu, pnet, pxeq, pmem, ppag, pdsk);
if (isRW && DiskFree != LastFree)
{mlMutex.Lock();
temp = LastFree; LastFree = DiskFree; Meter.setVirtUpdt();
if (!temp && DiskFree >= Config.DiskMin) do_Space(Arg);
mlMutex.UnLock();
}
}
// Report new load if need be
//
if (Config.LogPerf && !logload)
{char buff[1024];
long long tRefs = Cluster.Refs();
long long nRefs = static_cast<long long>(RefTotW + RefTotR)*100;
long long sRefs = static_cast<long long>(Share) * Shrin * 100;
int myShr = (Share ? Share : 100);
if (tRefs) {nRefs /= tRefs; sRefs /= tRefs;}
else nRefs = sRefs = 0;
snprintf(buff, sizeof(buff)-1,
"load=%d; cpu=%d net=%d inq=%d mem=%d pag=%d dsk=%d utl=%d "
"shr=[%d %lld %lld] ref=[%d %d]",
myLoad, pcpu, pnet, pxeq, pmem, ppag, Arg.dskFree, pdsk,
myShr, nRefs, sRefs, RefTotR+RefR, RefTotW+RefW);
Say.Emsg("Node", Name(), buff);
logload = Config.LogPerf;
} else logload--;
// Return as if we had gotten a pong
//
return do_Pong(Arg);
}
/******************************************************************************/
/* d o _ L o c a t e */
/******************************************************************************/
const char *XrdCmsNode::do_Locate(XrdCmsRRData &Arg)
{
EPNAME("do_Locate";)
XrdCmsRRQInfo reqInfo(Instance,RSlot,Arg.Request.streamid,Config.QryMinum);
XrdCmsSelect Sel(0, Arg.Path, Arg.PathLen-1);
XrdCmsSelected *sP = 0;
struct {kXR_unt32 Val;
char outbuff[CmsLocateRequest::RHLen*STMax];} Resp;
struct iovec ioV[2] = {{(char *)&Arg.Request, sizeof(Arg.Request)},
{(char *)&Resp, 0}};
const char *Why;
char eBuff[128], theopts[8], *toP = theopts;
XrdCmsCluster::CmsLSOpts lsopts = XrdCmsCluster::LS_NULL;
XrdNetIF::ifType ifType;
int rc, bytes;
bool lsuniq = false, oksel = false, lsall = (*Arg.Path == '*');
// Get the right interface selection options
//
ifType = ifVec[(Arg.Opts & CmsLocateRequest::kYR_retipmsk)
>> CmsLocateRequest::kYR_retipsft];
// Indicate whether we want a name or an actual address
//
lsopts = (Arg.Opts & CmsLocateRequest::kYR_retname
? XrdCmsCluster::LS_IDNT : XrdCmsCluster::LS_IPO);
// Indicate if only a single server entry should be listed
//
if (Arg.Opts & CmsLocateRequest::kYR_retuniq && baseFS.isDFS())
{lsuniq = true; *toP++='u';}
// Indicate whether we can ignore network restrictions
//
if (Arg.Opts & CmsLocateRequest::kYR_listall)
lsopts |= XrdCmsCluster::LS_ANY;
// Indicate whether we ony want to list a single entry
//
// Handle private networks here
//
if (Arg.Opts & CmsLocateRequest::kYR_prvtnet)
{XrdNetIF::Privatize(ifType);
*toP++='P';
}
// Encode if type into the options
//
Sel.Opts = static_cast<int>(ifType) & XrdCmsSelect::ifWant;
lsopts = static_cast<XrdCmsCluster::CmsLSOpts>(lsopts | ifType);
// Grab various options
//
if (Arg.Opts & CmsLocateRequest::kYR_refresh)
{Sel.Opts = XrdCmsSelect::Refresh; *toP++='s';}
if (Arg.Opts & CmsLocateRequest::kYR_asap)
{Sel.Opts |= XrdCmsSelect::Asap; *toP++='i'; Sel.InfoP = &reqInfo;
reqInfo.lsLU = static_cast<char>(lsopts);
}
else Sel.InfoP = 0;
// Do some debugging
//
*toP = '\0';
DEBUGR(theopts <<' ' <<Arg.Path);
// Perform location
//
if ((rc = Cluster.Locate(Sel)))
{if (rc > 0)
{Arg.Request.rrCode = kYR_wait;
bytes = sizeof(Resp.Val); Why = "delay ";
} else {
if (rc == XrdCmsCluster::Wait4CBk) return 0;
Arg.Request.rrCode = kYR_error;
rc = kYR_ENOENT; Why = "miss ";
bytes = strlcpy(Resp.outbuff, "No servers have access to the file",
sizeof(Resp.outbuff)) + sizeof(Resp.Val) + 1;
}
} else {Why = "?"; bytes = 0;}
// List the servers
//
if (!rc)
{if (!Sel.Vec.hf || !(sP=Cluster.List(Sel.Vec.hf, lsopts, oksel)))
{const char *eTxt;
Arg.Request.rrCode = kYR_error;
if (oksel)
{rc = kYR_ENETUNREACH; Why = "unreachable ";
sprintf(eBuff, "No servers are reachable via %s network",
XrdNetIF::Name(ifType));
eTxt = eBuff;
} else {
rc = kYR_ENOENT; Why = "none ";
eTxt = "No servers have the file";
}
bytes = strlcpy(Resp.outbuff, eTxt,
sizeof(Resp.outbuff)) + sizeof(Resp.Val) + 1;
} else rc = 0;
}
// Either prepare to send an error or format the result
//
if (rc)
{Resp.Val = htonl(rc);
DEBUGR(Why <<Arg.Path);
} else {
bytes = do_LocFmt(Resp.outbuff, sP, Sel.Vec.pf, Sel.Vec.wf, lsall,lsuniq)
+ sizeof(Resp.Val) + 1;
Resp.Val = 0;
Arg.Request.rrCode = kYR_data;
}
// Send off the response
//
Arg.Request.datalen = htons(bytes);
ioV[1].iov_len = bytes;
Link->Send(ioV, 2, bytes+sizeof(Arg.Request));
return 0;
}
/******************************************************************************/
/* Static d o _ L o c F m t */
/******************************************************************************/
int XrdCmsNode::do_LocFmt(char *buff, XrdCmsSelected *sP,
SMask_t pfVec, SMask_t wfVec, bool lsall, bool lsuniq)
{
static const int Skip = (XrdCmsSelected::Disable | XrdCmsSelected::Offline);
static const int Hung = (XrdCmsSelected::Disable | XrdCmsSelected::Offline
| XrdCmsSelected::Suspend);
XrdCmsSelected *pP;
char *oP = buff;
// If only unique entries are wanted then we need to only let through
// all non-servers and one server (prefereably a r/w one)
//
if (!lsall && lsuniq)
{XrdCmsSelected *xP = 0;
bool haverw = false;
pP = sP;
while(pP)
{if (!(pP->Status & (XrdCmsSelected::isMangr | Skip)))
{if (haverw) pP->Status |= Skip;
else {if (xP) xP->Status |= Skip;
xP = pP;
haverw = (pP->Mask & wfVec) != 0;
}
}
pP = pP->next;
}
}
// format out the request as follows:
// 01234567810123456789212345678
// xy[::123.123.123.123]:123456
//
if (lsall)
while(sP)
{*oP = (sP->Status & XrdCmsSelected::isMangr ? 'M' : 'S');
if (sP->Status & Hung) *oP = tolower(*oP);
*(oP+1) = (sP->Mask & wfVec ? 'w' : 'r');
strcpy(oP+2, sP->Ident); oP += sP->IdentLen + 2;
if (sP->next) *oP++ = ' ';
pP = sP; sP = sP->next; delete pP;
}
else
while(sP)
{if (!(sP->Status & Skip))
{*oP = (sP->Status & XrdCmsSelected::isMangr ? 'M' : 'S');
if (sP->Mask & pfVec) *oP = tolower(*oP);
*(oP+1) = (sP->Mask & wfVec ? 'w' : 'r');
strcpy(oP+2, sP->Ident); oP += sP->IdentLen + 2;
if (sP->next) *oP++ = ' ';
}
pP = sP; sP = sP->next; delete pP;
}
// Send of the result
//
*oP = '\0';
return (oP - buff);
}
/******************************************************************************/
/* d o _ M k d i r */
/******************************************************************************/
// Mkdir requests are forwarded to all subscribers
//
const char *XrdCmsNode::do_Mkdir(XrdCmsRRData &Arg)
{
EPNAME("do_Mkdir")
mode_t mode = 0;
int rc;
// Do some debugging
//
DEBUGR("mode " <<Arg.Mode <<' ' <<Arg.Path);
// We are don here if we have no data; otherwise convert the mode if we
// haven't done so already.
//
if (!Config.DiskOK) return 0;
if (!mode && !getMode(Arg.Mode, mode)) return "invalid mode";
// Attempt to create the directory either via call-out of oss plug-in
//
if (Config.ProgMD) rc = fsExec(Config.ProgMD, Arg.Mode, Arg.Path);
else rc = Config.ossFS->Mkdir(Arg.Path, mode);
// Return appropriate result
//
return (rc ? fsFail(Arg.Ident, "mkdir", Arg.Path, rc) : 0);
}
/******************************************************************************/
/* d o _ M k p a t h */
/******************************************************************************/
// Mkpath requests are forwarded to all subscribers
//
const char *XrdCmsNode::do_Mkpath(XrdCmsRRData &Arg)
{
EPNAME("do_Mkpath")
mode_t mode = 0;
int rc;
// Do some debugging
//
DEBUGR("mode " <<Arg.Mode <<' ' <<Arg.Path);
// We are don here if we have no data; otherwise convert the mode if we
// haven't done so already.
//
if (!Config.DiskOK) return 0;
if (!mode && !getMode(Arg.Mode, mode)) return "invalid mode";
// Attempt to create the directory path via call-out or oss plugin
//
if (Config.ProgMP) rc = fsExec(Config.ProgMP, Arg.Mode, Arg.Path);
else rc = Config.ossFS->Mkdir(Arg.Path, mode, 1);
// Return appropriate result
//
return (rc ? fsFail(Arg.Ident, "mkpath", Arg.Path, rc) : 0);
}
/******************************************************************************/
/* d o _ M v */
/******************************************************************************/
// Mv requests are forwarded to all subscribers
//
const char *XrdCmsNode::do_Mv(XrdCmsRRData &Arg)
{
EPNAME("do_Mv")
static const SMask_t allNodes(~0);
int rc;
// Do some debugging
//
DEBUGR(Arg.Path <<" to " <<Arg.Path2);
// If we are not a server, if must remove references to the old and new names
// from our cache. This is independent of how the raname is handled. We need
// not back percolate the mv since it was hanled top down in the first place.
// Note that we will scuttle the mv if the target file exists somewhere.
//
if (!Config.DiskOK)
{XrdCmsSelect Sel1(XrdCmsSelect::Defer, Arg.Path, strlen(Arg.Path ));
XrdCmsSelect Sel2(XrdCmsSelect::Defer, Arg.Path2,strlen(Arg.Path2));
// Setup select data (note that mv does not allow fast redirect)
//
Sel2.iovP = 0; Sel2.iovN = 0;
Sel2.InfoP = 0; // No fast redirects
Sel2.nmask = SMask_t(0);
// Perform selection
//
if ((rc = Cluster.Select(Sel2)))
{if (rc > 0) {Arg.waitVal = rc; return "!mv";}
else if (Sel2.Vec.hf)
{Say.Emsg("do_Mv",Arg.Path2,"exists; mv failed for",Arg.Path);
return "target file exists";
}
}
Cache.DelFile(Sel2, allNodes);
Cache.DelFile(Sel1, allNodes);
return 0;
}
// Rename the file via call-out or oss plug-in (we used to do this via a requeue
// to the local xrootd but it's no longer necessary).
//
if (Config.ProgMV) rc = fsExec(Config.ProgMV, Arg.Path, Arg.Path2);
else rc = Config.ossFS->Rename(Arg.Path, Arg.Path2);
// Return appropriate result
//
return (rc ? fsFail(Arg.Ident, "mv", Arg.Path, rc) : 0);
}
/******************************************************************************/
/* d o _ P i n g */
/******************************************************************************/
// Ping requests from a manager are local to the cell and never propagated.
//
const char *XrdCmsNode::do_Ping(XrdCmsRRData &Arg)
{
static CmsPongRequest pongIt = {{0, kYR_pong, 0, 0}};
// Process: ping
// Respond: pong
//
if (isBad & isDoomed) return ".redirected";
Link->Send((char *)&pongIt, sizeof(pongIt));
return 0;
}
/******************************************************************************/
/* d o _ P o n g */
/******************************************************************************/
// Responses to a ping are local to the cell and never propagated.
//
const char *XrdCmsNode::do_Pong(XrdCmsRRData &Arg)
{
// Process: pong
// Reponds: n/a
return 0;
}
/******************************************************************************/
/* d o _ P r e p A d d */
/******************************************************************************/
const char *XrdCmsNode::do_PrepAdd(XrdCmsRRData &Arg)
{
EPNAME("do_PrepAdd")
// Do some debugging
//
DEBUGR("parms: " <<Arg.Reqid <<' ' <<Arg.Notify <<' ' <<Arg.Prty <<' '
<<Arg.Mode <<' ' <<Arg.Path);
// Queue this request for async processing
//
(new XrdCmsPrepArgs(Arg))->Queue();
return 0;
}
/******************************************************************************/
/* d o _ P r e p D e l */
/******************************************************************************/
const char *XrdCmsNode::do_PrepDel(XrdCmsRRData &Arg)
{
EPNAME("do_PrepDel")
// Do some debugging
//
DEBUGR("reqid " <<Arg.Reqid);
// Cancel the request if applicable.
//
if (Config.DiskOK)
{if (!Config.DiskSS) {DEBUGR("ignoring cancel prepare " <<Arg.Reqid);}
else {DEBUGR("canceling prepare " <<Arg.Reqid);
PrepQ.Del(Arg.Reqid);
}
}
return 0;
}
/******************************************************************************/
/* d o _ R m */
/******************************************************************************/
// Rm requests are forwarded to all subscribers
//
const char *XrdCmsNode::do_Rm(XrdCmsRRData &Arg)
{
EPNAME("do_Rm")
static const SMask_t allNodes(~0);
int rc;
// Do some debugging
//
DEBUGR(Arg.Path);
// If we have no data then we should remove this file from our cache
//
if (!Config.DiskOK)
{XrdCmsSelect Sel(0, Arg.Path, strlen(Arg.Path));
Cache.DelFile(Sel, allNodes);
return 0;
}
// Remove the file either via call-out or the oss plugin. We used to requeue
// the request to the local xrootd but this is no longer needed.
//
if (Config.ProgRM) rc = fsExec(Config.ProgRM, Arg.Path);
else rc = Config.ossFS->Unlink(Arg.Path);
// Return appropriate result
//
return (rc ? fsFail(Arg.Ident, "rm", Arg.Path, rc) : 0);
}
/******************************************************************************/
/* d o _ R m d i r */
/******************************************************************************/
// Rmdir requests are forwarded to all subscribers
//
const char *XrdCmsNode::do_Rmdir(XrdCmsRRData &Arg)
{
EPNAME("do_Rmdir")
static const SMask_t allNodes(~0);
int rc;
// Do some debugging
//
DEBUGR(Arg.Path);
// If we have no data then we should remove this directory from our cache
//
if (!Config.DiskOK)
{XrdCmsSelect Sel(0, Arg.Path, strlen(Arg.Path));
Cache.DelFile(Sel, allNodes);
return 0;
}
// Remove the directory either via call-out or the oss plug-in (we used to
// do this by requeing the request to the local xrootd; no longer needed).
//
if (Config.ProgRD) rc = fsExec(Config.ProgRD, Arg.Path);
else rc = Config.ossFS->Remdir(Arg.Path);
// Return appropriate result
//
return (rc ? fsFail(Arg.Ident, "rmdir", Arg.Path, rc) : 0);
}
/******************************************************************************/
/* d o _ S e l A v o i d */
/******************************************************************************/
int XrdCmsNode::do_SelAvoid(XrdCmsRRData &Arg, XrdCmsSelect &Sel,
char *Avoid, bool &doRedir)
{
XrdNetAddr avoidAddr;
char *Comma;
int avNum = 0;
// Process the avoid list
//
Sel.InfoP = 0;
do {if ((Comma = index(Avoid,','))) *Comma = '\0';
if (*Avoid == '+') Sel.nmask |= Cluster.getMask(Avoid+1);
else if (!avoidAddr.Set(Avoid,0))
Sel.nmask |= Cluster.getMask(&avoidAddr);
Avoid = Comma+1; avNum++;
} while(Comma && *Avoid);