int iogen(int argc, char *argv[]) { int ch; int i, nr_proc = 1; struct stat sb; /* set defaults */ io_size = 64 * 1024; file_size = 1 * 1024 * 1024 * 1024; read_perc = 50; randomize = 0; interval = 60; strlcpy(target_dir, "./", sizeof target_dir); strlcpy(result_dir, "./", sizeof result_dir); while ((ch = getopt(argc, argv, "b:d:f:kn:p:rs:t:T:P:")) != -1) { switch (ch) { case 'b': io_size = atoll(optarg) * quantify(optarg[strlen(optarg) - 1]); if (io_size < MINIOSIZE) errx(1, "io block size too small"); if (io_size > MAXIOSIZE) errx(1, "io block size too large"); break; case 'd': if (stat(optarg, &sb) == -1) err(1, "stat failed"); else if (sb.st_mode & S_IFDIR) strlcpy(target_dir, optarg, sizeof target_dir); else errx(1, "invalid target path"); break; case 'f': if (stat(optarg, &sb) == -1) err(1, "stat failed"); else if (sb.st_mode & S_IFDIR) strlcpy(result_dir, optarg, sizeof result_dir); else errx(1, "invalid result path"); break; case 'k': killall(); /* NOTREACHED */ break; case 'n': nr_proc = atol(optarg); if (nr_proc < 1) errx(1, "invalid number of processes"); break; case 'p': read_perc = atol(optarg); if (read_perc < 10) errx(1, "read percentage size too small"); if (read_perc > 90) errx(1, "read percentage size too large"); break; case 'r': randomize = 1; break; case 's': file_size = atoll(optarg) * quantify(optarg[strlen(optarg) - 1]); if (file_size < MINFILESIZE) errx(1, "file size too small"); if (file_size > MAXFILESIZE) errx(1, "file size too large"); break; case 't': interval = atoi(optarg); if (interval < 1) errx(1, "time slice too small"); if (interval > 3600) errx(1, "time slice too large"); break; case 'T': timeout = atoi(optarg); if (timeout < 1) errx(1, "time slice too small"); if (timeout > 3600) errx(1, "time slice too large"); break; case 'P': if (optarg[0] == '?') { show_patterns(); exit(0); } pattern = atoi(optarg); if (pattern > IOGEN_PAT_TEXT) errx(1, "illegal pattern"); break; case 'h': default: usage(IOGEN_USAGE); /* NOTREACHED */ break; } } err_log(0, "%s test run commences with %u proc(s)", IOGEN_VERSION, nr_proc); err_log(0, "file size: %llu io size: %llu read percentage: %i random: %s " "target: %s result: %s update interval: %i", file_size, io_size, read_perc, randomize ? "yes" : "no", target_dir, result_dir, interval); for (i = 0; i < nr_proc; i++) fprintf(stderr, "child spawned %i\n", run_io()); return (0); }
int main(int argc, char **argv) { struct cmdline_config config = { .run_foreground = false, .bind_local_only = false, .user_name = NULL, .passwd_file = NULL, .request_target = "/api/jet/", }; init_parser(); int c; while ((c = getopt (argc, argv, "flp:r:u:")) != -1) { switch (c) { case 'f': config.run_foreground = true; break; case 'l': config.bind_local_only = true; break; case 'p': config.passwd_file = optarg; break; case 'r': config.request_target = optarg; break; case 'u': config.user_name = optarg; break; case '?': fprintf(stderr, "Usage: %s [-l] [-f] [-r <request target>] [-u <username>] [-p <password file>]\n", argv[0]); return EXIT_FAILURE; break; } } if (load_passwd_data(config.passwd_file) < 0) { log_err("Cannot load password file!\n"); return EXIT_FAILURE; } signal(SIGPIPE, SIG_IGN); int ret = EXIT_SUCCESS; if ((state_hashtable_create()) == -1) { log_err("Cannot allocate hashtable for states!\n"); ret = EXIT_FAILURE; goto state_hashtable_create_failed; } struct eventloop_epoll eloop = { .epoll_fd = 0, .loop = { .this_ptr = &eloop, .init = eventloop_epoll_init, .destroy = eventloop_epoll_destroy, .run = eventloop_epoll_run, .add = eventloop_epoll_add, .remove = eventloop_epoll_remove, }, }; log_info("%s version %s started", CJET_NAME, CJET_VERSION); if (run_io(&eloop.loop, &config) < 0) { ret = EXIT_FAILURE; goto run_io_failed; } log_info("%s stopped", CJET_NAME); run_io_failed: state_hashtable_delete(); state_hashtable_create_failed: free_passwd_data(); return ret; }
int main(int argc, char *argv[]) { int listenfd; struct sockaddr_in serv_addr; listenfd = socket(AF_INET, SOCK_STREAM, 0); if (listenfd < 0) { printf("Unable to open socket: %d (%s)\n", errno, strerror(errno)); return 1; } serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(60002); if (bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { printf("Unable to bind address: %d (%s)\n", errno, strerror(errno)); return 1; } listen(listenfd,5); if (fork()) exit(0); setsid(); if (fork()) exit(0); std::vector<Client> clients; while (true) { fd_set rfds, wfds; FD_ZERO(&rfds); FD_ZERO(&wfds); int maxfd = 0; if (clients.size() < MAX_CLIENTS) { FD_SET(listenfd, &rfds); maxfd = listenfd; } for (auto it = clients.begin(), eit = clients.end(); it != eit; ++it) { if (it->write_ready()) { FD_SET(it->fd, &wfds); if (maxfd < it->fd) maxfd = it->fd; } if (it->read_ready()) { FD_SET(it->fd, &rfds); if (maxfd < it->fd) maxfd = it->fd; } } if (select(maxfd+1, &rfds, &wfds, NULL, NULL) < 0) { if (errno == EINTR) continue; syslog(LOG_ERR, "Error in select(): %m"); break; } // Process any existing connections. for (auto it = clients.begin(), eit = clients.end(); it != eit; ++it) { if (FD_ISSET(it->fd, &rfds) || FD_ISSET(it->fd, &wfds)) it->run_io(); } // Accept New Connections if (FD_ISSET(listenfd, &rfds)) { struct sockaddr_in client_addr; socklen_t client_addr_len = sizeof(client_addr); int clientfd = accept(listenfd, reinterpret_cast<struct sockaddr*>(&client_addr), &client_addr_len); #ifdef IP_ACL_FILE if (authorize_ip(ntohl(client_addr.sin_addr.s_addr))) { #endif clients.emplace_back(clientfd); #ifdef IP_ACL_FILE } else { close(clientfd); char ipaddr[16]; ip2string(ntohl(client_addr.sin_addr.s_addr), ipaddr, 16); syslog(LOG_NOTICE, "Connection attempted from unauthorized IP: %s", ipaddr); } #endif } } return 1; }
int main(int argc, char **argv) { ARK *ark; int i=1; if (argv[1] == NULL) { printf("dev name required as parameter\n"); exit(-1); } if (0 == strncmp(argv[1], "-p", 7)) { printf("Attempting to run with physical lun\n"); ark_create_flag = ARK_KV_PERSIST_STORE; i = 2; } printf("%s: SYNC: npool:%d nasync:%d basync:%d\n", argv[i], KV_NPOOL, KV_NASYNC, KV_BASYNC); fflush(stdout); /* 1 ctxt, vlen 4k */ init_kv_db(KV_PTHS, KLEN, VLEN_4k, LEN_4k); NEW_ARK(argv[i], &ark); printf("ctxt:1 4k-k/v: 75%% read: "); fflush(stdout); fp = (void*(*)(void*))do_75_percent_read; run_io(ark, KV_PTHS); free_kv_db(KV_PTHS, LEN_4k); assert(0 == ark_delete(ark)); /* 1 ctxt, vlen 4k */ init_kv_db(KV_PTHS, KLEN, VLEN_4k, LEN_4k); NEW_ARK(argv[i], &ark); printf("ctxt:1 4k-k/v: 100%% read: "); fflush(stdout); fp = (void*(*)(void*))do_100_percent_read; run_io(ark, KV_PTHS); free_kv_db(KV_PTHS, LEN_4k); assert(0 == ark_delete(ark)); /* 1 ctxt, vlen 64k */ init_kv_db(KV_PTHS_BIG, KLEN, VLEN_64k, LEN_BIG); NEW_ARK(argv[i], &ark); printf("ctxt:1 64k-k/v: 100%% read: "); fflush(stdout); fp = (void*(*)(void*))do_100_percent_read; run_io(ark, KV_PTHS_BIG); free_kv_db(KV_PTHS_BIG, LEN_BIG); assert(0 == ark_delete(ark)); /* 1 ctxt, vlen 1mb */ init_kv_db(KV_PTHS_BIG, KLEN, VLEN_500k, LEN_BIG); NEW_ARK(argv[i], &ark); printf("ctxt:1 500k-k/v: 100%% read: "); fflush(stdout); fp = (void*(*)(void*))do_100_percent_read; run_io(ark, KV_PTHS_BIG); free_kv_db(KV_PTHS_BIG, LEN_BIG); assert(0 == ark_delete(ark)); /* if physical lun, cannot run multi-context, so exit */ if (ARK_KV_PERSIST_STORE == ark_create_flag) return 0; printf("ctxt:4 4k-k/v: 100%% read: "); fflush(stdout); fp = (void*(*)(void*))do_100_percent_read; run_max_io(argv[i], VLEN_4k, LEN_4k); printf("ctxt:4 64k-k/v: 100%% read: "); fflush(stdout); fp = (void*(*)(void*))do_100_percent_read; run_max_io(argv[i], VLEN_64k, LEN_BIG); return 0; }