mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
maint: reset error on entrance to public API
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. There are a couple of nested uses of virConnectRef (in lxc and qemu reboot paths), but they should not be affected by this change in semantics since there should not be any previous error getting nuked (a later patch will clean up the nested calls, along with abuse of virConnectClose on cleanup paths which DOES nuke errors). * 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@redhat.com>
This commit is contained in:
parent
ca0ea2a981
commit
f06d55da7b
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -929,6 +929,7 @@ virGetVersion(unsigned long *libVer, const char *type ATTRIBUTE_UNUSED,
|
||||
goto error;
|
||||
VIR_DEBUG("libVir=%p, type=%s, typeVer=%p", libVer, type, typeVer);
|
||||
|
||||
virResetLastError();
|
||||
if (libVer == NULL)
|
||||
goto error;
|
||||
*libVer = LIBVIR_VERSION_NUMBER;
|
||||
@ -1109,8 +1110,6 @@ do_open(const char *name,
|
||||
virConnectPtr ret;
|
||||
virConfPtr conf = NULL;
|
||||
|
||||
virResetLastError();
|
||||
|
||||
ret = virGetConnect();
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
@ -1543,6 +1542,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);
|
||||
@ -2471,6 +2472,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);
|
||||
@ -10731,6 +10734,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);
|
||||
@ -10777,6 +10782,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);
|
||||
@ -10846,6 +10853,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;
|
||||
@ -10933,6 +10942,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;
|
||||
@ -10993,6 +11004,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);
|
||||
@ -12106,6 +12119,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);
|
||||
@ -13075,6 +13090,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);
|
||||
@ -14146,6 +14163,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);
|
||||
@ -15273,6 +15292,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);
|
||||
@ -15808,6 +15829,8 @@ 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);
|
||||
@ -15983,6 +16006,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);
|
||||
@ -17114,6 +17139,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);
|
||||
@ -17211,6 +17238,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);
|
||||
@ -18651,6 +18680,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);
|
||||
@ -21000,6 +21031,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__);
|
||||
|
Loading…
Reference in New Issue
Block a user