vfs_delay_inject: adding delay to VFS calls
authorRalph Boehme <slow@samba.org>
Thu, 30 Aug 2018 15:27:08 +0000 (17:27 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 5 Sep 2018 11:35:26 +0000 (13:35 +0200)
Bug: https://bugzilla.samba.org/show_bug.cgi?id=13549

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 44840ba5b32a2ce7959fd3d7c87822b3159416d3)

source3/modules/vfs_delay_inject.c [new file with mode: 0644]
source3/modules/wscript_build
source3/wscript

diff --git a/source3/modules/vfs_delay_inject.c b/source3/modules/vfs_delay_inject.c
new file mode 100644 (file)
index 0000000..21fea9b
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ *  Unix SMB/CIFS implementation.
+ *  Samba VFS module for delay injection in VFS calls
+ *  Copyright (C) Ralph Boehme 2018
+ *
+ *  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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+#include "smbd/smbd.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_VFS
+
+static void inject_delay(const char *vfs_func, vfs_handle_struct *handle)
+{
+       int delay;
+
+       delay = lp_parm_int(SNUM(handle->conn), "delay_inject", vfs_func, 0);
+       if (delay == 0) {
+               return;
+       }
+
+       DBG_DEBUG("Injected delay for [%s] of [%d] ms\n", vfs_func, delay);
+
+       smb_msleep(delay);
+}
+
+static int vfs_delay_inject_ntimes(vfs_handle_struct *handle,
+                                  const struct smb_filename *smb_fname,
+                                  struct smb_file_time *ft)
+{
+       inject_delay("ntimes", handle);
+
+       return SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
+}
+
+static struct vfs_fn_pointers vfs_delay_inject_fns = {
+       .ntimes_fn = vfs_delay_inject_ntimes,
+};
+
+static_decl_vfs;
+NTSTATUS vfs_delay_inject_init(TALLOC_CTX *ctx)
+{
+       return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "delay_inject",
+                               &vfs_delay_inject_fns);
+}
index a6a01f9929f1182faf6dd6ad6157c08a75aa18a1..61b776f9ea44c2b5110fb7f24af5c8fb2ade79dd 100644 (file)
@@ -516,3 +516,10 @@ bld.SAMBA3_MODULE('vfs_error_inject',
                  init_function='',
                  internal_module=bld.SAMBA3_IS_STATIC_MODULE('vfs_error_inject'),
                  enabled=bld.SAMBA3_IS_ENABLED_MODULE('vfs_error_inject'))
+
+bld.SAMBA3_MODULE('vfs_delay_inject',
+                 subsystem='vfs',
+                 source='vfs_delay_inject.c',
+                 init_function='',
+                 internal_module=bld.SAMBA3_IS_STATIC_MODULE('vfs_delay_inject'),
+                 enabled=bld.SAMBA3_IS_ENABLED_MODULE('vfs_delay_inject'))
index 921c8bcef7052af6e47460e2d2c0055dfad09c34..bc51e184b85b44cc7520b36ab350e3cffaa74029 100644 (file)
@@ -1718,6 +1718,7 @@ main() {
     if Options.options.enable_selftest or Options.options.developer:
         default_shared_modules.extend(TO_LIST('vfs_fake_acls vfs_nfs4acl_xattr'))
         default_shared_modules.extend(TO_LIST('vfs_error_inject'))
+        default_shared_modules.extend(TO_LIST('vfs_delay_inject'))
 
     if conf.CONFIG_SET('AD_DC_BUILD_IS_ENABLED'):
         default_static_modules.extend(TO_LIST('pdb_samba_dsdb auth_samba4 vfs_dfs_samba4'))