/******************************************************************************/ /* */ /* X r d C m s C l u s t I D . c c */ /* */ /* (c) 2014 by the Board of Trustees of the Leland Stanford, Jr., University */ /* Produced by Andrew Hanushevsky for Stanford University under contract */ /* DE-AC02-76-SFO0515 with the Deprtment 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 . */ /* */ /* 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 #include "XrdCms/XrdCmsClustID.hh" #include "XrdCms/XrdCmsNode.hh" #include "XrdCms/XrdCmsTrace.hh" #include "XrdOuc/XrdOucHash.hh" #include "XrdSys/XrdSysPthread.hh" using namespace XrdCms; /******************************************************************************/ /* L o c a l S t a t i c O b j e c t s */ /******************************************************************************/ namespace { XrdSysMutex cidMtx; XrdOucHash cidTab; XrdCmsClustID *cidFree = new XrdCmsClustID(); }; /******************************************************************************/ /* Static: A d d I D */ /******************************************************************************/ XrdCmsClustID *XrdCmsClustID::AddID(const char *cID) { XrdCmsClustID *cidObj; const char *cHN; char *clustID; // Massage the clusterid (it's in bi-compatible format) // if ((cHN = rindex(cID, ' ')) && *(cHN+1)) cID = cHN+1; clustID = strdup(cID); // Lock ourselves // cidMtx.Lock(); // Allocate a new cluster ID object if we don't have one ready // if (!cidFree) cidFree = new XrdCmsClustID(); // Attempt to add this object to our cid table // if (!(cidObj = cidTab.Add(clustID, cidFree, 0, Hash_keep))) {cidObj = cidFree; cidObj->cidName = clustID; cidFree = new XrdCmsClustID(); } else free(clustID); // We can unlock now // cidMtx.UnLock(); // Return the entry // return cidObj; } /******************************************************************************/ /* A d d N o d e */ /******************************************************************************/ bool XrdCmsClustID::AddNode(XrdCmsNode *nP, bool isMan) { EPNAME("AddNode"); XrdSysMutexHelper cidHelper(cidMtx); int iNum, sNum; // For servers we only add the identification mask // if (!isMan) {cidMask |= nP->Mask(); DEBUG("srv " <Ident <<" cluster " <Name()); return false; } // Make sure the slot numbers match for this node // sNum = nP->ID(iNum); if (npNum > 0 && ntSlot != sNum) {char buff[256]; sprintf(buff,"cluster slot mismatch: %d != %d; rejecting",sNum,ntSlot); Say.Emsg("ClustID", cidName, buff, nP->Name()); return false; } // Add the entry to the table // ntSlot = sNum; cidMask |= nP->Mask(); nodeP[npNum++] = nP; DEBUG("man " <Ident <<" cluster " <isMan | nP->isPeer)) {cidMask &= ~(nP->Mask()); DEBUG("srv " <Ident <<" cluster " <Ident <<" cluster " <