Move QEMU_DRIVE_HOST_PREFIX into the qemu_alias.c to disuade future
callers from using it. Create qemuAliasDeviceDiskDriveSkipPrefix 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.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_alias.c | 17 +++++++++++++++++
src/qemu/qemu_alias.h | 4 ++--
src/qemu/qemu_domain.c | 3 +--
src/qemu/qemu_monitor_json.c | 6 ++----
src/qemu/qemu_monitor_text.c | 8 +++-----
src/qemu/qemu_process.c | 3 +--
6 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index b4a6e52..c7ef45a 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -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");
@@ -188,6 +190,21 @@ qemuAssignDeviceDiskDriveAlias(const char *srcalias)
}
+/* qemuAliasDeviceDiskDriveSkipPrefix:
+ * @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 *
+qemuAliasDeviceDiskDriveSkipPrefix(const char *dev_name)
+{
+ if (STRPREFIX(dev_name, QEMU_DRIVE_HOST_PREFIX))
+ dev_name += strlen(QEMU_DRIVE_HOST_PREFIX);
+ return dev_name;
+}
+
+
/* Our custom -drive naming scheme used with id= */
int
qemuAssignDeviceDiskAlias(virDomainDefPtr def,
diff --git a/src/qemu/qemu_alias.h b/src/qemu/qemu_alias.h
index 972de55..31bab07 100644
--- a/src/qemu/qemu_alias.h
+++ b/src/qemu/qemu_alias.h
@@ -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);
@@ -42,6 +40,8 @@ int qemuAssignDeviceControllerAlias(virDomainDefPtr domainDef,
char *qemuAssignDeviceDiskDriveAlias(const char *srcalias);
+const char *qemuAliasDeviceDiskDriveSkipPrefix(const char *dev_name);
+
int qemuAssignDeviceDiskAlias(virDomainDefPtr vmdef,
virDomainDiskDefPtr def,
virQEMUCapsPtr qemuCaps);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index fd25669..3264b94 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4225,8 +4225,7 @@ qemuDomainStorageAlias(const char *device, int depth)
{
char *alias;
- if (STRPREFIX(device, QEMU_DRIVE_HOST_PREFIX))
- device += strlen(QEMU_DRIVE_HOST_PREFIX);
+ device = qemuAliasDeviceDiskDriveSkipPrefix(device);
if (!depth)
ignore_value(VIR_STRDUP(alias, device));
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 633fb2a..4be4c6e 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1796,8 +1796,7 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
goto cleanup;
}
- if (STRPREFIX(thisdev, QEMU_DRIVE_HOST_PREFIX))
- thisdev += strlen(QEMU_DRIVE_HOST_PREFIX);
+ thisdev = qemuAliasDeviceDiskDriveSkipPrefix(thisdev);
if (VIR_ALLOC(info) < 0)
goto cleanup;
@@ -4196,8 +4195,7 @@ qemuMonitorJSONParseBlockJobInfo(virHashTablePtr blockJobs,
_("entry was missing 'device'"));
return -1;
}
- if (STRPREFIX(device, QEMU_DRIVE_HOST_PREFIX))
- device += strlen(QEMU_DRIVE_HOST_PREFIX);
+ device = qemuAliasDeviceDiskDriveSkipPrefix(device);
if (VIR_ALLOC(info) < 0 ||
virHashAddEntry(blockJobs, device, info) < 0) {
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index ff92bb1..b924ce6 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -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 *)qemuAliasDeviceDiskDriveSkipPrefix(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 = qemuAliasDeviceDiskDriveSkipPrefix(dev_name);
if (!(values = virStringSplit(line, " ", 0)))
goto cleanup;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 63da600..a4adeac 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -354,8 +354,7 @@ qemuProcessFindDomainDiskByAlias(virDomainObjPtr vm,
{
size_t i;
- if (STRPREFIX(alias, QEMU_DRIVE_HOST_PREFIX))
- alias += strlen(QEMU_DRIVE_HOST_PREFIX);
+ alias = qemuAliasDeviceDiskDriveSkipPrefix(alias);
for (i = 0; i < vm->def->ndisks; i++) {
virDomainDiskDefPtr disk;
--
2.5.5