[PATCH 2/3] Add sentinel for virErrorDomain enum

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

Add a VIR_ERR_DOMAIN_LAST sentinel for virErrorDomain and
replace the virErrorDomainName function by a VIR_ENUM_IMPL

In the process the naming of error domains is santized

* src/util/virterror.c: Use VIR_ENUM_IMPL for converting
  error domains to strings
* include/libvirt/virterror.h: Add VIR_ERR_DOMAIN_LAST
---
 include/libvirt/virterror.h |   13 +++
 src/util/virterror.c        |  219 +++++++++++++------------------------------
 2 files changed, 78 insertions(+), 154 deletions(-)

diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
index 7283207..0e0bc9c 100644
--- a/include/libvirt/virterror.h
+++ b/include/libvirt/virterror.h
@@ -43,51 +43,64 @@ typedef enum {
     VIR_FROM_XEND = 2,		/* Error at connection with xend daemon */
     VIR_FROM_XENSTORE = 3,	/* Error at connection with xen store */
     VIR_FROM_SEXPR = 4,		/* Error in the S-Expression code */
+
     VIR_FROM_XML = 5,		/* Error in the XML code */
     VIR_FROM_DOM = 6,		/* Error when operating on a domain */
     VIR_FROM_RPC = 7,		/* Error in the XML-RPC code */
     VIR_FROM_PROXY = 8,		/* Error in the proxy code; unused since
                                    0.8.6 */
     VIR_FROM_CONF = 9,		/* Error in the configuration file handling */
+
     VIR_FROM_QEMU = 10,		/* Error at the QEMU daemon */
     VIR_FROM_NET = 11,		/* Error when operating on a network */
     VIR_FROM_TEST = 12,		/* Error from test driver */
     VIR_FROM_REMOTE = 13,	/* Error from remote driver */
     VIR_FROM_OPENVZ = 14,	/* Error from OpenVZ driver */
+
     VIR_FROM_XENXM = 15,	/* Error at Xen XM layer */
     VIR_FROM_STATS_LINUX = 16,	/* Error in the Linux Stats code */
     VIR_FROM_LXC = 17,		/* Error from Linux Container driver */
     VIR_FROM_STORAGE = 18,	/* Error from storage driver */
     VIR_FROM_NETWORK = 19,	/* Error from network config */
+
     VIR_FROM_DOMAIN = 20,	/* Error from domain config */
     VIR_FROM_UML = 21,		/* Error at the UML driver */
     VIR_FROM_NODEDEV = 22,	/* Error from node device monitor */
     VIR_FROM_XEN_INOTIFY = 23,	/* Error from xen inotify layer */
     VIR_FROM_SECURITY = 24,	/* Error from security framework */
+
     VIR_FROM_VBOX = 25,		/* Error from VirtualBox driver */
     VIR_FROM_INTERFACE = 26,	/* Error when operating on an interface */
     VIR_FROM_ONE = 27,		/* The OpenNebula driver no longer exists.
                                    Retained for ABI/API compat only */
     VIR_FROM_ESX = 28,		/* Error from ESX driver */
     VIR_FROM_PHYP = 29,		/* Error from IBM power hypervisor */
+
     VIR_FROM_SECRET = 30,	/* Error from secret storage */
     VIR_FROM_CPU = 31,		/* Error from CPU driver */
     VIR_FROM_XENAPI = 32,	/* Error from XenAPI */
     VIR_FROM_NWFILTER = 33,	/* Error from network filter driver */
     VIR_FROM_HOOK = 34,		/* Error from Synchronous hooks */
+
     VIR_FROM_DOMAIN_SNAPSHOT = 35,/* Error from domain snapshot */
     VIR_FROM_AUDIT = 36,	/* Error from auditing subsystem */
     VIR_FROM_SYSINFO = 37,	/* Error from sysinfo/SMBIOS */
     VIR_FROM_STREAMS = 38,	/* Error from I/O streams */
     VIR_FROM_VMWARE = 39,	/* Error from VMware driver */
+
     VIR_FROM_EVENT = 40,	/* Error from event loop impl */
     VIR_FROM_LIBXL = 41,	/* Error from libxenlight driver */
     VIR_FROM_LOCKING = 42,	/* Error from lock manager */
     VIR_FROM_HYPERV = 43,	/* Error from Hyper-V driver */
     VIR_FROM_CAPABILITIES = 44, /* Error from capabilities */
+
     VIR_FROM_URI = 45,          /* Error from URI handling */
     VIR_FROM_AUTH = 46,         /* Error from auth handling */
     VIR_FROM_DBUS = 47,         /* Error from DBus */
+
+# ifdef VIR_ENUM_SENTINELS
+    VIR_ERR_DOMAIN_LAST
+# endif
 } virErrorDomain;
 
 
