From 5fb6f70471105256f41b3d87416bf46d824a40c3 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Sun, 29 Nov 2026 20:06:01 +0300 Subject: [PATCH 1/2] Fail the fio job instead of hanging when out of open files A fio job whose client runs out of file descriptors retries its OSD connections forever, so its I/O never completes and fio hangs. When no I/O has completed for 30 s and the process cannot open even /dev/null, fail the job with EMFILE and name the limit to raise. The client itself keeps retrying, as QEMU and the other users of the library expect. --- src/client/fio_cluster.cpp | 49 +++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/client/fio_cluster.cpp b/src/client/fio_cluster.cpp index 3515d96a..085634c2 100644 --- a/src/client/fio_cluster.cpp +++ b/src/client/fio_cluster.cpp @@ -18,6 +18,9 @@ // fio -thread -ioengine=./libfio_cluster.so -name=test -bs=4k -direct=1 -iodepth=32 -rw=randread \ // -etcd=127.0.0.1:2379 [-etcd_prefix=/vitastor] -image=testimg +#include +#include +#include #include #include #include @@ -38,6 +41,8 @@ struct sec_data /* The list of completed io_u structs. */ std::vector completed; uint64_t inflight = 0; + // last completion, or the first queued op after an idle period + time_t last_progress = 0; int mirror_fd = -1; bool trace = false; }; @@ -368,12 +373,20 @@ static int sec_init(struct thread_data *td) return 0; } +static time_t sec_now() +{ + timespec ts; + clock_gettime(CLOCK_MONOTONIC_COARSE, &ts); + return ts.tv_sec; +} + static void io_callback(void *opaque, long retval) { struct io_u *io = (struct io_u*)opaque; io->error = retval < 0 ? -retval : 0; sec_data *bsd = (sec_data*)io->engine_data; bsd->inflight--; + bsd->last_progress = sec_now(); bsd->completed.push_back(io); if (bsd->trace) { @@ -402,7 +415,8 @@ static enum fio_q_status sec_queue(struct thread_data *td, struct io_u *io) io->engine_data = bsd; io->error = 0; - bsd->inflight++; + if (!bsd->inflight++) + bsd->last_progress = sec_now(); uint64_t inode = opt->image ? vitastor_c_inode_get_num(bsd->watch) : opt->inode; assert(io->xfer_buflen < (size_t)-1); @@ -469,6 +483,35 @@ static enum fio_q_status sec_queue(struct thread_data *td, struct io_u *io) return FIO_Q_QUEUED; } +// A client out of fds retries its OSD connections forever, so its ops never complete: +// fail the job once nothing completed for this long and no fd can be opened +static const time_t sec_stall_seconds = 30; + +static bool sec_out_of_fds(struct thread_data *td, sec_data *bsd) +{ + if (!bsd->inflight || sec_now() - bsd->last_progress < sec_stall_seconds) + return false; + int fd = open("/dev/null", O_RDONLY | O_CLOEXEC); + if (fd >= 0) + { + close(fd); + return false; + } + int err = errno; + if (err != EMFILE && err != ENFILE) + return false; + struct rlimit rl = {}; + getrlimit(RLIMIT_NOFILE, &rl); + fprintf(stderr, "vitastor: no I/O completed for %ld s and no file descriptor is left (%s), open files" + " limit: soft %ju, hard %ju. Each job keeps a connection to every OSD it writes to: raise ulimit -n.\n", + (long)sec_stall_seconds, strerror(err), (uintmax_t)rl.rlim_cur, (uintmax_t)rl.rlim_max); + // fio keeps 128 bytes of the whole error line + char msg[64]; + snprintf(msg, sizeof(msg), "out of fds for %lds, ulimit -n %ju", (long)sec_stall_seconds, (uintmax_t)rl.rlim_cur); + td_verror(td, err, msg); + return true; +} + static int sec_getevents(struct thread_data *td, unsigned int min, unsigned int max, const struct timespec *t) { sec_data *bsd = (sec_data*)td->io_ops_data; @@ -479,6 +522,8 @@ static int sec_getevents(struct thread_data *td, unsigned int min, unsigned int vitastor_c_uring_handle_events(bsd->cli); if (bsd->completed.size() >= min) break; + if (sec_out_of_fds(td, bsd)) + return -td->error; vitastor_c_uring_wait_events(bsd->cli); } } @@ -488,6 +533,8 @@ static int sec_getevents(struct thread_data *td, unsigned int min, unsigned int { if (bsd->completed.size() >= min) break; + if (sec_out_of_fds(td, bsd)) + return -td->error; vitastor_c_epoll_handle_events(bsd->cli, 1000); } } -- 2.47.3 From 1874fb7343fb0da5b9324b22f46dc14e64ae13d6 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Sun, 29 Nov 2026 21:25:21 +0300 Subject: [PATCH 2/2] Fail a fio job out of open files also while it looks up the image With create_serialize=0 the image lookup runs in each job after the start, so one job can use up the process's fds while another is still waiting for etcd, and that job hangs before any I/O. Apply the same check there. Also count ops that sec_queue completes by itself (mirror error, read-only image, unknown direction) out of the in-flight count, so it does not stay above zero. --- src/client/fio_cluster.cpp | 84 +++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/src/client/fio_cluster.cpp b/src/client/fio_cluster.cpp index 085634c2..db5e0286 100644 --- a/src/client/fio_cluster.cpp +++ b/src/client/fio_cluster.cpp @@ -230,6 +230,42 @@ static void opt_push(std::vector & options, const char *opt, const char } } +static time_t sec_now() +{ + timespec ts; + clock_gettime(CLOCK_MONOTONIC_COARSE, &ts); + return ts.tv_sec; +} + +// A client out of fds retries its connections forever, so nothing it waits for completes: +// fail the job once nothing completed for this long and no fd can be opened +static const time_t sec_stall_seconds = 30; + +static bool sec_out_of_fds(struct thread_data *td, time_t since) +{ + if (sec_now() - since < sec_stall_seconds) + return false; + int fd = open("/dev/null", O_RDONLY | O_CLOEXEC); + if (fd >= 0) + { + close(fd); + return false; + } + int err = errno; + if (err != EMFILE && err != ENFILE) + return false; + struct rlimit rl = {}; + getrlimit(RLIMIT_NOFILE, &rl); + fprintf(stderr, "vitastor: nothing completed for %ld s and no file descriptor is left (%s), open files" + " limit: soft %ju, hard %ju. Each job keeps a connection to every OSD it writes to: raise ulimit -n.\n", + (long)sec_stall_seconds, strerror(err), (uintmax_t)rl.rlim_cur, (uintmax_t)rl.rlim_max); + // fio keeps 128 bytes of the whole error line + char msg[64]; + snprintf(msg, sizeof(msg), "out of fds for %lds, ulimit -n %ju", (long)sec_stall_seconds, (uintmax_t)rl.rlim_cur); + td_verror(td, err, msg); + return true; +} + static int sec_setup(struct thread_data *td) { sec_options *o = (sec_options*)td->eo; @@ -315,6 +351,7 @@ static int sec_setup(struct thread_data *td) if (o->image) { bsd->watch = NULL; + time_t start = sec_now(); vitastor_c_watch_inode(bsd->cli, o->image, watch_callback, bsd); if (!bsd->epoll_based) { @@ -323,6 +360,8 @@ static int sec_setup(struct thread_data *td) vitastor_c_uring_handle_events(bsd->cli); if (bsd->watch) break; + if (sec_out_of_fds(td, start)) + return 1; vitastor_c_uring_wait_events(bsd->cli); } } @@ -332,6 +371,8 @@ static int sec_setup(struct thread_data *td) { if (bsd->watch) break; + if (sec_out_of_fds(td, start)) + return 1; vitastor_c_epoll_handle_events(bsd->cli, 1000); } } @@ -373,13 +414,6 @@ static int sec_init(struct thread_data *td) return 0; } -static time_t sec_now() -{ - timespec ts; - clock_gettime(CLOCK_MONOTONIC_COARSE, &ts); - return ts.tv_sec; -} - static void io_callback(void *opaque, long retval) { struct io_u *io = (struct io_u*)opaque; @@ -438,6 +472,7 @@ static enum fio_q_status sec_queue(struct thread_data *td, struct io_u *io) { fprintf(stderr, "Error writing mirror file: %s\n", strerror(errno)); io->error = errno; + bsd->inflight--; return FIO_Q_COMPLETED; } if (r > 0) @@ -449,6 +484,7 @@ static enum fio_q_status sec_queue(struct thread_data *td, struct io_u *io) if (opt->image && vitastor_c_inode_get_readonly(bsd->watch)) { io->error = EROFS; + bsd->inflight--; return FIO_Q_COMPLETED; } iov = { .iov_base = io->xfer_buf, .iov_len = (size_t)io->xfer_buflen }; @@ -461,6 +497,7 @@ static enum fio_q_status sec_queue(struct thread_data *td, struct io_u *io) break; default: io->error = EINVAL; + bsd->inflight--; return FIO_Q_COMPLETED; } @@ -483,35 +520,6 @@ static enum fio_q_status sec_queue(struct thread_data *td, struct io_u *io) return FIO_Q_QUEUED; } -// A client out of fds retries its OSD connections forever, so its ops never complete: -// fail the job once nothing completed for this long and no fd can be opened -static const time_t sec_stall_seconds = 30; - -static bool sec_out_of_fds(struct thread_data *td, sec_data *bsd) -{ - if (!bsd->inflight || sec_now() - bsd->last_progress < sec_stall_seconds) - return false; - int fd = open("/dev/null", O_RDONLY | O_CLOEXEC); - if (fd >= 0) - { - close(fd); - return false; - } - int err = errno; - if (err != EMFILE && err != ENFILE) - return false; - struct rlimit rl = {}; - getrlimit(RLIMIT_NOFILE, &rl); - fprintf(stderr, "vitastor: no I/O completed for %ld s and no file descriptor is left (%s), open files" - " limit: soft %ju, hard %ju. Each job keeps a connection to every OSD it writes to: raise ulimit -n.\n", - (long)sec_stall_seconds, strerror(err), (uintmax_t)rl.rlim_cur, (uintmax_t)rl.rlim_max); - // fio keeps 128 bytes of the whole error line - char msg[64]; - snprintf(msg, sizeof(msg), "out of fds for %lds, ulimit -n %ju", (long)sec_stall_seconds, (uintmax_t)rl.rlim_cur); - td_verror(td, err, msg); - return true; -} - static int sec_getevents(struct thread_data *td, unsigned int min, unsigned int max, const struct timespec *t) { sec_data *bsd = (sec_data*)td->io_ops_data; @@ -522,7 +530,7 @@ static int sec_getevents(struct thread_data *td, unsigned int min, unsigned int vitastor_c_uring_handle_events(bsd->cli); if (bsd->completed.size() >= min) break; - if (sec_out_of_fds(td, bsd)) + if (bsd->inflight && sec_out_of_fds(td, bsd->last_progress)) return -td->error; vitastor_c_uring_wait_events(bsd->cli); } @@ -533,7 +541,7 @@ static int sec_getevents(struct thread_data *td, unsigned int min, unsigned int { if (bsd->completed.size() >= min) break; - if (sec_out_of_fds(td, bsd)) + if (bsd->inflight && sec_out_of_fds(td, bsd->last_progress)) return -td->error; vitastor_c_epoll_handle_events(bsd->cli, 1000); } -- 2.47.3