nodedev: driver: Swap virMdevctlStart and virMdevctlCreate

"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). Similarly, 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@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Erik Skultety 2021-03-31 15:32:44 +02:00 committed by Jonathon Jongsma
parent 94589d1dc8
commit 963888f288
10 changed files with 46 additions and 47 deletions

View File

@ -714,10 +714,10 @@ nodeDeviceFindAddressByName(const char *name)
* arguments, so provide a common implementation that can be wrapped by a more * arguments, so provide a common implementation that can be wrapped by a more
* specific function */ * specific function */
static virCommand* static virCommand*
nodeDeviceGetMdevctlDefineStartCommand(virNodeDeviceDef *def, nodeDeviceGetMdevctlDefineCreateCommand(virNodeDeviceDef *def,
const char *subcommand, const char *subcommand,
char **uuid_out, char **uuid_out,
char **errmsg) char **errmsg)
{ {
virCommand *cmd; virCommand *cmd;
g_autofree char *json = NULL; g_autofree char *json = NULL;
@ -752,12 +752,12 @@ nodeDeviceGetMdevctlDefineStartCommand(virNodeDeviceDef *def,
} }
virCommand* virCommand*
nodeDeviceGetMdevctlStartCommand(virNodeDeviceDef *def, nodeDeviceGetMdevctlCreateCommand(virNodeDeviceDef *def,
char **uuid_out, char **uuid_out,
char **errmsg) char **errmsg)
{ {
return nodeDeviceGetMdevctlDefineStartCommand(def, "start", uuid_out, return nodeDeviceGetMdevctlDefineCreateCommand(def, "start", uuid_out,
errmsg); errmsg);
} }
virCommand* virCommand*
@ -765,18 +765,18 @@ nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDef *def,
char **uuid_out, char **uuid_out,
char **errmsg) char **errmsg)
{ {
return nodeDeviceGetMdevctlDefineStartCommand(def, "define", uuid_out, return nodeDeviceGetMdevctlDefineCreateCommand(def, "define", uuid_out,
errmsg); errmsg);
} }
static int static int
virMdevctlStart(virNodeDeviceDef *def, char **uuid, char **errmsg) virMdevctlCreate(virNodeDeviceDef *def, char **uuid, char **errmsg)
{ {
int status; int status;
g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlStartCommand(def, uuid, g_autoptr(virCommand) cmd = nodeDeviceGetMdevctlCreateCommand(def, uuid,
errmsg); errmsg);
if (!cmd) if (!cmd)
return -1; return -1;
@ -826,7 +826,7 @@ nodeDeviceCreateXMLMdev(virConnectPtr conn,
return NULL; return NULL;
} }
if (virMdevctlStart(def, &uuid, &errmsg) < 0) { if (virMdevctlCreate(def, &uuid, &errmsg) < 0) {
if (errmsg) if (errmsg)
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to start mediated device '%s': %s"), _("Unable to start mediated device '%s': %s"),
@ -925,7 +925,7 @@ nodeDeviceGetMdevctlUndefineCommand(const char *uuid, char **errmsg)
} }
virCommand * virCommand *
nodeDeviceGetMdevctlCreateCommand(const char *uuid, char **errmsg) nodeDeviceGetMdevctlStartCommand(const char *uuid, char **errmsg)
{ {
virCommand *cmd = virCommandNewArgList(MDEVCTL, virCommand *cmd = virCommandNewArgList(MDEVCTL,
"start", "start",
@ -968,12 +968,12 @@ virMdevctlUndefine(virNodeDeviceDef *def, char **errmsg)
static int static int
virMdevctlCreate(virNodeDeviceDef *def, char **errmsg) virMdevctlStart(virNodeDeviceDef *def, char **errmsg)
{ {
int status; int status;
g_autoptr(virCommand) cmd = NULL; 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) if (virCommandRun(cmd, &status) < 0 || status != 0)
return -1; return -1;
@ -1435,7 +1435,7 @@ nodeDeviceCreate(virNodeDevice *device,
if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) {
g_autofree char *errmsg = NULL; g_autofree char *errmsg = NULL;
if (virMdevctlCreate(def, &errmsg) < 0) { if (virMdevctlStart(def, &errmsg) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to create mediated device: %s"), _("Unable to create mediated device: %s"),
errmsg && errmsg[0] ? errmsg : "Unknown Error"); errmsg && errmsg[0] ? errmsg : "Unknown Error");

View File

@ -123,9 +123,9 @@ nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr conn,
int callbackID); int callbackID);
virCommand * virCommand *
nodeDeviceGetMdevctlStartCommand(virNodeDeviceDef *def, nodeDeviceGetMdevctlCreateCommand(virNodeDeviceDef *def,
char **uuid_out, char **uuid_out,
char **errmsg); char **errmsg);
virCommand* virCommand*
nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDef *def, nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDef *def,
@ -162,8 +162,8 @@ bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst,
virNodeDeviceDef *src); virNodeDeviceDef *src);
virCommand* virCommand*
nodeDeviceGetMdevctlCreateCommand(const char *uuid, nodeDeviceGetMdevctlStartCommand(const char *uuid,
char **errmsg); char **errmsg);
int int
nodeDeviceCreate(virNodeDevice *dev, nodeDeviceCreate(virNodeDevice *dev,

View File

@ -44,12 +44,12 @@ typedef virCommand* (*MdevctlCmdFunc)(virNodeDeviceDef *, char **, char **);
static int static int
testMdevctlStartOrDefine(const char *virt_type, testMdevctlCreateOrDefine(const char *virt_type,
int create, int create,
MdevctlCmdFunc mdevctl_cmd_func, MdevctlCmdFunc mdevctl_cmd_func,
const char *mdevxml, const char *mdevxml,
const char *cmdfile, const char *cmdfile,
const char *jsonfile) const char *jsonfile)
{ {
g_autoptr(virNodeDeviceDef) def = NULL; g_autoptr(virNodeDeviceDef) def = NULL;
virNodeDeviceObj *obj = NULL; virNodeDeviceObj *obj = NULL;
@ -93,7 +93,7 @@ testMdevctlStartOrDefine(const char *virt_type,
} }
static int static int
testMdevctlStartOrDefineHelper(const void *data) testMdevctlCreateOrDefineHelper(const void *data)
{ {
const struct startTestInfo *info = data; const struct startTestInfo *info = data;
const char *cmd; const char *cmd;
@ -102,9 +102,9 @@ testMdevctlStartOrDefineHelper(const void *data)
g_autofree char *cmdlinefile = NULL; g_autofree char *cmdlinefile = NULL;
g_autofree char *jsonfile = NULL; g_autofree char *jsonfile = NULL;
if (info->command == MDEVCTL_CMD_START) { if (info->command == MDEVCTL_CMD_CREATE) {
cmd = "start"; cmd = "create";
func = nodeDeviceGetMdevctlStartCommand; func = nodeDeviceGetMdevctlCreateCommand;
} else if (info->command == MDEVCTL_CMD_DEFINE) { } else if (info->command == MDEVCTL_CMD_DEFINE) {
cmd = "define"; cmd = "define";
func = nodeDeviceGetMdevctlDefineCommand; func = nodeDeviceGetMdevctlDefineCommand;
@ -119,8 +119,8 @@ testMdevctlStartOrDefineHelper(const void *data)
jsonfile = g_strdup_printf("%s/nodedevmdevctldata/%s-%s.json", abs_srcdir, jsonfile = g_strdup_printf("%s/nodedevmdevctldata/%s-%s.json", abs_srcdir,
info->filename, cmd); info->filename, cmd);
return testMdevctlStartOrDefine(info->virt_type, info->create, func, return testMdevctlCreateOrDefine(info->virt_type, info->create, func,
mdevxml, cmdlinefile, jsonfile); mdevxml, cmdlinefile, jsonfile);
} }
typedef virCommand* (*GetStopUndefineCmdFunc)(const char *uuid, char **errbuf); typedef virCommand* (*GetStopUndefineCmdFunc)(const char *uuid, char **errbuf);
@ -180,9 +180,9 @@ testMdevctlUuidCommandHelper(const void *data)
} else if (info->command == MDEVCTL_CMD_UNDEFINE) { } else if (info->command == MDEVCTL_CMD_UNDEFINE) {
cmd = "undefine"; cmd = "undefine";
func = nodeDeviceGetMdevctlUndefineCommand; func = nodeDeviceGetMdevctlUndefineCommand;
}else if (info->command == MDEVCTL_CMD_CREATE) { }else if (info->command == MDEVCTL_CMD_START) {
cmd = "create"; cmd = "start";
func = nodeDeviceGetMdevctlCreateCommand; func = nodeDeviceGetMdevctlStartCommand;
} else { } else {
return -1; return -1;
} }
@ -403,12 +403,12 @@ mymain(void)
#define DO_TEST_CMD(desc, virt_type, create, filename, command) \ #define DO_TEST_CMD(desc, virt_type, create, filename, command) \
do { \ do { \
struct startTestInfo info = { virt_type, create, filename, command }; \ struct startTestInfo info = { virt_type, create, filename, command }; \
DO_TEST_FULL(desc, testMdevctlStartOrDefineHelper, &info); \ DO_TEST_FULL(desc, testMdevctlCreateOrDefineHelper, &info); \
} \ } \
while (0) while (0)
#define DO_TEST_START(filename) \ #define DO_TEST_CREATE(filename) \
DO_TEST_CMD("mdevctl start " filename, "QEMU", CREATE_DEVICE, filename, MDEVCTL_CMD_START) DO_TEST_CMD("mdevctl create " filename, "QEMU", CREATE_DEVICE, filename, MDEVCTL_CMD_CREATE)
#define DO_TEST_DEFINE(filename) \ #define DO_TEST_DEFINE(filename) \
DO_TEST_CMD("mdevctl define " filename, "QEMU", CREATE_DEVICE, filename, MDEVCTL_CMD_DEFINE) DO_TEST_CMD("mdevctl define " filename, "QEMU", CREATE_DEVICE, filename, MDEVCTL_CMD_DEFINE)
@ -426,8 +426,8 @@ mymain(void)
#define DO_TEST_UNDEFINE(filename) \ #define DO_TEST_UNDEFINE(filename) \
DO_TEST_UUID_COMMAND_FULL("mdevctl undefine " filename, filename, MDEVCTL_CMD_UNDEFINE) DO_TEST_UUID_COMMAND_FULL("mdevctl undefine " filename, filename, MDEVCTL_CMD_UNDEFINE)
#define DO_TEST_CREATE(filename) \ #define DO_TEST_START(filename) \
DO_TEST_UUID_COMMAND_FULL("mdevctl create " filename, filename, MDEVCTL_CMD_CREATE) DO_TEST_UUID_COMMAND_FULL("mdevctl start " filename, filename, MDEVCTL_CMD_START)
#define DO_TEST_LIST_DEFINED() \ #define DO_TEST_LIST_DEFINED() \
DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL) DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL)
@ -435,10 +435,9 @@ mymain(void)
#define DO_TEST_PARSE_JSON(filename) \ #define DO_TEST_PARSE_JSON(filename) \
DO_TEST_FULL("parse mdevctl json " filename, testMdevctlParse, filename) DO_TEST_FULL("parse mdevctl json " filename, testMdevctlParse, filename)
/* Test mdevctl start commands */ DO_TEST_CREATE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
DO_TEST_START("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); DO_TEST_CREATE("mdev_fedc4916_1ca8_49ac_b176_871d16c13076");
DO_TEST_START("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); DO_TEST_CREATE("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9");
DO_TEST_START("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9");
/* Test mdevctl stop command, pass an arbitrary uuid */ /* Test mdevctl stop command, pass an arbitrary uuid */
DO_TEST_STOP("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366"); 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_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: done:
nodedevTestDriverFree(driver); nodedevTestDriverFree(driver);