/* Calculate length of escaped string */
while (*tmp1 != '\0') {
- if (*tmp1 == escape || strspn(tmp1, special) > 0) {
+ if (*tmp1 == escape || strspn(tmp1, special) > 0)
length += 2;
- }
++tmp1;
++length;
/* Unescape from 'cXX' where c is the escape char and X is a hex digit */
while (*tmp1 != '\0') {
if (*tmp1 == escape) {
- if (!c_isxdigit(tmp1[1]) || !c_isxdigit(tmp1[2])) {
+ if (!c_isxdigit(tmp1[1]) || !c_isxdigit(tmp1[2]))
return -1;
- }
*tmp2++ = virHexToBin(tmp1[1]) * 16 + virHexToBin(tmp1[2]);
tmp1 += 3;
value = virConfGetValue(conf, name);
if (value == NULL) {
- if (optional) {
+ if (optional)
return 0;
- }
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Missing essential config entry '%s'"), name);
}
if (value->str == NULL) {
- if (optional) {
+ if (optional)
return 0;
- }
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Missing essential config entry '%s'"), name);
*unit = idx % 15;
/* Skip the controller ifself at unit 7 */
- if (*unit >= 7) {
+ if (*unit >= 7)
++(*unit);
- }
return 0;
}
const char *driver = virDomainDiskGetDriver(disk);
char *copy;
- if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI || !driver) {
+ if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI || !driver)
return 0;
- }
if (VIR_STRDUP(copy, driver) < 0)
return -1;
tmp = copy;
- for (; *tmp != '\0'; ++tmp) {
+ for (; *tmp != '\0'; ++tmp)
*tmp = c_tolower(*tmp);
- }
model = virDomainControllerModelSCSITypeFromString(copy);
VIR_FREE(copy);
conf = virConfReadMem(vmx, strlen(vmx), VIR_CONF_FLAG_VMX_FORMAT);
- if (conf == NULL) {
+ if (conf == NULL)
return NULL;
- }
/* vmx:.encoding */
- if (virVMXGetConfigString(conf, ".encoding", &encoding, true) < 0) {
+ if (virVMXGetConfigString(conf, ".encoding", &encoding, true) < 0)
goto cleanup;
- }
if (encoding == NULL || STRCASEEQ(encoding, "UTF-8")) {
/* nothing */
utf8 = virVMXConvertToUTF8(encoding, vmx);
- if (utf8 == NULL) {
+ if (utf8 == NULL)
goto cleanup;
- }
conf = virConfReadMem(utf8, strlen(utf8), VIR_CONF_FLAG_VMX_FORMAT);
VIR_FREE(utf8);
- if (conf == NULL) {
+ if (conf == NULL)
goto cleanup;
- }
}
/* Allocate domain def */
/* vmx:uuid.bios -> def:uuid */
/* FIXME: Need to handle 'uuid.action = "create"' */
- if (virVMXGetConfigUUID(conf, "uuid.bios", def->uuid, true) < 0) {
+ if (virVMXGetConfigUUID(conf, "uuid.bios", def->uuid, true) < 0)
goto cleanup;
- }
/* vmx:displayName -> def:name */
- if (virVMXGetConfigString(conf, "displayName", &def->name, true) < 0) {
+ if (virVMXGetConfigString(conf, "displayName", &def->name, true) < 0)
goto cleanup;
- }
if (def->name != NULL) {
if (virVMXUnescapeHexPercent(def->name) < 0 ||
}
/* vmx:memsize -> def:mem.max_balloon */
- if (virVMXGetConfigLong(conf, "memsize", &memsize, 32, true) < 0) {
+ if (virVMXGetConfigLong(conf, "memsize", &memsize, 32, true) < 0)
goto cleanup;
- }
if (memsize <= 0 || memsize % 4 != 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
goto cleanup;
}
- if (sched_mem_max < 0) {
+ if (sched_mem_max < 0)
sched_mem_max = memsize;
- }
def->mem.cur_balloon = sched_mem_max * 1024; /* Scale from megabytes to kilobytes */
- if (def->mem.cur_balloon > def->mem.max_balloon) {
+ if (def->mem.cur_balloon > def->mem.max_balloon)
def->mem.cur_balloon = def->mem.max_balloon;
- }
/* vmx:sched.mem.minsize -> def:mem.min_guarantee */
if (virVMXGetConfigLong(conf, "sched.mem.minsize", &sched_mem_minsize, 0,
goto cleanup;
}
- if (sched_mem_minsize < 0) {
+ if (sched_mem_minsize < 0)
sched_mem_minsize = 0;
- }
def->mem.min_guarantee = sched_mem_minsize * 1024; /* Scale from megabytes to kilobytes */
- if (def->mem.min_guarantee > def->mem.max_balloon) {
+ if (def->mem.min_guarantee > def->mem.max_balloon)
def->mem.min_guarantee = def->mem.max_balloon;
- }
/* vmx:numvcpus -> def:vcpus */
- if (virVMXGetConfigLong(conf, "numvcpus", &numvcpus, 1, true) < 0) {
+ if (virVMXGetConfigLong(conf, "numvcpus", &numvcpus, 1, true) < 0)
goto cleanup;
- }
if (numvcpus <= 0 || (numvcpus % 2 != 0 && numvcpus != 1)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
goto cleanup;
}
- if (number + 1 > cpumasklen) {
+ if (number + 1 > cpumasklen)
cpumasklen = number + 1;
- }
ignore_value(virBitmapSetBit(def->cpumask, number));
++count;
goto cleanup;
/* vmx:guestOS -> def:os.arch */
- if (virVMXGetConfigString(conf, "guestOS", &guestOS, true) < 0) {
+ if (virVMXGetConfigString(conf, "guestOS", &guestOS, true) < 0)
goto cleanup;
- }
if (guestOS != NULL && virFileHasSuffix(guestOS, "-64")) {
def->os.arch = VIR_ARCH_X86_64;
goto cleanup;
}
- if (smbios_reflecthost) {
+ if (smbios_reflecthost)
def->os.smbios_mode = VIR_DOMAIN_SMBIOS_HOST;
- }
/* def:features */
/* FIXME */
def->ngraphics = 0;
- if (virVMXParseVNC(conf, &def->graphics[def->ngraphics]) < 0) {
+ if (virVMXParseVNC(conf, &def->graphics[def->ngraphics]) < 0)
goto cleanup;
- }
- if (def->graphics[def->ngraphics] != NULL) {
+ if (def->graphics[def->ngraphics] != NULL)
++def->ngraphics;
- }
/* def:disks: 4 * 15 scsi + 2 * 2 ide + 2 floppy = 66 */
if (VIR_ALLOC_N(def->disks, 66) < 0)
goto cleanup;
}
- if (! present) {
+ if (! present)
continue;
- }
for (unit = 0; unit < 16; ++unit) {
if (unit == 7) {
goto cleanup;
}
- if (def->disks[def->ndisks] != NULL) {
+ if (def->disks[def->ndisks] != NULL)
++def->ndisks;
- }
}
}
goto cleanup;
}
- if (def->disks[def->ndisks] != NULL) {
+ if (def->disks[def->ndisks] != NULL)
++def->ndisks;
- }
}
}
goto cleanup;
}
- if (def->disks[def->ndisks] != NULL) {
+ if (def->disks[def->ndisks] != NULL)
++def->ndisks;
- }
}
/* def:controllers */
goto cleanup;
}
- if (def->fss[def->nfss] != NULL) {
+ if (def->fss[def->nfss] != NULL)
++def->nfss;
- }
}
}
}
goto cleanup;
}
- if (def->nets[def->nnets] != NULL) {
+ if (def->nets[def->nnets] != NULL)
++def->nnets;
- }
}
/* def:inputs */
def->nvideos = 0;
- if (virVMXParseSVGA(conf, &def->videos[def->nvideos]) < 0) {
+ if (virVMXParseSVGA(conf, &def->videos[def->nvideos]) < 0)
goto cleanup;
- }
def->nvideos = 1;
goto cleanup;
}
- if (def->serials[def->nserials] != NULL) {
+ if (def->serials[def->nserials] != NULL)
++def->nserials;
- }
}
/* def:parallels */
goto cleanup;
}
- if (def->parallels[def->nparallels] != NULL) {
+ if (def->parallels[def->nparallels] != NULL)
++def->nparallels;
- }
}
success = true;
return -1;
}
- if (! enabled) {
+ if (! enabled)
return 0;
- }
if (VIR_ALLOC(*def) < 0)
goto failure;
(*def)->data.vnc.port = 0;
(*def)->data.vnc.autoport = true;
} else {
- if (port < 5900 || port > 5964) {
+ if (port < 5900 || port > 5964)
VIR_WARN("VNC port %lld it out of [5900..5964] range", port);
- }
(*def)->data.vnc.port = port;
(*def)->data.vnc.autoport = false;
snprintf(virtualDev_name, sizeof(virtualDev_name), "scsi%d.virtualDev",
controller);
- if (virVMXGetConfigBoolean(conf, present_name, present, false, true) < 0) {
+ if (virVMXGetConfigBoolean(conf, present_name, present, false, true) < 0)
goto cleanup;
- }
if (! *present) {
result = 0;
if (virtualDev_string != NULL) {
tmp = virtualDev_string;
- for (; *tmp != '\0'; ++tmp) {
+ for (; *tmp != '\0'; ++tmp)
*tmp = c_tolower(*tmp);
- }
*virtualDev = virVMXControllerModelSCSITypeFromString(virtualDev_string);
virIndexToDiskName
(controllerOrBus * 15 + (unit < 7 ? unit : unit - 1), "sd");
- if ((*def)->dst == NULL) {
+ if ((*def)->dst == NULL)
goto cleanup;
- }
} else if (busType == VIR_DOMAIN_DISK_BUS_IDE) {
if (controllerOrBus < 0 || controllerOrBus > 1) {
virReportError(VIR_ERR_INTERNAL_ERROR,
(*def)->dst = virIndexToDiskName(controllerOrBus * 2 + unit, "hd");
- if ((*def)->dst == NULL) {
+ if ((*def)->dst == NULL)
goto cleanup;
- }
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported bus type '%s' for device type '%s'"),
(*def)->dst = virIndexToDiskName(unit, "fd");
- if ((*def)->dst == NULL) {
+ if ((*def)->dst == NULL)
goto cleanup;
- }
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported bus type '%s' for device type '%s'"),
VMX_BUILD_NAME(mode);
/* vmx:present */
- if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) {
+ if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0)
goto cleanup;
- }
/* vmx:startConnected */
if (virVMXGetConfigBoolean(conf, startConnected_name, &startConnected,
}
/* FIXME: Need to distiguish between active and inactive domains here */
- if (! present/* && ! startConnected*/) {
+ if (! present/* && ! startConnected*/)
goto ignore;
- }
/* vmx:deviceType -> def:type */
- if (virVMXGetConfigString(conf, deviceType_name, &deviceType, true) < 0) {
+ if (virVMXGetConfigString(conf, deviceType_name, &deviceType, true) < 0)
goto cleanup;
- }
/* vmx:clientDevice */
if (virVMXGetConfigBoolean(conf, clientDevice_name, &clientDevice, false,
}
/* vmx:mode -> def:transient */
- if (virVMXGetConfigString(conf, mode_name, &mode, true) < 0) {
+ if (virVMXGetConfigString(conf, mode_name, &mode, true) < 0)
goto cleanup;
- }
if (clientDevice) {
/*
}
/* vmx:fileType -> def:type */
- if (virVMXGetConfigString(conf, fileType_name, &fileType, true) < 0) {
+ if (virVMXGetConfigString(conf, fileType_name, &fileType, true) < 0)
goto cleanup;
- }
/* vmx:fileName -> def:src, def:type */
- if (virVMXGetConfigString(conf, fileName_name, &fileName, false) < 0) {
+ if (virVMXGetConfigString(conf, fileName_name, &fileName, false) < 0)
goto cleanup;
- }
/* vmx:writeThrough -> def:cachemode */
if (virVMXGetConfigBoolean(conf, writeThrough_name, &writeThrough, false,
VMX_BUILD_NAME(writeAccess);
/* vmx:present */
- if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) {
+ if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0)
goto cleanup;
- }
/* vmx:enabled */
- if (virVMXGetConfigBoolean(conf, enabled_name, &enabled, false, true) < 0) {
+ if (virVMXGetConfigBoolean(conf, enabled_name, &enabled, false, true) < 0)
goto cleanup;
- }
- if (!(present && enabled)) {
+ if (!(present && enabled))
goto ignore;
- }
/* vmx:hostPath */
- if (virVMXGetConfigString(conf, hostPath_name, &hostPath, false) < 0) {
+ if (virVMXGetConfigString(conf, hostPath_name, &hostPath, false) < 0)
goto cleanup;
- }
(*def)->src = hostPath;
hostPath = NULL;
/* vmx:guestName */
- if (virVMXGetConfigString(conf, guestName_name, &guestName, false) < 0) {
+ if (virVMXGetConfigString(conf, guestName_name, &guestName, false) < 0)
goto cleanup;
- }
(*def)->dst = guestName;
guestName = NULL;
VMX_BUILD_NAME(vnet);
/* vmx:present */
- if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) {
+ if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0)
goto cleanup;
- }
/* vmx:startConnected */
if (virVMXGetConfigBoolean(conf, startConnected_name, &startConnected,
}
/* FIXME: Need to distiguish between active and inactive domains here */
- if (! present/* && ! startConnected*/) {
+ if (! present/* && ! startConnected*/)
goto ignore;
- }
/* vmx:connectionType -> def:type */
if (virVMXGetConfigString(conf, connectionType_name, &connectionType,
VMX_BUILD_NAME_EXTRA(network_endPoint, "network.endPoint");
/* vmx:present */
- if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) {
+ if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0)
goto cleanup;
- }
/* vmx:startConnected */
if (virVMXGetConfigBoolean(conf, startConnected_name, &startConnected,
}
/* FIXME: Need to distiguish between active and inactive domains here */
- if (! present/* && ! startConnected*/) {
+ if (! present/* && ! startConnected*/)
goto ignore;
- }
/* vmx:fileType -> def:type */
- if (virVMXGetConfigString(conf, fileType_name, &fileType, false) < 0) {
+ if (virVMXGetConfigString(conf, fileType_name, &fileType, false) < 0)
goto cleanup;
- }
/* vmx:fileName -> def:data.file.path */
- if (virVMXGetConfigString(conf, fileName_name, &fileName, true) < 0) {
+ if (virVMXGetConfigString(conf, fileName_name, &fileName, true) < 0)
goto cleanup;
- }
/* vmx:network.endPoint -> def:data.tcp.listen */
if (virVMXGetConfigString(conf, network_endPoint_name, &network_endPoint,
(*def)->source.data.file.path = ctx->parseFileName(fileName,
ctx->opaque);
- if ((*def)->source.data.file.path == NULL) {
+ if ((*def)->source.data.file.path == NULL)
goto cleanup;
- }
} else if (STRCASEEQ(fileType, "pipe")) {
/*
* FIXME: Differences between client/server and VM/application pipes
VMX_BUILD_NAME(fileName);
/* vmx:present */
- if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) {
+ if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0)
goto cleanup;
- }
/* vmx:startConnected */
if (virVMXGetConfigBoolean(conf, startConnected_name, &startConnected,
}
/* FIXME: Need to distiguish between active and inactive domains here */
- if (! present/* && ! startConnected*/) {
+ if (! present/* && ! startConnected*/)
goto ignore;
- }
/* vmx:fileType -> def:type */
- if (virVMXGetConfigString(conf, fileType_name, &fileType, false) < 0) {
+ if (virVMXGetConfigString(conf, fileType_name, &fileType, false) < 0)
goto cleanup;
- }
/* vmx:fileName -> def:data.file.path */
- if (virVMXGetConfigString(conf, fileName_name, &fileName, false) < 0) {
+ if (virVMXGetConfigString(conf, fileName_name, &fileName, false) < 0)
goto cleanup;
- }
/* Setup virDomainChrDef */
if (STRCASEEQ(fileType, "device")) {
(*def)->source.data.file.path = ctx->parseFileName(fileName,
ctx->opaque);
- if ((*def)->source.data.file.path == NULL) {
+ if ((*def)->source.data.file.path == NULL)
goto cleanup;
- }
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'device' or 'file' but "
/* def:name -> vmx:displayName */
preliminaryDisplayName = virVMXEscapeHexPipe(def->name);
- if (preliminaryDisplayName == NULL) {
+ if (preliminaryDisplayName == NULL)
goto cleanup;
- }
displayName = virVMXEscapeHexPercent(preliminaryDisplayName);
- if (displayName == NULL) {
+ if (displayName == NULL)
goto cleanup;
- }
virBufferAsprintf(&buffer, "displayName = \"%s\"\n", displayName);
sched_cpu_affinity_length = 0;
bit = -1;
- while ((bit = virBitmapNextSetBit(def->cpumask, bit)) >= 0) {
+ while ((bit = virBitmapNextSetBit(def->cpumask, bit)) >= 0)
++sched_cpu_affinity_length;
- }
if (sched_cpu_affinity_length < def->maxvcpus) {
virReportError(VIR_ERR_INTERNAL_ERROR,
while ((bit = virBitmapNextSetBit(def->cpumask, bit)) >= 0) {
virBufferAsprintf(&buffer, "%d", bit);
- if (sched_cpu_affinity_length > 1) {
+ if (sched_cpu_affinity_length > 1)
virBufferAddChar(&buffer, ',');
- }
--sched_cpu_affinity_length;
}
for (i = 0; i < def->ngraphics; ++i) {
switch (def->graphics[i]->type) {
case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
- if (virVMXFormatVNC(def->graphics[i], &buffer) < 0) {
+ if (virVMXFormatVNC(def->graphics[i], &buffer) < 0)
goto cleanup;
- }
break;
case VIR_DOMAIN_DISK_DEVICE_DISK:
case VIR_DOMAIN_DISK_DEVICE_CDROM:
case VIR_DOMAIN_DISK_DEVICE_LUN:
- if (virVMXFormatDisk(ctx, def->disks[i], &buffer) < 0) {
+ if (virVMXFormatDisk(ctx, def->disks[i], &buffer) < 0)
goto cleanup;
- }
break;
for (i = 0; i < 2; ++i) {
/* floppy[0..1].present defaults to true, disable it explicitly */
- if (! floppy_present[i]) {
+ if (! floppy_present[i])
virBufferAsprintf(&buffer, "floppy%zu.present = \"false\"\n", i);
- }
}
/* def:fss */
}
for (i = 0; i < def->nfss; ++i) {
- if (virVMXFormatFileSystem(def->fss[i], i, &buffer) < 0) {
+ if (virVMXFormatFileSystem(def->fss[i], i, &buffer) < 0)
goto cleanup;
- }
}
/* def:nets */
for (i = 0; i < def->nnets; ++i) {
- if (virVMXFormatEthernet(def->nets[i], i, &buffer) < 0) {
+ if (virVMXFormatEthernet(def->nets[i], i, &buffer) < 0)
goto cleanup;
- }
}
/* def:inputs */
goto cleanup;
}
- if (virVMXFormatSVGA(def->videos[0], &buffer) < 0) {
+ if (virVMXFormatSVGA(def->videos[0], &buffer) < 0)
goto cleanup;
- }
}
/* def:hostdevs */
/* def:serials */
for (i = 0; i < def->nserials; ++i) {
- if (virVMXFormatSerial(ctx, def->serials[i], &buffer) < 0) {
+ if (virVMXFormatSerial(ctx, def->serials[i], &buffer) < 0)
goto cleanup;
- }
}
/* def:parallels */
for (i = 0; i < def->nparallels; ++i) {
- if (virVMXFormatParallel(ctx, def->parallels[i], &buffer) < 0) {
+ if (virVMXFormatParallel(ctx, def->parallels[i], &buffer) < 0)
goto cleanup;
- }
}
/* Get final VMX output */
vmx = virBufferContentAndReset(&buffer);
cleanup:
- if (vmx == NULL) {
+ if (vmx == NULL)
virBufferFreeAndReset(&buffer);
- }
VIR_FREE(preliminaryDisplayName);
VIR_FREE(displayName);
fileName = ctx->formatFileName(src, ctx->opaque);
- if (fileName == NULL) {
+ if (fileName == NULL)
return -1;
- }
virBufferAsprintf(buffer, "%s%d:%d.fileName = \"%s\"\n",
busType, controllerOrBus, unit, fileName);
return -1;
}
- if (virVMXFloppyDiskNameToUnit(def->dst, &unit) < 0) {
+ if (virVMXFloppyDiskNameToUnit(def->dst, &unit) < 0)
return -1;
- }
floppy_present[unit] = true;
if (src) {
fileName = ctx->formatFileName(src, ctx->opaque);
- if (fileName == NULL) {
+ if (fileName == NULL)
return -1;
- }
virBufferAsprintf(buffer, "floppy%d.fileName = \"%s\"\n",
unit, fileName);
fileName = ctx->formatFileName(def->source.data.file.path, ctx->opaque);
- if (fileName == NULL) {
+ if (fileName == NULL)
return -1;
- }
virBufferAsprintf(buffer, "serial%d.fileName = \"%s\"\n",
def->target.port, fileName);
fileName = ctx->formatFileName(def->source.data.file.path, ctx->opaque);
- if (fileName == NULL) {
+ if (fileName == NULL)
return -1;
- }
virBufferAsprintf(buffer, "parallel%d.fileName = \"%s\"\n",
def->target.port, fileName);