mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
Add virDomainDefFindDevice for looking up a device by its alias
This commit is contained in:
parent
1f71de59f6
commit
ae951e724c
@ -18314,3 +18314,44 @@ virDomainDiskDefGenSecurityLabelDef(const char *model)
|
||||
|
||||
return seclabel;
|
||||
}
|
||||
|
||||
|
||||
typedef struct {
|
||||
const char *devAlias;
|
||||
virDomainDeviceDefPtr dev;
|
||||
} virDomainDefFindDeviceCallbackData;
|
||||
|
||||
static int
|
||||
virDomainDefFindDeviceCallback(virDomainDefPtr def ATTRIBUTE_UNUSED,
|
||||
virDomainDeviceDefPtr dev,
|
||||
virDomainDeviceInfoPtr info,
|
||||
void *opaque)
|
||||
{
|
||||
virDomainDefFindDeviceCallbackData *data = opaque;
|
||||
|
||||
if (STREQ_NULLABLE(info->alias, data->devAlias)) {
|
||||
*data->dev = *dev;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
virDomainDefFindDevice(virDomainDefPtr def,
|
||||
const char *devAlias,
|
||||
virDomainDeviceDefPtr dev)
|
||||
{
|
||||
virDomainDefFindDeviceCallbackData data = { devAlias, dev };
|
||||
|
||||
dev->type = VIR_DOMAIN_DEVICE_NONE;
|
||||
virDomainDeviceInfoIterateInternal(def, virDomainDefFindDeviceCallback,
|
||||
true, &data);
|
||||
|
||||
if (dev->type == VIR_DOMAIN_DEVICE_NONE) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("no device found with alias %s"), devAlias);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -2688,4 +2688,8 @@ virDomainDefMaybeAddController(virDomainDefPtr def,
|
||||
|
||||
char *virDomainDefGetDefaultEmulator(virDomainDefPtr def, virCapsPtr caps);
|
||||
|
||||
int virDomainDefFindDevice(virDomainDefPtr def,
|
||||
const char *devAlias,
|
||||
virDomainDeviceDefPtr dev);
|
||||
|
||||
#endif /* __DOMAIN_CONF_H */
|
||||
|
@ -154,6 +154,7 @@ virDomainDefClearDeviceAliases;
|
||||
virDomainDefClearPCIAddresses;
|
||||
virDomainDefCompatibleDevice;
|
||||
virDomainDefCopy;
|
||||
virDomainDefFindDevice;
|
||||
virDomainDefFormat;
|
||||
virDomainDefFormatInternal;
|
||||
virDomainDefFree;
|
||||
|
Loading…
Reference in New Issue
Block a user