The datatype.c object checks could result in a message like: error: invalid connection pointer in no connection This consolidates all clients of this message to have uniform contents: error: invalid connection pointer in someFunc * src/datatypes.h (virCheckConnectReturn) (virCheckConnectGoto): New macros. * src/datatypes.c: Use new macro. * src/libvirt-qemu.c (virDomainQemuAttach): Likewise. (virLibConnError): Delete unused macro. * src/libvirt-lxc.c (virLibConnError): Likewise. * src/libvirt.c: Use new macro throughout. * docs/api_extension.html.in: Modernize documentation. Signed-off-by: Eric Blake <eblake@xxxxxxxxxx> --- docs/api_extension.html.in | 7 +- src/datatypes.c | 86 ++--- src/datatypes.h | 19 ++ src/libvirt-lxc.c | 4 - src/libvirt-qemu.c | 11 +- src/libvirt.c | 783 +++++++-------------------------------------- 6 files changed, 178 insertions(+), 732 deletions(-) diff --git a/docs/api_extension.html.in b/docs/api_extension.html.in index 6718625..ac7097b 100644 --- a/docs/api_extension.html.in +++ b/docs/api_extension.html.in @@ -180,12 +180,13 @@ being called and its parameters;</li> <li>MUST call virResetLastError();</li> <li>SHOULD confirm that the connection is valid with - VIR_IS_CONNECT(conn);</li> + virCheckConnectReturn() or virCheckConnectGoto();</li> <li><strong>SECURITY: If the API requires a connection with write privileges, MUST confirm that the connection flags do not - indicate that the connection is read-only;</strong></li> + indicate that the connection is read-only with + virCheckReadOnlyGoto();</strong></li> <li>SHOULD do basic validation of the parameters that are being - passed in;</li> + passed in, using helpers like virCheckNonNullArgGoto();</li> <li>MUST confirm that the driver for this connection exists and that it implements this function;</li> <li>MUST call the internal API;</li> diff --git a/src/datatypes.c b/src/datatypes.c index 161f1b0..b765ec8 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -1,7 +1,7 @@ /* * datatypes.h: management of structs for public data types * - * Copyright (C) 2006-2012 Red Hat, Inc. + * Copyright (C) 2006-2013 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -218,15 +218,12 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) if (virDataTypesInitialize() < 0) return NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection")); - return NULL; - } - virCheckNonNullArgReturn(name, NULL); - virCheckNonNullArgReturn(uuid, NULL); + virCheckConnectGoto(conn, error); + virCheckNonNullArgGoto(name, error); + virCheckNonNullArgGoto(uuid, error); if (!(ret = virObjectNew(virDomainClass))) - return NULL; + goto error; if (VIR_STRDUP(ret->name, name) < 0) goto error; @@ -289,15 +286,12 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) if (virDataTypesInitialize() < 0) return NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection")); - return NULL; - } - virCheckNonNullArgReturn(name, NULL); - virCheckNonNullArgReturn(uuid, NULL); + virCheckConnectGoto(conn, error); + virCheckNonNullArgGoto(name, error); + virCheckNonNullArgGoto(uuid, error); if (!(ret = virObjectNew(virNetworkClass))) - return NULL; + goto error; if (VIR_STRDUP(ret->name, name) < 0) goto error; @@ -360,18 +354,15 @@ virGetInterface(virConnectPtr conn, const char *name, const char *mac) if (virDataTypesInitialize() < 0) return NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection")); - return NULL; - } - virCheckNonNullArgReturn(name, NULL); + virCheckConnectGoto(conn, error); + virCheckNonNullArgGoto(name, error); /* a NULL mac from caller is okay. Treat it as blank */ if (mac == NULL) mac = ""; if (!(ret = virObjectNew(virInterfaceClass))) - return NULL; + goto error; if (VIR_STRDUP(ret->name, name) < 0 || VIR_STRDUP(ret->mac, mac) < 0) @@ -435,15 +426,12 @@ virGetStoragePool(virConnectPtr conn, const char *name, if (virDataTypesInitialize() < 0) return NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection")); - return NULL; - } - virCheckNonNullArgReturn(name, NULL); - virCheckNonNullArgReturn(uuid, NULL); + virCheckConnectGoto(conn, error); + virCheckNonNullArgGoto(name, error); + virCheckNonNullArgGoto(uuid, error); if (!(ret = virObjectNew(virStoragePoolClass))) - return NULL; + goto error; if (VIR_STRDUP(ret->name, name) < 0) goto error; @@ -518,16 +506,13 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, if (virDataTypesInitialize() < 0) return NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection")); - return NULL; - } - virCheckNonNullArgReturn(pool, NULL); - virCheckNonNullArgReturn(name, NULL); - virCheckNonNullArgReturn(key, NULL); + virCheckConnectGoto(conn, error); + virCheckNonNullArgGoto(pool, error); + virCheckNonNullArgGoto(name, error); + virCheckNonNullArgGoto(key, error); if (!(ret = virObjectNew(virStorageVolClass))) - return NULL; + goto error; if (VIR_STRDUP(ret->pool, pool) < 0 || VIR_STRDUP(ret->name, name) < 0 || @@ -597,14 +582,11 @@ virGetNodeDevice(virConnectPtr conn, const char *name) if (virDataTypesInitialize() < 0) return NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection")); - return NULL; - } - virCheckNonNullArgReturn(name, NULL); + virCheckConnectGoto(conn, error); + virCheckNonNullArgGoto(name, error); if (!(ret = virObjectNew(virNodeDeviceClass))) - return NULL; + goto error; if (VIR_STRDUP(ret->name, name) < 0) goto error; @@ -664,12 +646,9 @@ virGetSecret(virConnectPtr conn, const unsigned char *uuid, if (virDataTypesInitialize() < 0) return NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection")); - return NULL; - } - virCheckNonNullArgReturn(uuid, NULL); - virCheckNonNullArgReturn(usageID, NULL); + virCheckConnectGoto(conn, error); + virCheckNonNullArgGoto(uuid, error); + virCheckNonNullArgGoto(usageID, error); if (!(ret = virObjectNew(virSecretClass))) return NULL; @@ -761,15 +740,12 @@ virGetNWFilter(virConnectPtr conn, const char *name, if (virDataTypesInitialize() < 0) return NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, "%s", _("no connection")); - return NULL; - } - virCheckNonNullArgReturn(name, NULL); - virCheckNonNullArgReturn(uuid, NULL); + virCheckConnectGoto(conn, error); + virCheckNonNullArgGoto(name, error); + virCheckNonNullArgGoto(uuid, error); if (!(ret = virObjectNew(virNWFilterClass))) - return NULL; + goto error; if (VIR_STRDUP(ret->name, name) < 0) goto error; diff --git a/src/datatypes.h b/src/datatypes.h index 7f325b0..cb0a5d9 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -42,6 +42,25 @@ extern virClassPtr virStoragePoolClass; # define VIR_IS_CONNECT(obj) \ (virObjectIsClass((obj), virConnectClass)) +# define virCheckConnectReturn(obj, retval) \ + do { \ + if (!VIR_IS_CONNECT(obj)) { \ + virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \ + __FILE__, __FUNCTION__, __LINE__, \ + __FUNCTION__); \ + virDispatchError(NULL); \ + return retval; \ + } \ + } while (0) +# define virCheckConnectGoto(obj, label) \ + do { \ + if (!VIR_IS_CONNECT(obj)) { \ + virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INVALID_CONN, \ + __FILE__, __FUNCTION__, __LINE__, \ + __FUNCTION__); \ + goto label; \ + } \ + } while (0) # define VIR_IS_DOMAIN(obj) \ (virObjectIsClass((obj), virDomainClass)) diff --git a/src/libvirt-lxc.c b/src/libvirt-lxc.c index fc56a58..ae8bc88 100644 --- a/src/libvirt-lxc.c +++ b/src/libvirt-lxc.c @@ -36,10 +36,6 @@ #define VIR_FROM_THIS VIR_FROM_NONE -#define virLibConnError(conn, error, info) \ - virReportErrorHelper(VIR_FROM_NONE, error, __FILE__, __FUNCTION__, \ - __LINE__, info) - #define virLibDomainError(domain, error, info) \ virReportErrorHelper(VIR_FROM_DOM, error, __FILE__, __FUNCTION__, \ __LINE__, info) diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c index 4aaff39..79e8e6b 100644 --- a/src/libvirt-qemu.c +++ b/src/libvirt-qemu.c @@ -30,10 +30,6 @@ #define VIR_FROM_THIS VIR_FROM_NONE -#define virLibConnError(conn, error, info) \ - virReportErrorHelper(VIR_FROM_NONE, error, __FILE__, __FUNCTION__, \ - __LINE__, info) - #define virLibDomainError(domain, error, info) \ virReportErrorHelper(VIR_FROM_DOM, error, __FILE__, __FUNCTION__, \ __LINE__, info) @@ -149,12 +145,7 @@ virDomainQemuAttach(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } - + virCheckConnectReturn(conn, NULL); virCheckPositiveArgGoto(pid_value, error); if (pid != pid_value) { virReportInvalidArg(pid_value, diff --git a/src/libvirt.c b/src/libvirt.c index 6d1601f..e0b0b32 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -1492,23 +1492,15 @@ error: int virConnectClose(virConnectPtr conn) { - int ret = -1; VIR_DEBUG("conn=%p", conn); virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - goto error; - } + virCheckConnectReturn(conn, -1); if (!virObjectUnref(conn)) return 0; return 1; - -error: - virDispatchError(NULL); - return ret; } @@ -1536,11 +1528,7 @@ virConnectRef(virConnectPtr conn) virResetLastError(); - if ((!VIR_IS_CONNECT(conn))) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); virObjectRef(conn); return 0; } @@ -1558,11 +1546,7 @@ virConnectSupportsFeature(virConnectPtr conn, int feature) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (!conn->driver->connectSupportsFeature) ret = 0; @@ -1599,11 +1583,7 @@ virConnectGetType(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); if (conn->driver->connectGetType) { ret = conn->driver->connectGetType(conn); @@ -1633,12 +1613,7 @@ virConnectGetVersion(virConnectPtr conn, unsigned long *hvVer) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(hvVer, error); if (conn->driver->connectGetVersion) { @@ -1675,12 +1650,7 @@ virConnectGetLibVersion(virConnectPtr conn, unsigned long *libVer) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(libVer, error); if (conn->driver->connectGetLibVersion) { @@ -1719,11 +1689,7 @@ virConnectGetHostname(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); if (conn->driver->connectGetHostname) { char *ret = conn->driver->connectGetHostname(conn); @@ -1763,11 +1729,7 @@ virConnectGetURI(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); if (!(name = virURIFormat(conn->uri))) goto error; @@ -1800,11 +1762,7 @@ virConnectGetSysinfo(virConnectPtr conn, unsigned int flags) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); if (conn->driver->connectGetSysinfo) { char *ret = conn->driver->connectGetSysinfo(conn, flags); @@ -1840,11 +1798,7 @@ virConnectGetMaxVcpus(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->driver->connectGetMaxVcpus) { int ret = conn->driver->connectGetMaxVcpus(conn, type); @@ -1884,12 +1838,7 @@ virConnectListDomains(virConnectPtr conn, int *ids, int maxids) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(ids, error); virCheckNonNegativeArgGoto(maxids, error); @@ -1922,11 +1871,7 @@ virConnectNumOfDomains(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->driver->connectNumOfDomains) { int ret = conn->driver->connectNumOfDomains(conn); @@ -2006,11 +1951,7 @@ virDomainCreateXML(virConnectPtr conn, const char *xmlDesc, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(xmlDesc, error); virCheckReadOnlyGoto(conn->flags, error); @@ -2075,11 +2016,7 @@ virDomainCreateXMLWithFiles(virConnectPtr conn, const char *xmlDesc, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(xmlDesc, error); virCheckReadOnlyGoto(conn->flags, error); @@ -2139,11 +2076,7 @@ virDomainLookupByID(virConnectPtr conn, int id) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNegativeArgGoto(id, error); if (conn->driver->domainLookupByID) { @@ -2179,11 +2112,7 @@ virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(uuid, error); if (conn->driver->domainLookupByUUID) { @@ -2220,11 +2149,7 @@ virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(uuidstr, error); if (virUUIDParse(uuidstr, uuid) < 0) { @@ -2259,11 +2184,7 @@ virDomainLookupByName(virConnectPtr conn, const char *name) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(name, error); if (conn->driver->domainLookupByName) { @@ -2846,11 +2767,7 @@ virDomainRestore(virConnectPtr conn, const char *from) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); virCheckReadOnlyGoto(conn->flags, error); virCheckNonNullArgGoto(from, error); @@ -2920,11 +2837,7 @@ virDomainRestoreFlags(virConnectPtr conn, const char *from, const char *dxml, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); virCheckReadOnlyGoto(conn->flags, error); virCheckNonNullArgGoto(from, error); @@ -2990,11 +2903,7 @@ virDomainSaveImageGetXMLDesc(virConnectPtr conn, const char *file, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(file, error); if ((conn->flags & VIR_CONNECT_RO) && (flags & VIR_DOMAIN_XML_SECURE)) { @@ -3067,11 +2976,7 @@ virDomainSaveImageDefineXML(virConnectPtr conn, const char *file, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); virCheckReadOnlyGoto(conn->flags, error); virCheckNonNullArgGoto(file, error); virCheckNonNullArgGoto(dxml, error); @@ -4587,11 +4492,7 @@ char *virConnectDomainXMLFromNative(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckReadOnlyGoto(conn->flags, error); virCheckNonNullArgGoto(nativeFormat, error); @@ -4640,11 +4541,7 @@ char *virConnectDomainXMLToNative(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckReadOnlyGoto(conn->flags, error); virCheckNonNullArgGoto(nativeFormat, error); @@ -5500,10 +5397,7 @@ virDomainMigrate(virDomainPtr domain, virCheckReadOnlyGoto(domain->conn->flags, error); /* Now checkout the destination */ - if (!VIR_IS_CONNECT(dconn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - goto error; - } + virCheckConnectGoto(dconn, error); virCheckReadOnlyGoto(dconn->flags, error); if (flags & VIR_MIGRATE_NON_SHARED_DISK && @@ -5733,10 +5627,7 @@ virDomainMigrate2(virDomainPtr domain, virCheckReadOnlyGoto(domain->conn->flags, error); /* Now checkout the destination */ - if (!VIR_IS_CONNECT(dconn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - goto error; - } + virCheckConnectGoto(dconn, error); virCheckReadOnlyGoto(dconn->flags, error); if (flags & VIR_MIGRATE_NON_SHARED_DISK && @@ -5917,10 +5808,7 @@ virDomainMigrate3(virDomainPtr domain, virCheckReadOnlyGoto(domain->conn->flags, error); /* Now checkout the destination */ - if (!VIR_IS_CONNECT(dconn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - goto error; - } + virCheckConnectGoto(dconn, error); virCheckReadOnlyGoto(dconn->flags, error); if (flags & VIR_MIGRATE_NON_SHARED_DISK && @@ -6519,12 +6407,7 @@ virDomainMigratePrepare(virConnectPtr dconn, virResetLastError(); - if (!VIR_IS_CONNECT(dconn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(dconn, -1); virCheckReadOnlyGoto(dconn->flags, error); if (dconn->driver->domainMigratePrepare) { @@ -6611,12 +6494,7 @@ virDomainMigrateFinish(virConnectPtr dconn, virResetLastError(); - if (!VIR_IS_CONNECT(dconn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } - + virCheckConnectReturn(dconn, NULL); virCheckReadOnlyGoto(dconn->flags, error); if (dconn->driver->domainMigrateFinish) { @@ -6659,12 +6537,7 @@ virDomainMigratePrepare2(virConnectPtr dconn, virResetLastError(); - if (!VIR_IS_CONNECT(dconn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(dconn, -1); virCheckReadOnlyGoto(dconn->flags, error); if (dconn->driver->domainMigratePrepare2) { @@ -6705,12 +6578,7 @@ virDomainMigrateFinish2(virConnectPtr dconn, virResetLastError(); - if (!VIR_IS_CONNECT(dconn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } - + virCheckConnectReturn(dconn, NULL); virCheckReadOnlyGoto(dconn->flags, error); if (dconn->driver->domainMigrateFinish2) { @@ -6750,12 +6618,7 @@ virDomainMigratePrepareTunnel(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckReadOnlyGoto(conn->flags, error); if (conn != st->conn) { @@ -6857,12 +6720,7 @@ virDomainMigratePrepare3(virConnectPtr dconn, virResetLastError(); - if (!VIR_IS_CONNECT(dconn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(dconn, -1); virCheckReadOnlyGoto(dconn->flags, error); if (dconn->driver->domainMigratePrepare3) { @@ -6910,12 +6768,7 @@ virDomainMigratePrepareTunnel3(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckReadOnlyGoto(conn->flags, error); if (conn != st->conn) { @@ -7024,12 +6877,7 @@ virDomainMigrateFinish3(virConnectPtr dconn, virResetLastError(); - if (!VIR_IS_CONNECT(dconn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } - + virCheckConnectReturn(dconn, NULL); virCheckReadOnlyGoto(dconn->flags, error); if (dconn->driver->domainMigrateFinish3) { @@ -7170,12 +7018,7 @@ virDomainMigratePrepare3Params(virConnectPtr dconn, virResetLastError(); - if (!VIR_IS_CONNECT(dconn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(dconn, -1); virCheckReadOnlyGoto(dconn->flags, error); if (dconn->driver->domainMigratePrepare3Params) { @@ -7220,12 +7063,7 @@ virDomainMigratePrepareTunnel3Params(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckReadOnlyGoto(conn->flags, error); if (conn != st->conn) { @@ -7328,12 +7166,7 @@ virDomainMigrateFinish3Params(virConnectPtr dconn, virResetLastError(); - if (!VIR_IS_CONNECT(dconn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } - + virCheckConnectReturn(dconn, NULL); virCheckReadOnlyGoto(dconn->flags, error); if (dconn->driver->domainMigrateFinish3Params) { @@ -7419,11 +7252,7 @@ virNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(info, error); if (conn->driver->nodeGetInfo) { @@ -7459,11 +7288,7 @@ virConnectGetCapabilities(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); if (conn->driver->connectGetCapabilities) { char *ret; @@ -7547,12 +7372,7 @@ virNodeGetCPUStats(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(nparams, error); virCheckNonNegativeArgGoto(*nparams, error); if (((cpuNum < 0) && (cpuNum != VIR_NODE_CPU_STATS_ALL_CPUS))) { @@ -7638,12 +7458,7 @@ virNodeGetMemoryStats(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(nparams, error); virCheckNonNegativeArgGoto(*nparams, error); if (((cellNum < 0) && (cellNum != VIR_NODE_MEMORY_STATS_ALL_CELLS))) { @@ -7685,11 +7500,7 @@ virNodeGetFreeMemory(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return 0; - } + virCheckConnectReturn(conn, 0); if (conn->driver->nodeGetFreeMemory) { unsigned long long ret; @@ -7739,12 +7550,7 @@ virNodeSuspendForDuration(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckReadOnlyGoto(conn->flags, error); if (conn->driver->nodeSuspendForDuration) { @@ -7797,12 +7603,7 @@ virNodeGetMemoryParameters(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(nparams, error); virCheckNonNegativeArgGoto(*nparams, error); if (*nparams != 0) @@ -7862,14 +7663,8 @@ virNodeSetMemoryParameters(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckReadOnlyGoto(conn->flags, error); - virCheckNonNullArgGoto(params, error); virCheckNonNegativeArgGoto(nparams, error); @@ -8977,11 +8772,7 @@ virDomainDefineXML(virConnectPtr conn, const char *xml) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckReadOnlyGoto(conn->flags, error); virCheckNonNullArgGoto(xml, error); @@ -9122,11 +8913,7 @@ virConnectNumOfDefinedDomains(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->driver->connectNumOfDefinedDomains) { int ret; @@ -9170,12 +8957,7 @@ virConnectListDefinedDomains(virConnectPtr conn, char **const names, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(names, error); virCheckNonNegativeArgGoto(maxnames, error); @@ -9279,11 +9061,7 @@ virConnectListAllDomains(virConnectPtr conn, if (domains) *domains = NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->driver->connectListAllDomains) { int ret; @@ -10739,12 +10517,7 @@ virNodeGetSecurityModel(virConnectPtr conn, virSecurityModelPtr secmodel) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(secmodel, error); if (conn->driver->nodeGetSecurityModel) { @@ -11084,12 +10857,7 @@ virNodeGetCellsFreeMemory(virConnectPtr conn, unsigned long long *freeMems, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(freeMems, error); virCheckPositiveArgGoto(maxCells, error); virCheckNonNegativeArgGoto(startCell, error); @@ -11187,11 +10955,7 @@ virConnectListAllNetworks(virConnectPtr conn, if (nets) *nets = NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->networkDriver && conn->networkDriver->connectListAllNetworks) { @@ -11225,11 +10989,7 @@ virConnectNumOfNetworks(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->networkDriver && conn->networkDriver->connectNumOfNetworks) { int ret; @@ -11270,12 +11030,7 @@ virConnectListNetworks(virConnectPtr conn, char **const names, int maxnames) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(names, error); virCheckNonNegativeArgGoto(maxnames, error); @@ -11310,11 +11065,7 @@ virConnectNumOfDefinedNetworks(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->networkDriver && conn->networkDriver->connectNumOfDefinedNetworks) { int ret; @@ -11356,12 +11107,7 @@ virConnectListDefinedNetworks(virConnectPtr conn, char **const names, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(names, error); virCheckNonNegativeArgGoto(maxnames, error); @@ -11398,11 +11144,7 @@ virNetworkLookupByName(virConnectPtr conn, const char *name) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(name, error); if (conn->networkDriver && conn->networkDriver->networkLookupByName) { @@ -11438,12 +11180,7 @@ virNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } - + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(uuid, error); if (conn->networkDriver && conn->networkDriver->networkLookupByUUID){ @@ -11480,12 +11217,7 @@ virNetworkLookupByUUIDString(virConnectPtr conn, const char *uuidstr) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } - + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(uuidstr, error); if (virUUIDParse(uuidstr, uuid) < 0) { @@ -11520,13 +11252,8 @@ virNetworkCreateXML(virConnectPtr conn, const char *xmlDesc) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(xmlDesc, error); - virCheckReadOnlyGoto(conn->flags, error); if (conn->networkDriver && conn->networkDriver->networkCreateXML) { @@ -11561,11 +11288,7 @@ virNetworkDefineXML(virConnectPtr conn, const char *xml) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckReadOnlyGoto(conn->flags, error); virCheckNonNullArgGoto(xml, error); @@ -12171,11 +11894,7 @@ virConnectListAllInterfaces(virConnectPtr conn, if (ifaces) *ifaces = NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->interfaceDriver && conn->interfaceDriver->connectListAllInterfaces) { @@ -12209,11 +11928,7 @@ virConnectNumOfInterfaces(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->interfaceDriver && conn->interfaceDriver->connectNumOfInterfaces) { int ret; @@ -12255,12 +11970,7 @@ virConnectListInterfaces(virConnectPtr conn, char **const names, int maxnames) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(names, error); virCheckNonNegativeArgGoto(maxnames, error); @@ -12295,11 +12005,7 @@ virConnectNumOfDefinedInterfaces(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->interfaceDriver && conn->interfaceDriver->connectNumOfDefinedInterfaces) { int ret; @@ -12343,12 +12049,7 @@ virConnectListDefinedInterfaces(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(names, error); virCheckNonNegativeArgGoto(maxnames, error); @@ -12385,11 +12086,7 @@ virInterfaceLookupByName(virConnectPtr conn, const char *name) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(name, error); if (conn->interfaceDriver && conn->interfaceDriver->interfaceLookupByName) { @@ -12425,11 +12122,7 @@ virInterfaceLookupByMACString(virConnectPtr conn, const char *macstr) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(macstr, error); if (conn->interfaceDriver && conn->interfaceDriver->interfaceLookupByMACString) { @@ -12577,11 +12270,7 @@ virInterfaceDefineXML(virConnectPtr conn, const char *xml, unsigned int flags) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckReadOnlyGoto(conn->flags, error); virCheckNonNullArgGoto(xml, error); @@ -12833,12 +12522,7 @@ virInterfaceChangeBegin(virConnectPtr conn, unsigned int flags) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckReadOnlyGoto(conn->flags, error); if (conn->interfaceDriver && conn->interfaceDriver->interfaceChangeBegin) { @@ -12878,12 +12562,7 @@ virInterfaceChangeCommit(virConnectPtr conn, unsigned int flags) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckReadOnlyGoto(conn->flags, error); if (conn->interfaceDriver && conn->interfaceDriver->interfaceChangeCommit) { @@ -12923,12 +12602,7 @@ virInterfaceChangeRollback(virConnectPtr conn, unsigned int flags) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckReadOnlyGoto(conn->flags, error); if (conn->interfaceDriver && @@ -13040,11 +12714,7 @@ virConnectListAllStoragePools(virConnectPtr conn, if (pools) *pools = NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->storageDriver && conn->storageDriver->connectListAllStoragePools) { @@ -13078,11 +12748,7 @@ virConnectNumOfStoragePools(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->storageDriver && conn->storageDriver->connectNumOfStoragePools) { int ret; @@ -13127,12 +12793,7 @@ virConnectListStoragePools(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(names, error); virCheckNonNegativeArgGoto(maxnames, error); @@ -13167,11 +12828,7 @@ virConnectNumOfDefinedStoragePools(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->storageDriver && conn->storageDriver->connectNumOfDefinedStoragePools) { int ret; @@ -13216,12 +12873,7 @@ virConnectListDefinedStoragePools(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(names, error); virCheckNonNegativeArgGoto(maxnames, error); @@ -13273,13 +12925,8 @@ virConnectFindStoragePoolSources(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(type, error); - virCheckReadOnlyGoto(conn->flags, error); if (conn->storageDriver && conn->storageDriver->connectFindStoragePoolSources) { @@ -13315,11 +12962,7 @@ virStoragePoolLookupByName(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(name, error); if (conn->storageDriver && conn->storageDriver->storagePoolLookupByName) { @@ -13355,11 +12998,7 @@ virStoragePoolLookupByUUID(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(uuid, error); if (conn->storageDriver && conn->storageDriver->storagePoolLookupByUUID) { @@ -13396,11 +13035,7 @@ virStoragePoolLookupByUUIDString(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(uuidstr, error); if (virUUIDParse(uuidstr, uuid) < 0) { @@ -13476,13 +13111,8 @@ virStoragePoolCreateXML(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(xmlDesc, error); - virCheckReadOnlyGoto(conn->flags, error); if (conn->storageDriver && conn->storageDriver->storagePoolCreateXML) { @@ -13521,11 +13151,7 @@ virStoragePoolDefineXML(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckReadOnlyGoto(conn->flags, error); virCheckNonNullArgGoto(xml, error); @@ -14361,12 +13987,7 @@ virStorageVolLookupByKey(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } - + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(key, error); if (conn->storageDriver && conn->storageDriver->storageVolLookupByKey) { @@ -14403,11 +14024,7 @@ virStorageVolLookupByPath(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(path, error); if (conn->storageDriver && conn->storageDriver->storageVolLookupByPath) { @@ -15150,11 +14767,7 @@ virNodeNumOfDevices(virConnectPtr conn, const char *cap, unsigned int flags) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->nodeDeviceDriver && conn->nodeDeviceDriver->nodeNumOfDevices) { int ret; @@ -15223,11 +14836,7 @@ virConnectListAllNodeDevices(virConnectPtr conn, if (devices) *devices = NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->nodeDeviceDriver && conn->nodeDeviceDriver->connectListAllNodeDevices) { @@ -15274,11 +14883,7 @@ virNodeListDevices(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(names, error); virCheckNonNegativeArgGoto(maxnames, error); @@ -15314,12 +14919,7 @@ virNodeDeviceLookupByName(virConnectPtr conn, const char *name) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } - + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(name, error); if (conn->nodeDeviceDriver && conn->nodeDeviceDriver->nodeDeviceLookupByName) { @@ -15359,12 +14959,7 @@ virNodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } - + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(wwnn, error); virCheckNonNullArgGoto(wwpn, error); @@ -15855,14 +15450,8 @@ virNodeDeviceCreateXML(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } - + virCheckConnectReturn(conn, NULL); virCheckReadOnlyGoto(conn->flags, error); - virCheckNonNullArgGoto(xmlDesc, error); if (conn->nodeDeviceDriver && @@ -15960,11 +15549,7 @@ virConnectDomainEventRegister(virConnectPtr conn, VIR_DEBUG("conn=%p, cb=%p, opaque=%p, freecb=%p", conn, cb, opaque, freecb); virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(cb, error); if ((conn->driver) && (conn->driver->connectDomainEventRegister)) { @@ -16004,11 +15589,7 @@ virConnectDomainEventDeregister(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(cb, error); if ((conn->driver) && (conn->driver->connectDomainEventDeregister)) { @@ -16069,11 +15650,7 @@ virConnectNumOfSecrets(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->secretDriver != NULL && conn->secretDriver->connectNumOfSecrets != NULL) { @@ -16138,11 +15715,7 @@ virConnectListAllSecrets(virConnectPtr conn, if (secrets) *secrets = NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->secretDriver && conn->secretDriver->connectListAllSecrets) { @@ -16178,11 +15751,7 @@ virConnectListSecrets(virConnectPtr conn, char **uuids, int maxuuids) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(uuids, error); virCheckNonNegativeArgGoto(maxuuids, error); @@ -16221,11 +15790,7 @@ virSecretLookupByUUID(virConnectPtr conn, const unsigned char *uuid) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(uuid, error); if (conn->secretDriver && @@ -16264,11 +15829,7 @@ virSecretLookupByUUIDString(virConnectPtr conn, const char *uuidstr) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(uuidstr, error); if (virUUIDParse(uuidstr, uuid) < 0) { @@ -16308,11 +15869,7 @@ virSecretLookupByUsage(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(usageID, error); if (conn->secretDriver && @@ -16354,11 +15911,7 @@ virSecretDefineXML(virConnectPtr conn, const char *xml, unsigned int flags) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckReadOnlyGoto(conn->flags, error); virCheckNonNullArgGoto(xml, error); @@ -16775,11 +16328,7 @@ virStreamNew(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); st = virGetStream(conn); if (st) @@ -17735,11 +17284,7 @@ virConnectNumOfNWFilters(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->nwfilterDriver && conn->nwfilterDriver->connectNumOfNWFilters) { int ret; @@ -17786,11 +17331,7 @@ virConnectListAllNWFilters(virConnectPtr conn, if (filters) *filters = NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->nwfilterDriver && conn->nwfilterDriver->connectListAllNWFilters) { @@ -17826,12 +17367,7 @@ virConnectListNWFilters(virConnectPtr conn, char **const names, int maxnames) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } - + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(names, error); virCheckNonNegativeArgGoto(maxnames, error); @@ -17868,11 +17404,7 @@ virNWFilterLookupByName(virConnectPtr conn, const char *name) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(name, error); if (conn->nwfilterDriver && conn->nwfilterDriver->nwfilterLookupByName) { @@ -17908,11 +17440,7 @@ virNWFilterLookupByUUID(virConnectPtr conn, const unsigned char *uuid) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(uuid, error); if (conn->nwfilterDriver && conn->nwfilterDriver->nwfilterLookupByUUID){ @@ -17949,11 +17477,7 @@ virNWFilterLookupByUUIDString(virConnectPtr conn, const char *uuidstr) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(uuidstr, error); if (virUUIDParse(uuidstr, uuid) < 0) { @@ -18106,13 +17630,8 @@ virNWFilterDefineXML(virConnectPtr conn, const char *xmlDesc) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(xmlDesc, error); - virCheckReadOnlyGoto(conn->flags, error); if (conn->nwfilterDriver && conn->nwfilterDriver->nwfilterDefineXML) { @@ -18302,11 +17821,7 @@ virConnectIsEncrypted(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->driver->connectIsEncrypted) { int ret; ret = conn->driver->connectIsEncrypted(conn); @@ -18341,11 +17856,7 @@ virConnectIsSecure(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->driver->connectIsSecure) { int ret; ret = conn->driver->connectIsSecure(conn); @@ -18380,11 +17891,7 @@ virConnectCompareCPU(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return VIR_CPU_COMPARE_ERROR; - } + virCheckConnectReturn(conn, VIR_CPU_COMPARE_ERROR); virCheckNonNullArgGoto(xmlDesc, error); if (conn->driver->connectCompareCPU) { @@ -18430,11 +17937,7 @@ virConnectGetCPUModelNames(virConnectPtr conn, const char *arch, char ***models, if (models) *models = NULL; - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); virCheckNonNullArgGoto(arch, error); if (conn->driver->connectGetCPUModelNames) { @@ -18490,11 +17993,7 @@ virConnectBaselineCPU(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return NULL; - } + virCheckConnectReturn(conn, NULL); virCheckNonNullArgGoto(xmlCPUs, error); if (conn->driver->connectBaselineCPU) { @@ -18943,11 +18442,7 @@ virConnectDomainEventRegisterAny(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (dom != NULL && !(VIR_IS_CONNECTED_DOMAIN(dom) && dom->conn == conn)) { virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); @@ -18996,11 +18491,7 @@ virConnectDomainEventDeregisterAny(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); virCheckNonNegativeArgGoto(callbackID, error); if ((conn->driver) && (conn->driver->connectDomainEventDeregisterAny)) { @@ -19064,11 +18555,7 @@ virConnectNetworkEventRegisterAny(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (net != NULL && !(VIR_IS_CONNECTED_NETWORK(net) && net->conn == conn)) { virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); @@ -19121,11 +18608,7 @@ virConnectNetworkEventDeregisterAny(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); virCheckNonNegativeArgGoto(callbackID, error); if ((conn->networkDriver) && @@ -21333,11 +20816,7 @@ virConnectSetKeepAlive(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->driver->connectSetKeepAlive) { ret = conn->driver->connectSetKeepAlive(conn, interval, count); @@ -21372,11 +20851,7 @@ virConnectIsAlive(virConnectPtr conn) virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->driver->connectIsAlive) { int ret; ret = conn->driver->connectIsAlive(conn); @@ -21425,11 +20900,7 @@ virConnectRegisterCloseCallback(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); virObjectRef(conn); @@ -21484,11 +20955,7 @@ virConnectUnregisterCloseCallback(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); virMutexLock(&conn->lock); virObjectLock(conn->closeCallback); @@ -21968,11 +21435,7 @@ virNodeGetCPUMap(virConnectPtr conn, virResetLastError(); - if (!VIR_IS_CONNECT(conn)) { - virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); - virDispatchError(NULL); - return -1; - } + virCheckConnectReturn(conn, -1); if (conn->driver->nodeGetCPUMap) { int ret = conn->driver->nodeGetCPUMap(conn, cpumap, online, flags); -- 1.8.4.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list