aboutsummaryrefslogtreecommitdiffstats
path: root/smtpd/queue_fs.c
diff options
context:
space:
mode:
authorGilles Chehade <gilles@poolp.org>2015-11-23 01:28:10 +0100
committerGilles Chehade <gilles@poolp.org>2015-11-23 01:28:10 +0100
commit60f377980d347d29f8275530894b7240b3803e6f (patch)
tree29acd754a94fcb7667cf16cab29f2a7d85ccb0fa /smtpd/queue_fs.c
parentsync (diff)
downloadOpenSMTPD-60f377980d347d29f8275530894b7240b3803e6f.tar.xz
OpenSMTPD-60f377980d347d29f8275530894b7240b3803e6f.zip
sync
Diffstat (limited to 'smtpd/queue_fs.c')
-rw-r--r--smtpd/queue_fs.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/smtpd/queue_fs.c b/smtpd/queue_fs.c
index f7bd3d70..7ebfb8be 100644
--- a/smtpd/queue_fs.c
+++ b/smtpd/queue_fs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_fs.c,v 1.5 2014/04/19 13:48:57 gilles Exp $ */
+/* $OpenBSD: queue_fs.c,v 1.11 2015/11/05 09:14:31 sunil Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
@@ -17,7 +17,6 @@
*/
#include <sys/types.h>
-#include <sys/param.h> /* for OpenBSD-5.6, DO NOT BACKPORT TO OpenBSD-current ! */
#include <sys/mount.h>
#include <sys/queue.h>
#include <sys/tree.h>
@@ -34,7 +33,6 @@
#include <imsg.h>
#include <inttypes.h>
#include <libgen.h>
-#include <limits.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
@@ -51,8 +49,9 @@
#define PATH_EVPTMP PATH_INCOMING "/envelope.tmp"
#define PATH_MESSAGE "/message"
-/* minimum number of free blocks on filesystem */
-#define MINFREEBLOCKS 100
+/* percentage of remaining space / inodes required to accept new messages */
+#define MINSPACE 5
+#define MININODES 5
struct qwalk {
FTS *fts;
@@ -167,9 +166,6 @@ queue_fs_message_commit(uint32_t msgid, const char *path)
return 0;
}
- /* best effort */
- sync();
-
return 1;
}
@@ -427,7 +423,7 @@ queue_fs_message_walk(uint64_t *evpid, char *buf, size_t len,
continue;
/* ignore files other than envelopes */
- if (strlen(dp->d_name) != 16 || strncmp(dp->d_name, msgid_str, 8))
+ if (dp->d_namlen != 16 || strncmp(dp->d_name, msgid_str, 8))
continue;
tmp = NULL;
@@ -493,6 +489,8 @@ static int
fsqueue_check_space(void)
{
struct statfs buf;
+ uint64_t used;
+ uint64_t total;
if (statfs(PATH_QUEUE, &buf) < 0) {
log_warn("warn: queue-fs: statfs");
@@ -508,8 +506,29 @@ fsqueue_check_space(void)
(int64_t)buf.f_bfree == -1 || (int64_t)buf.f_ffree == -1)
return 1;
- if (buf.f_bavail < MINFREEBLOCKS) {
- log_warnx("warn: disk space running low, temporarily rejecting messages");
+ used = buf.f_blocks - buf.f_bfree;
+ total = buf.f_bavail + used;
+ if (total != 0)
+ used = (float)used / (float)total * 100;
+ else
+ used = 100;
+ if (100 - used < MINSPACE) {
+ log_warnx("warn: not enough disk space: %llu%% left",
+ (unsigned long long) 100 - used);
+ log_warnx("warn: temporarily rejecting messages");
+ return 0;
+ }
+
+ used = buf.f_files - buf.f_ffree;
+ total = buf.f_favail + used;
+ if (total != 0)
+ used = (float)used / (float)total * 100;
+ else
+ used = 100;
+ if (100 - used < MININODES) {
+ log_warnx("warn: not enough inodes: %llu%% left",
+ (unsigned long long) 100 - used);
+ log_warnx("warn: temporarily rejecting messages");
return 0;
}