Skip to content

Commit

Permalink
Add fault injection with 1-byte reads
Browse files Browse the repository at this point in the history
Closes #86
  • Loading branch information
ligurio committed Aug 11, 2021
1 parent d98e007 commit 6d538d0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Supported fault injections are:
(similar to [libeatmydata](https://github.com/stewartsmith/libeatmydata),
but applicable to any file operation).
- `errinj_slowdown` - slowdown invoked file operation.
- `errinj_1byte_read` - amount of data `read()` is returned is limited by 1 byte.

### Building

Expand Down
2 changes: 2 additions & 0 deletions unreliablefs.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Set random errno.
limited by supported errno's.
.It Cm errinj_slowdown
File operation slowdown for nanoseconds specified by duration parameter.
.It Cm errinj_1byte_read
Return exactly 1 byte on every read() operation.
.El
.Pp
The options are:
Expand Down
7 changes: 7 additions & 0 deletions unreliablefs_errinj.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ const char *errinj_name[] =
"errinj_kill_caller",
"errinj_noop",
"errinj_slowdown",
"errinj_1byte_read",
};

typedef enum {
ERRINJ_ERRNO,
ERRINJ_KILL_CALLER,
ERRINJ_NOOP,
ERRINJ_SLOWDOWN,
ERRINJ_1BYTE_READ,
} errinj_type;

typedef struct errinj_conf errinj_conf;
Expand Down Expand Up @@ -262,6 +264,11 @@ int error_inject(const char* path, fuse_op operation)
fprintf(stdout, "end of '%s' slowdown with '%d' ns\n", op_name, err->duration);
}
break;
case ERRINJ_1BYTE_READ:
fprintf(stdout, "start of 1-byte read\n");
if (strcmp(op_name, "read") == 0)
rc = -ERRINJ_1BYTE_READ;
break;
}
}

Expand Down
4 changes: 3 additions & 1 deletion unreliablefs_errinj.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
#define MAX_ERRINJ_NAME_LENGTH 20
#define MIN_PROBABLITY 0
#define MAX_PROBABLITY 100
#define ERRNO_NOOP -999
#define DEFAULT_SIGNAL_NAME SIGKILL

#define ERRNO_NOOP -999
#define ERRNO_1BYTE_READ -998

int error_inject(const char* path, fuse_op operation);
struct err_inj_q *config_init(const char* conf_path);
void config_delete(struct err_inj_q *config);
Expand Down
2 changes: 2 additions & 0 deletions unreliablefs_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ int unreliable_read(const char *path, char *buf, size_t size, off_t offset,
int ret = error_inject(path, OP_READ);
if (ret == -ERRNO_NOOP) {
return 0;
} else if (ret == -ERRNO_1BYTE_READ) {
size = 1;
} else if (ret) {
return ret;
}
Expand Down

0 comments on commit 6d538d0

Please sign in to comment.