From: Günther Deschner Date: Wed, 28 Sep 2016 19:23:20 +0000 (+0200) Subject: s4-torture: move oplock break handler out of the replay testsuite. X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=c1010396eb2f78250ebf56c530dc244685774170;p=obnox%2Fsamba%2Fsamba-obnox.git s4-torture: move oplock break handler out of the replay testsuite. Guenther Signed-off-by: Guenther Deschner --- diff --git a/source4/torture/smb2/oplock_break_handler.c b/source4/torture/smb2/oplock_break_handler.c new file mode 100644 index 00000000000..931338bebfa --- /dev/null +++ b/source4/torture/smb2/oplock_break_handler.c @@ -0,0 +1,100 @@ +/* + Unix SMB/CIFS implementation. + + test suite for SMB2 replay + + Copyright (C) Anubhav Rakshit 2014 + Copyright (C) Stefan Metzmacher 2014 + + 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 "libcli/smb2/smb2.h" +#include "libcli/smb2/smb2_calls.h" +#include "torture/torture.h" +#include "torture/smb2/proto.h" +#include "../libcli/smb/smbXcli_base.h" +#include "oplock_break_handler.h" + +struct break_info break_info; + + void torture_reset_break_info(struct torture_context *tctx, + struct break_info *r) +{ + ZERO_STRUCTP(r); + r->tctx = tctx; +} + +static void torture_oplock_ack_callback(struct smb2_request *req) +{ + NTSTATUS status; + + status = smb2_break_recv(req, &break_info.br); + if (!NT_STATUS_IS_OK(status)) { + break_info.failures++; + break_info.failure_status = status; + } + + return; +} + +/** + * A general oplock break notification handler. This should be used when a + * test expects to break from batch or exclusive to a lower level. + */ + +bool torture_oplock_ack_handler(struct smb2_transport *transport, + const struct smb2_handle *handle, + uint8_t level, + void *private_data) +{ + struct smb2_tree *tree = private_data; + const char *name; + struct smb2_request *req; + + ZERO_STRUCT(break_info.br); + + break_info.handle = *handle; + break_info.level = level; + break_info.count++; + + switch (level) { + case SMB2_OPLOCK_LEVEL_II: + name = "level II"; + break; + case SMB2_OPLOCK_LEVEL_NONE: + name = "none"; + break; + default: + name = "unknown"; + break_info.failures++; + } + torture_comment(break_info.tctx, + "transport[%p] Acking to %s [0x%02X] in oplock handler\n", + transport, name, level); + + break_info.br.in.file.handle = *handle; + break_info.br.in.oplock_level = level; + break_info.br.in.reserved = 0; + break_info.br.in.reserved2 = 0; + break_info.received_transport = tree->session->transport; + SMB_ASSERT(tree->session->transport == transport); + + req = smb2_break_send(tree, &break_info.br); + req->async.fn = torture_oplock_ack_callback; + req->async.private_data = NULL; + + return true; +} diff --git a/source4/torture/smb2/oplock_break_handler.h b/source4/torture/smb2/oplock_break_handler.h new file mode 100644 index 00000000000..c86e5022c97 --- /dev/null +++ b/source4/torture/smb2/oplock_break_handler.h @@ -0,0 +1,39 @@ +/* + Unix SMB/CIFS implementation. + + test suite for SMB2 replay + + Copyright (C) Anubhav Rakshit 2014 + Copyright (C) Stefan Metzmacher 2014 + + 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 . +*/ + +struct break_info { + struct torture_context *tctx; + struct smb2_handle handle; + uint8_t level; + struct smb2_break br; + int count; + int failures; + NTSTATUS failure_status; + struct smb2_transport *received_transport; +}; + +bool torture_oplock_ack_handler(struct smb2_transport *transport, + const struct smb2_handle *handle, + uint8_t level, + void *private_data); +void torture_reset_break_info(struct torture_context *tctx, + struct break_info *r); diff --git a/source4/torture/smb2/replay.c b/source4/torture/smb2/replay.c index 289fb0144d8..55ebe2cf045 100644 --- a/source4/torture/smb2/replay.c +++ b/source4/torture/smb2/replay.c @@ -32,6 +32,7 @@ #include "libcli/resolve/resolve.h" #include "lib/param/param.h" #include "lib/events/events.h" +#include "oplock_break_handler.h" #define CHECK_VAL(v, correct) do { \ if ((v) != (correct)) { \ @@ -94,82 +95,7 @@ #define BASEDIR "replaytestdir" -struct break_info { - struct torture_context *tctx; - struct smb2_handle handle; - uint8_t level; - struct smb2_break br; - int count; - int failures; - NTSTATUS failure_status; -}; - -static struct break_info break_info; - -static void torture_reset_break_info(struct torture_context *tctx, - struct break_info *r) -{ - ZERO_STRUCTP(r); - r->tctx = tctx; -} - -static void torture_oplock_ack_callback(struct smb2_request *req) -{ - NTSTATUS status; - - status = smb2_break_recv(req, &break_info.br); - if (!NT_STATUS_IS_OK(status)) { - break_info.failures++; - break_info.failure_status = status; - } - - return; -} - -/** - * A general oplock break notification handler. This should be used when a - * test expects to break from batch or exclusive to a lower level. - */ -static bool torture_oplock_ack_handler(struct smb2_transport *transport, - const struct smb2_handle *handle, - uint8_t level, - void *private_data) -{ - struct smb2_tree *tree = private_data; - const char *name; - struct smb2_request *req; - - ZERO_STRUCT(break_info.br); - - break_info.handle = *handle; - break_info.level = level; - break_info.count++; - - switch (level) { - case SMB2_OPLOCK_LEVEL_II: - name = "level II"; - break; - case SMB2_OPLOCK_LEVEL_NONE: - name = "none"; - break; - default: - name = "unknown"; - break_info.failures++; - } - torture_comment(break_info.tctx, - "Acking to %s [0x%02X] in oplock handler\n", - name, level); - - break_info.br.in.file.handle = *handle; - break_info.br.in.oplock_level = level; - break_info.br.in.reserved = 0; - break_info.br.in.reserved2 = 0; - - req = smb2_break_send(tree, &break_info.br); - req->async.fn = torture_oplock_ack_callback; - req->async.private_data = NULL; - return true; -} +extern struct break_info break_info; /** * Timer handler function notifies the registering function that time is up diff --git a/source4/torture/smb2/wscript_build b/source4/torture/smb2/wscript_build index e10d3d90ba5..1183cb93772 100644 --- a/source4/torture/smb2/wscript_build +++ b/source4/torture/smb2/wscript_build @@ -20,6 +20,7 @@ bld.SAMBA_MODULE('TORTURE_SMB2', maxfid.c maxwrite.c multichannel.c + oplock_break_handler.c notify.c notify_disabled.c oplock.c