]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: Remove GetMdevctl*Command() wrappers
authorJonathon Jongsma <jjongsma@redhat.com>
Wed, 31 Mar 2021 22:03:08 +0000 (17:03 -0500)
committerJonathon Jongsma <jjongsma@redhat.com>
Mon, 19 Apr 2021 15:24:13 +0000 (10:24 -0500)
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@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
src/node_device/node_device_driver.c
src/node_device/node_device_driver.h
tests/nodedevmdevctltest.c

index 7f99cd6b68f4e40fbb8e9ccd241d7dc3324d5472..b0cc63ed42223414de488765bda52922e3cfe90c 100644 (file)
@@ -717,7 +717,7 @@ nodeDeviceFindAddressByName(const char *name)
 }
 
 
-static virCommand *
+virCommand *
 nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def,
                             virMdevctlCommand cmd_type,
                             char **outbuf,
@@ -790,30 +790,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;
 
@@ -833,7 +818,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;
@@ -936,34 +923,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;
@@ -978,7 +944,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;
@@ -993,7 +959,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;
index 105a71dd9336f111d5f4d9fddbeae655321e4ff8..edd763f0e40b6b8e9a1ff923f98b3009df2a9de5 100644 (file)
@@ -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);
index 188bad6e5372b38c4a2106020ddb4de5cb6235f7..64ce7fec46d8a04a7934dabbe03a4ab5da52ac7c 100644 (file)
@@ -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