Skip to content

Commit d5103c8

Browse files
committed
Add error injection with operation slowdown
Closes #29
1 parent ecfa264 commit d5103c8

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Supported fault injections are:
1212
- `errinj_noop` - replace file operation with no operation
1313
(similar to [libeatmydata](https://github.com/stewartsmith/libeatmydata),
1414
but applicable to any file operation).
15+
- `errinj_slowdown` - slowdown invoked file operation.
1516

1617
### Building
1718

unreliablefs.conf.5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Send SIGKILL signal to a process that invoked file operation.
3434
Set random errno.
3535
.Xr errno 2
3636
limited by supported errno's.
37+
.It Cm errinj_slowdown
38+
File operation slowdown for nanoseconds specified by duration parameter.
3739
.El
3840
.Pp
3941
The options are:
@@ -52,6 +54,8 @@ POSIX Extended Regular Expression syntax is supported and regular expressions do
5254
Sets the probability in percents.
5355
Probability equal to 0 means that error injection will never happen.
5456
Probability equal to 100 means that error injection will happen on each file operation.
57+
.It Cm duration
58+
Sets the duration of file operation slowdown. Applicable to errinj_slowdown only.
5559
.El
5660
.Sh EXAMPLES
5761
.Bd -literal

unreliablefs_errinj.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ int error_inject(const char* path, fuse_op operation)
219219
fprintf(stdout, "errno '%s'\n", strerror(rc));
220220
rc = -rc;
221221
break;
222+
case ERRINJ_SLOWDOWN: ;
223+
struct timespec ts = {};
224+
ts.tv_nsec = err->duration;
225+
fprintf(stdout, "start of '%s' slowdown for '%d' ns\n", op_name, err->duration);
226+
if (nanosleep(&ts, NULL) != 0) {
227+
perror("nanosleep");
228+
} else {
229+
fprintf(stdout, "end of '%s' slowdown with '%d' ns\n", op_name, err->duration);
230+
}
231+
break;
222232
}
223233
}
224234

@@ -315,6 +325,8 @@ int conf_option_handler(void* cfg, const char* section,
315325
err->op_regexp = strdup(value);
316326
} else if (strcmp(key, "probability") == 0) {
317327
err->probability = atoi(value);
328+
} else if (strcmp(key, "duration") == 0) {
329+
err->duration = atoi(value);
318330
} else {
319331
fprintf(stderr, "unknown option '%s' in configuration file\n", key);
320332
return 0;

unreliablefs_errinj.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ const char *errinj_name[] =
3636
"errinj_errno",
3737
"errinj_kill_caller",
3838
"errinj_noop",
39+
"errinj_slowdown",
3940
};
4041

4142
typedef enum {
4243
ERRINJ_ERRNO,
4344
ERRINJ_KILL_CALLER,
4445
ERRINJ_NOOP,
46+
ERRINJ_SLOWDOWN,
4547
} errinj_type;
4648

4749
typedef struct errinj_conf errinj_conf;
@@ -52,6 +54,7 @@ struct errinj_conf {
5254
char *path_regexp;
5355
char *errno_regexp;
5456
unsigned int probability;
57+
unsigned int duration;
5558
errinj_type type;
5659

5760
TAILQ_ENTRY(errinj_conf) entries;

0 commit comments

Comments
 (0)