mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 14:57:42 +00:00
maint: improve error condition style in public API
While auditing error messages in libvirt.c, I found a couple instances that had not been converted to modern error styles, and a few places that failed to dispatch the error through the known-good connection. * src/libvirt.c (virDomainPinEmulator, virDomainGetDiskErrors) (virDomainSendKey, virDomainGetSecurityLabelList) (virDomainGetEmulatorPinInfo): Use typical error reporting. (virConnectGetCPUModelNames, virConnectRegisterCloseCallback) (virConnectUnregisterCloseCallback, virDomainGetUUID): Report error through connection. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
5e3e211dd5
commit
ca0ea2a981
@ -3599,11 +3599,15 @@ virDomainGetUUID(virDomainPtr domain, unsigned char *uuid)
|
|||||||
virDispatchError(NULL);
|
virDispatchError(NULL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
virCheckNonNullArgReturn(uuid, -1);
|
virCheckNonNullArgGoto(uuid, error);
|
||||||
|
|
||||||
memcpy(uuid, &domain->uuid[0], VIR_UUID_BUFLEN);
|
memcpy(uuid, &domain->uuid[0], VIR_UUID_BUFLEN);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
error:
|
||||||
|
virDispatchError(domain->conn);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -9882,18 +9886,22 @@ virDomainSendKey(virDomainPtr domain,
|
|||||||
|
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
if (keycodes == NULL ||
|
|
||||||
nkeycodes <= 0 || nkeycodes > VIR_DOMAIN_SEND_KEY_MAX_KEYS) {
|
|
||||||
virLibDomainError(VIR_ERR_OPERATION_INVALID, __FUNCTION__);
|
|
||||||
virDispatchError(NULL);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
|
||||||
virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
||||||
virDispatchError(NULL);
|
virDispatchError(NULL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virCheckNonNullArgGoto(keycodes, error);
|
||||||
|
virCheckPositiveArgGoto(nkeycodes, error);
|
||||||
|
|
||||||
|
if (nkeycodes > VIR_DOMAIN_SEND_KEY_MAX_KEYS) {
|
||||||
|
virReportInvalidArg(nkeycodes,
|
||||||
|
_("nkeycodes in %s must be <= %d"),
|
||||||
|
__FUNCTION__, VIR_DOMAIN_SEND_KEY_MAX_KEYS);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (domain->conn->flags & VIR_CONNECT_RO) {
|
if (domain->conn->flags & VIR_CONNECT_RO) {
|
||||||
virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
||||||
goto error;
|
goto error;
|
||||||
@ -10494,10 +10502,8 @@ virDomainPinEmulator(virDomainPtr domain, unsigned char *cpumap,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cpumap == NULL) || (maplen < 1)) {
|
virCheckNonNullArgGoto(cpumap, error);
|
||||||
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
virCheckPositiveArgGoto(maplen, error);
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
conn = domain->conn;
|
conn = domain->conn;
|
||||||
|
|
||||||
@ -10554,15 +10560,16 @@ virDomainGetEmulatorPinInfo(virDomainPtr domain, unsigned char *cpumap,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cpumap || maplen <= 0) {
|
virCheckNonNullArgGoto(cpumap, error);
|
||||||
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
virCheckPositiveArgGoto(maplen, error);
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* At most one of these two flags should be set. */
|
/* At most one of these two flags should be set. */
|
||||||
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
|
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
|
||||||
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
|
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
|
||||||
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
virReportInvalidArg(flags,
|
||||||
|
_("flags 'affect live' and 'affect config' in %s "
|
||||||
|
"are mutually exclusive"),
|
||||||
|
__FUNCTION__);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
conn = domain->conn;
|
conn = domain->conn;
|
||||||
@ -10776,10 +10783,7 @@ virDomainGetSecurityLabelList(virDomainPtr domain,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seclabels == NULL) {
|
virCheckNonNullArgGoto(seclabels, error);
|
||||||
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
conn = domain->conn;
|
conn = domain->conn;
|
||||||
|
|
||||||
@ -18840,7 +18844,7 @@ virConnectGetCPUModelNames(virConnectPtr conn, const char *arch, char ***models,
|
|||||||
virDispatchError(NULL);
|
virDispatchError(NULL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
virCheckNonNullArgReturn(arch, -1);
|
virCheckNonNullArgGoto(arch, error);
|
||||||
|
|
||||||
if (conn->driver->connectGetCPUModelNames) {
|
if (conn->driver->connectGetCPUModelNames) {
|
||||||
int ret;
|
int ret;
|
||||||
@ -21922,10 +21926,10 @@ virConnectRegisterCloseCallback(virConnectPtr conn,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
virDispatchError(conn);
|
||||||
virObjectUnlock(conn->closeCallback);
|
virObjectUnlock(conn->closeCallback);
|
||||||
virMutexUnlock(&conn->lock);
|
virMutexUnlock(&conn->lock);
|
||||||
virObjectUnref(conn);
|
virObjectUnref(conn);
|
||||||
virDispatchError(NULL);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21980,9 +21984,9 @@ virConnectUnregisterCloseCallback(virConnectPtr conn,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
virDispatchError(conn);
|
||||||
virObjectUnlock(conn->closeCallback);
|
virObjectUnlock(conn->closeCallback);
|
||||||
virMutexUnlock(&conn->lock);
|
virMutexUnlock(&conn->lock);
|
||||||
virDispatchError(NULL);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22341,10 +22345,10 @@ virDomainGetDiskErrors(virDomainPtr dom,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!errors && maxerrors) || (errors && !maxerrors)) {
|
if (maxerrors)
|
||||||
virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
|
virCheckNonNullArgGoto(errors, error);
|
||||||
goto error;
|
else
|
||||||
}
|
virCheckNullArgGoto(errors, error);
|
||||||
|
|
||||||
if (dom->conn->driver->domainGetDiskErrors) {
|
if (dom->conn->driver->domainGetDiskErrors) {
|
||||||
int ret = dom->conn->driver->domainGetDiskErrors(dom, errors,
|
int ret = dom->conn->driver->domainGetDiskErrors(dom, errors,
|
||||||
|
Loading…
Reference in New Issue
Block a user