/* Create a control connection to a slave */ static int new_control_connection(group_t *g, char *host) { protocol_t *p; if (host == NULL || host[0] == '\0') { uperf_error("remotehost not specified. Check profile\n"); return (UPERF_FAILURE); } /* First check if we already have one */ p = g->control; while (p) { if (strncasecmp(host, p->host, MAXHOSTNAME) == 0) { uperf_info("Resuing control connection for %s\n", host); return (UPERF_SUCCESS); } p = p->next; } /* Not found, create a new one */ p = create_protocol(PROTOCOL_TCP, host, MASTER_PORT, MASTER); if (p != NULL) { /* Try connecting */ if (p->connect(p, NULL) == 0) { p->next = g->control; if (g->control) g->control->prev = p; g->control = p; slaves[no_slaves++] = p; return (UPERF_SUCCESS); } } uperf_error("Error connecting to %s\n", host); return (UPERF_FAILURE); }
static int spawn_strands_group(uperf_shm_t *shm, group_t *gp, int id) { int j; int rc; strand_t *s; for (j = 0; j < gp->nthreads; j++) { s = shm_get_strand(shm, id + j); s->worklist = group_clone(gp); s->shmptr = shm; s->role = MASTER; (void) group_assign_stat(shm, s->worklist, id + j); if (STRAND_IS_PROCESS(gp)) { s->strand_flag |= STRAND_TYPE_PROCESS; rc = fork(); if (rc == 0) { (void) strand_run(s); exit(0); } else if (rc > 0) { s->pid = rc; } else { perror("fork"); uperf_error("fork failed"); return (1); } } else { s->strand_flag |= STRAND_TYPE_THREAD; rc = pthread_create(&(s->tid), NULL, &strand_run, (void *) s); if (rc) { perror("pthread_create"); uperf_error("pthread_create failed"); return (1); } } } return (0); }
static uperf_shm_t * master_init(workorder_t *w) { uperf_shm_t *shm; if (protocol_init(NULL) == UPERF_FAILURE) { return (NULL); } if (master_setup_signal_handler() != UPERF_SUCCESS) { uperf_error("Error setting up signal handlers\n"); return (NULL); } if ((shm = shm_init(w)) == NULL) { return (NULL); } if (create_control_connections(w) != UPERF_SUCCESS) { shm_fini(shm); return (NULL); } shm->endian = UPERF_ENDIAN_VALUE; shm->global_error = 0; shm->role = MASTER; shm->workorder = w; if (strand_init_all(shm, w) != UPERF_SUCCESS) { uperf_error("error in strand_init_all"); shm_fini(shm); return (NULL); } /* Initialize barriers */ if (shm_init_barriers_master(shm, shm->workorder) != 0) { shm_fini(shm); return (NULL); } return (shm); }
static int say_goodbye(goodbye_stat_t *total, protocol_t *p, int timeout) { goodbye_t g; char msg[GOODBYE_MESSAGE_LEN]; if (recv_goodbye(&g, p, timeout) != UPERF_SUCCESS) { uperf_error("\nError saying goodbye with %s\n", p->host); return (1); } switch (g.msg_type) { case MESSAGE_INFO: (void) snprintf(msg, GOODBYE_MESSAGE_LEN, "[%s] %s", p->host, g.message); uperf_info(msg); break; case MESSAGE_NONE: break; case MESSAGE_ERROR: (void) snprintf(msg, GOODBYE_MESSAGE_LEN, "[%s] %s", p->host, g.message); uperf_log_msg(UPERF_LOG_ERROR, 0, msg); break; case MESSAGE_WARNING: (void) snprintf(msg, GOODBYE_MESSAGE_LEN, "[%s] %s\n", p->host, g.message); uperf_log_msg(UPERF_LOG_WARN, 0, msg); break; } (void) print_goodbye_stat(p->host, &g.gstat); total->elapsed_time = MAX(g.gstat.elapsed_time, total->elapsed_time); total->error += g.gstat.error; total->bytes_xfer += g.gstat.bytes_xfer; total->count += g.gstat.count; return (0); }
static int protocol_ssl_undefined(protocol_t * p, void *options) { uperf_error("Undefined function in protocol called\n"); return (-1); }