static void s_destroy_channel(struct channel *channel) { if (channel != NULL) { lagopus_result_t ret; ret = channel_free(channel); if (ret != LAGOPUS_RESULT_OK) { lagopus_msg_fatal("channel_free error (%s)\n", lagopus_error_get_string(ret)); } } }
lagopus_result_t dataplane_initialize(int argc, const char *const argv[], __UNUSED void *extarg, lagopus_thread_t **thdptr) { #ifdef HAVE_DPDK static struct dataplane_arg dparg; #endif /* HAVE_DPDK */ static struct dataplane_arg sockarg; static struct dataplane_arg timerarg; lagopus_result_t nb_ports; nb_ports = lagopus_dataplane_init(argc, argv); if (nb_ports < 0) { lagopus_msg_fatal("lagopus_dataplane_init failed\n"); return nb_ports; } dp_api_init(); #ifdef HAVE_DPDK if (rawsocket_only_mode != true) { dparg.threadptr = &dpdk_thread; dparg.lock = &dpdk_lock; lagopus_thread_create(&dpdk_thread, dpdk_thread_loop, dp_finalproc, dp_freeproc, "dataplane", &dparg); if (lagopus_mutex_create(&dpdk_lock) != LAGOPUS_RESULT_OK) { lagopus_exit_fatal("lagopus_mutex_create"); } } #endif /* HAVE_DPDK */ lagopus_meter_init(); lagopus_register_action_hook = lagopus_set_action_function; lagopus_register_instruction_hook = lagopus_set_instruction_function; flowinfo_init(); timerarg.threadptr = &timer_thread; timerarg.lock = &timer_lock; timerarg.running = NULL; timerthread_initialize(&timerarg); sockarg.threadptr = &sock_thread; sockarg.lock = &sock_lock; sockarg.running = NULL; sockthread_initialize(&sockarg); *thdptr = &sock_thread; return LAGOPUS_RESULT_OK; }
lagopus_result_t dp_thread_shutdown(lagopus_thread_t *threadptr, lagopus_mutex_t *lockptr, bool *runptr, shutdown_grace_level_t level) { bool is_valid = false; lagopus_chrono_t nsec; lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; lagopus_msg_info("shutdown called\n"); lagopus_mutex_lock(lockptr); if (*runptr == false) { goto done; } ret = lagopus_thread_is_valid(threadptr, &is_valid); if (ret != LAGOPUS_RESULT_OK || is_valid == false) { lagopus_perror(ret); goto done; } /* XXX UP TO main() */ switch (level) { case SHUTDOWN_RIGHT_NOW: nsec = TIMEOUT_SHUTDOWN_RIGHT_NOW; break; case SHUTDOWN_GRACEFULLY: nsec = TIMEOUT_SHUTDOWN_GRACEFULLY; break; default: lagopus_msg_fatal("unknown shutdown level %d\n", level); ret = LAGOPUS_RESULT_ANY_FAILURES; goto done; } *runptr = false; ret = lagopus_thread_wait(threadptr, nsec); if (ret != LAGOPUS_RESULT_OK) { lagopus_perror(ret); goto done; } done: lagopus_mutex_unlock(lockptr); return ret; }
static inline lagopus_result_t s_get_n(lagopus_cbuffer_t *cbptr, void *valptr, size_t n_vals_max, size_t n_at_least, size_t valsz, lagopus_chrono_t nsec, size_t *n_actual_get, bool do_incr) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; lagopus_cbuffer_t cb = NULL; if (cbptr != NULL && (cb = *cbptr) != NULL && valptr != NULL && valsz == cb->m_element_size) { if (n_vals_max > 0) { int64_t n_copyout = 0LL; if (nsec == 0LL) { s_lock(cb); { /* * Just get and return. */ if (cb->m_is_operational == true) { n_copyout = ret = s_copyout(cb, valptr, n_vals_max, do_incr); } else { ret = LAGOPUS_RESULT_NOT_OPERATIONAL; } } s_unlock(cb); } else if (nsec < 0LL) { s_lock(cb); { /* * Repeat getting until all the required # of the data are got. */ check_inf: mbar(); if (cb->m_is_operational == true) { n_copyout += s_copyout(cb, (void *)((char *)valptr + ((size_t)n_copyout * valsz)), n_vals_max - (size_t)n_copyout, do_incr); if ((size_t)n_copyout < n_vals_max) { /* * Need to repeat. */ if (cb->m_n_elements < 1LL) { /* * No data. Need to wait for someone put data to the * buffer. */ if ((ret = s_wait_gettable(cb, -1LL)) == LAGOPUS_RESULT_OK) { goto check_inf; } else { /* * Any errors occur while waiting. */ if (ret == LAGOPUS_RESULT_TIMEDOUT) { /* * Must not happen. */ lagopus_msg_fatal("Timed out must not happen here.\n"); } } } else { /* * The buffer still has data but it couldn't get all * the data?? Must not happen?? */ lagopus_msg_fatal("Couldn't get all the data even the data " "available. Must not happen.\n"); } } else { /* * Succeeded. */ ret = n_copyout; } } else { ret = LAGOPUS_RESULT_NOT_OPERATIONAL; } } s_unlock(cb); } else { s_lock(cb); { /* * Repeat getting until all the required # of the data are * got or the spcified time limit is expired. */ lagopus_chrono_t copy_start; lagopus_chrono_t wait_end; lagopus_chrono_t to = nsec; check_to: mbar(); if (cb->m_is_operational == true) { WHAT_TIME_IS_IT_NOW_IN_NSEC(copy_start); n_copyout += s_copyout(cb, (void *)((char *)valptr + ((size_t)n_copyout * valsz)), n_vals_max - (size_t)n_copyout, do_incr); if ((size_t)n_copyout < n_at_least) { /* * Need to repeat. */ if (cb->m_n_elements < 1LL) { /* * No data. Need to wait for someone put data to the * buffer. */ if ((ret = s_wait_gettable(cb, to)) == LAGOPUS_RESULT_OK) { WHAT_TIME_IS_IT_NOW_IN_NSEC(wait_end); to -= (wait_end - copy_start); if (to > 0LL) { goto check_to; } ret = LAGOPUS_RESULT_TIMEDOUT; } } else { /* * The buffer still has data but it couldn't get all * the data?? Must not happen?? */ lagopus_msg_fatal("Couldn't get all the data even the data " "available. Must not happen.\n"); } } else { /* * Succeeded. */ ret = n_copyout; } } else { ret = LAGOPUS_RESULT_NOT_OPERATIONAL; } } s_unlock(cb); } if (n_actual_get != NULL) { *n_actual_get = (size_t)n_copyout; } } else { if (n_actual_get != NULL) { *n_actual_get = 0LL; } ret = LAGOPUS_RESULT_OK; } } else { if (n_actual_get != NULL) { *n_actual_get = 0LL; } ret = LAGOPUS_RESULT_INVALID_ARGS; } return ret; }
int main(int argc, const char *const argv[]) { const char *nm = myname(argv[0]); (void)argc; lagopus_log_set_trace_flags(TRACE_OFPT_HELLO | TRACE_OFPT_ERROR | TRACE_OFPT_METER_MOD); lagopus_msg("this should emitted to stderr.\n"); lagopus_msg_trace(TRACE_OFPT_HELLO, false, "hello test.\n"); lagopus_msg_trace(TRACE_OFPT_ERROR, false, "error test.\n"); lagopus_msg_trace(TRACE_OFPT_HELLO | TRACE_OFPT_ERROR, false, "hello|error test.\n"); /* * log to stderr. */ if (IS_LAGOPUS_RESULT_OK( lagopus_log_initialize(LAGOPUS_LOG_EMIT_TO_UNKNOWN, NULL, false, true, 1)) == false) { lagopus_msg_fatal("what's wrong??\n"); /* not reached. */ } lagopus_dprint("debug to stderr.\n"); /* * log to file. */ if (IS_LAGOPUS_RESULT_OK( lagopus_log_initialize(LAGOPUS_LOG_EMIT_TO_FILE, "./testlog.txt", false, true, 10)) == false) { lagopus_msg_fatal("what's wrong??\n"); /* not reached. */ } lagopus_dprint("debug to file.\n"); lagopus_msg_debug(5, "debug to file, again.\n"); lagopus_msg_trace(TRACE_OFPT_HELLO, false, "hello file test.\n"); lagopus_msg_trace(TRACE_OFPT_ERROR, false, "error file test.\n"); lagopus_msg_trace(TRACE_OFPT_HELLO | TRACE_OFPT_ERROR, false, "hello|error file test.\n"); if (IS_LAGOPUS_RESULT_OK( lagopus_log_initialize(LAGOPUS_LOG_EMIT_TO_SYSLOG, nm, false, false, 10)) == false) { lagopus_msg_fatal("what's wrong??\n"); /* not reached. */ } lagopus_msg_debug(5, "debug to syslog.\n"); lagopus_msg_trace(TRACE_OFPT_HELLO, false, "hello syslog test.\n"); lagopus_msg_trace(TRACE_OFPT_ERROR, false, "error syslog test.\n"); lagopus_msg_trace(TRACE_OFPT_HELLO | TRACE_OFPT_ERROR, false, "hello|error syslog test.\n"); /* * log to stderr, again. */ if (IS_LAGOPUS_RESULT_OK( lagopus_log_initialize(LAGOPUS_LOG_EMIT_TO_UNKNOWN, NULL, false, true, 1)) == false) { lagopus_msg_fatal("what's wrong??\n"); /* not reached. */ } lagopus_dprint("will exit 1 ...\n"); lagopus_exit_error(1, "exit 1 on purpose.\n"); return 0; }