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 9, 2021
1 parent b4e9070 commit e32292b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
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
5 changes: 5 additions & 0 deletions unreliablefs_errinj.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,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
3 changes: 3 additions & 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 All @@ -37,13 +38,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
1 change: 1 addition & 0 deletions unreliablefs_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ int unreliable_read(const char *path, char *buf, size_t size, off_t offset,
return -errno;
}

/* read 1 byte in a loop */
ret = pread(fd, buf, size, offset);
if (ret == -1) {
ret = -errno;
Expand Down

0 comments on commit e32292b

Please sign in to comment.