qemu: Make QEMU_DRIVE_HOST_PREFIX more private

Move QEMU_DRIVE_HOST_PREFIX into the qemu_alias.c to dissuade future
callers from using it. Create qemuAliasDiskDriveSkipPrefix in order
to handle the current consumers that desire to check if an alias has
the drive- prefix and "get beyond it" in order to get the disk alias.
This commit is contained in:
John Ferlan 2016-06-29 13:34:00 -04:00
parent f0f16c1e28
commit dd0dbe1d66
6 changed files with 26 additions and 15 deletions

View File

@ -29,6 +29,8 @@
#include "virstring.h"
#include "network/bridge_driver.h"
#define QEMU_DRIVE_HOST_PREFIX "drive-"
#define VIR_FROM_THIS VIR_FROM_QEMU
VIR_LOG_INIT("qemu.qemu_alias");
@ -476,6 +478,21 @@ qemuAliasFromDisk(const virDomainDiskDef *disk)
}
/* qemuAliasDiskDriveSkipPrefix:
* @dev_name: Pointer to a const char string
*
* If the QEMU_DRIVE_HOST_PREFIX exists in the input string, then
* increment the pointer and return it
*/
const char *
qemuAliasDiskDriveSkipPrefix(const char *dev_name)
{
if (STRPREFIX(dev_name, QEMU_DRIVE_HOST_PREFIX))
dev_name += strlen(QEMU_DRIVE_HOST_PREFIX);
return dev_name;
}
/* qemuDomainGetMasterKeyAlias:
*
* Generate and return the masterKey alias

View File

@ -30,8 +30,6 @@
# include "qemu_domain.h"
# include "qemu_domain_address.h"
# define QEMU_DRIVE_HOST_PREFIX "drive-"
int qemuAssignDeviceChrAlias(virDomainDefPtr def,
virDomainChrDefPtr chr,
ssize_t idx);
@ -69,6 +67,8 @@ int qemuDomainDeviceAliasIndex(const virDomainDeviceInfo *info,
char *qemuAliasFromDisk(const virDomainDiskDef *disk);
const char *qemuAliasDiskDriveSkipPrefix(const char *dev_name);
char *qemuDomainGetMasterKeyAlias(void);
char *qemuDomainGetSecretAESAlias(const char *srcalias,

View File

@ -4403,8 +4403,7 @@ qemuDomainStorageAlias(const char *device, int depth)
{
char *alias;
if (STRPREFIX(device, QEMU_DRIVE_HOST_PREFIX))
device += strlen(QEMU_DRIVE_HOST_PREFIX);
device = qemuAliasDiskDriveSkipPrefix(device);
if (!depth)
ignore_value(VIR_STRDUP(alias, device));

View File

@ -1800,8 +1800,7 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
goto cleanup;
}
if (STRPREFIX(thisdev, QEMU_DRIVE_HOST_PREFIX))
thisdev += strlen(QEMU_DRIVE_HOST_PREFIX);
thisdev = qemuAliasDiskDriveSkipPrefix(thisdev);
if (VIR_ALLOC(info) < 0)
goto cleanup;
@ -4195,8 +4194,7 @@ qemuMonitorJSONParseBlockJobInfo(virHashTablePtr blockJobs,
_("entry was missing 'device'"));
return -1;
}
if (STRPREFIX(device, QEMU_DRIVE_HOST_PREFIX))
device += strlen(QEMU_DRIVE_HOST_PREFIX);
device = qemuAliasDiskDriveSkipPrefix(device);
if (VIR_ALLOC(info) < 0 ||
virHashAddEntry(blockJobs, device, info) < 0) {

View File

@ -753,8 +753,7 @@ int qemuMonitorTextGetBlockInfo(qemuMonitorPtr mon,
p = reply;
while (*p) {
if (STRPREFIX(p, QEMU_DRIVE_HOST_PREFIX))
p += strlen(QEMU_DRIVE_HOST_PREFIX);
p = (char *)qemuAliasDiskDriveSkipPrefix(p);
eol = strchr(p, '\n');
if (!eol)
@ -839,7 +838,7 @@ qemuMonitorTextGetAllBlockStatsInfo(qemuMonitorPtr mon,
{
qemuBlockStatsPtr stats = NULL;
char *info = NULL;
char *dev_name;
const char *dev_name;
char **lines = NULL;
char **values = NULL;
char *line;
@ -901,8 +900,7 @@ qemuMonitorTextGetAllBlockStatsInfo(qemuMonitorPtr mon,
*line = '\0';
line += 2;
if (STRPREFIX(dev_name, QEMU_DRIVE_HOST_PREFIX))
dev_name += strlen(QEMU_DRIVE_HOST_PREFIX);
dev_name = qemuAliasDiskDriveSkipPrefix(dev_name);
if (!(values = virStringSplit(line, " ", 0)))
goto cleanup;

View File

@ -355,8 +355,7 @@ qemuProcessFindDomainDiskByAlias(virDomainObjPtr vm,
{
size_t i;
if (STRPREFIX(alias, QEMU_DRIVE_HOST_PREFIX))
alias += strlen(QEMU_DRIVE_HOST_PREFIX);
alias = qemuAliasDiskDriveSkipPrefix(alias);
for (i = 0; i < vm->def->ndisks; i++) {
virDomainDiskDefPtr disk;