[libvirt PATCH v2 08/10] nodedev: add mdev support to virNodeDeviceDestroy()

Jonathon Jongsma jjongsma at redhat.com
Tue Jun 9 21:43:48 UTC 2020


Add the ability to destroy mdev node devices via the mdevctl utility.

Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
---
 src/node_device/node_device_driver.c | 46 ++++++++++++++++++++++++++++
 src/node_device/node_device_driver.h |  3 ++
 2 files changed, 49 insertions(+)

diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index dbc7eb4d1e..c956bb55fc 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -790,6 +790,45 @@ nodeDeviceCreateXML(virConnectPtr conn,
 }
 
 
+virCommandPtr
+nodeDeviceGetMdevctlStopCommand(const char *uuid,
+                                bool persist)
+{
+    g_autofree char *mdevctl = virFindFileInPath(MDEVCTL);
+    const char *subcommand;
+
+    if (!mdevctl)
+        return NULL;
+
+    if (persist)
+        subcommand = "undefine";
+    else
+        subcommand = "stop";
+
+    virCommandPtr cmd = virCommandNewArgList(mdevctl,
+                                             subcommand,
+                                             "-u",
+                                             uuid,
+                                             NULL);
+
+    return cmd;
+}
+
+static int
+virMdevctlStop(virNodeDeviceDefPtr def)
+{
+    int status;
+    g_autoptr(virCommand) cmd = NULL;
+
+    cmd = nodeDeviceGetMdevctlStopCommand(def->caps->data.mdev.uuid, false);
+
+    if (virCommandRun(cmd, &status) < 0 || status != 0)
+        return -1;
+
+    return 0;
+}
+
+
 int
 nodeDeviceDestroy(virNodeDevicePtr device)
 {
@@ -836,6 +875,13 @@ nodeDeviceDestroy(virNodeDevicePtr device)
         if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_DELETE) < 0)
             goto cleanup;
 
+        ret = 0;
+    } else if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) {
+        if (virMdevctlStop(def) < 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("Unable to stop mediated device"));
+            goto cleanup;
+        }
         ret = 0;
     } else {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h
index 576f75375f..794cb5dc1c 100644
--- a/src/node_device/node_device_driver.h
+++ b/src/node_device/node_device_driver.h
@@ -122,3 +122,6 @@ virCommandPtr
 nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def,
                                  bool persist,
                                  char **uuid_out);
+virCommandPtr
+nodeDeviceGetMdevctlStopCommand(const char *uuid,
+                                bool persist);
-- 
2.21.3




More information about the libvir-list mailing list