From 647bc753d453dcf9ffafe95a3233cb4fbbffca5a Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Mon, 18 Jul 2016 13:19:02 -0400 Subject: [PATCH] qemu: Introduce qemuAliasFromHostdev Introduce a common API to generate the alias for a host device --- src/qemu/qemu_alias.c | 23 +++++++++++++++++++++++ src/qemu/qemu_alias.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 28260c92be..0102c96002 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -493,6 +493,29 @@ qemuAliasDiskDriveSkipPrefix(const char *dev_name) } +/* qemuAliasFromHostdev + * @hostdev: Pointer to host device + * + * Generate and return a string containing a drive alias + */ +char * +qemuAliasFromHostdev(const virDomainHostdevDef *hostdev) +{ + char *ret; + + if (!hostdev->info->alias) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("hostdev does not have an alias")); + return NULL; + } + + ignore_value(virAsprintf(&ret, "%s-%s", + virDomainDeviceAddressTypeToString(hostdev->info->type), + hostdev->info->alias)); + return ret; +} + + /* qemuDomainGetMasterKeyAlias: * * Generate and return the masterKey alias diff --git a/src/qemu/qemu_alias.h b/src/qemu/qemu_alias.h index 8f6d9a77f6..505c40ed6d 100644 --- a/src/qemu/qemu_alias.h +++ b/src/qemu/qemu_alias.h @@ -69,6 +69,8 @@ char *qemuAliasFromDisk(const virDomainDiskDef *disk); const char *qemuAliasDiskDriveSkipPrefix(const char *dev_name); +char *qemuAliasFromHostdev(const virDomainHostdevDef *hostdev); + char *qemuDomainGetMasterKeyAlias(void); char *qemuDomainGetSecretAESAlias(const char *srcalias,