Skip to content

Commit

Permalink
Add fault injection with wrong storage capacity
Browse files Browse the repository at this point in the history
Closes #62
  • Loading branch information
ligurio committed Jan 24, 2022
1 parent 33aa349 commit 50c3a08
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Supported fault injections are:
- `errinj_slowdown` - slowdown invoked file operation.
- `errinj_1byte_read` - amount of data returned by `read()` call is always
limited by a single byte.
- `errinj_wrong_capacity` - filesystem reports a wrong storage capacity, real
capacity increased for 15 percents. Simulated error can happen in a wild, for
instance see 'Fake capacity USB sticks' in
[SQLite Documentation](https://www.sqlite.org/howtocorrupt.html).

### Building

Expand Down
1 change: 1 addition & 0 deletions unreliablefs-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ description = {
- `errinj_slowdown` - slowdown invoked file operation;
- `errinj_1byte_read` - amount of data returned by `read()` call is always
limited by a single byte.
- `errinj_wrong_capacity` - filesystem reports a wrong storage capacity.
]],
homepage = "https://github.com/ligurio/unreliablefs",
maintainer = "Sergey Bronnikov <[email protected]>",
Expand Down
5 changes: 5 additions & 0 deletions unreliablefs.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ File operation slowdown for nanoseconds specified by duration parameter.
Return exactly 1 byte on every
.Xr read 2
operation.
.It Cm errinj_wrong_capacity
Report a wrong storage capacity. With enabled error injection real filesystem capacity increased for 15 percents.
.El
.Pp
The options are:
Expand Down Expand Up @@ -77,6 +79,9 @@ probability = 4
path_regexp = *.xlog
probability = 100

[errinj_wrong_capacity]
probability = 85

.Ed
.Sh SEE ALSO
.Xr unreliablefs 1 ,
Expand Down
6 changes: 6 additions & 0 deletions unreliablefs_errinj.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const char *errinj_name[] =
"errinj_noop",
"errinj_slowdown",
"errinj_1byte_read",
"errinj_wrong_capacity",
};

typedef enum {
Expand All @@ -30,6 +31,7 @@ typedef enum {
ERRINJ_NOOP,
ERRINJ_SLOWDOWN,
ERRINJ_1BYTE_READ,
ERRINJ_WRONG_CAPACITY,
} errinj_type;

typedef struct errinj_conf errinj_conf;
Expand Down Expand Up @@ -269,6 +271,10 @@ int error_inject(const char* path, fuse_op operation)
if (strcmp(op_name, "read") == 0)
rc = -ERRINJ_1BYTE_READ;
break;
case ERRINJ_WRONG_CAPACITY:
if (strcmp(op_name, "statfs") == 0)
rc = -ERRNO_WRONG_CAPACITY;
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions unreliablefs_errinj.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define MAX_PROBABLITY 100
#define ERRNO_NOOP -999
#define ERRNO_1BYTE_READ -998
#define ERRNO_WRONG_CAPACITY -997
#define DEFAULT_SIGNAL_NAME SIGKILL

int error_inject(const char* path, fuse_op operation);
Expand Down
8 changes: 8 additions & 0 deletions unreliablefs_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ int unreliable_statfs(const char *path, struct statvfs *buf)
int ret = error_inject(path, OP_STATFS);
if (ret == -ERRNO_NOOP) {
return 0;
} else if (ret == -ERRNO_WRONG_CAPACITY) {
/* wrong capacity */
ret = statvfs(path, buf);
if (ret == -1) {
return -errno;
}
buf->f_blocks = buf->f_blocks + ( 15 / 100.0 ) * (uint64_t)buf->f_blocks;
return 0;
} else if (ret) {
return ret;
}
Expand Down

0 comments on commit 50c3a08

Please sign in to comment.