mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-04-01 20:05:19 +00:00
conf: give each hostdevdef a parent pointer
The parent can be any type of device. It defaults to type=none, and a NULL pointer. The intent is that if a hostdevdef is contained in the def for a higher level device (e.g. virDomainNetDef), hostdev->parent will point to the higher level device, and type will be set to that type of device. This way, during attach and detach of the device, parent can be checked, and appropriate callouts made to do higher level device initialization (e.g. setting MAC address). Also, although these hostdevs with parents will be added to a domain's hostdevs list, they will be treated slightly differently when traversing the list, e.g. virDomainHostdefDefFree for a hostdev that has a parent doesn't need to be called (and will be a NOP); it will simply be removed from the list (since the parent device object is in its own type-specific list, and will be freed from there).
This commit is contained in:
parent
5560170d04
commit
b973f920ee
@ -1328,7 +1328,11 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
|
||||
* such resource is the virDomainDeviceInfo.
|
||||
*/
|
||||
|
||||
virDomainDeviceInfoFree(def->info);
|
||||
/* If there is a parent device object, it will handle freeing
|
||||
* def->info.
|
||||
*/
|
||||
if (def->parent.type == VIR_DOMAIN_DEVICE_NONE)
|
||||
virDomainDeviceInfoFree(def->info);
|
||||
}
|
||||
|
||||
void virDomainHostdevDefFree(virDomainHostdevDefPtr def)
|
||||
@ -1339,7 +1343,11 @@ void virDomainHostdevDefFree(virDomainHostdevDefPtr def)
|
||||
/* free all subordinate objects */
|
||||
virDomainHostdevDefClear(def);
|
||||
|
||||
VIR_FREE(def);
|
||||
/* If there is a parent device object, it will handle freeing
|
||||
* the memory.
|
||||
*/
|
||||
if (def->parent.type == VIR_DOMAIN_DEVICE_NONE)
|
||||
VIR_FREE(def);
|
||||
}
|
||||
|
||||
void virDomainHubDefFree(virDomainHubDefPtr def)
|
||||
|
@ -356,6 +356,7 @@ enum virDomainHostdevSubsysType {
|
||||
|
||||
/* basic device for direct passthrough */
|
||||
struct _virDomainHostdevDef {
|
||||
virDomainDeviceDef parent; /* higher level Def containing this */
|
||||
int mode; /* enum virDomainHostdevMode */
|
||||
unsigned int managed : 1;
|
||||
union {
|
||||
|
Loading…
x
Reference in New Issue
Block a user