Docs · I/O adapters

Intercept POSIX I/O.

The POSIX interceptor sends open, read, write, stat and related calls on clio:: paths to the CLIO filesystem module instead of the kernel. The program needs no changes and no recompile: preload the library and point the program at a clio:: path.

Library
libclio_cte_posix.so
Build
CLIO_CTE_ENABLE_POSIX_ADAPTER=ON CLIO_CORE_ENABLE_ELF=ON
Load
LD_PRELOAD
Platform
Linux
Install
Source builds: Spack (+posix) or CMake

How it works

The library defines open, write and the other functions below itself. Loaded with LD_PRELOAD, its definitions win over the C library's. Each call checks the path (or the descriptor): if the path has a component starting with clio::, the call goes to the clio_cte_filesystem module in the runtime; anything else goes to the real C library untouched. The marker is removed, so clio::/data/out.bin is the file /data/out.bin in the clio-fs namespace, the same namespace a Context FS mount shows. Nothing is written to /data/out.bin on the host's own filesystem.

The interceptor attaches to the runtime on the first clio:: open, not at load time, so a preloaded program that never opens a clio:: path never connects.

1. Build it

The POSIX adapter option is on by default, but it is only built when ELF support is on. Configure a source build with:

shell
$ cmake -S . -B build -DCLIO_CORE_ENABLE_ELF=ON -DCLIO_CTE_ENABLE_POSIX_ADAPTER=ON
$ cmake --build build -j"$(nproc)"
$ ls build/bin/libclio_cte_posix.so

ELF support needs libelf through pkg-config. See Install for the details and for the other adapters. The interceptor is not in the pip wheel, conda or Docker; Spack builds it with +posix (on by default).

2. Start a runtime

The interceptor needs a running runtime with a filesystem pool. The default configuration composes one (clio_cte_filesystem at 560.0), so the plain command is enough:

shell
$ build/bin/clio-run start &

If you use your own configuration, it must contain a clio_cte_filesystem entry; the interceptor looks the pool up by that name and creates none. Set CLIO_CFS_POOL to use a pool with another name, or to name it by id (CLIO_CFS_POOL=560.0).

When no runtime or no filesystem pool can be reached, opening a clio:: path fails with EIO. The attach first waits for a server for CLIO_WAIT_SERVER seconds (30 by default).

3. Run a program under the interceptor

Any program that does POSIX I/O works. This one writes a file, syncs it, and reads it back; the path comes from the command line, which is the usual way to steer an unmodified program to a clio:: path.

c · hello_posix.c
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv) {
  const char *path = argc > 1 ? argv[1] : "clio::/demo/hello.txt";
  const char msg[] = "hello from the POSIX interceptor\n";

  int fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0644);
  if (fd < 0) { perror("open"); return 1; }
  if (write(fd, msg, sizeof(msg) - 1) < 0) { perror("write"); return 1; }
  if (fsync(fd) != 0) { perror("fsync"); return 1; }
  close(fd);

  char buf[64] = {0};
  fd = open(path, O_RDONLY);
  if (fd < 0) { perror("open"); return 1; }
  ssize_t n = read(fd, buf, sizeof(buf) - 1);
  close(fd);
  printf("read %zd bytes: %s", n, buf);
  return 0;
}
shell
$ cc -o hello_posix hello_posix.c          # no CLIO headers or libraries needed
$ LD_PRELOAD=$PWD/build/bin/libclio_cte_posix.so ./hello_posix clio::/demo/hello.txt
read 33 bytes: hello from the POSIX interceptor

Run it without LD_PRELOAD and the same path is just a relative path whose first directory, clio::, does not exist, so open fails. That is a quick way to confirm the interceptor was loaded. After an install, the library is <prefix>/lib/libclio_cte_posix.so.

What is intercepted

Open and create
open, open64, __open_2, creat, creat64. O_CREAT, O_TRUNC and O_APPEND are honored. Parent directories that do not exist yet in clio-fs are created on the fly.
Data
read, write, pread, pwrite, pread64, pwrite64, lseek, lseek64.
Metadata
stat, fstat, their 64 variants and the glibc __xstat, __lxstat, __fxstat and __fxstatat entry points; ftruncate, ftruncate64.
Lifetime
fsync, close, unlink, remove. flock on a CLIO descriptor succeeds without locking anything.

Descriptors returned for clio:: files start at 8192, so they never collide with the kernel's. stat results are synthesized by the filesystem module and report 1 MiB blocks, the module's page size.

Behavior

  • Writes are synchronous. write returns once the filesystem module has the bytes, and a failure is reported by that write itself: ENOSPC when the store is full, EIO otherwise.
  • fsync is a durability barrier. It puts the file's bytes on a persistent device, the same guarantee as fsync through the Context FS mount. Without it, data stays on whichever tier took it (RAM, typically) until the runtime's periodic flush.
  • Reads can skip the runtime. When the configuration composes the shared-memory cache module (clio_cte_core_shm_cache_writethru, part of the default configuration), committed pages are read straight from shared memory. Otherwise each read is a task to the filesystem module. CLIO_CFS_SHM_READ=0 turns the shared-memory path off, for diagnosis.
  • Durability is the compose's. There is no backing file on a parallel filesystem; the tiers the runtime composes decide where the data lives and how long it survives.

Limits

  • Not intercepted: mmap, vectored I/O (readv, writev), openat, rename, dup, fcntl, mkdir and directory iteration (opendir, readdir), fallocate. A program that relies on these for a clio:: file will see the kernel's answer for a descriptor or path it does not know. Use the Context FS mount when you need full POSIX semantics.
  • The checked variants glibc substitutes under _FORTIFY_SOURCE with optimization (__read_chk, __pread_chk) are not defined by the interceptor, so those reads are not intercepted; __open_2 is. Build the program without _FORTIFY_SOURCE (add -U_FORTIFY_SOURCE where the toolchain enables it by default).
  • Linux only, and only for dynamically linked programs: LD_PRELOAD has no effect on a static binary.
  • The program must open the file under a clio:: path. Paths without the marker are never redirected.

Where to go next