xref: /linux/drivers/md/dm-vdo/errors.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright 2023 Red Hat
4  */
5 
6 #ifndef UDS_ERRORS_H
7 #define UDS_ERRORS_H
8 
9 #include <linux/compiler.h>
10 #include <linux/types.h>
11 
12 /* Custom error codes and error-related utilities */
13 #define VDO_SUCCESS 0
14 
15 /* Valid status codes for internal UDS functions. */
16 enum uds_status_codes {
17 	/* Successful return */
18 	UDS_SUCCESS = VDO_SUCCESS,
19 	/* Used as a base value for reporting internal errors */
20 	UDS_ERROR_CODE_BASE = 1024,
21 	/* Index overflow */
22 	UDS_OVERFLOW = UDS_ERROR_CODE_BASE,
23 	/* Invalid argument passed to internal routine */
24 	UDS_INVALID_ARGUMENT,
25 	/* UDS data structures are in an invalid state */
26 	UDS_BAD_STATE,
27 	/* Attempt to enter the same name into an internal structure twice */
28 	UDS_DUPLICATE_NAME,
29 	/* An assertion failed */
30 	UDS_ASSERTION_FAILED,
31 	/* A request has been queued for later processing (not an error) */
32 	UDS_QUEUED,
33 	/* This error range has already been registered */
34 	UDS_ALREADY_REGISTERED,
35 	/* Attempt to read or write data outside the valid range */
36 	UDS_OUT_OF_RANGE,
37 	/* The index session is disabled */
38 	UDS_DISABLED,
39 	/* The index configuration or volume format is no longer supported */
40 	UDS_UNSUPPORTED_VERSION,
41 	/* Some index structure is corrupt */
42 	UDS_CORRUPT_DATA,
43 	/* No index state found */
44 	UDS_NO_INDEX,
45 	/* Attempt to access incomplete index save data */
46 	UDS_INDEX_NOT_SAVED_CLEANLY,
47 	/* One more than the last UDS_INTERNAL error code */
48 	UDS_ERROR_CODE_LAST,
49 	/* One more than the last error this block will ever use */
50 	UDS_ERROR_CODE_BLOCK_END = UDS_ERROR_CODE_BASE + 440,
51 };
52 
53 enum {
54 	VDO_MAX_ERROR_NAME_SIZE = 80,
55 	VDO_MAX_ERROR_MESSAGE_SIZE = 128,
56 };
57 
58 struct error_info {
59 	const char *name;
60 	const char *message;
61 };
62 
63 const char * __must_check uds_string_error(int errnum, char *buf, size_t buflen);
64 
65 const char *uds_string_error_name(int errnum, char *buf, size_t buflen);
66 
67 int uds_status_to_errno(int error);
68 
69 int uds_register_error_block(const char *block_name, int first_error,
70 			     int last_reserved_error, const struct error_info *infos,
71 			     size_t info_size);
72 
73 #endif /* UDS_ERRORS_H */
74