[PATCH v2 03/12] Simplify bhyve driver caps helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Ryan Moeller <ryan@xxxxxxxxxxxxx>
---
 src/bhyve/bhyve_command.c | 40 +++++++++++++++++++--------------------
 src/bhyve/bhyve_command.h |  4 ++--
 src/bhyve/bhyve_driver.c  | 21 +++++++++-----------
 src/bhyve/bhyve_driver.h  |  4 ++--
 src/bhyve/bhyve_process.c |  8 +++-----
 5 files changed, 35 insertions(+), 42 deletions(-)

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 48336ffa1b..c8424063b7 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -44,7 +44,7 @@
 VIR_LOG_INIT("bhyve.bhyve_command");
 
 static int
-bhyveBuildNetArgStr(virConnectPtr conn,
+bhyveBuildNetArgStr(bhyveConnPtr driver,
                     const virDomainDef *def,
                     virDomainNetDefPtr net,
                     virCommandPtr cmd,
@@ -60,7 +60,7 @@ bhyveBuildNetArgStr(virConnectPtr conn,
     if (net->model == VIR_DOMAIN_NET_MODEL_VIRTIO) {
         nic_model = g_strdup("virtio-net");
     } 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");
         } else {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -166,7 +166,7 @@ bhyveBuildConsoleArgStr(const virDomainDef *def, virCommandPtr cmd)
 static int
 bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
                                virDomainControllerDefPtr controller,
-                               virConnectPtr conn,
+                               bhyveConnPtr driver,
                                virCommandPtr cmd)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -207,13 +207,13 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
 
         switch (disk->device) {
         case VIR_DOMAIN_DISK_DEVICE_DISK:
-            if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_AHCI32SLOT))
+            if ((bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_AHCI32SLOT))
                 virBufferAsprintf(&device, ",hd:%s", disk_source);
             else
                 virBufferAsprintf(&device, "-hd,%s", disk_source);
             break;
         case VIR_DOMAIN_DISK_DEVICE_CDROM:
-            if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_AHCI32SLOT))
+            if ((bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_AHCI32SLOT))
                 virBufferAsprintf(&device, ",cd:%s", disk_source);
             else
                 virBufferAsprintf(&device, "-cd,%s", disk_source);
