On 3/20/24 10:46 AM, Boris Fiuczynski wrote:
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(a)linux.ibm.com>
---
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;
+}
+
+
A good portion of this function is duplicating code that exists in
virNodeDevCapsDefFree(). Let's just factor that code out into a
virMediatedDeviceConfigClear() function and then use it from both locations.
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);