]> xenbits.xensource.com Git - libvirt.git/commitdiff
maint: improve VIR_ERR_INVALID_SECRET usage
authorEric Blake <eblake@redhat.com>
Sat, 28 Dec 2013 01:12:05 +0000 (18:12 -0700)
committerEric Blake <eblake@redhat.com>
Thu, 9 Jan 2014 20:55:20 +0000 (13:55 -0700)
While all errors related to invalid secrets appeared to be
consistent, we might as well continue the trend of using a
common macro.  Just as in commit 6e130ddc, the difference
between VIR_IS_SECRET and VIR_IS_CONNECTED_SECRET is moot
(due to reference counting, any valid secret must be tied to
a valid domain).  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@redhat.com>
src/datatypes.h
src/libvirt.c

index f4783601248ee65226a8c0c13601869755aa7789..29a1096ccd86e5d601a5799bcf1a91b07d867efa 100644 (file)
@@ -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))
index baf11192f107eec500eed2d76a039077c121a62f..5be360d50787e06672c54b44c4f5d4484bfce8f0 100644 (file)
@@ -528,9 +528,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__)
@@ -14967,11 +14964,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;
 }
 
@@ -15290,11 +15284,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);
@@ -15324,11 +15314,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);
@@ -15360,11 +15346,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;
 }
 
@@ -15392,11 +15375,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;
 }
 
@@ -15420,13 +15400,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;
 
@@ -15466,12 +15442,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);
 
@@ -15512,12 +15485,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);
 
@@ -15556,12 +15526,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) {
@@ -15605,11 +15572,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;
 }
@@ -15630,11 +15594,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;
 }