[libvirt PATCH v4 06/25] nodedev: add ability to list defined mdevs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/node_device/node_device_driver.c          | 18 +++++++++
 src/node_device/node_device_driver.h          |  3 ++
 .../mdevctl-list-defined.argv                 |  1 +
 tests/nodedevmdevctltest.c                    | 39 +++++++++++++++++++
 4 files changed, 61 insertions(+)
 create mode 100644 tests/nodedevmdevctldata/mdevctl-list-defined.argv

diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index fc5ac1d27e..2778e41f97 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -853,6 +853,24 @@ virMdevctlStop(virNodeDeviceDefPtr def)
 }
 
 
+virCommandPtr
+nodeDeviceGetMdevctlListCommand(bool defined,
+                                char **output)
+{
+    virCommandPtr cmd = virCommandNewArgList(MDEVCTL,
+                                             "list",
+                                             "--dumpjson",
+                                             NULL);
+
+    if (defined)
+        virCommandAddArg(cmd, "--defined");
+
+    virCommandSetOutputBuffer(cmd, output);
+
+    return cmd;
+}
+
+
 static void mdevGenerateDeviceName(virNodeDeviceDefPtr dev)
 {
     nodeDeviceGenerateName(dev, "mdev", dev->caps->data.mdev.uuid, NULL);
diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h
index 2a162513c0..80ac7c5320 100644
--- a/src/node_device/node_device_driver.h
+++ b/src/node_device/node_device_driver.h
@@ -119,6 +119,9 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def,
 virCommandPtr
 nodeDeviceGetMdevctlStopCommand(const char *uuid);
 
+virCommandPtr
+nodeDeviceGetMdevctlListCommand(bool defined, char **output);
+
 int
 nodeDeviceParseMdevctlJSON(const char *jsonstring,
                            virNodeDeviceDefPtr **devs);
diff --git a/tests/nodedevmdevctldata/mdevctl-list-defined.argv b/tests/nodedevmdevctldata/mdevctl-list-defined.argv
new file mode 100644
index 0000000000..72b5906e9e
--- /dev/null
+++ b/tests/nodedevmdevctldata/mdevctl-list-defined.argv
@@ -0,0 +1 @@
+$MDEVCTL_BINARY$ list --dumpjson --defined
diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c
index 93f4e3252c..8bc464d59f 100644
--- a/tests/nodedevmdevctltest.c
+++ b/tests/nodedevmdevctltest.c
@@ -143,6 +143,40 @@ 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 *cmdlinefile =
+        g_strdup_printf("%s/nodedevmdevctldata/mdevctl-list-defined.argv",
+                        abs_srcdir);
+
+    cmd = nodeDeviceGetMdevctlListCommand(true, &output);
+
+    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)
@@ -326,6 +360,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)
 
@@ -337,6 +374,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:
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux