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@xxxxxxxxxx> --- 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 0fddfdde86..76019b8631 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(virNodeDeviceDefPtr def, virMdevctlCommand cmd_type, char **outbuf, @@ -775,30 +775,15 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDefPtr 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(virNodeDeviceDefPtr 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(virNodeDeviceDefPtr 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, } -virCommandPtr -nodeDeviceGetMdevctlStopCommand(virNodeDeviceDefPtr def, - char **errmsg) -{ - return nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_STOP, NULL, errmsg); -} - -virCommand * -nodeDeviceGetMdevctlUndefineCommand(virNodeDeviceDefPtr 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(virNodeDeviceDefPtr 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 0fea75a118..482a5cfb3e 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -141,23 +141,11 @@ int nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr conn, int callbackID); -virCommandPtr -nodeDeviceGetMdevctlCreateCommand(virNodeDeviceDefPtr def, - char **uuid_out, - char **errmsg); - -virCommand* -nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDef *def, - char **uuid_out, - char **errmsg); - -virCommandPtr -nodeDeviceGetMdevctlStopCommand(virNodeDeviceDefPtr def, - char **errmsg); - virCommand * -nodeDeviceGetMdevctlUndefineCommand(virNodeDeviceDefPtr def, - char **errmsg); +nodeDeviceGetMdevctlCommand(virNodeDeviceDefPtr def, + virMdevctlCommand cmd_type, + char **outbuf, + char **errbuf); virCommandPtr nodeDeviceGetMdevctlListCommand(bool defined, @@ -180,10 +168,6 @@ nodeDeviceGenerateName(virNodeDeviceDef *def, bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, virNodeDeviceDef *src); -virCommand* -nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, - char **errmsg); - int nodeDeviceCreate(virNodeDevice *dev, unsigned int flags); diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index e766ae8f34..c467c798e7 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -53,7 +53,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) @@ -73,7 +73,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; @@ -103,22 +103,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", @@ -126,7 +115,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); } @@ -137,7 +126,7 @@ struct UuidCommandTestInfo { }; static int -testMdevctlUuidCommand(GetStopUndefineCmdFunc func, +testMdevctlUuidCommand(virMdevctlCommand command, const char *mdevxml, const char *outfile) { g_autoptr(virNodeDeviceDef) def = NULL; @@ -150,7 +139,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; @@ -176,30 +165,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