vfs_delay_inject: adding delay to VFS calls
[Samba.git] / source3 / modules / vfs_delay_inject.c
blob21fea9b10f4d8e135e4c9ff4e2cd1813ff7db6cd
1 /*
2 * Unix SMB/CIFS implementation.
3 * Samba VFS module for delay injection in VFS calls
4 * Copyright (C) Ralph Boehme 2018
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "smbd/smbd.h"
23 #undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_VFS
26 static void inject_delay(const char *vfs_func, vfs_handle_struct *handle)
28 int delay;
30 delay = lp_parm_int(SNUM(handle->conn), "delay_inject", vfs_func, 0);
31 if (delay == 0) {
32 return;
35 DBG_DEBUG("Injected delay for [%s] of [%d] ms\n", vfs_func, delay);
37 smb_msleep(delay);
40 static int vfs_delay_inject_ntimes(vfs_handle_struct *handle,
41 const struct smb_filename *smb_fname,
42 struct smb_file_time *ft)
44 inject_delay("ntimes", handle);
46 return SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
49 static struct vfs_fn_pointers vfs_delay_inject_fns = {
50 .ntimes_fn = vfs_delay_inject_ntimes,
53 static_decl_vfs;
54 NTSTATUS vfs_delay_inject_init(TALLOC_CTX *ctx)
56 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "delay_inject",
57 &vfs_delay_inject_fns);