sq source4/torture/util_writetime.c source4/torture/smb2/durable_open.c
authorStefan Metzmacher <metze@samba.org>
Wed, 15 Aug 2018 07:39:36 +0000 (09:39 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 15 Aug 2018 07:39:36 +0000 (09:39 +0200)
source4/torture/smb2/durable_open.c
source4/torture/util.h
source4/torture/util_writetime.c

index 814f4944152d195b2034e6f5b3bb07698caf385f..f5ace21de8a39148f6762e14d3259075de422c4c 100644 (file)
@@ -2974,6 +2974,62 @@ done:
        return ret;
 }
 
+static bool test_durable_open_delaywrite1_close(void *private_data,
+                                               union smb_fileinfo *finfo)
+{
+       struct test_durable_open_delaywrite1_state *state =
+               (struct test_durable_open_delaywrite1_state *)private_data;
+       struct torture_context *tctx = state->tctx;
+       union smb_fileinfo t1finfoCL;
+       union smb_fileinfo t2finfoCL;
+       struct smb2_close cl1;
+       struct smb2_close cl2;
+       union smb_fileinfo t2finfo;
+       NTSTATUS status;
+       bool ret = true;
+
+       ZERO_STRUCTP(finfo);
+
+       ZERO_STRUCT(cl1);
+       cl1.in.file.handle = *state->h1;
+       cl1.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
+       status = smb2_close(state->tree1, &cl1);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       state->h1 = NULL;
+       ZERO_STRUCT(t1finfoCL);
+       t1finfoCL.basic_info.out.create_time = cl1.out.create_time;
+       t1finfoCL.basic_info.out.access_time = cl1.out.access_time;
+       t1finfoCL.basic_info.out.write_time = cl1.out.write_time;
+       t1finfoCL.basic_info.out.change_time = cl1.out.change_time;
+       t1finfoCL.basic_info.out.attrib = cl1.out.file_attr;
+
+       ZERO_STRUCT(t2finfo);
+       t2finfo.basic_info.level = RAW_FILEINFO_BASIC_INFORMATION;
+       t2finfo.basic_info.in.file.handle = *state->h2;
+
+       GET_INFO_FILE(state->tree2, t2finfo);
+       COMPARE_ALL_TIMES_EQUAL(t2finfo, t1finfoCL);
+
+       ZERO_STRUCT(cl2);
+       cl2.in.file.handle = *state->h2;
+       cl2.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
+       status = smb2_close(state->tree2, &cl2);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       state->h2 = NULL;
+       ZERO_STRUCT(t2finfoCL);
+       t2finfoCL.basic_info.out.create_time = cl2.out.create_time;
+       t2finfoCL.basic_info.out.access_time = cl2.out.access_time;
+       t2finfoCL.basic_info.out.write_time = cl2.out.write_time;
+       t2finfoCL.basic_info.out.change_time = cl2.out.change_time;
+       t2finfoCL.basic_info.out.attrib = cl2.out.file_attr;
+       COMPARE_ALL_TIMES_EQUAL(t2finfoCL, t1finfoCL);
+
+       finfo->basic_info.out = t1finfoCL.basic_info.out;
+
+done:
+       return ret;
+}
+
 static bool test_durable_open_delaywrite1(struct torture_context *tctx,
                                          struct smb2_tree *tree1,
                                          struct smb2_tree *tree2)
