1 /* 2 * virterror.h: Error handling interfaces for the libvirt library 3 * Summary: error handling interfaces for the libvirt library 4 * Description: Provides the interfaces of the libvirt library to handle 5 * errors raised while using the library. 6 * 7 * Copyright (C) 2006-2019 Red Hat, Inc. 8 * 9 * This library is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Lesser General Public 11 * License as published by the Free Software Foundation; either 12 * version 2.1 of the License, or (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this library. If not, see 21 * <http://www.gnu.org/licenses/>. 22 */ 23 24 #ifndef LIBVIRT_VIRTERROR_H 25 # define LIBVIRT_VIRTERROR_H 26 27 # include <libvirt/libvirt.h> 28 29 # ifdef __cplusplus 30 extern "C" { 31 # endif 32 33 /** 34 * virErrorLevel: 35 * 36 * Indicates the level of an error 37 */ 38 typedef enum { 39 VIR_ERR_NONE = 0, 40 VIR_ERR_WARNING = 1, /* A simple warning */ 41 VIR_ERR_ERROR = 2 /* An error */ 42 } virErrorLevel; 43 44 /** 45 * virErrorDomain: 46 * 47 * Indicates where an error may have come from. This should remain 48 * stable, with all additions placed at the end since libvirt 0.1.0. 49 */ 50 typedef enum { 51 VIR_FROM_NONE = 0, 52 VIR_FROM_XEN = 1, /* Error at Xen hypervisor layer */ 53 VIR_FROM_XEND = 2, /* Error at connection with xend daemon */ 54 VIR_FROM_XENSTORE = 3, /* Error at connection with xen store */ 55 VIR_FROM_SEXPR = 4, /* Error in the S-Expression code */ 56 57 VIR_FROM_XML = 5, /* Error in the XML code */ 58 VIR_FROM_DOM = 6, /* Error when operating on a domain */ 59 VIR_FROM_RPC = 7, /* Error in the XML-RPC code */ 60 VIR_FROM_PROXY = 8, /* Error in the proxy code; unused since 61 0.8.6 */ 62 VIR_FROM_CONF = 9, /* Error in the configuration file handling */ 63 64 VIR_FROM_QEMU = 10, /* Error at the QEMU daemon */ 65 VIR_FROM_NET = 11, /* Error when operating on a network */ 66 VIR_FROM_TEST = 12, /* Error from test driver */ 67 VIR_FROM_REMOTE = 13, /* Error from remote driver */ 68 VIR_FROM_OPENVZ = 14, /* Error from OpenVZ driver */ 69 70 VIR_FROM_XENXM = 15, /* Error at Xen XM layer */ 71 VIR_FROM_STATS_LINUX = 16, /* Error in the Linux Stats code */ 72 VIR_FROM_LXC = 17, /* Error from Linux Container driver */ 73 VIR_FROM_STORAGE = 18, /* Error from storage driver */ 74 VIR_FROM_NETWORK = 19, /* Error from network config */ 75 76 VIR_FROM_DOMAIN = 20, /* Error from domain config */ 77 VIR_FROM_UML = 21, /* Error at the UML driver; unused since 5.0.0 */ 78 VIR_FROM_NODEDEV = 22, /* Error from node device monitor */ 79 VIR_FROM_XEN_INOTIFY = 23, /* Error from xen inotify layer */ 80 VIR_FROM_SECURITY = 24, /* Error from security framework */ 81 82 VIR_FROM_VBOX = 25, /* Error from VirtualBox driver */ 83 VIR_FROM_INTERFACE = 26, /* Error when operating on an interface */ 84 VIR_FROM_ONE = 27, /* The OpenNebula driver no longer exists. 85 Retained for ABI/API compat only */ 86 VIR_FROM_ESX = 28, /* Error from ESX driver */ 87 VIR_FROM_PHYP = 29, /* Error from the phyp driver, unused since 6.0.0 */ 88 89 VIR_FROM_SECRET = 30, /* Error from secret storage */ 90 VIR_FROM_CPU = 31, /* Error from CPU driver */ 91 VIR_FROM_XENAPI = 32, /* Error from XenAPI */ 92 VIR_FROM_NWFILTER = 33, /* Error from network filter driver */ 93 VIR_FROM_HOOK = 34, /* Error from Synchronous hooks */ 94 95 VIR_FROM_DOMAIN_SNAPSHOT = 35,/* Error from domain snapshot */ 96 VIR_FROM_AUDIT = 36, /* Error from auditing subsystem */ 97 VIR_FROM_SYSINFO = 37, /* Error from sysinfo/SMBIOS */ 98 VIR_FROM_STREAMS = 38, /* Error from I/O streams */ 99 VIR_FROM_VMWARE = 39, /* Error from VMware driver */ 100 101 VIR_FROM_EVENT = 40, /* Error from event loop impl */ 102 VIR_FROM_LIBXL = 41, /* Error from libxenlight driver */ 103 VIR_FROM_LOCKING = 42, /* Error from lock manager */ 104 VIR_FROM_HYPERV = 43, /* Error from Hyper-V driver */ 105 VIR_FROM_CAPABILITIES = 44, /* Error from capabilities */ 106 107 VIR_FROM_URI = 45, /* Error from URI handling */ 108 VIR_FROM_AUTH = 46, /* Error from auth handling */ 109 VIR_FROM_DBUS = 47, /* Error from DBus */ 110 VIR_FROM_PARALLELS = 48, /* Error from Parallels */ 111 VIR_FROM_DEVICE = 49, /* Error from Device */ 112 113 VIR_FROM_SSH = 50, /* Error from libssh2 connection transport */ 114 VIR_FROM_LOCKSPACE = 51, /* Error from lockspace */ 115 VIR_FROM_INITCTL = 52, /* Error from initctl device communication */ 116 VIR_FROM_IDENTITY = 53, /* Error from identity code */ 117 VIR_FROM_CGROUP = 54, /* Error from cgroups */ 118 119 VIR_FROM_ACCESS = 55, /* Error from access control manager */ 120 VIR_FROM_SYSTEMD = 56, /* Error from systemd code */ 121 VIR_FROM_BHYVE = 57, /* Error from bhyve driver */ 122 VIR_FROM_CRYPTO = 58, /* Error from crypto code */ 123 VIR_FROM_FIREWALL = 59, /* Error from firewall */ 124 125 VIR_FROM_POLKIT = 60, /* Error from polkit code */ 126 VIR_FROM_THREAD = 61, /* Error from thread utils */ 127 VIR_FROM_ADMIN = 62, /* Error from admin backend */ 128 VIR_FROM_LOGGING = 63, /* Error from log manager */ 129 VIR_FROM_XENXL = 64, /* Error from Xen xl config code */ 130 131 VIR_FROM_PERF = 65, /* Error from perf */ 132 VIR_FROM_LIBSSH = 66, /* Error from libssh connection transport */ 133 VIR_FROM_RESCTRL = 67, /* Error from resource control */ 134 VIR_FROM_FIREWALLD = 68, /* Error from firewalld */ 135 VIR_FROM_DOMAIN_CHECKPOINT = 69, /* Error from domain checkpoint */ 136 137 VIR_FROM_TPM = 70, /* Error from TPM */ 138 VIR_FROM_BPF = 71, /* Error from BPF code */ 139 VIR_FROM_CH = 72, /* Error from Cloud-Hypervisor driver */ 140 141 # ifdef VIR_ENUM_SENTINELS 142 VIR_ERR_DOMAIN_LAST 143 # endif 144 } virErrorDomain; 145 146 147 /** 148 * virError: 149 * 150 * A libvirt Error instance. 151 * 152 * The conn, dom and net fields should be used with extreme care. 153 * Reference counts are not incremented so the underlying objects 154 * may be deleted without notice after the error has been delivered. 155 */ 156 157 typedef struct _virError virError; 158 typedef virError *virErrorPtr; 159 struct _virError { 160 int code; /* The error code, a virErrorNumber */ 161 int domain; /* What part of the library raised this error */ 162 char *message;/* human-readable informative error message */ 163 virErrorLevel level;/* how consequent is the error */ 164 virConnectPtr conn VIR_DEPRECATED; /* connection if available, deprecated 165 see note above */ 166 virDomainPtr dom VIR_DEPRECATED; /* domain if available, deprecated 167 see note above */ 168 char *str1; /* extra string information */ 169 char *str2; /* extra string information */ 170 char *str3; /* extra string information */ 171 int int1; /* extra number information */ 172 int int2; /* extra number information */ 173 virNetworkPtr net VIR_DEPRECATED; /* network if available, deprecated 174 see note above */ 175 }; 176 177 /** 178 * virErrorNumber: 179 * 180 * The full list of errors the library can generate 181 * 182 * This list should remain stable, with all additions placed at the 183 * end since libvirt 0.1.0. There is one exception: values added 184 * between libvirt 0.7.1 and libvirt 0.7.7 (VIR_WAR_NO_SECRET through 185 * VIR_ERR_MIGRATE_PERSIST_FAILED) were inadvertently relocated by 186 * four positions in 0.8.0. If you suspect version mismatch between a 187 * server and client, then you can decipher values as follows: 188 * 189 * switch (err.code) { 190 * case 60: 191 * // no way to tell VIR_WAR_NO_SECRET apart from VIR_WAR_NO_NWFILTER, 192 * // but both are very similar warnings 193 * break; 194 * case 61: case 62: case 63: 195 * if (err.domain != VIR_FROM_NWFILTER) 196 * err.code += 4; 197 * break; 198 * case 64: 199 * if (err.domain == VIR_FROM_QEMU) 200 * err.code += 4; 201 * break; 202 * case 65: 203 * if (err.domain == VIR_FROM_XEN) 204 * err.code += 4; 205 * break; 206 * default: 207 * } 208 */ 209 typedef enum { 210 VIR_ERR_OK = 0, 211 VIR_ERR_INTERNAL_ERROR = 1, /* internal error */ 212 VIR_ERR_NO_MEMORY = 2, /* memory allocation failure */ 213 VIR_ERR_NO_SUPPORT = 3, /* no support for this function */ 214 VIR_ERR_UNKNOWN_HOST = 4, /* could not resolve hostname */ 215 VIR_ERR_NO_CONNECT = 5, /* can't connect to hypervisor */ 216 VIR_ERR_INVALID_CONN = 6, /* invalid connection object */ 217 VIR_ERR_INVALID_DOMAIN = 7, /* invalid domain object */ 218 VIR_ERR_INVALID_ARG = 8, /* invalid function argument */ 219 VIR_ERR_OPERATION_FAILED = 9, /* a command to hypervisor failed */ 220 VIR_ERR_GET_FAILED = 10, /* a HTTP GET command to failed */ 221 VIR_ERR_POST_FAILED = 11, /* a HTTP POST command to failed */ 222 VIR_ERR_HTTP_ERROR = 12, /* unexpected HTTP error code */ 223 VIR_ERR_SEXPR_SERIAL = 13, /* failure to serialize an S-Expr */ 224 VIR_ERR_NO_XEN = 14, /* could not open Xen hypervisor 225 control */ 226 VIR_ERR_XEN_CALL = 15, /* failure doing an hypervisor call */ 227 VIR_ERR_OS_TYPE = 16, /* unknown OS type */ 228 VIR_ERR_NO_KERNEL = 17, /* missing kernel information */ 229 VIR_ERR_NO_ROOT = 18, /* missing root device information */ 230 VIR_ERR_NO_SOURCE = 19, /* missing source device information */ 231 VIR_ERR_NO_TARGET = 20, /* missing target device information */ 232 VIR_ERR_NO_NAME = 21, /* missing domain name information */ 233 VIR_ERR_NO_OS = 22, /* missing domain OS information */ 234 VIR_ERR_NO_DEVICE = 23, /* missing domain devices information */ 235 VIR_ERR_NO_XENSTORE = 24, /* could not open Xen Store control */ 236 VIR_ERR_DRIVER_FULL = 25, /* too many drivers registered */ 237 VIR_ERR_CALL_FAILED = 26, /* not supported by the drivers 238 (DEPRECATED) */ 239 VIR_ERR_XML_ERROR = 27, /* an XML description is not well 240 formed or broken */ 241 VIR_ERR_DOM_EXIST = 28, /* the domain already exist */ 242 VIR_ERR_OPERATION_DENIED = 29, /* operation forbidden on read-only 243 connections */ 244 VIR_ERR_OPEN_FAILED = 30, /* failed to open a conf file */ 245 VIR_ERR_READ_FAILED = 31, /* failed to read a conf file */ 246 VIR_ERR_PARSE_FAILED = 32, /* failed to parse a conf file */ 247 VIR_ERR_CONF_SYNTAX = 33, /* failed to parse the syntax of a 248 conf file */ 249 VIR_ERR_WRITE_FAILED = 34, /* failed to write a conf file */ 250 VIR_ERR_XML_DETAIL = 35, /* detail of an XML error */ 251 VIR_ERR_INVALID_NETWORK = 36, /* invalid network object */ 252 VIR_ERR_NETWORK_EXIST = 37, /* the network already exist */ 253 VIR_ERR_SYSTEM_ERROR = 38, /* general system call failure */ 254 VIR_ERR_RPC = 39, /* some sort of RPC error */ 255 VIR_ERR_GNUTLS_ERROR = 40, /* error from a GNUTLS call */ 256 VIR_WAR_NO_NETWORK = 41, /* failed to start network */ 257 VIR_ERR_NO_DOMAIN = 42, /* domain not found or unexpectedly 258 disappeared */ 259 VIR_ERR_NO_NETWORK = 43, /* network not found */ 260 VIR_ERR_INVALID_MAC = 44, /* invalid MAC address */ 261 VIR_ERR_AUTH_FAILED = 45, /* authentication failed */ 262 VIR_ERR_INVALID_STORAGE_POOL = 46, /* invalid storage pool object */ 263 VIR_ERR_INVALID_STORAGE_VOL = 47, /* invalid storage vol object */ 264 VIR_WAR_NO_STORAGE = 48, /* failed to start storage */ 265 VIR_ERR_NO_STORAGE_POOL = 49, /* storage pool not found */ 266 VIR_ERR_NO_STORAGE_VOL = 50, /* storage volume not found */ 267 VIR_WAR_NO_NODE = 51, /* failed to start node driver */ 268 VIR_ERR_INVALID_NODE_DEVICE = 52, /* invalid node device object */ 269 VIR_ERR_NO_NODE_DEVICE = 53, /* node device not found */ 270 VIR_ERR_NO_SECURITY_MODEL = 54, /* security model not found */ 271 VIR_ERR_OPERATION_INVALID = 55, /* operation is not applicable at this 272 time */ 273 VIR_WAR_NO_INTERFACE = 56, /* failed to start interface driver */ 274 VIR_ERR_NO_INTERFACE = 57, /* interface driver not running */ 275 VIR_ERR_INVALID_INTERFACE = 58, /* invalid interface object */ 276 VIR_ERR_MULTIPLE_INTERFACES = 59, /* more than one matching interface 277 found */ 278 VIR_WAR_NO_NWFILTER = 60, /* failed to start nwfilter driver */ 279 VIR_ERR_INVALID_NWFILTER = 61, /* invalid nwfilter object */ 280 VIR_ERR_NO_NWFILTER = 62, /* nw filter pool not found */ 281 VIR_ERR_BUILD_FIREWALL = 63, /* nw filter pool not found */ 282 VIR_WAR_NO_SECRET = 64, /* failed to start secret storage */ 283 VIR_ERR_INVALID_SECRET = 65, /* invalid secret */ 284 VIR_ERR_NO_SECRET = 66, /* secret not found */ 285 VIR_ERR_CONFIG_UNSUPPORTED = 67, /* unsupported configuration 286 construct */ 287 VIR_ERR_OPERATION_TIMEOUT = 68, /* timeout occurred during operation */ 288 VIR_ERR_MIGRATE_PERSIST_FAILED = 69,/* a migration worked, but making the 289 VM persist on the dest host failed */ 290 VIR_ERR_HOOK_SCRIPT_FAILED = 70, /* a synchronous hook script failed */ 291 VIR_ERR_INVALID_DOMAIN_SNAPSHOT = 71,/* invalid domain snapshot */ 292 VIR_ERR_NO_DOMAIN_SNAPSHOT = 72, /* domain snapshot not found */ 293 VIR_ERR_INVALID_STREAM = 73, /* stream pointer not valid */ 294 VIR_ERR_ARGUMENT_UNSUPPORTED = 74, /* valid API use but unsupported by 295 the given driver */ 296 VIR_ERR_STORAGE_PROBE_FAILED = 75, /* storage pool probe failed */ 297 VIR_ERR_STORAGE_POOL_BUILT = 76, /* storage pool already built */ 298 VIR_ERR_SNAPSHOT_REVERT_RISKY = 77, /* force was not requested for a 299 risky domain snapshot revert */ 300 VIR_ERR_OPERATION_ABORTED = 78, /* operation on a domain was 301 canceled/aborted by user */ 302 VIR_ERR_AUTH_CANCELLED = 79, /* authentication cancelled */ 303 VIR_ERR_NO_DOMAIN_METADATA = 80, /* The metadata is not present */ 304 VIR_ERR_MIGRATE_UNSAFE = 81, /* Migration is not safe */ 305 VIR_ERR_OVERFLOW = 82, /* integer overflow */ 306 VIR_ERR_BLOCK_COPY_ACTIVE = 83, /* action prevented by block copy job */ 307 VIR_ERR_OPERATION_UNSUPPORTED = 84, /* The requested operation is not 308 supported */ 309 VIR_ERR_SSH = 85, /* error in ssh transport driver */ 310 VIR_ERR_AGENT_UNRESPONSIVE = 86, /* guest agent is unresponsive, 311 not running or not usable */ 312 VIR_ERR_RESOURCE_BUSY = 87, /* resource is already in use */ 313 VIR_ERR_ACCESS_DENIED = 88, /* operation on the object/resource 314 was denied */ 315 VIR_ERR_DBUS_SERVICE = 89, /* error from a dbus service */ 316 VIR_ERR_STORAGE_VOL_EXIST = 90, /* the storage vol already exists */ 317 VIR_ERR_CPU_INCOMPATIBLE = 91, /* given CPU is incompatible with host CPU */ 318 VIR_ERR_XML_INVALID_SCHEMA = 92, /* XML document doesn't validate against schema */ 319 VIR_ERR_MIGRATE_FINISH_OK = 93, /* Finish API succeeded but it is expected to return NULL */ 320 VIR_ERR_AUTH_UNAVAILABLE = 94, /* authentication unavailable */ 321 VIR_ERR_NO_SERVER = 95, /* Server was not found */ 322 VIR_ERR_NO_CLIENT = 96, /* Client was not found */ 323 VIR_ERR_AGENT_UNSYNCED = 97, /* guest agent replies with wrong id 324 to guest-sync command (DEPRECATED) */ 325 VIR_ERR_LIBSSH = 98, /* error in libssh transport driver */ 326 VIR_ERR_DEVICE_MISSING = 99, /* fail to find the desired device */ 327 VIR_ERR_INVALID_NWFILTER_BINDING = 100, /* invalid nwfilter binding */ 328 VIR_ERR_NO_NWFILTER_BINDING = 101, /* no nwfilter binding */ 329 VIR_ERR_INVALID_DOMAIN_CHECKPOINT = 102, /* invalid domain checkpoint */ 330 VIR_ERR_NO_DOMAIN_CHECKPOINT = 103, /* domain checkpoint not found */ 331 VIR_ERR_NO_DOMAIN_BACKUP = 104, /* domain backup job id not found */ 332 VIR_ERR_INVALID_NETWORK_PORT = 105, /* invalid network port object */ 333 VIR_ERR_NETWORK_PORT_EXIST = 106, /* the network port already exist */ 334 VIR_ERR_NO_NETWORK_PORT = 107, /* network port not found */ 335 VIR_ERR_NO_HOSTNAME = 108, /* no domain's hostname found */ 336 VIR_ERR_CHECKPOINT_INCONSISTENT = 109, /* checkpoint can't be used */ 337 VIR_ERR_MULTIPLE_DOMAINS = 110, /* more than one matching domain found */ 338 339 # ifdef VIR_ENUM_SENTINELS 340 VIR_ERR_NUMBER_LAST 341 # endif 342 } virErrorNumber; 343 344 /** 345 * virErrorFunc: 346 * @userData: user provided data for the error callback 347 * @error: the error being raised. 348 * 349 * Signature of a function to use when there is an error raised by the library. 350 */ 351 typedef void (*virErrorFunc) (void *userData, virErrorPtr error); 352 353 /* 354 * Errors can be handled as asynchronous callbacks or after the routine 355 * failed. They can also be handled globally at the library level, or 356 * at the connection level (which then has priority). 357 */ 358 359 virErrorPtr virGetLastError (void); 360 virErrorPtr virSaveLastError (void); 361 void virResetLastError (void); 362 void virResetError (virErrorPtr err); 363 void virFreeError (virErrorPtr err); 364 365 int virGetLastErrorCode (void); 366 int virGetLastErrorDomain (void); 367 const char * virGetLastErrorMessage (void); 368 369 virErrorPtr virConnGetLastError (virConnectPtr conn); 370 void virConnResetLastError (virConnectPtr conn); 371 int virCopyLastError (virErrorPtr to); 372 373 void virDefaultErrorFunc (virErrorPtr err); 374 void virSetErrorFunc (void *userData, 375 virErrorFunc handler); 376 void virConnSetErrorFunc (virConnectPtr conn, 377 void *userData, 378 virErrorFunc handler); 379 int virConnCopyLastError (virConnectPtr conn, 380 virErrorPtr to); 381 # ifdef __cplusplus 382 } 383 # endif 384 385 #endif /* LIBVIRT_VIRTERROR_H */ 386