New upstream version 8.1.0
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
#ifndef GETMIRRORBUDDYGROUPSMSG_H
|
||||
#define GETMIRRORBUDDYGROUPSMSG_H
|
||||
|
||||
#include <common/net/message/SimpleIntMsg.h>
|
||||
|
||||
struct GetMirrorBuddyGroupsMsg;
|
||||
typedef struct GetMirrorBuddyGroupsMsg GetMirrorBuddyGroupsMsg;
|
||||
|
||||
static inline void GetMirrorBuddyGroupsMsg_init(GetMirrorBuddyGroupsMsg* this, NodeType nodeType);
|
||||
|
||||
struct GetMirrorBuddyGroupsMsg
|
||||
{
|
||||
SimpleIntMsg simpleIntMsg;
|
||||
};
|
||||
|
||||
void GetMirrorBuddyGroupsMsg_init(GetMirrorBuddyGroupsMsg* this, NodeType nodeType)
|
||||
{
|
||||
SimpleIntMsg_initFromValue( (SimpleIntMsg*)this, NETMSGTYPE_GetMirrorBuddyGroups, nodeType);
|
||||
}
|
||||
|
||||
#endif /* GETMIRRORBUDDYGROUPSMSG_H */
|
||||
32
client_module/source/common/net/message/nodes/GetNodesMsg.h
Normal file
32
client_module/source/common/net/message/nodes/GetNodesMsg.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef GETNODESMSG_H_
|
||||
#define GETNODESMSG_H_
|
||||
|
||||
#include <common/net/message/SimpleIntMsg.h>
|
||||
|
||||
|
||||
struct GetNodesMsg;
|
||||
typedef struct GetNodesMsg GetNodesMsg;
|
||||
|
||||
static inline void GetNodesMsg_init(GetNodesMsg* this);
|
||||
static inline void GetNodesMsg_initFromValue(GetNodesMsg* this, int nodeType);
|
||||
|
||||
struct GetNodesMsg
|
||||
{
|
||||
SimpleIntMsg simpleIntMsg;
|
||||
};
|
||||
|
||||
|
||||
void GetNodesMsg_init(GetNodesMsg* this)
|
||||
{
|
||||
SimpleIntMsg_init( (SimpleIntMsg*)this, NETMSGTYPE_GetNodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeType NODETYPE_...
|
||||
*/
|
||||
void GetNodesMsg_initFromValue(GetNodesMsg* this, int nodeType)
|
||||
{
|
||||
SimpleIntMsg_initFromValue( (SimpleIntMsg*)this, NETMSGTYPE_GetNodes, nodeType);
|
||||
}
|
||||
|
||||
#endif /* GETNODESMSG_H_ */
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "GetNodesRespMsg.h"
|
||||
|
||||
const struct NetMessageOps GetNodesRespMsg_Ops = {
|
||||
.serializePayload = _NetMessage_serializeDummy,
|
||||
.deserializePayload = GetNodesRespMsg_deserializePayload,
|
||||
.processIncoming = NetMessage_processIncoming,
|
||||
.getSupportedHeaderFeatureFlagsMask = NetMessage_getSupportedHeaderFeatureFlagsMask,
|
||||
};
|
||||
|
||||
|
||||
bool GetNodesRespMsg_deserializePayload(NetMessage* this, DeserializeCtx* ctx)
|
||||
{
|
||||
GetNodesRespMsg* thisCast = (GetNodesRespMsg*)this;
|
||||
|
||||
// nodeList
|
||||
if(!Serialization_deserializeNodeListPreprocess(ctx, &thisCast->rawNodeList) )
|
||||
return false;
|
||||
|
||||
// rootNumID
|
||||
if(!NumNodeID_deserialize(ctx, &thisCast->rootNumID) )
|
||||
return false;
|
||||
|
||||
// rootIsBuddyMirrored
|
||||
if(!Serialization_deserializeBool(ctx, &thisCast->rootIsBuddyMirrored) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#ifndef GETNODESRESPMSG_H_
|
||||
#define GETNODESRESPMSG_H_
|
||||
|
||||
#include <common/net/message/NetMessage.h>
|
||||
#include <common/nodes/NodeList.h>
|
||||
|
||||
/*
|
||||
* note: serialization not implemented
|
||||
*/
|
||||
struct GetNodesRespMsg;
|
||||
typedef struct GetNodesRespMsg GetNodesRespMsg;
|
||||
|
||||
static inline void GetNodesRespMsg_init(GetNodesRespMsg* this);
|
||||
|
||||
// virtual functions
|
||||
extern bool GetNodesRespMsg_deserializePayload(NetMessage* this, DeserializeCtx* ctx);
|
||||
|
||||
// inliners
|
||||
static inline void GetNodesRespMsg_parseNodeList(App* app, GetNodesRespMsg* this,
|
||||
NodeList* outNodeList);
|
||||
|
||||
// getters & setters
|
||||
static inline NumNodeID GetNodesRespMsg_getRootNumID(GetNodesRespMsg* this);
|
||||
static inline bool GetNodesRespMsg_getRootIsBuddyMirrored(GetNodesRespMsg* this);
|
||||
|
||||
|
||||
struct GetNodesRespMsg
|
||||
{
|
||||
NetMessage netMessage;
|
||||
|
||||
NumNodeID rootNumID;
|
||||
bool rootIsBuddyMirrored;
|
||||
|
||||
// for deserialization
|
||||
RawList rawNodeList;
|
||||
};
|
||||
|
||||
extern const struct NetMessageOps GetNodesRespMsg_Ops;
|
||||
|
||||
void GetNodesRespMsg_init(GetNodesRespMsg* this)
|
||||
{
|
||||
NetMessage_init(&this->netMessage, NETMSGTYPE_GetNodesResp, &GetNodesRespMsg_Ops);
|
||||
|
||||
this->rootNumID = (NumNodeID){0};
|
||||
}
|
||||
|
||||
void GetNodesRespMsg_parseNodeList(App* app, GetNodesRespMsg* this, NodeList* outNodeList)
|
||||
{
|
||||
Serialization_deserializeNodeList(app, &this->rawNodeList, outNodeList);
|
||||
}
|
||||
|
||||
NumNodeID GetNodesRespMsg_getRootNumID(GetNodesRespMsg* this)
|
||||
{
|
||||
return this->rootNumID;
|
||||
}
|
||||
|
||||
bool GetNodesRespMsg_getRootIsBuddyMirrored(GetNodesRespMsg* this)
|
||||
{
|
||||
return this->rootIsBuddyMirrored;
|
||||
}
|
||||
|
||||
#endif /* GETNODESRESPMSG_H_ */
|
||||
@@ -0,0 +1,27 @@
|
||||
#include "GetStatesAndBuddyGroupsMsg.h"
|
||||
|
||||
static void GetStatesAndBuddyGroupsMsg_serializePayload(NetMessage* this, SerializeCtx* ctx)
|
||||
{
|
||||
GetStatesAndBuddyGroupsMsg* thisCast = (GetStatesAndBuddyGroupsMsg*)this;
|
||||
|
||||
Serialization_serializeInt(ctx, thisCast->nodeType);
|
||||
NumNodeID_serialize(ctx, &thisCast->requestedByClientID);
|
||||
}
|
||||
|
||||
static bool GetStatesAndBuddyGroupsMsg_deserializePayload(NetMessage* this, DeserializeCtx* ctx)
|
||||
{
|
||||
GetStatesAndBuddyGroupsMsg* thisCast = (GetStatesAndBuddyGroupsMsg*)this;
|
||||
|
||||
bool result =
|
||||
Serialization_deserializeInt(ctx, (int32_t*)&thisCast->nodeType)
|
||||
&& NumNodeID_deserialize(ctx, &thisCast->requestedByClientID);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const struct NetMessageOps GetStatesAndBuddyGroupsMsg_Ops = {
|
||||
.serializePayload = GetStatesAndBuddyGroupsMsg_serializePayload,
|
||||
.deserializePayload = GetStatesAndBuddyGroupsMsg_deserializePayload,
|
||||
.processIncoming = NetMessage_processIncoming,
|
||||
.getSupportedHeaderFeatureFlagsMask = NetMessage_getSupportedHeaderFeatureFlagsMask,
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef GETSTATESANDBUDDYGROUPSMSG_H_
|
||||
#define GETSTATESANDBUDDYGROUPSMSG_H_
|
||||
|
||||
#include <common/net/message/NetMessage.h>
|
||||
#include "common/nodes/NumNodeID.h"
|
||||
#include <common/nodes/Node.h>
|
||||
|
||||
struct GetStatesAndBuddyGroupsMsg;
|
||||
typedef struct GetStatesAndBuddyGroupsMsg GetStatesAndBuddyGroupsMsg;
|
||||
|
||||
|
||||
static inline void GetStatesAndBuddyGroupsMsg_init(GetStatesAndBuddyGroupsMsg* this,
|
||||
NodeType nodeType, NumNodeID requestedByClientID);
|
||||
|
||||
|
||||
struct GetStatesAndBuddyGroupsMsg
|
||||
{
|
||||
NetMessage netMessage;
|
||||
|
||||
NodeType nodeType;
|
||||
NumNodeID requestedByClientID;
|
||||
};
|
||||
|
||||
extern const struct NetMessageOps GetStatesAndBuddyGroupsMsg_Ops;
|
||||
|
||||
void GetStatesAndBuddyGroupsMsg_init(GetStatesAndBuddyGroupsMsg* this, NodeType nodeType, NumNodeID requestedByClientID)
|
||||
{
|
||||
NetMessage_init(&this->netMessage, NETMSGTYPE_GetStatesAndBuddyGroups, &GetStatesAndBuddyGroupsMsg_Ops);
|
||||
|
||||
this->nodeType = nodeType;
|
||||
this->requestedByClientID = requestedByClientID;
|
||||
}
|
||||
|
||||
#endif /* GETSTATESANDBUDDYGROUPSMSG_H_ */
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "GetStatesAndBuddyGroupsRespMsg.h"
|
||||
|
||||
static void GetStatesAndBuddyGroupsRespMsg_release(NetMessage* msg)
|
||||
{
|
||||
GetStatesAndBuddyGroupsRespMsg* this = container_of(msg, struct GetStatesAndBuddyGroupsRespMsg,
|
||||
netMessage);
|
||||
|
||||
BEEGFS_KFREE_LIST(&this->groups, struct BuddyGroupMapping, _list);
|
||||
BEEGFS_KFREE_LIST(&this->states, struct TargetStateMapping, _list);
|
||||
}
|
||||
|
||||
const struct NetMessageOps GetStatesAndBuddyGroupsRespMsg_Ops = {
|
||||
.serializePayload = _NetMessage_serializeDummy,
|
||||
.deserializePayload = GetStatesAndBuddyGroupsRespMsg_deserializePayload,
|
||||
.processIncoming = NetMessage_processIncoming,
|
||||
.getSupportedHeaderFeatureFlagsMask = NetMessage_getSupportedHeaderFeatureFlagsMask,
|
||||
.release = GetStatesAndBuddyGroupsRespMsg_release,
|
||||
};
|
||||
|
||||
bool GetStatesAndBuddyGroupsRespMsg_deserializePayload(NetMessage* this, DeserializeCtx* ctx)
|
||||
{
|
||||
GetStatesAndBuddyGroupsRespMsg* thisCast = (GetStatesAndBuddyGroupsRespMsg*)this;
|
||||
|
||||
if (!BuddyGroupMappingList_deserialize(ctx, &thisCast->groups))
|
||||
return false;
|
||||
|
||||
if (!TargetStateMappingList_deserialize(ctx, &thisCast->states))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef GETSTATESANDBUDDYGROUPSRESPMSG_H_
|
||||
#define GETSTATESANDBUDDYGROUPSRESPMSG_H_
|
||||
|
||||
#include <common/net/message/NetMessage.h>
|
||||
#include <common/Common.h>
|
||||
#include <common/Types.h>
|
||||
|
||||
|
||||
struct GetStatesAndBuddyGroupsRespMsg;
|
||||
typedef struct GetStatesAndBuddyGroupsRespMsg GetStatesAndBuddyGroupsRespMsg;
|
||||
|
||||
static inline void GetStatesAndBuddyGroupsRespMsg_init(GetStatesAndBuddyGroupsRespMsg* this);
|
||||
|
||||
// virtual functions
|
||||
extern bool GetStatesAndBuddyGroupsRespMsg_deserializePayload(NetMessage* this,
|
||||
DeserializeCtx* ctx);
|
||||
|
||||
/**
|
||||
* This message carries two maps:
|
||||
* 1) buddyGroupID -> primaryTarget, secondaryTarget
|
||||
* 2) targetID -> targetReachabilityState, targetConsistencyState
|
||||
*
|
||||
* Note: This message can only be received/deserialized (send/serialization not implemented).
|
||||
*/
|
||||
struct GetStatesAndBuddyGroupsRespMsg
|
||||
{
|
||||
NetMessage netMessage;
|
||||
|
||||
struct list_head groups; /* struct BuddyGroupMapping */
|
||||
struct list_head states; /* struct TargetStateMapping */
|
||||
};
|
||||
extern const struct NetMessageOps GetStatesAndBuddyGroupsRespMsg_Ops;
|
||||
|
||||
void GetStatesAndBuddyGroupsRespMsg_init(GetStatesAndBuddyGroupsRespMsg* this)
|
||||
{
|
||||
NetMessage_init(&this->netMessage, NETMSGTYPE_GetStatesAndBuddyGroupsResp,
|
||||
&GetStatesAndBuddyGroupsRespMsg_Ops);
|
||||
|
||||
INIT_LIST_HEAD(&this->groups);
|
||||
INIT_LIST_HEAD(&this->states);
|
||||
}
|
||||
|
||||
#endif /* GETSTATESANDBUDDYGROUPSRESPMSG_H_ */
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef GETTARGETMAPPINGSMSG_H_
|
||||
#define GETTARGETMAPPINGSMSG_H_
|
||||
|
||||
#include "../SimpleMsg.h"
|
||||
|
||||
|
||||
struct GetTargetMappingsMsg;
|
||||
typedef struct GetTargetMappingsMsg GetTargetMappingsMsg;
|
||||
|
||||
static inline void GetTargetMappingsMsg_init(GetTargetMappingsMsg* this);
|
||||
|
||||
|
||||
struct GetTargetMappingsMsg
|
||||
{
|
||||
SimpleMsg simpleMsg;
|
||||
};
|
||||
|
||||
|
||||
void GetTargetMappingsMsg_init(GetTargetMappingsMsg* this)
|
||||
{
|
||||
SimpleMsg_init( (SimpleMsg*)this, NETMSGTYPE_GetTargetMappings);
|
||||
}
|
||||
|
||||
#endif /* GETTARGETMAPPINGSMSG_H_ */
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "GetTargetMappingsRespMsg.h"
|
||||
|
||||
#include <common/nodes/TargetMapper.h>
|
||||
|
||||
static void GetTargetMappingsRespMsg_release(NetMessage* this)
|
||||
{
|
||||
GetTargetMappingsRespMsg* thisCast = (GetTargetMappingsRespMsg*)this;
|
||||
|
||||
BEEGFS_KFREE_LIST(&thisCast->mappings, struct TargetMapping, _list);
|
||||
}
|
||||
|
||||
bool GetTargetMappingsRespMsg_deserializePayload(NetMessage* this, DeserializeCtx* ctx)
|
||||
{
|
||||
GetTargetMappingsRespMsg* thisCast = (GetTargetMappingsRespMsg*)this;
|
||||
|
||||
if (!TargetMappingList_deserialize(ctx, &thisCast->mappings))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const struct NetMessageOps GetTargetMappingsRespMsg_Ops = {
|
||||
.serializePayload = _NetMessage_serializeDummy,
|
||||
.deserializePayload = GetTargetMappingsRespMsg_deserializePayload,
|
||||
.processIncoming = NetMessage_processIncoming,
|
||||
.getSupportedHeaderFeatureFlagsMask = NetMessage_getSupportedHeaderFeatureFlagsMask,
|
||||
.release = GetTargetMappingsRespMsg_release,
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef GETTARGETMAPPINGSRESPMSG_H_
|
||||
#define GETTARGETMAPPINGSRESPMSG_H_
|
||||
|
||||
#include <common/net/message/NetMessage.h>
|
||||
#include <common/Common.h>
|
||||
|
||||
/**
|
||||
* Note: This message can only be received/deserialized (send/serialization not implemented)
|
||||
*/
|
||||
|
||||
|
||||
struct GetTargetMappingsRespMsg;
|
||||
typedef struct GetTargetMappingsRespMsg GetTargetMappingsRespMsg;
|
||||
|
||||
static inline void GetTargetMappingsRespMsg_init(GetTargetMappingsRespMsg* this);
|
||||
|
||||
// virtual functions
|
||||
extern bool GetTargetMappingsRespMsg_deserializePayload(NetMessage* this, DeserializeCtx* ctx);
|
||||
|
||||
|
||||
struct GetTargetMappingsRespMsg
|
||||
{
|
||||
NetMessage netMessage;
|
||||
|
||||
struct list_head mappings; /* TargetMapping */
|
||||
};
|
||||
|
||||
extern const struct NetMessageOps GetTargetMappingsRespMsg_Ops;
|
||||
|
||||
void GetTargetMappingsRespMsg_init(GetTargetMappingsRespMsg* this)
|
||||
{
|
||||
NetMessage_init(&this->netMessage, NETMSGTYPE_GetTargetMappingsResp,
|
||||
&GetTargetMappingsRespMsg_Ops);
|
||||
|
||||
INIT_LIST_HEAD(&this->mappings);
|
||||
}
|
||||
|
||||
#endif /* GETTARGETMAPPINGSRESPMSG_H_ */
|
||||
257
client_module/source/common/net/message/nodes/HeartbeatMsgEx.c
Normal file
257
client_module/source/common/net/message/nodes/HeartbeatMsgEx.c
Normal file
@@ -0,0 +1,257 @@
|
||||
#include <app/App.h>
|
||||
#include <common/nodes/Node.h>
|
||||
#include <common/toolkit/SocketTk.h>
|
||||
#include <common/net/msghelpers/MsgHelperAck.h>
|
||||
#include <common/toolkit/ListTk.h>
|
||||
#include <nodes/NodeStoreEx.h>
|
||||
#include <app/config/Config.h>
|
||||
#include "HeartbeatMsgEx.h"
|
||||
|
||||
const struct NetMessageOps HeartbeatMsgEx_Ops = {
|
||||
.serializePayload = HeartbeatMsgEx_serializePayload,
|
||||
.deserializePayload = HeartbeatMsgEx_deserializePayload,
|
||||
.processIncoming = __HeartbeatMsgEx_processIncoming,
|
||||
.getSupportedHeaderFeatureFlagsMask = NetMessage_getSupportedHeaderFeatureFlagsMask,
|
||||
};
|
||||
|
||||
void HeartbeatMsgEx_serializePayload(NetMessage* this, SerializeCtx* ctx)
|
||||
{
|
||||
HeartbeatMsgEx* thisCast = (HeartbeatMsgEx*)this;
|
||||
|
||||
// instanceVersion
|
||||
Serialization_serializeUInt64(ctx, thisCast->instanceVersion);
|
||||
|
||||
// nicListVersion
|
||||
Serialization_serializeUInt64(ctx, thisCast->nicListVersion);
|
||||
|
||||
// nodeType
|
||||
Serialization_serializeInt(ctx, thisCast->nodeType);
|
||||
|
||||
// nodeID
|
||||
Serialization_serializeStr(ctx, thisCast->nodeIDLen, thisCast->nodeID);
|
||||
|
||||
// ackID
|
||||
Serialization_serializeStrAlign4(ctx, thisCast->ackIDLen, thisCast->ackID);
|
||||
|
||||
// nodeNumID
|
||||
NumNodeID_serialize(ctx, &thisCast->nodeNumID);
|
||||
|
||||
// rootNumID
|
||||
NumNodeID_serialize(ctx, &thisCast->rootNumID);
|
||||
|
||||
// rootIsBuddyMirrored
|
||||
Serialization_serializeBool(ctx, thisCast->rootIsBuddyMirrored);
|
||||
|
||||
// portUDP
|
||||
Serialization_serializeUShort(ctx, thisCast->portUDP);
|
||||
|
||||
// portTCP
|
||||
Serialization_serializeUShort(ctx, thisCast->portTCP);
|
||||
|
||||
// nicList
|
||||
Serialization_serializeNicList(ctx, thisCast->nicList);
|
||||
|
||||
// machineUUID
|
||||
Serialization_serializeStr(ctx, thisCast->machineUUIDLen, thisCast->machineUUID);
|
||||
}
|
||||
|
||||
bool HeartbeatMsgEx_deserializePayload(NetMessage* this, DeserializeCtx* ctx)
|
||||
{
|
||||
HeartbeatMsgEx* thisCast = (HeartbeatMsgEx*)this;
|
||||
|
||||
// instanceVersion
|
||||
if(!Serialization_deserializeUInt64(ctx, &thisCast->instanceVersion) )
|
||||
return false;
|
||||
|
||||
// nicListVersion
|
||||
if(!Serialization_deserializeUInt64(ctx, &thisCast->nicListVersion) )
|
||||
return false;
|
||||
|
||||
// nodeType
|
||||
if(!Serialization_deserializeInt(ctx, &thisCast->nodeType) )
|
||||
return false;
|
||||
|
||||
// nodeID
|
||||
if(!Serialization_deserializeStr(ctx, &thisCast->nodeIDLen, &thisCast->nodeID) )
|
||||
return false;
|
||||
|
||||
// ackID
|
||||
if(!Serialization_deserializeStrAlign4(ctx, &thisCast->ackIDLen, &thisCast->ackID) )
|
||||
return false;
|
||||
|
||||
// nodeNumID
|
||||
if(!NumNodeID_deserialize(ctx, &thisCast->nodeNumID) )
|
||||
return false;
|
||||
|
||||
// rootNumID
|
||||
if(!NumNodeID_deserialize(ctx, &thisCast->rootNumID) )
|
||||
return false;
|
||||
|
||||
// rootIsBuddyMirrored
|
||||
if(!Serialization_deserializeBool(ctx, &thisCast->rootIsBuddyMirrored) )
|
||||
return false;
|
||||
|
||||
// portUDP
|
||||
if(!Serialization_deserializeUShort(ctx, &thisCast->portUDP) )
|
||||
return false;
|
||||
|
||||
// portTCP
|
||||
if(!Serialization_deserializeUShort(ctx, &thisCast->portTCP) )
|
||||
return false;
|
||||
|
||||
// nicList
|
||||
if(!Serialization_deserializeNicListPreprocess(ctx, &thisCast->rawNicList) )
|
||||
return false;
|
||||
|
||||
// machineUUID
|
||||
if(!Serialization_deserializeStr(ctx, &thisCast->machineUUIDLen, &thisCast->machineUUID) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool __HeartbeatMsgEx_processIncoming(NetMessage* this, struct App* app,
|
||||
fhgfs_sockaddr_in* fromAddr, struct Socket* sock, char* respBuf, size_t bufLen)
|
||||
{
|
||||
Logger* log = App_getLogger(app);
|
||||
const char* logContext = "Heartbeat incoming";
|
||||
|
||||
HeartbeatMsgEx* thisCast = (HeartbeatMsgEx*)this;
|
||||
|
||||
NicAddressList nicList;
|
||||
Node* node;
|
||||
NodeConnPool* connPool;
|
||||
Node* localNode;
|
||||
NicAddressList localNicList;
|
||||
NicListCapabilities localNicCaps;
|
||||
NodeStoreEx* nodes = NULL;
|
||||
bool isNodeNew;
|
||||
NumNodeID nodeNumID;
|
||||
int nodeType;
|
||||
|
||||
// check if nodeNumID is set
|
||||
nodeNumID = HeartbeatMsgEx_getNodeNumID(thisCast);
|
||||
if(NumNodeID_isZero(&nodeNumID))
|
||||
{ // shouldn't happen: this node would need to register first to get a nodeNumID assigned
|
||||
Logger_logFormatted(log, Log_WARNING, logContext,
|
||||
"Rejecting heartbeat of node without numeric ID: %s (Type: %s)",
|
||||
HeartbeatMsgEx_getNodeID(thisCast),
|
||||
Node_nodeTypeToStr(HeartbeatMsgEx_getNodeType(thisCast) ) );
|
||||
|
||||
goto ack_resp;
|
||||
}
|
||||
|
||||
// find the corresponding node store for this node type
|
||||
|
||||
nodeType = HeartbeatMsgEx_getNodeType(thisCast);
|
||||
switch(nodeType)
|
||||
{
|
||||
case NODETYPE_Meta:
|
||||
nodes = App_getMetaNodes(app); break;
|
||||
|
||||
case NODETYPE_Storage:
|
||||
nodes = App_getStorageNodes(app); break;
|
||||
|
||||
case NODETYPE_Mgmt:
|
||||
nodes = App_getMgmtNodes(app); break;
|
||||
|
||||
default:
|
||||
{
|
||||
const char* nodeID = HeartbeatMsgEx_getNodeID(thisCast);
|
||||
|
||||
Logger_logErrFormatted(log, logContext, "Invalid node type: %d (%s); ID: %s",
|
||||
nodeType, Node_nodeTypeToStr(nodeType), nodeID);
|
||||
|
||||
goto ack_resp;
|
||||
} break;
|
||||
}
|
||||
|
||||
// construct node
|
||||
|
||||
NicAddressList_init(&nicList);
|
||||
|
||||
HeartbeatMsgEx_parseNicList(thisCast, &nicList);
|
||||
|
||||
App_lockNicList(app);
|
||||
node = Node_construct(app,
|
||||
HeartbeatMsgEx_getNodeID(thisCast), HeartbeatMsgEx_getNodeNumID(thisCast),
|
||||
HeartbeatMsgEx_getPortUDP(thisCast), HeartbeatMsgEx_getPortTCP(thisCast), &nicList,
|
||||
nodeType == NODETYPE_Meta || nodeType == NODETYPE_Storage? App_getLocalRDMANicListLocked(app) : NULL);
|
||||
// (will belong to the NodeStore => no destruct() required)
|
||||
App_unlockNicList(app);
|
||||
|
||||
Node_setNodeAliasAndType(node, NULL, nodeType);
|
||||
|
||||
// set local nic capabilities
|
||||
|
||||
localNode = App_getLocalNode(app);
|
||||
Node_cloneNicList(localNode, &localNicList);
|
||||
connPool = Node_getConnPool(node);
|
||||
|
||||
NIC_supportedCapabilities(&localNicList, &localNicCaps);
|
||||
NodeConnPool_setLocalNicCaps(connPool, &localNicCaps);
|
||||
|
||||
// add node to store (or update it)
|
||||
|
||||
isNodeNew = NodeStoreEx_addOrUpdateNode(nodes, &node);
|
||||
if(isNodeNew)
|
||||
{
|
||||
bool supportsRDMA = NIC_supportsRDMA(&nicList);
|
||||
|
||||
Logger_logFormatted(log, Log_WARNING, logContext,
|
||||
"New node: %s %s [ID: %hu]; %s",
|
||||
Node_nodeTypeToStr(nodeType),
|
||||
HeartbeatMsgEx_getNodeID(thisCast),
|
||||
HeartbeatMsgEx_getNodeNumID(thisCast).value,
|
||||
(supportsRDMA ? "RDMA; " : "") );
|
||||
}
|
||||
|
||||
__HeartbeatMsgEx_processIncomingRoot(thisCast, app);
|
||||
|
||||
ack_resp:
|
||||
// send ack
|
||||
MsgHelperAck_respondToAckRequest(app, HeartbeatMsgEx_getAckID(thisCast), fromAddr, sock,
|
||||
respBuf, bufLen);
|
||||
|
||||
// clean-up
|
||||
ListTk_kfreeNicAddressListElems(&nicList);
|
||||
NicAddressList_uninit(&nicList);
|
||||
ListTk_kfreeNicAddressListElems(&localNicList);
|
||||
NicAddressList_uninit(&localNicList);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the contained root information.
|
||||
*/
|
||||
void __HeartbeatMsgEx_processIncomingRoot(HeartbeatMsgEx* this, App* app)
|
||||
{
|
||||
Logger* log = App_getLogger(app);
|
||||
const char* logContext = "Heartbeat incoming (root)";
|
||||
|
||||
NodeStoreEx* metaNodes;
|
||||
bool setRootRes;
|
||||
NodeOrGroup rootOwner = this->rootIsBuddyMirrored
|
||||
? NodeOrGroup_fromGroup(this->rootNumID.value)
|
||||
: NodeOrGroup_fromNode(this->rootNumID);
|
||||
NumNodeID rootNumID = HeartbeatMsgEx_getRootNumID(this);
|
||||
|
||||
// check whether root info is defined
|
||||
if( (HeartbeatMsgEx_getNodeType(this) != NODETYPE_Meta) || (NumNodeID_isZero(&rootNumID)))
|
||||
return;
|
||||
|
||||
// try to apply the contained root info
|
||||
|
||||
metaNodes = App_getMetaNodes(app);
|
||||
|
||||
setRootRes = NodeStoreEx_setRootOwner(metaNodes, rootOwner, false);
|
||||
|
||||
if(setRootRes)
|
||||
{ // found the very first root
|
||||
Logger_logFormatted(log, Log_CRITICAL, logContext, "Root (by Heartbeat): %hu",
|
||||
HeartbeatMsgEx_getRootNumID(this).value );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
152
client_module/source/common/net/message/nodes/HeartbeatMsgEx.h
Normal file
152
client_module/source/common/net/message/nodes/HeartbeatMsgEx.h
Normal file
@@ -0,0 +1,152 @@
|
||||
#ifndef HEARTBEATMSG_H_
|
||||
#define HEARTBEATMSG_H_
|
||||
|
||||
#include <common/net/message/NetMessage.h>
|
||||
#include <common/net/sock/NetworkInterfaceCard.h>
|
||||
|
||||
|
||||
struct HeartbeatMsgEx;
|
||||
typedef struct HeartbeatMsgEx HeartbeatMsgEx;
|
||||
|
||||
static inline void HeartbeatMsgEx_init(HeartbeatMsgEx* this);
|
||||
static inline void HeartbeatMsgEx_initFromNodeData(HeartbeatMsgEx* this,
|
||||
const char* nodeID, NumNodeID nodeNumID, int nodeType, NicAddressList* nicList);
|
||||
|
||||
extern void __HeartbeatMsgEx_processIncomingRoot(HeartbeatMsgEx* this, struct App* app);
|
||||
|
||||
// virtual functions
|
||||
extern void HeartbeatMsgEx_serializePayload(NetMessage* this, SerializeCtx* ctx);
|
||||
extern bool HeartbeatMsgEx_deserializePayload(NetMessage* this, DeserializeCtx* ctx);
|
||||
extern bool __HeartbeatMsgEx_processIncoming(NetMessage* this, struct App* app,
|
||||
fhgfs_sockaddr_in* fromAddr, struct Socket* sock, char* respBuf, size_t bufLen);
|
||||
|
||||
// inliners
|
||||
static inline void HeartbeatMsgEx_parseNicList(HeartbeatMsgEx* this,
|
||||
NicAddressList* outNicList);
|
||||
|
||||
// getters & setters
|
||||
static inline const char* HeartbeatMsgEx_getNodeID(HeartbeatMsgEx* this);
|
||||
static inline NumNodeID HeartbeatMsgEx_getNodeNumID(HeartbeatMsgEx* this);
|
||||
static inline int HeartbeatMsgEx_getNodeType(HeartbeatMsgEx* this);
|
||||
static inline NumNodeID HeartbeatMsgEx_getRootNumID(HeartbeatMsgEx* this);
|
||||
static inline const char* HeartbeatMsgEx_getAckID(HeartbeatMsgEx* this);
|
||||
static inline void HeartbeatMsgEx_setPorts(HeartbeatMsgEx* this,
|
||||
uint16_t portUDP, uint16_t portTCP);
|
||||
static inline uint16_t HeartbeatMsgEx_getPortUDP(HeartbeatMsgEx* this);
|
||||
static inline uint16_t HeartbeatMsgEx_getPortTCP(HeartbeatMsgEx* this);
|
||||
|
||||
|
||||
struct HeartbeatMsgEx
|
||||
{
|
||||
NetMessage netMessage;
|
||||
|
||||
unsigned nodeIDLen;
|
||||
const char* nodeID;
|
||||
int nodeType;
|
||||
NumNodeID nodeNumID;
|
||||
NumNodeID rootNumID; // 0 means unknown/undefined
|
||||
bool rootIsBuddyMirrored;
|
||||
uint64_t instanceVersion; // not used currently
|
||||
uint64_t nicListVersion; // not used currently
|
||||
uint16_t portUDP; // 0 means "undefined"
|
||||
uint16_t portTCP; // 0 means "undefined"
|
||||
unsigned ackIDLen;
|
||||
const char* ackID;
|
||||
const char* machineUUID;
|
||||
unsigned machineUUIDLen;
|
||||
|
||||
// for serialization
|
||||
NicAddressList* nicList; // not owned by this object
|
||||
|
||||
// for deserialization
|
||||
RawList rawNicList;
|
||||
};
|
||||
|
||||
extern const struct NetMessageOps HeartbeatMsgEx_Ops;
|
||||
|
||||
void HeartbeatMsgEx_init(HeartbeatMsgEx* this)
|
||||
{
|
||||
NetMessage_init(&this->netMessage, NETMSGTYPE_Heartbeat, &HeartbeatMsgEx_Ops);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeID just a reference, so do not free it as long as you use this object
|
||||
* @param nicList just a reference, so do not free it as long as you use this object
|
||||
*/
|
||||
void HeartbeatMsgEx_initFromNodeData(HeartbeatMsgEx* this,
|
||||
const char* nodeID, NumNodeID nodeNumID, int nodeType, NicAddressList* nicList)
|
||||
{
|
||||
HeartbeatMsgEx_init(this);
|
||||
|
||||
this->nodeID = nodeID;
|
||||
this->nodeIDLen = strlen(nodeID);
|
||||
this->nodeNumID = nodeNumID;
|
||||
|
||||
this->nodeType = nodeType;
|
||||
|
||||
this->rootNumID = (NumNodeID){0}; // 0 means undefined/unknown
|
||||
this->rootIsBuddyMirrored = false;
|
||||
|
||||
this->instanceVersion = 0; // reserverd for future use
|
||||
|
||||
this->nicListVersion = 0; // reserverd for future use
|
||||
this->nicList = nicList;
|
||||
|
||||
this->portUDP = 0; // 0 means "undefined"
|
||||
this->portTCP = 0; // 0 means "undefined"
|
||||
|
||||
this->ackID = "";
|
||||
this->ackIDLen = 0;
|
||||
|
||||
this->machineUUID = ""; // not currently needed on the client
|
||||
this->machineUUIDLen = 0;
|
||||
}
|
||||
|
||||
void HeartbeatMsgEx_parseNicList(HeartbeatMsgEx* this, NicAddressList* outNicList)
|
||||
{
|
||||
Serialization_deserializeNicList(&this->rawNicList, outNicList);
|
||||
}
|
||||
|
||||
const char* HeartbeatMsgEx_getNodeID(HeartbeatMsgEx* this)
|
||||
{
|
||||
return this->nodeID;
|
||||
}
|
||||
|
||||
NumNodeID HeartbeatMsgEx_getNodeNumID(HeartbeatMsgEx* this)
|
||||
{
|
||||
return this->nodeNumID;
|
||||
}
|
||||
|
||||
int HeartbeatMsgEx_getNodeType(HeartbeatMsgEx* this)
|
||||
{
|
||||
return this->nodeType;
|
||||
}
|
||||
|
||||
NumNodeID HeartbeatMsgEx_getRootNumID(HeartbeatMsgEx* this)
|
||||
{
|
||||
return this->rootNumID;
|
||||
}
|
||||
|
||||
const char* HeartbeatMsgEx_getAckID(HeartbeatMsgEx* this)
|
||||
{
|
||||
return this->ackID;
|
||||
}
|
||||
|
||||
void HeartbeatMsgEx_setPorts(HeartbeatMsgEx* this, uint16_t portUDP, uint16_t portTCP)
|
||||
{
|
||||
this->portUDP = portUDP;
|
||||
this->portTCP = portTCP;
|
||||
}
|
||||
|
||||
uint16_t HeartbeatMsgEx_getPortUDP(HeartbeatMsgEx* this)
|
||||
{
|
||||
return this->portUDP;
|
||||
}
|
||||
|
||||
uint16_t HeartbeatMsgEx_getPortTCP(HeartbeatMsgEx* this)
|
||||
{
|
||||
return this->portTCP;
|
||||
}
|
||||
|
||||
|
||||
#endif /*HEARTBEATMSG_H_*/
|
||||
@@ -0,0 +1,65 @@
|
||||
#include <common/nodes/Node.h>
|
||||
#include <components/DatagramListener.h>
|
||||
#include <common/toolkit/SocketTk.h>
|
||||
#include <app/App.h>
|
||||
#include "HeartbeatMsgEx.h"
|
||||
#include "HeartbeatRequestMsgEx.h"
|
||||
|
||||
|
||||
const struct NetMessageOps HeartbeatRequestMsgEx_Ops = {
|
||||
.serializePayload = SimpleMsg_serializePayload,
|
||||
.deserializePayload = SimpleMsg_deserializePayload,
|
||||
.processIncoming = __HeartbeatRequestMsgEx_processIncoming,
|
||||
.getSupportedHeaderFeatureFlagsMask = NetMessage_getSupportedHeaderFeatureFlagsMask,
|
||||
};
|
||||
|
||||
bool __HeartbeatRequestMsgEx_processIncoming(NetMessage* this, struct App* app,
|
||||
fhgfs_sockaddr_in* fromAddr, struct Socket* sock, char* respBuf, size_t bufLen)
|
||||
{
|
||||
Logger* log = App_getLogger(app);
|
||||
const char* logContext = "HeartbeatRequest incoming";
|
||||
|
||||
Config* cfg = App_getConfig(app);
|
||||
Node* localNode = App_getLocalNode(app);
|
||||
NodeString alias;
|
||||
NumNodeID localNodeNumID = Node_getNumID(localNode);
|
||||
NicAddressList nicList;
|
||||
|
||||
HeartbeatMsgEx hbMsg;
|
||||
unsigned respLen;
|
||||
bool serializeRes;
|
||||
ssize_t sendRes;
|
||||
|
||||
Node_cloneNicList(localNode, &nicList);
|
||||
Node_copyAlias(localNode, &alias);
|
||||
HeartbeatMsgEx_initFromNodeData(&hbMsg, alias.buf, localNodeNumID, NODETYPE_Client, &nicList);
|
||||
HeartbeatMsgEx_setPorts(&hbMsg, Config_getConnClientPort(cfg), 0);
|
||||
|
||||
respLen = NetMessage_getMsgLength( (NetMessage*)&hbMsg);
|
||||
serializeRes = NetMessage_serialize( (NetMessage*)&hbMsg, respBuf, bufLen);
|
||||
if(unlikely(!serializeRes) )
|
||||
{
|
||||
Logger_logErrFormatted(log, logContext, "Unable to serialize response");
|
||||
goto err_uninit;
|
||||
}
|
||||
|
||||
if(fromAddr)
|
||||
{ // datagram => sync via dgramLis send method
|
||||
DatagramListener* dgramLis = App_getDatagramListener(app);
|
||||
sendRes = DatagramListener_sendto_kernel(dgramLis, respBuf, respLen, 0, fromAddr);
|
||||
}
|
||||
else
|
||||
sendRes = Socket_sendto_kernel(sock, respBuf, respLen, 0, NULL);
|
||||
|
||||
if(unlikely(sendRes <= 0) )
|
||||
Logger_logErrFormatted(log, logContext, "Send error. ErrCode: %lld", (long long)sendRes);
|
||||
|
||||
err_uninit:
|
||||
|
||||
ListTk_kfreeNicAddressListElems(&nicList);
|
||||
NicAddressList_uninit(&nicList);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef HEARTBEATREQUESTMSGEX_H_
|
||||
#define HEARTBEATREQUESTMSGEX_H_
|
||||
|
||||
#include "../SimpleMsg.h"
|
||||
|
||||
|
||||
struct HeartbeatRequestMsgEx;
|
||||
typedef struct HeartbeatRequestMsgEx HeartbeatRequestMsgEx;
|
||||
|
||||
static inline void HeartbeatRequestMsgEx_init(HeartbeatRequestMsgEx* this);
|
||||
|
||||
// virtual functions
|
||||
extern bool __HeartbeatRequestMsgEx_processIncoming(NetMessage* this, struct App* app,
|
||||
fhgfs_sockaddr_in* fromAddr, struct Socket* sock, char* respBuf, size_t bufLen);
|
||||
|
||||
|
||||
struct HeartbeatRequestMsgEx
|
||||
{
|
||||
SimpleMsg simpleMsg;
|
||||
};
|
||||
|
||||
extern const struct NetMessageOps HeartbeatRequestMsgEx_Ops;
|
||||
|
||||
void HeartbeatRequestMsgEx_init(HeartbeatRequestMsgEx* this)
|
||||
{
|
||||
SimpleMsg_init(&this->simpleMsg, NETMSGTYPE_HeartbeatRequest);
|
||||
this->simpleMsg.netMessage.ops = &HeartbeatRequestMsgEx_Ops;
|
||||
}
|
||||
|
||||
#endif /* HEARTBEATREQUESTMSGEX_H_ */
|
||||
@@ -0,0 +1,84 @@
|
||||
#include <app/App.h>
|
||||
#include <common/nodes/Node.h>
|
||||
#include <common/toolkit/SocketTk.h>
|
||||
#include <common/net/msghelpers/MsgHelperAck.h>
|
||||
#include <common/toolkit/ListTk.h>
|
||||
#include <nodes/NodeStoreEx.h>
|
||||
#include <app/config/Config.h>
|
||||
#include "MapTargetsMsgEx.h"
|
||||
|
||||
|
||||
static void MapTargetsMsgEx_release(NetMessage* msg)
|
||||
{
|
||||
MapTargetsMsgEx* this = container_of(msg, struct MapTargetsMsgEx, netMessage);
|
||||
|
||||
BEEGFS_KFREE_LIST(&this->poolMappings, struct TargetPoolMapping, _list);
|
||||
}
|
||||
|
||||
const struct NetMessageOps MapTargetsMsgEx_Ops = {
|
||||
.serializePayload = _NetMessage_serializeDummy,
|
||||
.deserializePayload = MapTargetsMsgEx_deserializePayload,
|
||||
.processIncoming = __MapTargetsMsgEx_processIncoming,
|
||||
.getSupportedHeaderFeatureFlagsMask = NetMessage_getSupportedHeaderFeatureFlagsMask,
|
||||
.release = MapTargetsMsgEx_release,
|
||||
};
|
||||
|
||||
bool MapTargetsMsgEx_deserializePayload(NetMessage* this, DeserializeCtx* ctx)
|
||||
{
|
||||
MapTargetsMsgEx* thisCast = (MapTargetsMsgEx*)this;
|
||||
|
||||
// targets
|
||||
if (!TargetPoolMappingList_deserialize(ctx, &thisCast->poolMappings))
|
||||
return false;
|
||||
|
||||
// nodeID
|
||||
if(!NumNodeID_deserialize(ctx, &thisCast->nodeID) )
|
||||
return false;
|
||||
|
||||
// ackID
|
||||
if(!Serialization_deserializeStr(ctx, &thisCast->ackIDLen, &thisCast->ackID) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool __MapTargetsMsgEx_processIncoming(NetMessage* this, struct App* app,
|
||||
fhgfs_sockaddr_in* fromAddr, struct Socket* sock, char* respBuf, size_t bufLen)
|
||||
{
|
||||
Logger* log = App_getLogger(app);
|
||||
const char* logContext = "MapTargetsMsg incoming";
|
||||
|
||||
MapTargetsMsgEx* thisCast = (MapTargetsMsgEx*)this;
|
||||
|
||||
const char* peer;
|
||||
|
||||
TargetMapper* targetMapper = App_getTargetMapper(app);
|
||||
NumNodeID nodeID = MapTargetsMsgEx_getNodeID(thisCast);
|
||||
struct TargetPoolMapping* mapping;
|
||||
|
||||
|
||||
peer = fromAddr ?
|
||||
SocketTk_ipaddrToStr(fromAddr->addr) : StringTk_strDup(Socket_getPeername(sock) );
|
||||
LOG_DEBUG_FORMATTED(log, 4, logContext, "Received a MapTargetsMsg from: %s", peer);
|
||||
kfree(peer);
|
||||
|
||||
IGNORE_UNUSED_VARIABLE(log);
|
||||
IGNORE_UNUSED_VARIABLE(logContext);
|
||||
|
||||
list_for_each_entry(mapping, &thisCast->poolMappings, _list)
|
||||
{
|
||||
bool wasNewTarget = TargetMapper_mapTarget(targetMapper, mapping->targetID, nodeID);
|
||||
if(wasNewTarget)
|
||||
{
|
||||
LOG_DEBUG_FORMATTED(log, Log_WARNING, logContext, "Mapping target %hu => node %hu",
|
||||
mapping->targetID, nodeID.value);
|
||||
}
|
||||
}
|
||||
|
||||
// send ack
|
||||
MsgHelperAck_respondToAckRequest(app, MapTargetsMsgEx_getAckID(thisCast), fromAddr, sock,
|
||||
respBuf, bufLen);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#ifndef MAPTARGETSMSGEX_H_
|
||||
#define MAPTARGETSMSGEX_H_
|
||||
|
||||
#include <common/net/message/NetMessage.h>
|
||||
#include <common/Common.h>
|
||||
#include <common/storage/StoragePoolId.h>
|
||||
|
||||
/**
|
||||
* Note: Only the receive/deserialize part of this message is implemented (so it cannot be sent).
|
||||
* Note: Processing only sends response when ackID is set (no MapTargetsRespMsg implemented).
|
||||
*/
|
||||
|
||||
struct MapTargetsMsgEx;
|
||||
typedef struct MapTargetsMsgEx MapTargetsMsgEx;
|
||||
|
||||
static inline void MapTargetsMsgEx_init(MapTargetsMsgEx* this);
|
||||
|
||||
// virtual functions
|
||||
extern bool MapTargetsMsgEx_deserializePayload(NetMessage* this, DeserializeCtx* ctx);
|
||||
extern bool __MapTargetsMsgEx_processIncoming(NetMessage* this, struct App* app,
|
||||
fhgfs_sockaddr_in* fromAddr, struct Socket* sock, char* respBuf, size_t bufLen);
|
||||
|
||||
// getters & setters
|
||||
static inline NumNodeID MapTargetsMsgEx_getNodeID(MapTargetsMsgEx* this);
|
||||
static inline const char* MapTargetsMsgEx_getAckID(MapTargetsMsgEx* this);
|
||||
|
||||
|
||||
struct MapTargetsMsgEx
|
||||
{
|
||||
NetMessage netMessage;
|
||||
|
||||
NumNodeID nodeID;
|
||||
unsigned ackIDLen;
|
||||
const char* ackID;
|
||||
|
||||
struct list_head poolMappings; /* struct TargetPoolMapping */
|
||||
};
|
||||
|
||||
extern const struct NetMessageOps MapTargetsMsgEx_Ops;
|
||||
|
||||
void MapTargetsMsgEx_init(MapTargetsMsgEx* this)
|
||||
{
|
||||
NetMessage_init(&this->netMessage, NETMSGTYPE_MapTargets, &MapTargetsMsgEx_Ops);
|
||||
|
||||
INIT_LIST_HEAD(&this->poolMappings);
|
||||
}
|
||||
|
||||
NumNodeID MapTargetsMsgEx_getNodeID(MapTargetsMsgEx* this)
|
||||
{
|
||||
return this->nodeID;
|
||||
}
|
||||
|
||||
const char* MapTargetsMsgEx_getAckID(MapTargetsMsgEx* this)
|
||||
{
|
||||
return this->ackID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* MAPTARGETSMSGEX_H_ */
|
||||
@@ -0,0 +1,53 @@
|
||||
#include <app/App.h>
|
||||
#include <common/toolkit/SocketTk.h>
|
||||
#include <common/net/msghelpers/MsgHelperAck.h>
|
||||
#include <components/InternodeSyncer.h>
|
||||
|
||||
#include "RefreshTargetStatesMsgEx.h"
|
||||
|
||||
|
||||
const struct NetMessageOps RefreshTargetStatesMsgEx_Ops = {
|
||||
.serializePayload = _NetMessage_serializeDummy,
|
||||
.deserializePayload = RefreshTargetStatesMsgEx_deserializePayload,
|
||||
.processIncoming = __RefreshTargetStatesMsgEx_processIncoming,
|
||||
.getSupportedHeaderFeatureFlagsMask = NetMessage_getSupportedHeaderFeatureFlagsMask,
|
||||
};
|
||||
|
||||
bool RefreshTargetStatesMsgEx_deserializePayload(NetMessage* this, DeserializeCtx* ctx)
|
||||
{
|
||||
RefreshTargetStatesMsgEx* thisCast = (RefreshTargetStatesMsgEx*)this;
|
||||
|
||||
// ackID
|
||||
if(!Serialization_deserializeStr(ctx, &thisCast->ackIDLen, &thisCast->ackID) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool __RefreshTargetStatesMsgEx_processIncoming(NetMessage* this, struct App* app,
|
||||
fhgfs_sockaddr_in* fromAddr, struct Socket* sock, char* respBuf, size_t bufLen)
|
||||
{
|
||||
Logger* log = App_getLogger(app);
|
||||
const char* logContext = "RefreshTargetStatesMsg incoming";
|
||||
|
||||
RefreshTargetStatesMsgEx* thisCast = (RefreshTargetStatesMsgEx*)this;
|
||||
|
||||
const char* peer;
|
||||
|
||||
InternodeSyncer* internodeSyncer = App_getInternodeSyncer(app);
|
||||
InternodeSyncer_setForceTargetStatesUpdate(internodeSyncer);
|
||||
|
||||
peer = fromAddr ?
|
||||
SocketTk_ipaddrToStr(fromAddr->addr) : StringTk_strDup(Socket_getPeername(sock) );
|
||||
LOG_DEBUG_FORMATTED(log, 4, logContext, "Received a RefreshTargetStatesMsg from: %s", peer);
|
||||
kfree(peer);
|
||||
|
||||
IGNORE_UNUSED_VARIABLE(log);
|
||||
IGNORE_UNUSED_VARIABLE(logContext);
|
||||
|
||||
// send ack
|
||||
MsgHelperAck_respondToAckRequest(app, RefreshTargetStatesMsgEx_getAckID(thisCast), fromAddr,
|
||||
sock, respBuf, bufLen);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef REFRESHTARGETSTATESMSGEX_H_
|
||||
#define REFRESHTARGETSTATESMSGEX_H_
|
||||
|
||||
#include <common/net/message/NetMessage.h>
|
||||
#include <common/Common.h>
|
||||
|
||||
/**
|
||||
* Note: Only the receive/deserialize part of this message is implemented (so it cannot be sent).
|
||||
* Note: Processing only sends response when ackID is set (no RefreshTargetStatesRespMsg
|
||||
* implemented).
|
||||
*/
|
||||
|
||||
struct RefreshTargetStatesMsgEx;
|
||||
typedef struct RefreshTargetStatesMsgEx RefreshTargetStatesMsgEx;
|
||||
|
||||
static inline void RefreshTargetStatesMsgEx_init(RefreshTargetStatesMsgEx* this);
|
||||
|
||||
// virtual functions
|
||||
extern bool RefreshTargetStatesMsgEx_deserializePayload(NetMessage* this, DeserializeCtx* ctx);
|
||||
extern bool __RefreshTargetStatesMsgEx_processIncoming(NetMessage* this, struct App* app,
|
||||
fhgfs_sockaddr_in* fromAddr, struct Socket* sock, char* respBuf, size_t bufLen);
|
||||
|
||||
// getters & setters
|
||||
static inline const char* RefreshTargetStatesMsgEx_getAckID(RefreshTargetStatesMsgEx* this);
|
||||
|
||||
|
||||
struct RefreshTargetStatesMsgEx
|
||||
{
|
||||
NetMessage netMessage;
|
||||
|
||||
unsigned ackIDLen;
|
||||
const char* ackID;
|
||||
};
|
||||
|
||||
extern const struct NetMessageOps RefreshTargetStatesMsgEx_Ops;
|
||||
|
||||
void RefreshTargetStatesMsgEx_init(RefreshTargetStatesMsgEx* this)
|
||||
{
|
||||
NetMessage_init(&this->netMessage, NETMSGTYPE_RefreshTargetStates, &RefreshTargetStatesMsgEx_Ops);
|
||||
}
|
||||
|
||||
const char* RefreshTargetStatesMsgEx_getAckID(RefreshTargetStatesMsgEx* this)
|
||||
{
|
||||
return this->ackID;
|
||||
}
|
||||
|
||||
#endif /* REFRESHTARGETSTATESMSGEX_H_ */
|
||||
@@ -0,0 +1,46 @@
|
||||
#include "RegisterNodeMsg.h"
|
||||
|
||||
const struct NetMessageOps RegisterNodeMsg_Ops = {
|
||||
.serializePayload = RegisterNodeMsg_serializePayload,
|
||||
.deserializePayload = _NetMessage_deserializeDummy,
|
||||
.processIncoming = NetMessage_processIncoming,
|
||||
.getSupportedHeaderFeatureFlagsMask = NetMessage_getSupportedHeaderFeatureFlagsMask,
|
||||
};
|
||||
|
||||
void RegisterNodeMsg_serializePayload(NetMessage* this, SerializeCtx* ctx)
|
||||
{
|
||||
RegisterNodeMsg* thisCast = (RegisterNodeMsg*)this;
|
||||
|
||||
// instanceVersion
|
||||
Serialization_serializeUInt64(ctx, thisCast->instanceVersion);
|
||||
|
||||
// nicListVersion
|
||||
Serialization_serializeUInt64(ctx, thisCast->nicListVersion);
|
||||
|
||||
// nodeID
|
||||
Serialization_serializeStr(ctx, thisCast->nodeIDLen, thisCast->nodeID);
|
||||
|
||||
// nicList
|
||||
Serialization_serializeNicList(ctx, thisCast->nicList);
|
||||
|
||||
// nodeType
|
||||
Serialization_serializeInt(ctx, thisCast->nodeType);
|
||||
|
||||
// nodeNumID
|
||||
NumNodeID_serialize(ctx, &thisCast->nodeNumID);
|
||||
|
||||
// rootNumID
|
||||
NumNodeID_serialize(ctx, &thisCast->rootNumID);
|
||||
|
||||
// rootIsBuddyMirrored
|
||||
Serialization_serializeBool(ctx, thisCast->rootIsBuddyMirrored);
|
||||
|
||||
// portUDP
|
||||
Serialization_serializeUShort(ctx, thisCast->portUDP);
|
||||
|
||||
// portTCP
|
||||
Serialization_serializeUShort(ctx, thisCast->portTCP);
|
||||
|
||||
// machineUUID
|
||||
Serialization_serializeStr(ctx, thisCast->machineUUIDLen, thisCast->machineUUID);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
#ifndef REGISTERNODEMSG_H
|
||||
#define REGISTERNODEMSG_H
|
||||
|
||||
#include <common/net/message/NetMessage.h>
|
||||
#include <common/net/sock/NetworkInterfaceCard.h>
|
||||
#include <toolkit/BitStore.h>
|
||||
|
||||
struct RegisterNodeMsg;
|
||||
typedef struct RegisterNodeMsg RegisterNodeMsg;
|
||||
|
||||
static inline void RegisterNodeMsg_init(RegisterNodeMsg* this);
|
||||
static inline void RegisterNodeMsg_initFromNodeData(RegisterNodeMsg* this, const char* nodeID,
|
||||
const NumNodeID nodeNumID, const int nodeType, NicAddressList* nicList, const uint16_t portUDP);
|
||||
|
||||
// virtual functions
|
||||
extern void RegisterNodeMsg_serializePayload(NetMessage* this, SerializeCtx* ctx);
|
||||
|
||||
struct RegisterNodeMsg
|
||||
{
|
||||
NetMessage netMessage;
|
||||
|
||||
const char* nodeID; // not owned by this object
|
||||
unsigned nodeIDLen;
|
||||
NumNodeID nodeNumID;
|
||||
|
||||
NumNodeID rootNumID;
|
||||
bool rootIsBuddyMirrored;
|
||||
|
||||
int nodeType;
|
||||
|
||||
NicAddressList* nicList; // not owned by this object
|
||||
|
||||
uint16_t portUDP;
|
||||
uint16_t portTCP;
|
||||
|
||||
uint64_t instanceVersion; // not used currently
|
||||
uint64_t nicListVersion; // not used currently
|
||||
|
||||
const char* machineUUID;
|
||||
unsigned machineUUIDLen;
|
||||
};
|
||||
|
||||
extern const struct NetMessageOps RegisterNodeMsg_Ops;
|
||||
|
||||
void RegisterNodeMsg_init(RegisterNodeMsg* this)
|
||||
{
|
||||
NetMessage_init(&this->netMessage, NETMSGTYPE_RegisterNode, &RegisterNodeMsg_Ops);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeID just a reference, so do not free it as long as you use this object
|
||||
* @param nicList just a reference, so do not free it as long as you use this object
|
||||
*/
|
||||
void RegisterNodeMsg_initFromNodeData(RegisterNodeMsg* this, const char* nodeID,
|
||||
const NumNodeID nodeNumID, const int nodeType,
|
||||
NicAddressList* nicList, const uint16_t portUDP)
|
||||
{
|
||||
RegisterNodeMsg_init(this);
|
||||
|
||||
this->nodeID = nodeID;
|
||||
this->nodeIDLen = strlen(nodeID);
|
||||
this->nodeNumID = nodeNumID;
|
||||
this->nodeType = nodeType;
|
||||
this->nicList = nicList;
|
||||
this->portUDP = portUDP;
|
||||
|
||||
// not used in client, but general RegisterNodeMsg has it and expects it to be serialized
|
||||
this->rootNumID = (NumNodeID){0};
|
||||
this->rootIsBuddyMirrored = false;
|
||||
|
||||
this->nicListVersion = 0; // undefined
|
||||
this->instanceVersion = 0; // undefined
|
||||
this->portTCP = 0; // undefined
|
||||
this->machineUUID = ""; // not currently needed on the client
|
||||
this->machineUUIDLen = 0;
|
||||
}
|
||||
|
||||
#endif /*REGISTERNODEMSG_H*/
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "RegisterNodeRespMsg.h"
|
||||
|
||||
const struct NetMessageOps RegisterNodeRespMsg_Ops = {
|
||||
.serializePayload = _NetMessage_serializeDummy, // serialization not implemented
|
||||
.deserializePayload = RegisterNodeRespMsg_deserializePayload,
|
||||
.processIncoming = NetMessage_processIncoming,
|
||||
.getSupportedHeaderFeatureFlagsMask = NetMessage_getSupportedHeaderFeatureFlagsMask,
|
||||
};
|
||||
|
||||
bool RegisterNodeRespMsg_deserializePayload(NetMessage* this, DeserializeCtx* ctx)
|
||||
{
|
||||
RegisterNodeRespMsg* thisCast = (RegisterNodeRespMsg*)this;
|
||||
|
||||
// nodeNumID
|
||||
if(!NumNodeID_deserialize(ctx, &thisCast->nodeNumID) )
|
||||
return false;
|
||||
|
||||
// GRPC Port
|
||||
if(!Serialization_deserializeUShort(ctx, &thisCast->grpcPort) )
|
||||
return false;
|
||||
|
||||
// fsUUID
|
||||
if(!Serialization_deserializeStr(ctx, &thisCast->fsUUIDLen,
|
||||
&thisCast->fsUUID) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef REGISTERNODERESPMSG_H
|
||||
#define REGISTERNODERESPMSG_H
|
||||
|
||||
#include <common/net/message/NetMessage.h>
|
||||
|
||||
struct RegisterNodeRespMsg;
|
||||
typedef struct RegisterNodeRespMsg RegisterNodeRespMsg;
|
||||
|
||||
static inline void RegisterNodeRespMsg_init(RegisterNodeRespMsg* this);
|
||||
static inline NumNodeID RegisterNodeRespMsg_getNodeNumID(RegisterNodeRespMsg* this);
|
||||
static inline int RegisterNodeRespMsg_getGrpcPort(RegisterNodeRespMsg* this);
|
||||
static inline const char* RegisterNodeRespMsg_getFsUUID(RegisterNodeRespMsg* this);
|
||||
|
||||
// virtual functions
|
||||
extern bool RegisterNodeRespMsg_deserializePayload(NetMessage* this, DeserializeCtx* ctx);
|
||||
|
||||
struct RegisterNodeRespMsg
|
||||
{
|
||||
NetMessage netMessage;
|
||||
|
||||
NumNodeID nodeNumID;
|
||||
unsigned short grpcPort;
|
||||
unsigned fsUUIDLen;
|
||||
const char* fsUUID;
|
||||
};
|
||||
|
||||
extern const struct NetMessageOps RegisterNodeRespMsg_Ops;
|
||||
|
||||
void RegisterNodeRespMsg_init(RegisterNodeRespMsg* this)
|
||||
{
|
||||
NetMessage_init(&this->netMessage, NETMSGTYPE_RegisterNodeResp, &RegisterNodeRespMsg_Ops);
|
||||
}
|
||||
|
||||
NumNodeID RegisterNodeRespMsg_getNodeNumID(RegisterNodeRespMsg* this)
|
||||
{
|
||||
return this->nodeNumID;
|
||||
}
|
||||
|
||||
int RegisterNodeRespMsg_getGrpcPort(RegisterNodeRespMsg* this)
|
||||
{
|
||||
return this->grpcPort;
|
||||
}
|
||||
|
||||
const char* RegisterNodeRespMsg_getFsUUID(RegisterNodeRespMsg* this)
|
||||
{
|
||||
return this->fsUUID;
|
||||
}
|
||||
|
||||
#endif /*REGISTERNODERESPMSG_H*/
|
||||
126
client_module/source/common/net/message/nodes/RemoveNodeMsgEx.c
Normal file
126
client_module/source/common/net/message/nodes/RemoveNodeMsgEx.c
Normal file
@@ -0,0 +1,126 @@
|
||||
#include <common/nodes/Node.h>
|
||||
#include <components/DatagramListener.h>
|
||||
#include <nodes/NodeStoreEx.h>
|
||||
#include <common/toolkit/SocketTk.h>
|
||||
#include <common/net/msghelpers/MsgHelperAck.h>
|
||||
#include <app/App.h>
|
||||
#include "RemoveNodeRespMsg.h"
|
||||
#include "RemoveNodeMsgEx.h"
|
||||
|
||||
|
||||
const struct NetMessageOps RemoveNodeMsgEx_Ops = {
|
||||
.serializePayload = RemoveNodeMsgEx_serializePayload,
|
||||
.deserializePayload = RemoveNodeMsgEx_deserializePayload,
|
||||
.processIncoming = __RemoveNodeMsgEx_processIncoming,
|
||||
.getSupportedHeaderFeatureFlagsMask = NetMessage_getSupportedHeaderFeatureFlagsMask,
|
||||
};
|
||||
|
||||
void RemoveNodeMsgEx_serializePayload(NetMessage* this, SerializeCtx* ctx)
|
||||
{
|
||||
RemoveNodeMsgEx* thisCast = (RemoveNodeMsgEx*)this;
|
||||
|
||||
// nodeType
|
||||
Serialization_serializeShort(ctx, thisCast->nodeType);
|
||||
|
||||
// nodeNumID
|
||||
NumNodeID_serialize(ctx, &thisCast->nodeNumID);
|
||||
|
||||
// ackID
|
||||
Serialization_serializeStr(ctx, thisCast->ackIDLen, thisCast->ackID);
|
||||
}
|
||||
|
||||
bool RemoveNodeMsgEx_deserializePayload(NetMessage* this, DeserializeCtx* ctx)
|
||||
{
|
||||
RemoveNodeMsgEx* thisCast = (RemoveNodeMsgEx*)this;
|
||||
|
||||
// nodeType
|
||||
if(!Serialization_deserializeShort(ctx, &thisCast->nodeType) )
|
||||
return false;
|
||||
|
||||
// nodeNumID
|
||||
if(!NumNodeID_deserialize(ctx, &thisCast->nodeNumID) )
|
||||
return false;
|
||||
|
||||
// ackID
|
||||
if(!Serialization_deserializeStr(ctx, &thisCast->ackIDLen, &thisCast->ackID) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool __RemoveNodeMsgEx_processIncoming(NetMessage* this, struct App* app,
|
||||
fhgfs_sockaddr_in* fromAddr, struct Socket* sock, char* respBuf, size_t bufLen)
|
||||
{
|
||||
Logger* log = App_getLogger(app);
|
||||
const char* logContext = "RemoveNodeMsg incoming";
|
||||
|
||||
RemoveNodeMsgEx* thisCast = (RemoveNodeMsgEx*)this;
|
||||
|
||||
const char* peer;
|
||||
NodeType nodeType = (NodeType)RemoveNodeMsgEx_getNodeType(thisCast);
|
||||
NumNodeID nodeID = RemoveNodeMsgEx_getNodeNumID(thisCast);
|
||||
|
||||
RemoveNodeRespMsg respMsg;
|
||||
unsigned respLen;
|
||||
bool serializeRes;
|
||||
ssize_t sendRes;
|
||||
|
||||
peer = fromAddr ?
|
||||
SocketTk_ipaddrToStr(fromAddr->addr) : StringTk_strDup(Socket_getPeername(sock) );
|
||||
LOG_DEBUG_FORMATTED(log, Log_DEBUG, logContext,
|
||||
"Received a RemoveNodeMsg from: %s; Node: %s %hu",
|
||||
peer, Node_nodeTypeToStr(nodeType), nodeID.value);
|
||||
kfree(peer);
|
||||
|
||||
|
||||
if(nodeType == NODETYPE_Meta)
|
||||
{
|
||||
NodeStoreEx* nodes = App_getMetaNodes(app);
|
||||
if(NodeStoreEx_deleteNode(nodes, nodeID) )
|
||||
Logger_logFormatted(log, Log_WARNING, logContext, "Removed metadata node: %hu", nodeID.value);
|
||||
}
|
||||
else
|
||||
if(nodeType == NODETYPE_Storage)
|
||||
{
|
||||
NodeStoreEx* nodes = App_getStorageNodes(app);
|
||||
if(NodeStoreEx_deleteNode(nodes, nodeID) )
|
||||
Logger_logFormatted(log, Log_WARNING, logContext, "Removed storage node: %hu", nodeID.value);
|
||||
}
|
||||
else
|
||||
{ // should never happen
|
||||
Logger_logFormatted(log, Log_WARNING, logContext,
|
||||
"Received removal request for invalid node type: %d (%s)",
|
||||
(int)nodeType, Node_nodeTypeToStr(nodeType) );
|
||||
}
|
||||
|
||||
|
||||
// send response
|
||||
if(!MsgHelperAck_respondToAckRequest(app, RemoveNodeMsgEx_getAckID(thisCast),
|
||||
fromAddr, sock, respBuf, bufLen) )
|
||||
{
|
||||
RemoveNodeRespMsg_initFromValue(&respMsg, 0);
|
||||
|
||||
respLen = NetMessage_getMsgLength( (NetMessage*)&respMsg);
|
||||
serializeRes = NetMessage_serialize( (NetMessage*)&respMsg, respBuf, bufLen);
|
||||
if(unlikely(!serializeRes) )
|
||||
{
|
||||
Logger_logErrFormatted(log, logContext, "Unable to serialize response");
|
||||
goto err_resp_uninit;
|
||||
}
|
||||
|
||||
if(fromAddr)
|
||||
{ // datagram => sync via dgramLis send method
|
||||
DatagramListener* dgramLis = App_getDatagramListener(app);
|
||||
sendRes = DatagramListener_sendto_kernel(dgramLis, respBuf, respLen, 0, fromAddr);
|
||||
}
|
||||
else
|
||||
sendRes = Socket_sendto_kernel(sock, respBuf, respLen, 0, NULL);
|
||||
|
||||
if(unlikely(sendRes <= 0) )
|
||||
Logger_logErrFormatted(log, logContext, "Send error. ErrCode: %lld", (long long)sendRes);
|
||||
}
|
||||
|
||||
err_resp_uninit:
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#ifndef REMOVENODEMSGEX_H_
|
||||
#define REMOVENODEMSGEX_H_
|
||||
|
||||
#include <common/net/message/NetMessage.h>
|
||||
|
||||
|
||||
struct RemoveNodeMsgEx;
|
||||
typedef struct RemoveNodeMsgEx RemoveNodeMsgEx;
|
||||
|
||||
static inline void RemoveNodeMsgEx_init(RemoveNodeMsgEx* this);
|
||||
static inline void RemoveNodeMsgEx_initFromNodeData(RemoveNodeMsgEx* this,
|
||||
NumNodeID nodeNumID, NodeType nodeType);
|
||||
|
||||
// virtual functions
|
||||
extern void RemoveNodeMsgEx_serializePayload(NetMessage* this, SerializeCtx* ctx);
|
||||
extern bool RemoveNodeMsgEx_deserializePayload(NetMessage* this, DeserializeCtx* ctx);
|
||||
extern bool __RemoveNodeMsgEx_processIncoming(NetMessage* this, struct App* app,
|
||||
fhgfs_sockaddr_in* fromAddr, struct Socket* sock, char* respBuf, size_t bufLen);
|
||||
|
||||
// getters & setters
|
||||
static inline NumNodeID RemoveNodeMsgEx_getNodeNumID(RemoveNodeMsgEx* this);
|
||||
static inline NodeType RemoveNodeMsgEx_getNodeType(RemoveNodeMsgEx* this);
|
||||
static inline const char* RemoveNodeMsgEx_getAckID(RemoveNodeMsgEx* this);
|
||||
|
||||
|
||||
struct RemoveNodeMsgEx
|
||||
{
|
||||
NetMessage netMessage;
|
||||
|
||||
NumNodeID nodeNumID;
|
||||
int16_t nodeType;
|
||||
unsigned ackIDLen;
|
||||
const char* ackID;
|
||||
};
|
||||
|
||||
extern const struct NetMessageOps RemoveNodeMsgEx_Ops;
|
||||
|
||||
void RemoveNodeMsgEx_init(RemoveNodeMsgEx* this)
|
||||
{
|
||||
NetMessage_init(&this->netMessage, NETMSGTYPE_RemoveNode, &RemoveNodeMsgEx_Ops);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeID just a reference, so do not free it as long as you use this object!
|
||||
*/
|
||||
void RemoveNodeMsgEx_initFromNodeData(RemoveNodeMsgEx* this,
|
||||
NumNodeID nodeNumID, NodeType nodeType)
|
||||
{
|
||||
RemoveNodeMsgEx_init(this);
|
||||
|
||||
this->nodeNumID = nodeNumID;
|
||||
|
||||
this->nodeType = (int16_t)nodeType;
|
||||
|
||||
this->ackID = "";
|
||||
this->ackIDLen = 0;
|
||||
}
|
||||
|
||||
NumNodeID RemoveNodeMsgEx_getNodeNumID(RemoveNodeMsgEx* this)
|
||||
{
|
||||
return this->nodeNumID;
|
||||
}
|
||||
|
||||
NodeType RemoveNodeMsgEx_getNodeType(RemoveNodeMsgEx* this)
|
||||
{
|
||||
return (NodeType)this->nodeType;
|
||||
}
|
||||
|
||||
const char* RemoveNodeMsgEx_getAckID(RemoveNodeMsgEx* this)
|
||||
{
|
||||
return this->ackID;
|
||||
}
|
||||
|
||||
#endif /* REMOVENODEMSGEX_H_ */
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef REMOVENODERESPMSG_H_
|
||||
#define REMOVENODERESPMSG_H_
|
||||
|
||||
#include <common/net/message/SimpleIntMsg.h>
|
||||
|
||||
|
||||
struct RemoveNodeRespMsg;
|
||||
typedef struct RemoveNodeRespMsg RemoveNodeRespMsg;
|
||||
|
||||
static inline void RemoveNodeRespMsg_init(RemoveNodeRespMsg* this);
|
||||
static inline void RemoveNodeRespMsg_initFromValue(RemoveNodeRespMsg* this, int value);
|
||||
|
||||
struct RemoveNodeRespMsg
|
||||
{
|
||||
SimpleIntMsg simpleIntMsg;
|
||||
};
|
||||
|
||||
|
||||
void RemoveNodeRespMsg_init(RemoveNodeRespMsg* this)
|
||||
{
|
||||
SimpleIntMsg_init( (SimpleIntMsg*)this, NETMSGTYPE_RemoveNodeResp);
|
||||
}
|
||||
|
||||
void RemoveNodeRespMsg_initFromValue(RemoveNodeRespMsg* this, int value)
|
||||
{
|
||||
SimpleIntMsg_initFromValue( (SimpleIntMsg*)this, NETMSGTYPE_RemoveNodeResp, value);
|
||||
}
|
||||
|
||||
#endif /* REMOVENODERESPMSG_H_ */
|
||||
@@ -0,0 +1,103 @@
|
||||
#include <common/net/msghelpers/MsgHelperAck.h>
|
||||
#include <common/nodes/MirrorBuddyGroupMapper.h>
|
||||
#include <app/App.h>
|
||||
|
||||
#include "SetMirrorBuddyGroupMsgEx.h"
|
||||
|
||||
const struct NetMessageOps SetMirrorBuddyGroupMsgEx_Ops = {
|
||||
.serializePayload = _NetMessage_serializeDummy,
|
||||
.deserializePayload = SetMirrorBuddyGroupMsgEx_deserializePayload,
|
||||
.processIncoming = __SetMirrorBuddyGroupMsgEx_processIncoming,
|
||||
.getSupportedHeaderFeatureFlagsMask = NetMessage_getSupportedHeaderFeatureFlagsMask,
|
||||
};
|
||||
|
||||
bool SetMirrorBuddyGroupMsgEx_deserializePayload(NetMessage* this, DeserializeCtx* ctx)
|
||||
{
|
||||
SetMirrorBuddyGroupMsgEx* thisCast = (SetMirrorBuddyGroupMsgEx*)this;
|
||||
|
||||
// nodeType
|
||||
if (!Serialization_deserializeInt(ctx, &thisCast->nodeType) )
|
||||
return false;
|
||||
|
||||
// primaryTargetID
|
||||
if (!Serialization_deserializeUShort(ctx, &thisCast->primaryTargetID) )
|
||||
return false;
|
||||
|
||||
// secondaryTargetID
|
||||
if (!Serialization_deserializeUShort(ctx, &thisCast->secondaryTargetID) )
|
||||
return false;
|
||||
|
||||
// buddyGroupID
|
||||
if (!Serialization_deserializeUShort(ctx, &thisCast->buddyGroupID) )
|
||||
return false;
|
||||
|
||||
// allowUpdate
|
||||
if (!Serialization_deserializeBool(ctx, &thisCast->allowUpdate) )
|
||||
return false;
|
||||
|
||||
// ackID
|
||||
if (!Serialization_deserializeStr(ctx, &thisCast->ackIDLen, &thisCast->ackID) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool __SetMirrorBuddyGroupMsgEx_processIncoming(NetMessage* this, struct App* app,
|
||||
fhgfs_sockaddr_in* fromAddr, struct Socket* sock, char* respBuf, size_t bufLen)
|
||||
{
|
||||
Logger* log = App_getLogger(app);
|
||||
MirrorBuddyGroupMapper* mirrorBuddyGroupMapper;
|
||||
TargetMapper* targetMapper = NULL;
|
||||
const char* logContext = "SetMirrorBuddyGroupMsg Incoming";
|
||||
FhgfsOpsErr addGroupResult;
|
||||
|
||||
SetMirrorBuddyGroupMsgEx* thisCast = (SetMirrorBuddyGroupMsgEx*)this;
|
||||
|
||||
const char* peer;
|
||||
|
||||
uint16_t primaryTargetID = SetMirrorBuddyGroupMsgEx_getPrimaryTargetID(thisCast);
|
||||
uint16_t secondaryTargetID = SetMirrorBuddyGroupMsgEx_getSecondaryTargetID(thisCast);
|
||||
uint16_t buddyGroupID = SetMirrorBuddyGroupMsgEx_getBuddyGroupID(thisCast);
|
||||
bool allowUpdate = SetMirrorBuddyGroupMsgEx_getAllowUpdate(thisCast);
|
||||
|
||||
NodeType nodeType = SetMirrorBuddyGroupMsgEx_getNodeType(thisCast);
|
||||
|
||||
switch (nodeType)
|
||||
{
|
||||
case NODETYPE_Storage:
|
||||
mirrorBuddyGroupMapper = App_getStorageBuddyGroupMapper(app);
|
||||
targetMapper = App_getTargetMapper(app);
|
||||
break;
|
||||
|
||||
case NODETYPE_Meta:
|
||||
mirrorBuddyGroupMapper = App_getMetaBuddyGroupMapper(app);
|
||||
break;
|
||||
|
||||
default:
|
||||
Logger_logErr(log, logContext, "Node type mismatch");
|
||||
return false;
|
||||
}
|
||||
|
||||
addGroupResult = MirrorBuddyGroupMapper_addGroup(mirrorBuddyGroupMapper, app->cfg, targetMapper,
|
||||
buddyGroupID, primaryTargetID, secondaryTargetID, allowUpdate);
|
||||
|
||||
if (addGroupResult == FhgfsOpsErr_SUCCESS)
|
||||
Logger_logFormatted(log, Log_NOTICE, logContext, "Added mirror group: Node type: %s; "
|
||||
"Group ID: %hu; Primary target ID: %hu; Secondary target ID: %hu.",
|
||||
Node_nodeTypeToStr(nodeType), buddyGroupID, primaryTargetID, secondaryTargetID);
|
||||
else
|
||||
Logger_logFormatted(log, Log_WARNING, logContext, "Error adding mirror buddy group: "
|
||||
"Node type: %s, Group ID: %hu; Primary target ID: %hu; Secondary target ID: %hu; "
|
||||
"Error: %s",
|
||||
Node_nodeTypeToStr(nodeType), buddyGroupID, primaryTargetID, secondaryTargetID,
|
||||
FhgfsOpsErr_toErrString(addGroupResult) );
|
||||
|
||||
peer = fromAddr ?
|
||||
SocketTk_ipaddrToStr(fromAddr->addr) : StringTk_strDup(Socket_getPeername(sock) );
|
||||
|
||||
// send Ack
|
||||
MsgHelperAck_respondToAckRequest(app, SetMirrorBuddyGroupMsgEx_getAckID(thisCast), fromAddr,
|
||||
sock, respBuf, bufLen);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#ifndef SETMIRRORBUDDYGROUPMSGEX_H_
|
||||
#define SETMIRRORBUDDYGROUPMSGEX_H_
|
||||
|
||||
#include <common/net/message/NetMessage.h>
|
||||
|
||||
|
||||
struct SetMirrorBuddyGroupMsgEx;
|
||||
typedef struct SetMirrorBuddyGroupMsgEx SetMirrorBuddyGroupMsgEx;
|
||||
|
||||
static inline void SetMirrorBuddyGroupMsgEx_init(SetMirrorBuddyGroupMsgEx* this);
|
||||
|
||||
// virtual functions
|
||||
extern bool SetMirrorBuddyGroupMsgEx_deserializePayload(NetMessage* this, DeserializeCtx* ctx);
|
||||
extern bool __SetMirrorBuddyGroupMsgEx_processIncoming(NetMessage* this, struct App* app,
|
||||
fhgfs_sockaddr_in* fromAddr, struct Socket* sock, char* respBuf, size_t bufLen);
|
||||
|
||||
// getters and setters
|
||||
static inline NodeType SetMirrorBuddyGroupMsgEx_getNodeType(SetMirrorBuddyGroupMsgEx* this);
|
||||
static inline uint16_t SetMirrorBuddyGroupMsgEx_getPrimaryTargetID(SetMirrorBuddyGroupMsgEx* this);
|
||||
static inline uint16_t SetMirrorBuddyGroupMsgEx_getSecondaryTargetID(SetMirrorBuddyGroupMsgEx* this);
|
||||
static inline uint16_t SetMirrorBuddyGroupMsgEx_getBuddyGroupID(SetMirrorBuddyGroupMsgEx* this);
|
||||
static inline bool SetMirrorBuddyGroupMsgEx_getAllowUpdate(SetMirrorBuddyGroupMsgEx* this);
|
||||
static inline const char* SetMirrorBuddyGroupMsgEx_getAckID(SetMirrorBuddyGroupMsgEx* this);
|
||||
|
||||
struct SetMirrorBuddyGroupMsgEx
|
||||
{
|
||||
NetMessage netMessage;
|
||||
|
||||
int nodeType;
|
||||
uint16_t primaryTargetID;
|
||||
uint16_t secondaryTargetID;
|
||||
uint16_t buddyGroupID;
|
||||
bool allowUpdate;
|
||||
|
||||
unsigned ackIDLen;
|
||||
const char* ackID;
|
||||
};
|
||||
|
||||
extern const struct NetMessageOps SetMirrorBuddyGroupMsgEx_Ops;
|
||||
|
||||
void SetMirrorBuddyGroupMsgEx_init(SetMirrorBuddyGroupMsgEx* this)
|
||||
{
|
||||
NetMessage_init(&this->netMessage, NETMSGTYPE_SetMirrorBuddyGroup,
|
||||
&SetMirrorBuddyGroupMsgEx_Ops);
|
||||
}
|
||||
|
||||
static inline NodeType SetMirrorBuddyGroupMsgEx_getNodeType(SetMirrorBuddyGroupMsgEx* this)
|
||||
{
|
||||
return (NodeType)this->nodeType;
|
||||
}
|
||||
|
||||
static inline uint16_t SetMirrorBuddyGroupMsgEx_getPrimaryTargetID(SetMirrorBuddyGroupMsgEx* this)
|
||||
{
|
||||
return this->primaryTargetID;
|
||||
}
|
||||
|
||||
static inline uint16_t SetMirrorBuddyGroupMsgEx_getSecondaryTargetID(SetMirrorBuddyGroupMsgEx* this)
|
||||
{
|
||||
return this->secondaryTargetID;
|
||||
}
|
||||
|
||||
static inline uint16_t SetMirrorBuddyGroupMsgEx_getBuddyGroupID(SetMirrorBuddyGroupMsgEx* this)
|
||||
{
|
||||
return this->buddyGroupID;
|
||||
}
|
||||
|
||||
static inline bool SetMirrorBuddyGroupMsgEx_getAllowUpdate(SetMirrorBuddyGroupMsgEx* this)
|
||||
{
|
||||
return this->allowUpdate;
|
||||
}
|
||||
|
||||
const char* SetMirrorBuddyGroupMsgEx_getAckID(SetMirrorBuddyGroupMsgEx* this)
|
||||
{
|
||||
return this->ackID;
|
||||
}
|
||||
|
||||
#endif /* SETMIRRORBUDDYGROUPMSGEX_H_ */
|
||||
Reference in New Issue
Block a user