[libvirt PATCH v2 08/12] nodedev: Remove GetMdevctl*Command() wrappers

Jonathon Jongsma jjongsma at redhat.com
Tue Apr 13 20:39:44 UTC 2021


These per-command generator functions were only exposed in the header to
allow the commandline generation to be tested. Now that we have a
generic mdevctl command generator, we can get rid of the per-command
wrappers and reduce the noise in the header.

Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
---
 src/node_device/node_device_driver.c | 56 ++++++----------------------
 src/node_device/node_device_driver.h | 24 ++----------
 tests/nodedevmdevctltest.c           | 41 ++++----------------
 3 files changed, 23 insertions(+), 98 deletions(-)

diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index bbb01c3967..b8e68d3b27 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -702,7 +702,7 @@ nodeDeviceFindAddressByName(const char *name)
 }
 
 
-static virCommand *
+virCommand *
 nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def,
                             virMdevctlCommand cmd_type,
                             char **outbuf,
@@ -775,30 +775,15 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def,
     return cmd;
 }
 
-virCommand*
-nodeDeviceGetMdevctlCreateCommand(virNodeDeviceDef *def,
-                                 char **uuid_out,
-                                 char **errmsg)
-{
-    return nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_CREATE, uuid_out, errmsg);
-}
-
-virCommand*
-nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDef *def,
-                                  char **uuid_out,
-                                  char **errmsg)
-{
-    return nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_DEFINE, uuid_out, errmsg);
-}
-
-
 
 static int
 virMdevctlCreate(virNodeDeviceDef *def, char **uuid, char **errmsg)
 {
     int status;
-    g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlCreateCommand(def, uuid,
-                                                                  errmsg);
+    g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlCommand(def,
+                                                            MDEVCTL_CMD_CREATE,
+                                                            uuid,
+                                                            errmsg);
     if (!cmd)
         return -1;
 
@@ -818,7 +803,9 @@ static int
 virMdevctlDefine(virNodeDeviceDef *def, char **uuid, char **errmsg)
 {
     int status;
-    g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlDefineCommand(def, uuid, errmsg);
+    g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlCommand(def,
+                                                            MDEVCTL_CMD_DEFINE,
+                                                            uuid, errmsg);
 
     if (!cmd)
         return -1;
@@ -921,34 +908,13 @@ nodeDeviceCreateXML(virConnectPtr conn,
 }
 
 
-virCommand *
-nodeDeviceGetMdevctlStopCommand(virNodeDeviceDef *def,
-                                char **errmsg)
-{
-    return nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_STOP, NULL, errmsg);
-}
-
-virCommand *
-nodeDeviceGetMdevctlUndefineCommand(virNodeDeviceDef *def,
-                                    char **errmsg)
-{
-    return nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_UNDEFINE, NULL, errmsg);
-}
-
-virCommand *
-nodeDeviceGetMdevctlStartCommand(virNodeDeviceDef *def,
-                                 char **errmsg)
-{
-    return nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_START, NULL, errmsg);
-}
-
 static int
 virMdevctlStop(virNodeDeviceDef *def, char **errmsg)
 {
     int status;
     g_autoptr(virCommand) cmd = NULL;
 
-    cmd = nodeDeviceGetMdevctlStopCommand(def, errmsg);
+    cmd = nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_STOP, NULL, errmsg);
 
     if (virCommandRun(cmd, &status) < 0 || status != 0)
         return -1;
@@ -963,7 +929,7 @@ virMdevctlUndefine(virNodeDeviceDef *def, char **errmsg)
     int status;
     g_autoptr(virCommand) cmd = NULL;
 
-    cmd = nodeDeviceGetMdevctlUndefineCommand(def, errmsg);
+    cmd = nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_UNDEFINE, NULL, errmsg);
 
     if (virCommandRun(cmd, &status) < 0 || status != 0)
         return -1;
@@ -978,7 +944,7 @@ virMdevctlStart(virNodeDeviceDef *def, char **errmsg)
     int status;
     g_autoptr(virCommand) cmd = NULL;
 
-    cmd = nodeDeviceGetMdevctlStartCommand(def, errmsg);
+    cmd = nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_START, NULL, errmsg);
 
     if (virCommandRun(cmd, &status) < 0 || status != 0)
         return -1;
diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h
index 105a71dd93..edd763f0e4 100644
--- a/src/node_device/node_device_driver.h
+++ b/src/node_device/node_device_driver.h
@@ -142,22 +142,10 @@ nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr conn,
                                         int callbackID);
 
 virCommand *
