[PATCH 12/24] maint: improve VIR_ERR_INVALID_DOMAIN usage

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

 



In datatype.c, virGetDomainSnapshot could result in the message:

error: invalid domain pointer in bad domain

Furthermore, while there are a few functions in libvirt.c that
only care about a virDomainPtr without regards to the connection
(such as virDomainGetName), most functions also require a valid
connection.  Yet several functions were blindly derefencing the
conn member without checking it for validity first (such as
virDomainOpenConsole).  Rather than try and correct all usage
of VIR_IS_DOMAIN vs. VIR_IS_CONNECTED_DOMAIN, it is easier to
just blindly require that a valid domain object always has a
valid connection object (which should be true anyways, since
every domain object holds a reference to its connection, so the
connection will not be closed until all domain objects have
also been closed to release their reference).

After this patch, all places that validate a domain consistently
report:

error: invalid domain pointer in someFunc

* src/datatypes.h (virCheckDomainReturn, virCheckDomainGoto): New
macros.
* src/datatypes.c (virGetDomainSnapshot): Use new macro.
(virLibConnError): Delete unused macro.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 po/POTFILES.in     |    1 -
 src/datatypes.c    |   18 +-
 src/datatypes.h    |   23 ++
 src/libvirt-lxc.c  |   11 +-
 src/libvirt-qemu.c |   18 +-
 src/libvirt.c      | 1055 +++++++++++++---------------------------------------
 6 files changed, 284 insertions(+), 842 deletions(-)

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 49dfc9c..0359b2f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -32,7 +32,6 @@ src/cpu/cpu_generic.c
 src/cpu/cpu_map.c
 src/cpu/cpu_powerpc.c
 src/cpu/cpu_x86.c
-src/datatypes.c
 src/driver.c
 src/esx/esx_driver.c
 src/esx/esx_network_driver.c
diff --git a/src/datatypes.c b/src/datatypes.c
index b765ec8..044afae 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -31,11 +31,6 @@

 #define VIR_FROM_THIS VIR_FROM_NONE

-#define virLibConnError(code, ...)                                \
-    virReportErrorHelper(VIR_FROM_THIS, code, __FILE__,           \
-                         __FUNCTION__, __LINE__, __VA_ARGS__)
-
-
 virClassPtr virConnectClass;
 virClassPtr virConnectCloseCallbackDataClass;
 virClassPtr virDomainClass;
@@ -796,22 +791,19 @@ virGetDomainSnapshot(virDomainPtr domain, const char *name)
     if (virDataTypesInitialize() < 0)
         return NULL;

-    if (!VIR_IS_DOMAIN(domain)) {
-        virLibConnError(VIR_ERR_INVALID_DOMAIN, "%s", _("bad domain"));
-        return NULL;
-    }
-    virCheckNonNullArgReturn(name, NULL);
+    virCheckDomainGoto(domain, error);
+    virCheckNonNullArgGoto(name, error);

     if (!(ret = virObjectNew(virDomainSnapshotClass)))
-        return NULL;
+        goto error;
     if (VIR_STRDUP(ret->name, name) < 0)
-        goto cleanup;
+        goto error;

     ret->domain = virObjectRef(domain);

     return ret;

-cleanup:
+error:
     virObjectUnref(ret);
     return NULL;
 }
diff --git a/src/datatypes.h b/src/datatypes.h
index e3d8da0..eda4b9c 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -64,6 +64,29 @@ extern virClassPtr virStoragePoolClass;
     (virObjectIsClass((obj), virDomainClass))
 # define VIR_IS_CONNECTED_DOMAIN(obj) \
     (VIR_IS_DOMAIN(obj) && virObjectIsClass((obj)->conn, virConnectClass))
+# define virCheckDomainReturn(obj, retval)                              \
+    do {                                                                \
+        virDomainPtr _dom = (obj);                                      \
+        if (!virObjectIsClass(_dom, virDomainClass) ||                  \
+            !virObjectIsClass(_dom->conn, virConnectClass)) {           \
+            virReportErrorHelper(VIR_FROM_DOM, VIR_ERR_INVALID_DOMAIN,  \
+                                 __FILE__, __FUNCTION__, __LINE__,      \
+                                 __FUNCTION__);                         \
+            virDispatchError(NULL);                                     \
+            return retval;                                              \
+        }                                                               \
+    } while (0)
+# define virCheckDomainGoto(obj, label)                                 \
+    do {                                                                \
+        virDomainPtr _dom = (obj);                                      \
+        if (!virObjectIsClass(_dom, virDomainClass) ||                  \
+            !virObjectIsClass(_dom->conn, virConnectClass)) {           \
+            virReportErrorHelper(VIR_FROM_DOM, VIR_ERR_INVALID_DOMAIN,  \
+                                 __FILE__, __FUNCTION__, __LINE__,      \
+                                 __FUNCTION__);                         \
+            goto label;                                                 \
+        }                                                               \
+    } while (0)

 # define VIR_IS_NETWORK(obj) \
     (virObjectIsClass((obj), virNetworkClass))
