Split test_multichannel_lease_break()
authorSachin Prabhu <sprabhu@redhat.com>
Wed, 14 Feb 2018 11:50:32 +0000 (17:20 +0530)
committerSachin Prabhu <sprabhu@redhat.com>
Tue, 17 Jul 2018 20:46:27 +0000 (21:46 +0100)
into
test_multichannel_lease_break_test2() and
test_multichannel_lease_break_test3()

Signed-off-by: Sachin Prabhu <sprabhu@redhat.com>
source4/torture/smb2/multichannel.c

index a1d75c17d0414ac5b2e58a21496b2f6b58b360ec..7176a716b3f03049385e0e481df03409f45f8b80 100644 (file)
@@ -1077,10 +1077,22 @@ done:
        return ret;
 }
 
-static bool test_multichannel_lease_break(struct torture_context *tctx,
-                                         struct smb2_tree *tree1)
+/*
+ * Test 2:
+ *     open file1 in session 2A
+ *     open file2 in session 2B
+ *     open file3 in session 2C
+ *     block 2B 2C
+ *     open file2 in session 1
+ *             lease break reaches through session 2A
+ *     server allows session 1 to open file1
+ *     unblock 2B 2C, send keep alive
+ *     open file1 in session 1
+ *             lease break sent to 2A
+ */
+static bool test_multichannel_lease_break_test2(struct torture_context *tctx,
+                                               struct smb2_tree *tree1)
 {
-
        const char *host = torture_setting_string(tctx, "host", NULL);
        const char *share = torture_setting_string(tctx, "share", NULL);
        struct cli_credentials *credentials = popt_get_cmdline_credentials();
@@ -1104,7 +1116,6 @@ static bool test_multichannel_lease_break(struct torture_context *tctx,
        struct smb2_tree *tree2B = NULL;
        struct smb2_tree *tree2C = NULL;
        struct smb2_transport *transport1 = tree1->session->transport;
-       struct smb2_transport *transport2A = NULL;
        struct smb2_transport *transport2B = NULL;
        struct smb2_transport *transport2C = NULL;
        struct smbcli_options transport2_options;
@@ -1115,7 +1126,6 @@ static bool test_multichannel_lease_break(struct torture_context *tctx,
        struct smb2_lease ls1;
        struct smb2_lease ls2;
        struct smb2_lease ls3;
-       DATA_BLOB blob;
 
        if (!test_multichannel_initial_checks(tctx, tree1))
                return true;
@@ -1150,27 +1160,13 @@ static bool test_multichannel_lease_break(struct torture_context *tctx,
 
        transport2_options = transport1->options;
 
-       /*
-        * Test 3:
-        *      open file1 in session 2A
-        *      open file2 in session 2B
-        *      open file3 in session 2C
-        *      block 2B 2C
-        *      open file2 in session 1
-        *              lease break reaches through session 2A
-        *      server allows session 1 to open file1
-        *      unblock 2B 2C, send keep alive
-        *      open file1 in session 1
-        *              lease break sent to 2A
-        */
-       torture_comment(tctx, "Test 3 start \n");
+       torture_comment(tctx, "Test 2 start \n");
 
        rval = test_multichannel_create_channels2(tctx, host, share,
                                                  credentials,
                                                  &transport2_options,
                                                  &tree2A, &tree2B, &tree2C);
        CHECK_VAL(rval, 0);
-       transport2A = tree2A->session->transport;
        transport2B = tree2B->session->transport;
        transport2C = tree2C->session->transport;
 
@@ -1282,30 +1278,137 @@ static bool test_multichannel_lease_break(struct torture_context *tctx,
        test_multichannel_free_channels2(tree2A, tree2B, tree2C);
        tree2A = tree2B = tree2C = NULL;
 
-       /*
-        * Test 4:
-        *      open file1 in session 2A
-        *      open file2 in session 2B
-        *      open file3 in session 2C
-        *      Disconnect 2C
-        *      open file3 in session 1
-        *              lease break?
-        *      server allows session 1 to open file1
-        *      Block 2B
-        *      open file2 in session 1
-        *              no oplock break because 2B blocked.
-        *      session 1 allowed to open file2
-        *      2A writes "Here I am to file 2"
-        *      Recieve break on 1 drop oplock.
-        */
-       torture_comment(tctx, "Test 4 start \n");
+done:
+       if (block_ok && !unblock_ok) {
+               /* unblock tcp connection of transport2C */
+               unblock_ok = torture_unblock_tcp_transport(tctx, transport2C);
+               unblock_ok = torture_unblock_tcp_transport(tctx, transport2B);
+       }
+
+       tree1->session = session1;
+
+       smb2_util_close(tree1, h_client1_file1);
+       smb2_util_close(tree1, h_client1_file2);
+       smb2_util_close(tree1, h_client1_file3);
+       if (tree2A != NULL) {
+               smb2_util_close(tree2A, h_client2_file1);
+               smb2_util_close(tree2A, h_client2_file2);
+               smb2_util_close(tree2A, h_client2_file3);
+       }
+
+       if (h != NULL) {
+               smb2_util_close(tree1, *h);
+       }
+
+       smb2_util_unlink(tree1, fname1);
+       smb2_util_unlink(tree1, fname2);
+       smb2_util_unlink(tree1, fname3);
+       smb2_deltree(tree1, BASEDIR);
+
+       test_multichannel_free_channels2(tree2A, tree2B, tree2C);
+       talloc_free(tree1);
+       talloc_free(mem_ctx);
+
+       return ret;
+}
+
+/*
+ * Test 3:
+ *     open file1 in session 2A
+ *     open file2 in session 2B
+ *     open file3 in session 2C
+ *     Disconnect 2C
+ *     open file3 in session 1
+ *             lease break sent to 2A
+ *             open success
+ *     Block 2B
+ *     open file2 in session 1
+ *             lease break sent to 2A
+ *     session 1 allowed to open file2
+ *     2A writes "Here I am to file 2"
+ *             lease break sent to 1
+ *     Cleanup
+ */
+static bool test_multichannel_lease_break_test3(struct torture_context *tctx,
+                                         struct smb2_tree *tree1)
+{
+
+       const char *host = torture_setting_string(tctx, "host", NULL);
+       const char *share = torture_setting_string(tctx, "share", NULL);
+       struct cli_credentials *credentials = popt_get_cmdline_credentials();
+       NTSTATUS status;
+       TALLOC_CTX *mem_ctx = talloc_new(tctx);
+       struct smb2_handle _h;
+       struct smb2_handle *h = NULL;
+       struct smb2_handle h_client1_file1 = { 0 };
+       struct smb2_handle h_client1_file2 = { 0 };
+       struct smb2_handle h_client1_file3 = { 0 };
+       struct smb2_handle h_client2_file1 = { 0 };
+       struct smb2_handle h_client2_file2 = { 0 };
+       struct smb2_handle h_client2_file3 = { 0 };
+       struct smb2_create io1, io2, io3;
+       bool ret = true;
+       int rval;
+       const char *fname1 = BASEDIR "\\lease_break_test1.dat";
+       const char *fname2 = BASEDIR "\\lease_break_test2.dat";
+       const char *fname3 = BASEDIR "\\lease_break_test3.dat";
+       struct smb2_tree *tree2A = NULL;
+       struct smb2_tree *tree2B = NULL;
+       struct smb2_tree *tree2C = NULL;
+       struct smb2_transport *transport1 = tree1->session->transport;
+       struct smb2_transport *transport2B = NULL;
+       struct smb2_transport *transport2C = NULL;
+       struct smbcli_options transport2_options;
+       struct smb2_session *session1 = tree1->session;
+       uint16_t local_port = 0;
+       bool block_ok = false;
+       bool unblock_ok = false;
+       struct smb2_lease ls1;
+       struct smb2_lease ls2;
+       struct smb2_lease ls3;
+       DATA_BLOB blob;
+
+       if (!test_multichannel_initial_checks(tctx, tree1))
+               return true;
+
+       torture_reset_lease_break_info(tctx, &lease_break_info);
+
+       transport1->lease.handler = torture_lease_handler;
+       transport1->lease.private_data = tree1;
+       torture_comment(tctx, "transport1  [%p]\n", transport1);
+       local_port = torture_get_local_port_from_transport(transport1);
+       torture_comment(tctx, "transport1 uses tcp port: %d\n", local_port);
+
+       status = torture_smb2_testdir(tree1, BASEDIR, &_h);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       smb2_util_close(tree1, _h);
+       smb2_util_unlink(tree1, fname1);
+       smb2_util_unlink(tree1, fname2);
+       smb2_util_unlink(tree1, fname3);
+       CHECK_VAL(lease_break_info.count, 0);
+
+       smb2_lease_create(&io1, &ls1, false, fname1, LEASE2F1,
+                         smb2_util_lease_state("RHW"));
+       test_multichannel_init_smb_create(&io1);
+
+       smb2_lease_create(&io2, &ls2, false, fname2, LEASE2F2,
+                         smb2_util_lease_state("RHW"));
+       test_multichannel_init_smb_create(&io2);
+
+       smb2_lease_create(&io3, &ls3, false, fname3, LEASE2F3,
+                         smb2_util_lease_state("RHW"));
+       test_multichannel_init_smb_create(&io3);
+
+       transport2_options = transport1->options;
+
+
+       torture_comment(tctx, "Test 3 start \n");
 
        rval = test_multichannel_create_channels2(tctx, host, share,
                                                  credentials,
                                                  &transport2_options,
                                                  &tree2A, &tree2B, &tree2C);
        CHECK_VAL(rval, 0);
-       transport2A = tree2A->session->transport;
        transport2B = tree2B->session->transport;
        transport2C = tree2C->session->transport;
 
@@ -1318,9 +1421,6 @@ static bool test_multichannel_lease_break(struct torture_context *tctx,
        h_client2_file1 = io1.out.file.handle;
        CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
        CHECK_LEASE(&io1, "RHW", true, LEASE2F1, 0);
-       CHECK_VAL(io1.out.durable_open_v2, false); //true);
-       CHECK_VAL(io1.out.timeout, io1.in.timeout);
-       CHECK_VAL(io1.out.durable_open, false);
        CHECK_VAL(lease_break_info.count, 0);
 
        /* 2b opens file2 */
@@ -1332,9 +1432,6 @@ static bool test_multichannel_lease_break(struct torture_context *tctx,
        h_client2_file2 = io2.out.file.handle;
        CHECK_CREATED(&io2, CREATED, FILE_ATTRIBUTE_ARCHIVE);
        CHECK_LEASE(&io2, "RHW", true, LEASE2F2, 0);
-       CHECK_VAL(io2.out.durable_open_v2, false); //true);
-       CHECK_VAL(io2.out.timeout, io2.in.timeout);
-       CHECK_VAL(io2.out.durable_open, false);
        CHECK_VAL(lease_break_info.count, 0);
 
        /* 2c opens file3 */
@@ -1346,9 +1443,6 @@ static bool test_multichannel_lease_break(struct torture_context *tctx,
        h_client2_file3 = io3.out.file.handle;
        CHECK_CREATED(&io3, CREATED, FILE_ATTRIBUTE_ARCHIVE);
        CHECK_LEASE(&io3, "RHW", true, LEASE2F3, 0);
-       CHECK_VAL(io3.out.durable_open_v2, false);
-       CHECK_VAL(io3.out.timeout, io2.in.timeout);
-       CHECK_VAL(io3.out.durable_open, false);
        CHECK_VAL(lease_break_info.count, 0);
 
        /* Disconnect 2C */
@@ -1369,9 +1463,6 @@ static bool test_multichannel_lease_break(struct torture_context *tctx,
        CHECK_CREATED(&io3, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
        CHECK_LEASE(&io3, "RH", true, LEASE1F3, 0);
        CHECK_BREAK_INFO("RHW", "RH", LEASE2F3);
-       CHECK_VAL(io1.out.durable_open_v2, false);
-       CHECK_VAL(io1.out.timeout, 0);
-       CHECK_VAL(io1.out.durable_open, false);
        CHECK_VAL(lease_break_info.count, 1);
 
        torture_reset_lease_break_info(tctx, &lease_break_info);
@@ -1393,10 +1484,8 @@ static bool test_multichannel_lease_break(struct torture_context *tctx,
        CHECK_CREATED(&io2, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
        CHECK_LEASE(&io2, "RH", true, LEASE1F2, 0);
        CHECK_BREAK_INFO("RHW", "RH", LEASE2F2);
-       CHECK_VAL(io2.out.durable_open_v2, false);
-       CHECK_VAL(io2.out.timeout, 0);
-       CHECK_VAL(io2.out.durable_open, false);
        CHECK_VAL(lease_break_info.count, 1);
+       torture_reset_lease_break_info(tctx, &lease_break_info);
 
        /* 2A writes "Here I am to file 2" */
 
@@ -1414,14 +1503,25 @@ static bool test_multichannel_lease_break(struct torture_context *tctx,
        unblock_ok = torture_unblock_tcp_transport(tctx, transport2B);
        torture_assert(tctx, unblock_ok, "we could not unblock tcp transport");
 
-       torture_reset_lease_break_info(tctx, &lease_break_info);
        smb2_util_close(tree1, h_client1_file1);
        smb2_util_close(tree1, h_client1_file2);
        smb2_util_close(tree1, h_client1_file3);
+
+       /* Writing to the file by Session 2 earlier leads to a
+        * lease break sent to session 1.
+        * Make sure that this is received.
+        * Check placed here because of delay in response
+        * to the lease break by this test.
+        */
+       CHECK_VAL(lease_break_info.count, 1);
+       torture_reset_lease_break_info(tctx, &lease_break_info);
+
        smb2_util_close(tree2A, h_client2_file1);
        smb2_util_close(tree2A, h_client2_file2);
        smb2_util_close(tree2A, h_client2_file3);
 
+       CHECK_VAL(lease_break_info.count, 0);
+
        smb2_util_unlink(tree1, fname1);
        smb2_util_unlink(tree1, fname2);
        smb2_util_unlink(tree1, fname3);
@@ -1431,9 +1531,6 @@ static bool test_multichannel_lease_break(struct torture_context *tctx,
 
 done:
        if (block_ok && !unblock_ok) {
-               /* unblock tcp connection of transport2C */
-               unblock_ok = torture_unblock_tcp_transport(tctx, transport2C);
-               unblock_ok = torture_unblock_tcp_transport(tctx, transport2A);
                unblock_ok = torture_unblock_tcp_transport(tctx, transport2B);
        }
 
@@ -1576,8 +1673,10 @@ struct torture_suite *torture_smb2_multichannel_init(TALLOC_CTX *ctx)
        torture_suite_add_1smb2_test(suite, "session_bind_multiple_nics", test_session_bind_multiple_nics);
        torture_suite_add_1smb2_test(suite, "interface_info", test_multichannel_interface_info);
        torture_suite_add_1smb2_test(suite, "oplock_break", test_multichannel_oplock_break);
-       torture_suite_add_1smb2_test(suite, "lease_break", test_multichannel_lease_break);
+       //torture_suite_add_1smb2_test(suite, "lease_break", test_multichannel_lease_break);
        torture_suite_add_1smb2_test(suite, "lease_break_test1", test_multichannel_lease_break_test1);
+       torture_suite_add_1smb2_test(suite, "lease_break_test2", test_multichannel_lease_break_test2);
+       torture_suite_add_1smb2_test(suite, "lease_break_test3", test_multichannel_lease_break_test3);
        torture_suite_add_1smb2_test(suite, "num_channels", test_multichannel_num_channels);
 
        suite->description = talloc_strdup(suite, "SMB2 Multichannel tests");