bhyve: simplify driver caps helpers

Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Ryan Moeller 2020-02-22 01:38:41 -05:00 committed by Ján Tomko
parent 6801ad1624
commit b4a076ea78
6 changed files with 37 additions and 44 deletions

View File

@ -40,7 +40,7 @@
VIR_LOG_INIT("bhyve.bhyve_command"); VIR_LOG_INIT("bhyve.bhyve_command");
static int static int
bhyveBuildNetArgStr(virConnectPtr conn, bhyveBuildNetArgStr(bhyveConnPtr driver,
const virDomainDef *def, const virDomainDef *def,
virDomainNetDefPtr net, virDomainNetDefPtr net,
virCommandPtr cmd, virCommandPtr cmd,
@ -56,7 +56,7 @@ bhyveBuildNetArgStr(virConnectPtr conn,
if (net->model == VIR_DOMAIN_NET_MODEL_VIRTIO) { if (net->model == VIR_DOMAIN_NET_MODEL_VIRTIO) {
nic_model = g_strdup("virtio-net"); nic_model = g_strdup("virtio-net");
} else if (net->model == VIR_DOMAIN_NET_MODEL_E1000) { } else if (net->model == VIR_DOMAIN_NET_MODEL_E1000) {
if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_NET_E1000) != 0) { if ((bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_NET_E1000) != 0) {
nic_model = g_strdup("e1000"); nic_model = g_strdup("e1000");
} else { } else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@ -163,7 +163,7 @@ bhyveBuildConsoleArgStr(const virDomainDef *def, virCommandPtr cmd)
static int static int
bhyveBuildAHCIControllerArgStr(const virDomainDef *def, bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
virDomainControllerDefPtr controller, virDomainControllerDefPtr controller,
virConnectPtr conn, bhyveConnPtr driver,
virCommandPtr cmd) virCommandPtr cmd)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
@ -204,13 +204,13 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
switch (disk->device) { switch (disk->device) {
case VIR_DOMAIN_DISK_DEVICE_DISK: case VIR_DOMAIN_DISK_DEVICE_DISK:
if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_AHCI32SLOT)) if ((bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_AHCI32SLOT))
virBufferAsprintf(&device, ",hd:%s", disk_source); virBufferAsprintf(&device, ",hd:%s", disk_source);
else else
virBufferAsprintf(&device, "-hd,%s", disk_source); virBufferAsprintf(&device, "-hd,%s", disk_source);
break; break;
case VIR_DOMAIN_DISK_DEVICE_CDROM: case VIR_DOMAIN_DISK_DEVICE_CDROM:
if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_AHCI32SLOT)) if ((bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_AHCI32SLOT))
virBufferAsprintf(&device, ",cd:%s", disk_source); virBufferAsprintf(&device, ",cd:%s", disk_source);
else else
virBufferAsprintf(&device, "-cd,%s", disk_source); virBufferAsprintf(&device, "-cd,%s", disk_source);
@ -319,7 +319,7 @@ static int
bhyveBuildGraphicsArgStr(const virDomainDef *def, bhyveBuildGraphicsArgStr(const virDomainDef *def,
virDomainGraphicsDefPtr graphics, virDomainGraphicsDefPtr graphics,
virDomainVideoDefPtr video, virDomainVideoDefPtr video,
virConnectPtr conn, bhyveConnPtr driver,
virCommandPtr cmd, virCommandPtr cmd,
bool dryRun) bool dryRun)
{ {
@ -328,9 +328,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
bool escapeAddr; bool escapeAddr;
unsigned short port; unsigned short port;
bhyveConnPtr driver = conn->privateData; if (!(bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_LPC_BOOTROM) ||
if (!(bhyveDriverGetCaps(conn) & BHYVE_CAP_LPC_BOOTROM) ||
def->os.bootloader || def->os.bootloader ||
!def->os.loader) { !def->os.loader) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@ -339,7 +337,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
return -1; return -1;
} }
if (!(bhyveDriverGetCaps(conn) & BHYVE_CAP_FBUF)) { if (!(bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_FBUF)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Bhyve version does not support framebuffer")); _("Bhyve version does not support framebuffer"));
return -1; return -1;
@ -430,7 +428,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
} }
virCommandPtr virCommandPtr
virBhyveProcessBuildBhyveCmd(virConnectPtr conn, virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver,
virDomainDefPtr def, bool dryRun) virDomainDefPtr def, bool dryRun)
{ {
/* /*
@ -463,7 +461,7 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
goto error; goto error;
} }
if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_CPUTOPOLOGY) != 0) { if ((bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_CPUTOPOLOGY) != 0) {
virCommandAddArgFormat(cmd, "cpus=%d,sockets=%d,cores=%d,threads=%d", virCommandAddArgFormat(cmd, "cpus=%d,sockets=%d,cores=%d,threads=%d",
nvcpus, nvcpus,
def->cpu->sockets, def->cpu->sockets,
@ -502,7 +500,7 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
/* used by default in bhyve */ /* used by default in bhyve */
break; break;
case VIR_DOMAIN_CLOCK_OFFSET_UTC: case VIR_DOMAIN_CLOCK_OFFSET_UTC:
if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_RTC_UTC) != 0) { if ((bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_RTC_UTC) != 0) {
virCommandAddArg(cmd, "-u"); virCommandAddArg(cmd, "-u");
} else { } else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@ -536,7 +534,7 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
if (def->os.bootloader == NULL && if (def->os.bootloader == NULL &&
def->os.loader) { def->os.loader) {
if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_LPC_BOOTROM)) { if ((bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_LPC_BOOTROM)) {
virCommandAddArg(cmd, "-l"); virCommandAddArg(cmd, "-l");
virCommandAddArgFormat(cmd, "bootrom,%s", def->os.loader->path); virCommandAddArgFormat(cmd, "bootrom,%s", def->os.loader->path);
} else { } else {
@ -559,7 +557,7 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
} }
break; break;
case VIR_DOMAIN_CONTROLLER_TYPE_SATA: case VIR_DOMAIN_CONTROLLER_TYPE_SATA:
if (bhyveBuildAHCIControllerArgStr(def, controller, conn, cmd) < 0) if (bhyveBuildAHCIControllerArgStr(def, controller, driver, cmd) < 0)
goto error; goto error;
break; break;
case VIR_DOMAIN_CONTROLLER_TYPE_USB: case VIR_DOMAIN_CONTROLLER_TYPE_USB:
@ -576,7 +574,7 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
} }
for (i = 0; i < def->nnets; i++) { for (i = 0; i < def->nnets; i++) {
virDomainNetDefPtr net = def->nets[i]; virDomainNetDefPtr net = def->nets[i];
if (bhyveBuildNetArgStr(conn, def, net, cmd, dryRun) < 0) if (bhyveBuildNetArgStr(driver, def, net, cmd, dryRun) < 0)
goto error; goto error;
} }
for (i = 0; i < def->ndisks; i++) { for (i = 0; i < def->ndisks; i++) {
@ -600,7 +598,7 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
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],
conn, cmd, dryRun) < 0) driver, cmd, dryRun) < 0)
goto error; goto error;
} else { } else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@ -743,7 +741,7 @@ virBhyveFormatGrubDevice(virBufferPtr devicemap, virDomainDiskDefPtr def)
static virCommandPtr static virCommandPtr
virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def, virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
virConnectPtr conn, bhyveConnPtr driver,
const char *devmap_file, const char *devmap_file,
char **devicesmap_out) char **devicesmap_out)
{ {
@ -826,7 +824,7 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
virCommandAddArgFormat(cmd, "%llu", virCommandAddArgFormat(cmd, "%llu",
VIR_DIV_UP(virDomainDefGetMemoryInitial(def), 1024)); VIR_DIV_UP(virDomainDefGetMemoryInitial(def), 1024));
if ((bhyveDriverGetGrubCaps(conn) & BHYVE_GRUB_CAP_CONSDEV) != 0 && if ((bhyveDriverGetGrubCaps(driver) & BHYVE_GRUB_CAP_CONSDEV) != 0 &&
def->nserials > 0) { def->nserials > 0) {
virDomainChrDefPtr chr; virDomainChrDefPtr chr;
@ -935,7 +933,7 @@ virBhyveGetBootDisk(virDomainDefPtr def)
} }
virCommandPtr virCommandPtr
virBhyveProcessBuildLoadCmd(virConnectPtr conn, virDomainDefPtr def, virBhyveProcessBuildLoadCmd(bhyveConnPtr driver, virDomainDefPtr def,
const char *devmap_file, char **devicesmap_out) const char *devmap_file, char **devicesmap_out)
{ {
virDomainDiskDefPtr disk = NULL; virDomainDiskDefPtr disk = NULL;
@ -948,7 +946,7 @@ virBhyveProcessBuildLoadCmd(virConnectPtr conn, virDomainDefPtr def,
return virBhyveProcessBuildBhyveloadCmd(def, disk); return virBhyveProcessBuildBhyveloadCmd(def, disk);
} else if (strstr(def->os.bootloader, "grub-bhyve") != NULL) { } else if (strstr(def->os.bootloader, "grub-bhyve") != NULL) {
return virBhyveProcessBuildGrubbhyveCmd(def, conn, devmap_file, return virBhyveProcessBuildGrubbhyveCmd(def, driver, devmap_file,
devicesmap_out); devicesmap_out);
} else { } else {
return virBhyveProcessBuildCustomLoaderCmd(def); return virBhyveProcessBuildCustomLoaderCmd(def);

View File

@ -29,7 +29,7 @@
#define BHYVE_CONFIG_FORMAT_ARGV "bhyve-argv" #define BHYVE_CONFIG_FORMAT_ARGV "bhyve-argv"
virCommandPtr virBhyveProcessBuildBhyveCmd(virConnectPtr conn, virCommandPtr virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver,
virDomainDefPtr def, virDomainDefPtr def,
bool dryRun); bool dryRun);
@ -38,5 +38,5 @@ virBhyveProcessBuildDestroyCmd(bhyveConnPtr driver,
virDomainDefPtr def); virDomainDefPtr def);
virCommandPtr virCommandPtr
virBhyveProcessBuildLoadCmd(virConnectPtr conn, virDomainDefPtr def, virBhyveProcessBuildLoadCmd(bhyveConnPtr driver, virDomainDefPtr def,
const char *devmap_file, char **devicesmap_out); const char *devmap_file, char **devicesmap_out);

View File

@ -710,22 +710,22 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_LPC_BOOTROM) == 0) { if ((bhyveDriverGetBhyveCaps(privconn) & BHYVE_CAP_LPC_BOOTROM) == 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Installed bhyve binary does not support " _("Installed bhyve binary does not support "
"bootrom")); "bootrom"));
goto cleanup; goto cleanup;
} }
} else { } else {
if (!(loadcmd = virBhyveProcessBuildLoadCmd(conn, def, "<device.map>", if (!(loadcmd = virBhyveProcessBuildLoadCmd(privconn, def,
NULL))) "<device.map>", NULL)))
goto cleanup; goto cleanup;
virBufferAdd(&buf, virCommandToString(loadcmd, false), -1); virBufferAdd(&buf, virCommandToString(loadcmd, false), -1);
virBufferAddChar(&buf, '\n'); virBufferAddChar(&buf, '\n');
} }
if (!(cmd = virBhyveProcessBuildBhyveCmd(conn, def, true))) if (!(cmd = virBhyveProcessBuildBhyveCmd(privconn, def, true)))
goto cleanup; goto cleanup;
virBufferAdd(&buf, virCommandToString(cmd, false), -1); virBufferAdd(&buf, virCommandToString(cmd, false), -1);
@ -1282,20 +1282,16 @@ bhyveStateInitialize(bool privileged,
} }
unsigned unsigned
bhyveDriverGetCaps(virConnectPtr conn) bhyveDriverGetBhyveCaps(bhyveConnPtr driver)
{ {
bhyveConnPtr driver = conn->privateData;
if (driver != NULL) if (driver != NULL)
return driver->bhyvecaps; return driver->bhyvecaps;
return 0; return 0;
} }
unsigned unsigned
bhyveDriverGetGrubCaps(virConnectPtr conn) bhyveDriverGetGrubCaps(bhyveConnPtr driver)
{ {
bhyveConnPtr driver = conn->privateData;
if (driver != NULL) if (driver != NULL)
return driver->grubcaps; return driver->grubcaps;
return 0; return 0;
@ -1543,7 +1539,7 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn,
char *xml = NULL; char *xml = NULL;
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
bhyveConnPtr privconn = conn->privateData; bhyveConnPtr privconn = conn->privateData;
unsigned caps = bhyveDriverGetCaps(conn); unsigned bhyveCaps = bhyveDriverGetBhyveCaps(privconn);
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
@ -1556,7 +1552,8 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
def = bhyveParseCommandLineString(nativeConfig, caps, privconn->xmlopt); def = bhyveParseCommandLineString(nativeConfig, bhyveCaps,
privconn->xmlopt);
if (def == NULL) if (def == NULL)
goto cleanup; goto cleanup;

View File

@ -25,8 +25,8 @@
int bhyveRegister(void); int bhyveRegister(void);
unsigned bhyveDriverGetCaps(virConnectPtr conn); unsigned bhyveDriverGetBhyveCaps(bhyveConnPtr driver);
unsigned bhyveDriverGetGrubCaps(virConnectPtr conn); unsigned bhyveDriverGetGrubCaps(bhyveConnPtr driver);
virCapsPtr bhyveDriverGetCapabilities(bhyveConnPtr driver); virCapsPtr bhyveDriverGetCapabilities(bhyveConnPtr driver);

View File

@ -141,9 +141,7 @@ virBhyveProcessStart(virConnectPtr conn,
goto cleanup; goto cleanup;
/* Call bhyve to start the VM */ /* Call bhyve to start the VM */
if (!(cmd = virBhyveProcessBuildBhyveCmd(conn, if (!(cmd = virBhyveProcessBuildBhyveCmd(driver, vm->def, false)))
vm->def,
false)))
goto cleanup; goto cleanup;
virCommandSetOutputFD(cmd, &logfd); virCommandSetOutputFD(cmd, &logfd);
@ -159,8 +157,8 @@ virBhyveProcessStart(virConnectPtr conn,
virBhyveFormatDevMapFile(vm->def->name, &devmap_file); virBhyveFormatDevMapFile(vm->def->name, &devmap_file);
if (!(load_cmd = virBhyveProcessBuildLoadCmd(conn, vm->def, devmap_file, if (!(load_cmd = virBhyveProcessBuildLoadCmd(driver, vm->def,
&devicemap))) devmap_file, &devicemap)))
goto cleanup; goto cleanup;
virCommandSetOutputFD(load_cmd, &logfd); virCommandSetOutputFD(load_cmd, &logfd);
virCommandSetErrorFD(load_cmd, &logfd); virCommandSetErrorFD(load_cmd, &logfd);

View File

@ -51,11 +51,11 @@ static int testCompareXMLToArgvFiles(const char *xml,
conn->privateData = &driver; conn->privateData = &driver;
cmd = virBhyveProcessBuildBhyveCmd(conn, vmdef, false); cmd = virBhyveProcessBuildBhyveCmd(&driver, vmdef, false);
if (vmdef->os.loader) if (vmdef->os.loader)
ldcmd = virCommandNew("dummy"); ldcmd = virCommandNew("dummy");
else else
ldcmd = virBhyveProcessBuildLoadCmd(conn, vmdef, "<device.map>", ldcmd = virBhyveProcessBuildLoadCmd(&driver, vmdef, "<device.map>",
&actualdm); &actualdm);
if ((cmd == NULL) || (ldcmd == NULL)) { if ((cmd == NULL) || (ldcmd == NULL)) {