The branch, master has been updated
       via  2c745cf s4-torture: move lease break handler outside the lease 
testsuite.
      from  68c3ea7 selftest: Avoid a build started just before midnight failing

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 2c745cfac5ccabdceb28fb30eb84346bb2844d1d
Author: Günther Deschner <[email protected]>
Date:   Thu Sep 29 08:41:01 2016 +0200

    s4-torture: move lease break handler outside the lease testsuite.
    
    Guenther
    
    Signed-off-by: Guenther Deschner <[email protected]>
    Pair-Programmed-With: Jose A. Rivera <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>
    
    Autobuild-User(master): Ralph Böhme <[email protected]>
    Autobuild-Date(master): Tue Sep 19 09:36:40 CEST 2017 on sn-devel-144

-----------------------------------------------------------------------

Summary of changes:
 source4/torture/smb2/lease.c               | 440 +++++++++--------------------
 source4/torture/smb2/lease_break_handler.c | 134 +++++++++
 source4/torture/smb2/lease_break_handler.h | 120 ++++++++
 source4/torture/smb2/wscript_build         |   1 +
 4 files changed, 382 insertions(+), 313 deletions(-)
 create mode 100644 source4/torture/smb2/lease_break_handler.c
 create mode 100644 source4/torture/smb2/lease_break_handler.h


Changeset truncated at 500 lines:

diff --git a/source4/torture/smb2/lease.c b/source4/torture/smb2/lease.c
index 6212c08..e8f6d3f 100644
--- a/source4/torture/smb2/lease.c
+++ b/source4/torture/smb2/lease.c
@@ -29,6 +29,7 @@
 #include "libcli/smb/smbXcli_base.h"
 #include "libcli/security/security.h"
 #include "lib/param/param.h"
