We document that calling any public API wipes out all prior libvirt errors in the same thread; but weren't obeying this style in a few functions. * src/libvirt.c (virGetVersion, virConnectRef, virDomainRef) (virDomainGetSecurityLabel, virDomainGetSecurityLabelList) (virDomainSetMetadata, virDomainGetMetadata) (virNodeGetSecurityModel, virNetworkRef, virInterfaceRef) (virStoragePoolRef, virStorageVolRef, virNodeDeviceGetName) (virNodeDeviceRef, virSecretRef, virStreamRef, virNWFilterRef) (virDomainSnapshotRef): Reset error on entrance. (do_open): Drop redundant error reset. * src/libvirt-qemu.c (virDomainQemuAgentCommand): Likewise. * src/libvirt-lxc.c (virDomainLxcEnterNamespace) (virDomainLxcEnterSecurityLabel): Likewise. Signed-off-by: Eric Blake <eblake@xxxxxxxxxx> --- src/libvirt-lxc.c | 4 ++++ src/libvirt-qemu.c | 4 ++++ src/libvirt.c | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/libvirt-lxc.c b/src/libvirt-lxc.c index 7ffed3e..e7b4198 100644 --- a/src/libvirt-lxc.c +++ b/src/libvirt-lxc.c @@ -142,6 +142,8 @@ virDomainLxcEnterNamespace(virDomainPtr domain, "noldfdlist=%p, oldfdlist=%p, flags=%x", nfdlist, fdlist, noldfdlist, oldfdlist, flags); + virResetLastError(); + virCheckFlagsGoto(0, error); if (noldfdlist && oldfdlist) { @@ -203,6 +205,8 @@ virDomainLxcEnterSecurityLabel(virSecurityModelPtr model, VIR_DEBUG("model=%p, label=%p, oldlabel=%p, flags=%x", model, label, oldlabel, flags); + virResetLastError(); + virCheckFlagsGoto(0, error); virCheckNonNullArgGoto(model, error); diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c index 2fa5522..71148f7 100644 --- a/src/libvirt-qemu.c +++ b/src/libvirt-qemu.c @@ -112,6 +112,7 @@ error: return -1; } + /** * virDomainQemuAttach: * @conn: pointer to a hypervisor connection @@ -186,6 +187,7 @@ error: return NULL; } + /** * virDomainQemuAgentCommand: * @domain: a domain object @@ -217,6 +219,8 @@ virDomainQemuAgentCommand(virDomainPtr domain, VIR_DOMAIN_DEBUG(domain, "cmd=%s, timeout=%d, flags=%x", cmd, timeout, flags); + virResetLastError(); + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); virDispatchError(NULL); diff --git a/src/libvirt.c b/src/libvirt.c index 7fd6072..cd1112a 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -918,6 +918,7 @@ virGetVersion(unsigned long *libVer, const char *type ATTRIBUTE_UNUSED, if (virInitialize() < 0) goto error; + virResetLastError(); if (libVer == NULL) goto error; *libVer = LIBVIR_VERSION_NUMBER; @@ -1098,8 +1099,6 @@ do_open(const char *name, virConnectPtr ret; virConfPtr conf = NULL; - virResetLastError(); - ret = virGetConnect(); if (ret == NULL) return NULL; @@ -1535,6 +1534,8 @@ virConnectRef(virConnectPtr conn) { VIR_DEBUG("conn=%p refs=%d", conn, conn ? conn->object.u.s.refs : 0); + virResetLastError(); + if ((!VIR_IS_CONNECT(conn))) { virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); virDispatchError(NULL); @@ -2463,6 +2464,8 @@ virDomainRef(virDomainPtr domain) { VIR_DOMAIN_DEBUG(domain, "refs=%d", domain ? domain->object.u.s.refs : 0); + virResetLastError(); + if ((!VIR_IS_CONNECTED_DOMAIN(domain))) { virLibConnError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__); virDispatchError(NULL); @@ -10712,6 +10715,8 @@ virDomainGetSecurityLabel(virDomainPtr domain, virSecurityLabelPtr seclabel) VIR_DOMAIN_DEBUG(domain, "seclabel=%p", seclabel); + virResetLastError(); + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__); virDispatchError(NULL); @@ -10758,6 +10763,8 @@ virDomainGetSecurityLabelList(virDomainPtr domain, VIR_DOMAIN_DEBUG(domain, "seclabels=%p", seclabels); + virResetLastError(); + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__); virDispatchError(NULL); @@ -10827,6 +10834,8 @@ virDomainSetMetadata(virDomainPtr domain, type, NULLSTR(metadata), NULLSTR(key), NULLSTR(uri), flags); + virResetLastError(); + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__); goto error; @@ -10913,6 +10922,8 @@ virDomainGetMetadata(virDomainPtr domain, VIR_DOMAIN_DEBUG(domain, "type=%d, uri='%s', flags=%x", type, NULLSTR(uri), flags); + virResetLastError(); + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__); goto error; @@ -10972,6 +10983,8 @@ virNodeGetSecurityModel(virConnectPtr conn, virSecurityModelPtr secmodel) { VIR_DEBUG("conn=%p secmodel=%p", conn, secmodel); + virResetLastError(); + if (!VIR_IS_CONNECT(conn)) { virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); virDispatchError(NULL); @@ -12085,6 +12098,8 @@ virNetworkRef(virNetworkPtr network) VIR_DEBUG("network=%p refs=%d", network, network ? network->object.u.s.refs : 0); + virResetLastError(); + if ((!VIR_IS_CONNECTED_NETWORK(network))) { virLibConnError(VIR_ERR_INVALID_NETWORK, __FUNCTION__); virDispatchError(NULL); @@ -13054,6 +13069,8 @@ virInterfaceRef(virInterfacePtr iface) { VIR_DEBUG("iface=%p refs=%d", iface, iface ? iface->object.u.s.refs : 0); + virResetLastError(); + if ((!VIR_IS_CONNECTED_INTERFACE(iface))) { virLibConnError(VIR_ERR_INVALID_INTERFACE, __FUNCTION__); virDispatchError(NULL); @@ -14125,6 +14142,8 @@ virStoragePoolRef(virStoragePoolPtr pool) { VIR_DEBUG("pool=%p refs=%d", pool, pool ? pool->object.u.s.refs : 0); + virResetLastError(); + if ((!VIR_IS_CONNECTED_STORAGE_POOL(pool))) { virLibConnError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__); virDispatchError(NULL); @@ -15252,6 +15271,8 @@ virStorageVolRef(virStorageVolPtr vol) { VIR_DEBUG("vol=%p refs=%d", vol, vol ? vol->object.u.s.refs : 0); + virResetLastError(); + if ((!VIR_IS_CONNECTED_STORAGE_VOL(vol))) { virLibConnError(VIR_ERR_INVALID_STORAGE_VOL, __FUNCTION__); virDispatchError(NULL); @@ -15784,6 +15805,8 @@ const char *virNodeDeviceGetName(virNodeDevicePtr dev) { VIR_DEBUG("dev=%p, conn=%p", dev, dev ? dev->conn : NULL); + virResetLastError(); + if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) { virLibNodeDeviceError(VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__); virDispatchError(NULL); @@ -15958,6 +15981,8 @@ virNodeDeviceRef(virNodeDevicePtr dev) { VIR_DEBUG("dev=%p refs=%d", dev, dev ? dev->object.u.s.refs : 0); + virResetLastError(); + if ((!VIR_IS_CONNECTED_NODE_DEVICE(dev))) { virLibConnError(VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__); virDispatchError(NULL); @@ -17087,6 +17112,8 @@ virSecretRef(virSecretPtr secret) VIR_DEBUG("secret=%p refs=%d", secret, secret ? secret->object.u.s.refs : 0); + virResetLastError(); + if (!VIR_IS_CONNECTED_SECRET(secret)) { virLibSecretError(VIR_ERR_INVALID_SECRET, __FUNCTION__); virDispatchError(NULL); @@ -17184,6 +17211,8 @@ virStreamRef(virStreamPtr stream) VIR_DEBUG("stream=%p refs=%d", stream, stream ? stream->object.u.s.refs : 0); + virResetLastError(); + if ((!VIR_IS_CONNECTED_STREAM(stream))) { virLibConnError(VIR_ERR_INVALID_STREAM, __FUNCTION__); virDispatchError(NULL); @@ -18624,6 +18653,8 @@ virNWFilterRef(virNWFilterPtr nwfilter) VIR_DEBUG("nwfilter=%p refs=%d", nwfilter, nwfilter ? nwfilter->object.u.s.refs : 0); + virResetLastError(); + if ((!VIR_IS_CONNECTED_NWFILTER(nwfilter))) { virLibConnError(VIR_ERR_INVALID_NWFILTER, __FUNCTION__); virDispatchError(NULL); @@ -20964,6 +20995,8 @@ virDomainSnapshotRef(virDomainSnapshotPtr snapshot) VIR_DEBUG("snapshot=%p, refs=%d", snapshot, snapshot ? snapshot->object.u.s.refs : 0); + virResetLastError(); + if ((!VIR_IS_DOMAIN_SNAPSHOT(snapshot))) { virLibDomainSnapshotError(VIR_ERR_INVALID_DOMAIN_SNAPSHOT, __FUNCTION__); -- 1.8.4.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list