From: Erik Skultety <eskultet@xxxxxxxxxx> "start" in libvirt means - "take this object and create an instance out of it" "create" in libvirt most of the time means - "take and XML description, make an object out of it and use it to create an instance" This gets confusing with mdevctl which uses "start" for both. So, this patch proposes to use virMdevctlStart in cases where from libvirt's POV we're starting a defined device (unlike mdevctl). Analogically, use virMdevctlCreate in scenarios where XML description is passed to libvirt and a transient device is supposed to be created. Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx> Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx> --- src/node_device/node_device_driver.c | 34 ++++++------- src/node_device/node_device_driver.h | 10 ++-- ...9_36ea_4111_8f0a_8c9a70e21366-create.argv} | 0 ...9_36ea_4111_8f0a_8c9a70e21366-create.json} | 0 ...9_495e_4243_ad9f_beb3f14c23d9-create.argv} | 0 ...9_495e_4243_ad9f_beb3f14c23d9-create.json} | 0 ...6_1ca8_49ac_b176_871d16c13076-create.argv} | 0 ...6_1ca8_49ac_b176_871d16c13076-create.json} | 0 ...mdevctl-create.argv => mdevctl-start.argv} | 0 tests/nodedevmdevctltest.c | 49 +++++++++---------- 10 files changed, 46 insertions(+), 47 deletions(-) rename tests/nodedevmdevctldata/{mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-start.argv => mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-create.argv} (100%) rename tests/nodedevmdevctldata/{mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-start.json => mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-create.json} (100%) rename tests/nodedevmdevctldata/{mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-start.argv => mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-create.argv} (100%) rename tests/nodedevmdevctldata/{mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-start.json => mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-create.json} (100%) rename tests/nodedevmdevctldata/{mdev_fedc4916_1ca8_49ac_b176_871d16c13076-start.argv => mdev_fedc4916_1ca8_49ac_b176_871d16c13076-create.argv} (100%) rename tests/nodedevmdevctldata/{mdev_fedc4916_1ca8_49ac_b176_871d16c13076-start.json => mdev_fedc4916_1ca8_49ac_b176_871d16c13076-create.json} (100%) rename tests/nodedevmdevctldata/{mdevctl-create.argv => mdevctl-start.argv} (100%) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index 1d1eaa9561..dda118b0e5 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -699,10 +699,10 @@ nodeDeviceFindAddressByName(const char *name) * arguments, so provide a common implementation that can be wrapped by a more * specific function */ static virCommand* -nodeDeviceGetMdevctlDefineStartCommand(virNodeDeviceDef *def, - const char *subcommand, - char **uuid_out, - char **errmsg) +nodeDeviceGetMdevctlDefineCreateCommand(virNodeDeviceDef *def, + const char *subcommand, + char **uuid_out, + char **errmsg) { virCommand *cmd; g_autofree char *json = NULL; @@ -737,12 +737,12 @@ nodeDeviceGetMdevctlDefineStartCommand(virNodeDeviceDef *def, } virCommand* -nodeDeviceGetMdevctlStartCommand(virNodeDeviceDef *def, +nodeDeviceGetMdevctlCreateCommand(virNodeDeviceDef *def, char **uuid_out, char **errmsg) { - return nodeDeviceGetMdevctlDefineStartCommand(def, "start", uuid_out, - errmsg); + return nodeDeviceGetMdevctlDefineCreateCommand(def, "start", uuid_out, + errmsg); } virCommand* @@ -750,18 +750,18 @@ nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDef *def, char **uuid_out, char **errmsg) { - return nodeDeviceGetMdevctlDefineStartCommand(def, "define", uuid_out, - errmsg); + return nodeDeviceGetMdevctlDefineCreateCommand(def, "define", uuid_out, + errmsg); } static int -virMdevctlStart(virNodeDeviceDef *def, char **uuid, char **errmsg) +virMdevctlCreate(virNodeDeviceDef *def, char **uuid, char **errmsg) { int status; - g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlStartCommand(def, uuid, - errmsg); + g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlCreateCommand(def, uuid, + errmsg); if (!cmd) return -1; @@ -811,7 +811,7 @@ nodeDeviceCreateXMLMdev(virConnectPtr conn, return NULL; } - if (virMdevctlStart(def, &uuid, &errmsg) < 0) { + if (virMdevctlCreate(def, &uuid, &errmsg) < 0) { if (errmsg) virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to start mediated device '%s': %s"), @@ -910,7 +910,7 @@ nodeDeviceGetMdevctlUndefineCommand(const char *uuid, char **errmsg) } virCommand * -nodeDeviceGetMdevctlCreateCommand(const char *uuid, char **errmsg) +nodeDeviceGetMdevctlStartCommand(const char *uuid, char **errmsg) { virCommand *cmd = virCommandNewArgList(MDEVCTL, "start", @@ -953,12 +953,12 @@ virMdevctlUndefine(virNodeDeviceDef *def, char **errmsg) static int -virMdevctlCreate(virNodeDeviceDef *def, char **errmsg) +virMdevctlStart(virNodeDeviceDef *def, char **errmsg) { int status; g_autoptr(virCommand) cmd = NULL; - cmd = nodeDeviceGetMdevctlCreateCommand(def->caps->data.mdev.uuid, errmsg); + cmd = nodeDeviceGetMdevctlStartCommand(def->caps->data.mdev.uuid, errmsg); if (virCommandRun(cmd, &status) < 0 || status != 0) return -1; @@ -1412,7 +1412,7 @@ nodeDeviceCreate(virNodeDevice *device, if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { g_autofree char *errmsg = NULL; - if (virMdevctlCreate(def, &errmsg) < 0) { + if (virMdevctlStart(def, &errmsg) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to create mediated device: %s"), errmsg && errmsg[0] ? errmsg : "Unknown Error"); diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h index 5a64558f81..4101e34a8f 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -123,9 +123,9 @@ nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr conn, int callbackID); virCommand * -nodeDeviceGetMdevctlStartCommand(virNodeDeviceDef *def, - char **uuid_out, - char **errmsg); +nodeDeviceGetMdevctlCreateCommand(virNodeDeviceDef *def, + char **uuid_out, + char **errmsg); virCommand* nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDef *def, @@ -162,8 +162,8 @@ bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, virNodeDeviceDef *src); virCommand* -nodeDeviceGetMdevctlCreateCommand(const char *uuid, - char **errmsg); +nodeDeviceGetMdevctlStartCommand(const char *uuid, + char **errmsg); int nodeDeviceCreate(virNodeDevice *dev, diff --git a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-start.argv b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-create.argv similarity index 100% rename from tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-start.argv rename to tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-create.argv diff --git a/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-start.json b/tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-create.json similarity index 100% rename from tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-start.json rename to tests/nodedevmdevctldata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366-create.json diff --git a/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-start.argv b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-create.argv similarity index 100% rename from tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-start.argv rename to tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-create.argv diff --git a/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-start.json b/tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-create.json similarity index 100% rename from tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-start.json rename to tests/nodedevmdevctldata/mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9-create.json diff --git a/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-start.argv b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-create.argv similarity index 100% rename from tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-start.argv rename to tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-create.argv diff --git a/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-start.json b/tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-create.json similarity index 100% rename from tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-start.json rename to tests/nodedevmdevctldata/mdev_fedc4916_1ca8_49ac_b176_871d16c13076-create.json diff --git a/tests/nodedevmdevctldata/mdevctl-create.argv b/tests/nodedevmdevctldata/mdevctl-start.argv similarity index 100% rename from tests/nodedevmdevctldata/mdevctl-create.argv rename to tests/nodedevmdevctldata/mdevctl-start.argv diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index df4185b5f8..188e521f59 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -44,12 +44,12 @@ typedef virCommand* (*MdevctlCmdFunc)(virNodeDeviceDef *, char **, char **); static int -testMdevctlStartOrDefine(const char *virt_type, - int create, - MdevctlCmdFunc mdevctl_cmd_func, - const char *mdevxml, - const char *cmdfile, - const char *jsonfile) +testMdevctlCreateOrDefine(const char *virt_type, + int create, + MdevctlCmdFunc mdevctl_cmd_func, + const char *mdevxml, + const char *cmdfile, + const char *jsonfile) { g_autoptr(virNodeDeviceDef) def = NULL; virNodeDeviceObj *obj = NULL; @@ -93,7 +93,7 @@ testMdevctlStartOrDefine(const char *virt_type, } static int -testMdevctlStartOrDefineHelper(const void *data) +testMdevctlCreateOrDefineHelper(const void *data) { const struct startTestInfo *info = data; const char *cmd; @@ -102,9 +102,9 @@ testMdevctlStartOrDefineHelper(const void *data) g_autofree char *cmdlinefile = NULL; g_autofree char *jsonfile = NULL; - if (info->command == MDEVCTL_CMD_START) { - cmd = "start"; - func = nodeDeviceGetMdevctlStartCommand; + if (info->command == MDEVCTL_CMD_CREATE) { + cmd = "create"; + func = nodeDeviceGetMdevctlCreateCommand; } else if (info->command == MDEVCTL_CMD_DEFINE) { cmd = "define"; func = nodeDeviceGetMdevctlDefineCommand; @@ -119,8 +119,8 @@ testMdevctlStartOrDefineHelper(const void *data) jsonfile = g_strdup_printf("%s/nodedevmdevctldata/%s-%s.json", abs_srcdir, info->filename, cmd); - return testMdevctlStartOrDefine(info->virt_type, info->create, func, - mdevxml, cmdlinefile, jsonfile); + return testMdevctlCreateOrDefine(info->virt_type, info->create, func, + mdevxml, cmdlinefile, jsonfile); } typedef virCommand* (*GetStopUndefineCmdFunc)(const char *uuid, char **errbuf); @@ -180,9 +180,9 @@ testMdevctlUuidCommandHelper(const void *data) } else if (info->command == MDEVCTL_CMD_UNDEFINE) { cmd = "undefine"; func = nodeDeviceGetMdevctlUndefineCommand; - }else if (info->command == MDEVCTL_CMD_CREATE) { - cmd = "create"; - func = nodeDeviceGetMdevctlCreateCommand; + }else if (info->command == MDEVCTL_CMD_START) { + cmd = "start"; + func = nodeDeviceGetMdevctlStartCommand; } else { return -1; } @@ -403,12 +403,12 @@ mymain(void) #define DO_TEST_CMD(desc, virt_type, create, filename, command) \ do { \ struct startTestInfo info = { virt_type, create, filename, command }; \ - DO_TEST_FULL(desc, testMdevctlStartOrDefineHelper, &info); \ + DO_TEST_FULL(desc, testMdevctlCreateOrDefineHelper, &info); \ } \ while (0) -#define DO_TEST_START(filename) \ - DO_TEST_CMD("mdevctl start " filename, "QEMU", CREATE_DEVICE, filename, MDEVCTL_CMD_START) +#define DO_TEST_CREATE(filename) \ + DO_TEST_CMD("mdevctl create " filename, "QEMU", CREATE_DEVICE, filename, MDEVCTL_CMD_CREATE) #define DO_TEST_DEFINE(filename) \ DO_TEST_CMD("mdevctl define " filename, "QEMU", CREATE_DEVICE, filename, MDEVCTL_CMD_DEFINE) @@ -426,8 +426,8 @@ mymain(void) #define DO_TEST_UNDEFINE(filename) \ DO_TEST_UUID_COMMAND_FULL("mdevctl undefine " filename, filename, MDEVCTL_CMD_UNDEFINE) -#define DO_TEST_CREATE(filename) \ - DO_TEST_UUID_COMMAND_FULL("mdevctl create " filename, filename, MDEVCTL_CMD_CREATE) +#define DO_TEST_START(filename) \ + DO_TEST_UUID_COMMAND_FULL("mdevctl start " filename, filename, MDEVCTL_CMD_START) #define DO_TEST_LIST_DEFINED() \ DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL) @@ -435,10 +435,9 @@ mymain(void) #define DO_TEST_PARSE_JSON(filename) \ DO_TEST_FULL("parse mdevctl json " filename, testMdevctlParse, filename) - /* Test mdevctl start commands */ - DO_TEST_START("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); - DO_TEST_START("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); - DO_TEST_START("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); + DO_TEST_CREATE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); + DO_TEST_CREATE("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); + DO_TEST_CREATE("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); /* Test mdevctl stop command, pass an arbitrary uuid */ DO_TEST_STOP("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); @@ -453,7 +452,7 @@ mymain(void) DO_TEST_UNDEFINE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); - DO_TEST_CREATE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); + DO_TEST_START("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); done: nodedevTestDriverFree(driver); -- 2.26.3