예제 #1
0
/*************************************************
  Function:         setDeviceNumberRule
  Description:      设置编号规则
  Input:
        devnorule   规则
        devno       设备号

  Output:           无
  Return:           是否成功
  Others:
*************************************************/
int operGuiStorage::setDeviceNumberRule(DEVICENO_RULE devnorule, QString devno)
{
    int tmp1 = 0;
    int tmp2 = 0;
    tmp1 = set_devno_rule(devnorule);
    tmp2 = set_devno(/*DEVICE_TYPE_MANAGER, */devno.toLatin1().data());
    if((tmp1 == 0) && (tmp2 == 0))
        return true;
    else
        return false;
}
static void parse_ccw_args(char *nargv[], int nargc)
{
    /*
     * we might be called like this:
     * chreipl ccw 4711
     */
    if (devno_set) {
        fprintf(stderr, "%s: Use either options or possitional "
                "parameters.\n", name);
        exit(1);
    }
    if (nargc == 0) {
        fprintf(stderr, "%s: ccw action requires device.\n", name);
        exit(1);
    } else if (nargc > 1) {
        fprintf(stderr, "%s: Too many arguments specified for"
                " ccw action.\n", name);
        exit(1);
    }
    set_devno(nargv[0]);
}
static void parse_fcp_args(char *nargv[], int nargc)
{
    /*
     * we might be called like this:
     * chreipl fcp 4711 0x12345... 0x12345...
     */
    if (devno_set || wwpn_set || lun_set) {
        fprintf(stderr, "%s: Use either options or possitional "
                "parameters.\n", name);
        exit(1);
    }
    if (nargc > 3) {
        fprintf(stderr, "%s: Too many arguments specified for "
                "fcp action.\n", name);
        exit(1);
    } else if (nargc != 3) {
        fprintf(stderr, "%s: fcp action requires device, WWPN and "
                "LUN\n", name);
        exit(1);
    }
    set_devno(nargv[0]);
    set_wwpn(nargv[1]);
    set_lun(nargv[2]);
}
void parse_options(int argc, char **argv)
{
    int index, result;

    /*
     * TOOD: In the future we'll add -P for kernel parameter
     */
    const struct option long_options[] = {
        { "help",	 no_argument,		NULL, 'h'},
        { "bootprog",	 required_argument,	NULL, 'b' },
        { "device",	 required_argument,	NULL, 'd' },
        { "lun",	 required_argument,	NULL, 'l' },
        { "wwpn",	 required_argument,	NULL, 'w' },
        { "loadparm",	 required_argument,	NULL, 'L' },
        { "version",	 no_argument,		NULL, 'v' },
        { NULL,		 0,			NULL,  0  }
    };

    /* dont run without any argument */
    if (argc == 0 || argc == 1)
        print_usage_ripl(argv[0]);
    if  (strncmp(argv[1], "fcp", 3) == 0) {
        action = ACT_FCP;
        use_ccw = 0;
    } else if (strncmp(argv[1], "ccw", 3) == 0) {
        use_ccw = 1;
        action = ACT_CCW;
    } else if (strncmp(argv[1], "node", 4) == 0) {
        action = ACT_NODE;
    }
    /*
     *TODO: In the future we will have an additional argument called
     * nss with a parameter -n
     */
    while (1) {
        index = -1;
        result = getopt_long(argc, argv, "hcd:vw:l:f:L:b:",
                             long_options, &index);
        if (result == -1)
            break;		/* end of list */
        switch (result) {
        case 'h':
            print_usage_ripl(argv[0]);
            break;
        case 'd':
            check_blank(argv[optind - 1], optarg);
            set_devno(optarg);
            break;
        case 'l':
            check_blank(argv[optind - 1], optarg);
            set_lun(optarg);
            break;
        case 'w':
            check_blank(argv[optind - 1], optarg);
            set_wwpn(optarg);
            break;
        case 'L':
            check_blank(argv[optind - 1], optarg);
            set_loadparm(optarg);
            break;
        case 'b':
            check_blank(argv[optind - 1], optarg);
            set_bootprog(optarg);
            break;
        case 'v':
            print_version();
            break;
        case '?':
            printf("Try '%s' --help' for more information.\n",
                   name);
            exit(1);
            break;
        case -1:
            /*
             * we also run in this case if no argument was specified
             */
            break;
        default:
            print_usage_ripl(argv[0]);
        }
    }
    if (!action) {
        fprintf(stderr, "%s: No valid action specified\n", name);
        exit(1);
    }
    /*
     * optind is a index which points to the first unrecognised
     * command line argument
     */
    if (argc - optind > 1)
        parse_args(&argv[optind + 1], argc - optind - 1);

    /*
     * Check for valid option combinations
     */
    switch (action) {
    case ACT_FCP:
        check_fcp_opts();
        break;
    case ACT_CCW:
        check_ccw_opts();
        break;
    case ACT_NODE:
        check_node_opts();
        break;
    }
}