]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: add macro to handle command errors
authorJonathon Jongsma <jjongsma@redhat.com>
Tue, 22 Jun 2021 19:53:34 +0000 (14:53 -0500)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 1 Jul 2021 14:34:03 +0000 (16:34 +0200)
This macro will be utilized in the following patch. Since mdevctl
commands can fail with or without an error message, this macro makes it
easy to print a fallback error in the case that the error message is not
set.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
src/node_device/node_device_driver.c

index d13bae33f21c64f92f0cab53f1a1bf8f2649964a..46d0dbf4a94bb3d4ea3550930f32b8d6fb09c167 100644 (file)
@@ -57,6 +57,9 @@ VIR_ENUM_IMPL(virMdevctlCommand,
 );
 
 
+#define MDEVCTL_ERROR(msg) (msg && msg[0] != '\0' ? msg : _("Unknown error"))
+
+
 virDrvOpenStatus
 nodeConnectOpen(virConnectPtr conn,
                 virConnectAuthPtr auth G_GNUC_UNUSED,
@@ -1390,7 +1393,7 @@ nodeDeviceUndefine(virNodeDevice *device,
         if (virMdevctlUndefine(def, &errmsg) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Unable to undefine mediated device: %s"),
-                           errmsg && errmsg[0] ? errmsg : "Unknown Error");
+                           MDEVCTL_ERROR(errmsg));
             goto cleanup;
         }
         ret = 0;
@@ -1437,7 +1440,7 @@ nodeDeviceCreate(virNodeDevice *device,
         if (virMdevctlStart(def, &errmsg) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Unable to create mediated device: %s"),
-                           errmsg && errmsg[0] ? errmsg : "Unknown Error");
+                           MDEVCTL_ERROR(errmsg));
             goto cleanup;
         }
         ret = 0;