From: Ralph Boehme Date: Mon, 23 Nov 2020 16:53:57 +0000 (+0100) Subject: s4: add samba server tevent trace helper stuff X-Git-Tag: samba-4.12.11~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b838f5075c856779a38d9a2a023bf1b33cb1afd;p=thirdparty%2Fsamba.git s4: add samba server tevent trace helper stuff BUG: https://bugzilla.samba.org/show_bug.cgi?id=14248 Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison (backported from commit 68f71f227b17774a12c84575c1eecd82279fac95) [slow@samba.org: conflict due to rename source4/smbd/ -> source4/samba/ in master] --- diff --git a/source4/smbd/server_util.c b/source4/smbd/server_util.c new file mode 100644 index 00000000000..282ad9b17cd --- /dev/null +++ b/source4/smbd/server_util.c @@ -0,0 +1,94 @@ +/* + Unix SMB/CIFS implementation. + + Utility routines + + Copyright (C) 2020 Ralph Boehme + + 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 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include "lib/tevent/tevent.h" +#include "lib/util/unix_privs.h" +#include "server_util.h" + +struct samba_tevent_trace_state { + size_t events; + time_t last_logsize_check; +}; + +struct samba_tevent_trace_state *create_samba_tevent_trace_state( + TALLOC_CTX *mem_ctx) +{ + return talloc_zero(mem_ctx, struct samba_tevent_trace_state); +} + +void samba_tevent_trace_callback(enum tevent_trace_point point, + void *private_data) +{ + struct samba_tevent_trace_state *state = + talloc_get_type_abort(private_data, + struct samba_tevent_trace_state); + time_t now = time(NULL); + bool do_check_logs = false; + void *priv = NULL; + + switch (point) { + case TEVENT_TRACE_BEFORE_WAIT: + break; + default: + return; + } + + state->events++; + + /* + * Throttling by some random numbers. smbd uses a similar logic + * checking every 50 SMB requests. Assuming 4 events per request + * we get to the number of 200. + */ + if ((state->events % 200) == 0) { + do_check_logs = true; + } + /* + * Throttling by some delay, choosing 29 to avoid lockstep with + * the default tevent tickle timer. + */ + if ((state->last_logsize_check + 29) < now) { + do_check_logs = true; + } + + if (!do_check_logs) { + return; + } + + /* + * need_to_check_log_size() checks both the number of messages + * that have been logged and if the logging backend is actually + * going to file. We want to bypass the "number of messages" + * check, so we have to call force_check_log_size() before. + */ + force_check_log_size(); + if (!need_to_check_log_size()) { + return; + } + + priv = root_privileges(); + check_log_size(); + TALLOC_FREE(priv); + + state->last_logsize_check = now; + return; +} diff --git a/source4/smbd/server_util.h b/source4/smbd/server_util.h new file mode 100644 index 00000000000..08c09cc67c2 --- /dev/null +++ b/source4/smbd/server_util.h @@ -0,0 +1,33 @@ +/* + Unix SMB/CIFS implementation. + + Utility routines + + Copyright (C) 2020 Ralph Boehme + + 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 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef SAMBA_SERVER_UTIL_H +#define SAMBA_SERVER_UTIL_H + +struct samba_tevent_trace_state; + +struct samba_tevent_trace_state *create_samba_tevent_trace_state( + TALLOC_CTX *mem_ctx); + +void samba_tevent_trace_callback(enum tevent_trace_point point, + void *private_data); + +#endif diff --git a/source4/smbd/wscript_build b/source4/smbd/wscript_build index ef0aaf773c1..146098ec8e4 100644 --- a/source4/smbd/wscript_build +++ b/source4/smbd/wscript_build @@ -17,6 +17,10 @@ bld.SAMBA_LIBRARY('process_model', enabled=bld.AD_DC_BUILD_IS_ENABLED() ) +bld.SAMBA_SUBSYSTEM('samba_server_util', + source='server_util.c', + deps='samba-util') + bld.SAMBA_BINARY('samba', source='server.c', subsystem_name='service',