diff --git a/README.md b/README.md index cb76719..d0053a6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/unreliablefs.conf.5 b/unreliablefs.conf.5 index 624bc25..916146f 100644 --- a/unreliablefs.conf.5 +++ b/unreliablefs.conf.5 @@ -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: diff --git a/unreliablefs_errinj.c b/unreliablefs_errinj.c index a069f4d..681de37 100644 --- a/unreliablefs_errinj.c +++ b/unreliablefs_errinj.c @@ -21,6 +21,7 @@ const char *errinj_name[] = "errinj_kill_caller", "errinj_noop", "errinj_slowdown", + "errinj_1byte_read", }; typedef enum { @@ -28,6 +29,7 @@ typedef enum { ERRINJ_KILL_CALLER, ERRINJ_NOOP, ERRINJ_SLOWDOWN, + ERRINJ_1BYTE_READ, } errinj_type; typedef struct errinj_conf errinj_conf; @@ -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; } } diff --git a/unreliablefs_errinj.h b/unreliablefs_errinj.h index 299d502..44287a4 100644 --- a/unreliablefs_errinj.h +++ b/unreliablefs_errinj.h @@ -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); diff --git a/unreliablefs_ops.c b/unreliablefs_ops.c index f9d48d5..2c20d7d 100644 --- a/unreliablefs_ops.c +++ b/unreliablefs_ops.c @@ -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; }