Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor/linux: report large files when exiting with ENOSPC error #2127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions executor/executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,42 @@ void setup_features(char** enable, int n)
}
}

#if GOOS_linux
#include <ftw.h>
#include <sys/vfs.h>

static int nftw_callback(const char* fpath, const struct stat* sbuf, int tflag, struct FTW* ftwbuf)
{
static char buffer[4096] = {};
static struct stat sbuf2 = {};

if (S_ISLNK(sbuf->st_mode) && strstr(fpath, "/fd/") && !stat(fpath, &sbuf2) &&
(unsigned long long)sbuf2.st_blocks >= 1048576ULL / 512)
fprintf(stderr, "%10llu %s\n", (unsigned long long)sbuf2.st_size,
readlink(fpath, buffer, sizeof(buffer) - 1) > 0 ? buffer : fpath);
return 0;
}
#endif

static void check_large_files(int err)
{
#if GOOS_linux
char buffer[4096] = {};
struct statfs sbuf = {};

if (err != ENOSPC)
return;
fprintf(stderr, "Current directory is %s\n", getcwd(buffer, sizeof(buffer) - 1));
statfs(".", &sbuf);
fprintf(stderr, " Free blocks: %llu/%llu\n", (unsigned long long)sbuf.f_bfree, (unsigned long long)sbuf.f_blocks);
fprintf(stderr, " Block size: %llu\n", (unsigned long long)sbuf.f_bsize);
fprintf(stderr, " Filesystem type: %lx\n", (unsigned long)sbuf.f_type);
fprintf(stderr, " Free inodes: %llu/%llu\n", (unsigned long long)sbuf.f_ffree, (unsigned long long)sbuf.f_files);
fprintf(stderr, "Scanning large files from /proc/\052/fd/\052\n");
nftw("/proc/", nftw_callback, 512, FTW_DEPTH | FTW_PHYS | FTW_MOUNT);
#endif
}

void fail(const char* msg, ...)
{
int e = errno;
Expand All @@ -1486,6 +1522,7 @@ void fail(const char* msg, ...)
vfprintf(stderr, msg, args);
va_end(args);
fprintf(stderr, " (errno %d)\n", e);
check_large_files(e);

// fail()'s are often used during the validation of kernel reactions to queries
// that were issued by pseudo syscalls implementations. As fault injection may
Expand All @@ -1511,6 +1548,7 @@ void exitf(const char* msg, ...)
vfprintf(stderr, msg, args);
va_end(args);
fprintf(stderr, " (errno %d)\n", e);
check_large_files(e);
doexit(0);
}

Expand Down