[PATCH 25/32] node_device_udev: switch to using virReportError

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

 



Also use the more common "Unable to initialize mutex" string
and virReportSystemError instead of virStrerror.
---
 src/node_device/node_device_udev.c | 47 +++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 19 deletions(-)

diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 54eb319..8307b80 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -105,7 +105,8 @@ static int udevGetIntProperty(struct udev_device *udev_device,
     str = udevGetDeviceProperty(udev_device, property_key);
 
     if (str && virStrToLong_i(str, NULL, base, value) < 0) {
-        VIR_ERROR(_("Failed to convert '%s' to int"), str);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to convert '%s' to int"), str);
         return -1;
     }
     return 0;
@@ -122,7 +123,8 @@ static int udevGetUintProperty(struct udev_device *udev_device,
     str = udevGetDeviceProperty(udev_device, property_key);
 
     if (str && virStrToLong_ui(str, NULL, base, value) < 0) {
-        VIR_ERROR(_("Failed to convert '%s' to int"), str);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to convert '%s' to int"), str);
         return -1;
     }
     return 0;
@@ -170,7 +172,8 @@ static int udevGetIntSysfsAttr(struct udev_device *udev_device,
     str = udevGetDeviceSysfsAttr(udev_device, attr_name);
 
     if (str && virStrToLong_i(str, NULL, base, value) < 0) {
-        VIR_ERROR(_("Failed to convert '%s' to int"), str);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to convert '%s' to int"), str);
         return -1;
     }
 
@@ -188,7 +191,8 @@ static int udevGetUintSysfsAttr(struct udev_device *udev_device,
     str = udevGetDeviceSysfsAttr(udev_device, attr_name);
 
     if (str && virStrToLong_ui(str, NULL, base, value) < 0) {
-        VIR_ERROR(_("Failed to convert '%s' to unsigned int"), str);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to convert '%s' to unsigned int"), str);
         return -1;
     }
 
@@ -205,7 +209,8 @@ static int udevGetUint64SysfsAttr(struct udev_device *udev_device,
     str = udevGetDeviceSysfsAttr(udev_device, attr_name);
 
     if (str && virStrToLong_ull(str, NULL, 0, value) < 0) {
-        VIR_ERROR(_("Failed to convert '%s' to unsigned long long"), str);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to convert '%s' to unsigned long long"), str);
         return -1;
     }
 
@@ -674,8 +679,9 @@ static int udevProcessSCSIDevice(struct udev_device *device ATTRIBUTE_UNUSED,
 
  out:
     if (ret != 0) {
-        VIR_ERROR(_("Failed to process SCSI device with sysfs path '%s'"),
-                  def->sysfs_path);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to process SCSI device with sysfs path '%s'"),
+                       def->sysfs_path);
     }
     return ret;
 }
@@ -1049,7 +1055,8 @@ static int udevGetDeviceDetails(struct udev_device *device,
         ret = udevProcessSCSIGeneric(device, def);
         break;
     default:
-        VIR_ERROR(_("Unknown device type %d"), def->caps->data.type);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unknown device type %d"), def->caps->data.type);
         ret = -1;
         break;
     }
@@ -1212,7 +1219,7 @@ static int udevEnumerateDevices(struct udev *udev)
 
     ret = udev_enumerate_scan_devices(udev_enumerate);
     if (0 != ret) {
-        VIR_ERROR(_("udev scan devices returned %d"), ret);
+        virReportError(VIR_ERR_INTERNAL_ERROR, _("udev scan devices returned %d"), ret);
         goto out;
     }
 
@@ -1292,14 +1299,15 @@ static void udevEventHandleCallback(int watch ATTRIBUTE_UNUSED,
     nodeDeviceLock();
     udev_fd = udev_monitor_get_fd(udev_monitor);
     if (fd != udev_fd) {
-        VIR_ERROR(_("File descriptor returned by udev %d does not "
+        virReportError(VIR_ERR_INTERNAL_ERROR, _("File descriptor returned by udev %d does not "
                     "match node device file descriptor %d"), fd, udev_fd);
         goto out;
     }
 
     device = udev_monitor_receive_device(udev_monitor);
     if (device == NULL) {
-        VIR_ERROR(_("udev_monitor_receive_device returned NULL"));
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("udev_monitor_receive_device returned NULL"));
         goto out;
     }
 
@@ -1337,7 +1345,7 @@ udevGetDMIData(virNodeDevCapDataPtr data)
     if (device == NULL) {
         device = udev_device_new_from_syspath(udev, DMI_DEVPATH_FALLBACK);
         if (device == NULL) {
-            VIR_ERROR(_("Failed to get udev device for syspath '%s' or '%s'"),
+            virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to get udev device for syspath '%s' or '%s'"),
                       DMI_DEVPATH, DMI_DEVPATH_FALLBACK);
             goto out;
         }
@@ -1417,16 +1425,15 @@ static int udevPCITranslateInit(bool privileged ATTRIBUTE_UNUSED)
     /* On s390(x) system there is no PCI bus.
      * Therefore there is nothing to initialize here. */
 #else
-    int pciret;
+    int rc;
 
-    if ((pciret = pci_system_init()) != 0) {
+    if ((rc = pci_system_init()) != 0) {
         /* Ignore failure as non-root; udev is not as helpful in that
          * situation, but a non-privileged user won't benefit much
          * from udev in the first place.  */
         if (errno != ENOENT && (privileged  || errno != EACCES)) {
-            char ebuf[256];
-            VIR_ERROR(_("Failed to initialize libpciaccess: %s"),
-                      virStrerror(pciret, ebuf, sizeof(ebuf)));
+            virReportSystemError(rc, "%s",
+                                 _("Failed to initialize libpciaccess"));
             return -1;
         }
     }
@@ -1454,7 +1461,8 @@ static int nodeStateInitialize(bool privileged,
     }
 
     if (virMutexInit(&driver->lock) < 0) {
-        VIR_ERROR(_("Failed to initialize mutex for driver"));
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Unable to initialize mutex"));
         VIR_FREE(priv);
         VIR_FREE(driver);
         return -1;
@@ -1480,7 +1488,8 @@ static int nodeStateInitialize(bool privileged,
 
     priv->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
     if (priv->udev_monitor == NULL) {
-        VIR_ERROR(_("udev_monitor_new_from_netlink returned NULL"));
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("udev_monitor_new_from_netlink returned NULL"));
         goto out_unlock;
     }
 
-- 
2.7.3

--
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]