mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-28 07:25:17 +00:00
bhyve: refactor virBhyveProcessBuildBhyveCmd
Use automatic cleanup for virCommand, steal it on success and remove the error label. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
0c0a8ba43b
commit
ee6b552aab
@ -649,7 +649,7 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, virDomainDef *def,
|
|||||||
* -S 31,uart,stdio \
|
* -S 31,uart,stdio \
|
||||||
* vm0
|
* vm0
|
||||||
*/
|
*/
|
||||||
virCommand *cmd = virCommandNew(BHYVE);
|
g_autoptr(virCommand) cmd = virCommandNew(BHYVE);
|
||||||
size_t i;
|
size_t i;
|
||||||
unsigned nusbcontrollers = 0;
|
unsigned nusbcontrollers = 0;
|
||||||
unsigned nisacontrollers = 0;
|
unsigned nisacontrollers = 0;
|
||||||
@ -661,14 +661,14 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, virDomainDef *def,
|
|||||||
if (def->cpu->dies != 1) {
|
if (def->cpu->dies != 1) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("Only 1 die per socket is supported"));
|
_("Only 1 die per socket is supported"));
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (nvcpus != def->cpu->sockets * def->cpu->cores * def->cpu->threads) {
|
if (nvcpus != def->cpu->sockets * def->cpu->cores * def->cpu->threads) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("Invalid CPU topology: total number of vCPUs "
|
_("Invalid CPU topology: total number of vCPUs "
|
||||||
"must equal the product of sockets, cores, "
|
"must equal the product of sockets, cores, "
|
||||||
"and threads"));
|
"and threads"));
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_CPUTOPOLOGY) != 0) {
|
if ((bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_CPUTOPOLOGY) != 0) {
|
||||||
@ -681,7 +681,7 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, virDomainDef *def,
|
|||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("Installed bhyve binary does not support "
|
_("Installed bhyve binary does not support "
|
||||||
"defining CPU topology"));
|
"defining CPU topology"));
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
virCommandAddArgFormat(cmd, "%d", nvcpus);
|
virCommandAddArgFormat(cmd, "%d", nvcpus);
|
||||||
@ -716,14 +716,14 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, virDomainDef *def,
|
|||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("Installed bhyve binary does not support "
|
_("Installed bhyve binary does not support "
|
||||||
"UTC clock"));
|
"UTC clock"));
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("unsupported clock offset '%s'"),
|
_("unsupported clock offset '%s'"),
|
||||||
virDomainClockOffsetTypeToString(def->clock.offset));
|
virDomainClockOffsetTypeToString(def->clock.offset));
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clarification about -H and -P flags from Peter Grehan:
|
/* Clarification about -H and -P flags from Peter Grehan:
|
||||||
@ -751,7 +751,7 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, virDomainDef *def,
|
|||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("Installed bhyve binary does not support "
|
_("Installed bhyve binary does not support "
|
||||||
"UEFI loader"));
|
"UEFI loader"));
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -759,26 +759,26 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, virDomainDef *def,
|
|||||||
for (i = 0; i < def->ncontrollers; i++) {
|
for (i = 0; i < def->ncontrollers; i++) {
|
||||||
if (bhyveBuildControllerArgStr(def, def->controllers[i], driver, cmd,
|
if (bhyveBuildControllerArgStr(def, def->controllers[i], driver, cmd,
|
||||||
&nusbcontrollers, &nisacontrollers) < 0)
|
&nusbcontrollers, &nisacontrollers) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (i = 0; i < def->nnets; i++) {
|
for (i = 0; i < def->nnets; i++) {
|
||||||
if (bhyveBuildNetArgStr(def, def->nets[i], driver, cmd, dryRun) < 0)
|
if (bhyveBuildNetArgStr(def, def->nets[i], driver, cmd, dryRun) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (i = 0; i < def->ndisks; i++) {
|
for (i = 0; i < def->ndisks; i++) {
|
||||||
if (bhyveBuildDiskArgStr(def, def->disks[i], cmd) < 0)
|
if (bhyveBuildDiskArgStr(def, def->disks[i], cmd) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def->ngraphics && def->nvideos) {
|
if (def->ngraphics && def->nvideos) {
|
||||||
if (def->ngraphics == 1 && def->nvideos == 1) {
|
if (def->ngraphics == 1 && def->nvideos == 1) {
|
||||||
if (bhyveBuildGraphicsArgStr(def, def->graphics[0], def->videos[0],
|
if (bhyveBuildGraphicsArgStr(def, def->graphics[0], def->videos[0],
|
||||||
driver, cmd, dryRun) < 0)
|
driver, cmd, dryRun) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("Multiple graphics devices are not supported"));
|
_("Multiple graphics devices are not supported"));
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -786,16 +786,16 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, virDomainDef *def,
|
|||||||
if (bhyveBuildSoundArgStr(def, def->sounds[i],
|
if (bhyveBuildSoundArgStr(def, def->sounds[i],
|
||||||
virDomainDefFindAudioByID(def, def->sounds[i]->audioId),
|
virDomainDefFindAudioByID(def, def->sounds[i]->audioId),
|
||||||
driver, cmd) < 0)
|
driver, cmd) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < def->nfss; i++) {
|
for (i = 0; i < def->nfss; i++) {
|
||||||
if (bhyveBuildFSArgStr(def, def->fss[i], cmd) < 0)
|
if (bhyveBuildFSArgStr(def, def->fss[i], cmd) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bhyveBuildConsoleArgStr(def, cmd) < 0)
|
if (bhyveBuildConsoleArgStr(def, cmd) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
if (def->namespaceData) {
|
if (def->namespaceData) {
|
||||||
bhyveDomainCmdlineDef *bhyvecmd;
|
bhyveDomainCmdlineDef *bhyvecmd;
|
||||||
@ -811,11 +811,7 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, virDomainDef *def,
|
|||||||
|
|
||||||
virCommandAddArg(cmd, def->name);
|
virCommandAddArg(cmd, def->name);
|
||||||
|
|
||||||
return cmd;
|
return g_steal_pointer(&cmd);
|
||||||
|
|
||||||
error:
|
|
||||||
virCommandFree(cmd);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virCommand *
|
virCommand *
|
||||||
|
Loading…
x
Reference in New Issue
Block a user