/* * Copyright (C) 2025 Mateusz Guzik * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #define _GNU_SOURCE #include #include #include #include #include #include #include /* * Invoke a bunch of VFS syscalls. * * Inspired by "vfsmix" testcase by Ingo Molnar: * https://lkml.org/lkml/2015/5/19/1009 * * Note: mmap/munmap are deliberately omitted to avoid going into the VM * layer. This does ignore some of the VFS code. * * The idea is to let interested developers check where the time is * wast^Wspent while issuing typical syscalls. */ char *testcase_description = "vfstour1"; void testcase(unsigned long long *iterations, unsigned long nr) { struct stat sb; char buf[128]; char tmppath[] = "/tmp/willitscale.XXXXXX"; char *tmpdir; char *tmpfile; int fd, ret; uid_t uid; gid_t gid; tmpdir = mkdtemp(tmppath); if (tmpdir == NULL) { perror("mkdtemp"); exit(1); } rmdir(tmpdir); uid = getuid(); gid = getgid(); ret = asprintf(&tmpfile, "%s/file", tmppath); assert(ret != -1); while (1) { ret = mkdir(tmppath, 0700); assert(ret == 0); fd = open(tmpfile, O_RDWR | O_CREAT, 0600); assert(fd >= 0); ret = lstat(tmpfile, &sb); assert(ret == 0); ret = truncate(tmpfile, sizeof(buf) * 2); assert(ret == 0); ret = write(fd, buf, sizeof(buf)); assert(ret == sizeof(buf)); ret = fstat(fd, &sb); assert(ret == 0); ret = lseek(fd, 0, SEEK_SET); assert(ret == 0); ret = access(tmpfile, 0); assert(ret == 0); ret = read(fd, buf, sizeof(buf)); assert(ret == sizeof(buf)); ret = ftruncate(fd, sizeof(buf)); assert(ret == 0); ret = chmod(tmpfile, 0400); assert(ret == 0); ret = close(fd); assert(ret == 0); ret = chown(tmpfile, uid, gid); assert(ret == 0); ret = unlink(tmpfile); assert(ret == 0); ret = rmdir(tmppath); assert(ret == 0); (*iterations)++; } }