[PATCH 3/3] nodedev: reset active config data on udev remove event

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

 



When a mdev device is destroyed or stopped the udev remove event
handling needs to reset the active config data of the node object
representing a persisted mdev.

Signed-off-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx>
---
 src/node_device/node_device_driver.c | 22 ++++++++++++++++++++++
 src/node_device/node_device_driver.h |  3 +++
 src/node_device/node_device_udev.c   |  1 +
 3 files changed, 26 insertions(+)

diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index d99b48138e..1d93106e29 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -2018,6 +2018,28 @@ nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst,
 }
 
 
+/* A mediated device definition contains data from mdevctl about the active
+ * device. When the device is deactivated the active configuration data needs
+ * to be removed. */
+void
+nodeDeviceDefResetMdevActiveConfig(virNodeDeviceDef *def)
+{
+    size_t i = 0;
+    virMediatedDeviceConfig *active_config;
+
+    if (def->caps->data.type != VIR_NODE_DEV_CAP_MDEV)
+        return;
+
+    active_config = &def->caps->data.mdev.active_config;
+
+    g_clear_pointer(&active_config->type, g_free);
+    for (i = 0; i < active_config->nattributes; i++)
+        virMediatedDeviceAttrFree(active_config->attributes[i]);
+    g_clear_pointer(&active_config->attributes, g_free);
+    active_config->nattributes = 0;
+}
+
+
 int
 nodeDeviceSetAutostart(virNodeDevice *device,
                        int autostart)
diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h
index b3bc4b2e96..f195cfef9d 100644
--- a/src/node_device/node_device_driver.h
+++ b/src/node_device/node_device_driver.h
@@ -197,3 +197,6 @@ int
 nodeDeviceUpdate(virNodeDevice *dev,
                  const char *xmlDesc,
                  unsigned int flags);
+
+void
+nodeDeviceDefResetMdevActiveConfig(virNodeDeviceDef *def);
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 0f335df950..93d0dcedbc 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1467,6 +1467,7 @@ udevRemoveOneDeviceSysPath(const char *path)
     if (virNodeDeviceObjIsPersistent(obj)) {
         VIR_FREE(def->sysfs_path);
         virNodeDeviceObjSetActive(obj, false);
+        nodeDeviceDefResetMdevActiveConfig(def);
     } else {
         VIR_DEBUG("Removing device '%s' with sysfs path '%s'",
                   def->name, path);
-- 
2.42.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[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