/** * smfnd_up * @param i_node_id Clm node id * @param i_smfnd_dest Destination to Clm node */ uns32 smfnd_up(SaClmNodeIdT i_node_id, MDS_DEST i_smfnd_dest) { SaAisErrorT rc; SaClmHandleT clmHandle; SmfndNodeT *smfnd = NULL; TRACE("SMFND UP for node id %x", i_node_id); /* Find Clm info about the node */ rc = saClmInitialize(&clmHandle, NULL, &clmVersion); if (rc != SA_AIS_OK) { LOG_ER("saClmInitialize failed %d", rc); return NCSCC_RC_FAILURE; } /* Make shure the node id does not already exists */ smfnd = get_smfnd(i_node_id); if (smfnd != NULL) { LOG_ER("smfnd already exists %x", i_node_id); return NCSCC_RC_FAILURE; } /* Does not exists, create a new cleared structure */ smfnd = calloc(1, sizeof(SmfndNodeT)); if (smfnd == NULL) { LOG_ER("alloc failed"); return NCSCC_RC_FAILURE; } /* Get Clm info about the node */ rc = saClmClusterNodeGet(clmHandle, i_node_id, 10000000000LL, &smfnd->clmInfo); if (rc != SA_AIS_OK) { LOG_ER("saClmClusterNodeGet failed %d", rc); free(smfnd); return NCSCC_RC_FAILURE; } rc = saClmFinalize(clmHandle); if (rc != SA_AIS_OK) { LOG_ER("saClmFinalize failed %d", rc); free(smfnd); return NCSCC_RC_FAILURE; } /* Make shure the name string is null terminated */ smfnd->clmInfo.nodeName.value[smfnd->clmInfo.nodeName.length] = 0; /* Store the destination to the smfnd */ smfnd->dest = i_smfnd_dest; /* Store the node info in the smfnd list */ smfnd->next = firstSmfnd; firstSmfnd = smfnd; TRACE("SMFND added for node name %s, id %x", smfnd->clmInfo.nodeName.value, smfnd->clmInfo.nodeId); return NCSCC_RC_SUCCESS; }
void saClmFinalize_03(void) { safassert(saClmInitialize(&clmHandle, &clmCallbacks_1, &clmVersion_1), SA_AIS_OK); safassert(saClmFinalize(clmHandle), SA_AIS_OK); rc = saClmFinalize(clmHandle); test_validate(rc, SA_AIS_ERR_BAD_HANDLE); }
void saClmFinalize_01(void) { safassert(saClmInitialize(&clmHandle, &clmCallbacks_1, &clmVersion_1), SA_AIS_OK); rc = saClmFinalize(clmHandle); test_validate(rc, SA_AIS_OK); safassert(saClmInitialize_4(&clmHandle, &clmCallbacks_4, &clmVersion_4), SA_AIS_OK); rc = saClmFinalize(clmHandle); test_validate(rc, SA_AIS_OK); }
int ast_ais_clm_load_module(void) { clm_init_res = saClmInitialize(&clm_handle, &clm_callbacks, &ais_version); if (clm_init_res != SA_AIS_OK) { ast_log(LOG_ERROR, "Could not initialize cluster membership service: %s\n", ais_err2str(clm_init_res)); return -1; } ast_cli_register_multiple(ais_cli, ARRAY_LEN(ais_cli)); return 0; }
void saClmClusterTrackStop_01(void) { trackFlags = SA_TRACK_CURRENT; nodeId = 131343; invocation = 600; safassert(saClmInitialize(&clmHandle, &clmCallback11, &clmVersion_1), SA_AIS_OK); rc = saClmClusterTrack(clmHandle, trackFlags, NULL); rc = saClmClusterTrack(clmHandle, trackFlags, NULL); rc = saClmClusterNodeGetAsync(clmHandle, invocation, nodeId); rc = saClmClusterTrack(clmHandle, trackFlags, NULL); rc = saClmClusterNodeGetAsync(clmHandle, invocation, nodeId); rc = saClmClusterNodeGetAsync(clmHandle, invocation, nodeId); rc = saClmClusterTrack(clmHandle, trackFlags, NULL); safassert(saClmClusterTrackStop(clmHandle), SA_AIS_OK); safassert(saClmDispatch(clmHandle,SA_DISPATCH_ALL), SA_AIS_OK); rc = saClmClusterTrack(clmHandle, trackFlags, NULL); safassert(saClmClusterTrackStop(clmHandle), SA_AIS_OK); safassert(saClmFinalize(clmHandle), SA_AIS_OK); test_validate(rc, SA_AIS_OK); }
void saftest_daemon_handle_init_request( saftest_map_table_entry_t *map_entry, saftest_msg_t *request, saftest_msg_t **reply) { clm_session_t *clm_session; SaClmHandleT *handle = NULL; SaClmCallbacksT *callbacks = NULL; SaVersionT *version = NULL; SaAisErrorT status; char *releaseCodeStr; char releaseCode; releaseCodeStr = saftest_msg_get_str_value(request, "VERSION_RELEASE_CODE"); releaseCode = releaseCodeStr[0]; saftest_log("Received an init request from for id %d " "release code=%c, majorVersion=%d, minorVersion=%d\n", saftest_msg_get_ubit32_value(request, "CLM_SESSION_ID"), releaseCode, saftest_msg_get_ubit32_value(request, "VERSION_MAJOR"), saftest_msg_get_ubit32_value(request, "VERSION_MINOR")); clm_session = lookup_clm_session_from_request(request); clm_session->clm_callbacks.saClmClusterNodeGetCallback = NULL; clm_session->clm_callbacks.saClmClusterTrackCallback = NULL; if (0 == strcmp("FALSE", saftest_msg_get_str_value(request, "NULL_CLM_HANDLE"))) { handle = &clm_session->clm_handle; } if (0 == strcmp("FALSE", saftest_msg_get_str_value(request, "NULL_CALLBACKS"))) { callbacks = &clm_session->clm_callbacks; if (0 == strcmp("TRUE", saftest_msg_get_str_value(request, "CLUSTER_NODE_GET_CB"))) { clm_session->clm_callbacks.saClmClusterNodeGetCallback = saftest_daemon_cluster_node_get_callback; } if (0 == strcmp("TRUE", saftest_msg_get_str_value(request, "CLUSTER_TRACK_CB"))) { clm_session->clm_callbacks.saClmClusterTrackCallback = saftest_daemon_cluster_track_callback; } } if (0 == strcmp("FALSE", saftest_msg_get_str_value(request, "NULL_VERSION"))) { version = &clm_session->version; clm_session->version.releaseCode = releaseCode; clm_session->version.majorVersion = saftest_msg_get_ubit8_value(request, "VERSION_MAJOR"); clm_session->version.minorVersion = saftest_msg_get_ubit8_value(request, "VERSION_MINOR"); } clm_session->dispatch_flags = saftest_dispatch_flags_from_string( saftest_msg_get_str_value(request, "DISPATCH_FLAGS")); status = saClmInitialize(handle, callbacks, version); (*reply) = saftest_reply_msg_create(request, map_entry->reply_op, status); }
static void test_clm_during_cpg_test(void) { SaClmHandleT clmHandle = { 0 }; SaAisErrorT err; SaClmCallbacksT callbacks = { .saClmClusterNodeGetCallback = _clm_nodeget_callback, .saClmClusterTrackCallback = _clm_nodetrack_callback, }; SaVersionT version = { .releaseCode = 'B', .majorVersion = 1, .minorVersion = 1 }; SaClmClusterNodeT node; int status = 0; pid_t r; while ( (err = saClmInitialize(&clmHandle, &callbacks, &version)) == SA_AIS_ERR_TRY_AGAIN ); if ( err != SA_AIS_OK ) DIE("saClmInitialize(): %d", err); if ( (err = saClmClusterNodeGet(clmHandle, SA_CLM_LOCAL_NODE_ID, 1000000, &node)) != SA_AIS_OK ) DIE("saClmNodeGet(): %d", err); test_data.node_id = node.nodeId; DPRINTF("We are '%.*s', ID: %d", node.nodeName.length, node.nodeName.value, node.nodeId); if ( (err = saClmClusterTrack(clmHandle, SA_TRACK_CURRENT | SA_TRACK_CHANGES, NULL)) != SA_AIS_OK ) DIE("saClmClusterTrack(): %d", err); r = 0; status = 0; /* Note: The man pages of FreeBSD says that waitpid() should return 0 if no process has ended * but I get 1 instead. Weird. * TODO(Jflesch): Figure out what I did wrong. */ while ( test_data.keep_dispatching && (test_data.test_cpg_pid == -1 || ( (r = waitpid(test_data.test_cpg_pid, &status, WNOHANG) != -1) && (r == 0 || r == 1 || (!WIFEXITED(status) && !WIFSIGNALED(status))) ) ) ) { if ( (err = saClmDispatch(clmHandle, SA_DISPATCH_ALL)) != SA_AIS_OK ) DIE("saClmDispatch(): %d", err); if ( test_data.nmb_peers == test_data.max_nmb_peers ) { if ( test_data.master_id != test_data.node_id ) { DPRINTF("Synchronized."); /* -> we are a slave, the only thing we have to do is run CPG tests again */ test_data.keep_dispatching = 0; test_data.run_cpg_test = 1; } else if ( test_data.test_cpg_pid == -1 ) { DPRINTF("Synchronized."); test_data.nmb_clm_notifications = 0; DPRINTF("(master) Running CPG tests ..."); test_data.test_cpg_pid = start_cpg_tests(); /* // */ DPRINTF("(master) CPG tests started"); } } usleep(10 * 1000); /* 10ms */ } if ( test_data.keep_dispatching ) /* => end of test */ { if ( test_data.test_cpg_pid < 0 ) DIE("CPG tests not even started"); if ( r <= -1 ) DIE("waitpid() failed: %d, %s", errno, strerror(errno)); if ( WIFSIGNALED(status) ) DIE("CPG tests died because of signal %d", WTERMSIG(status)); if ( WEXITSTATUS(status) != 0 ) DIE("CPG tests died returning the value %d", WEXITSTATUS(status)); } #ifdef BE_NICE if ( (err = saClmClusterTrackStop(clmHandle)) != SA_AIS_OK ) DIE("saClmTrackStop(): %d", err); #endif if ( (err = saClmFinalize(clmHandle)) != SA_AIS_OK ) DIE("saClmFinalize(): %d", err); if ( test_data.nmb_clm_notifications <= 0 ) DIE("Got no CLM notifications"); if ( test_data.run_cpg_test ) { DPRINTF("(slave) Running CPG tests ..."); test_cpg_multiplayer(test_data.max_nmb_peers); DPRINTF("(slave) CPG test finished"); } } void test_clm(int nmb_peers) { if ( nmb_peers <= 1 ) DIE("Not enought peers"); test_data = TEST_DATA_START_VALUE; test_data.max_nmb_peers = nmb_peers; DPRINTF(" - Rerun of the CPG multiplayer test, keeping an eye on CLM behavior"); test_clm_during_cpg_test(); /* DPRINTF(" - Misuse of the API"); ? */ }
int main(void) { SaSelectionObjectT st; SaErrorT ret; SaClmNodeIdT nid; SaClmCallbacksT my_callbacks = { .saClmClusterTrackCallback = (SaClmClusterTrackCallbackT)track_callback, .saClmClusterNodeGetCallback = (SaClmClusterNodeGetCallbackT)getnode_callback }; if ((ret = saClmInitialize(&hd, &my_callbacks, NULL)) != SA_OK) { fprintf(stderr, "saClmInitialize error, errno [%d]\n",ret); return 1; } if ((ret = saClmSelectionObjectGet(&hd, &st)) != SA_OK) { fprintf(stderr, "saClmSelectionObjectGet error, errno [%d]\n" , ret); return 1; } nid = 0; /* Synchronously get nodeId information */ printf("-------------------------------------------------\n"); printf("Get nodeId [%lu] info by SaClmClusterNodeGet\n", nid); if ((ret = saClmClusterNodeGet(nid, 10, &cn)) != SA_OK) { if (ret == SA_ERR_INVALID_PARAM) { fprintf(stderr, "NodeId [%lu] record not found!\n",nid); } else { fprintf(stderr , "saClmClusterNodeGet error, errno [%d]\n" , ret); return 1; } } else { dump_nodeinfo(&cn); } /* Asynchronously get my nodeId information */ nid = 1; printf("-------------------------------------------------\n"); printf("Get nodeId [%lu] info by SaClmClusterNodeGetAsync\n", nid); if ((ret = saClmClusterNodeGetAsync(&hd, 1234, nid, &cn)) != SA_OK) { if (ret == SA_ERR_INVALID_PARAM) { fprintf(stderr, "NodeId [%lu] record not found!\n",nid); } else { fprintf(stderr , "saClmClusterNodeGet error, errno [%d]\n" , ret); return 1; } } /* Start to track cluster membership changes events */ track_start(SIGUSR1); signal(SIGUSR2, &track_stop); for (;;) { fd_set rset; FD_ZERO(&rset); FD_SET(st, &rset); if (select(st + 1, &rset, NULL, NULL, NULL) == -1) { /* TODO should we use pselect here? */ if (errno == EINTR) continue; else { perror("select"); return 1; } } if ((ret = saClmDispatch(&hd, SA_DISPATCH_ALL)) != SA_OK) { if (ret == SA_ERR_LIBRARY) { fprintf(stderr, "I am evicted!\n"); return 1; } fprintf(stderr, "saClmDispatch error, errno [%d]\n" , ret); return 1; } } return 0; }