diff --git a/src/libvirt-lxc.c b/src/libvirt-lxc.c
index ae8bc88..5de07c3 100644
--- a/src/libvirt-lxc.c
+++ b/src/libvirt-lxc.c
@@ -36,10 +36,6 @@

 #define VIR_FROM_THIS VIR_FROM_NONE

-#define virLibDomainError(domain, error, info)                          \
-    virReportErrorHelper(VIR_FROM_DOM, error, __FILE__, __FUNCTION__,   \
-                         __LINE__, info)
-
 /**
  * virDomainLxcOpenNamespace:
  * @domain: a domain object
@@ -70,12 +66,7 @@ virDomainLxcOpenNamespace(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

     virCheckNonNullArgGoto(fdlist, error);
diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c
index 79e8e6b..83d756a 100644
--- a/src/libvirt-qemu.c
+++ b/src/libvirt-qemu.c
@@ -30,10 +30,6 @@

 #define VIR_FROM_THIS VIR_FROM_NONE

-#define virLibDomainError(domain, error, info)                          \
-    virReportErrorHelper(VIR_FROM_DOM, error, __FILE__, __FUNCTION__,   \
-                         __LINE__, info)
-
 /**
  * virDomainQemuMonitorCommand:
  * @domain: a domain object
@@ -77,12 +73,7 @@ virDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

     virCheckNonNullArgGoto(result, error);
@@ -205,12 +196,7 @@ virDomainQemuAgentCommand(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
-
+    virCheckDomainReturn(domain, NULL);
     conn = domain->conn;

     virCheckReadOnlyGoto(conn->flags, error);
diff --git a/src/libvirt.c b/src/libvirt.c
index e0b0b32..accbe69 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -1908,11 +1908,8 @@ virDomainGetConnect(virDomainPtr dom)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
+    virCheckDomainReturn(dom, NULL);
+
     return dom->conn;
 }

@@ -2236,13 +2233,9 @@ virDomainDestroy(virDomainPtr domain)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainDestroy) {
@@ -2300,13 +2293,9 @@ virDomainDestroyFlags(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainDestroyFlags) {
@@ -2341,11 +2330,8 @@ virDomainFree(virDomainPtr domain)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
+
     virObjectUnref(domain);
     return 0;
 }
@@ -2375,11 +2361,7 @@ virDomainRef(virDomainPtr domain)

     virResetLastError();

-    if ((!VIR_IS_CONNECTED_DOMAIN(domain))) {
-        virLibConnError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);

     virObjectRef(domain);
     return 0;
@@ -2409,15 +2391,11 @@ virDomainSuspend(virDomainPtr domain)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

+    virCheckReadOnlyGoto(conn->flags, error);
+
     if (conn->driver->domainSuspend) {
         int ret;
         ret = conn->driver->domainSuspend(domain);
@@ -2455,15 +2433,11 @@ virDomainResume(virDomainPtr domain)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

+    virCheckReadOnlyGoto(conn->flags, error);
+
     if (conn->driver->domainResume) {
         int ret;
         ret = conn->driver->domainResume(domain);
@@ -2519,12 +2493,7 @@ virDomainPMSuspendForDuration(virDomainPtr dom,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;

     virCheckReadOnlyGoto(conn->flags, error);
@@ -2568,12 +2537,7 @@ virDomainPMWakeup(virDomainPtr dom,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;

     virCheckReadOnlyGoto(conn->flags, error);
@@ -2619,13 +2583,10 @@ virDomainSave(virDomainPtr domain, const char *to)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(to, error);

     if (conn->driver->domainSave) {
@@ -2706,13 +2667,10 @@ virDomainSaveFlags(virDomainPtr domain, const char *to,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(to, error);

     if ((flags & VIR_DOMAIN_SAVE_RUNNING) && (flags & VIR_DOMAIN_SAVE_PAUSED)) {
@@ -3050,13 +3008,10 @@ virDomainCoreDump(virDomainPtr domain, const char *to, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(to, error);

     if ((flags & VIR_DUMP_CRASH) && (flags & VIR_DUMP_LIVE)) {
@@ -3138,11 +3093,7 @@ virDomainScreenshot(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
+    virCheckDomainReturn(domain, NULL);
     if (!VIR_IS_STREAM(stream)) {
         virLibConnError(VIR_ERR_INVALID_STREAM, __FUNCTION__);
         return NULL;
@@ -3196,15 +3147,11 @@ virDomainShutdown(virDomainPtr domain)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

+    virCheckReadOnlyGoto(conn->flags, error);
+
     if (conn->driver->domainShutdown) {
         int ret;
         ret = conn->driver->domainShutdown(domain);
@@ -3257,15 +3204,11 @@ virDomainShutdownFlags(virDomainPtr domain, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

+    virCheckReadOnlyGoto(conn->flags, error);
+
     if (conn->driver->domainShutdownFlags) {
         int ret;
         ret = conn->driver->domainShutdownFlags(domain, flags);
@@ -3319,15 +3262,11 @@ virDomainReboot(virDomainPtr domain, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

+    virCheckReadOnlyGoto(conn->flags, error);
+
     if (conn->driver->domainReboot) {
         int ret;
         ret = conn->driver->domainReboot(domain, flags);
@@ -3367,15 +3306,11 @@ virDomainReset(virDomainPtr domain, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

+    virCheckReadOnlyGoto(conn->flags, error);
+
     if (conn->driver->domainReset) {
         int ret;
         ret = conn->driver->domainReset(domain, flags);
@@ -3408,11 +3343,8 @@ virDomainGetName(virDomainPtr domain)

     virResetLastError();

-    if (!VIR_IS_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
+    virCheckDomainReturn(domain, NULL);
+
     return domain->name;
 }

@@ -3433,11 +3365,7 @@ virDomainGetUUID(virDomainPtr domain, unsigned char *uuid)

     virResetLastError();

-    if (!VIR_IS_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckNonNullArgGoto(uuid, error);

     memcpy(uuid, &domain->uuid[0], VIR_UUID_BUFLEN);
@@ -3467,11 +3395,7 @@ virDomainGetUUIDString(virDomainPtr domain, char *buf)

     virResetLastError();

-    if (!VIR_IS_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckNonNullArgGoto(buf, error);

     virUUIDFormat(domain->uuid, buf);
@@ -3498,11 +3422,8 @@ virDomainGetID(virDomainPtr domain)

     virResetLastError();

-    if (!VIR_IS_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return (unsigned int)-1;
-    }
+    virCheckDomainReturn(domain, (unsigned int)-1);
+
     return domain->id;
 }

@@ -3525,12 +3446,7 @@ virDomainGetOSType(virDomainPtr domain)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
-
+    virCheckDomainReturn(domain, NULL);
     conn = domain->conn;

     if (conn->driver->domainGetOSType) {
@@ -3569,12 +3485,7 @@ virDomainGetMaxMemory(virDomainPtr domain)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return 0;
-    }
-
+    virCheckDomainReturn(domain, 0);
     conn = domain->conn;

     if (conn->driver->domainGetMaxMemory) {
@@ -3623,16 +3534,12 @@ virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-    virCheckNonZeroArgGoto(memory, error);
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

+    virCheckReadOnlyGoto(conn->flags, error);
+    virCheckNonZeroArgGoto(memory, error);
+
     if (conn->driver->domainSetMaxMemory) {
         int ret;
         ret = conn->driver->domainSetMaxMemory(domain, memory);
@@ -3673,16 +3580,12 @@ virDomainSetMemory(virDomainPtr domain, unsigned long memory)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-    virCheckNonZeroArgGoto(memory, error);
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

+    virCheckReadOnlyGoto(conn->flags, error);
+    virCheckNonZeroArgGoto(memory, error);
+
     if (conn->driver->domainSetMemory) {
         int ret;
         ret = conn->driver->domainSetMemory(domain, memory);
@@ -3734,17 +3637,12 @@ virDomainSetMemoryFlags(virDomainPtr domain, unsigned long memory,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonZeroArgGoto(memory, error);

-    conn = domain->conn;
-
     if (conn->driver->domainSetMemoryFlags) {
         int ret;
         ret = conn->driver->domainSetMemoryFlags(domain, memory, flags);
@@ -3793,19 +3691,14 @@ virDomainSetMemoryStatsPeriod(virDomainPtr domain, int period,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(conn->flags, error);

     /* This must be positive to set the balloon collection period */
     virCheckNonNegativeArgGoto(period, error);

