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

[libvirt] [PATCH 11/23] Replace use of virLockError with virReportError



From: "Daniel P. Berrange" <berrange redhat com>

Update the lock manager drivers to use virReportError instead
of the virLockError custom macro

Signed-off-by: Daniel P. Berrange <berrange redhat com>
---
 src/locking/lock_driver_sanlock.c |  157 ++++++++++++++++++-------------------
 src/locking/lock_manager.c        |   30 +++----
 2 files changed, 89 insertions(+), 98 deletions(-)

diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c
index 40cd518..67b70ca 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -48,11 +48,6 @@
 
 #define VIR_FROM_THIS VIR_FROM_LOCKING
 
-#define virLockError(code, ...)                                     \
-    virReportErrorHelper(VIR_FROM_THIS, code, __FILE__,             \
-                         __FUNCTION__, __LINE__, __VA_ARGS__)
-
-
 #define VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE "__LIBVIRT__DISKS__"
 
 /*
@@ -111,9 +106,9 @@ static int virLockManagerSanlockLoadConfig(const char *configFile)
         return -1;
 
 #define CHECK_TYPE(name,typ) if (p && p->type != (typ)) {               \
-        virLockError(VIR_ERR_INTERNAL_ERROR,                            \
-                     "%s: %s: expected type " #typ,                     \
-                     configFile, (name));                               \
+        virReportError(VIR_ERR_INTERNAL_ERROR,                          \
+                       "%s: %s: expected type " #typ,                   \
+                       configFile, (name));                             \
         virConfFree(conf);                                              \
         return -1;                                                      \
     }
@@ -167,9 +162,9 @@ static int virLockManagerSanlockSetupLockspace(void)
     ls.host_id = 0; /* Doesn't matter for initialization */
     ls.flags = 0;
     if (!virStrcpy(ls.host_id_disk.path, path, SANLK_PATH_LEN)) {
-        virLockError(VIR_ERR_INTERNAL_ERROR,
-                     _("Lockspace path '%s' exceeded %d characters"),
-                     path, SANLK_PATH_LEN);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Lockspace path '%s' exceeded %d characters"),
+                       path, SANLK_PATH_LEN);
         goto error;
     }
     ls.host_id_disk.offset = 0;
