2008-11-04 22:30:33 +00:00
|
|
|
/*
|
2014-03-07 13:38:51 +00:00
|
|
|
* virerror.h: error handling and reporting code for libvirt
|
2008-11-04 22:30:33 +00:00
|
|
|
*
|
2013-12-20 01:38:59 +00:00
|
|
|
* Copyright (C) 2006-2014 Red Hat, Inc.
|
2008-11-04 22:30:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-11-04 22:30:33 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VIRT_ERROR_H_
|
2010-03-09 18:22:22 +00:00
|
|
|
# define __VIRT_ERROR_H_
|
2008-11-04 22:30:33 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# include "internal.h"
|
2018-07-24 15:52:02 +00:00
|
|
|
# include "viralloc.h"
|
2008-11-04 22:30:33 +00:00
|
|
|
|
2017-11-22 09:28:35 +00:00
|
|
|
# define VIR_ERROR_MAX_LENGTH 1024
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
extern virErrorFunc virErrorHandler;
|
|
|
|
extern void *virUserData;
|
|
|
|
|
2009-01-20 12:01:45 +00:00
|
|
|
int virErrorInitialize(void);
|
2011-04-16 08:30:22 +00:00
|
|
|
void virRaiseErrorFull(const char *filename,
|
2009-05-27 12:10:47 +00:00
|
|
|
const char *funcname,
|
|
|
|
size_t linenr,
|
|
|
|
int domain,
|
|
|
|
int code,
|
|
|
|
virErrorLevel level,
|
|
|
|
const char *str1,
|
|
|
|
const char *str2,
|
|
|
|
const char *str3,
|
|
|
|
int int1,
|
|
|
|
int int2,
|
|
|
|
const char *fmt, ...)
|
2011-04-16 08:30:22 +00:00
|
|
|
ATTRIBUTE_FMT_PRINTF(12, 13);
|
2009-05-27 12:10:47 +00:00
|
|
|
|
2015-01-19 12:30:24 +00:00
|
|
|
void virRaiseErrorObject(const char *filename,
|
|
|
|
const char *funcname,
|
|
|
|
size_t linenr,
|
|
|
|
virErrorPtr err);
|
|
|
|
|
2011-04-16 08:30:22 +00:00
|
|
|
void virReportErrorHelper(int domcode, int errcode,
|
2011-07-08 21:58:28 +00:00
|
|
|
const char *filename,
|
|
|
|
const char *funcname,
|
|
|
|
size_t linenr,
|
2008-11-04 22:30:33 +00:00
|
|
|
const char *fmt, ...)
|
2011-04-16 08:30:22 +00:00
|
|
|
ATTRIBUTE_FMT_PRINTF(6, 7);
|
2008-11-04 22:30:33 +00:00
|
|
|
|
2010-02-04 20:02:58 +00:00
|
|
|
void virReportSystemErrorFull(int domcode,
|
2009-01-20 17:13:33 +00:00
|
|
|
int theerrno,
|
|
|
|
const char *filename,
|
|
|
|
const char *funcname,
|
|
|
|
size_t linenr,
|
|
|
|
const char *fmt, ...)
|
2010-02-04 20:02:58 +00:00
|
|
|
ATTRIBUTE_FMT_PRINTF(6, 7);
|
2009-01-20 17:13:33 +00:00
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReportSystemError(theerrno, fmt,...) \
|
|
|
|
virReportSystemErrorFull(VIR_FROM_THIS, \
|
|
|
|
(theerrno), \
|
|
|
|
__FILE__, __FUNCTION__, __LINE__, \
|
2009-01-20 17:13:33 +00:00
|
|
|
(fmt), __VA_ARGS__)
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReportInvalidNullArg(argname) \
|
|
|
|
virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
VIR_FROM_THIS, \
|
|
|
|
VIR_ERR_INVALID_ARG, \
|
|
|
|
VIR_ERR_ERROR, \
|
|
|
|
__FUNCTION__, \
|
|
|
|
#argname, \
|
|
|
|
NULL, \
|
|
|
|
0, 0, \
|
|
|
|
_("%s in %s must be NULL"), \
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
#argname, __FUNCTION__)
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReportInvalidNonNullArg(argname) \
|
|
|
|
virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
VIR_FROM_THIS, \
|
|
|
|
VIR_ERR_INVALID_ARG, \
|
|
|
|
VIR_ERR_ERROR, \
|
|
|
|
__FUNCTION__, \
|
|
|
|
#argname, \
|
|
|
|
NULL, \
|
|
|
|
0, 0, \
|
|
|
|
_("%s in %s must not be NULL"), \
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
#argname, __FUNCTION__)
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReportInvalidEmptyStringArg(argname) \
|
|
|
|
virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
VIR_FROM_THIS, \
|
|
|
|
VIR_ERR_INVALID_ARG, \
|
|
|
|
VIR_ERR_ERROR, \
|
|
|
|
__FUNCTION__, \
|
|
|
|
#argname, \
|
|
|
|
NULL, \
|
|
|
|
0, 0, \
|
|
|
|
_("string %s in %s must not be empty"), \
|
2015-06-23 15:35:16 +00:00
|
|
|
#argname, __FUNCTION__)
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReportInvalidPositiveArg(argname) \
|
|
|
|
virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
VIR_FROM_THIS, \
|
|
|
|
VIR_ERR_INVALID_ARG, \
|
|
|
|
VIR_ERR_ERROR, \
|
|
|
|
__FUNCTION__, \
|
|
|
|
#argname, \
|
|
|
|
NULL, \
|
|
|
|
0, 0, \
|
|
|
|
_("%s in %s must be greater than zero"), \
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
#argname, __FUNCTION__)
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReportInvalidNonZeroArg(argname) \
|
|
|
|
virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
VIR_FROM_THIS, \
|
|
|
|
VIR_ERR_INVALID_ARG, \
|
|
|
|
VIR_ERR_ERROR, \
|
|
|
|
__FUNCTION__, \
|
|
|
|
#argname, \
|
|
|
|
NULL, \
|
|
|
|
0, 0, \
|
|
|
|
_("%s in %s must not be zero"), \
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
#argname, __FUNCTION__)
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReportInvalidZeroArg(argname) \
|
|
|
|
virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
VIR_FROM_THIS, \
|
|
|
|
VIR_ERR_INVALID_ARG, \
|
|
|
|
VIR_ERR_ERROR, \
|
|
|
|
__FUNCTION__, \
|
|
|
|
#argname, \
|
|
|
|
NULL, \
|
|
|
|
0, 0, \
|
|
|
|
_("%s in %s must be zero"), \
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
#argname, __FUNCTION__)
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReportInvalidNonNegativeArg(argname) \
|
|
|
|
virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
VIR_FROM_THIS, \
|
|
|
|
VIR_ERR_INVALID_ARG, \
|
|
|
|
VIR_ERR_ERROR, \
|
|
|
|
__FUNCTION__, \
|
|
|
|
#argname, \
|
|
|
|
NULL, \
|
|
|
|
0, 0, \
|
|
|
|
_("%s in %s must be zero or greater"), \
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
#argname, __FUNCTION__)
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReportInvalidArg(argname, fmt, ...) \
|
|
|
|
virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
VIR_FROM_THIS, \
|
|
|
|
VIR_ERR_INVALID_ARG, \
|
|
|
|
VIR_ERR_ERROR, \
|
|
|
|
__FUNCTION__, \
|
|
|
|
#argname, \
|
|
|
|
NULL, \
|
|
|
|
0, 0, \
|
Santize the reporting of VIR_ERR_INVALID_ERROR
To ensure consistent error reporting of invalid arguments,
provide a number of predefined helper methods & macros.
- An arg which must not be NULL:
virCheckNonNullArgReturn(argname, retvalue)
virCheckNonNullArgGoto(argname, label)
- An arg which must be NULL
virCheckNullArgGoto(argname, label)
- An arg which must be positive (ie 1 or greater)
virCheckPositiveArgGoto(argname, label)
- An arg which must not be 0
virCheckNonZeroArgGoto(argname, label)
- An arg which must be zero
virCheckZeroArgGoto(argname, label)
- An arg which must not be negative (ie 0 or greater)
virCheckNonNegativeArgGoto(argname, label)
* src/libvirt.c, src/libvirt-qemu.c,
src/nodeinfo.c, src/datatypes.c: Update to use
virCheckXXXX macros
* po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
* src/internal.h: Define macros for checking invalid args
* src/util/virterror_internal.h: Define macros for reporting
invalid args
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-25 17:41:07 +00:00
|
|
|
(fmt), __VA_ARGS__)
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReportUnsupportedError() \
|
|
|
|
virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_NO_SUPPORT, \
|
2013-12-20 01:38:59 +00:00
|
|
|
__FILE__, __FUNCTION__, __LINE__, __FUNCTION__)
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReportRestrictedError(...) \
|
|
|
|
virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_OPERATION_DENIED, \
|
2013-12-20 14:02:49 +00:00
|
|
|
__FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
2018-02-20 15:56:52 +00:00
|
|
|
/* The sizeof(...) comparison here is a hack to catch typos
|
|
|
|
* in the name of the enum by triggering a compile error, as well
|
|
|
|
* as detecting if you passed a typename that refers to a function
|
|
|
|
* or struct type, instead of an enum. It should get optimized away
|
|
|
|
* since sizeof() is known at compile time */
|
|
|
|
# define virReportEnumRangeError(typname, value) \
|
|
|
|
virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INTERNAL_ERROR, \
|
|
|
|
__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
"Unexpected enum value %d for %s", \
|
2018-02-14 09:43:59 +00:00
|
|
|
value, sizeof((typname)1) != 0 ? #typname : #typname);
|
2013-12-20 01:38:59 +00:00
|
|
|
|
2010-02-04 18:19:08 +00:00
|
|
|
void virReportOOMErrorFull(int domcode,
|
2009-01-20 17:13:33 +00:00
|
|
|
const char *filename,
|
|
|
|
const char *funcname,
|
|
|
|
size_t linenr);
|
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# define virReportOOMError() \
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMErrorFull(VIR_FROM_THIS, __FILE__, __FUNCTION__, __LINE__)
|
2009-01-20 17:13:33 +00:00
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReportError(code, ...) \
|
|
|
|
virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \
|
2012-07-18 10:23:56 +00:00
|
|
|
__FUNCTION__, __LINE__, __VA_ARGS__)
|
2008-11-04 22:30:33 +00:00
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define virReportErrorObject(obj) \
|
2015-01-19 12:30:24 +00:00
|
|
|
virRaiseErrorObject(__FILE__, __FUNCTION__, __LINE__, obj)
|
|
|
|
|
2010-01-09 01:38:55 +00:00
|
|
|
int virSetError(virErrorPtr newerr);
|
2015-07-10 06:44:41 +00:00
|
|
|
virErrorPtr virErrorCopyNew(virErrorPtr err);
|
2009-09-30 15:11:47 +00:00
|
|
|
void virDispatchError(virConnectPtr conn);
|
2009-02-05 16:10:07 +00:00
|
|
|
const char *virStrerror(int theerrno, char *errBuf, size_t errBufLen);
|
2009-01-20 12:01:45 +00:00
|
|
|
|
2011-01-21 17:25:01 +00:00
|
|
|
typedef int (*virErrorLogPriorityFunc)(virErrorPtr, int);
|
|
|
|
void virSetErrorLogPriorityFunc(virErrorLogPriorityFunc func);
|
|
|
|
|
2013-07-19 10:14:51 +00:00
|
|
|
void virErrorSetErrnoFromLastError(void);
|
|
|
|
|
|
|
|
bool virLastErrorIsSystemErrno(int errnum);
|
|
|
|
|
2017-09-01 14:19:56 +00:00
|
|
|
void virErrorPreserveLast(virErrorPtr *saveerr);
|
|
|
|
void virErrorRestore(virErrorPtr *savederr);
|
|
|
|
|
2018-07-24 15:52:02 +00:00
|
|
|
VIR_DEFINE_AUTOPTR_FUNC(virError, virFreeError)
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
#endif
|