]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: add ability to list defined mdevs
authorJonathon Jongsma <jjongsma@redhat.com>
Fri, 10 Jul 2020 22:12:18 +0000 (17:12 -0500)
committerJonathon Jongsma <jjongsma@redhat.com>
Wed, 7 Apr 2021 20:07:35 +0000 (15:07 -0500)
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>
src/node_device/node_device_driver.c
src/node_device/node_device_driver.h
tests/nodedevmdevctldata/mdevctl-list-defined.argv [new file with mode: 0644]
tests/nodedevmdevctltest.c

index 7c9992cacaba235ea2d73d532de55d071e07fff7..65b683c4dc5db59a6b5855807b23b63ed278fff8 100644 (file)
@@ -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);
index f1c93f4b21b0cf192bd31d3a9974b46a6101f3e3..167e6bfa534598af1c6f4df1aedf3133d38d3834 100644 (file)
@@ -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);
diff --git a/tests/nodedevmdevctldata/mdevctl-list-defined.argv b/tests/nodedevmdevctldata/mdevctl-list-defined.argv
new file mode 100644 (file)
index 0000000..72b5906
--- /dev/null
@@ -0,0 +1 @@
+$MDEVCTL_BINARY$ list --dumpjson --defined
index 6c92d839d14ccbd1ea5547d0b636421c5fc8fa39..b3513fa940668a867ab6988aacfc1becfc81ebf6 100644 (file)
@@ -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: