static int setup_queues(struct nullb *nullb) { struct nullb_queue *nq; int i; nullb->queues = kzalloc(submit_queues * sizeof(*nq), GFP_KERNEL); if (!nullb->queues) return 1; nullb->nr_queues = 0; nullb->queue_depth = hw_queue_depth; if (queue_mode == NULL_Q_MQ) return 0; for (i = 0; i < submit_queues; i++) { nq = &nullb->queues[i]; init_waitqueue_head(&nq->wait); nq->queue_depth = hw_queue_depth; if (setup_commands(nq)) break; nullb->nr_queues++; } if (i == submit_queues) return 0; cleanup_queues(nullb); return 1; }
/* * Initalizer for a CLI context */ cli_ctx * cli_init_cmd(AnySerial *aserial, common_cli_ctx *common, WiFly *wifly, Encoder *ra, Encoder *dec) { cli_ctx *ctx; ctx = (cli_ctx *)malloc(sizeof(cli_ctx)); bzero(ctx, sizeof(cli_ctx)); ctx->common = common; ctx->common->test_mode = false; ctx->common->alignment = false; ctx->state = BASIC_DSC; ctx->prev_state = NONE; ctx->serial = aserial; ctx->wifly = wifly; ctx->ra = ra; ctx->dec = dec; if (wifly == NULL) { ctx->eat_errors = true; } else { ctx->eat_errors = false; } setup_commands(ctx); return ctx; }
/* * Run this every time we change CLI state * to update our CTX */ void change_state(cli_ctx *ctx, cli_state new_state) { ctx->prev_state = ctx->state; ctx->state = new_state; setup_commands(ctx); // if changing to WIFI mode, then enter now. if (ctx->state == WIFI && ctx->wifly != NULL) { wifi_interactive(ctx); } else if (ctx->state == WIFI) { ctx->serial->printf("ctx->wifly not defined. Can't change mode\n"); ctx->state = ctx->prev_state; setup_commands(ctx); } else { ctx->serial->printf("OK\n"); } }
static int init_driver_queues(struct nullb *nullb) { struct nullb_queue *nq; int i, ret = 0; for (i = 0; i < submit_queues; i++) { nq = &nullb->queues[i]; null_init_queue(nullb, nq); ret = setup_commands(nq); if (ret) return ret; nullb->nr_queues++; } return 0; }
int main(int argc, char **argv) { int ch, longindex, ret; unsigned long flags; struct option *long_options; const struct command *commands; const char *short_options; char *p; const struct sd_option *sd_opts; uint8_t sdhost[16]; int sdport; log_dog_operation(argc, argv); install_crash_handler(crash_handler); init_commands(&commands); if (argc < 2) usage(commands, 0); flags = setup_commands(commands, argv[1], argv[2]); optind = 3; sd_opts = build_sd_options(command_opts); long_options = build_long_options(sd_opts); short_options = build_short_options(sd_opts); while ((ch = getopt_long(argc, argv, short_options, long_options, &longindex)) >= 0) { switch (ch) { case 'a': if (!str_to_addr(optarg, sdhost)) { sd_err("Invalid ip address %s", optarg); return EXIT_FAILURE; } memcpy(sd_nid.addr, sdhost, sizeof(sdhost)); break; case 'p': sdport = strtol(optarg, &p, 10); if (optarg == p || sdport < 1 || sdport > UINT16_MAX) { sd_err("Invalid port number '%s'", optarg); exit(EXIT_USAGE); } sd_nid.port = sdport; break; case 'r': raw_output = true; break; case 'v': verbose = true; break; case 'h': subcommand_usage(argv[1], argv[2], EXIT_SUCCESS); break; case '?': usage(commands, EXIT_USAGE); break; default: if (command_parser) command_parser(ch, optarg); else usage(commands, EXIT_USAGE); break; } } if (!is_stdout_console() || raw_output) highlight = false; if (flags & CMD_NEED_NODELIST) { ret = update_node_list(SD_MAX_NODES); if (ret < 0) { sd_err("Failed to get node list"); exit(EXIT_SYSFAIL); } } if (flags & CMD_NEED_ARG && argc == optind) subcommand_usage(argv[1], argv[2], EXIT_USAGE); if (init_event(EPOLL_SIZE) < 0) exit(EXIT_SYSFAIL); if (init_work_queue(get_nr_nodes) != 0) { sd_err("Failed to init work queue"); exit(EXIT_SYSFAIL); } if (sockfd_init()) { sd_err("sockfd_init() failed"); exit(EXIT_SYSFAIL); } ret = command_fn(argc, argv); if (ret == EXIT_USAGE) subcommand_usage(argv[1], argv[2], EXIT_USAGE); return ret; }
int main(int argc, char **argv) { int ch, longindex, ret; unsigned long flags; struct option *long_options; const struct command *commands; const char *short_options; char *p, *env; const struct sd_option *sd_opts; uint8_t sdhost[16]; int sdport; struct timespec start, end; start = get_time_tick(); log_dog_operation(argc, argv); install_crash_handler(crash_handler); init_commands(&commands); if (argc < 2) usage(commands, 0); flags = setup_commands(commands, argv[1], argv[2]); optind = 3; sd_opts = build_sd_options(command_opts); long_options = build_long_options(sd_opts); short_options = build_short_options(sd_opts); env = getenv("SHEEPDOG_DOG_ADDR"); if (env) { if (!str_to_addr(env, sdhost)) { sd_err("Invalid ip address %s", env); return EXIT_FAILURE; } memcpy(sd_nid.addr, sdhost, sizeof(sdhost)); } env = getenv("SHEEPDOG_DOG_PORT"); if (env) { sdport = strtol(env, &p, 10); if (env == p || sdport < 1 || sdport > UINT16_MAX || !is_numeric(env)) { sd_err("Invalid port number '%s'", env); exit(EXIT_USAGE); } sd_nid.port = sdport; } while ((ch = getopt_long(argc, argv, short_options, long_options, &longindex)) >= 0) { switch (ch) { case 'a': if (!str_to_addr(optarg, sdhost)) { sd_err("Invalid ip address %s", optarg); return EXIT_FAILURE; } memcpy(sd_nid.addr, sdhost, sizeof(sdhost)); break; case 'p': sdport = strtol(optarg, &p, 10); if (optarg == p || sdport < 1 || sdport > UINT16_MAX || !is_numeric(optarg)) { sd_err("Invalid port number '%s'", optarg); exit(EXIT_USAGE); } sd_nid.port = sdport; break; case 'r': raw_output = true; break; case 'v': verbose = true; break; case 'h': subcommand_usage(argv[1], argv[2], EXIT_SUCCESS); break; case 'T': elapsed_time = true; break; case '?': usage(commands, EXIT_USAGE); break; default: if (command_parser) command_parser(ch, optarg); else usage(commands, EXIT_USAGE); break; } } if (sd_inode_actor_init(dog_bnode_writer, dog_bnode_reader) < 0) exit(EXIT_SYSFAIL); if (!is_stdout_console() || raw_output) highlight = false; if (flags & CMD_NEED_NODELIST) { ret = update_node_list(SD_MAX_NODES); if (ret < 0) { sd_err("Failed to get node list"); exit(EXIT_SYSFAIL); } } if (flags & CMD_NEED_ARG && argc == optind) subcommand_usage(argv[1], argv[2], EXIT_USAGE); if (init_event(EPOLL_SIZE) < 0) exit(EXIT_SYSFAIL); if (wq_trace_init() < 0) exit(EXIT_SYSFAIL); if (init_work_queue(get_nr_nodes) != 0) { sd_err("Failed to init work queue"); exit(EXIT_SYSFAIL); } if (sockfd_init()) { sd_err("sockfd_init() failed"); exit(EXIT_SYSFAIL); } ret = command_fn(argc, argv); if (ret == EXIT_USAGE) subcommand_usage(argv[1], argv[2], EXIT_USAGE); if (elapsed_time) { end = get_time_tick(); printf("\nElapsed time: %.3lf seconds\n", get_time_interval(&start, &end)); } return ret; }
int main(int argc, char **argv) { int ch, longindex, ret; unsigned long flags; struct option *long_options; const struct command *commands; const char *short_options; char *p; const struct sd_option *sd_opts; install_crash_handler(crash_handler); init_commands(&commands); if (argc < 3) usage(commands, 0); flags = setup_commands(commands, argv[1], argv[2]); optind = 3; sd_opts = build_sd_options(command_opts); long_options = build_long_options(sd_opts); short_options = build_short_options(sd_opts); while ((ch = getopt_long(argc, argv, short_options, long_options, &longindex)) >= 0) { switch (ch) { case 'a': sdhost = optarg; break; case 'p': sdport = strtol(optarg, &p, 10); if (optarg == p || sdport < 1 || sdport > UINT16_MAX) { fprintf(stderr, "Invalid port number '%s'\n", optarg); exit(EXIT_USAGE); } break; case 'r': raw_output = true; break; case 'h': subcommand_usage(argv[1], argv[2], EXIT_SUCCESS); break; case '?': usage(commands, EXIT_USAGE); break; default: if (command_parser) command_parser(ch, optarg); else usage(commands, EXIT_USAGE); break; } } if (!is_stdout_console() || raw_output) highlight = false; if (flags & SUBCMD_FLAG_NEED_NODELIST) { ret = update_node_list(SD_MAX_NODES, 0); if (ret < 0) { fprintf(stderr, "Failed to get node list\n"); exit(EXIT_SYSFAIL); } } if (flags & SUBCMD_FLAG_NEED_ARG && argc == optind) subcommand_usage(argv[1], argv[2], EXIT_USAGE); return command_fn(argc, argv); }