[PATCH 4/6] node_device_driver: Deduplicate mediated devices listing

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

 



We have virMdevctlListDefined() to list defined mdevs, and
virMdevctlListActive() to list active mdevs. Both have the same
body except for one boolean argument passed to
nodeDeviceGetMdevctlListCommand(). Join the two functions under
virMdevctlList() name and introduce @defined argument that is
then just passed to the cmd line builder function.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/node_device/node_device_driver.c | 30 ++++++----------------------
 1 file changed, 6 insertions(+), 24 deletions(-)

diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index 593bc64e25..ac50c96837 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -1636,32 +1636,14 @@ nodeDeviceGenerateName(virNodeDeviceDef *def,
 
 
 static int
-virMdevctlListDefined(virNodeDeviceDef ***devs, char **errmsg)
+virMdevctlList(bool defined,
+               virNodeDeviceDef ***devs,
+               char **errmsg)
 {
     int status;
     g_autofree char *output = NULL;
     g_autofree char *errbuf = NULL;
-    g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlListCommand(true, &output, &errbuf);
-
-    if (virCommandRun(cmd, &status) < 0 || status != 0) {
-        *errmsg = g_steal_pointer(&errbuf);
-        return -1;
-    }
-
-    if (!output)
-        return -1;
-
-    return nodeDeviceParseMdevctlJSON(output, devs);
-}
-
-
-static int
-virMdevctlListActive(virNodeDeviceDef ***devs, char **errmsg)
-{
-    int status;
-    g_autofree char *output = NULL;
-    g_autofree char *errbuf = NULL;
-    g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlListCommand(false, &output, &errbuf);
+    g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlListCommand(defined, &output, &errbuf);
 
     if (virCommandRun(cmd, &status) < 0 || status != 0) {
         *errmsg = g_steal_pointer(&errbuf);
@@ -1750,7 +1732,7 @@ nodeDeviceUpdateMediatedDevices(void)
         return 0;
     }
 
-    if ((data.ndefs = virMdevctlListDefined(&defs, &errmsg)) < 0) {
+    if ((data.ndefs = virMdevctlList(true, &defs, &errmsg)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("failed to query mdevs from mdevctl: %1$s"), errmsg);
         return -1;
@@ -1767,7 +1749,7 @@ nodeDeviceUpdateMediatedDevices(void)
             return -1;
 
     /* Update active/transient mdev devices */
-    if ((act_ndefs = virMdevctlListActive(&act_defs, &errmsg)) < 0) {
+    if ((act_ndefs = virMdevctlList(false, &act_defs, &errmsg)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("failed to query mdevs from mdevctl: %1$s"), errmsg);
         return -1;
-- 
2.41.0




[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