From 6035182b900cd667517b669962412179a08d0e1b Mon Sep 17 00:00:00 2001 From: Sergey Bronnikov Date: Mon, 9 Aug 2021 21:54:30 +0300 Subject: [PATCH] Add fault injection with 1-byte reads Closes #86 --- README.md | 2 ++ unreliablefs.conf.5 | 4 ++++ unreliablefs_errinj.c | 7 +++++++ unreliablefs_errinj.h | 1 + unreliablefs_ops.c | 2 ++ 5 files changed, 16 insertions(+) diff --git a/README.md b/README.md index cb76719..241b8d1 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/unreliablefs.conf.5 b/unreliablefs.conf.5 index 624bc25..20b828a 100644 --- a/unreliablefs.conf.5 +++ b/unreliablefs.conf.5 @@ -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: 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..4889de8 100644 --- a/unreliablefs_errinj.h +++ b/unreliablefs_errinj.h @@ -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); diff --git a/unreliablefs_ops.c b/unreliablefs_ops.c index 2e6f33d..50d8715 100644 --- a/unreliablefs_ops.c +++ b/unreliablefs_ops.c @@ -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; }