int stats_update(int type, strand_t *s, newstats_t *stats, uint64_t size, uint64_t count) { if (DISABLED_STATS(options)) return (0); switch (type) { case FLOWOP_BEGIN: if (ENABLED_FLOWOP_STATS(options) || ENABLED_HISTORY_STATS(options)) { return (newstat_begin(s, stats, 0, 0)); } return (0); case FLOWOP_END: /* We update the strand stats instead of having a global one */ STRAND_STAT(s)->size += size*count; /* Thread safe */ STRAND_STAT(s)->count += count; /* Thread safe */ if (ENABLED_FLOWOP_STATS(options) || ENABLED_HISTORY_STATS(options)) { int err = newstat_end(s, stats, size, count); if (ENABLED_HISTORY_STATS(options)) { history_record(s, NSTAT_FLOWOP, stats->end_time, stats->end_time - stats->time_used_start); } return (err); } return (0); case TXN_BEGIN: if (ENABLED_TXN_STATS(options)) return (newstat_begin(s, stats, 0, 0)); return (0); case GROUP_BEGIN: if (ENABLED_GROUP_STATS(options)) return (newstat_begin(s, stats, 0, 0)); return (0); case TXN_END: if (ENABLED_TXN_STATS(options)) return (newstat_end(s, stats, 0, count)); return (0); case GROUP_END: if (ENABLED_GROUP_STATS(options)) return (newstat_end(s, stats, 0, count)); return (0); } return (0); }
/*call by main*/ int next_cmd(char *out_cmd) { unsigned char c = 0; int key_no = 0; int seq_char = 0; int str_valid = 0; /*set terminal new attrib */ term_config(); /*termial initial */ term_init(out_cmd); /*main loop */ while ((c = getc(stdin)) != '\n') { key_no = 0; seq_char = 0; if (!_isspace(c)) { str_valid = 1; } if (c == 27) { /*escape sequence */ if ((c = getc(stdin)) == '[' || c == 'O') { c = getc(stdin); seq_char = 1; } } /*search for bind key handle function */ while (key_no < sizeof (key_bind) / sizeof (key_bind[0])) { if ((seq_char == key_bind[key_no].is_eseq) && (c == key_bind[key_no].key_last)) { key_bind[key_no].func(); break; } key_no++; } if (key_no == sizeof (key_bind) / sizeof (key_bind[0])) handle_normal(out_cmd, c); } /*handle enter when at the end of a line */ if (term_cursor) putchar('\n'); /* record command history without '\n' */ history_record(out_cmd); #if 0 /* add '\n' to out_cmd */ if (str_valid) { out_cmd[cmd_strlen++] = '\n'; } else { cmd_strlen = 0; out_cmd[cmd_strlen++] = '\n'; } if (cmd_strlen > 1 && out_cmd[cmd_strlen - 1] == '\n') out_cmd[cmd_strlen - 1] = 0; #else if (!str_valid) cmd_strlen = 0; #endif /*retore terminal to orginal status */ term_restore(); fflush(stdout); return cmd_strlen; }
static int do_fence_request_vsock(int fd, fence_req_t *req, vsock_info *info) { char response = 1; struct vsock_hostlist_arg arg; uint32_t peer_cid = 0; char peer_cid_str[24]; int ret; ret = get_peer_cid(fd, &peer_cid); if (ret < 0) { printf("Unable to get peer CID: %s\n", strerror(errno)); return -1; } snprintf(peer_cid_str, sizeof(peer_cid_str), "%u", peer_cid); /* Noops if auth == AUTH_NONE */ if (sock_response(fd, info->args.auth, info->key, info->key_len, 10) <= 0) { printf("CID %u Failed to respond to challenge\n", peer_cid); close(fd); return -1; } ret = sock_challenge(fd, info->args.auth, info->key, info->key_len, 10); if (ret <= 0) { printf("Remote CID %u failed challenge\n", peer_cid); close(fd); return -1; } dbg_printf(2, "Request %d seqno %d target %s from CID %u\n", req->request, req->seqno, req->domain, peer_cid); switch(req->request) { case FENCE_NULL: response = info->cb->null((char *)req->domain, info->priv); break; case FENCE_ON: if (map_check(info->map, peer_cid_str, (const char *)req->domain) == 0) { response = RESP_PERM; break; } response = info->cb->on((char *)req->domain, peer_cid_str, req->seqno, info->priv); break; case FENCE_OFF: if (map_check(info->map, peer_cid_str, (const char *)req->domain) == 0) { response = RESP_PERM; break; } response = info->cb->off((char *)req->domain, peer_cid_str, req->seqno, info->priv); break; case FENCE_REBOOT: if (map_check(info->map, peer_cid_str, (const char *)req->domain) == 0) { response = RESP_PERM; break; } response = info->cb->reboot((char *)req->domain, peer_cid_str, req->seqno, info->priv); break; case FENCE_STATUS: if (map_check(info->map, peer_cid_str, (const char *)req->domain) == 0) { response = RESP_PERM; break; } response = info->cb->status((char *)req->domain, info->priv); break; case FENCE_DEVSTATUS: response = info->cb->devstatus(info->priv); break; case FENCE_HOSTLIST: arg.map = info->map; arg.fd = fd; vsock_hostlist_begin(arg.fd); response = info->cb->hostlist(vsock_hostlist, &arg, info->priv); vsock_hostlist_end(arg.fd); break; } dbg_printf(3, "Sending response to caller CID %u...\n", peer_cid); if (_write_retry(fd, &response, 1, NULL) < 0) perror("write"); history_record(info->history, req); if (fd != -1) close(fd); return 1; }
static int do_fence_request_tcp(fence_req_t *req, mcast_info *info) { char ip_addr_src[1024]; int fd = -1; char response = 1; struct mcast_hostlist_arg arg; fd = connect_tcp(req, info->args.auth, info->key, info->key_len); if (fd < 0) { dbg_printf(2, "Could not send reply to fence request: %s\n", strerror(errno)); goto out; } inet_ntop(req->family, req->address, ip_addr_src, sizeof(ip_addr_src)); dbg_printf(2, "Request %d seqno %d src %s target %s\n", req->request, req->seqno, ip_addr_src, req->domain); switch(req->request) { case FENCE_NULL: response = info->cb->null((char *)req->domain, info->priv); break; case FENCE_ON: if (map_check(info->map, ip_addr_src, (const char *)req->domain) == 0) { response = RESP_PERM; break; } response = info->cb->on((char *)req->domain, ip_addr_src, req->seqno, info->priv); break; case FENCE_OFF: if (map_check(info->map, ip_addr_src, (const char *)req->domain) == 0) { response = RESP_PERM; break; } response = info->cb->off((char *)req->domain, ip_addr_src, req->seqno, info->priv); break; case FENCE_REBOOT: if (map_check(info->map, ip_addr_src, (const char *)req->domain) == 0) { response = RESP_PERM; break; } response = info->cb->reboot((char *)req->domain, ip_addr_src, req->seqno, info->priv); break; case FENCE_STATUS: if (map_check(info->map, ip_addr_src, (const char *)req->domain) == 0) { response = RESP_PERM; break; } response = info->cb->status((char *)req->domain, info->priv); break; case FENCE_DEVSTATUS: response = info->cb->devstatus(info->priv); break; case FENCE_HOSTLIST: arg.map = info->map; arg.src = ip_addr_src; arg.fd = fd; mcast_hostlist_begin(arg.fd); response = info->cb->hostlist(mcast_hostlist, &arg, info->priv); mcast_hostlist_end(arg.fd); break; } dbg_printf(3, "Sending response to caller...\n"); if (write(fd, &response, 1) < 0) { perror("write"); } /* XVM shotguns multicast packets, so we want to avoid * acting on the same request multiple times if the first * attempt was successful. */ history_record(info->history, req); out: if (fd != -1) close(fd); return 1; }
static int do_fence_request_tcp(int fd, fence_req_t *req, tcp_info *info) { char ip_addr_src[1024]; char response = 1; struct tcp_hostlist_arg arg; /* Noops if auth == AUTH_NONE */ if (tcp_response(fd, info->args.auth, info->key, info->key_len, 10) <= 0) { printf("Failed to respond to challenge\n"); close(fd); return -1; } if (tcp_challenge(fd, info->args.auth, info->key, info->key_len, 10) <= 0) { printf("Remote failed challenge\n"); close(fd); return -1; } dbg_printf(2, "Request %d seqno %d target %s\n", req->request, req->seqno, req->domain); switch(req->request) { case FENCE_NULL: response = info->cb->null((char *)req->domain, info->priv); break; case FENCE_ON: if (map_check(info->map, ip_addr_src, (const char *)req->domain) == 0) { response = RESP_PERM; break; } response = info->cb->on((char *)req->domain, ip_addr_src, req->seqno, info->priv); break; case FENCE_OFF: if (map_check(info->map, ip_addr_src, (const char *)req->domain) == 0) { response = RESP_PERM; break; } response = info->cb->off((char *)req->domain, ip_addr_src, req->seqno, info->priv); break; case FENCE_REBOOT: if (map_check(info->map, ip_addr_src, (const char *)req->domain) == 0) { response = RESP_PERM; break; } response = info->cb->reboot((char *)req->domain, ip_addr_src, req->seqno, info->priv); break; case FENCE_STATUS: if (map_check(info->map, ip_addr_src, (const char *)req->domain) == 0) { response = RESP_PERM; break; } response = info->cb->status((char *)req->domain, info->priv); break; case FENCE_DEVSTATUS: response = info->cb->devstatus(info->priv); break; case FENCE_HOSTLIST: arg.map = info->map; arg.src = ip_addr_src; arg.fd = fd; tcp_hostlist_begin(arg.fd); response = info->cb->hostlist(tcp_hostlist, &arg, info->priv); tcp_hostlist_end(arg.fd); break; } dbg_printf(3, "Sending response to caller...\n"); if (write(fd, &response, 1) < 0) { perror("write"); } history_record(info->history, req); if (fd != -1) close(fd); return 1; }