As stated in our contributor guidelines, we don't want curly brackets around oneline code block (with some exceptions). Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx> --- src/vmx/vmx.c | 369 ++++++++++++++++++++-------------------------------------- 1 file changed, 123 insertions(+), 246 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 389a012..79a3d11 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -565,9 +565,8 @@ virVMXEscapeHex(const char *string, char escape, const char *special) /* 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; @@ -610,9 +609,8 @@ virVMXUnescapeHex(char *string, char escape) /* 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; @@ -676,9 +674,8 @@ virVMXGetConfigString(virConfPtr conf, const char *name, char **string, value = virConfGetValue(conf, name); if (value == NULL) { - if (optional) { + if (optional) return 0; - } virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing essential config entry '%s'"), name); @@ -692,9 +689,8 @@ virVMXGetConfigString(virConfPtr conf, const char *name, char **string, } if (value->str == NULL) { - if (optional) { + if (optional) return 0; - } virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing essential config entry '%s'"), name); @@ -882,9 +878,8 @@ virVMXSCSIDiskNameToControllerAndUnit(const char *name, int *controller, int *un *unit = idx % 15; /* Skip the controller ifself at unit 7 */ - if (*unit >= 7) { + if (*unit >= 7) ++(*unit); - } return 0; } @@ -1082,17 +1077,15 @@ virVMXHandleLegacySCSIDiskDriverName(virDomainDefPtr def, 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); @@ -1186,9 +1179,8 @@ virVMXGatherSCSIControllers(virVMXContext *ctx, virDomainDefPtr def, disk->info.addr.drive.controller == controller->idx) { if (ctx->autodetectSCSIControllerModel (disk, &autodetectedModels[count], - ctx->opaque) < 0) { + ctx->opaque) < 0) goto cleanup; - } ++count; } @@ -1278,14 +1270,12 @@ virVMXParseConfig(virVMXContext *ctx, 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 */ @@ -1295,17 +1285,15 @@ virVMXParseConfig(virVMXContext *ctx, 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 */ @@ -1317,9 +1305,8 @@ virVMXParseConfig(virVMXContext *ctx, /* vmx:config.version */ if (virVMXGetConfigLong(conf, "config.version", &config_version, 0, - false) < 0) { + false) < 0) goto cleanup; - } if (config_version != 8) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1330,9 +1317,8 @@ virVMXParseConfig(virVMXContext *ctx, /* vmx:virtualHW.version */ if (virVMXGetConfigLong(conf, "virtualHW.version", &virtualHW_version, 0, - false) < 0) { + false) < 0) goto cleanup; - } if (virtualHW_version < 4) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1344,14 +1330,12 @@ virVMXParseConfig(virVMXContext *ctx, /* 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 || @@ -1364,9 +1348,8 @@ virVMXParseConfig(virVMXContext *ctx, /* vmx:annotation -> def:description */ if (virVMXGetConfigString(conf, "annotation", &def->description, - true) < 0) { + true) < 0) goto cleanup; - } if (def->description != NULL) { if (virVMXUnescapeHexPipe(def->description) < 0) { @@ -1378,9 +1361,8 @@ virVMXParseConfig(virVMXContext *ctx, } /* 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, @@ -1393,40 +1375,33 @@ virVMXParseConfig(virVMXContext *ctx, /* vmx:sched.mem.max -> def:mem.cur_balloon */ if (virVMXGetConfigLong(conf, "sched.mem.max", &sched_mem_max, memsize, - true) < 0) { + true) < 0) 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, - true) < 0) { + true) < 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, @@ -1440,9 +1415,8 @@ virVMXParseConfig(virVMXContext *ctx, /* vmx:sched.cpu.affinity -> def:cpumask */ /* NOTE: maps to VirtualMachine:config.cpuAffinity.affinitySet */ if (virVMXGetConfigString(conf, "sched.cpu.affinity", &sched_cpu_affinity, - true) < 0) { + true) < 0) goto cleanup; - } if (sched_cpu_affinity != NULL && STRCASENEQ(sched_cpu_affinity, "all")) { const char *current = sched_cpu_affinity; @@ -1474,9 +1448,8 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; } - if (number + 1 > cpumasklen) { + if (number + 1 > cpumasklen) cpumasklen = number + 1; - } ignore_value(virBitmapSetBit(def->cpumask, number)); ++count; @@ -1509,9 +1482,8 @@ virVMXParseConfig(virVMXContext *ctx, /* vmx:sched.cpu.shares -> def:cputune.shares */ if (virVMXGetConfigString(conf, "sched.cpu.shares", &sched_cpu_shares, - true) < 0) { + true) < 0) goto cleanup; - } if (sched_cpu_shares != NULL) { /* See http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.SharesInfo.Level.html */ @@ -1542,9 +1514,8 @@ virVMXParseConfig(virVMXContext *ctx, 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; @@ -1554,13 +1525,11 @@ virVMXParseConfig(virVMXContext *ctx, /* vmx:smbios.reflecthost -> def:os.smbios_mode */ if (virVMXGetConfigBoolean(conf, "smbios.reflecthost", - &smbios_reflecthost, false, true) < 0) { + &smbios_reflecthost, false, true) < 0) goto cleanup; - } - if (smbios_reflecthost) { + if (smbios_reflecthost) def->os.smbios_mode = VIR_DOMAIN_SMBIOS_HOST; - } /* def:features */ /* FIXME */ @@ -1574,13 +1543,11 @@ virVMXParseConfig(virVMXContext *ctx, 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) @@ -1591,13 +1558,11 @@ virVMXParseConfig(virVMXContext *ctx, /* def:disks (scsi) */ for (controller = 0; controller < 4; ++controller) { if (virVMXParseSCSIController(conf, controller, &present, - &scsi_virtualDev[controller]) < 0) { + &scsi_virtualDev[controller]) < 0) goto cleanup; - } - if (! present) { + if (! present) continue; - } for (unit = 0; unit < 16; ++unit) { if (unit == 7) { @@ -1610,9 +1575,8 @@ virVMXParseConfig(virVMXContext *ctx, if (virVMXParseDisk(ctx, xmlopt, conf, VIR_DOMAIN_DISK_DEVICE_DISK, VIR_DOMAIN_DISK_BUS_SCSI, controller, unit, - &def->disks[def->ndisks]) < 0) { + &def->disks[def->ndisks]) < 0) goto cleanup; - } if (def->disks[def->ndisks] != NULL) { ++def->ndisks; @@ -1621,13 +1585,11 @@ virVMXParseConfig(virVMXContext *ctx, if (virVMXParseDisk(ctx, xmlopt, conf, VIR_DOMAIN_DISK_DEVICE_CDROM, VIR_DOMAIN_DISK_BUS_SCSI, controller, unit, - &def->disks[def->ndisks]) < 0) { + &def->disks[def->ndisks]) < 0) goto cleanup; - } - if (def->disks[def->ndisks] != NULL) { + if (def->disks[def->ndisks] != NULL) ++def->ndisks; - } } } @@ -1636,9 +1598,8 @@ virVMXParseConfig(virVMXContext *ctx, for (unit = 0; unit < 2; ++unit) { if (virVMXParseDisk(ctx, xmlopt, conf, VIR_DOMAIN_DISK_DEVICE_DISK, VIR_DOMAIN_DISK_BUS_IDE, bus, unit, - &def->disks[def->ndisks]) < 0) { + &def->disks[def->ndisks]) < 0) goto cleanup; - } if (def->disks[def->ndisks] != NULL) { ++def->ndisks; @@ -1647,13 +1608,11 @@ virVMXParseConfig(virVMXContext *ctx, if (virVMXParseDisk(ctx, xmlopt, conf, VIR_DOMAIN_DISK_DEVICE_CDROM, VIR_DOMAIN_DISK_BUS_IDE, bus, unit, - &def->disks[def->ndisks]) < 0) { + &def->disks[def->ndisks]) < 0) goto cleanup; - } - if (def->disks[def->ndisks] != NULL) { + if (def->disks[def->ndisks] != NULL) ++def->ndisks; - } } } @@ -1661,13 +1620,11 @@ virVMXParseConfig(virVMXContext *ctx, for (unit = 0; unit < 2; ++unit) { if (virVMXParseDisk(ctx, xmlopt, conf, VIR_DOMAIN_DISK_DEVICE_FLOPPY, VIR_DOMAIN_DISK_BUS_FDC, 0, unit, - &def->disks[def->ndisks]) < 0) { + &def->disks[def->ndisks]) < 0) goto cleanup; - } - if (def->disks[def->ndisks] != NULL) { + if (def->disks[def->ndisks] != NULL) ++def->ndisks; - } } /* def:controllers */ @@ -1692,15 +1649,13 @@ virVMXParseConfig(virVMXContext *ctx, /* def:fss */ if (virVMXGetConfigBoolean(conf, "isolation.tools.hgfs.disable", - &hgfs_disabled, true, true) < 0) { + &hgfs_disabled, true, true) < 0) goto cleanup; - } if (!hgfs_disabled) { if (virVMXGetConfigLong(conf, "sharedFolder.maxNum", &sharedFolder_maxNum, - 0, true) < 0) { + 0, true) < 0) goto cleanup; - } if (sharedFolder_maxNum > 0) { int number; @@ -1712,13 +1667,11 @@ virVMXParseConfig(virVMXContext *ctx, for (number = 0; number < sharedFolder_maxNum; ++number) { if (virVMXParseFileSystem(conf, number, - &def->fss[def->nfss]) < 0) { + &def->fss[def->nfss]) < 0) goto cleanup; - } - if (def->fss[def->nfss] != NULL) { + if (def->fss[def->nfss] != NULL) ++def->nfss; - } } } } @@ -1731,13 +1684,11 @@ virVMXParseConfig(virVMXContext *ctx, for (controller = 0; controller < 4; ++controller) { if (virVMXParseEthernet(conf, controller, - &def->nets[def->nnets]) < 0) { + &def->nets[def->nnets]) < 0) goto cleanup; - } - if (def->nets[def->nnets] != NULL) { + if (def->nets[def->nnets] != NULL) ++def->nnets; - } } /* def:inputs */ @@ -1749,9 +1700,8 @@ virVMXParseConfig(virVMXContext *ctx, def->nvideos = 0; - if (virVMXParseSVGA(conf, &def->videos[def->nvideos]) < 0) { + if (virVMXParseSVGA(conf, &def->videos[def->nvideos]) < 0) goto cleanup; - } def->nvideos = 1; @@ -1769,13 +1719,11 @@ virVMXParseConfig(virVMXContext *ctx, for (port = 0; port < 4; ++port) { if (virVMXParseSerial(ctx, conf, port, - &def->serials[def->nserials]) < 0) { + &def->serials[def->nserials]) < 0) goto cleanup; - } - if (def->serials[def->nserials] != NULL) { + if (def->serials[def->nserials] != NULL) ++def->nserials; - } } /* def:parallels */ @@ -1786,13 +1734,11 @@ virVMXParseConfig(virVMXContext *ctx, for (port = 0; port < 3; ++port) { if (virVMXParseParallel(ctx, conf, port, - &def->parallels[def->nparallels]) < 0) { + &def->parallels[def->nparallels]) < 0) goto cleanup; - } - if (def->parallels[def->nparallels] != NULL) { + if (def->parallels[def->nparallels] != NULL) ++def->nparallels; - } } success = true; @@ -1827,13 +1773,11 @@ virVMXParseVNC(virConfPtr conf, virDomainGraphicsDefPtr *def) } if (virVMXGetConfigBoolean(conf, "RemoteDisplay.vnc.enabled", &enabled, - false, true) < 0) { + false, true) < 0) return -1; - } - if (! enabled) { + if (! enabled) return 0; - } if (VIR_ALLOC(*def) < 0) goto failure; @@ -1847,9 +1791,8 @@ virVMXParseVNC(virConfPtr conf, virDomainGraphicsDefPtr *def) virVMXGetConfigString(conf, "RemoteDisplay.vnc.keymap", &(*def)->data.vnc.keymap, true) < 0 || virVMXGetConfigString(conf, "RemoteDisplay.vnc.password", - &(*def)->data.vnc.auth.passwd, true) < 0) { + &(*def)->data.vnc.auth.passwd, true) < 0) goto failure; - } if (listenAddr) { if (virDomainGraphicsListenSetAddress(*def, 0, listenAddr, -1, true) < 0) @@ -1864,9 +1807,8 @@ virVMXParseVNC(virConfPtr conf, virDomainGraphicsDefPtr *def) (*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; @@ -1910,9 +1852,8 @@ virVMXParseSCSIController(virConfPtr conf, int controller, bool *present, 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; @@ -1920,16 +1861,14 @@ virVMXParseSCSIController(virConfPtr conf, int controller, bool *present, } if (virVMXGetConfigString(conf, virtualDev_name, &virtualDev_string, - true) < 0) { + true) < 0) goto cleanup; - } if (virtualDev_string != NULL) { tmp = virtualDev_string; - for (; *tmp != '\0'; ++tmp) { + for (; *tmp != '\0'; ++tmp) *tmp = c_tolower(*tmp); - } *virtualDev = virVMXControllerModelSCSITypeFromString(virtualDev_string); @@ -2045,9 +1984,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con 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, @@ -2067,9 +2005,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con (*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'"), @@ -2098,9 +2035,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con (*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'"), @@ -2125,36 +2061,30 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con 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, - true, true) < 0) { + true, true) < 0) goto cleanup; - } /* 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, - true) < 0) { + true) < 0) goto cleanup; - } /* vmx:mode -> def:transient */ - if (virVMXGetConfigString(conf, mode_name, &mode, true) < 0) { + if (virVMXGetConfigString(conf, mode_name, &mode, true) < 0) goto cleanup; - } if (clientDevice) { /* @@ -2165,20 +2095,17 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con } /* 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, - true) < 0) { + true) < 0) goto cleanup; - } /* Setup virDomainDiskDef */ if (device == VIR_DOMAIN_DISK_DEVICE_DISK) { @@ -2396,40 +2323,34 @@ int virVMXParseFileSystem(virConfPtr conf, int number, virDomainFSDefPtr *def) 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:writeAccess */ if (virVMXGetConfigBoolean(conf, writeAccess_name, &writeAccess, false, - true) < 0) { + true) < 0) goto cleanup; - } (*def)->readonly = !writeAccess; @@ -2522,35 +2443,30 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) 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, - true, true) < 0) { + true, true) < 0) goto cleanup; - } /* 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, - true) < 0) { + true) < 0) goto cleanup; - } /* vmx:addressType, vmx:generatedAddress, vmx:address -> def:mac */ if (virVMXGetConfigString(conf, addressType_name, &addressType, true) < 0 || virVMXGetConfigString(conf, generatedAddress_name, &generatedAddress, true) < 0 || - virVMXGetConfigString(conf, address_name, &address, true) < 0) { + virVMXGetConfigString(conf, address_name, &address, true) < 0) goto cleanup; - } if (addressType == NULL || STRCASEEQ(addressType, "generated") || STRCASEEQ(addressType, "vpx")) { @@ -2581,9 +2497,8 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) /* vmx:virtualDev, vmx:features -> def:model */ if (virVMXGetConfigString(conf, virtualDev_name, &virtualDev, true) < 0 || - virVMXGetConfigLong(conf, features_name, &features, 0, true) < 0) { + virVMXGetConfigLong(conf, features_name, &features, 0, true) < 0) goto cleanup; - } if (virtualDev != NULL) { if (STRCASENEQ(virtualDev, "vlance") && @@ -2619,9 +2534,8 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) /* vmx:vnet -> def:data.ifname */ if (connectionType != NULL && STRCASEEQ(connectionType, "custom") && - virVMXGetConfigString(conf, vnet_name, &vnet, false) < 0) { + virVMXGetConfigString(conf, vnet_name, &vnet, false) < 0) goto cleanup; - } /* Setup virDomainNetDef */ if (connectionType == NULL || STRCASEEQ(connectionType, "bridged")) { @@ -2736,36 +2650,30 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port, 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, - true, true) < 0) { + true, true) < 0) goto cleanup; - } /* 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, - true) < 0) { + true) < 0) goto cleanup; - } /* Setup virDomainChrDef */ if (STRCASEEQ(fileType, "device")) { @@ -2780,9 +2688,8 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port, (*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 @@ -2924,30 +2831,25 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr conf, int port, 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, - true, true) < 0) { + true, true) < 0) goto cleanup; - } /* 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")) { @@ -2962,9 +2864,8 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr conf, int port, (*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 " @@ -3014,9 +2915,8 @@ virVMXParseSVGA(virConfPtr conf, virDomainVideoDefPtr *def) /* vmx:vramSize */ if (virVMXGetConfigLong(conf, "svga.vramSize", &svga_vramSize, - 4 * 1024 * 1024, true) < 0) { + 4 * 1024 * 1024, true) < 0) goto cleanup; - } (*def)->vram = VIR_DIV_UP(svga_vramSize, 1024); /* Scale from bytes to kilobytes */ @@ -3122,15 +3022,13 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe /* 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); @@ -3188,9 +3086,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe 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, @@ -3204,9 +3101,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe 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; } @@ -3233,9 +3129,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe 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; @@ -3250,15 +3145,13 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe /* def:disks */ for (i = 0; i < def->ndisks; ++i) { if (virVMXVerifyDiskAddress(xmlopt, def->disks[i]) < 0 || - virVMXHandleLegacySCSIDiskDriverName(def, def->disks[i]) < 0) { + virVMXHandleLegacySCSIDiskDriverName(def, def->disks[i]) < 0) goto cleanup; - } } if (virVMXGatherSCSIControllers(ctx, def, scsi_virtualDev, - scsi_present) < 0) { + scsi_present) < 0) goto cleanup; - } for (i = 0; i < 4; ++i) { if (scsi_present[i]) { @@ -3277,17 +3170,15 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe 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; case VIR_DOMAIN_DISK_DEVICE_FLOPPY: if (virVMXFormatFloppy(ctx, def->disks[i], &buffer, - floppy_present) < 0) { + floppy_present) < 0) goto cleanup; - } break; @@ -3301,9 +3192,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe 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 */ @@ -3313,16 +3203,14 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe } 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 */ @@ -3339,9 +3227,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe goto cleanup; } - if (virVMXFormatSVGA(def->videos[0], &buffer) < 0) { + if (virVMXFormatSVGA(def->videos[0], &buffer) < 0) goto cleanup; - } } /* def:hostdevs */ @@ -3349,16 +3236,14 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe /* 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 */ @@ -3368,9 +3253,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe vmx = virBufferContentAndReset(&buffer); cleanup: - if (vmx == NULL) { + if (vmx == NULL) virBufferFreeAndReset(&buffer); - } VIR_FREE(preliminaryDisplayName); VIR_FREE(displayName); @@ -3467,14 +3351,12 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def, if (def->bus == VIR_DOMAIN_DISK_BUS_SCSI) { if (virVMXSCSIDiskNameToControllerAndUnit(def->dst, &controllerOrBus, - &unit) < 0) { + &unit) < 0) return -1; - } } else if (def->bus == VIR_DOMAIN_DISK_BUS_IDE) { if (virVMXIDEDiskNameToBusAndUnit(def->dst, &controllerOrBus, - &unit) < 0) { + &unit) < 0) return -1; - } } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported bus type '%s' for %s"), @@ -3518,9 +3400,8 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def, 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); @@ -3575,9 +3456,8 @@ virVMXFormatFloppy(virVMXContext *ctx, virDomainDiskDefPtr def, return -1; } - if (virVMXFloppyDiskNameToUnit(def->dst, &unit) < 0) { + if (virVMXFloppyDiskNameToUnit(def->dst, &unit) < 0) return -1; - } floppy_present[unit] = true; @@ -3589,9 +3469,8 @@ virVMXFormatFloppy(virVMXContext *ctx, virDomainDiskDefPtr def, 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); @@ -3784,9 +3663,8 @@ virVMXFormatSerial(virVMXContext *ctx, virDomainChrDefPtr def, 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); @@ -3891,9 +3769,8 @@ virVMXFormatParallel(virVMXContext *ctx, virDomainChrDefPtr def, 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); -- 2.1.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list