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

[libvirt] [PATCH] Fix usage of virReportSystemError



virReportSystemError is reserved for reporting system errors, calling it
with VIR_ERR_* error codes produces error messages that do not make any
sense, such as

    internal error: guest failed to start: Kernel doesn't support user
    namespace: Link has been severed

We should prohibit wrong usage with a syntax-check rule.

Signed-off-by: Jiri Denemark <jdenemar redhat com>
---
 cfg.mk                          |  5 +++++
 src/lxc/lxc_container.c         |  4 ++--
 src/openvz/openvz_conf.c        |  4 ++--
 src/qemu/qemu_migration.c       | 12 ++++++------
 src/util/virnetdevopenvswitch.c | 22 +++++++++++-----------
 src/util/virobject.c            |  4 ++--
 6 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index d829a3c..3f35479 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -983,6 +983,11 @@ sc_prohibit_devname:
 	halt='avoid using 'devname' as FreeBSD exports the symbol' \
 	  $(_sc_search_regexp)
 
+sc_prohibit_system_error_with_vir_err:
+	@prohibit='\bvirReportSystemError *\(VIR_ERR_' \
+	halt='do not use virReportSystemError with VIR_ERR_* error codes' \
+	  $(_sc_search_regexp)
+
 # We don't use this feature of maint.mk.
 prev_version_file = /dev/null
 
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 334a1df..3b08b86 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -2309,8 +2309,8 @@ int lxcContainerStart(virDomainDefPtr def,
             VIR_DEBUG("Enable user namespace");
             cflags |= CLONE_NEWUSER;
         } else {
-            virReportSystemError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                                 _("Kernel doesn't support user namespace"));
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Kernel doesn't support user namespace"));
             VIR_FREE(stack);
             return -1;
         }
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index edf37d0..4b918c0 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -405,8 +405,8 @@ openvzReadFSConf(virDomainDefPtr def,
             /* Ensure that we can multiply by 1024 without overflowing. */
             if (barrier > ULLONG_MAX / 1024 ||
                 limit > ULLONG_MAX / 1024) {
-                virReportSystemError(VIR_ERR_OVERFLOW, "%s",
-                                     _("Unable to parse quota"));
+                virReportError(VIR_ERR_OVERFLOW, "%s",
+                               _("Unable to parse quota"));
                 goto error;
             }
             fs->space_soft_limit = barrier * 1024; /* unit is bytes */
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index a1b1458..74cda96 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -369,9 +369,9 @@ qemuMigrationCookieNetworkAlloc(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
             case VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH:
                 if (virNetDevOpenvswitchGetMigrateData(&mig->net[i].portdata,
                                                        netptr->ifname) != 0) {
-                        virReportSystemError(VIR_ERR_INTERNAL_ERROR,
-                                             _("Unable to run command to get OVS port data for "
-                                             "interface %s"), netptr->ifname);
+                        virReportError(VIR_ERR_INTERNAL_ERROR,
+                                       _("Unable to run command to get OVS port data for "
+                                         "interface %s"), netptr->ifname);
                         goto error;
                 }
                 break;
@@ -2223,9 +2223,9 @@ qemuDomainMigrateOPDRelocate(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
         case VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH:
             if (virNetDevOpenvswitchSetMigrateData(cookie->network->net[i].portdata,
                                                    netptr->ifname) != 0) {
-                virReportSystemError(VIR_ERR_INTERNAL_ERROR,
-                                     _("Unable to run command to set OVS port data for "
-                                     "interface %s"), netptr->ifname);
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Unable to run command to set OVS port data for "
+                                 "interface %s"), netptr->ifname);
                 goto cleanup;
             }
             break;
diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c
index 8ea1def..e5c87bb 100644
--- a/src/util/virnetdevopenvswitch.c
+++ b/src/util/virnetdevopenvswitch.c
@@ -147,9 +147,9 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
     }
 
     if (virCommandRun(cmd, NULL) < 0) {
-        virReportSystemError(VIR_ERR_INTERNAL_ERROR,
-                             _("Unable to add port %s to OVS bridge %s"),
-                             ifname, brname);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to add port %s to OVS bridge %s"),
+                       ifname, brname);
         goto cleanup;
     }
 
@@ -181,8 +181,8 @@ int virNetDevOpenvswitchRemovePort(const char *brname ATTRIBUTE_UNUSED, const ch
     virCommandAddArgList(cmd, "--timeout=5", "--", "--if-exists", "del-port", ifname, NULL);
 
     if (virCommandRun(cmd, NULL) < 0) {
-        virReportSystemError(VIR_ERR_INTERNAL_ERROR,
-                             _("Unable to delete port %s from OVS"), ifname);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to delete port %s from OVS"), ifname);
         goto cleanup;
     }
 
@@ -213,9 +213,9 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname)
 
     /* Run the command */
     if (virCommandRun(cmd, NULL) < 0) {
-        virReportSystemError(VIR_ERR_INTERNAL_ERROR,
-                             _("Unable to run command to get OVS port data for "
-                             "interface %s"), ifname);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to run command to get OVS port data for "
+                         "interface %s"), ifname);
         goto cleanup;
     }
 
@@ -247,9 +247,9 @@ int virNetDevOpenvswitchSetMigrateData(char *migrate, const char *ifname)
 
     /* Run the command */
     if (virCommandRun(cmd, NULL) < 0) {
-        virReportSystemError(VIR_ERR_INTERNAL_ERROR,
-                             _("Unable to run command to set OVS port data for "
-                             "interface %s"), ifname);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to run command to set OVS port data for "
+                         "interface %s"), ifname);
         goto cleanup;
     }
 
diff --git a/src/util/virobject.c b/src/util/virobject.c
index 6cb84b4..9ccd310 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -220,8 +220,8 @@ void *virObjectLockableNew(virClassPtr klass)
         return NULL;
 
     if (virMutexInit(&obj->lock) < 0) {
-        virReportSystemError(VIR_ERR_INTERNAL_ERROR, "%s",
-                             _("Unable to initialize mutex"));
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Unable to initialize mutex"));
         virObjectUnref(obj);
         return NULL;
     }
-- 
2.1.3


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