s4/torture: some tests for kernel oplocks
authorRalph Boehme <slow@samba.org>
Wed, 1 Mar 2017 17:13:35 +0000 (18:13 +0100)
committerKarolin Seeger <kseeger@samba.org>
Tue, 14 Mar 2017 11:49:24 +0000 (12:49 +0100)
Bug: https://bugzilla.samba.org/show_bug.cgi?id=7537

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(backported from commit fd03420c4f59d3248b80d07a302d1404ce78b09f)

selftest/target/Samba3.pm
source3/selftest/tests.py
source4/selftest/tests.py
source4/torture/smb2/oplock.c
source4/torture/smb2/smb2.c

index 4596a0a118da05a663d5262f806a4a9e753e4886..619ae1eafaa201266fa2c706c472732ba5fc1ee8 100755 (executable)
@@ -1717,6 +1717,10 @@ sub provision($$$$$$$$)
        copy = tmp
        acl_xattr:ignore system acls = yes
        acl_xattr:default acl style = windows
+[kernel_oplocks]
+       copy = tmp
+       kernel oplocks = yes
+       vfs objects = streams_xattr xattr_tdb
        ";
        close(CONF);
 
index 4ad8aa98ec48e7f173d9f97f6cef89c8cd0a9b92..9915fb66a25399f64b53fe2cb00379f2f2a476de 100755 (executable)
@@ -55,6 +55,7 @@ finally:
     f.close()
 
 have_libarchive = ("HAVE_LIBARCHIVE" in config_hash)
+have_linux_kernel_oplocks = ("HAVE_KERNEL_OPLOCKS_LINUX" in config_hash)
 
 plantestsuite("samba3.blackbox.success", "nt4_dc:local", [os.path.join(samba3srcdir, "script/tests/test_success.sh")])
 plantestsuite("samba3.blackbox.failure", "nt4_dc:local", [os.path.join(samba3srcdir, "script/tests/test_failure.sh")])
