static void parse_global_config(const char *configfile, const char *configfile_data, int configfile_len) { long l; XLU_Config *config; int e; const char *buf; config = xlu_cfg_init(stderr, configfile); if (!config) { fprintf(stderr, "Failed to allocate for configuration\n"); exit(1); } e = xlu_cfg_readdata(config, configfile_data, configfile_len); if (e) { fprintf(stderr, "Failed to parse config file: %s\n", strerror(e)); exit(1); } if (!xlu_cfg_get_long (config, "autoballoon", &l, 0)) autoballoon = l; if (!xlu_cfg_get_long (config, "run_hotplug_scripts", &l, 0)) run_hotplug_scripts = l; if (!xlu_cfg_get_string (config, "lockfile", &buf, 0)) lockfile = strdup(buf); else { lockfile = strdup(XL_LOCK_FILE); } if (!lockfile < 0) { fprintf(stderr, "failed to allocate lockdir \n"); exit(1); } if (!xlu_cfg_get_string (config, "vifscript", &buf, 0)) default_vifscript = strdup(buf); if (!xlu_cfg_get_string (config, "defaultbridge", &buf, 0)) default_bridge = strdup(buf); if (!xlu_cfg_get_string (config, "output_format", &buf, 0)) { if (!strcmp(buf, "json")) default_output_format = OUTPUT_FORMAT_JSON; else if (!strcmp(buf, "sxp")) default_output_format = OUTPUT_FORMAT_SXP; else { fprintf(stderr, "invalid default output format \"%s\"\n", buf); } } if (!xlu_cfg_get_string (config, "blkdev_start", &buf, 0)) blkdev_start = strdup(buf); xlu_cfg_destroy(config); }
static void parse_global_config(const char *configfile, const char *configfile_data, int configfile_len) { long l; XLU_Config *config; int e; const char *buf; config = xlu_cfg_init(stderr, configfile); if (!config) { fprintf(stderr, "Failed to allocate for configuration\n"); exit(1); } e = xlu_cfg_readdata(config, configfile_data, configfile_len); if (e) { fprintf(stderr, "Failed to parse config file: %s\n", strerror(e)); exit(1); } if (!xlu_cfg_get_string(config, "autoballoon", &buf, 0)) { if (!strcmp(buf, "on") || !strcmp(buf, "1")) autoballoon = 1; else if (!strcmp(buf, "off") || !strcmp(buf, "0")) autoballoon = 0; else if (!strcmp(buf, "auto")) autoballoon = -1; else fprintf(stderr, "invalid autoballoon option"); } if (autoballoon == -1) autoballoon = auto_autoballoon(); if (!xlu_cfg_get_long (config, "run_hotplug_scripts", &l, 0)) run_hotplug_scripts = l; if (!xlu_cfg_get_string (config, "lockfile", &buf, 0)) lockfile = strdup(buf); else { lockfile = strdup(XL_LOCK_FILE); } if (!lockfile) { fprintf(stderr, "failed to allocate lockfile\n"); exit(1); } /* * For global options that are related to a specific type of device * we use the following nomenclature: * * <device type>.default.<option name> * * This allows us to keep the default options classified for the * different device kinds. */ if (!xlu_cfg_get_string (config, "vifscript", &buf, 0)) { fprintf(stderr, "the global config option vifscript is deprecated, " "please switch to vif.default.script\n"); free(default_vifscript); default_vifscript = strdup(buf); } if (!xlu_cfg_get_string (config, "vif.default.script", &buf, 0)) { free(default_vifscript); default_vifscript = strdup(buf); } if (!xlu_cfg_get_string (config, "defaultbridge", &buf, 0)) { fprintf(stderr, "the global config option defaultbridge is deprecated, " "please switch to vif.default.bridge\n"); free(default_bridge); default_bridge = strdup(buf); } if (!xlu_cfg_get_string (config, "vif.default.bridge", &buf, 0)) { free(default_bridge); default_bridge = strdup(buf); } if (!xlu_cfg_get_string (config, "vif.default.gatewaydev", &buf, 0)) default_gatewaydev = strdup(buf); if (!xlu_cfg_get_string (config, "vif.default.backend", &buf, 0)) default_vifbackend = strdup(buf); if (!xlu_cfg_get_string (config, "output_format", &buf, 0)) { if (!strcmp(buf, "json")) default_output_format = OUTPUT_FORMAT_JSON; else if (!strcmp(buf, "sxp")) default_output_format = OUTPUT_FORMAT_SXP; else { fprintf(stderr, "invalid default output format \"%s\"\n", buf); } } if (!xlu_cfg_get_string (config, "blkdev_start", &buf, 0)) blkdev_start = strdup(buf); if (!xlu_cfg_get_long (config, "claim_mode", &l, 0)) claim_mode = l; xlu_cfg_replace_string (config, "remus.default.netbufscript", &default_remus_netbufscript, 0); xlu_cfg_destroy(config); }
/* * For details on xl disk config syntax, see * docs/misc/xl-disk-configuration.txt in the Xen sources. The important * section of text is: * * More formally, the string is a series of comma-separated keyword/value * pairs, flags and positional parameters. Parameters which are not bare * keywords and which do not contain "=" symbols are assigned to the * so-far-unspecified positional parameters, in the order below. The * positional parameters may also be specified explicitly by name. * * Each parameter may be specified at most once, either as a positional * parameter or a named parameter. Default values apply if the parameter * is not specified, or if it is specified with an empty value (whether * positionally or explicitly). * * Whitespace may appear before each parameter and will be ignored. * * The order of the positional parameters mentioned in the quoted text is: * * target,format,vdev,access * * The following options must be specified by key=value: * * devtype=<devtype> * backendtype=<backend-type> * * The following options are currently not supported: * * backend=<domain-name> * script=<script> * direct-io-safe * */ static int xenParseXLDisk(virConfPtr conf, virDomainDefPtr def) { int ret = -1; virConfValuePtr list = virConfGetValue(conf, "disk"); XLU_Config *xluconf; libxl_device_disk *libxldisk; virDomainDiskDefPtr disk = NULL; if (VIR_ALLOC(libxldisk) < 0) return -1; if (!(xluconf = xlu_cfg_init(stderr, "command line"))) goto cleanup; if (list && list->type == VIR_CONF_LIST) { list = list->list; while (list) { const char *disk_spec = list->str; if (list->type != VIR_CONF_STRING || list->str == NULL) goto skipdisk; libxl_device_disk_init(libxldisk); if (xlu_disk_parse(xluconf, 1, &disk_spec, libxldisk)) goto fail; if (!(disk = virDomainDiskDefNew(NULL))) goto fail; if (xenParseXLDiskSrc(disk, libxldisk->pdev_path) < 0) goto fail; if (VIR_STRDUP(disk->dst, libxldisk->vdev) < 0) goto fail; disk->src->readonly = !libxldisk->readwrite; disk->removable = libxldisk->removable; if (libxldisk->is_cdrom) { if (virDomainDiskSetDriver(disk, "qemu") < 0) goto fail; virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; if (!disk->src->path || STREQ(disk->src->path, "")) disk->src->format = VIR_STORAGE_FILE_NONE; else disk->src->format = VIR_STORAGE_FILE_RAW; } else { switch (libxldisk->format) { case LIBXL_DISK_FORMAT_QCOW: disk->src->format = VIR_STORAGE_FILE_QCOW; break; case LIBXL_DISK_FORMAT_QCOW2: disk->src->format = VIR_STORAGE_FILE_QCOW2; break; case LIBXL_DISK_FORMAT_VHD: disk->src->format = VIR_STORAGE_FILE_VHD; break; case LIBXL_DISK_FORMAT_RAW: case LIBXL_DISK_FORMAT_UNKNOWN: disk->src->format = VIR_STORAGE_FILE_RAW; break; case LIBXL_DISK_FORMAT_EMPTY: break; } switch (libxldisk->backend) { case LIBXL_DISK_BACKEND_QDISK: case LIBXL_DISK_BACKEND_UNKNOWN: if (virDomainDiskSetDriver(disk, "qemu") < 0) goto fail; if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_NONE) virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); break; case LIBXL_DISK_BACKEND_TAP: if (virDomainDiskSetDriver(disk, "tap") < 0) goto fail; virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); break; case LIBXL_DISK_BACKEND_PHY: if (virDomainDiskSetDriver(disk, "phy") < 0) goto fail; virDomainDiskSetType(disk, VIR_STORAGE_TYPE_BLOCK); break; } } if (STRPREFIX(libxldisk->vdev, "xvd") || def->os.type != VIR_DOMAIN_OSTYPE_HVM) disk->bus = VIR_DOMAIN_DISK_BUS_XEN; else if (STRPREFIX(libxldisk->vdev, "sd")) disk->bus = VIR_DOMAIN_DISK_BUS_SCSI; else disk->bus = VIR_DOMAIN_DISK_BUS_IDE; if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0) goto fail; libxl_device_disk_dispose(libxldisk); skipdisk: list = list->next; } } ret = 0; cleanup: virDomainDiskDefFree(disk); xlu_cfg_destroy(xluconf); VIR_FREE(libxldisk); return ret; fail: libxl_device_disk_dispose(libxldisk); goto cleanup; }