diff --git a/src/util/virterror.c b/src/util/virterror.c
index b1a5d2b..fa57833 100644
--- a/src/util/virterror.c
+++ b/src/util/virterror.c
@@ -40,156 +40,67 @@ static virLogPriority virErrorLevelPriority(virErrorLevel level) {
     return VIR_LOG_ERROR;
 }
 
-static const char *virErrorDomainName(virErrorDomain domain) {
-    const char *dom = "unknown";
-    switch (domain) {
-        case VIR_FROM_NONE:
-            dom = "";
-            break;
-        case VIR_FROM_XEN:
-            dom = "Xen ";
-            break;
-        case VIR_FROM_XENAPI:
-            dom = "XenAPI ";
-            break;
-        case VIR_FROM_LIBXL:
-            dom = "xenlight ";
-            break;
-        case VIR_FROM_XML:
-            dom = "XML ";
-            break;
-        case VIR_FROM_XEND:
-            dom = "Xen Daemon ";
-            break;
-        case VIR_FROM_XENSTORE:
-            dom = "Xen Store ";
-            break;
-        case VIR_FROM_XEN_INOTIFY:
-            dom = "Xen Inotify ";
-            break;
-        case VIR_FROM_DOM:
-            dom = "Domain ";
-            break;
-        case VIR_FROM_RPC:
-            dom = "RPC ";
-            break;
-        case VIR_FROM_QEMU:
-            dom = "QEMU ";
-            break;
-        case VIR_FROM_NET:
-            dom = "Network ";
-            break;
-        case VIR_FROM_TEST:
-            dom = "Test ";
-            break;
-        case VIR_FROM_REMOTE:
-            dom = "Remote ";
-            break;
-        case VIR_FROM_SEXPR:
-            dom = "S-Expr ";
-            break;
-        case VIR_FROM_PROXY:
-            dom = "PROXY ";
-            break;
-        case VIR_FROM_CONF:
-            dom = "Config ";
-            break;
-        case VIR_FROM_PHYP:
-            dom = "IBM power hypervisor ";
-            break;
-        case VIR_FROM_OPENVZ:
-            dom = "OpenVZ ";
-            break;
-        case VIR_FROM_VMWARE:
-            dom = "VMware ";
-            break;
-        case VIR_FROM_XENXM:
-            dom = "Xen XM ";
-            break;
-        case VIR_FROM_STATS_LINUX:
-            dom = "Linux Stats ";
-            break;
-        case VIR_FROM_LXC:
-            dom = "Linux Container ";
-            break;
-        case VIR_FROM_STORAGE:
-            dom = "Storage ";
-            break;
-        case VIR_FROM_NETWORK:
-            dom = "Network Config ";
-            break;
-        case VIR_FROM_DOMAIN:
-            dom = "Domain Config ";
-            break;
-        case VIR_FROM_NODEDEV:
-            dom = "Node Device ";
-            break;
-        case VIR_FROM_UML:
-            dom = "UML ";
-            break;
-        case VIR_FROM_SECURITY:
-            dom = "Security Labeling ";
-            break;
-        case VIR_FROM_VBOX:
-            dom = "VBOX ";
-            break;
-        case VIR_FROM_INTERFACE:
-            dom = "Interface ";
-            break;
-        case VIR_FROM_ONE:
-            dom = "ONE ";
-            break;
-        case VIR_FROM_ESX:
-            dom = "ESX ";
-            break;
-        case VIR_FROM_SECRET:
-            dom = "Secret Storage ";
-            break;
-        case VIR_FROM_CPU:
-            dom = "CPU ";
-            break;
-        case VIR_FROM_NWFILTER:
-            dom = "Network Filter ";
-            break;
-        case VIR_FROM_HOOK:
-            dom = "Sync Hook ";
-            break;
-        case VIR_FROM_DOMAIN_SNAPSHOT:
-            dom = "Domain Snapshot ";
-            break;
-        case VIR_FROM_AUDIT:
-            dom = "Audit ";
-            break;
-        case VIR_FROM_SYSINFO:
-            dom = "Sysinfo ";
-            break;
-        case VIR_FROM_STREAMS:
-            dom = "Streams ";
-            break;
-        case VIR_FROM_EVENT:
-            dom = "Events ";
-            break;
-        case VIR_FROM_LOCKING:
-            dom = "Locking ";
-            break;
-        case VIR_FROM_HYPERV:
-            dom = "Hyper-V ";
-            break;
-        case VIR_FROM_CAPABILITIES:
-            dom = "Capabilities ";
-            break;
-        case VIR_FROM_URI:
-            dom = "URI ";
-            break;
-        case VIR_FROM_AUTH:
-            dom = "Auth ";
-            break;
-        case VIR_FROM_DBUS:
-            dom = "DBus ";
-            break;
-    }
-    return dom;
-}
+
+VIR_ENUM_DECL(virErrorDomain)
+VIR_ENUM_IMPL(virErrorDomain, VIR_ERR_DOMAIN_LAST,
+              "", /* 0 */
+              "Xen Driver",
+              "Xen Daemon",
+              "Xen Store",
+              "S-Expression",
+
+              "XML Util", /* 5 */
+              "Domain",
+              "XML-RPC",
+              "Proxy Daemon",
+              "Config File",
+
+              "QEMU Driver", /* 10 */
+              "Network",
+              "Test Driver",
+              "Remote Driver",
+              "OpenVZ Driver",
+
+              "Xen XM Driver", /* 15 */
+              "Linux Statistics",
+              "LXC Driver",
+              "Storage Driver",
+              "Network Driver",
+
+              "Domain Config", /* 20 */
+              "User Mode Linux Driver",
+              "Node Device Driver",
+              "Xen Inotify Driver",
+              "Security Driver",
+
+              "VirtualBox Driver", /* 25 */
+              "Network Interface Driver",
+              "Open Nebula Driver",
+              "ESX Driver",
+              "Power Hypervisor Driver",
+
+              "Secrets Driver", /* 30 */
+              "CPU Driver",
+              "XenAPI Driver",
+              "Network Filter Driver",
+              "Lifecycle Hook",
+
+              "Domain Snapshot", /* 35 */
+              "Audit Utils",
+              "Sysinfo Utils",
+              "I/O Stream Utils",
+              "VMWare Driver",
+
+              "Event Loop", /* 40 */
+              "Xen Light Driver",
+              "Lock Driver",
+              "Hyper-V Driver",
+              "Capabilities Utils",
+
+              "URI Utils", /* 45 */
+              "Authentication Utils",
+              "DBus Utils"
+    )
 
 
 /*
@@ -585,7 +496,7 @@ virDefaultErrorFunc(virErrorPtr err)
             lvl = _("error");
             break;
     }
-    dom = virErrorDomainName(err->domain);
+    dom = virErrorDomainTypeToString(err->domain);
     if ((err->dom != NULL) && (err->code != VIR_ERR_INVALID_DOMAIN)) {
         domain = err->dom->name;
     } else if ((err->net != NULL) && (err->code != VIR_ERR_INVALID_NETWORK)) {
@@ -594,13 +505,13 @@ virDefaultErrorFunc(virErrorPtr err)
     len = strlen(err->message);
     if ((err->domain == VIR_FROM_XML) && (err->code == VIR_ERR_XML_DETAIL) &&
         (err->int1 != 0))
-        fprintf(stderr, "libvir: %s%s %s%s: line %d: %s",
+        fprintf(stderr, "libvir: %s %s %s%s: line %d: %s",
                 dom, lvl, domain, network, err->int1, err->message);
     else if ((len == 0) || (err->message[len - 1] != '\n'))
-        fprintf(stderr, "libvir: %s%s %s%s: %s\n",
+        fprintf(stderr, "libvir: %s %s %s%s: %s\n",
                 dom, lvl, domain, network, err->message);
     else
-        fprintf(stderr, "libvir: %s%s %s%s: %s",
+        fprintf(stderr, "libvir: %s %s %s%s: %s",
                 dom, lvl, domain, network, err->message);
 }
 
-- 
1.7.10.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]