-    conn = domain->conn;
-
     if (conn->driver->domainSetMemoryStatsPeriod) {
         int ret;
         ret = conn->driver->domainSetMemoryStatsPeriod(domain, period, flags);
@@ -3890,20 +3783,16 @@ virDomainSetMemoryParameters(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;
+
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(params, error);
     virCheckPositiveArgGoto(nparams, error);

-    if (virTypedParameterValidateSet(domain->conn, params, nparams) < 0)
+    if (virTypedParameterValidateSet(conn, params, nparams) < 0)
         goto error;

-    conn = domain->conn;
-
     if (conn->driver->domainSetMemoryParameters) {
         int ret;
         ret = conn->driver->domainSetMemoryParameters(domain, params, nparams, flags);
@@ -3967,11 +3856,7 @@ virDomainGetMemoryParameters(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckNonNullArgGoto(nparams, error);
     virCheckNonNegativeArgGoto(*nparams, error);
     if (*nparams != 0)
@@ -4032,11 +3917,7 @@ virDomainSetNumaParameters(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckReadOnlyGoto(domain->conn->flags, error);
     virCheckNonNullArgGoto(params, error);
     virCheckPositiveArgGoto(nparams, error);
@@ -4100,11 +3981,7 @@ virDomainGetNumaParameters(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckNonNullArgGoto(nparams, error);
     virCheckNonNegativeArgGoto(*nparams, error);
     if (*nparams != 0)
@@ -4158,20 +4035,16 @@ virDomainSetBlkioParameters(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;
+
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(params, error);
     virCheckNonNegativeArgGoto(nparams, error);

-    if (virTypedParameterValidateSet(domain->conn, params, nparams) < 0)
+    if (virTypedParameterValidateSet(conn, params, nparams) < 0)
         goto error;

-    conn = domain->conn;
-
     if (conn->driver->domainSetBlkioParameters) {
         int ret;
         ret = conn->driver->domainSetBlkioParameters(domain, params, nparams, flags);
@@ -4226,11 +4099,7 @@ virDomainGetBlkioParameters(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckNonNullArgGoto(nparams, error);
     virCheckNonNegativeArgGoto(*nparams, error);
     if (*nparams != 0)
@@ -4287,11 +4156,7 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)

     memset(info, 0, sizeof(virDomainInfo));

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckNonNullArgGoto(info, error);

     conn = domain->conn;
@@ -4338,11 +4203,7 @@ virDomainGetState(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckNonNullArgGoto(state, error);

     conn = domain->conn;
@@ -4383,12 +4244,7 @@ virDomainGetControlInfo(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     virCheckNonNullArgGoto(info, error);

     conn = domain->conn;
@@ -4438,12 +4294,7 @@ virDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
-
+    virCheckDomainReturn(domain, NULL);
     conn = domain->conn;

     if ((conn->flags & VIR_CONNECT_RO) && (flags & VIR_DOMAIN_XML_SECURE)) {
@@ -5389,11 +5240,7 @@ virDomainMigrate(virDomainPtr domain,
     virResetLastError();

     /* First checkout the source */
-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
+    virCheckDomainReturn(domain, NULL);
     virCheckReadOnlyGoto(domain->conn->flags, error);

     /* Now checkout the destination */
@@ -5619,11 +5466,7 @@ virDomainMigrate2(virDomainPtr domain,
     virResetLastError();

     /* First checkout the source */
-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
+    virCheckDomainReturn(domain, NULL);
     virCheckReadOnlyGoto(domain->conn->flags, error);

     /* Now checkout the destination */
@@ -5800,11 +5643,7 @@ virDomainMigrate3(virDomainPtr domain,
     virResetLastError();

     /* First checkout the source */
-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
+    virCheckDomainReturn(domain, NULL);
     virCheckReadOnlyGoto(domain->conn->flags, error);

     /* Now checkout the destination */
@@ -6023,11 +5862,7 @@ virDomainMigrateToURI(virDomainPtr domain,
     virResetLastError();

     /* First checkout the source */
-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckReadOnlyGoto(domain->conn->flags, error);

     virCheckNonNullArgGoto(duri, error);
@@ -6186,11 +6021,7 @@ virDomainMigrateToURI2(virDomainPtr domain,
     virResetLastError();

     /* First checkout the source */
-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckReadOnlyGoto(domain->conn->flags, error);

     if (flags & VIR_MIGRATE_NON_SHARED_DISK &&
@@ -6299,11 +6130,7 @@ virDomainMigrateToURI3(virDomainPtr domain,
     virResetLastError();

     /* First checkout the source */
-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckReadOnlyGoto(domain->conn->flags, error);

     if (flags & VIR_MIGRATE_NON_SHARED_DISK &&
@@ -6449,14 +6276,10 @@ virDomainMigratePerform(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainMigratePerform) {
         int ret;
@@ -6667,14 +6490,10 @@ virDomainMigrateBegin3(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
+    virCheckDomainReturn(domain, NULL);
     conn = domain->conn;

-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainMigrateBegin3) {
         char *xml;
@@ -6825,14 +6644,10 @@ virDomainMigratePerform3(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainMigratePerform3) {
         int ret;
@@ -6919,14 +6734,10 @@ virDomainMigrateConfirm3(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainMigrateConfirm3) {
         int ret;
@@ -6967,14 +6778,10 @@ virDomainMigrateBegin3Params(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
+    virCheckDomainReturn(domain, NULL);
     conn = domain->conn;

-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainMigrateBegin3Params) {
         char *xml;
@@ -7116,14 +6923,10 @@ virDomainMigratePerform3Params(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainMigratePerform3Params) {
         int ret;
@@ -7209,14 +7012,10 @@ virDomainMigrateConfirm3Params(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainMigrateConfirm3Params) {
         int ret;
@@ -7708,11 +7507,7 @@ virDomainGetSchedulerType(virDomainPtr domain, int *nparams)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
+    virCheckDomainReturn(domain, NULL);
     conn = domain->conn;

     if (conn->driver->domainGetSchedulerType){
@@ -7760,11 +7555,7 @@ virDomainGetSchedulerParameters(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);

     virCheckNonNullArgGoto(params, error);
     virCheckNonNullArgGoto(nparams, error);
@@ -7831,11 +7622,7 @@ virDomainGetSchedulerParametersFlags(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);

     virCheckNonNullArgGoto(params, error);
     virCheckNonNullArgGoto(nparams, error);
@@ -7898,21 +7685,16 @@ virDomainSetSchedulerParameters(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(params, error);
     virCheckNonNegativeArgGoto(nparams, error);

-    if (virTypedParameterValidateSet(domain->conn, params, nparams) < 0)
+    if (virTypedParameterValidateSet(conn, params, nparams) < 0)
         goto error;

-    conn = domain->conn;
-
     if (conn->driver->domainSetSchedulerParameters) {
         int ret;
         ret = conn->driver->domainSetSchedulerParameters(domain, params, nparams);
@@ -7960,21 +7742,16 @@ virDomainSetSchedulerParametersFlags(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(params, error);
     virCheckNonNegativeArgGoto(nparams, error);

-    if (virTypedParameterValidateSet(domain->conn, params, nparams) < 0)
+    if (virTypedParameterValidateSet(conn, params, nparams) < 0)
         goto error;

-    conn = domain->conn;
-
     if (conn->driver->domainSetSchedulerParametersFlags) {
         int ret;
         ret = conn->driver->domainSetSchedulerParametersFlags(domain,
@@ -8031,11 +7808,7 @@ virDomainBlockStats(virDomainPtr dom, const char *disk,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
     virCheckNonNullArgGoto(disk, error);
     virCheckNonNullArgGoto(stats, error);
     if (size > sizeof(stats2)) {
@@ -8113,11 +7886,7 @@ virDomainBlockStatsFlags(virDomainPtr dom,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
     virCheckNonNullArgGoto(disk, error);
     virCheckNonNullArgGoto(nparams, error);
     virCheckNonNegativeArgGoto(*nparams, error);
@@ -8178,11 +7947,7 @@ virDomainInterfaceStats(virDomainPtr dom, const char *path,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
     virCheckNonNullArgGoto(path, error);
     virCheckNonNullArgGoto(stats, error);
     if (size > sizeof(stats2)) {
@@ -8243,20 +8008,16 @@ virDomainSetInterfaceParameters(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;
+
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(params, error);
     virCheckPositiveArgGoto(nparams, error);

-    if (virTypedParameterValidateSet(domain->conn, params, nparams) < 0)
+    if (virTypedParameterValidateSet(conn, params, nparams) < 0)
         goto error;

-    conn = domain->conn;
-
     if (conn->driver->domainSetInterfaceParameters) {
         int ret;
         ret = conn->driver->domainSetInterfaceParameters(domain, device,
@@ -8314,11 +8075,7 @@ virDomainGetInterfaceParameters(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckNonNullArgGoto(nparams, error);
     virCheckNonNegativeArgGoto(*nparams, error);
     if (*nparams != 0)
@@ -8391,11 +8148,7 @@ virDomainMemoryStats(virDomainPtr dom, virDomainMemoryStatPtr stats,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);

     if (!stats || nr_stats == 0)
         return 0;
@@ -8479,15 +8232,10 @@ virDomainBlockPeek(virDomainPtr dom,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;

-    virCheckReadOnlyGoto(dom->conn->flags, error);
-
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(disk, error);

     /* Allow size == 0 as an access test. */
@@ -8550,15 +8298,10 @@ virDomainBlockResize(virDomainPtr dom,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;

-    virCheckReadOnlyGoto(dom->conn->flags, error);
-
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(disk, error);

     if (conn->driver->domainBlockResize) {
@@ -8625,14 +8368,10 @@ virDomainMemoryPeek(virDomainPtr dom,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;

-    virCheckReadOnlyGoto(dom->conn->flags, error);
+    virCheckReadOnlyGoto(conn->flags, error);

     /* Note on access to physical memory: A VIR_MEMORY_PHYSICAL flag is
      * a possibility.  However it isn't really useful unless the caller
@@ -8716,11 +8455,7 @@ virDomainGetBlockInfo(virDomainPtr domain, const char *disk,

     memset(info, 0, sizeof(virDomainBlockInfo));

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckNonNullArgGoto(disk, error);
     virCheckNonNullArgGoto(info, error);

@@ -8816,12 +8551,9 @@ virDomainUndefine(virDomainPtr domain)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainUndefine) {
@@ -8874,12 +8606,9 @@ virDomainUndefineFlags(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainUndefineFlags) {
@@ -9099,12 +8828,9 @@ virDomainCreate(virDomainPtr domain)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainCreate) {
@@ -9165,12 +8891,9 @@ virDomainCreateWithFlags(virDomainPtr domain, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainCreateWithFlags) {
@@ -9242,12 +8965,9 @@ virDomainCreateWithFiles(virDomainPtr domain, unsigned int nfiles,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainCreateWithFiles) {
@@ -9289,11 +9009,7 @@ virDomainGetAutostart(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckNonNullArgGoto(autostart, error);

     conn = domain->conn;
@@ -9334,15 +9050,10 @@ virDomainSetAutostart(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainSetAutostart) {
         int ret;
@@ -9377,15 +9088,11 @@ virDomainInjectNMI(virDomainPtr domain, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

+    virCheckReadOnlyGoto(conn->flags, error);
+
     if (conn->driver->domainInjectNMI) {
         int ret;
         ret = conn->driver->domainInjectNMI(domain, flags);
@@ -9439,15 +9146,11 @@ virDomainSendKey(virDomainPtr domain,
         goto error;
     }

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

+    virCheckReadOnlyGoto(conn->flags, error);
+
     if (conn->driver->domainSendKey) {
         int ret;
         ret = conn->driver->domainSendKey(domain, codeset, holdtime,
@@ -9510,17 +9213,11 @@ virDomainSendProcessSignal(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

     virCheckNonZeroArgGoto(pid_value, error);
-
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-
-    conn = domain->conn;
+    virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainSendProcessSignal) {
         int ret;
@@ -9567,17 +9264,12 @@ virDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonZeroArgGoto(nvcpus, error);

-    conn = domain->conn;
-
     if (conn->driver->domainSetVcpus) {
         int ret;
         ret = conn->driver->domainSetVcpus(domain, nvcpus);
@@ -9640,11 +9332,7 @@ virDomainSetVcpusFlags(virDomainPtr domain, unsigned int nvcpus,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckReadOnlyGoto(domain->conn->flags, error);

     if (flags & VIR_DOMAIN_VCPU_GUEST &&
@@ -9717,11 +9405,7 @@ virDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);

     /* At most one of these two flags should be set.  */
     if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
@@ -9782,13 +9466,10 @@ virDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(cpumap, error);
     virCheckPositiveArgGoto(maplen, error);

@@ -9797,8 +9478,6 @@ virDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
         goto error;
     }

-    conn = domain->conn;
-
     if (conn->driver->domainPinVcpu) {
         int ret;
         ret = conn->driver->domainPinVcpu(domain, vcpu, cpumap, maplen);
@@ -9857,16 +9536,12 @@ virDomainPinVcpuFlags(virDomainPtr domain, unsigned int vcpu,
     VIR_DOMAIN_DEBUG(domain, "vcpu=%u, cpumap=%p, maplen=%d, flags=%x",
                      vcpu, cpumap, maplen, flags);

-    virResetLastError();
-
-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(cpumap, error);
     virCheckPositiveArgGoto(maplen, error);

@@ -9875,8 +9550,6 @@ virDomainPinVcpuFlags(virDomainPtr domain, unsigned int vcpu,
         goto error;
     }

-    conn = domain->conn;
-
     if (conn->driver->domainPinVcpuFlags) {
         int ret;
         ret = conn->driver->domainPinVcpuFlags(domain, vcpu, cpumap, maplen, flags);
@@ -9928,11 +9601,8 @@ virDomainGetVcpuPinInfo(virDomainPtr domain, int ncpumaps,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

     virCheckNonNullArgGoto(cpumaps, error);
     virCheckPositiveArgGoto(ncpumaps, error);
@@ -9952,7 +9622,6 @@ virDomainGetVcpuPinInfo(virDomainPtr domain, int ncpumaps,
                             __FUNCTION__);
         goto error;
     }
-    conn = domain->conn;

     if (conn->driver->domainGetVcpuPinInfo) {
         int ret;
@@ -10014,19 +9683,14 @@ virDomainPinEmulator(virDomainPtr domain, unsigned char *cpumap,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

-    virCheckReadOnlyGoto(domain->conn->flags, error);
+    virCheckReadOnlyGoto(conn->flags, error);

     virCheckNonNullArgGoto(cpumap, error);
     virCheckPositiveArgGoto(maplen, error);

-    conn = domain->conn;
-
     if (conn->driver->domainPinEmulator) {
         int ret;
         ret = conn->driver->domainPinEmulator(domain, cpumap, maplen, flags);
@@ -10074,11 +9738,7 @@ virDomainGetEmulatorPinInfo(virDomainPtr domain, unsigned char *cpumap,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);

     virCheckNonNullArgGoto(cpumap, error);
     virCheckPositiveArgGoto(maplen, error);
@@ -10147,11 +9807,7 @@ virDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckNonNullArgGoto(info, error);
     virCheckPositiveArgGoto(maxinfo, error);

@@ -10208,12 +9864,7 @@ virDomainGetMaxVcpus(virDomainPtr domain)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

     if (conn->driver->domainGetMaxVcpus) {
@@ -10252,16 +9903,11 @@ virDomainGetSecurityLabel(virDomainPtr domain, virSecurityLabelPtr seclabel)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

     virCheckNonNullArgGoto(seclabel, error);

-    conn = domain->conn;
-
     if (conn->driver->domainGetSecurityLabel) {
         int ret;
         ret = conn->driver->domainGetSecurityLabel(domain, seclabel);
@@ -10300,11 +9946,7 @@ virDomainGetSecurityLabelList(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);

     virCheckNonNullArgGoto(seclabels, error);

@@ -10371,11 +10013,7 @@ virDomainSetMetadata(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        goto error;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

     virCheckReadOnlyGoto(conn->flags, error);
@@ -10456,10 +10094,7 @@ virDomainGetMetadata(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        goto error;
-    }
+    virCheckDomainReturn(domain, NULL);

     if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
         (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
@@ -10559,16 +10194,11 @@ virDomainAttachDevice(virDomainPtr domain, const char *xml)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

     virCheckNonNullArgGoto(xml, error);
-
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-    conn = domain->conn;
+    virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainAttachDevice) {
        int ret;
@@ -10620,16 +10250,11 @@ virDomainAttachDeviceFlags(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

     virCheckNonNullArgGoto(xml, error);
-
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-    conn = domain->conn;
+    virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainAttachDeviceFlags) {
         int ret;
@@ -10666,16 +10291,11 @@ virDomainDetachDevice(virDomainPtr domain, const char *xml)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

     virCheckNonNullArgGoto(xml, error);
-
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-    conn = domain->conn;
+    virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainDetachDevice) {
         int ret;
@@ -10743,16 +10363,11 @@ virDomainDetachDeviceFlags(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

     virCheckNonNullArgGoto(xml, error);
-
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-    conn = domain->conn;
+    virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainDetachDeviceFlags) {
         int ret;
@@ -10804,16 +10419,11 @@ virDomainUpdateDeviceFlags(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;

     virCheckNonNullArgGoto(xml, error);
-
-    virCheckReadOnlyGoto(domain->conn->flags, error);
-    conn = domain->conn;
+    virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainUpdateDeviceFlags) {
         int ret;
@@ -17036,11 +16646,8 @@ virDomainIsActive(virDomainPtr dom)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
+
     if (dom->conn->driver->domainIsActive) {
         int ret;
         ret = dom->conn->driver->domainIsActive(dom);
@@ -17072,11 +16679,8 @@ virDomainIsPersistent(virDomainPtr dom)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
+
     if (dom->conn->driver->domainIsPersistent) {
         int ret;
         ret = dom->conn->driver->domainIsPersistent(dom);
@@ -17107,11 +16711,8 @@ virDomainIsUpdated(virDomainPtr dom)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
+
     if (dom->conn->driver->domainIsUpdated) {
         int ret;
         ret = dom->conn->driver->domainIsUpdated(dom);
@@ -18037,11 +17638,7 @@ virDomainGetJobInfo(virDomainPtr domain, virDomainJobInfoPtr info)

     memset(info, 0, sizeof(virDomainJobInfo));

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckNonNullArgGoto(info, error);

     conn = domain->conn;
@@ -18094,11 +17691,7 @@ virDomainGetJobStats(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);
     virCheckNonNullArgGoto(type, error);
     virCheckNonNullArgGoto(params, error);
     virCheckNonNullArgGoto(nparams, error);
@@ -18140,13 +17733,9 @@ virDomainAbortJob(virDomainPtr domain)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainAbortJob) {
@@ -18188,13 +17777,9 @@ virDomainMigrateSetMaxDowntime(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainMigrateSetMaxDowntime) {
@@ -18232,12 +17817,7 @@ virDomainMigrateGetCompressionCache(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

     virCheckNonNullArgGoto(cacheSize, error);
@@ -18281,13 +17861,9 @@ virDomainMigrateSetCompressionCache(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainMigrateSetCompressionCache) {
@@ -18327,13 +17903,9 @@ virDomainMigrateSetMaxSpeed(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainMigrateSetMaxSpeed) {
@@ -18371,16 +17943,10 @@ virDomainMigrateGetMaxSpeed(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

     virCheckNonNullArgGoto(bandwidth, error);
-
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainMigrateGetMaxSpeed) {
@@ -18443,11 +18009,14 @@ virConnectDomainEventRegisterAny(virConnectPtr conn,
     virResetLastError();

     virCheckConnectReturn(conn, -1);
-    if (dom != NULL &&
-        !(VIR_IS_CONNECTED_DOMAIN(dom) && dom->conn == conn)) {
-        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
-        virDispatchError(conn);
-        return -1;
+    if (dom) {
+        virCheckDomainGoto(dom, error);
+        if (dom->conn != conn) {
+            virReportInvalidArg(dom,
+                                _("domain '%s' in %s must match connection"),
+                                dom->name, __FUNCTION__);
+            goto error;
+        }
     }
     virCheckNonNullArgGoto(cb, error);
     virCheckNonNegativeArgGoto(eventID, error);
@@ -18666,13 +18235,9 @@ virDomainManagedSave(virDomainPtr dom, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if ((flags & VIR_DOMAIN_SAVE_RUNNING) && (flags & VIR_DOMAIN_SAVE_PAUSED)) {
@@ -18720,12 +18285,7 @@ virDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;

     if (conn->driver->domainHasManagedSaveImage) {
@@ -18763,13 +18323,9 @@ virDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainManagedSaveRemove) {
@@ -18983,16 +18539,10 @@ virDomainSnapshotCreateXML(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
-
+    virCheckDomainReturn(domain, NULL);
     conn = domain->conn;

     virCheckNonNullArgGoto(xmlDesc, error);
-
     virCheckReadOnlyGoto(conn->flags, error);

     if ((flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT) &&
@@ -19136,11 +18686,7 @@ virDomainSnapshotNum(virDomainPtr domain, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(domain, -1);

     conn = domain->conn;
     if (conn->driver->domainSnapshotNum) {
@@ -19223,12 +18769,7 @@ virDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

     virCheckNonNullArgGoto(names, error);
@@ -19313,12 +18854,7 @@ virDomainListAllSnapshots(virDomainPtr domain, virDomainSnapshotPtr **snaps,
     if (snaps)
         *snaps = NULL;

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

     if (conn->driver->domainListAllSnapshots) {
@@ -19617,12 +19153,7 @@ virDomainSnapshotLookupByName(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
-
+    virCheckDomainReturn(domain, NULL);
     conn = domain->conn;

     virCheckNonNullArgGoto(name, error);
@@ -19660,12 +19191,7 @@ virDomainHasCurrentSnapshot(virDomainPtr domain, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;

     if (conn->driver->domainHasCurrentSnapshot) {
@@ -19703,12 +19229,7 @@ virDomainSnapshotCurrent(virDomainPtr domain,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
-
+    virCheckDomainReturn(domain, NULL);
     conn = domain->conn;

     if (conn->driver->domainSnapshotCurrent) {
@@ -20118,13 +19639,9 @@ virDomainOpenConsole(virDomainPtr dom,

     virResetLastError();

-    if (!VIR_IS_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainOpenConsole) {
@@ -20178,13 +19695,9 @@ virDomainOpenChannel(virDomainPtr dom,

     virResetLastError();

-    if (!VIR_IS_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;
+
     virCheckReadOnlyGoto(conn->flags, error);

     if (conn->driver->domainOpenChannel) {
@@ -20253,15 +19766,10 @@ virDomainBlockJobAbort(virDomainPtr dom, const char *disk,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;

-    virCheckReadOnlyGoto(dom->conn->flags, error);
-
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(disk, error);

     if (conn->driver->domainBlockJobAbort) {
@@ -20311,11 +19819,7 @@ virDomainGetBlockJobInfo(virDomainPtr dom, const char *disk,

     memset(info, 0, sizeof(*info));

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;

     virCheckNonNullArgGoto(disk, error);
@@ -20367,15 +19871,10 @@ virDomainBlockJobSetSpeed(virDomainPtr dom, const char *disk,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;

-    virCheckReadOnlyGoto(dom->conn->flags, error);
-
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(disk, error);

     if (conn->driver->domainBlockJobSetSpeed) {
@@ -20438,15 +19937,10 @@ virDomainBlockPull(virDomainPtr dom, const char *disk,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;

-    virCheckReadOnlyGoto(dom->conn->flags, error);
-
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(disk, error);

     if (conn->driver->domainBlockPull) {
@@ -20555,15 +20049,10 @@ virDomainBlockRebase(virDomainPtr dom, const char *disk,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;

-    virCheckReadOnlyGoto(dom->conn->flags, error);
-
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(disk, error);

     if (flags & VIR_DOMAIN_BLOCK_REBASE_COPY) {
@@ -20671,15 +20160,10 @@ virDomainBlockCommit(virDomainPtr dom, const char *disk,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);
     conn = dom->conn;

-    virCheckReadOnlyGoto(dom->conn->flags, error);
-
+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(disk, error);

     if (conn->driver->domainBlockCommit) {
@@ -20735,12 +20219,7 @@ virDomainOpenGraphics(virDomainPtr dom,

     virResetLastError();

-    if (!VIR_IS_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(dom, -1);
     virCheckNonNegativeArgGoto(fd, error);

     if (fstat(fd, &sb) < 0) {
@@ -21022,14 +20501,10 @@ virDomainSetBlockIoTune(virDomainPtr dom,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
-    virCheckReadOnlyGoto(dom->conn->flags, error);
+    virCheckDomainReturn(dom, -1);
+    conn = dom->conn;

+    virCheckReadOnlyGoto(conn->flags, error);
     virCheckNonNullArgGoto(disk, error);
     virCheckPositiveArgGoto(nparams, error);
     virCheckNonNullArgGoto(params, error);
@@ -21037,8 +20512,6 @@ virDomainSetBlockIoTune(virDomainPtr dom,
     if (virTypedParameterValidateSet(dom->conn, params, nparams) < 0)
         goto error;

-    conn = dom->conn;
-
     if (conn->driver->domainSetBlockIoTune) {
         int ret;
         ret = conn->driver->domainSetBlockIoTune(dom, disk, params, nparams, flags);
@@ -21102,11 +20575,7 @@ virDomainGetBlockIoTune(virDomainPtr dom,

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);

     virCheckNonNullArgGoto(nparams, error);
     virCheckNonNegativeArgGoto(*nparams, error);
@@ -21234,13 +20703,9 @@ virDomainGetCPUStats(virDomainPtr domain,
                      params, nparams, start_cpu, ncpus, flags);
     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(domain, -1);
     conn = domain->conn;
+
     /* Special cases:
      * start_cpu must be non-negative, or else -1
      * if start_cpu is -1, ncpus must be 1
@@ -21331,11 +20796,7 @@ virDomainGetDiskErrors(virDomainPtr dom,

     virResetLastError();

-    if (!VIR_IS_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
+    virCheckDomainReturn(dom, -1);

     if (maxerrors)
         virCheckNonNullArgGoto(errors, error);
@@ -21380,12 +20841,7 @@ virDomainGetHostname(virDomainPtr domain, unsigned int flags)

     virResetLastError();

-    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return NULL;
-    }
-
+    virCheckDomainReturn(domain, NULL);
     conn = domain->conn;

     if (conn->driver->domainGetHostname) {
@@ -21482,12 +20938,7 @@ virDomainFSTrim(virDomainPtr dom,

     virResetLastError();

-    if (!VIR_IS_DOMAIN(dom)) {
-        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
-        virDispatchError(NULL);
-        return -1;
-    }
-
+    virCheckDomainReturn(dom, -1);
     virCheckReadOnlyGoto(dom->conn->flags, error);

     if (dom->conn->driver->domainFSTrim) {
-- 
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]