forked from confluentinc/kibosh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfault.h
More file actions
157 lines (137 loc) · 4.07 KB
/
fault.h
File metadata and controls
157 lines (137 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* Copyright 2017 Confluent Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef KIBOSH_FAULT_H
#define KIBOSH_FAULT_H
#include "json.h"
/**
* The maximum length of a Kibosh fault type string.
*/
#define KIBOSH_FAULT_TYPE_STR_LEN 32
/**
* Base class for Kibosh faults.
*/
struct kibosh_fault_base {
/**
* The type of fault.
*/
char type[KIBOSH_FAULT_TYPE_STR_LEN];
};
/**
* The type of kibosh_fault_unreadable.
*/
#define KIBOSH_FAULT_TYPE_UNREADABLE "unreadable"
/**
* Class for Kibosh faults that make files unreadable.
*/
struct kibosh_fault_unreadable {
/**
* The base class members.
*/
struct kibosh_fault_base base;
/**
* The path prefix.
*/
char *prefix;
/**
* The error code to return from read faults.
*/
int code;
};
struct kibosh_faults {
/**
* A NULL-terminated list of pointers to fault objects.
*/
struct kibosh_fault_base **list;
};
/**
* Allocate an empty Kibosh faults structure.
*
* @param out (out parameter) the new Kibosh faults structre
*
* @return 0 on sucess, or the negative error code on error.
*/
int faults_calloc(struct kibosh_faults **out);
/**
* Parse a JSON string as a fault object.
*
* @param str The string to parse.
*
* @return the dynamically allocated kibosh_faults structure, or NULL on error.
*/
struct kibosh_fault_base *kibosh_fault_base_parse(json_value *obj);
/**
* Convert a fault object into a JSON string.
*
* @param fault The fault object.
*
* @return A dynamically allocated JSON string on success; NULL on OOM.
*/
char *kibosh_fault_base_unparse(struct kibosh_fault_base *fault);
/**
* Check whether a given kibosh FS operation should trigger this fault.
*
* @param fault The fault structure.
* @param path The path.
* @param op The operation.
*
* @return 0 if no fault should be injected; an error code greater than 0 if we should
* inject the corresponding fault. (Note: Linux FUSE requires negative return
* codes.)
*/
int kibosh_fault_base_check(struct kibosh_fault_base *fault, const char *path, const char *op);
/**
* Free the memory associated with a fault objectg.
*
* @param fault The fault object.
*/
void kibosh_fault_base_free(struct kibosh_fault_base *fault);
/**
* Parse a JSON string as a faults object.
*
* @param str The string to parse.
* @param out (out param) the dynamically allocated kibosh_faults structure.
*
* @return 0 on success; an error code greater than 0 on failure.
*/
int faults_parse(const char *str, struct kibosh_faults **out);
/**
* Convert a faults object into a JSON string.
*
* @param faults The faults object.
*
* @return A dynamically allocated JSON string on success; NULL on OOM.
*/
char *faults_unparse(const struct kibosh_faults *faults);
/**
* Check whether a given kibosh FS operation should trigger one of the configured faults.
*
* @param faults The faults structure.
* @param path The path.
* @param op The operation.
*
* @return 0 if no fault should be injected; an error code greater than 0 if we should
* inject the corresponding fault. (Note: Linux FUSE requires negative return
* codes.)
*/
int faults_check(struct kibosh_faults *faults, const char *path, const char *op);
/**
* Free a dynamically allocated kibosh_faults structure.
*
* @param faults The structure to free.
*/
void faults_free(struct kibosh_faults *faults);
#endif
// vim: ts=4:sw=4:tw=99:et