@@ -322,7 +322,7 @@ static int
 bhyveBuildGraphicsArgStr(const virDomainDef *def,
                          virDomainGraphicsDefPtr graphics,
                          virDomainVideoDefPtr video,
-                         virConnectPtr conn,
+                         bhyveConnPtr driver,
                          virCommandPtr cmd,
                          bool dryRun)
 {
@@ -331,9 +331,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
     bool escapeAddr;
     unsigned short port;
 
-    bhyveConnPtr driver = conn->privateData;
-
-    if (!(bhyveDriverGetCaps(conn) & BHYVE_CAP_LPC_BOOTROM) ||
+    if (!(bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_LPC_BOOTROM) ||
         def->os.bootloader ||
         !def->os.loader) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -342,7 +340,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
         return -1;
     }
 
-    if (!(bhyveDriverGetCaps(conn) & BHYVE_CAP_FBUF)) {
+    if (!(bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_FBUF)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Bhyve version does not support framebuffer"));
         return -1;
@@ -433,7 +431,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 }
 
 virCommandPtr
-virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
+virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver,
                              virDomainDefPtr def, bool dryRun)
 {
     /*
@@ -461,7 +459,7 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
             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",
                                    nvcpus,
                                    def->cpu->sockets,
@@ -500,7 +498,7 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
         /* used by default in bhyve */
         break;
     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");
         } else {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -534,7 +532,7 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
 
     if (def->os.bootloader == NULL &&
         def->os.loader) {
-        if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_LPC_BOOTROM)) {
+        if ((bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_LPC_BOOTROM)) {
             virCommandAddArg(cmd, "-l");
             virCommandAddArgFormat(cmd, "bootrom,%s", def->os.loader->path);
         } else {
@@ -557,7 +555,7 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
                 }
                 break;
         case VIR_DOMAIN_CONTROLLER_TYPE_SATA:
-                if (bhyveBuildAHCIControllerArgStr(def, controller, conn, cmd) < 0)
+                if (bhyveBuildAHCIControllerArgStr(def, controller, driver, cmd) < 0)
                     goto error;
                 break;
         case VIR_DOMAIN_CONTROLLER_TYPE_USB:
@@ -574,7 +572,7 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
     }
     for (i = 0; i < def->nnets; i++) {
         virDomainNetDefPtr net = def->nets[i];
-        if (bhyveBuildNetArgStr(conn, def, net, cmd, dryRun) < 0)
+        if (bhyveBuildNetArgStr(driver, def, net, cmd, dryRun) < 0)
             goto error;
     }
     for (i = 0; i < def->ndisks; i++) {
@@ -598,7 +596,7 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
     if (def->ngraphics && def->nvideos) {
         if (def->ngraphics == 1 && def->nvideos == 1) {
             if (bhyveBuildGraphicsArgStr(def, def->graphics[0], def->videos[0],
-                                         conn, cmd, dryRun) < 0)
+                                         driver, cmd, dryRun) < 0)
                 goto error;
         } else {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -741,7 +739,7 @@ virBhyveFormatGrubDevice(virBufferPtr devicemap, virDomainDiskDefPtr def)
 
 static virCommandPtr
 virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
-                                 virConnectPtr conn,
+                                 bhyveConnPtr driver,
                                  const char *devmap_file,
                                  char **devicesmap_out)
 {
@@ -824,7 +822,7 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
     virCommandAddArgFormat(cmd, "%llu",
                            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) {
         virDomainChrDefPtr chr;
 
@@ -933,7 +931,7 @@ virBhyveGetBootDisk(virDomainDefPtr def)
 }
 
 virCommandPtr
-virBhyveProcessBuildLoadCmd(virConnectPtr conn, virDomainDefPtr def,
+virBhyveProcessBuildLoadCmd(bhyveConnPtr driver, virDomainDefPtr def,
                             const char *devmap_file, char **devicesmap_out)
 {
     virDomainDiskDefPtr disk = NULL;
@@ -946,7 +944,7 @@ virBhyveProcessBuildLoadCmd(virConnectPtr conn, virDomainDefPtr def,
 
         return virBhyveProcessBuildBhyveloadCmd(def, disk);
     } else if (strstr(def->os.bootloader, "grub-bhyve") != NULL) {
-        return virBhyveProcessBuildGrubbhyveCmd(def, conn, devmap_file,
+        return virBhyveProcessBuildGrubbhyveCmd(def, driver, devmap_file,
                                                 devicesmap_out);
     } else {
         return virBhyveProcessBuildCustomLoaderCmd(def);
diff --git a/src/bhyve/bhyve_command.h b/src/bhyve/bhyve_command.h
index 8c39f4eb2f..5a934c4883 100644
--- a/src/bhyve/bhyve_command.h
+++ b/src/bhyve/bhyve_command.h
@@ -29,7 +29,7 @@
 
 #define BHYVE_CONFIG_FORMAT_ARGV "bhyve-argv"
 
-virCommandPtr virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
+virCommandPtr virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver,
                                            virDomainDefPtr def,
                                            bool dryRun);
 
@@ -38,5 +38,5 @@ virBhyveProcessBuildDestroyCmd(bhyveConnPtr driver,
                                virDomainDefPtr def);
 
 virCommandPtr
-virBhyveProcessBuildLoadCmd(virConnectPtr conn, virDomainDefPtr def,
+virBhyveProcessBuildLoadCmd(bhyveConnPtr driver, virDomainDefPtr def,
                             const char *devmap_file, char **devicesmap_out);
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index a764b4d4ed..760619a5a6 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -711,22 +711,22 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn,
             goto cleanup;
         }
 
-        if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_LPC_BOOTROM) == 0) {
+        if ((bhyveDriverGetBhyveCaps(privconn) & BHYVE_CAP_LPC_BOOTROM) == 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("Installed bhyve binary does not support "
                           "bootrom"));
             goto cleanup;
         }
     } else {
-        if (!(loadcmd = virBhyveProcessBuildLoadCmd(conn, def, "<device.map>",
-                                                NULL)))
+        if (!(loadcmd = virBhyveProcessBuildLoadCmd(privconn, def,
+                                                    "<device.map>", NULL)))
             goto cleanup;
 
         virBufferAdd(&buf, virCommandToString(loadcmd, false), -1);
         virBufferAddChar(&buf, '\n');
     }
 
-    if (!(cmd = virBhyveProcessBuildBhyveCmd(conn, def, true)))
+    if (!(cmd = virBhyveProcessBuildBhyveCmd(privconn, def, true)))
         goto cleanup;
 
     virBufferAdd(&buf, virCommandToString(cmd, false), -1);
@@ -1276,20 +1276,16 @@ bhyveStateInitialize(bool privileged,
 }
 
 unsigned
-bhyveDriverGetCaps(virConnectPtr conn)
+bhyveDriverGetBhyveCaps(bhyveConnPtr driver)
 {
-    bhyveConnPtr driver = conn->privateData;
-
     if (driver != NULL)
         return driver->bhyvecaps;
     return 0;
 }
 
 unsigned
-bhyveDriverGetGrubCaps(virConnectPtr conn)
+bhyveDriverGetGrubCaps(bhyveConnPtr driver)
 {
-    bhyveConnPtr driver = conn->privateData;
-
     if (driver != NULL)
         return driver->grubcaps;
     return 0;
@@ -1537,7 +1533,7 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn,
     char *xml = NULL;
     virDomainDefPtr def = NULL;
     bhyveConnPtr privconn = conn->privateData;
-    unsigned caps = bhyveDriverGetCaps(conn);
+    unsigned bhyveCaps = bhyveDriverGetBhyveCaps(privconn);
 
     virCheckFlags(0, NULL);
 
@@ -1550,7 +1546,8 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn,
         goto cleanup;
     }
 
-    def = bhyveParseCommandLineString(nativeConfig, caps, privconn->xmlopt);
+    def = bhyveParseCommandLineString(nativeConfig, bhyveCaps,
+                                      privconn->xmlopt);
     if (def == NULL)
         goto cleanup;
 
diff --git a/src/bhyve/bhyve_driver.h b/src/bhyve/bhyve_driver.h
index 98e75039a3..75a63e0233 100644
--- a/src/bhyve/bhyve_driver.h
+++ b/src/bhyve/bhyve_driver.h
@@ -25,8 +25,8 @@
 
 int bhyveRegister(void);
 
-unsigned bhyveDriverGetCaps(virConnectPtr conn);
+unsigned bhyveDriverGetBhyveCaps(bhyveConnPtr driver);
 
-unsigned bhyveDriverGetGrubCaps(virConnectPtr conn);
+unsigned bhyveDriverGetGrubCaps(bhyveConnPtr driver);
 
 virCapsPtr bhyveDriverGetCapabilities(bhyveConnPtr driver);
diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c
index d9815851de..bddd4e9461 100644
--- a/src/bhyve/bhyve_process.c
+++ b/src/bhyve/bhyve_process.c
@@ -164,9 +164,7 @@ virBhyveProcessStart(virConnectPtr conn,
         goto cleanup;
 
     /* Call bhyve to start the VM */
-    if (!(cmd = virBhyveProcessBuildBhyveCmd(conn,
-                                             vm->def,
-                                             false)))
+    if (!(cmd = virBhyveProcessBuildBhyveCmd(driver, vm->def, false)))
         goto cleanup;
 
     virCommandSetOutputFD(cmd, &logfd);
@@ -182,8 +180,8 @@ virBhyveProcessStart(virConnectPtr conn,
 
         virBhyveFormatDevMapFile(vm->def->name, &devmap_file);
 
-        if (!(load_cmd = virBhyveProcessBuildLoadCmd(conn, vm->def, devmap_file,
-                                                     &devicemap)))
+        if (!(load_cmd = virBhyveProcessBuildLoadCmd(driver, vm->def,
+                                                     devmap_file, &devicemap)))
             goto cleanup;
         virCommandSetOutputFD(load_cmd, &logfd);
         virCommandSetErrorFD(load_cmd, &logfd);
-- 
2.23.0


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux