1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-20 18:03:50 +03:00

nodedev: reset active config data on udev remove event

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.

Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
This commit is contained in:
Boris Fiuczynski 2024-04-23 20:08:50 +02:00 committed by Jonathon Jongsma
parent 23df65de2f
commit 0f87a53a0a
7 changed files with 45 additions and 8 deletions

View File

@ -2581,15 +2581,9 @@ virNodeDevCapsDefFree(virNodeDevCapsDef *caps)
g_free(data->sg.path);
break;
case VIR_NODE_DEV_CAP_MDEV:
g_free(data->mdev.defined_config.type);
g_free(data->mdev.active_config.type);
g_free(data->mdev.uuid);
for (i = 0; i < data->mdev.defined_config.nattributes; i++)
virMediatedDeviceAttrFree(data->mdev.defined_config.attributes[i]);
g_free(data->mdev.defined_config.attributes);
for (i = 0; i < data->mdev.active_config.nattributes; i++)
virMediatedDeviceAttrFree(data->mdev.active_config.attributes[i]);
g_free(data->mdev.active_config.attributes);
virMediatedDeviceConfigClear(&data->mdev.defined_config);
virMediatedDeviceConfigClear(&data->mdev.active_config);
g_free(data->mdev.parent_addr);
break;
case VIR_NODE_DEV_CAP_CSS_DEV:

View File

@ -2765,6 +2765,8 @@ virMacMapWriteFile;
# util/virmdev.h
virMediatedDeviceAttrFree;
virMediatedDeviceAttrNew;
virMediatedDeviceConfigClear;
virMediatedDeviceConfigFree;
virMediatedDeviceFree;
virMediatedDeviceGetIOMMUGroupDev;
virMediatedDeviceGetIOMMUGroupNum;

View File

@ -2016,6 +2016,19 @@ 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)
{
if (def->caps->data.type != VIR_NODE_DEV_CAP_MDEV)
return;
virMediatedDeviceConfigClear(&def->caps->data.mdev.active_config);
}
int
nodeDeviceSetAutostart(virNodeDevice *device,
int autostart)

View File

@ -197,3 +197,6 @@ int
nodeDeviceUpdate(virNodeDevice *dev,
const char *xmlDesc,
unsigned int flags);
void
nodeDeviceDefResetMdevActiveConfig(virNodeDeviceDef *def);

View File

@ -1464,6 +1464,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);

View File

@ -516,6 +516,26 @@ void virMediatedDeviceAttrFree(virMediatedDeviceAttr *attr)
g_free(attr);
}
void virMediatedDeviceConfigFree(virMediatedDeviceConfig *config)
{
if (!config)
return;
virMediatedDeviceConfigClear(config);
g_free(config);
}
void virMediatedDeviceConfigClear(virMediatedDeviceConfig *config)
{
size_t i = 0;
g_clear_pointer(&config->type, g_free);
for (i = 0; i < config->nattributes; i++)
virMediatedDeviceAttrFree(config->attributes[i]);
config->nattributes = 0;
g_clear_pointer(&config->attributes, g_free);
}
#define MDEV_BUS_DIR "/sys/class/mdev_bus"

View File

@ -54,6 +54,10 @@ struct _virMediatedDeviceConfig {
size_t nattributes;
};
void virMediatedDeviceConfigClear(virMediatedDeviceConfig *config);
void virMediatedDeviceConfigFree(virMediatedDeviceConfig *config);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceConfig, virMediatedDeviceConfigFree);
typedef struct _virMediatedDeviceType virMediatedDeviceType;
struct _virMediatedDeviceType {
char *id;