+#include "lease_break_handler.h"
 
 #define CHECK_VAL(v, correct) do { \
        if ((v) != (correct)) { \
@@ -384,140 +385,6 @@ static bool test_lease_upgrade2(struct torture_context 
*tctx,
 }
 
 
-#define CHECK_LEASE_BREAK(__lb, __oldstate, __state, __key)            \
-       do {                                                            \
-               uint16_t __new = smb2_util_lease_state(__state); \
-               uint16_t __old = smb2_util_lease_state(__oldstate); \
-               CHECK_VAL((__lb)->new_lease_state, __new);      \
-               CHECK_VAL((__lb)->current_lease.lease_state, __old); \
-               CHECK_VAL((__lb)->current_lease.lease_key.data[0], (__key)); \
-               CHECK_VAL((__lb)->current_lease.lease_key.data[1], ~(__key)); \
-               if (__old & (SMB2_LEASE_WRITE | SMB2_LEASE_HANDLE)) { \
-                       CHECK_VAL((__lb)->break_flags, \
-                                 SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED);   
\
-               } else { \
-                       CHECK_VAL((__lb)->break_flags, 0); \
-               } \
-       } while(0)
-
-#define CHECK_LEASE_BREAK_ACK(__lba, __state, __key)                   \
-       do {                                                            \
-               CHECK_VAL((__lba)->out.reserved, 0);                    \
-               CHECK_VAL((__lba)->out.lease.lease_key.data[0], (__key)); \
-               CHECK_VAL((__lba)->out.lease.lease_key.data[1], ~(__key)); \
-               CHECK_VAL((__lba)->out.lease.lease_state, 
smb2_util_lease_state(__state)); \
-               CHECK_VAL((__lba)->out.lease.lease_flags, 0);           \
-               CHECK_VAL((__lba)->out.lease.lease_duration, 0);        \
-       } while(0)
-
-static struct torture_lease_break {
-       struct smb2_lease_break lease_break;
-       struct smb2_transport *lease_transport;
-       bool lease_skip_ack;
-       struct smb2_lease_break_ack lease_break_ack;
-       int count;
-       int failures;
-
-       struct smb2_handle oplock_handle;
-       uint8_t held_oplock_level;
-       uint8_t oplock_level;
-       int oplock_count;
-       int oplock_failures;
-} break_info;
-
-#define CHECK_NO_BREAK(tctx)   \
-       do {                                                            \
-               torture_wait_for_lease_break(tctx);                     \
-               CHECK_VAL(break_info.failures, 0);                      \
-               CHECK_VAL(break_info.count, 0);                         \
-               CHECK_VAL(break_info.oplock_failures, 0);               \
-               CHECK_VAL(break_info.oplock_count, 0);                  \
-       } while(0)
-
-#define CHECK_OPLOCK_BREAK(__brokento) \
-       do {                                                            \
-               torture_wait_for_lease_break(tctx);                     \
-               CHECK_VAL(break_info.oplock_count, 1);                  \
-               CHECK_VAL(break_info.oplock_failures, 0);               \
-               CHECK_VAL(break_info.oplock_level,                      \
-                         smb2_util_oplock_level(__brokento)); \
-               break_info.held_oplock_level = break_info.oplock_level; \
-       } while(0)
-
-#define _CHECK_BREAK_INFO(__oldstate, __state, __key)                  \
-       do {                                                            \
-               torture_wait_for_lease_break(tctx);                     \
-               CHECK_VAL(break_info.failures, 0);                      \
-               CHECK_VAL(break_info.count, 1);                         \
-               CHECK_LEASE_BREAK(&break_info.lease_break, (__oldstate), \
-                   (__state), (__key));                                \
-               if (!break_info.lease_skip_ack && \
-                   (break_info.lease_break.break_flags &               \
-                    SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED))        \
-               {       \
-                       torture_wait_for_lease_break(tctx);             \
-                       CHECK_LEASE_BREAK_ACK(&break_info.lease_break_ack, \
-                                             (__state), (__key));      \
-               }                                                       \
-       } while(0)
-
-#define CHECK_BREAK_INFO(__oldstate, __state, __key)                   \
-       do {                                                            \
-               _CHECK_BREAK_INFO(__oldstate, __state, __key);          \
-               CHECK_VAL(break_info.lease_break.new_epoch, 0);         \
-       } while(0)
-
-#define CHECK_BREAK_INFO_V2(__transport, __oldstate, __state, __key, __epoch) \
-       do {                                                            \
-               _CHECK_BREAK_INFO(__oldstate, __state, __key);          \
-               CHECK_VAL(break_info.lease_break.new_epoch, __epoch);   \
-               if (!TARGET_IS_SAMBA3(tctx)) {                          \
-                       CHECK_VAL((uintptr_t)break_info.lease_transport, \
-                                 (uintptr_t)__transport);              \
-               } \
-       } while(0)
-
-static void torture_lease_break_callback(struct smb2_request *req)
-{
-       NTSTATUS status;
-
-       status = smb2_lease_break_ack_recv(req, &break_info.lease_break_ack);
-       if (!NT_STATUS_IS_OK(status))
-               break_info.failures++;
-
-       return;
-}
-
-/* a lease break request handler */
-static bool torture_lease_handler(struct smb2_transport *transport,
-                                 const struct smb2_lease_break *lb,
-                                 void *private_data)
-{
-       struct smb2_tree *tree = private_data;
-       struct smb2_lease_break_ack io;
-       struct smb2_request *req;
-
-       break_info.lease_transport = transport;
-       break_info.lease_break = *lb;
-       break_info.count++;
-
-       if (break_info.lease_skip_ack) {
-               return true;
-       }
-
-       if (lb->break_flags & SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED) {
-               ZERO_STRUCT(io);
-               io.in.lease.lease_key = lb->current_lease.lease_key;
-               io.in.lease.lease_state = lb->new_lease_state;
-
-               req = smb2_lease_break_ack_send(tree, &io);
-               req->async.fn = torture_lease_break_callback;
-               req->async.private_data = NULL;
-       }
-
-       return true;
-}
-
 /**
  * upgrade3:
  * full matrix of lease upgrade combinations
@@ -607,7 +474,7 @@ static bool test_lease_upgrade3(struct torture_context 
*tctx,
 
                smb2_util_unlink(tree, fname);
 
-               ZERO_STRUCT(break_info);
+               ZERO_STRUCT(lease_break_info);
 
                /* grab first lease */
                smb2_lease_create(&io, &ls, false, fname, LEASE1, 
smb2_util_lease_state(t.held1));
@@ -626,8 +493,8 @@ static bool test_lease_upgrade3(struct torture_context 
*tctx,
                h2 = io.out.file.handle;
 
                /* no break has happened */
-               CHECK_VAL(break_info.count, 0);
-               CHECK_VAL(break_info.failures, 0);
+               CHECK_VAL(lease_break_info.count, 0);
+               CHECK_VAL(lease_break_info.failures, 0);
 
                /* try to upgrade lease1 */
                smb2_lease_create(&io, &ls, false, fname, LEASE1, 
smb2_util_lease_state(t.upgrade_to));
@@ -638,8 +505,8 @@ static bool test_lease_upgrade3(struct torture_context 
*tctx,
                hnew = io.out.file.handle;
 
                /* no break has happened */
-               CHECK_VAL(break_info.count, 0);
-               CHECK_VAL(break_info.failures, 0);
+               CHECK_VAL(lease_break_info.count, 0);
+               CHECK_VAL(lease_break_info.failures, 0);
 
                smb2_util_close(tree, hnew);
                smb2_util_close(tree, h);
@@ -661,59 +528,6 @@ static bool test_lease_upgrade3(struct torture_context 
*tctx,
 
 
 /*
-   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_lease_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 lease 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;
-}
-
-/*
   break_results should be read as "held lease, new lease, hold broken to, new
   grant", i.e. { "RH", "RW", "RH", "R" } means that if key1 holds RH and key2
   tries for RW, key1 will be broken to RH (in this case, not broken at all)
@@ -778,7 +592,7 @@ static bool test_lease_break(struct torture_context *tctx,
                    held, smb2_util_lease_state(held), contend, 
smb2_util_lease_state(contend),
                    brokento, smb2_util_lease_state(brokento), granted, 
smb2_util_lease_state(granted));
 
-               ZERO_STRUCT(break_info);
+               ZERO_STRUCT(lease_break_info);
 
                /* Grab lease. */
                smb2_lease_create(&io, &ls, false, fname, LEASE1, 
smb2_util_lease_state(held));
@@ -802,7 +616,7 @@ static bool test_lease_break(struct torture_context *tctx,
                        CHECK_NO_BREAK(tctx);
                }
 
-               ZERO_STRUCT(break_info);
+               ZERO_STRUCT(lease_break_info);
 
                /*
                  Now verify that an attempt to upgrade LEASE1 results in no
@@ -814,8 +628,8 @@ static bool test_lease_break(struct torture_context *tctx,
                h3 = io.out.file.handle;
                CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
                CHECK_LEASE(&io, brokento, true, LEASE1, 0);
-               CHECK_VAL(break_info.count, 0);
-               CHECK_VAL(break_info.failures, 0);
+               CHECK_VAL(lease_break_info.count, 0);
+               CHECK_VAL(lease_break_info.failures, 0);
 
                smb2_util_close(tree, h);
                smb2_util_close(tree, h2);
@@ -874,7 +688,7 @@ static bool test_lease_nobreakself(struct torture_context 
*tctx,
        h2 = io.out.file.handle;
        CHECK_LEASE(&io, "R", true, LEASE2, 0);
 
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
 
        tree->session->transport->lease.handler = torture_lease_handler;
        tree->session->transport->lease.private_data = tree;
@@ -896,14 +710,14 @@ static bool test_lease_nobreakself(struct torture_context 
*tctx,
 
        /* Now break LEASE1 via h2 */
 
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
        status = smb2_util_write(tree, h2, &c, 0, 1);
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_BREAK_INFO("R", "", LEASE1);
 
        /* .. and break LEASE2 via h1 */
 
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
        status = smb2_util_write(tree, h1, &c, 0, 1);
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_BREAK_INFO("R", "", LEASE2);
@@ -956,7 +770,7 @@ static bool test_lease_statopen(struct torture_context 
*tctx,
        h2 = io.out.file.handle;
        CHECK_LEASE(&io, "RWH", true, LEASE1, 0);
 
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
 
        tree->session->transport->lease.handler = torture_lease_handler;
        tree->session->transport->lease.private_data = tree;
@@ -1014,7 +828,7 @@ static bool test_lease_statopen2(struct torture_context 
*tctx,
        }
 
        smb2_util_unlink(tree, fname);
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
        tree->session->transport->lease.handler = torture_lease_handler;
        tree->session->transport->lease.private_data = tree;
 
@@ -1095,7 +909,7 @@ static bool test_lease_statopen3(struct torture_context 
*tctx,
        }
 
        smb2_util_unlink(tree, fname);
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
        tree->session->transport->lease.handler = torture_lease_handler;
        tree->session->transport->lease.private_data = tree;
 
@@ -1149,7 +963,7 @@ static void torture_oplock_break_callback(struct 
smb2_request *req)
        ZERO_STRUCT(br);
        status = smb2_break_recv(req, &br);
        if (!NT_STATUS_IS_OK(status))
-               break_info.oplock_failures++;
+               lease_break_info.oplock_failures++;
 
        return;
 }
@@ -1163,20 +977,20 @@ static bool torture_oplock_handler(struct smb2_transport 
*transport,
        struct smb2_request *req;
        struct smb2_break br;
 
-       break_info.oplock_handle = *handle;
-       break_info.oplock_level = level;
-       break_info.oplock_count++;
+       lease_break_info.oplock_handle = *handle;
+       lease_break_info.oplock_level   = level;
+       lease_break_info.oplock_count++;
 
        ZERO_STRUCT(br);
        br.in.file.handle = *handle;
        br.in.oplock_level = level;
 
-       if (break_info.held_oplock_level > SMB2_OPLOCK_LEVEL_II) {
+       if (lease_break_info.held_oplock_level > SMB2_OPLOCK_LEVEL_II) {
                req = smb2_break_send(tree, &br);
                req->async.fn = torture_oplock_break_callback;
                req->async.private_data = NULL;
        }
-       break_info.held_oplock_level = level;
+       lease_break_info.held_oplock_level = level;
 
        return true;
 }
@@ -1252,7 +1066,7 @@ static bool test_lease_oplock(struct torture_context 
*tctx,
                    held, smb2_util_lease_state(held), contend, 
smb2_util_oplock_level(contend),
                    brokento, smb2_util_lease_state(brokento), granted, 
smb2_util_oplock_level(granted));
 
-               ZERO_STRUCT(break_info);
+               ZERO_STRUCT(lease_break_info);
 
                /* Grab lease. */
                smb2_lease_create(&io, &ls, false, fname, LEASE1, 
smb2_util_lease_state(held));
@@ -1269,7 +1083,7 @@ static bool test_lease_oplock(struct torture_context 
*tctx,
                h2 = io.out.file.handle;
                CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
                CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level(granted));
-               break_info.held_oplock_level = io.out.oplock_level;
+               lease_break_info.held_oplock_level = io.out.oplock_level;
 
                if (smb2_util_lease_state(held) != 
smb2_util_lease_state(brokento)) {
                        CHECK_BREAK_INFO(held, brokento, LEASE1);
@@ -1294,7 +1108,7 @@ static bool test_lease_oplock(struct torture_context 
*tctx,
                    held, smb2_util_oplock_level(held), contend, 
smb2_util_lease_state(contend),
                    brokento, smb2_util_oplock_level(brokento), granted, 
smb2_util_lease_state(granted));
 
-               ZERO_STRUCT(break_info);
+               ZERO_STRUCT(lease_break_info);
 
                /* Grab an oplock. */
                smb2_oplock_create(&io, fname, smb2_util_oplock_level(held));
@@ -1303,7 +1117,7 @@ static bool test_lease_oplock(struct torture_context 
*tctx,
                h = io.out.file.handle;
                CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
                CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level(held));
-               break_info.held_oplock_level = io.out.oplock_level;
+               lease_break_info.held_oplock_level = io.out.oplock_level;
 
                /* Grab lease. */
                smb2_lease_create(&io, &ls, false, fname, LEASE1, 
smb2_util_lease_state(contend));
@@ -1364,7 +1178,7 @@ static bool test_lease_multibreak(struct torture_context 
*tctx,
 
        smb2_util_unlink(tree, fname);
 
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
 
        /* Grab lease, upgrade to RHW .. */
        smb2_lease_create(&io, &ls, false, fname, LEASE1, 
smb2_util_lease_state("RH"));
@@ -1400,7 +1214,7 @@ static bool test_lease_multibreak(struct torture_context 
*tctx,
        status = smb2_util_close(tree, h3);
        CHECK_STATUS(status, NT_STATUS_OK);
 
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
 
        /* Grab an R lease. */
        smb2_lease_create(&io, &ls, false, fname, LEASE1, 
smb2_util_lease_state("R"));
@@ -1417,7 +1231,7 @@ static bool test_lease_multibreak(struct torture_context 
*tctx,
        h2 = io.out.file.handle;
        CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
        CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level("s"));
-       break_info.held_oplock_level = io.out.oplock_level;
+       lease_break_info.held_oplock_level = io.out.oplock_level;
 
        /* Verify no breaks. */
        CHECK_NO_BREAK(tctx);
@@ -1430,7 +1244,7 @@ static bool test_lease_multibreak(struct torture_context 
*tctx,
        h3 = io.out.file.handle;
        CHECK_CREATED(&io, TRUNCATED, FILE_ATTRIBUTE_ARCHIVE);
        CHECK_VAL(io.out.oplock_level, smb2_util_oplock_level(""));
-       break_info.held_oplock_level = io.out.oplock_level;
+       lease_break_info.held_oplock_level = io.out.oplock_level;
 
        /* Sleep, use a write to clear the recv queue. */
        smb_msleep(250);
@@ -1487,7 +1301,7 @@ static bool test_lease_v2_request_parent(struct 
torture_context *tctx,
 
        smb2_util_unlink(tree, fname);
 
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
 
        ZERO_STRUCT(io);
        smb2_lease_v2_create_share(&io, &ls, false, fname,
@@ -1540,7 +1354,7 @@ static bool test_lease_break_twice(struct torture_context 
*tctx,
 
        smb2_util_unlink(tree, fname);
 
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
        ZERO_STRUCT(io);
 
        smb2_lease_v2_create_share(
@@ -1556,7 +1370,7 @@ static bool test_lease_break_twice(struct torture_context 
*tctx,
        tree->session->transport->lease.handler = torture_lease_handler;
        tree->session->transport->lease.private_data = tree;
 
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
 
        smb2_lease_v2_create_share(
                &io, &ls2, false, fname, smb2_util_share_access("R"),
@@ -1571,7 +1385,7 @@ static bool test_lease_break_twice(struct torture_context 
*tctx,
                &io, &ls2, false, fname, smb2_util_share_access("RWD"),
                LEASE2, NULL, smb2_util_lease_state("RWH"), 0x22);
 
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
 
        status = smb2_create(tree, mem_ctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
@@ -1628,7 +1442,7 @@ static bool test_lease_v2_request(struct torture_context 
*tctx,
        tree->session->transport->oplock.handler = torture_oplock_handler;
        tree->session->transport->oplock.private_data = tree;
 
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
 
        ZERO_STRUCT(io);
        smb2_lease_v2_create_share(&io, &ls1, false, fname,
@@ -1686,7 +1500,7 @@ static bool test_lease_v2_request(struct torture_context 
*tctx,
        CHECK_BREAK_INFO_V2(tree->session->transport,
                            "RH", "", LEASE2, ls2.lease_epoch + 2);
 
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
 
        ZERO_STRUCT(io);
        smb2_lease_v2_create_share(&io, &ls2t, true, dname,
@@ -1771,7 +1585,7 @@ static bool test_lease_v2_epoch1(struct torture_context 
*tctx,
        tree->session->transport->oplock.handler = torture_oplock_handler;
        tree->session->transport->oplock.private_data = tree;
 
-       ZERO_STRUCT(break_info);
+       ZERO_STRUCT(lease_break_info);
 
        ZERO_STRUCT(io);
        smb2_lease_v2_create_share(&io, &ls, false, fname,
@@ -1836,7 +1650,7 @@ static bool test_lease_v2_epoch2(struct torture_context 
*tctx,
        tree->session->transport->oplock.handler = torture_oplock_handler;
        tree->session->transport->oplock.private_data = tree;
 


-- 
Samba Shared Repository

Reply via email to