/*
* vmx.c: VMware VMX parsing/formatting functions
*
- * Copyright (C) 2010-2013 Red Hat, Inc.
+ * Copyright (C) 2010-2014 Red Hat, Inc.
* Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte@googlemail.com>
*
* This library is free software; you can redistribute it and/or
int model;
size_t i;
virDomainControllerDefPtr controller = NULL;
+ const char *driver = virDomainDiskGetDriver(disk);
+ char *copy;
- if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI || disk->driverName == NULL) {
+ if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI || !driver) {
return 0;
}
- tmp = disk->driverName;
+ if (VIR_STRDUP(copy, driver) < 0)
+ return -1;
+ tmp = copy;
for (; *tmp != '\0'; ++tmp) {
*tmp = c_tolower(*tmp);
}
- model = virDomainControllerModelSCSITypeFromString(disk->driverName);
+ model = virDomainControllerModelSCSITypeFromString(copy);
+ VIR_FREE(copy);
if (model < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unknown driver name '%s'"), disk->driverName);
+ _("Unknown driver name '%s'"), driver);
return -1;
}
} else if (controller->model != model) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Inconsistent SCSI controller model ('%s' is not '%s') "
- "for SCSI controller index %d"), disk->driverName,
+ "for SCSI controller index %d"), driver,
virDomainControllerModelSCSITypeToString(controller->model),
controller->idx);
return -1;
/* Setup virDomainDiskDef */
if (device == VIR_DOMAIN_DISK_DEVICE_DISK) {
if (virFileHasSuffix(fileName, ".vmdk")) {
+ char *tmp;
+
if (deviceType != NULL) {
if (busType == VIR_DOMAIN_DISK_BUS_SCSI &&
STRCASENEQ(deviceType, "scsi-hardDisk") &&
}
}
- (*def)->type = VIR_DOMAIN_DISK_TYPE_FILE;
- (*def)->src = ctx->parseFileName(fileName, ctx->opaque);
+ virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_FILE);
+ if (!(tmp = ctx->parseFileName(fileName, ctx->opaque)))
+ goto cleanup;
+ if (virDomainDiskSetSource(*def, tmp) < 0) {
+ VIR_FREE(tmp);
+ goto cleanup;
+ }
+ VIR_FREE(tmp);
(*def)->cachemode = writeThrough ? VIR_DOMAIN_DISK_CACHE_WRITETHRU
: VIR_DOMAIN_DISK_CACHE_DEFAULT;
if (mode)
(*def)->transient = STRCASEEQ(mode,
"independent-nonpersistent");
-
- if ((*def)->src == NULL) {
- goto cleanup;
- }
} else if (virFileHasSuffix(fileName, ".iso") ||
STRCASEEQ(deviceType, "atapi-cdrom") ||
STRCASEEQ(deviceType, "cdrom-raw")) {
}
} else if (device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
if (virFileHasSuffix(fileName, ".iso")) {
+ char *tmp;
+
if (deviceType != NULL) {
if (STRCASENEQ(deviceType, "cdrom-image")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
}
}
- (*def)->type = VIR_DOMAIN_DISK_TYPE_FILE;
- (*def)->src = ctx->parseFileName(fileName, ctx->opaque);
-
- if ((*def)->src == NULL) {
+ virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_FILE);
+ if (!(tmp = ctx->parseFileName(fileName, ctx->opaque)))
+ goto cleanup;
+ if (virDomainDiskSetSource(*def, tmp) < 0) {
+ VIR_FREE(tmp);
goto cleanup;
}
+ VIR_FREE(tmp);
} else if (virFileHasSuffix(fileName, ".vmdk")) {
/*
* This function was called in order to parse a CDROM device, but
*/
goto ignore;
} else if (STRCASEEQ(deviceType, "atapi-cdrom")) {
- (*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
+ virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_BLOCK);
if (STRCASEEQ(fileName, "auto detect")) {
- (*def)->src = NULL;
+ ignore_value(virDomainDiskSetSource(*def, NULL));
(*def)->startupPolicy = VIR_DOMAIN_STARTUP_POLICY_OPTIONAL;
- } else {
- (*def)->src = fileName;
- fileName = NULL;
+ } else if (virDomainDiskSetSource(*def, fileName) < 0) {
+ goto cleanup;
}
} else if (STRCASEEQ(deviceType, "cdrom-raw")) {
/* Raw access CD-ROMs actually are device='lun' */
(*def)->device = VIR_DOMAIN_DISK_DEVICE_LUN;
- (*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
+ virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_BLOCK);
if (STRCASEEQ(fileName, "auto detect")) {
- (*def)->src = NULL;
+ ignore_value(virDomainDiskSetSource(*def, NULL));
(*def)->startupPolicy = VIR_DOMAIN_STARTUP_POLICY_OPTIONAL;
- } else {
- (*def)->src = fileName;
- fileName = NULL;
+ } else if (virDomainDiskSetSource(*def, fileName) < 0) {
+ goto cleanup;
}
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
}
} else if (device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
if (fileType != NULL && STRCASEEQ(fileType, "device")) {
- (*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
- (*def)->src = fileName;
-
- fileName = NULL;
+ virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_BLOCK);
+ if (virDomainDiskSetSource(*def, fileName) < 0)
+ goto cleanup;
} else if (fileType != NULL && STRCASEEQ(fileType, "file")) {
- (*def)->type = VIR_DOMAIN_DISK_TYPE_FILE;
- (*def)->src = ctx->parseFileName(fileName, ctx->opaque);
+ char *tmp;
+
+ virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_FILE);
+ if (!(tmp = ctx->parseFileName(fileName, ctx->opaque)))
+ goto cleanup;
+ if (virDomainDiskSetSource(*def, tmp) < 0) {
+ VIR_FREE(tmp);
+ goto cleanup;
+ }
+ VIR_FREE(tmp);
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid or not yet handled value '%s' "
if (virDomainDiskDefAssignAddress(xmlopt, *def) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Could not assign address to disk '%s'"), (*def)->src);
+ _("Could not assign address to disk '%s'"),
+ virDomainDiskGetSource(*def));
goto cleanup;
}
int controllerOrBus, unit;
const char *vmxDeviceType = NULL;
char *fileName = NULL;
+ int type = virDomainDiskGetType(def);
/* Convert a handful of types to their string values */
const char *busType = virDomainDiskBusTypeToString(def->bus);
const char *deviceType = virDomainDeviceTypeToString(def->device);
- const char *diskType = virDomainDeviceTypeToString(def->type);
+ const char *diskType = virDomainDeviceTypeToString(type);
/* If we are dealing with a disk its a .vmdk, otherwise it must be
* an ISO.
}
/* We only support type='file' and type='block' */
- if (def->type != VIR_DOMAIN_DISK_TYPE_FILE &&
- def->type != VIR_DOMAIN_DISK_TYPE_BLOCK) {
+ if (type != VIR_DOMAIN_DISK_TYPE_FILE &&
+ type != VIR_DOMAIN_DISK_TYPE_BLOCK) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("%s %s '%s' has unsupported type '%s', expecting "
"'%s' or '%s'"), busType, deviceType, def->dst,
}
if (def->device == VIR_DOMAIN_DISK_DEVICE_DISK &&
- def->type == VIR_DOMAIN_DISK_TYPE_FILE) {
+ type == VIR_DOMAIN_DISK_TYPE_FILE) {
vmxDeviceType = (def->bus == VIR_DOMAIN_DISK_BUS_SCSI) ?
"scsi-hardDisk" : "ata-hardDisk";
} else if (def->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
- if (def->type == VIR_DOMAIN_DISK_TYPE_FILE)
+ if (type == VIR_DOMAIN_DISK_TYPE_FILE)
vmxDeviceType = "cdrom-image";
else
vmxDeviceType = "atapi-cdrom";
virBufferAsprintf(buffer, "%s%d:%d.deviceType = \"%s\"\n",
busType, controllerOrBus, unit, vmxDeviceType);
- if (def->type == VIR_DOMAIN_DISK_TYPE_FILE) {
- if (def->src != NULL && ! virFileHasSuffix(def->src, fileExt)) {
+ if (type == VIR_DOMAIN_DISK_TYPE_FILE) {
+ const char *src = virDomainDiskGetSource(def);
+
+ if (src && ! virFileHasSuffix(src, fileExt)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Image file for %s %s '%s' has "
"unsupported suffix, expecting '%s'"),
return -1;
}
- fileName = ctx->formatFileName(def->src, ctx->opaque);
+ fileName = ctx->formatFileName(src, ctx->opaque);
if (fileName == NULL) {
return -1;
busType, controllerOrBus, unit, fileName);
VIR_FREE(fileName);
- } else if (def->type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
- if (!def->src &&
+ } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
+ const char *src = virDomainDiskGetSource(def);
+
+ if (!src &&
def->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_OPTIONAL) {
virBufferAsprintf(buffer, "%s%d:%d.autodetect = \"true\"\n",
busType, controllerOrBus, unit);
busType, controllerOrBus, unit);
} else {
virBufferAsprintf(buffer, "%s%d:%d.fileName = \"%s\"\n",
- busType, controllerOrBus, unit, def->src);
+ busType, controllerOrBus, unit, src);
}
}
{
int unit;
char *fileName = NULL;
+ int type = virDomainDiskGetType(def);
+ const char *src = virDomainDiskGetSource(def);
if (def->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
virBufferAsprintf(buffer, "floppy%d.present = \"true\"\n", unit);
- if (def->type == VIR_DOMAIN_DISK_TYPE_FILE) {
+ if (type == VIR_DOMAIN_DISK_TYPE_FILE) {
virBufferAsprintf(buffer, "floppy%d.fileType = \"file\"\n", unit);
- if (def->src != NULL) {
- fileName = ctx->formatFileName(def->src, ctx->opaque);
+ if (src) {
+ fileName = ctx->formatFileName(src, ctx->opaque);
if (fileName == NULL) {
return -1;
VIR_FREE(fileName);
}
- } else if (def->type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
+ } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
virBufferAsprintf(buffer, "floppy%d.fileType = \"device\"\n", unit);
- if (def->src != NULL) {
+ if (src) {
virBufferAsprintf(buffer, "floppy%d.fileName = \"%s\"\n",
- unit, def->src);
+ unit, src);
}
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Floppy '%s' has unsupported type '%s', expecting '%s' "
"or '%s'"), def->dst,
- virDomainDiskTypeToString(def->type),
+ virDomainDiskTypeToString(type),
virDomainDiskTypeToString(VIR_DOMAIN_DISK_TYPE_FILE),
virDomainDiskTypeToString(VIR_DOMAIN_DISK_TYPE_BLOCK));
return -1;