@mark1russell7/harness 0.16.30 → 0.16.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/build/index.d.ts +33 -3
- package/build/index.js +80 -17
- package/build/index.js.map +1 -1
- package/image/lazyfs/Dockerfile +6 -2
- package/image/lazyfs/faultfs.c +452 -0
- package/image/lazyfs/start.mts +31 -6
- package/package.json +2 -1
package/image/lazyfs/Dockerfile
CHANGED
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
# the two sources that libpcache fetches (toml11 v3.7.1 and spdlog v1.10.0), and checks the SHA-256 of
|
|
5
5
|
# each before it builds. Thus the build fetches nothing that the file does not pin.
|
|
6
6
|
#
|
|
7
|
+
# The build also compiles faultfs.c: the fault layer above LazyFS, for the kinds fsync-error, full and slow.
|
|
8
|
+
#
|
|
7
9
|
# The runtime stage has Node.js 24, thus a subject writes its files with node:sqlite or with node:fs.
|
|
8
10
|
# The container needs /dev/fuse and the capability of a mount: the disk tier starts it privileged.
|
|
9
11
|
FROM node:24.21.0-bookworm-slim@sha256:d6aa754f16b3197301076f047b5def2f02ea1dbbc2ca920407d46d7ec7f87b20 AS build
|
|
10
12
|
RUN apt-get update \
|
|
11
|
-
&& apt-get install -y --no-install-recommends g++ make cmake libfuse3-dev curl ca-certificates \
|
|
13
|
+
&& apt-get install -y --no-install-recommends gcc g++ make cmake pkg-config libfuse3-dev curl ca-certificates \
|
|
12
14
|
&& rm -rf /var/lib/apt/lists/*
|
|
13
15
|
ARG LAZYFS=3edad01aa936b81fed9bd64e47e725fc5ef6c977
|
|
14
16
|
ARG LAZYFS_SHA256=9c5004c4f704f059120daa2934a38a45002bda67ebd9e2d16a066a3499f5959d
|
|
@@ -38,13 +40,15 @@ RUN cd libs/libpcache/build \
|
|
|
38
40
|
&& mkdir -p /out/bin /out/lib \
|
|
39
41
|
&& install -m 0755 lazyfs /out/bin/lazyfs \
|
|
40
42
|
&& cp -a /src/libs/libpcache/build/libpcache.so* /out/lib/
|
|
43
|
+
COPY harness/image/lazyfs/faultfs.c /src/faultfs/faultfs.c
|
|
44
|
+
RUN gcc -O2 -Wall -Wextra -o /out/bin/faultfs /src/faultfs/faultfs.c $(pkg-config fuse3 --cflags --libs) -lpthread
|
|
41
45
|
|
|
42
46
|
FROM node:24.21.0-bookworm-slim@sha256:d6aa754f16b3197301076f047b5def2f02ea1dbbc2ca920407d46d7ec7f87b20
|
|
43
47
|
RUN apt-get update \
|
|
44
48
|
&& apt-get install -y --no-install-recommends fuse3 \
|
|
45
49
|
&& rm -rf /var/lib/apt/lists/* \
|
|
46
50
|
&& sed -i 's/^#user_allow_other/user_allow_other/' /etc/fuse.conf \
|
|
47
|
-
&& mkdir -p /etc/lazyfs /run/lazyfs /var/disk /mnt/disk /opt/subject
|
|
51
|
+
&& mkdir -p /etc/lazyfs /run/lazyfs /run/faultfs /var/disk /mnt/lazy /mnt/disk /opt/subject
|
|
48
52
|
COPY --from=build /out/bin/ /usr/local/bin/
|
|
49
53
|
# A copy of a folder keeps the links of the library (libpcache.so to libpcache.so.0)
|
|
50
54
|
COPY --from=build /out/lib/ /usr/local/lib/
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* faultfs: the fault layer of the disk tier of the harness. It is a passthrough FUSE file system above the mount of
|
|
3
|
+
* LazyFS. It applies the disk kinds of rigor-chaos that LazyFS cannot apply: fsync-error, full and slow.
|
|
4
|
+
*
|
|
5
|
+
* Usage: faultfs <lower folder> <mount> [FUSE options]
|
|
6
|
+
*
|
|
7
|
+
* The layer reads one command on each line of the FIFO /run/faultfs/commands.fifo. It writes "ok <command>" or
|
|
8
|
+
* "error <command>" to /run/faultfs/acks for each command, and one line to /run/faultfs/hits for each operation that a
|
|
9
|
+
* fault changed.
|
|
10
|
+
*
|
|
11
|
+
* fsync-error The next fsync gives EIO. The layer does not send it to LazyFS. It also writes back the old
|
|
12
|
+
* bytes of each write to the file after its last good fsync, as Linux drops the dirty pages
|
|
13
|
+
* after a failed writeback. Thus a retry of the fsync passes, but the writes are lost.
|
|
14
|
+
* fsync-error keep-dirty The next fsync gives EIO, and the layer keeps the writes. A later good fsync makes them durable.
|
|
15
|
+
* full Each write from now on gives ENOSPC.
|
|
16
|
+
* slow <ms> Each write and each fsync from now on waits <ms> ms first.
|
|
17
|
+
*
|
|
18
|
+
* To write back the old bytes, the layer keeps them for each write until the next good fsync of the file. A subject that
|
|
19
|
+
* writes much data with no fsync thus uses that much memory. The subjects of the disk tier are small.
|
|
20
|
+
*/
|
|
21
|
+
#define FUSE_USE_VERSION 31
|
|
22
|
+
#define _GNU_SOURCE
|
|
23
|
+
#include <fuse.h>
|
|
24
|
+
#include <dirent.h>
|
|
25
|
+
#include <errno.h>
|
|
26
|
+
#include <fcntl.h>
|
|
27
|
+
#include <pthread.h>
|
|
28
|
+
#include <stdio.h>
|
|
29
|
+
#include <stdlib.h>
|
|
30
|
+
#include <string.h>
|
|
31
|
+
#include <sys/stat.h>
|
|
32
|
+
#include <sys/statvfs.h>
|
|
33
|
+
#include <time.h>
|
|
34
|
+
#include <unistd.h>
|
|
35
|
+
|
|
36
|
+
#define COMMANDS "/run/faultfs/commands.fifo"
|
|
37
|
+
#define ACKS "/run/faultfs/acks"
|
|
38
|
+
#define HITS "/run/faultfs/hits"
|
|
39
|
+
|
|
40
|
+
/* The lower folder: the mount of LazyFS. */
|
|
41
|
+
static int root = -1;
|
|
42
|
+
|
|
43
|
+
/* The faults. The lock also keeps each write and its old bytes together. */
|
|
44
|
+
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
|
45
|
+
static int fsync_error = 0;
|
|
46
|
+
static int keep_dirty = 0;
|
|
47
|
+
static int full = 0;
|
|
48
|
+
static long slow_ms = 0;
|
|
49
|
+
|
|
50
|
+
/* The old bytes of one write. */
|
|
51
|
+
struct change {
|
|
52
|
+
off_t off;
|
|
53
|
+
size_t len;
|
|
54
|
+
char *old;
|
|
55
|
+
struct change *next;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/* The writes to one file after its last good fsync, the newest first, and the size of the file at that fsync. */
|
|
59
|
+
struct undo {
|
|
60
|
+
dev_t dev;
|
|
61
|
+
ino_t ino;
|
|
62
|
+
off_t size;
|
|
63
|
+
struct change *changes;
|
|
64
|
+
struct undo *next;
|
|
65
|
+
};
|
|
66
|
+
static struct undo *undos = NULL;
|
|
67
|
+
|
|
68
|
+
static const char *rel(const char *path) { return path[1] == '\0' ? "." : path + 1; }
|
|
69
|
+
|
|
70
|
+
static void hit(const char *op, const char *what, const char *path) {
|
|
71
|
+
FILE *file = fopen(HITS, "a");
|
|
72
|
+
if (file == NULL) return;
|
|
73
|
+
fprintf(file, "%s %s %s\n", op, what, path);
|
|
74
|
+
fclose(file);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static void pause_ms(long ms) {
|
|
78
|
+
struct timespec ts = {ms / 1000, (ms % 1000) * 1000000L};
|
|
79
|
+
while (nanosleep(&ts, &ts) == -1 && errno == EINTR) {
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static long slow_now(void) {
|
|
84
|
+
pthread_mutex_lock(&lock);
|
|
85
|
+
long ms = slow_ms;
|
|
86
|
+
pthread_mutex_unlock(&lock);
|
|
87
|
+
return ms;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* This function gives the undo list of a file, and makes it at the first write after a good fsync. Call it with the lock. */
|
|
91
|
+
static struct undo *undo_of(int fd, struct stat *st) {
|
|
92
|
+
if (fstat(fd, st) == -1) return NULL;
|
|
93
|
+
for (struct undo *u = undos; u != NULL; u = u->next)
|
|
94
|
+
if (u->dev == st->st_dev && u->ino == st->st_ino) return u;
|
|
95
|
+
struct undo *u = calloc(1, sizeof *u);
|
|
96
|
+
if (u == NULL) return NULL;
|
|
97
|
+
u->dev = st->st_dev;
|
|
98
|
+
u->ino = st->st_ino;
|
|
99
|
+
u->size = st->st_size;
|
|
100
|
+
u->next = undos;
|
|
101
|
+
undos = u;
|
|
102
|
+
return u;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* This function keeps the old bytes of the range [off, off + len) of a file before a change. Call it with the lock. */
|
|
106
|
+
static int keep_old(int fd, off_t off, size_t len) {
|
|
107
|
+
struct stat st;
|
|
108
|
+
struct undo *u = undo_of(fd, &st);
|
|
109
|
+
if (u == NULL) return -ENOMEM;
|
|
110
|
+
size_t have = off >= st.st_size ? 0 : (size_t)(st.st_size - off) < len ? (size_t)(st.st_size - off) : len;
|
|
111
|
+
if (have == 0) return 0;
|
|
112
|
+
struct change *c = calloc(1, sizeof *c);
|
|
113
|
+
char *old = malloc(have);
|
|
114
|
+
if (c == NULL || old == NULL) {
|
|
115
|
+
free(c);
|
|
116
|
+
free(old);
|
|
117
|
+
return -ENOMEM;
|
|
118
|
+
}
|
|
119
|
+
ssize_t got = pread(fd, old, have, off);
|
|
120
|
+
if (got < 0) {
|
|
121
|
+
free(c);
|
|
122
|
+
free(old);
|
|
123
|
+
return -errno;
|
|
124
|
+
}
|
|
125
|
+
c->off = off;
|
|
126
|
+
c->len = (size_t)got;
|
|
127
|
+
c->old = old;
|
|
128
|
+
c->next = u->changes;
|
|
129
|
+
u->changes = c;
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* This function removes the undo list of a file, and gives it to the caller. Call it with the lock. */
|
|
134
|
+
static struct undo *take_undo(int fd) {
|
|
135
|
+
struct stat st;
|
|
136
|
+
if (fstat(fd, &st) == -1) return NULL;
|
|
137
|
+
for (struct undo **p = &undos; *p != NULL; p = &(*p)->next) {
|
|
138
|
+
if ((*p)->dev == st.st_dev && (*p)->ino == st.st_ino) {
|
|
139
|
+
struct undo *u = *p;
|
|
140
|
+
*p = u->next;
|
|
141
|
+
return u;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return NULL;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static void free_undo(struct undo *u) {
|
|
148
|
+
if (u == NULL) return;
|
|
149
|
+
for (struct change *c = u->changes; c != NULL;) {
|
|
150
|
+
struct change *next = c->next;
|
|
151
|
+
free(c->old);
|
|
152
|
+
free(c);
|
|
153
|
+
c = next;
|
|
154
|
+
}
|
|
155
|
+
free(u);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/* This function writes back the old bytes, the newest write first, and sets the size of the file at its last good fsync. */
|
|
159
|
+
static void write_back(int fd, struct undo *u) {
|
|
160
|
+
if (u == NULL) return;
|
|
161
|
+
for (struct change *c = u->changes; c != NULL; c = c->next)
|
|
162
|
+
if (pwrite(fd, c->old, c->len, c->off) == -1) perror("faultfs: write back");
|
|
163
|
+
if (ftruncate(fd, u->size) == -1) perror("faultfs: truncate back");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
static void *ff_init(struct fuse_conn_info *conn, struct fuse_config *cfg) {
|
|
167
|
+
cfg->use_ino = 1;
|
|
168
|
+
cfg->entry_timeout = 0;
|
|
169
|
+
cfg->attr_timeout = 0;
|
|
170
|
+
cfg->negative_timeout = 0;
|
|
171
|
+
cfg->kernel_cache = 0;
|
|
172
|
+
/* An open with O_TRUNC then comes as a truncate, and the layer keeps the old bytes. */
|
|
173
|
+
conn->want &= ~FUSE_CAP_ATOMIC_O_TRUNC;
|
|
174
|
+
return NULL;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
static int ff_getattr(const char *path, struct stat *st, struct fuse_file_info *fi) {
|
|
178
|
+
int r = fi != NULL ? fstat((int)fi->fh, st) : fstatat(root, rel(path), st, AT_SYMLINK_NOFOLLOW);
|
|
179
|
+
return r == -1 ? -errno : 0;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
static int ff_access(const char *path, int mask) { return faccessat(root, rel(path), mask, 0) == -1 ? -errno : 0; }
|
|
183
|
+
|
|
184
|
+
static int ff_readlink(const char *path, char *buf, size_t size) {
|
|
185
|
+
ssize_t n = readlinkat(root, rel(path), buf, size - 1);
|
|
186
|
+
if (n == -1) return -errno;
|
|
187
|
+
buf[n] = '\0';
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
static int ff_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t off, struct fuse_file_info *fi,
|
|
192
|
+
enum fuse_readdir_flags flags) {
|
|
193
|
+
(void)off;
|
|
194
|
+
(void)fi;
|
|
195
|
+
(void)flags;
|
|
196
|
+
int fd = openat(root, rel(path), O_RDONLY | O_DIRECTORY);
|
|
197
|
+
if (fd == -1) return -errno;
|
|
198
|
+
DIR *dir = fdopendir(fd);
|
|
199
|
+
if (dir == NULL) {
|
|
200
|
+
int e = errno;
|
|
201
|
+
close(fd);
|
|
202
|
+
return -e;
|
|
203
|
+
}
|
|
204
|
+
struct dirent *de;
|
|
205
|
+
while ((de = readdir(dir)) != NULL) {
|
|
206
|
+
struct stat st;
|
|
207
|
+
memset(&st, 0, sizeof st);
|
|
208
|
+
st.st_ino = de->d_ino;
|
|
209
|
+
st.st_mode = (mode_t)de->d_type << 12;
|
|
210
|
+
if (filler(buf, de->d_name, &st, 0, 0) != 0) break;
|
|
211
|
+
}
|
|
212
|
+
closedir(dir);
|
|
213
|
+
return 0;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
static int ff_mknod(const char *path, mode_t mode, dev_t rdev) {
|
|
217
|
+
int r = S_ISFIFO(mode) ? mkfifoat(root, rel(path), mode) : mknodat(root, rel(path), mode, rdev);
|
|
218
|
+
return r == -1 ? -errno : 0;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
static int ff_mkdir(const char *path, mode_t mode) { return mkdirat(root, rel(path), mode) == -1 ? -errno : 0; }
|
|
222
|
+
static int ff_unlink(const char *path) { return unlinkat(root, rel(path), 0) == -1 ? -errno : 0; }
|
|
223
|
+
static int ff_rmdir(const char *path) { return unlinkat(root, rel(path), AT_REMOVEDIR) == -1 ? -errno : 0; }
|
|
224
|
+
static int ff_symlink(const char *from, const char *to) { return symlinkat(from, root, rel(to)) == -1 ? -errno : 0; }
|
|
225
|
+
|
|
226
|
+
static int ff_rename(const char *from, const char *to, unsigned int flags) {
|
|
227
|
+
return renameat2(root, rel(from), root, rel(to), flags) == -1 ? -errno : 0;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
static int ff_link(const char *from, const char *to) { return linkat(root, rel(from), root, rel(to), 0) == -1 ? -errno : 0; }
|
|
231
|
+
|
|
232
|
+
static int ff_chmod(const char *path, mode_t mode, struct fuse_file_info *fi) {
|
|
233
|
+
int r = fi != NULL ? fchmod((int)fi->fh, mode) : fchmodat(root, rel(path), mode, 0);
|
|
234
|
+
return r == -1 ? -errno : 0;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
static int ff_chown(const char *path, uid_t uid, gid_t gid, struct fuse_file_info *fi) {
|
|
238
|
+
int r = fi != NULL ? fchown((int)fi->fh, uid, gid) : fchownat(root, rel(path), uid, gid, AT_SYMLINK_NOFOLLOW);
|
|
239
|
+
return r == -1 ? -errno : 0;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
static int ff_truncate(const char *path, off_t size, struct fuse_file_info *fi) {
|
|
243
|
+
int fd = fi != NULL ? (int)fi->fh : openat(root, rel(path), O_RDWR);
|
|
244
|
+
if (fd == -1) return -errno;
|
|
245
|
+
pthread_mutex_lock(&lock);
|
|
246
|
+
struct stat st;
|
|
247
|
+
int r = fstat(fd, &st) == -1 ? -errno : 0;
|
|
248
|
+
if (r == 0 && size < st.st_size) r = keep_old(fd, size, (size_t)(st.st_size - size));
|
|
249
|
+
else if (r == 0) r = undo_of(fd, &st) == NULL ? -ENOMEM : 0;
|
|
250
|
+
if (r == 0 && ftruncate(fd, size) == -1) r = -errno;
|
|
251
|
+
pthread_mutex_unlock(&lock);
|
|
252
|
+
if (fi == NULL) close(fd);
|
|
253
|
+
return r;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
static int ff_utimens(const char *path, const struct timespec ts[2], struct fuse_file_info *fi) {
|
|
257
|
+
int r = fi != NULL ? futimens((int)fi->fh, ts) : utimensat(root, rel(path), ts, AT_SYMLINK_NOFOLLOW);
|
|
258
|
+
return r == -1 ? -errno : 0;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/*
|
|
262
|
+
* This function opens the lower file to read and write when it can: the layer reads the old bytes before a write, and
|
|
263
|
+
* writes them back after a failed fsync. It does not give O_APPEND to the lower file: a write gets its offset from the
|
|
264
|
+
* size of the file, under the lock.
|
|
265
|
+
*/
|
|
266
|
+
static int open_lower(const char *path, int flags, mode_t mode) {
|
|
267
|
+
int lower = flags & ~O_APPEND;
|
|
268
|
+
if ((flags & O_ACCMODE) != O_RDWR) {
|
|
269
|
+
int fd = openat(root, rel(path), (lower & ~O_ACCMODE) | O_RDWR, mode);
|
|
270
|
+
if (fd != -1) return fd;
|
|
271
|
+
}
|
|
272
|
+
return openat(root, rel(path), lower, mode);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
static int ff_create(const char *path, mode_t mode, struct fuse_file_info *fi) {
|
|
276
|
+
int fd = open_lower(path, fi->flags, mode);
|
|
277
|
+
if (fd == -1) return -errno;
|
|
278
|
+
fi->fh = (uint64_t)fd;
|
|
279
|
+
return 0;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
static int ff_open(const char *path, struct fuse_file_info *fi) {
|
|
283
|
+
int fd = open_lower(path, fi->flags, 0);
|
|
284
|
+
if (fd == -1) return -errno;
|
|
285
|
+
fi->fh = (uint64_t)fd;
|
|
286
|
+
return 0;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
static int ff_read(const char *path, char *buf, size_t size, off_t off, struct fuse_file_info *fi) {
|
|
290
|
+
(void)path;
|
|
291
|
+
ssize_t n = pread((int)fi->fh, buf, size, off);
|
|
292
|
+
return n == -1 ? -errno : (int)n;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
static int ff_write(const char *path, const char *buf, size_t size, off_t off, struct fuse_file_info *fi) {
|
|
296
|
+
long ms = slow_now();
|
|
297
|
+
if (ms > 0) {
|
|
298
|
+
hit("write", "slow", path);
|
|
299
|
+
pause_ms(ms);
|
|
300
|
+
}
|
|
301
|
+
int fd = (int)fi->fh;
|
|
302
|
+
pthread_mutex_lock(&lock);
|
|
303
|
+
if (full) {
|
|
304
|
+
pthread_mutex_unlock(&lock);
|
|
305
|
+
hit("write", "ENOSPC", path);
|
|
306
|
+
return -ENOSPC;
|
|
307
|
+
}
|
|
308
|
+
if (fi->flags & O_APPEND) {
|
|
309
|
+
struct stat st;
|
|
310
|
+
if (fstat(fd, &st) == -1) {
|
|
311
|
+
int e = errno;
|
|
312
|
+
pthread_mutex_unlock(&lock);
|
|
313
|
+
return -e;
|
|
314
|
+
}
|
|
315
|
+
off = st.st_size;
|
|
316
|
+
}
|
|
317
|
+
int r = keep_old(fd, off, size);
|
|
318
|
+
ssize_t n = r == 0 ? pwrite(fd, buf, size, off) : -1;
|
|
319
|
+
if (n == -1 && r == 0) r = -errno;
|
|
320
|
+
pthread_mutex_unlock(&lock);
|
|
321
|
+
return r != 0 ? r : (int)n;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
static int ff_statfs(const char *path, struct statvfs *st) {
|
|
325
|
+
(void)path;
|
|
326
|
+
return fstatvfs(root, st) == -1 ? -errno : 0;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
static int ff_release(const char *path, struct fuse_file_info *fi) {
|
|
330
|
+
(void)path;
|
|
331
|
+
close((int)fi->fh);
|
|
332
|
+
return 0;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
static int ff_fsync(const char *path, int datasync, struct fuse_file_info *fi) {
|
|
336
|
+
long ms = slow_now();
|
|
337
|
+
if (ms > 0) {
|
|
338
|
+
hit("fsync", "slow", path);
|
|
339
|
+
pause_ms(ms);
|
|
340
|
+
}
|
|
341
|
+
int fd = (int)fi->fh;
|
|
342
|
+
pthread_mutex_lock(&lock);
|
|
343
|
+
if (fsync_error) {
|
|
344
|
+
fsync_error = 0;
|
|
345
|
+
if (!keep_dirty) {
|
|
346
|
+
struct undo *u = take_undo(fd);
|
|
347
|
+
write_back(fd, u);
|
|
348
|
+
free_undo(u);
|
|
349
|
+
}
|
|
350
|
+
pthread_mutex_unlock(&lock);
|
|
351
|
+
hit("fsync", "EIO", path);
|
|
352
|
+
return -EIO;
|
|
353
|
+
}
|
|
354
|
+
int r = (datasync ? fdatasync(fd) : fsync(fd)) == -1 ? -errno : 0;
|
|
355
|
+
if (r == 0) free_undo(take_undo(fd));
|
|
356
|
+
pthread_mutex_unlock(&lock);
|
|
357
|
+
return r;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/* This function applies one command, and gives 0, or -1 for a command that it does not know. */
|
|
361
|
+
static int apply(const char *line) {
|
|
362
|
+
long ms;
|
|
363
|
+
char rest;
|
|
364
|
+
int r = 0;
|
|
365
|
+
pthread_mutex_lock(&lock);
|
|
366
|
+
if (strcmp(line, "fsync-error") == 0) {
|
|
367
|
+
fsync_error = 1;
|
|
368
|
+
keep_dirty = 0;
|
|
369
|
+
} else if (strcmp(line, "fsync-error keep-dirty") == 0) {
|
|
370
|
+
fsync_error = 1;
|
|
371
|
+
keep_dirty = 1;
|
|
372
|
+
} else if (strcmp(line, "full") == 0) {
|
|
373
|
+
full = 1;
|
|
374
|
+
} else if (sscanf(line, "slow %ld%c", &ms, &rest) == 1 && ms >= 1) {
|
|
375
|
+
slow_ms = ms;
|
|
376
|
+
} else {
|
|
377
|
+
r = -1;
|
|
378
|
+
}
|
|
379
|
+
pthread_mutex_unlock(&lock);
|
|
380
|
+
return r;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/* The thread of the commands. The open to read and write does not wait for a writer, and it does not see an end. */
|
|
384
|
+
static void *commands(void *arg) {
|
|
385
|
+
(void)arg;
|
|
386
|
+
FILE *in = fopen(COMMANDS, "r+");
|
|
387
|
+
if (in == NULL) {
|
|
388
|
+
perror("faultfs: " COMMANDS);
|
|
389
|
+
return NULL;
|
|
390
|
+
}
|
|
391
|
+
char *line = NULL;
|
|
392
|
+
size_t cap = 0;
|
|
393
|
+
ssize_t n;
|
|
394
|
+
while ((n = getline(&line, &cap, in)) != -1) {
|
|
395
|
+
while (n > 0 && (line[n - 1] == '\n' || line[n - 1] == '\r')) line[--n] = '\0';
|
|
396
|
+
if (n == 0) continue;
|
|
397
|
+
int r = apply(line);
|
|
398
|
+
FILE *acks = fopen(ACKS, "a");
|
|
399
|
+
if (acks != NULL) {
|
|
400
|
+
fprintf(acks, "%s %s\n", r == 0 ? "ok" : "error", line);
|
|
401
|
+
fclose(acks);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
free(line);
|
|
405
|
+
return NULL;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
static const struct fuse_operations ops = {
|
|
409
|
+
.init = ff_init,
|
|
410
|
+
.getattr = ff_getattr,
|
|
411
|
+
.access = ff_access,
|
|
412
|
+
.readlink = ff_readlink,
|
|
413
|
+
.readdir = ff_readdir,
|
|
414
|
+
.mknod = ff_mknod,
|
|
415
|
+
.mkdir = ff_mkdir,
|
|
416
|
+
.unlink = ff_unlink,
|
|
417
|
+
.rmdir = ff_rmdir,
|
|
418
|
+
.symlink = ff_symlink,
|
|
419
|
+
.rename = ff_rename,
|
|
420
|
+
.link = ff_link,
|
|
421
|
+
.chmod = ff_chmod,
|
|
422
|
+
.chown = ff_chown,
|
|
423
|
+
.truncate = ff_truncate,
|
|
424
|
+
.utimens = ff_utimens,
|
|
425
|
+
.create = ff_create,
|
|
426
|
+
.open = ff_open,
|
|
427
|
+
.read = ff_read,
|
|
428
|
+
.write = ff_write,
|
|
429
|
+
.statfs = ff_statfs,
|
|
430
|
+
.release = ff_release,
|
|
431
|
+
.fsync = ff_fsync,
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
int main(int argc, char *argv[]) {
|
|
435
|
+
if (argc < 3) {
|
|
436
|
+
fprintf(stderr, "Usage: faultfs <lower folder> <mount> [FUSE options]\n");
|
|
437
|
+
return 2;
|
|
438
|
+
}
|
|
439
|
+
root = open(argv[1], O_RDONLY | O_DIRECTORY);
|
|
440
|
+
if (root == -1) {
|
|
441
|
+
perror(argv[1]);
|
|
442
|
+
return 1;
|
|
443
|
+
}
|
|
444
|
+
pthread_t thread;
|
|
445
|
+
if (pthread_create(&thread, NULL, commands, NULL) != 0) {
|
|
446
|
+
fprintf(stderr, "faultfs: the thread of the commands did not start\n");
|
|
447
|
+
return 1;
|
|
448
|
+
}
|
|
449
|
+
pthread_detach(thread);
|
|
450
|
+
argv[1] = argv[0];
|
|
451
|
+
return fuse_main(argc - 1, argv + 1, &ops, NULL);
|
|
452
|
+
}
|
package/image/lazyfs/start.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The command of the image `lazyfs`. It starts LazyFS in the foreground: `/mnt/
|
|
3
|
-
* holds the files.
|
|
2
|
+
* The command of the image `lazyfs`. It starts LazyFS in the foreground: `/mnt/lazy` is its mount, and `/var/disk`
|
|
3
|
+
* holds the files. After the mount of LazyFS, it starts the fault layer `faultfs` with `/mnt/disk` as its mount, above
|
|
4
|
+
* `/mnt/lazy`. The subject writes in `/mnt/disk`. Node.js 24 of the image strips the types of this file.
|
|
4
5
|
*
|
|
5
6
|
* LazyFS opens `done.fifo` to write, and that open waits for a reader. LazyFS gets a reader of `done.fifo` as its
|
|
6
7
|
* descriptor 3, and this process keeps the reader open. Thus LazyFS starts at once, and a write after a reader went away
|
|
@@ -11,10 +12,11 @@
|
|
|
11
12
|
*
|
|
12
13
|
* This process is PID 1 of the container. It gives `SIGTERM` and `SIGINT` to LazyFS, and it ends with the exit of LazyFS.
|
|
13
14
|
* When the file `armed` exists, the end of LazyFS is a fault: this process writes the exit of LazyFS to `exit`, and keeps
|
|
14
|
-
* the container for the check until a signal.
|
|
15
|
+
* the container for the check until a signal. A crash of LazyFS does not stop `faultfs`: each operation of the subject
|
|
16
|
+
* then gives an error.
|
|
15
17
|
*/
|
|
16
18
|
import { execFileSync, spawn } from "node:child_process";
|
|
17
|
-
import { appendFileSync, constants, existsSync, openSync, writeFileSync } from "node:fs";
|
|
19
|
+
import { appendFileSync, constants, existsSync, openSync, readFileSync, writeFileSync } from "node:fs";
|
|
18
20
|
import { constants as os } from "node:os";
|
|
19
21
|
import type { Readable } from "node:stream";
|
|
20
22
|
|
|
@@ -23,13 +25,16 @@ const DONE = "/run/lazyfs/done.fifo";
|
|
|
23
25
|
const ARMED = "/run/lazyfs/armed";
|
|
24
26
|
const EXIT = "/run/lazyfs/exit";
|
|
25
27
|
const ACKS = "/run/lazyfs/acks";
|
|
28
|
+
const COMMANDS = "/run/faultfs/commands.fifo";
|
|
29
|
+
/** The time in ms between two reads of the mounts while LazyFS starts. */
|
|
30
|
+
const MOUNT_POLL_MS = 50;
|
|
26
31
|
|
|
27
|
-
execFileSync("mkfifo", [FAULTS, DONE], { stdio: "inherit" });
|
|
32
|
+
execFileSync("mkfifo", [FAULTS, DONE, COMMANDS], { stdio: "inherit" });
|
|
28
33
|
// On Linux, an open of a FIFO to read and write does not wait for the other end, the same as `exec 3<>` of a shell
|
|
29
34
|
const reader = openSync(DONE, constants.O_RDWR);
|
|
30
35
|
const lazyfs = spawn(
|
|
31
36
|
"/usr/local/bin/lazyfs",
|
|
32
|
-
["/mnt/
|
|
37
|
+
["/mnt/lazy", "--config-path", "/etc/lazyfs/config.toml", "-o", "allow_other", "-o", "modules=subdir", "-o", "subdir=/var/disk", "-f"],
|
|
33
38
|
{ stdio: ["inherit", "pipe", "pipe", reader] },
|
|
34
39
|
);
|
|
35
40
|
|
|
@@ -49,10 +54,29 @@ const watch = (from: Readable, to: NodeJS.WriteStream): void => {
|
|
|
49
54
|
if (lazyfs.stdout !== null) watch(lazyfs.stdout, process.stdout);
|
|
50
55
|
if (lazyfs.stderr !== null) watch(lazyfs.stderr, process.stderr);
|
|
51
56
|
|
|
57
|
+
/** This function tells if a folder is a mount point, from the mounts of this process. The fifth field is the mount point. */
|
|
58
|
+
const mounted = (folder: string): boolean => readFileSync("/proc/self/mountinfo", "utf8").split("\n").some((line) => line.split(" ")[4] === folder);
|
|
59
|
+
|
|
60
|
+
// The fault layer opens its lower folder at its start. Thus it starts after the mount of LazyFS, else it holds the folder below it.
|
|
61
|
+
let faultfs: ReturnType<typeof spawn> | undefined;
|
|
62
|
+
const waitForLazyFs = setInterval(() => {
|
|
63
|
+
if (!mounted("/mnt/lazy")) return;
|
|
64
|
+
clearInterval(waitForLazyFs);
|
|
65
|
+
faultfs = spawn("/usr/local/bin/faultfs", ["/mnt/lazy", "/mnt/disk", "-f", "-o", "allow_other"], { stdio: "inherit" });
|
|
66
|
+
faultfs.on("error", (error) => {
|
|
67
|
+
console.error(`faultfs did not start: ${error.message}`);
|
|
68
|
+
lazyfs.kill("SIGTERM");
|
|
69
|
+
});
|
|
70
|
+
faultfs.on("exit", (code, signal) => {
|
|
71
|
+
if (!ended) console.error(`faultfs ended: ${signal === null ? `code=${String(code)}` : `signal=${signal}`}`);
|
|
72
|
+
});
|
|
73
|
+
}, MOUNT_POLL_MS);
|
|
74
|
+
|
|
52
75
|
let ended = false;
|
|
53
76
|
for (const signal of ["SIGTERM", "SIGINT"] as const) {
|
|
54
77
|
process.on(signal, () => {
|
|
55
78
|
if (ended) process.exit(0);
|
|
79
|
+
faultfs?.kill(signal);
|
|
56
80
|
lazyfs.kill(signal);
|
|
57
81
|
});
|
|
58
82
|
}
|
|
@@ -62,6 +86,7 @@ lazyfs.on("error", (error) => {
|
|
|
62
86
|
});
|
|
63
87
|
lazyfs.on("exit", (code, signal) => {
|
|
64
88
|
ended = true;
|
|
89
|
+
clearInterval(waitForLazyFs);
|
|
65
90
|
if (existsSync(ARMED)) {
|
|
66
91
|
writeFileSync(EXIT, signal === null ? `code=${String(code)}\n` : `signal=${signal}\n`);
|
|
67
92
|
// The timer keeps this process, and with it the container, until a signal
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/harness",
|
|
4
|
-
"version": "0.16.
|
|
4
|
+
"version": "0.16.31",
|
|
5
5
|
"description": "Network labs in Docker, declared as data. A cell builds a topology of networks, routers and proxies around a stock target. It injects a fault at layer 3 or 4 from a NET_ADMIN sidecar, measures the records of the kernel and judges a prediction. The faults are black holes, resets, ICMP unreachable, one-way and MTU drops, tc netem, the toxics of Toxiproxy and frozen processes. Its disk tier cuts the power of a program on LazyFS: the disk loses each write after the last fsync. Its memory tier sets the limits of the cgroup of a client, and judges its throttle above memory.high and the choice of the OOM killer. Its egress tier puts a netem or tbf qdisc on the interface of a client, and judges the departure of each datagram from the stamps of the kernel. Its replicated groups are Redis with Sentinels, MongoDB replica sets, PostgreSQL standbys, Kafka, RabbitMQ and BGP fabrics with BFD. A lab can also operate in a QEMU guest. Its first use is connection timers: keep-alive, TCP retransmission, heartbeats and reconnects.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"fault-injection",
|
|
@@ -116,6 +116,7 @@
|
|
|
116
116
|
"image/lazyfs/Dockerfile",
|
|
117
117
|
"image/lazyfs/config.toml",
|
|
118
118
|
"image/lazyfs/start.mts",
|
|
119
|
+
"image/lazyfs/faultfs.c",
|
|
119
120
|
"README.md",
|
|
120
121
|
"LICENSE"
|
|
121
122
|
],
|