-nodeDeviceGetMdevctlCreateCommand(virNodeDeviceDef *def,
-                                  char **uuid_out,
-                                  char **errmsg);
-
-virCommand*
-nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDef *def,
-                                  char **uuid_out,
-                                  char **errmsg);
-
-virCommand *
-nodeDeviceGetMdevctlStopCommand(virNodeDeviceDef *def,
-                                char **errmsg);
-
-virCommand *
-nodeDeviceGetMdevctlUndefineCommand(virNodeDeviceDef *def,
-                                    char **errmsg);
+nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def,
+                            virMdevctlCommand cmd_type,
+                            char **outbuf,
+                            char **errbuf);
 
 virCommand *
 nodeDeviceGetMdevctlListCommand(bool defined,
@@ -180,10 +168,6 @@ nodeDeviceGenerateName(virNodeDeviceDef *def,
 bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst,
                                   virNodeDeviceDef *src);
 
-virCommand*
-nodeDeviceGetMdevctlStartCommand(virNodeDeviceDef *def,
-                                 char **errmsg);
-
 int
 nodeDeviceCreate(virNodeDevice *dev,
                  unsigned int flags);
diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c
index 188bad6e53..64ce7fec46 100644
--- a/tests/nodedevmdevctltest.c
+++ b/tests/nodedevmdevctltest.c
@@ -38,7 +38,7 @@ typedef virCommand* (*MdevctlCmdFunc)(virNodeDeviceDef *, char **, char **);
 static int
 testMdevctlCreateOrDefine(const char *virt_type,
                           int create,
-                          MdevctlCmdFunc mdevctl_cmd_func,
+                          virMdevctlCommand cmd_type,
                           const char *mdevxml,
                           const char *cmdfile,
                           const char *jsonfile)
@@ -59,7 +59,7 @@ testMdevctlCreateOrDefine(const char *virt_type,
 
     /* this function will set a stdin buffer containing the json configuration
      * of the device. The json value is captured in the callback above */
-    cmd = mdevctl_cmd_func(def, &uuid, &errmsg);
+    cmd = nodeDeviceGetMdevctlCommand(def, cmd_type, &uuid, &errmsg);
 
     if (!cmd)
         goto cleanup;
@@ -88,22 +88,11 @@ static int
 testMdevctlCreateOrDefineHelper(const void *data)
 {
     const struct startTestInfo *info = data;
-    const char *cmd;
-    MdevctlCmdFunc func;
+    const char *cmd = virMdevctlCommandTypeToString(info->command);
     g_autofree char *mdevxml = NULL;
     g_autofree char *cmdlinefile = NULL;
     g_autofree char *jsonfile = NULL;
 
-    if (info->command == MDEVCTL_CMD_CREATE) {
-        cmd = "create";
-        func = nodeDeviceGetMdevctlCreateCommand;
-    } else if (info->command == MDEVCTL_CMD_DEFINE) {
-        cmd = "define";
-        func = nodeDeviceGetMdevctlDefineCommand;
-    } else {
-        return -1;
-    }
-
     mdevxml = g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir,
                               info->filename);
     cmdlinefile = g_strdup_printf("%s/nodedevmdevctldata/%s-%s.argv",
@@ -111,7 +100,7 @@ testMdevctlCreateOrDefineHelper(const void *data)
     jsonfile = g_strdup_printf("%s/nodedevmdevctldata/%s-%s.json", abs_srcdir,
                                info->filename, cmd);
 
-    return testMdevctlCreateOrDefine(info->virt_type, info->create, func,
+    return testMdevctlCreateOrDefine(info->virt_type, info->create, info->command,
                                      mdevxml, cmdlinefile, jsonfile);
 }
 
@@ -122,7 +111,7 @@ struct UuidCommandTestInfo {
 };
 
 static int
-testMdevctlUuidCommand(GetStopUndefineCmdFunc func,
+testMdevctlUuidCommand(virMdevctlCommand command,
                        const char *mdevxml, const char *outfile)
 {
     g_autoptr(virNodeDeviceDef) def = NULL;
@@ -136,7 +125,7 @@ testMdevctlUuidCommand(GetStopUndefineCmdFunc func,
     if (!(def = virNodeDeviceDefParseFile(mdevxml, EXISTING_DEVICE, "QEMU")))
         goto cleanup;
 
-    cmd = func(def, &errmsg);
+    cmd = nodeDeviceGetMdevctlCommand(def, command, NULL, &errmsg);
 
     if (!cmd)
         goto cleanup;
@@ -161,30 +150,16 @@ static int
 testMdevctlUuidCommandHelper(const void *data)
 {
     const struct UuidCommandTestInfo *info = data;
-    GetStopUndefineCmdFunc func;
-    const char *cmd;
+    const char *cmd = virMdevctlCommandTypeToString(info->command);
     g_autofree char *cmdlinefile = NULL;
     g_autofree char *mdevxml = NULL;
 
-    if (info->command == MDEVCTL_CMD_STOP) {
-        cmd = "stop";
-        func = nodeDeviceGetMdevctlStopCommand;
-    } else if (info->command == MDEVCTL_CMD_UNDEFINE) {
-        cmd = "undefine";
-        func = nodeDeviceGetMdevctlUndefineCommand;
-    }else if (info->command == MDEVCTL_CMD_START) {
-        cmd = "start";
-        func = nodeDeviceGetMdevctlStartCommand;
-    } else {
-        return -1;
-    }
-
     mdevxml = g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir,
                               info->filename);
     cmdlinefile = g_strdup_printf("%s/nodedevmdevctldata/mdevctl-%s.argv",
                                   abs_srcdir, cmd);
 
-    return testMdevctlUuidCommand(func, mdevxml, cmdlinefile);
+    return testMdevctlUuidCommand(info->command, mdevxml, cmdlinefile);
 }
 
 static int
-- 
2.26.3




More information about the libvir-list mailing list