[PATCH 19/24] maint: improve VIR_ERR_INVALID_SECRET usage

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

 



While all errors related to invalid secrets appeared to be
consistent, we might as well continue the trend of using a
common macro.  For now, we don't need virCheckSecretGoto().

* src/datatypes.h (virCheckSecretReturn): New macro.
(VIR_IS_SECRET, VIR_IS_CONNECTED_SECRET): Drop unused macros.
* src/libvirt.c: Use macro throughout.
(virLibSecretError): Drop unused macro.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 src/datatypes.h | 17 ++++++++++---
 src/libvirt.c   | 79 +++++++++++++++------------------------------------------
 2 files changed, 33 insertions(+), 63 deletions(-)

diff --git a/src/datatypes.h b/src/datatypes.h
index 8b3b153..024a2e3 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -178,10 +178,19 @@ extern virClassPtr virStoragePoolClass;
         }                                                               \
     } while (0)

-# define VIR_IS_SECRET(obj) \
-    (virObjectIsClass((obj), virSecretClass))
-# define VIR_IS_CONNECTED_SECRET(obj) \
-    (VIR_IS_SECRET(obj) && virObjectIsClass((obj)->conn, virConnectClass))
+# define virCheckSecretReturn(obj, retval)                              \
+    do {                                                                \
+        virSecretPtr _secret = (obj);                                   \
+        if (!virObjectIsClass(_secret, virSecretClass) ||               \
+            !virObjectIsClass(_secret->conn, virConnectClass)) {        \
+            virReportErrorHelper(VIR_FROM_SECRET,                       \
+                                 VIR_ERR_INVALID_SECRET,                \
+                                 __FILE__, __FUNCTION__, __LINE__,      \
+                                 __FUNCTION__);                         \
+            virDispatchError(NULL);                                     \
+            return retval;                                              \
+        }                                                               \
+    } while (0)

 # define VIR_IS_STREAM(obj) \
     (virObjectIsClass((obj), virStreamClass))
diff --git a/src/libvirt.c b/src/libvirt.c
index 6b6e19b..eaa4c89 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -518,9 +518,6 @@ DllMain(HINSTANCE instance ATTRIBUTE_UNUSED,
 #define virLibDomainError(code, ...)                              \
     virReportErrorHelper(VIR_FROM_DOM, code, __FILE__,            \
                          __FUNCTION__, __LINE__, __VA_ARGS__)
-#define virLibSecretError(code, ...)                              \
-    virReportErrorHelper(VIR_FROM_SECRET, code, __FILE__,         \
-                         __FUNCTION__, __LINE__, __VA_ARGS__)
 #define virLibStreamError(code, ...)                              \
     virReportErrorHelper(VIR_FROM_STREAMS, code, __FILE__,        \
                          __FUNCTION__, __LINE__, __VA_ARGS__)
@@ -14938,11 +14935,8 @@ virSecretGetConnect(virSecretPtr secret)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_SECRET(secret)) {
-        virLibSecretError(VIR_ERR_INVALID_SECRET, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
+    virCheckSecretReturn(secret, NULL);
+
     return secret->conn;
 }

@@ -15261,11 +15255,7 @@ virSecretGetUUID(virSecretPtr secret, unsigned char *uuid)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_SECRET(secret)) {
-        virLibSecretError(VIR_ERR_INVALID_SECRET, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckSecretReturn(secret, -1);
     virCheckNonNullArgGoto(uuid, error);

     memcpy(uuid, &secret->uuid[0], VIR_UUID_BUFLEN);
@@ -15295,11 +15285,7 @@ virSecretGetUUIDString(virSecretPtr secret, char *buf)

     virResetLastError();

-    if (!VIR_IS_SECRET(secret)) {
-        virLibSecretError(VIR_ERR_INVALID_SECRET, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckSecretReturn(secret, -1);
     virCheckNonNullArgGoto(buf, error);

     virUUIDFormat(secret->uuid, buf);
@@ -15331,11 +15317,8 @@ virSecretGetUsageType(virSecretPtr secret)

     virResetLastError();

-    if (!VIR_IS_SECRET(secret)) {
-        virLibSecretError(VIR_ERR_INVALID_SECRET, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckSecretReturn(secret, -1);
+
     return secret->usageType;
 }

@@ -15363,11 +15346,8 @@ virSecretGetUsageID(virSecretPtr secret)

     virResetLastError();

-    if (!VIR_IS_SECRET(secret)) {
-        virLibSecretError(VIR_ERR_INVALID_SECRET, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
+    virCheckSecretReturn(secret, NULL);
+
     return secret->usageID;
 }

@@ -15391,13 +15371,9 @@ virSecretGetXMLDesc(virSecretPtr secret, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_SECRET(secret)) {
-        virLibSecretError(VIR_ERR_INVALID_SECRET, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
-
+    virCheckSecretReturn(secret, NULL);
     conn = secret->conn;
+
     if (conn->secretDriver != NULL && conn->secretDriver->secretGetXMLDesc != NULL) {
         char *ret;

@@ -15437,12 +15413,9 @@ virSecretSetValue(virSecretPtr secret, const unsigned char *value,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_SECRET(secret)) {
-        virLibSecretError(VIR_ERR_INVALID_SECRET, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckSecretReturn(secret, -1);
     conn = secret->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(value, error);

@@ -15483,12 +15456,9 @@ virSecretGetValue(virSecretPtr secret, size_t *value_size, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_SECRET(secret)) {
-        virLibSecretError(VIR_ERR_INVALID_SECRET, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
+    virCheckSecretReturn(secret, NULL);
     conn = secret->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(value_size, error);

@@ -15527,12 +15497,9 @@ virSecretUndefine(virSecretPtr secret)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_SECRET(secret)) {
-        virLibSecretError(VIR_ERR_INVALID_SECRET, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckSecretReturn(secret, -1);
     conn = secret->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->secretDriver != NULL && conn->secretDriver->secretUndefine != NULL) {
@@ -15576,11 +15543,8 @@ virSecretRef(virSecretPtr secret)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_SECRET(secret)) {
-        virLibSecretError(VIR_ERR_INVALID_SECRET, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckSecretReturn(secret, -1);
+
     virObjectRef(secret);
     return 0;
 }
@@ -15601,11 +15565,8 @@ virSecretFree(virSecretPtr secret)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_SECRET(secret)) {
-        virLibSecretError(VIR_ERR_INVALID_SECRET, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckSecretReturn(secret, -1);
+
     virObjectUnref(secret);
     return 0;
 }
-- 
1.8.4.2

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