Ejemplo n.º 1
0
int
_getopt_long_only_r (int argc, char *const *argv, const char *options,
		     const struct option *long_options, int *opt_index,
		     struct _getopt_data *d)
{
  return _getopt_internal_r (argc, argv, options, long_options, opt_index,
			     1, d);
}
Ejemplo n.º 2
0
/*
 * Parse the /usr/sbin/bhyveload command line.
 */
static int
bhyveParseBhyveLoadCommandLine(virDomainDefPtr def,
                               int argc, char **argv)
{
    int c;
    /* bhyveload called with default arguments when only -m and -d are given.
     * Store this in a bit field and check if only those two options are given
     * later */
    unsigned arguments = 0;
    size_t memory = 0;
    struct _getopt_data *parser;
    size_t i = 0;
    int ret = -1;

    const char optstr[] = "CSc:d:e:h:l:m:";

    if (!argv)
        goto error;

    if (VIR_ALLOC(parser) < 0)
        goto error;

    while ((c = _getopt_internal_r(argc, argv, optstr,
            NULL, NULL, 0, parser, 0)) != -1) {
        switch (c) {
        case 'd':
            arguments |= 1;
            /* Iterate over the disks of the domain trying to match up the
             * source */
            for (i = 0; i < def->ndisks; i++) {
                if (STREQ(virDomainDiskGetSource(def->disks[i]),
                          parser->optarg)) {
                    def->disks[i]->info.bootIndex = i;
                    break;
                }
            }
            break;
        case 'm':
            arguments |= 2;
            if (bhyveParseMemsize(parser->optarg, &memory)) {
                virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                               _("Failed to parse memory"));
                goto error;
            }
            if (def->mem.cur_balloon != 0 && def->mem.cur_balloon != memory) {
                virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                               _("Failed to parse memory: size mismatch"));
                goto error;
            }
            def->mem.cur_balloon = memory;
            virDomainDefSetMemoryTotal(def, memory);
            break;
        default:
            arguments |= 4;
        }
    }

    if (arguments != 3) {
        /* Set os.bootloader since virDomainDefFormatInternal will only format
         * the bootloader arguments if os->bootloader is set. */
        if (VIR_STRDUP(def->os.bootloader, argv[0]) < 0)
           goto error;

        def->os.bootloaderArgs = virStringJoin((const char**) &argv[1], " ");
    }

    if (argc != parser->optind) {
        virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                       _("Failed to parse arguments for bhyveload command"));
        goto error;
    }

    if (def->name == NULL) {
        if (VIR_STRDUP(def->name, argv[argc]) < 0)
            goto error;
    } else if (STRNEQ(def->name, argv[argc])) {
        /* the vm name of the loader and the bhyverun command differ, throw an
         * error here */
        virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                       _("Failed to parse arguments: VM name mismatch"));
        goto error;
    }

    ret = 0;
 error:
    VIR_FREE(parser);
    return ret;
}
Ejemplo n.º 3
0
/*
 * Parse the /usr/sbin/bhyve command line.
 */
static int
bhyveParseBhyveCommandLine(virDomainDefPtr def,
                           virDomainXMLOptionPtr xmlopt,
                           unsigned caps,
                           int argc, char **argv)
{
    int c;
    const char optstr[] = "abehuwxACHIPSWYp:g:c:s:m:l:U:";
    int vcpus = 1;
    size_t memory = 0;
    unsigned nahcidisks = 0;
    unsigned nvirtiodisks = 0;
    struct _getopt_data *parser;

    if (!argv)
        goto error;

    if (VIR_ALLOC(parser) < 0)
        goto error;

    while ((c = _getopt_internal_r(argc, argv, optstr,
            NULL, NULL, 0, parser, 0)) != -1) {
        switch (c) {
        case 'A':
            def->features[VIR_DOMAIN_FEATURE_ACPI] = VIR_TRISTATE_SWITCH_ON;
            break;
        case 'c':
            if (virStrToLong_i(parser->optarg, NULL, 10, &vcpus) < 0) {
                virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                               _("Failed to parse number of vCPUs"));
                goto error;
            }
            if (virDomainDefSetVcpusMax(def, vcpus, xmlopt) < 0)
                goto error;
            if (virDomainDefSetVcpus(def, vcpus) < 0)
                goto error;
            break;
        case 'l':
            if (bhyveParseBhyveLPCArg(def, caps, parser->optarg))
                goto error;
            break;
        case 's':
            if (bhyveParseBhyvePCIArg(def,
                                      xmlopt,
                                      caps,
                                      &nahcidisks,
                                      &nvirtiodisks,
                                      parser->optarg))
                goto error;
            break;
        case 'm':
            if (bhyveParseMemsize(parser->optarg, &memory)) {
                virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                               _("Failed to parse memory"));
                goto error;
            }
            if (def->mem.cur_balloon != 0 && def->mem.cur_balloon != memory) {
                virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                           _("Failed to parse memory: size mismatch"));
                goto error;
            }
            def->mem.cur_balloon = memory;
            virDomainDefSetMemoryTotal(def, memory);
            break;
        case 'I':
            /* While this flag was deprecated in FreeBSD r257423, keep checking
             * for it for backwards compatibility. */
            def->features[VIR_DOMAIN_FEATURE_APIC] = VIR_TRISTATE_SWITCH_ON;
            break;
        case 'u':
            def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
            break;
        case 'U':
            if (virUUIDParse(parser->optarg, def->uuid) < 0) {
                virReportError(VIR_ERR_INTERNAL_ERROR,
                               _("Cannot parse UUID '%s'"), parser->optarg);
                goto error;
            }
            break;
        }
    }

    if (argc != parser->optind) {
        virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                       _("Failed to parse arguments for bhyve command"));
        goto error;
    }

    if (def->name == NULL) {
        if (VIR_STRDUP(def->name, argv[argc]) < 0)
            goto error;
    } else if (STRNEQ(def->name, argv[argc])) {
        /* the vm name of the loader and the bhyverun command differ, throw an
         * error here */
        virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                       _("Failed to parse arguments: VM name mismatch"));
        goto error;
    }

    VIR_FREE(parser);
    return 0;

 error:
    VIR_FREE(parser);
    return -1;
}