Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
    struct option long_opts[] = {
        { "async",         no_argument,       NULL, 'a' },
        { "break",         no_argument,       NULL, 'b' },
        { "disk",          required_argument, NULL, 'd' },
        { "get-status",    no_argument,       NULL, 'G' },
        { "help",          no_argument,       NULL, 'h' },
        { "list-statuses", no_argument,       NULL, 'L' },
        { "offset",        required_argument, NULL, 'o' },
/*      { "random",        no_argument,       NULL, 'r' }, */
        { "size",          required_argument, NULL, 's' },
        { "set-status",    required_argument, NULL, 'S' },
        { "write",         no_argument,       NULL, 'w' },
        { NULL,            0,                 NULL, '\0' }
    };
    int long_idx;
    int opt;
    enum {
        OP_IO,
        OP_LIST_STATUSES,
        OP_GET_STATUS,
        OP_SET_STATUS,
        OP_DEACTIVATE_DEVICE
    } op = OP_IO;
    char *disk_path = NULL;
/*     bool random = false; */
    bool async = false;
    bool write = false;
    uint64_t size_in_bytes = 0;
    uint64_t offset = 0;
    char status_str[256] = "";
    int err;

#ifdef WIN32
    os_windows_disable_crash_popup();
#endif

    program = argv[0];

    if (argc == 1)
    {
	fprintf(stderr, "%s: no option given\nType %s --help for usage help\n",
                program, program);
	return -1;
    }

    while (true)
    {
	opt = os_getopt_long(argc, argv, "ad:bGhLo:r:s:wS:", long_opts, &long_idx);
        /* Missing argument, quit right away (os_getopt_long() takes care of
         * printing an error message) */
        if (opt == ':' || opt == '?')
            return 1;

        if (opt == -1)
            break;

	switch (opt)
	{
	case 'a':
	    async = true;
	    break;

	case 'b':
	    op = OP_DEACTIVATE_DEVICE;
	    break;

	case 'd':
	    disk_path = optarg;
	    break;

        case 'G':
            op = OP_GET_STATUS;
            break;

	case 'h':
	    usage();
	    break;

        case 'L':
            op = OP_LIST_STATUSES;
            break;

	case 'o':
            if (to_uint64(optarg, &offset) != EXA_SUCCESS)
            {
                fprintf(stderr, "invalid offset\n");
                exit(1);
            }
	    break;

/* 	case 'r': */
/* 	    random = true; */
/* 	    break; */

	case 's':
            if (to_uint64(optarg, &size_in_bytes) != EXA_SUCCESS)
            {
                fprintf(stderr, "invalid size\n");
                exit(1);
            }
	    break;

	case 'w':
	    write = true;
	    break;

        case 'S':
            op = OP_SET_STATUS;
            strlcpy(status_str, optarg, sizeof(status_str));
            break;
	}
    }

    if (optind < argc)
    {
        fprintf(stderr, "%s: too many arguments\nType %s --help for usage help\n",
                program, program);
        return 1;
    }

    err = exa_rdev_static_init(RDEV_STATIC_GET);
    if (err != 0)
    {
        fprintf(stderr, "failed initializating RDEV statics: error %d\n", err);
        fprintf(stderr, "\tExanodes is probably not running on this node.\n");
        return 1;
    }

    if (disk_path == NULL && op != OP_LIST_STATUSES)
    {
        fprintf(stderr, "no disk path specified\n");
        err = -1;
        goto done;
    }

    switch (op)
    {
    case OP_IO:
        err = do_io(disk_path, async, write, offset, size_in_bytes);
        break;

    case OP_LIST_STATUSES:
        err = list_statuses();
        break;

    case OP_GET_STATUS:
        err = do_status(disk_path, 'g', NULL);
        break;

    case OP_SET_STATUS:
        err = do_status(disk_path, 's', status_str);
        break;

    case OP_DEACTIVATE_DEVICE:
	err = deactivate_device(disk_path);
	break;
    }

done:
    exa_rdev_static_clean(RDEV_STATIC_RELEASE);
    return err ? 1 : 0;
}
Ejemplo n.º 2
0
static void deactivate(GtkWidget *widget, gpointer data)
{
	gtk_main_iteration();

	deactivate_device(client);
}