[PATCH 06/14] resource limits: track highwater mark of cores dumped

From: Topi Miettinen
Date: Fri Jul 15 2016 - 06:41:07 EST


Track maximum size of core dump written, to be able to configure
RLIMIT_CORE resource limits. The information is available
with taskstats and cgroupstats netlink socket.

Signed-off-by: Topi Miettinen <toiwoton@xxxxxxxxx>
---
fs/coredump.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/fs/coredump.c b/fs/coredump.c
index 281b768..a0ace88 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -784,20 +784,25 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
struct file *file = cprm->file;
loff_t pos = file->f_pos;
ssize_t n;
+ int r = 0;
+
if (cprm->written + nr > cprm->limit)
return 0;
while (nr) {
if (dump_interrupted())
- return 0;
+ goto err;
n = __kernel_write(file, addr, nr, &pos);
if (n <= 0)
- return 0;
+ goto err;
file->f_pos = pos;
cprm->written += n;
cprm->pos += n;
nr -= n;
}
- return 1;
+ r = 1;
+ err:
+ update_resource_highwatermark(RLIMIT_CORE, cprm->written);
+ return r;
}
EXPORT_SYMBOL(dump_emit);

--
2.8.1