/*############################## tcp_cmd() ##############################*/ static int tcp_cmd(char *fmt, ...) { int bytes_buffered, bytes_done; va_list ap; va_start(ap, fmt); (void)vfprintf(p_control, fmt, ap); va_end(ap); (void)fprintf(p_control, "\r\n"); (void)fflush(p_control); while ((bytes_buffered = read_msg()) != INCORRECT) { if (bytes_buffered > 3) { if ((msg_str[0] == '2') && (msg_str[1] == '1') && (msg_str[2] == '1') && (msg_str[3] == '-')) { bytes_buffered = read_msg(); break; } if ((isdigit((int)msg_str[0])) && (isdigit((int)msg_str[1])) && (isdigit((int)msg_str[2])) && (msg_str[3] == '-')) { return(-(((msg_str[0] - '0') * 100) + ((msg_str[1] - '0') * 10) + (msg_str[2] - '0'))); } if ((isupper((int)msg_str[0])) && (isupper((int)msg_str[1])) && (msg_str[2] == ' ')) { if (evaluate_message(&bytes_done) == AFDD_SHUTTING_DOWN) { return(-AFDD_SHUTTING_DOWN); } bytes_buffered -= bytes_done; } else { mon_log(WARN_SIGN, __FILE__, __LINE__, 0L, msg_str, "Reading garbage, don't know what to do?"); return(INCORRECT); } } else { mon_log(WARN_SIGN, __FILE__, __LINE__, 0L, msg_str, "Reading garbage, don't know what to do?"); return(INCORRECT); } } return(bytes_buffered); }
void hv_message_intr(struct pt_regs *regs, int intnum) { /* * We enter with interrupts disabled and leave them disabled, * to match expectations of called functions (e.g. * do_ccupdate_local() in mm/slab.c). This is also consistent * with normal call entry for device interrupts. */ int message[HV_MAX_MESSAGE_SIZE/sizeof(int)]; HV_RcvMsgInfo rmi; int nmsgs = 0; /* Track time spent here in an interrupt context */ struct pt_regs *old_regs = set_irq_regs(regs); irq_enter(); #ifdef CONFIG_DEBUG_STACKOVERFLOW /* Debugging check for stack overflow: less than 1/8th stack free? */ { long sp = stack_pointer - (long) current_thread_info(); if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) { pr_emerg("hv_message_intr: " "stack overflow: %ld\n", sp - sizeof(struct thread_info)); dump_stack(); } } #endif while (1) { rmi = hv_receive_message(__get_cpu_var(msg_state), (HV_VirtAddr) message, sizeof(message)); #ifdef CONFIG_DATAPLANE if (dataplane_debug(smp_processor_id())) pr_warn("cpu %d: dataplane recv msg len %d, src %d\n", smp_processor_id(), rmi.msglen, rmi.source); #endif if (rmi.msglen == 0) break; if (rmi.msglen < 0) panic("hv_receive_message failed: %d", rmi.msglen); ++nmsgs; if (rmi.source == HV_MSG_TILE) { int tag; /* we just send tags for now */ BUG_ON(rmi.msglen != sizeof(int)); tag = message[0]; #ifdef CONFIG_SMP evaluate_message(message[0]); #else panic("Received IPI message %d in UP mode", tag); #endif } else if (rmi.source == HV_MSG_INTR) { HV_IntrMsg *him = (HV_IntrMsg *)message; struct hv_driver_cb *cb = (struct hv_driver_cb *)him->intarg; cb->callback(cb, him->intdata); __get_cpu_var(irq_stat).irq_hv_msg_count++; } } /* * We shouldn't have gotten a message downcall with no * messages available. */ if (nmsgs == 0) panic("Message downcall invoked with no messages!"); /* * Track time spent against the current process again and * process any softirqs if they are waiting. */ irq_exit(); set_irq_regs(old_regs); }
void hv_message_intr(struct pt_regs *regs, int intnum) { int message[HV_MAX_MESSAGE_SIZE/sizeof(int)]; HV_RcvMsgInfo rmi; int nmsgs = 0; struct pt_regs *old_regs = set_irq_regs(regs); irq_enter(); #ifdef CONFIG_DEBUG_STACKOVERFLOW { long sp = stack_pointer - (long) current_thread_info(); if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) { pr_emerg("hv_message_intr: " "stack overflow: %ld\n", sp - sizeof(struct thread_info)); dump_stack(); } } #endif while (1) { rmi = hv_receive_message(__get_cpu_var(msg_state), (HV_VirtAddr) message, sizeof(message)); if (rmi.msglen == 0) break; if (rmi.msglen < 0) panic("hv_receive_message failed: %d", rmi.msglen); ++nmsgs; if (rmi.source == HV_MSG_TILE) { int tag; BUG_ON(rmi.msglen != sizeof(int)); tag = message[0]; #ifdef CONFIG_SMP evaluate_message(message[0]); #else panic("Received IPI message %d in UP mode", tag); #endif } else if (rmi.source == HV_MSG_INTR) { HV_IntrMsg *him = (HV_IntrMsg *)message; struct hv_driver_cb *cb = (struct hv_driver_cb *)him->intarg; cb->callback(cb, him->intdata); __get_cpu_var(irq_stat).irq_hv_msg_count++; } } if (nmsgs == 0) panic("Message downcall invoked with no messages!"); irq_exit(); set_irq_regs(old_regs); }
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ mon() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ int main(int argc, char *argv[]) { int bytes_done = 0, bytes_buffered = 0, i, retry_fd, #ifdef WITHOUT_FIFO_RW_SUPPORT retry_writefd, #endif status; time_t new_day_time, now, retry_interval = RETRY_INTERVAL, start_time; char mon_log_fifo[MAX_PATH_LENGTH], retry_fifo[MAX_PATH_LENGTH], work_dir[MAX_PATH_LENGTH]; fd_set rset; struct stat stat_buf; struct timeval timeout; CHECK_FOR_VERSION(argc, argv); if (get_mon_path(&argc, argv, work_dir) < 0) { exit(INCORRECT); } p_work_dir = work_dir; if (argc != 2) { (void)fprintf(stderr, "Usage: %s [-w working directory] AFD-number\n", argv[0]); exit(SYNTAX_ERROR); } else { char *ptr = argv[1]; while (*ptr != '\0') { if (isdigit((int)(*ptr)) == 0) { (void)fprintf(stderr, "Usage: %s [-w working directory] AFD-number\n", argv[0]); exit(SYNTAX_ERROR); } ptr++; } afd_no = atoi(argv[1]); } /* Initialize variables. */ (void)strcpy(mon_log_fifo, p_work_dir); (void)strcat(mon_log_fifo, FIFO_DIR); (void)strcpy(retry_fifo, mon_log_fifo); (void)strcat(retry_fifo, RETRY_MON_FIFO); (void)strcat(retry_fifo, argv[1]); (void)strcat(mon_log_fifo, MON_LOG_FIFO); /* Open (create) monitor log fifo. */ if ((stat(mon_log_fifo, &stat_buf) < 0) || (!S_ISFIFO(stat_buf.st_mode))) { if (make_fifo(mon_log_fifo) < 0) { (void)fprintf(stderr, "ERROR : Could not create fifo %s. (%s %d)\n", mon_log_fifo, __FILE__, __LINE__); exit(INCORRECT); } } #ifdef WITHOUT_FIFO_RW_SUPPORT if (open_fifo_rw(mon_log_fifo, &mon_log_readfd, &mon_log_fd) == -1) #else if ((mon_log_fd = open(mon_log_fifo, O_RDWR)) == -1) #endif { (void)fprintf(stderr, "ERROR : Could not open() fifo %s : %s (%s %d)\n", mon_log_fifo, strerror(errno), __FILE__, __LINE__); exit(INCORRECT); } /* Open (create) retry fifo. */ if ((stat(retry_fifo, &stat_buf) < 0) || (!S_ISFIFO(stat_buf.st_mode))) { if (make_fifo(retry_fifo) < 0) { (void)fprintf(stderr, "ERROR : Could not create fifo %s. (%s %d)\n", retry_fifo, __FILE__, __LINE__); exit(INCORRECT); } } #ifdef WITHOUT_FIFO_RW_SUPPORT if (open_fifo_rw(retry_fifo, &retry_fd, &retry_writefd) == -1) #else if ((retry_fd = open(retry_fifo, O_RDWR)) == -1) #endif { (void)fprintf(stderr, "ERROR : Could not open() fifo %s : %s (%s %d)\n", retry_fifo, strerror(errno), __FILE__, __LINE__); exit(INCORRECT); } /* Do some cleanups when we exit. */ if (atexit(mon_exit) != 0) { system_log(FATAL_SIGN, __FILE__, __LINE__, "Could not register exit handler : %s", strerror(errno)); exit(INCORRECT); } if ((signal(SIGINT, sig_exit) == SIG_ERR) || (signal(SIGQUIT, sig_exit) == SIG_ERR) || (signal(SIGTERM, sig_exit) == SIG_ERR) || (signal(SIGSEGV, sig_segv) == SIG_ERR) || (signal(SIGBUS, sig_bus) == SIG_ERR) || (signal(SIGPIPE, SIG_IGN) == SIG_ERR) || (signal(SIGHUP, SIG_IGN) == SIG_ERR)) { system_log(FATAL_SIGN, __FILE__, __LINE__, "Could not set signal handlers : %s", strerror(errno)); exit(INCORRECT); } if (msa_attach() != SUCCESS) { system_log(FATAL_SIGN, __FILE__, __LINE__, "Failed to attach to MSA."); exit(INCORRECT); } msa[afd_no].tr = 0; p_mon_alias = msa[afd_no].afd_alias; now = time(NULL); new_day_time = ((now / 86400) * 86400) + 86400; new_hour_time = ((now / 3600) * 3600) + 3600; for (i = 0; i < NO_OF_LOG_HISTORY; i++) { shift_log_his[i] = DONE; } for (;;) { msa[afd_no].connect_status = CONNECTING; timeout_flag = OFF; if ((status = tcp_connect(msa[afd_no].hostname[(int)msa[afd_no].afd_toggle], msa[afd_no].port[(int)msa[afd_no].afd_toggle], NO)) != SUCCESS) { if (timeout_flag == OFF) { if (status != INCORRECT) { mon_log(WARN_SIGN, NULL, 0, 0L, msg_str, "Failed to connect."); } /* * The tcp_connect() function wrote to the log file if status * is INCORRECT. Thus it is not necessary to do it here again. */ } else { mon_log(ERROR_SIGN, __FILE__, __LINE__, 0L, NULL, "Failed to connect due to timeout."); } msa[afd_no].connect_status = CONNECTION_DEFUNCT; retry_interval = RETRY_INTERVAL; if (msa[afd_no].afd_switching == AUTO_SWITCHING) { if (msa[afd_no].afd_toggle == (HOST_ONE - 1)) { msa[afd_no].afd_toggle = (HOST_TWO - 1); } else { msa[afd_no].afd_toggle = (HOST_ONE - 1); } mon_log(WARN_SIGN, NULL, 0, 0L, NULL, "Automatic switching to %s%d (%s at port %d).", msa[afd_no].afd_alias, (int)msa[afd_no].afd_toggle + 1, msa[afd_no].hostname[(int)msa[afd_no].afd_toggle], msa[afd_no].port[(int)msa[afd_no].afd_toggle]); } } else { char current_afd_toggle; got_log_capabilities = NO; send_log_request = NO; if (msa[afd_no].afd_switching != NO_SWITCHING) { current_afd_toggle = msa[afd_no].afd_toggle; } msa[afd_no].connect_status = CONNECTION_ESTABLISHED; mon_log(INFO_SIGN, NULL, 0, 0L, NULL, "========> AFDD Connected <========"); if ((bytes_buffered = tcp_cmd("%s", START_STAT_CMD)) < 0) { if (bytes_buffered == -AFDD_SHUTTING_DOWN) { timeout_flag = ON; (void)tcp_quit(); timeout_flag = OFF; msa[afd_no].connect_status = DISCONNECTED; } else { mon_log(ERROR_SIGN, __FILE__, __LINE__, 0L, msg_str, "Failed to send %s command.", START_STAT_CMD); (void)tcp_quit(); msa[afd_no].connect_status = CONNECTION_DEFUNCT; } retry_interval = RETRY_INTERVAL; } else { if ((msa[afd_no].connect_time != 0) && (msa[afd_no].disconnect_time != 0)) { start_time = time(NULL); } FD_ZERO(&rset); for (;;) { /* * Check if it is midnight so we can reset the top * rate counters. */ if (time(&now) > new_day_time) { for (i = (STORAGE_TIME - 1); i > 0; i--) { msa[afd_no].top_no_of_transfers[i] = msa[afd_no].top_no_of_transfers[i - 1]; msa[afd_no].top_tr[i] = msa[afd_no].top_tr[i - 1]; msa[afd_no].top_fr[i] = msa[afd_no].top_fr[i - 1]; } msa[afd_no].top_no_of_transfers[0] = 0; msa[afd_no].top_tr[0] = msa[afd_no].top_fr[0] = 0; msa[afd_no].top_not_time = msa[afd_no].top_tr_time = msa[afd_no].top_fr_time = 0L; new_day_time = ((now / 86400) * 86400) + 86400; } if (now > (new_hour_time + 120)) { for (i = 0; i < NO_OF_LOG_HISTORY; i++) { shift_log_his[i] = NO; } new_hour_time = ((now / 3600) * 3600) + 3600; } while (bytes_buffered > 0) { if ((bytes_buffered = read_msg()) == INCORRECT) { bytes_buffered -= bytes_done; msa[afd_no].connect_status = CONNECTION_DEFUNCT; retry_interval = RETRY_INTERVAL; goto done; } else { if (evaluate_message(&bytes_done) == AFDD_SHUTTING_DOWN) { bytes_buffered -= bytes_done; retry_interval = RETRY_INTERVAL; goto done; } bytes_buffered -= bytes_done; } } if ((msa[afd_no].log_capabilities > 0) && (got_log_capabilities == YES) && (send_log_request == NO)) { if (send_got_log_capabilities(afd_no) == SUCCESS) { send_log_request = YES; } } /* Initialise descriptor set and timeout. */ FD_SET(sock_fd, &rset); timeout.tv_usec = 0; timeout.tv_sec = msa[afd_no].poll_interval; /* Wait for message x seconds and then continue. */ status = select(sock_fd + 1, &rset, NULL, NULL, &timeout); if (FD_ISSET(sock_fd, &rset)) { msa[afd_no].last_data_time = time(NULL); do { if ((bytes_buffered = read_msg()) == INCORRECT) { msa[afd_no].connect_status = CONNECTION_DEFUNCT; retry_interval = RETRY_INTERVAL; goto done; } else { if (evaluate_message(&bytes_done) == AFDD_SHUTTING_DOWN) { bytes_buffered -= bytes_done; retry_interval = RETRY_INTERVAL; goto done; } bytes_buffered -= bytes_done; } } while (bytes_buffered > 0); } else if (status == 0) { if ((bytes_buffered = tcp_cmd("%s", STAT_CMD)) < 0) { if (bytes_buffered != -AFDD_SHUTTING_DOWN) { mon_log(ERROR_SIGN, __FILE__, __LINE__, 0L, msg_str, "Failed to send %s command.", STAT_CMD); (void)tcp_quit(); msa[afd_no].connect_status = CONNECTION_DEFUNCT; } retry_interval = RETRY_INTERVAL; break; } else { msa[afd_no].last_data_time = now + msa[afd_no].poll_interval; if (evaluate_message(&bytes_done) == AFDD_SHUTTING_DOWN) { bytes_buffered -= bytes_done; retry_interval = RETRY_INTERVAL; break; } bytes_buffered -= bytes_done; } } else { system_log(FATAL_SIGN, __FILE__, __LINE__, "select() error : %s", strerror(errno)); exit(SELECT_ERROR); } if ((msa[afd_no].connect_time != 0) && (msa[afd_no].disconnect_time != 0)) { if ((time(NULL) - start_time) >= msa[afd_no].connect_time) { if (tcp_quit() != SUCCESS) { mon_log(ERROR_SIGN, __FILE__, __LINE__, 0L, msg_str, "Failed to send %s command.", QUIT_CMD); } retry_interval = msa[afd_no].disconnect_time; msa[afd_no].connect_status = DISCONNECTED; mon_log(INFO_SIGN, NULL, 0, 0L, NULL, "========> Disconnect (due to connect interval %ds) <========", msa[afd_no].connect_time); break; } } if ((msa[afd_no].afd_switching != NO_SWITCHING) && (current_afd_toggle != msa[afd_no].afd_toggle)) { if (tcp_quit() != SUCCESS) { mon_log(ERROR_SIGN, __FILE__, __LINE__, 0L, msg_str, "Failed to send %s command.", QUIT_CMD); } msa[afd_no].connect_status = DISCONNECTED; retry_interval = 0L; mon_log(WARN_SIGN, NULL, 0, 0L, NULL, "Switching to %s%d (%s at port %d).", msa[afd_no].afd_alias, (int)msa[afd_no].afd_toggle, msa[afd_no].hostname[(int)msa[afd_no].afd_toggle], msa[afd_no].port[(int)msa[afd_no].afd_toggle]); break; } } /* for (;;) */ } } done: if (adl != NULL) { #ifdef HAVE_MMAP if (munmap((void *)adl, adl_size) == -1) #else if (munmap_emu((void *)adl) == -1) #endif { system_log(ERROR_SIGN, __FILE__, __LINE__, "munmap() error : %s", strerror(errno)); } adl = NULL; } if (ajl != NULL) { #ifdef HAVE_MMAP if (munmap((void *)ajl, ajl_size) == -1) #else if (munmap_emu((void *)ajl) == -1) #endif { system_log(ERROR_SIGN, __FILE__, __LINE__, "munmap() error : %s", strerror(errno)); } ajl = NULL; } msa[afd_no].tr = 0; /* Initialise descriptor set and timeout. */ FD_ZERO(&rset); FD_SET(retry_fd, &rset); timeout.tv_usec = 0L; timeout.tv_sec = retry_interval; /* Wait for message x seconds and then continue. */ status = select(retry_fd + 1, &rset, NULL, NULL, &timeout); if (FD_ISSET(retry_fd, &rset)) { /* * This fifo is just here to wake up, so disregard whats * in it. */ if (read(retry_fd, msg_str, MAX_RET_MSG_LENGTH) < 0) { system_log(ERROR_SIGN, __FILE__, __LINE__, "read() error on %s : %s", retry_fifo, strerror(errno)); } } else if (status == -1) { system_log(FATAL_SIGN, __FILE__, __LINE__, "select() error : %s", strerror(errno)); exit(INCORRECT); } if (retry_interval == 0L) { if (msa[afd_no].disconnect_time != 0L) { retry_interval = msa[afd_no].disconnect_time; } else { retry_interval = RETRY_INTERVAL; } } } /* for (;;) */ }