works for SMB2, fails SMB1
authorStefan Metzmacher <metze@samba.org>
Wed, 15 Aug 2018 07:58:38 +0000 (09:58 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 15 Aug 2018 07:58:38 +0000 (09:58 +0200)
SMB1:
no update at all.
What's the difference to 'delayed update of write time' test???

source4/torture/basic/delaywrite.c
source4/torture/smb2/durable_open.c
source4/torture/util.h
source4/torture/util_writetime.c

index da69a5a6d126b6b7437939494c75ec62a29500c3..c95d8ab518d2f2cac7abf3bb105ace3f9058f1de 100644 (file)
@@ -3225,6 +3225,48 @@ done:
        return ret;
 }
 
+static bool test_delaywrite_delaywrite1_close(void *private_data,
+                                             union smb_fileinfo *finfo)
+{
+       struct test_delaywrite_delaywrite1_state *state =
+               (struct test_delaywrite_delaywrite1_state *)private_data;
+       struct torture_context *tctx = state->tctx;
+       struct smbcli_state *cli2 = state->cli2;
+       union smb_fileinfo t2finfo;
+       union smb_fileinfo t2pinfo;
+       bool ret = true;
+
+       ZERO_STRUCTP(finfo);
+
+       /*
+        * 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");
+       smbcli_close(state->cli1->tree, state->fnum1);
+       state->fnum1 = -1;
+
+       ZERO_STRUCT(t2finfo);
+       t2finfo.basic_info.level = RAW_FILEINFO_BASIC_INFO;
+       t2finfo.basic_info.in.file.fnum = state->fnum2;
+       ZERO_STRUCT(t2pinfo);
+       t2pinfo.basic_info.level = RAW_FILEINFO_BASIC_INFO;
+       t2pinfo.basic_info.in.file.path = state->fname;
+
+       GET_INFO_FILE2(t2finfo);
+
+       smbcli_close(state->cli2->tree, state->fnum2);
+       state->fnum2 = -1;
+
+       GET_INFO_PATH(t2pinfo);
+       COMPARE_ALL_TIMES_EQUAL(t2pinfo, t2finfo);
+
+       finfo->basic_info.out = t2finfo.basic_info.out;
+
+done:
+       return ret;
+}
+
 static bool test_delaywrite_delaywrite1(struct torture_context *tctx,
                                        struct smbcli_state *cli,
                                        struct smbcli_state *cli2)
@@ -3233,12 +3275,10 @@ static bool test_delaywrite_delaywrite1(struct torture_context *tctx,
                .tctx = tctx,
                .cli1 = cli,
                .cli2 = cli2,
+               .fnum1 = -1,
+               .fnum2 = -1,
        };
-       union smb_fileinfo c1finfo0, c1finfo1, c1finfo2;
-       union smb_fileinfo c2pinfo0, c2pinfo1, c2pinfo2, c2pinfo3;
        const char *fname = BASEDIR "\\torture_file3.txt";
-       int fnum1 = -1;
-       int fnum2 = -1;
        bool ret = true;
        //double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000);
        //double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 1000000);
@@ -3246,8 +3286,6 @@ static bool test_delaywrite_delaywrite1(struct torture_context *tctx,
        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 ok;
 
        torture_comment(tctx, "\nRunning test_delayed_write_update3\n");
@@ -3255,81 +3293,35 @@ static bool test_delaywrite_delaywrite1(struct torture_context *tctx,
        torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
 
        torture_comment(tctx, "Open the file handle\n");
-       fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
-       if (fnum1 == -1) {
+       state.fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
+       if (state.fnum1 == -1) {
                ret = false;
                torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
                goto done;
        }
-       fnum2 = smbcli_open(cli2->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
-       if (fnum2 == -1) {
+       state.fnum2 = smbcli_open(cli2->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
+       if (state.fnum2 == -1) {
                ret = false;
                torture_result(tctx, TORTURE_FAIL, __location__": unable to open %s", fname);
                goto done;
        }
 
-       c1finfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
-       c1finfo0.basic_info.in.file.fnum = fnum1;
-       c1finfo1 = c1finfo0;
-       c1finfo2 = c1finfo0;
-       c2pinfo0.basic_info.level = RAW_FILEINFO_BASIC_INFO;
-       c2pinfo0.basic_info.in.file.path = fname;
-       c2pinfo1 = c2pinfo0;
-       c2pinfo2 = c2pinfo0;
-       c2pinfo3 = c2pinfo0;
-
-       /* get the initial times */
-       GET_INFO_BOTH(c1finfo0,c2pinfo0);
-
        state.fname = fname;
-       state.fnum1 = fnum1;
-       state.fnum2 = fnum2;
 
        ok = test_delay_writetime1(tctx, used_delay, normal_delay,
-                       "run1",
+                       "run", true, /* smb1 */
                        test_delaywrite_delaywrite1_get_info,
                        test_delaywrite_delaywrite1_write_data,
+                       test_delaywrite_delaywrite1_close,
                        &state);
-       torture_assert(tctx, ok, "test_delay_writetime1(1)");
-       ok = test_delay_writetime1(tctx, used_delay, normal_delay,
-                       "run2",
-                       test_delaywrite_delaywrite1_get_info,
-                       test_delaywrite_delaywrite1_write_data,
-                       &state);
-       torture_assert(tctx, ok, "test_delay_writetime2(2)");
-
-       GET_INFO_BOTH(c1finfo1, c2pinfo1);
-       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, c2pinfo2);
-       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");
-       smbcli_close(cli->tree, fnum1);
-       fnum1 = -1;
-
-       GET_INFO_PATH(c2pinfo3);
-       COMPARE_WRITE_TIME_GREATER(c2pinfo3, c2pinfo2);
-
-       if (c2pinfo3.basic_info.out.write_time > c2pinfo2.basic_info.out.write_time) {
-               torture_comment(tctx, "Server updated the write_time on close (correct)\n");
-       }
+       torture_assert_goto(tctx, ok, ret, done, "test_delay_writetime2(2)");
 
  done:
