From: claudio Date: Mon, 14 Jun 2021 09:54:15 +0000 (+0000) Subject: Do a fstatvfs() call to figure out if the filesystem used for the cache X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c97c4358f10340a5877285d314eee39cf8f118c5;p=openbsd Do a fstatvfs() call to figure out if the filesystem used for the cache is large enough for the cache. People like to build VM images with way too small filesystems and so warning about this situation should help. With deraadt@ and job@ --- diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index 41c04695a58..b5adfa586b9 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.142 2021/06/03 15:10:05 claudio Exp $ */ +/* $OpenBSD: main.c,v 1.143 2021/06/14 09:54:15 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -15,11 +15,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #include #include #include +#include #include -#include #include #include @@ -579,6 +580,31 @@ tal_load_default(const char *tals[], size_t max) return s; } +static void +check_fs_size(int fd, const char *cachedir) +{ + struct statvfs fs; + const long long minsize = 500 * 1024 * 1024; + const long long minnode = 300 * 1000; + + if (fstatvfs(fd, &fs) == -1) + err(1, "statfs %s", cachedir); + + if (fs.f_bavail < minsize / fs.f_frsize || fs.f_favail < minnode) { + fprintf(stderr, "WARNING: rpki-client may need more than " + "the availabe disk space\n" + "on the file-system holding %s.\n", cachedir); + fprintf(stderr, "available space: %lldkB, " + "suggested minimum %lldkB\n", + (long long)fs.f_bavail * fs.f_frsize / 1024, + minsize / 1024); + fprintf(stderr, "available inodes %lld, " + "suggested minimum %lld\n\n", + (long long)fs.f_favail, minnode); + fflush(stderr); + } +} + void suicide(int sig __attribute__((unused))) { @@ -706,6 +732,8 @@ main(int argc, char *argv[]) if ((outdirfd = open(outputdir, O_RDONLY | O_DIRECTORY, 0)) == -1) err(1, "output directory %s", outputdir); + check_fs_size(cachefd, cachedir); + if (outformats == 0) outformats = FORMAT_OPENBGPD;