/** * 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 saftest_daemon_handle_cluster_node_get_request( saftest_map_table_entry_t *map_entry, saftest_msg_t *request, saftest_msg_t **reply) { clm_session_t *clm_session = NULL; SaAisErrorT status; SaClmNodeIdT node_id; SaTimeT timeout; const char *xml_file = NULL; FILE *fp = NULL; SaClmClusterNodeT cluster_node; SaClmClusterNodeT *cluster_node_ptr = NULL; saftest_log("Received a cluster node get request for id %d\n", saftest_msg_get_ubit32_value(request, "CLM_SESSION_ID")); clm_session = lookup_clm_session_from_request(request); if (0 == strcmp("FALSE", saftest_msg_get_str_value(request, "NULL_CLUSTER_NODE"))) { cluster_node_ptr = &cluster_node; } /* * !!! Need to address this timeout problem. What is a timeout of 0 * supposed to represent? */ node_id = get_node_id_from_string( saftest_msg_get_str_value(request, "NODE_ID")); if (0 == strcmp(saftest_msg_get_str_value(request, "TIMEOUT"), "SA_TIME_MAX")) { timeout = SA_TIME_MAX; } else { timeout = saftest_msg_get_sbit64_value(request, "TIMEOUT"); } status = saClmClusterNodeGet(clm_session->clm_handle, node_id, timeout, cluster_node_ptr); if ((SA_AIS_OK == status) && (NULL != (xml_file = saftest_msg_get_str_value(request, "XML_FILE")))) { saftest_assert(NULL != cluster_node_ptr, "Can't ask for an XML_FILE without a cluster_node"); fp = fopen(xml_file, "w+"); if (NULL == fp) { saftest_abort("Unable to open %s for writing\n", xml_file); } saftest_daemon_write_cluster_node(fp, cluster_node_ptr); fclose(fp); (*reply) = saftest_reply_msg_create(request, map_entry->reply_op, SA_AIS_OK); } (*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; }