[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv2 1/9] conf: utility to return alias of a controller based on type/index



Because there are multiple potential reasons for an error, this
function logs any errors before returning NULL (since the caller won't
have the information needed to determine which was the reason for
failure).
---
(this was 05/13 in V1)

No diff from V1, already ACKed, included for continuity/clarity.


 src/conf/domain_conf.c   | 34 ++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h   |  3 +++
 src/libvirt_private.syms |  1 +
 3 files changed, 38 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d150582..4d3620e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12535,6 +12535,40 @@ virDomainControllerFind(virDomainDefPtr def,
     return -1;
 }
 
+
+const char *
+virDomainControllerAliasFind(virDomainDefPtr def,
+                             int type, int idx)
+{
+    int contIndex;
+    const char *contTypeStr = virDomainControllerTypeToString(type);
+
+    if (!contTypeStr) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unknown controller type %d"),
+                       type);
+        return NULL;
+    }
+
+    contIndex = virDomainControllerFind(def, type, idx);
+    if (contIndex < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Could not find %s controller with index %d "
+                         "required for device"),
+                       contTypeStr, idx);
+        return NULL;
+    }
+    if (!def->controllers[contIndex]->info.alias) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Device alias was not set for %s controller "
+                         "with index %d "),
+                       contTypeStr, idx);
+        return NULL;
+    }
+    return def->controllers[contIndex]->info.alias;
+}
+
+
 int
 virDomainControllerFindByType(virDomainDefPtr def,
                               int type)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 2cd105a7..2527ff4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2754,6 +2754,9 @@ int virDomainControllerFindByType(virDomainDefPtr def, int type);
 int virDomainControllerFindByPCIAddress(virDomainDefPtr def,
                                         virDevicePCIAddressPtr addr);
 virDomainControllerDefPtr virDomainControllerRemove(virDomainDefPtr def, size_t i);
+const char *virDomainControllerAliasFind(virDomainDefPtr def,
+                                         int type, int idx)
+    ATTRIBUTE_NONNULL(1);
 
 int virDomainLeaseIndex(virDomainDefPtr def,
                         virDomainLeaseDefPtr lease);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6e33f84..74847d7 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -181,6 +181,7 @@ virDomainClockBasisTypeToString;
 virDomainClockOffsetTypeFromString;
 virDomainClockOffsetTypeToString;
 virDomainConfigFile;
+virDomainControllerAliasFind;
 virDomainControllerDefFree;
 virDomainControllerFind;
 virDomainControllerFindByType;
-- 
2.1.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]