Since we already have a function that will generate the drivestr from the alias, let's use it and remove the qemuDeviceDriveHostAlias. Move the QEMU_DRIVE_HOST_PREFIX definition into qemu_alias.h. Also alter qemuAliasFromDisk to use the QEMU_DRIVE_HOST_PREFIX instead of "drive-%s". Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/qemu/qemu_alias.c | 13 +++++++++++-- src/qemu/qemu_alias.h | 2 ++ src/qemu/qemu_command.c | 11 ----------- src/qemu/qemu_command.h | 1 - src/qemu/qemu_hotplug.c | 4 ++-- src/qemu/qemu_migration.c | 2 +- src/qemu/qemu_monitor_json.c | 2 +- src/qemu/qemu_monitor_text.c | 2 +- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 51a654a..f263586 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -451,17 +451,26 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) } +/* qemuAliasFromDisk + * @disk: Pointer to a disk definition + * + * Generate and return an alias for the device disk '-drive' + * + * Returns NULL with error or a string containing the alias + */ char * qemuAliasFromDisk(const virDomainDiskDef *disk) { char *ret; if (!disk->info.alias) { - virReportError(VIR_ERR_INVALID_ARG, "%s", _("disk does not have an alias")); + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("disk does not have an alias")); return NULL; } - ignore_value(virAsprintf(&ret, "drive-%s", disk->info.alias)); + ignore_value(virAsprintf(&ret, "%s%s", QEMU_DRIVE_HOST_PREFIX, + disk->info.alias)); return ret; } diff --git a/src/qemu/qemu_alias.h b/src/qemu/qemu_alias.h index d1c6ba8..5202f73 100644 --- a/src/qemu/qemu_alias.h +++ b/src/qemu/qemu_alias.h @@ -30,6 +30,8 @@ # include "qemu_domain.h" # include "qemu_domain_address.h" +# define QEMU_DRIVE_HOST_PREFIX "drive-" + int qemuAssignDeviceChrAlias(virDomainDefPtr def, virDomainChrDefPtr chr, ssize_t idx); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 5325f48..5141612 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -272,17 +272,6 @@ qemuVirCommandGetDevSet(virCommandPtr cmd, int fd) } -char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk) -{ - char *ret; - - if (virAsprintf(&ret, "%s%s", - QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0) - return NULL; - return ret; -} - - static int qemuBuildDeviceAddressStr(virBufferPtr buf, const virDomainDef *domainDef, diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index c4d0567..dcf9ba6 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -37,7 +37,6 @@ /* Config type for XML import/export conversions */ # define QEMU_CONFIG_FORMAT_ARGV "qemu-argv" -# define QEMU_DRIVE_HOST_PREFIX "drive-" # define QEMU_FSDEV_HOST_PREFIX "fsdev-" # define QEMU_BLOCK_IOTUNE_MAX 1000000000000000LL diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index fd365de..356741f 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -229,7 +229,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, if (qemuDomainPrepareDisk(driver, vm, disk, newsrc, false) < 0) goto cleanup; - if (!(driveAlias = qemuDeviceDriveHostAlias(disk))) + if (!(driveAlias = qemuAliasFromDisk(disk))) goto error; qemuDomainObjEnterMonitor(driver, vm); @@ -369,7 +369,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn, if (!(drivestr = qemuBuildDriveStr(disk, false, priv->qemuCaps))) goto error; - if (!(drivealias = qemuDeviceDriveHostAlias(disk))) + if (!(drivealias = qemuAliasFromDisk(disk))) goto error; if (!(devstr = qemuBuildDriveDevStr(vm->def, disk, 0, priv->qemuCaps))) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 463e624..04c847e 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -36,7 +36,7 @@ #include "qemu_domain.h" #include "qemu_process.h" #include "qemu_capabilities.h" -#include "qemu_command.h" +#include "qemu_alias.h" #include "qemu_cgroup.h" #include "qemu_hotplug.h" #include "qemu_blockjob.h" diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index a415e59..2995264 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -33,7 +33,7 @@ #include "qemu_monitor_text.h" #include "qemu_monitor_json.h" -#include "qemu_command.h" +#include "qemu_alias.h" #include "qemu_parse_command.h" #include "qemu_capabilities.h" #include "viralloc.h" diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 00310d9..cf2979d 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -31,7 +31,7 @@ #include <string.h> #include "qemu_monitor_text.h" -#include "qemu_command.h" +#include "qemu_alias.h" #include "c-ctype.h" #include "c-strcasestr.h" #include "viralloc.h" -- 2.7.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list