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 Jan 24, 2022
1 parent 13e00b1 commit 6035182
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ 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 returned by `read()` call is always
limited by a single byte.

### Building

Expand Down
4 changes: 4 additions & 0 deletions unreliablefs.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ 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
.Xr read 2
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
1 change: 1 addition & 0 deletions unreliablefs_errinj.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define MIN_PROBABLITY 0
#define MAX_PROBABLITY 100
#define ERRNO_NOOP -999
#define ERRNO_1BYTE_READ -998
#define DEFAULT_SIGNAL_NAME SIGKILL

int error_inject(const char* path, fuse_op operation);
Expand Down
2 changes: 2 additions & 0 deletions unreliablefs_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,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 6035182

Please sign in to comment.