smbtorture: Add smb2.ioctl.sparse_set_sparse
authorChristof Schmitt <cs@samba.org>
Fri, 28 Sep 2018 23:08:22 +0000 (16:08 -0700)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 5 Jul 2019 03:33:19 +0000 (03:33 +0000)
This allows for manual testing of changing the sparse setting on a file
and verifying the flag in the file system.

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
selftest/skip
source4/torture/smb2/ioctl.c
source4/torture/smb2/smb2.c

index 43f65c3f1bdd3afda1ae0e4cfc4aecdae0873266..d9e615146fb195d6c1599b9c81414803a2d91728 100644 (file)
@@ -70,6 +70,7 @@
 ^samba3.smb2.hold-oplock                # Not a test, but a way to block other clients for a test
 ^samba3.smb2.hold-sharemode             # Not a test, but a way to block other clients for a test
 ^samba3.smb2.check-sharemode            # Not a test, but a way to test sharemodes outside of Samba
+^samba3.smb2.set-sparse-ioctl           # For manual testing, needs additional parameters.
 ^samba3.smb2.durable-open-disconnect    # Not a test, but a way to create a disconnected durable
 ^samba3.smb2.scan                       # No tests
 ^samba3.smb2.oplock.levelii501         # No test yet
@@ -83,6 +84,7 @@
 ^samba4.smb2.hold-oplock               # Not a test, but a way to block other clients for a test
 ^samba4.smb2.hold-sharemode            # Not a test, but a way to block other clients for a test
 ^samba4.smb2.check-sharemode            # Not a test, but a way to test sharemodes outside of Samba
+^samba4.smb2.set-sparse-ioctl           # For manual testing, needs additional parameters.
 ^samba4.raw.ping.pong          # Needs second server to test
 ^samba4.rpc.samr.accessmask
 ^samba4.rpc.samr.passwords.*ncacn_np\(ad_dc_ntvfs\) # currently fails, possibly config issue
index 302ca4418f1e79daf43bb42047ea5f12e0a81dc4..39aedba7cc8a03fec887a42641f93a5d3a5b6ef8 100644 (file)
@@ -3235,6 +3235,55 @@ static NTSTATUS test_sparse_get(struct torture_context *torture,
        return status;
 }
 
+/*
+ * Manually test setting and clearing sparse flag. Intended for file system
+ * specifc tests to toggle the flag through SMB and check the status in the
+ * file system.
+ */
+bool test_ioctl_set_sparse(struct torture_context *tctx)
+{
+       bool set, ret = true;
+       const char *filename = NULL;
+       struct smb2_create create = { };
+       struct smb2_tree *tree = NULL;
+       NTSTATUS status;
+
+       set = torture_setting_bool(tctx, "set_sparse", true);
+       filename = torture_setting_string(tctx, "filename", NULL);
+
+       if (filename == NULL) {
+               torture_fail(tctx, "Need to provide filename through "
+                            "--option=torture:filename=testfile\n");
+               return false;
+       }
+
+       if (!torture_smb2_connection(tctx, &tree)) {
+               torture_comment(tctx, "Initializing smb2 connection failed.\n");
+               return false;
+       }
+
+       create.in.desired_access = SEC_RIGHTS_DIR_ALL;
+       create.in.create_options = 0;
+       create.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+       create.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
+               NTCREATEX_SHARE_ACCESS_WRITE |
+               NTCREATEX_SHARE_ACCESS_DELETE;
+       create.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
+       create.in.fname = filename;
+
+       status = smb2_create(tree, tctx, &create);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "CREATE failed.\n");
+
+       status = test_ioctl_sparse_req(tctx, tctx, tree,
+                                      create.out.file.handle, set);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "FSCTL_SET_SPARSE failed.\n");
+done:
+
+       return ret;
+}
+
 static bool test_ioctl_sparse_file_flag(struct torture_context *torture,
                                        struct smb2_tree *tree)
 {
index 2a465a55ba2fe9acf2b518a18358a0b5e0fb2f4f..56df0ddaafe5128e8bac3fa447ca38b06de9aeae 100644 (file)
@@ -175,6 +175,8 @@ NTSTATUS torture_smb2_init(TALLOC_CTX *ctx)
        torture_suite_add_suite(suite, torture_smb2_kernel_oplocks_init(suite));
        torture_suite_add_suite(suite, torture_smb2_streams_init(suite));
        torture_suite_add_suite(suite, torture_smb2_ioctl_init(suite));
+       torture_suite_add_simple_test(suite, "set-sparse-ioctl",
+                                     test_ioctl_set_sparse);
        torture_suite_add_suite(suite, torture_smb2_rename_init(suite));
        torture_suite_add_1smb2_test(suite, "bench-oplock", test_smb2_bench_oplock);
        torture_suite_add_suite(suite, torture_smb2_sharemode_init(suite));