mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
nodedev: add ability to list defined mdevs
This adds an internal API to query for persistent mediated devices that are defined by mdevctl. Upcoming commits will make use of this information. Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
58d093a55f
commit
066c13de66
@ -861,6 +861,26 @@ virMdevctlStop(virNodeDeviceDefPtr def, char **errmsg)
|
||||
}
|
||||
|
||||
|
||||
virCommand*
|
||||
nodeDeviceGetMdevctlListCommand(bool defined,
|
||||
char **output,
|
||||
char **errmsg)
|
||||
{
|
||||
virCommand *cmd = virCommandNewArgList(MDEVCTL,
|
||||
"list",
|
||||
"--dumpjson",
|
||||
NULL);
|
||||
|
||||
if (defined)
|
||||
virCommandAddArg(cmd, "--defined");
|
||||
|
||||
virCommandSetOutputBuffer(cmd, output);
|
||||
virCommandSetErrorBuffer(cmd, errmsg);
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
|
||||
static void mdevGenerateDeviceName(virNodeDeviceDef *dev)
|
||||
{
|
||||
nodeDeviceGenerateName(dev, "mdev", dev->caps->data.mdev.uuid, NULL);
|
||||
|
@ -121,6 +121,11 @@ virCommandPtr
|
||||
nodeDeviceGetMdevctlStopCommand(const char *uuid,
|
||||
char **errmsg);
|
||||
|
||||
virCommandPtr
|
||||
nodeDeviceGetMdevctlListCommand(bool defined,
|
||||
char **output,
|
||||
char **errmsg);
|
||||
|
||||
int
|
||||
nodeDeviceParseMdevctlJSON(const char *jsonstring,
|
||||
virNodeDeviceDef ***devs);
|
||||
|
1
tests/nodedevmdevctldata/mdevctl-list-defined.argv
Normal file
1
tests/nodedevmdevctldata/mdevctl-list-defined.argv
Normal file
@ -0,0 +1 @@
|
||||
$MDEVCTL_BINARY$ list --dumpjson --defined
|
@ -145,6 +145,41 @@ testMdevctlStop(const void *data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
testMdevctlListDefined(const void *data G_GNUC_UNUSED)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
const char *actualCmdline = NULL;
|
||||
int ret = -1;
|
||||
g_autoptr(virCommand) cmd = NULL;
|
||||
g_autofree char *output = NULL;
|
||||
g_autofree char *errmsg = NULL;
|
||||
g_autofree char *cmdlinefile =
|
||||
g_strdup_printf("%s/nodedevmdevctldata/mdevctl-list-defined.argv",
|
||||
abs_srcdir);
|
||||
|
||||
cmd = nodeDeviceGetMdevctlListCommand(true, &output, &errmsg);
|
||||
|
||||
if (!cmd)
|
||||
goto cleanup;
|
||||
|
||||
virCommandSetDryRun(&buf, NULL, NULL);
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(actualCmdline = virBufferCurrentContent(&buf)))
|
||||
goto cleanup;
|
||||
|
||||
if (nodedevCompareToFile(actualCmdline, cmdlinefile) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virBufferFreeAndReset(&buf);
|
||||
virCommandSetDryRun(NULL, NULL, NULL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
testMdevctlParse(const void *data)
|
||||
@ -328,6 +363,9 @@ mymain(void)
|
||||
#define DO_TEST_STOP(uuid) \
|
||||
DO_TEST_FULL("mdevctl stop " uuid, testMdevctlStop, uuid)
|
||||
|
||||
#define DO_TEST_LIST_DEFINED() \
|
||||
DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL)
|
||||
|
||||
#define DO_TEST_PARSE_JSON(filename) \
|
||||
DO_TEST_FULL("parse mdevctl json " filename, testMdevctlParse, filename)
|
||||
|
||||
@ -339,6 +377,8 @@ mymain(void)
|
||||
/* Test mdevctl stop command, pass an arbitrary uuid */
|
||||
DO_TEST_STOP("e2451f73-c95b-4124-b900-e008af37c576");
|
||||
|
||||
DO_TEST_LIST_DEFINED();
|
||||
|
||||
DO_TEST_PARSE_JSON("mdevctl-list-multiple");
|
||||
|
||||
done:
|
||||
|
Loading…
x
Reference in New Issue
Block a user