@@ -190,9 +185,9 @@ static int virLockManagerSanlockSetupLockspace(void)
         } else {
             if ((rv = sanlock_align(&ls.host_id_disk)) < 0) {
                 if (rv <= -200)
-                    virLockError(VIR_ERR_INTERNAL_ERROR,
-                                 _("Unable to query sector size %s: error %d"),
-                                 path, rv);
+                    virReportError(VIR_ERR_INTERNAL_ERROR,
+                                   _("Unable to query sector size %s: error %d"),
+                                   path, rv);
                 else
                     virReportSystemError(-rv,
                                          _("Unable to query sector size %s"),
@@ -219,9 +214,9 @@ static int virLockManagerSanlockSetupLockspace(void)
 
             if ((rv = sanlock_init(&ls, NULL, 0, 0)) < 0) {
                 if (rv <= -200)
-                    virLockError(VIR_ERR_INTERNAL_ERROR,
-                                 _("Unable to initialize lockspace %s: error %d"),
-                                 path, rv);
+                    virReportError(VIR_ERR_INTERNAL_ERROR,
+                                   _("Unable to initialize lockspace %s: error %d"),
+                                   path, rv);
                 else
                     virReportSystemError(-rv,
                                          _("Unable to initialize lockspace %s"),
@@ -240,9 +235,9 @@ static int virLockManagerSanlockSetupLockspace(void)
     if ((rv = sanlock_add_lockspace(&ls, 0)) < 0) {
         if (-rv != EEXIST) {
             if (rv <= -200)
-                virLockError(VIR_ERR_INTERNAL_ERROR,
-                             _("Unable to add lockspace %s: error %d"),
-                             path, rv);
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Unable to add lockspace %s: error %d"),
+                               path, rv);
             else
                 virReportSystemError(-rv,
                                      _("Unable to add lockspace %s"),
@@ -296,8 +291,8 @@ static int virLockManagerSanlockInit(unsigned int version,
         goto error;
 
     if (driver->autoDiskLease && !driver->hostID) {
-        virLockError(VIR_ERR_INTERNAL_ERROR,
-                     _("Automatic disk lease mode enabled, but no host ID is set"));
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Automatic disk lease mode enabled, but no host ID is set"));
         goto error;
     }
 
@@ -338,14 +333,14 @@ static int virLockManagerSanlockNew(virLockManagerPtr lock,
     virCheckFlags(0, -1);
 
     if (!driver) {
-        virLockError(VIR_ERR_INTERNAL_ERROR,
-                     _("Sanlock plugin is not initialized"));
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Sanlock plugin is not initialized"));
         return -1;
     }
 
     if (type != VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN) {
-        virLockError(VIR_ERR_INTERNAL_ERROR,
-                     _("Unsupported object type %d"), type);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unsupported object type %d"), type);
         return -1;
     }
 
@@ -363,9 +358,9 @@ static int virLockManagerSanlockNew(virLockManagerPtr lock,
             memcpy(priv->vm_uuid, param->value.uuid, 16);
         } else if (STREQ(param->key, "name")) {
             if (!virStrcpy(priv->vm_name, param->value.str, SANLK_NAME_LEN)) {
-                virLockError(VIR_ERR_INTERNAL_ERROR,
-                             _("Domain name '%s' exceeded %d characters"),
-                             param->value.str, SANLK_NAME_LEN);
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Domain name '%s' exceeded %d characters"),
+                               param->value.str, SANLK_NAME_LEN);
                 goto error;
             }
         } else if (STREQ(param->key, "pid")) {
@@ -409,14 +404,14 @@ static int virLockManagerSanlockDiskLeaseName(const char *path,
     int i;
 
     if (strbuflen < ((MD5_DIGEST_SIZE * 2) + 1)) {
-        virLockError(VIR_ERR_INTERNAL_ERROR,
-                     _("String length too small to store md5 checksum"));
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("String length too small to store md5 checksum"));
         return -1;
     }
 
     if (!(md5_buffer(path, strlen(path), buf))) {
-        virLockError(VIR_ERR_INTERNAL_ERROR,
-                     _("Unable to compute md5 checksum"));
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to compute md5 checksum"));
         return -1;
     }
 
@@ -447,27 +442,27 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
     res->flags = shared ? SANLK_RES_SHARED : 0;
     res->num_disks = 1;
     if (!virStrcpy(res->name, name, SANLK_NAME_LEN)) {
-        virLockError(VIR_ERR_INTERNAL_ERROR,
-                     _("Resource name '%s' exceeds %d characters"),
-                     name, SANLK_NAME_LEN);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Resource name '%s' exceeds %d characters"),
+                       name, SANLK_NAME_LEN);
         goto cleanup;
     }
 
     for (i = 0; i < nparams; i++) {
         if (STREQ(params[i].key, "path")) {
             if (!virStrcpy(res->disks[0].path, params[i].value.str, SANLK_PATH_LEN)) {
-                virLockError(VIR_ERR_INTERNAL_ERROR,
-                             _("Lease path '%s' exceeds %d characters"),
-                             params[i].value.str, SANLK_PATH_LEN);
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Lease path '%s' exceeds %d characters"),
+                               params[i].value.str, SANLK_PATH_LEN);
                 goto cleanup;
             }
         } else if (STREQ(params[i].key, "offset")) {
             res->disks[0].offset = params[i].value.ul;
         } else if (STREQ(params[i].key, "lockspace")) {
             if (!virStrcpy(res->lockspace_name, params[i].value.str, SANLK_NAME_LEN)) {
-                virLockError(VIR_ERR_INTERNAL_ERROR,
-                             _("Resource lockspace '%s' exceeds %d characters"),
-                             params[i].value.str, SANLK_NAME_LEN);
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Resource lockspace '%s' exceeds %d characters"),
+                               params[i].value.str, SANLK_NAME_LEN);
                 goto cleanup;
             }
         }
@@ -499,8 +494,8 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr lock,
     char *path = NULL;
 
     if (nparams) {
-        virLockError(VIR_ERR_INTERNAL_ERROR,
-                     _("Unexpected lock parameters for disk resource"));
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unexpected lock parameters for disk resource"));
         return -1;
     }
 
@@ -520,18 +515,18 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr lock,
         goto cleanup;
     }
     if (!virStrcpy(res->disks[0].path, path, SANLK_PATH_LEN)) {
-        virLockError(VIR_ERR_INTERNAL_ERROR,
-                     _("Lease path '%s' exceeds %d characters"),
-                     path, SANLK_PATH_LEN);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Lease path '%s' exceeds %d characters"),
+                       path, SANLK_PATH_LEN);
         goto cleanup;
     }
 
     if (!virStrcpy(res->lockspace_name,
                    VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE,
                    SANLK_NAME_LEN)) {
-        virLockError(VIR_ERR_INTERNAL_ERROR,
-                     _("Resource lockspace '%s' exceeds %d characters"),
-                     VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE, SANLK_NAME_LEN);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Resource lockspace '%s' exceeds %d characters"),
+                       VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE, SANLK_NAME_LEN);
         goto cleanup;
     }
 
@@ -567,9 +562,9 @@ static int virLockManagerSanlockCreateLease(struct sanlk_resource *res)
         } else {
             if ((rv = sanlock_align(&res->disks[0])) < 0) {
                 if (rv <= -200)
-                    virLockError(VIR_ERR_INTERNAL_ERROR,
-                                 _("Unable to query sector size %s: error %d"),
-                                 res->disks[0].path, rv);
+                    virReportError(VIR_ERR_INTERNAL_ERROR,
+                                   _("Unable to query sector size %s: error %d"),
+                                   res->disks[0].path, rv);
                 else
                     virReportSystemError(-rv,
                                          _("Unable to query sector size %s"),
@@ -596,9 +591,9 @@ static int virLockManagerSanlockCreateLease(struct sanlk_resource *res)
 
             if ((rv = sanlock_init(NULL, res, 0, 0)) < 0) {
                 if (rv <= -200)
-                    virLockError(VIR_ERR_INTERNAL_ERROR,
-                                 _("Unable to initialize lease %s: error %d"),
-                                 res->disks[0].path, rv);
+                    virReportError(VIR_ERR_INTERNAL_ERROR,
+                                   _("Unable to initialize lease %s: error %d"),
+                                   res->disks[0].path, rv);
                 else
                     virReportSystemError(-rv,
                                          _("Unable to initialize lease %s"),
@@ -631,9 +626,9 @@ static int virLockManagerSanlockAddResource(virLockManagerPtr lock,
                   VIR_LOCK_MANAGER_RESOURCE_SHARED, -1);
 
     if (priv->res_count == SANLK_MAX_RESOURCES) {
-        virLockError(VIR_ERR_INTERNAL_ERROR,
-                     _("Too many resources %d for object"),
-                     SANLK_MAX_RESOURCES);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Too many resources %d for object"),
+                       SANLK_MAX_RESOURCES);
         return -1;
     }
 
@@ -692,8 +687,8 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
     if (priv->res_count == 0 &&
         priv->hasRWDisks &&
         driver->requireLeaseForDisks) {
-        virLockError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                     _("Read/write, exclusive access, disks were present, but no leases specified"));
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Read/write, exclusive access, disks were present, but no leases specified"));
         return -1;
     }
 
@@ -703,9 +698,9 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
     }
 
     if (!virStrcpy(opt->owner_name, priv->vm_name, SANLK_NAME_LEN)) {
-        virLockError(VIR_ERR_INTERNAL_ERROR,
-                     _("Domain name '%s' exceeded %d characters"),
-                     priv->vm_name, SANLK_NAME_LEN);
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Domain name '%s' exceeded %d characters"),
+                       priv->vm_name, SANLK_NAME_LEN);
         goto error;
     }
 
@@ -714,9 +709,9 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
                                         &res_count,
                                         &res_args)) < 0) {
             if (rv <= -200)
-                virLockError(VIR_ERR_INTERNAL_ERROR,
-                             _("Unable to parse lock state %s: error %d"),
-                             state, rv);
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Unable to parse lock state %s: error %d"),
+                               state, rv);
             else
                 virReportSystemError(-rv,
                                      _("Unable to parse lock state %s"),
@@ -739,9 +734,9 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
     if (priv->vm_pid == getpid() &&
         (sock = sanlock_register()) < 0) {
         if (sock <= -200)
-            virLockError(VIR_ERR_INTERNAL_ERROR,
-                         _("Failed to open socket to sanlock daemon: error %d"),
-                         sock);
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Failed to open socket to sanlock daemon: error %d"),
+                           sock);
         else
             virReportSystemError(-sock, "%s",
                                  _("Failed to open socket to sanlock daemon"));
@@ -754,8 +749,8 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
                                   priv->res_count, priv->res_args,
                                   opt)) < 0) {
             if (rv <= -200)
-                virLockError(VIR_ERR_INTERNAL_ERROR,
-                             _("Failed to acquire lock: error %d"), rv);
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Failed to acquire lock: error %d"), rv);
             else
                 virReportSystemError(-rv, "%s",
                                      _("Failed to acquire lock"));
@@ -778,8 +773,8 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
     if (flags & VIR_LOCK_MANAGER_ACQUIRE_RESTRICT) {
         if ((rv = sanlock_restrict(sock, SANLK_RESTRICT_ALL)) < 0) {
             if (rv <= -200)
-                virLockError(VIR_ERR_INTERNAL_ERROR,
-                             _("Failed to restrict process: error %d"), rv);
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Failed to restrict process: error %d"), rv);
             else
                 virReportSystemError(-rv, "%s",
                                      _("Failed to restrict process"));
@@ -827,8 +822,8 @@ static int virLockManagerSanlockRelease(virLockManagerPtr lock,
     if (state) {
         if ((rv = sanlock_inquire(-1, priv->vm_pid, 0, &res_count, state)) < 0) {
             if (rv <= -200)
-                virLockError(VIR_ERR_INTERNAL_ERROR,
-                             _("Failed to inquire lock: error %d"), rv);
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Failed to inquire lock: error %d"), rv);
             else
                 virReportSystemError(-rv, "%s",
                                      _("Failed to inquire lock"));
@@ -841,8 +836,8 @@ static int virLockManagerSanlockRelease(virLockManagerPtr lock,
 
     if ((rv = sanlock_release(-1, priv->vm_pid, SANLK_REL_ALL, 0, NULL)) < 0) {
         if (rv <= -200)
-            virLockError(VIR_ERR_INTERNAL_ERROR,
-                         _("Failed to release lock: error %d"), rv);
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Failed to release lock: error %d"), rv);
         else
             virReportSystemError(-rv, "%s",
                                  _("Failed to release lock"));
@@ -862,7 +857,7 @@ static int virLockManagerSanlockInquire(virLockManagerPtr lock,
     virCheckFlags(0, -1);
 
     if (!state) {
-        virLockError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
 
@@ -870,8 +865,8 @@ static int virLockManagerSanlockInquire(virLockManagerPtr lock,
 
     if ((rv = sanlock_inquire(-1, priv->vm_pid, 0, &res_count, state)) < 0) {
         if (rv <= -200)
-            virLockError(VIR_ERR_INTERNAL_ERROR,
-                         _("Failed to inquire lock: error %d"), rv);
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Failed to inquire lock: error %d"), rv);
         else
             virReportSystemError(-rv, "%s",
                                  _("Failed to inquire lock"));
diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c
index f07f9d7..d7929e3 100644
--- a/src/locking/lock_manager.c
+++ b/src/locking/lock_manager.c
@@ -39,23 +39,19 @@
 
 #define VIR_FROM_THIS VIR_FROM_LOCKING
 
-#define virLockError(code, ...)                                      \
-    virReportErrorHelper(VIR_FROM_THIS, code, __FILE__,              \
-                             __FUNCTION__, __LINE__, __VA_ARGS__)
-
 #define CHECK_PLUGIN(field, errret)                                  \
     if (!plugin->driver->field) {                                    \
-        virLockError(VIR_ERR_INTERNAL_ERROR,                         \
-                     _("Missing '%s' field in lock manager driver"), \
-                     #field);                                        \
+        virReportError(VIR_ERR_INTERNAL_ERROR,                         \
+                       _("Missing '%s' field in lock manager driver"), \
+                       #field);                                        \
         return errret;                                               \
     }
 
 #define CHECK_MANAGER(field, errret)                                 \
     if (!lock->driver->field) {                                      \
-        virLockError(VIR_ERR_INTERNAL_ERROR,                         \
-                     _("Missing '%s' field in lock manager driver"), \
-                     #field);                                        \
+        virReportError(VIR_ERR_INTERNAL_ERROR,                         \
+                       _("Missing '%s' field in lock manager driver"), \
+                       #field);                                        \
         return errret;                                               \
     }
 
@@ -150,15 +146,15 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
 
         handle = dlopen(modfile, RTLD_NOW | RTLD_LOCAL);
         if (!handle) {
-            virLockError(VIR_ERR_SYSTEM_ERROR,
-                         _("Failed to load plugin %s: %s"),
-                         modfile, dlerror());
+            virReportError(VIR_ERR_SYSTEM_ERROR,
+                           _("Failed to load plugin %s: %s"),
+                           modfile, dlerror());
             goto cleanup;
         }
 
         if (!(driver = dlsym(handle, "virLockDriverImpl"))) {
-            virLockError(VIR_ERR_INTERNAL_ERROR, "%s",
-                         _("Missing plugin initialization symbol 'virLockDriverImpl'"));
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("Missing plugin initialization symbol 'virLockDriverImpl'"));
             goto cleanup;
         }
     }
@@ -195,8 +191,8 @@ virLockManagerPluginNew(const char *name ATTRIBUTE_UNUSED,
                         const char *configFile ATTRIBUTE_UNUSED,
                         unsigned int flags_unused ATTRIBUTE_UNUSED)
 {
-    virLockError(VIR_ERR_INTERNAL_ERROR, "%s",
-                 _("this platform is missing dlopen"));
+    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                   _("this platform is missing dlopen"));
     return NULL;
 }
 #endif /* !HAVE_DLFCN_H */
-- 
1.7.10.4


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