@@ -2987,23 +3043,17 @@ static bool test_durable_open_delaywrite1(struct torture_context *tctx,
        TALLOC_CTX *mem_ctx = talloc_new(tctx);
        char fname[256];
        struct smb2_handle _h1;
-       struct smb2_handle *h1 = NULL;
        struct smb2_handle _h2;
-       struct smb2_handle *h2 = NULL;
        struct smb2_create cr1;
        struct smb2_create cr2;
-       union smb_fileinfo c1finfoCR, c1finfo0, c1finfo1, c1finfo2, c1finfoCL;
-       union smb_fileinfo c2finfoCR, c2finfo0, c2finfo1, c2finfo2, c2finfo3, c2finfoCL;
-       struct smb2_close cl1;
-       struct smb2_close cl2;
+       union smb_fileinfo c1finfoCR, c1finfo0;
+       union smb_fileinfo c2finfoCR, c2finfo0;
        //double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
        //double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 1000000);
        double normal_delay = 1000000;
        double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", normal_delay);
        //double normal_delay = 1000000;
        //int normal_delay = 2000000;
-       double sec = ((double)used_delay) / ((double)normal_delay);
-       int msec = 1000 * sec;
        bool ret = true;
        bool ok;
 
@@ -3021,7 +3071,7 @@ static bool test_durable_open_delaywrite1(struct torture_context *tctx,
        status = smb2_create(tree1, mem_ctx, &cr1);
        CHECK_STATUS(status, NT_STATUS_OK);
        _h1 = cr1.out.file.handle;
-       h1 = &_h1;
+       state.h1 = &_h1;
        CHECK_CREATED(&cr1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
        CHECK_VAL(cr1.out.oplock_level, smb2_util_oplock_level("b"));
        CHECK_VAL(cr1.out.durable_open, true);
@@ -3036,7 +3086,7 @@ static bool test_durable_open_delaywrite1(struct torture_context *tctx,
        status = smb2_create(tree2, mem_ctx, &cr2);
        CHECK_STATUS(status, NT_STATUS_OK);
        _h2 = cr2.out.file.handle;
-       h2 = &_h2;
+       state.h2 = &_h2;
        CHECK_CREATED(&cr2, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
        CHECK_VAL(cr2.out.oplock_level, 0);
        CHECK_VAL(cr2.out.durable_open, false);
@@ -3061,90 +3111,36 @@ static bool test_durable_open_delaywrite1(struct torture_context *tctx,
 
        ZERO_STRUCT(c1finfo0);
        c1finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFORMATION;
-       c1finfo0.basic_info.in.file.handle = *h1;
-       c1finfo1 = c1finfo0;
-       c1finfo2 = c1finfo0;
+       c1finfo0.basic_info.in.file.handle = *state.h1;
 
        ZERO_STRUCT(c2finfo0);
        c2finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFORMATION;
-       c2finfo0.basic_info.in.file.handle = *h2;
-       c2finfo1 = c2finfo0;
-       c2finfo2 = c2finfo0;
-       c2finfo3 = c2finfo0;
+       c2finfo0.basic_info.in.file.handle = *state.h2;
 
        GET_INFO_BOTH(c1finfo0, c2finfo0);
        COMPARE_ALL_TIMES_EQUAL(c1finfo0, c1finfoCR);
 
-       state.h1 = h1;
-       state.h2 = h2;
-
        ok = test_delay_writetime1(tctx, used_delay, normal_delay,
                        "run1",
                        test_durable_open_delaywrite1_get_info,
                        test_durable_open_delaywrite1_write_data,
+                       NULL, /* close_cb */
                        &state);
        torture_assert(tctx, ok, "test_delay_writetime1(1)");
        ok = test_delay_writetime1(tctx, used_delay, normal_delay,
                        "run2",
                        test_durable_open_delaywrite1_get_info,
                        test_durable_open_delaywrite1_write_data,
+                       test_durable_open_delaywrite1_close,
                        &state);
        torture_assert(tctx, ok, "test_delay_writetime2(2)");
 
-       GET_INFO_BOTH(c1finfo1, c2finfo1);
-       COMPARE_TIMES_AFTER_WRITE(c1finfo1, c1finfo0);
-
-       /* sleep */
-       torture_comment(tctx, "Sleep ...\n");
-       smb_msleep(5 * msec);
-       torture_comment(tctx, "... continue\n");
-
-       GET_INFO_BOTH(c1finfo2, c2finfo2);
-       COMPARE_ALL_TIMES_EQUAL(c1finfo2, c1finfo1);
-
-       /*
-        * the close updates the write time to the time of the close
-        * and not to the time of the last write!
-        */
-       torture_comment(tctx, "Close the file handle\n");
-
-       ZERO_STRUCT(cl1);
-       cl1.in.file.handle = *h1;
-       cl1.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
-       status = smb2_close(tree1, &cl1);
-       CHECK_STATUS(status, NT_STATUS_OK);
-       h1 = NULL;
-       ZERO_STRUCT(c1finfoCL);
-       c1finfoCL.basic_info.out.create_time = cl1.out.create_time;
-       c1finfoCL.basic_info.out.access_time = cl1.out.access_time;
-       c1finfoCL.basic_info.out.write_time = cl1.out.write_time;
-       c1finfoCL.basic_info.out.change_time = cl1.out.change_time;
-       c1finfoCL.basic_info.out.attrib = cl1.out.file_attr;
-       COMPARE_ALL_TIMES_EQUAL(c1finfoCL, c1finfo2);
-
-       GET_INFO_FILE(tree2, c2finfo3);
-       COMPARE_ALL_TIMES_EQUAL(c2finfo3, c1finfoCL);
-
-       ZERO_STRUCT(cl2);
-       cl2.in.file.handle = *h2;
-       cl2.in.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
-       status = smb2_close(tree2, &cl2);
-       CHECK_STATUS(status, NT_STATUS_OK);
-       h2 = NULL;
-       ZERO_STRUCT(c2finfoCL);
-       c2finfoCL.basic_info.out.create_time = cl2.out.create_time;
-       c2finfoCL.basic_info.out.access_time = cl2.out.access_time;
-       c2finfoCL.basic_info.out.write_time = cl2.out.write_time;
-       c2finfoCL.basic_info.out.change_time = cl2.out.change_time;
-       c2finfoCL.basic_info.out.attrib = cl2.out.file_attr;
-       COMPARE_ALL_TIMES_EQUAL(c2finfoCL, c1finfoCL);
-
 done:
-       if (h1 != NULL) {
-               smb2_util_close(tree1, *h1);
+       if (state.h1 != NULL) {
+               smb2_util_close(tree1, *state.h1);
        }
-       if (h2 != NULL) {
-               smb2_util_close(tree2, *h2);
+       if (state.h2 != NULL) {
+               smb2_util_close(tree2, *state.h2);
        }
 
        smb2_util_unlink(tree1, fname);
index cd0a530be409e33b2ec79c4171e1f2b7d7700a3b..05e983453d2238fbddcdcb3c45c457bc5a843e0f 100644 (file)
@@ -114,6 +114,8 @@ bool test_delay_writetime1(struct torture_context *tctx,
                           bool (*get_basic_info_cb)(void *private_data,
                                                     union smb_fileinfo *finfo),
                           bool (*write_data_cb)(void *private_data),
+                          bool (*close_cb)(void *private_data,
+                                           union smb_fileinfo *finfo),
                           void *private_data);
 
 #endif /* _TORTURE_UTIL_H_ */
index 7ded582dd894101723ceffc1f12e975b914619e1..c567280eb36b95ed56147d48a981f9af37e9ff5c 100644 (file)
@@ -121,6 +121,8 @@ bool test_delay_writetime1(struct torture_context *tctx,
                           bool (*get_basic_info_cb)(void *private_data,
                                                     union smb_fileinfo *finfo),
                           bool (*write_data_cb)(void *private_data),
+                          bool (*close_cb)(void *private_data,
+                                           union smb_fileinfo *finfo),
                           void *private_data)
 {
        union smb_fileinfo finfo0, finfo1, finfo2, finfo3, finfoT;
@@ -295,6 +297,20 @@ bool test_delay_writetime1(struct torture_context *tctx,
        torture_assert(tctx, ok, "get_basic_info_cb: finfoT");
        COMPARE_ALL_TIMES_EQUAL(finfoT, finfo3);
 
+       if (close_cb == NULL) {
+               goto done;
+       }
+
+       /*
+        * the close updates the write time to the time of the close
+        * and not to the time of the last write!
+        */
+       torture_comment(tctx, "Close the file handle\n");
+
+       ok = close_cb(private_data, &finfoT);
+       torture_assert(tctx, ok, "close_cb: finfoT");
+       COMPARE_ALL_TIMES_EQUAL(finfoT, finfo3);
+
 done:
        return ret;
 }