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
* 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;
@ -752,12 +752,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*
@ -765,18 +765,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;
@ -826,7 +826,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"),
@ -925,7 +925,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",
@ -968,12 +968,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;
@ -1435,7 +1435,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");

View File

@ -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,

View File

@ -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);