@@ -418,6 +419,9 @@ for t in tests:
         plansmbtorture4testsuite(t, "ad_dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD --signing=required')
     elif t == "smb2.dosmode":
         plansmbtorture4testsuite(t, "simpleserver", '//$SERVER/dosmode -U$USERNAME%$PASSWORD')
+    elif t == "smb2.kernel-oplocks":
+        if have_linux_kernel_oplocks:
+            plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER/kernel_oplocks -U$USERNAME%$PASSWORD')
     elif t == "vfs.acl_xattr":
         plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD')
     else:
index 7eb4e462b55120139beb661dcf81701014c434a9..073ff0ac4743e56b21b0a7511babbf2da62ac50e 100755 (executable)
@@ -301,7 +301,7 @@ for t in nbt_tests:
 ntvfsargs = ["--option=torture:sharedelay=100000", "--option=torture:oplocktimeout=3", "--option=torture:writetimeupdatedelay=500000"]
 
 # Filter smb2 tests that should not run against ad_dc_ntvfs
-smb2_s3only = ["smb2.change_notify_disabled", "smb2.dosmode"]
+smb2_s3only = ["smb2.change_notify_disabled", "smb2.dosmode", "smb2.kernel-oplocks"]
 smb2 = [x for x in smbtorture4_testsuites("smb2.") if x not in smb2_s3only]
 
 #The QFILEINFO-IPC test needs to be on ipc$
index fdd29c3c905d4afdcf01d4912cb9eb7b30b680e0..11e1bdc6e376eebb4abb9a6d5b05a49aaab30c54 100644 (file)
@@ -4197,3 +4197,143 @@ bool test_smb2_hold_oplock(struct torture_context *tctx,
        talloc_free(mem_ctx);
        return true;
 }
+
+
+static bool test_smb2_kernel_oplocks1(struct torture_context *tctx,
+                                     struct smb2_tree *tree)
+{
+       const char *fname = "test_kernel_oplock1.dat";
+       NTSTATUS status;
+       bool ret = true;
+       struct smb2_create create;
+       struct smb2_handle h1 = {{0}}, h2 = {{0}};
+
+       smb2_util_unlink(tree, fname);
+
+       tree->session->transport->oplock.handler = torture_oplock_handler;
+       tree->session->transport->oplock.private_data = tree;
+       ZERO_STRUCT(break_info);
+
+       ZERO_STRUCT(create);
+       create.in.desired_access = SEC_RIGHTS_FILE_ALL;
+       create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+       create.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
+       create.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
+       create.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
+       create.in.fname = fname;
+       create.in.oplock_level = SMB2_OPLOCK_LEVEL_EXCLUSIVE;
+
+       status = smb2_create(tree, tctx, &create);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "Error opening the file\n");
+       h1 = create.out.file.handle;
+
+       torture_assert_goto(tctx, create.out.oplock_level == SMB2_OPLOCK_LEVEL_EXCLUSIVE, ret, done,
+                           "Oplock level is not SMB2_OPLOCK_LEVEL_EXCLUSIVE\n");
+
+       ZERO_STRUCT(create);
+       create.in.desired_access = SEC_RIGHTS_FILE_ALL;
+       create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+       create.in.share_access = NTCREATEX_SHARE_ACCESS_MASK;
+       create.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
+       create.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
+       create.in.fname = fname;
+
+       status = smb2_create(tree, tctx, &create);
+       torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_SHARING_VIOLATION, ret, done,
+                                          "Open didn't return NT_STATUS_SHARING_VIOLATION\n");
+       h2 = create.out.file.handle;
+
+       torture_wait_for_oplock_break(tctx);
+       if (break_info.count != 0) {
+               torture_warning(tctx, "Open caused oplock break\n");
+       }
+
+       smb2_util_close(tree, h1);
+       smb2_util_close(tree, h2);
+
+done:
+       if (!smb2_util_handle_empty(h1)) {
+               smb2_util_close(tree, h1);
+       }
+       if (!smb2_util_handle_empty(h2)) {
+               smb2_util_close(tree, h2);
+       }
+       smb2_util_unlink(tree, fname);
+       return ret;
+}
+
+static bool test_smb2_kernel_oplocks2(struct torture_context *tctx,
+                                     struct smb2_tree *tree)
+{
+       const char *fname = "test_kernel_oplock2.dat";
+       const char *sname = "test_kernel_oplock2.dat:foo";
+       NTSTATUS status;
+       bool ret = true;
+       struct smb2_create create;
+       struct smb2_handle h1 = {{0}}, h2 = {{0}};
+
+       smb2_util_unlink(tree, fname);
+
+       tree->session->transport->oplock.handler = torture_oplock_handler;
+       tree->session->transport->oplock.private_data = tree;
+       ZERO_STRUCT(break_info);
+
+       ZERO_STRUCT(create);
+       create.in.desired_access = SEC_RIGHTS_FILE_ALL;
+       create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+       create.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
+       create.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
+       create.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
+       create.in.fname = fname;
+       create.in.oplock_level = SMB2_OPLOCK_LEVEL_EXCLUSIVE;
+
+       status = smb2_create(tree, tctx, &create);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "Error opening the file\n");
+       h1 = create.out.file.handle;
+
+       torture_assert_goto(tctx, create.out.oplock_level == SMB2_OPLOCK_LEVEL_EXCLUSIVE, ret, done,
+                           "Oplock level is not SMB2_OPLOCK_LEVEL_EXCLUSIVE\n");
+
+       ZERO_STRUCT(create);
+       create.in.desired_access = SEC_RIGHTS_FILE_ALL;
+       create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+       create.in.share_access = NTCREATEX_SHARE_ACCESS_MASK;
+       create.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
+       create.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
+       create.in.fname = sname;
+
+       status = smb2_create(tree, tctx, &create);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "Error opening the file\n");
+       h2 = create.out.file.handle;
+
+       torture_wait_for_oplock_break(tctx);
+       if (break_info.count != 0) {
+               torture_warning(tctx, "Stream open caused oplock break\n");
+       }
+
+       smb2_util_close(tree, h1);
+       smb2_util_close(tree, h2);
+
+done:
+       if (!smb2_util_handle_empty(h1)) {
+               smb2_util_close(tree, h1);
+       }
+       if (!smb2_util_handle_empty(h2)) {
+               smb2_util_close(tree, h2);
+       }
+       smb2_util_unlink(tree, fname);
+       return ret;
+}
+
+struct torture_suite *torture_smb2_kernel_oplocks_init(void)
+{
+       struct torture_suite *suite =
+           torture_suite_create(talloc_autofree_context(), "kernel-oplocks");
+
+       torture_suite_add_1smb2_test(suite, "kernel_oplocks1", test_smb2_kernel_oplocks1);
+       torture_suite_add_1smb2_test(suite, "kernel_oplocks2", test_smb2_kernel_oplocks2);
+
+       suite->description = talloc_strdup(suite, "SMB2-KERNEL-OPLOCK tests");
+
+       return suite;
+}
index be632cccca5ad5a7cfe25f8ea68e88d4f8124204..9f2f757646ed72e736a21321e82e06c29360c4ce 100644 (file)
@@ -163,6 +163,7 @@ NTSTATUS torture_smb2_init(void)
        torture_suite_add_suite(suite, torture_smb2_lease_init());
        torture_suite_add_suite(suite, torture_smb2_compound_init());
        torture_suite_add_suite(suite, torture_smb2_oplocks_init());
+       torture_suite_add_suite(suite, torture_smb2_kernel_oplocks_init());
        torture_suite_add_suite(suite, torture_smb2_streams_init());
        torture_suite_add_suite(suite, torture_smb2_ioctl_init());
        torture_suite_add_suite(suite, torture_smb2_rename_init());