-       if (fnum1 != -1) {
-               smbcli_close(cli->tree, fnum1);
+       if (state.fnum1 != -1) {
+               smbcli_close(cli->tree, state.fnum1);
        }
-       if (fnum2 != -1) {
-               smbcli_close(cli2->tree, fnum2);
+       if (state.fnum2 != -1) {
+               smbcli_close(cli2->tree, state.fnum2);
        }
        smbcli_unlink(cli->tree, fname);
        smbcli_deltree(cli->tree, BASEDIR);
index f5ace21de8a39148f6762e14d3259075de422c4c..a21fca2373d117a6223eb697190681c0148c8146 100644 (file)
@@ -3121,19 +3121,19 @@ static bool test_durable_open_delaywrite1(struct torture_context *tctx,
        COMPARE_ALL_TIMES_EQUAL(c1finfo0, c1finfoCR);
 
        ok = test_delay_writetime1(tctx, used_delay, normal_delay,
-                       "run1",
+                       "run1", false, /* smb1 */
                        test_durable_open_delaywrite1_get_info,
                        test_durable_open_delaywrite1_write_data,
                        NULL, /* close_cb */
                        &state);
-       torture_assert(tctx, ok, "test_delay_writetime1(1)");
+       torture_assert_goto(tctx, ok, ret, done, "test_delay_writetime1(1)");
        ok = test_delay_writetime1(tctx, used_delay, normal_delay,
-                       "run2",
+                       "run2", false, /* smb1 */
                        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)");
+       torture_assert_goto(tctx, ok, ret, done, "test_delay_writetime2(2)");
 
 done:
        if (state.h1 != NULL) {
index 05e983453d2238fbddcdcb3c45c457bc5a843e0f..f0b3e15c1ecc3921452810e3c56407354bec1318 100644 (file)
@@ -111,6 +111,7 @@ bool test_delay_writetime1(struct torture_context *tctx,
                           double used_delay,
                           double normal_delay,
                           const char *description,
+                          bool smb1,
                           bool (*get_basic_info_cb)(void *private_data,
                                                     union smb_fileinfo *finfo),
                           bool (*write_data_cb)(void *private_data),
index c567280eb36b95ed56147d48a981f9af37e9ff5c..a6e42274466c0c5b81e1b5fe6b17144fbecb5ee5 100644 (file)
@@ -118,6 +118,7 @@ bool test_delay_writetime1(struct torture_context *tctx,
                           double used_delay,
                           double normal_delay,
                           const char *description,
+                          bool smb1,
                           bool (*get_basic_info_cb)(void *private_data,
                                                     union smb_fileinfo *finfo),
                           bool (*write_data_cb)(void *private_data),
@@ -229,6 +230,11 @@ bool test_delay_writetime1(struct torture_context *tctx,
        after_write = timeval_current();
        torture_assert(tctx, ok, "write_data_cb");
 
+       if (smb1) {
+               finfo2 = finfo1;
+               goto no_change;
+       }
+
        ZERO_STRUCT(finfo2);
        before_last_write = before_write;
        after_last_write = after_write;
@@ -275,7 +281,7 @@ bool test_delay_writetime1(struct torture_context *tctx,
        }
 
        // We may get one additional change...
-
+no_change:
        ok = get_basic_info_cb(private_data, &finfo3);
        torture_assert(tctx, ok, "get_basic_info_cb: finfo3");
        COMPARE_ALL_TIMES_EQUAL(finfo3, finfo2);
@@ -309,7 +315,11 @@ bool test_delay_writetime1(struct torture_context *tctx,
 
        ok = close_cb(private_data, &finfoT);
        torture_assert(tctx, ok, "close_cb: finfoT");
-       COMPARE_ALL_TIMES_EQUAL(finfoT, finfo3);
+       if (smb1) {
+               COMPARE_TIMES_AFTER_CLOSE(finfoT, finfo1);
+       } else {
+               COMPARE_ALL_TIMES_EQUAL(finfoT, finfo3);
+       }
 
 done:
        return ret;