s4-torture: move torture_wait_for_oplock_break() to central oplock handler.
authorSachin Prabhu <sprabhu@redhat.com>
Thu, 14 Mar 2019 18:15:27 +0000 (18:15 +0000)
committerJeremy Allison <jra@samba.org>
Fri, 19 Apr 2019 17:27:12 +0000 (17:27 +0000)
Signed-off-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source4/torture/smb2/oplock.c
source4/torture/smb2/oplock_break_handler.c
source4/torture/smb2/oplock_break_handler.h
source4/torture/smb2/replay.c

index d6156eb4d8cf0e78e31ffe1a5f8ced8652dbe1a5..885bf1a9e3a4a98b37803a59b54a8ef05c4159d8 100644 (file)
@@ -304,60 +304,6 @@ static bool open_smb2_connection_no_level2_oplocks(struct torture_context *tctx,
        return true;
 }
 
-/*
-   Timer handler function notifies the registering function that time is up
-*/
-static void timeout_cb(struct tevent_context *ev,
-                      struct tevent_timer *te,
-                      struct timeval current_time,
-                      void *private_data)
-{
-       bool *timesup = (bool *)private_data;
-       *timesup = true;
-       return;
-}
-
-/*
-   Wait a short period of time to receive a single oplock break request
-*/
-static void torture_wait_for_oplock_break(struct torture_context *tctx)
-{
-       TALLOC_CTX *tmp_ctx = talloc_new(NULL);
-       struct tevent_timer *te = NULL;
-       struct timeval ne;
-       bool timesup = false;
-       int old_count = break_info.count;
-
-       /* Wait .1 seconds for an oplock break */
-       ne = tevent_timeval_current_ofs(0, 100000);
-
-       if ((te = tevent_add_timer(tctx->ev, tmp_ctx, ne, timeout_cb, &timesup))
-           == NULL)
-       {
-               torture_comment(tctx, "Failed to wait for an oplock break. "
-                                     "test results may not be accurate.");
-               goto done;
-       }
-
-       while (!timesup && break_info.count < old_count + 1) {
-               if (tevent_loop_once(tctx->ev) != 0) {
-                       torture_comment(tctx, "Failed to wait for an oplock "
-                                             "break. test results may not be "
-                                             "accurate.");
-                       goto done;
-               }
-       }
-
-done:
-       /* We don't know if the timed event fired and was freed, we received
-        * our oplock break, or some other event triggered the loop.  Thus,
-        * we create a tmp_ctx to be able to safely free/remove the timed
-        * event in all 3 cases. */
-       talloc_free(tmp_ctx);
-
-       return;
-}
-
 static bool test_smb2_oplock_exclusive1(struct torture_context *tctx,
                                        struct smb2_tree *tree1,
                                        struct smb2_tree *tree2)
index 30863a9167e897c7119ab22f24e24f44b2dd6948..1b20781065840f7525e8222281103056e5a86d9f 100644 (file)
@@ -27,6 +27,7 @@
 #include "torture/smb2/proto.h"
 #include "../libcli/smb/smbXcli_base.h"
 #include "oplock_break_handler.h"
+#include "lib/events/events.h"
 
 struct break_info break_info;
 
@@ -89,3 +90,55 @@ bool torture_oplock_ack_handler(struct smb2_transport *transport,
 
        return true;
 }
+
+
+/*
+ * Timer handler function notifies the registering function that time is up
+ */
+static void timeout_cb(struct tevent_context *ev,
+                      struct tevent_timer *te,
+                      struct timeval current_time,
+                      void *private_data)
+{
+       bool *timesup = (bool *)private_data;
+       *timesup = true;
+}
+
+/*
+ * Wait a short period of time to receive a single oplock break request
+ */
+void torture_wait_for_oplock_break(struct torture_context *tctx)
+{
+       TALLOC_CTX *tmp_ctx = talloc_new(NULL);
+       struct tevent_timer *te = NULL;
+       struct timeval ne;
+       bool timesup = false;
+       int old_count = break_info.count;
+
+       /* Wait .1 seconds for an oplock break */
+       ne = tevent_timeval_current_ofs(0, 100000);
+
+       te = tevent_add_timer(tctx->ev, tmp_ctx, ne, timeout_cb, &timesup);
+       if (te == NULL) {
+               torture_comment(tctx, "Failed to wait for an oplock break. "
+                                     "test results may not be accurate.");
+               goto done;
+       }
+
+       while (!timesup && break_info.count < old_count + 1) {
+               if (tevent_loop_once(tctx->ev) != 0) {
+                       torture_comment(tctx, "Failed to wait for an oplock "
+                                             "break. test results may not be "
+                                             "accurate.");
+                       goto done;
+               }
+       }
+
+done:
+       /* We don't know if the timed event fired and was freed, we received
+        * our oplock break, or some other event triggered the loop.  Thus,
+        * we create a tmp_ctx to be able to safely free/remove the timed
+        * event in all 3 cases.
+        */
+       talloc_free(tmp_ctx);
+}
index 78bba103fb2173680edc3a594c3011a7ad0ed978..6b1eeb14b639979f3de306f3947ac87301854960 100644 (file)
@@ -40,6 +40,7 @@ bool torture_oplock_ack_handler(struct smb2_transport *transport,
                                const struct smb2_handle *handle,
                                uint8_t level,
                                void *private_data);
+void torture_wait_for_oplock_break(struct torture_context *tctx);
 
 static inline void torture_reset_break_info(struct torture_context *tctx,
                              struct break_info *r)
index 903adc6798f6c7419a4578bb332e6bba5a00c8b2..abb026419c7c52f36962f5046b0f33a9073054be 100644 (file)
 
 #define BASEDIR "replaytestdir"
 
-/**
- * Timer handler function notifies the registering function that time is up
- */
-static void timeout_cb(struct tevent_context *ev,
-                      struct tevent_timer *te,
-                      struct timeval current_time,
-                      void *private_data)
-{
-       bool *timesup = (bool *)private_data;
-       *timesup = true;
-       return;
-}
-
-/**
- *  Wait a short period of time to receive a single oplock break request
- */
-static void torture_wait_for_oplock_break(struct torture_context *tctx)
-{
-       TALLOC_CTX *tmp_ctx = talloc_new(NULL);
-       struct tevent_timer *te = NULL;
-       struct timeval ne;
-       bool timesup = false;
-       int old_count = break_info.count;
-
-       /* Wait .1 seconds for an oplock break */
-       ne = tevent_timeval_current_ofs(0, 100000);
-
-       te = tevent_add_timer(tctx->ev, tmp_ctx, ne, timeout_cb, &timesup);
-       if (te == NULL) {
-               torture_comment(tctx, "Failed to wait for an oplock break. "
-                                     "test results may not be accurate.");
-               goto done;
-       }
-
-       while (!timesup && break_info.count < old_count + 1) {
-               if (tevent_loop_once(tctx->ev) != 0) {
-                       torture_comment(tctx, "Failed to wait for an oplock "
-                                             "break. test results may not be "
-                                             "accurate.");
-                       goto done;
-               }
-       }
-
-done:
-       /*
-        * We don't know if the timed event fired and was freed, we received
-        * our oplock break, or some other event triggered the loop.  Thus,
-        * we create a tmp_ctx to be able to safely free/remove the timed
-        * event in all 3 cases.
-        */
-       talloc_free(tmp_ctx);
-
-       return;
-}
-
 /**
  * Test what happens when SMB2_FLAGS_REPLAY_OPERATION is enabled for various
  * commands. We want to verify if the server returns an error code or not.