From: Ralph Boehme Date: Tue, 4 Mar 2025 15:32:11 +0000 (+0100) Subject: smbtorture: adjust "base.delaywrite.update of write time using SET_END_OF_FILE" for... X-Git-Tag: tevent-0.17.0~495 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=344ec3971aedf301b355fcf6ea77ca34196cbbbd;p=thirdparty%2Fsamba.git smbtorture: adjust "base.delaywrite.update of write time using SET_END_OF_FILE" for modern SMB delayed write The adjusted test passes against Windows Server 2022. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13594 Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/selftest/knownfail.d/samba3.base.delaywrite b/selftest/knownfail.d/samba3.base.delaywrite index d68ddf0d9d1..1a7bdbaa8d6 100644 --- a/selftest/knownfail.d/samba3.base.delaywrite +++ b/selftest/knownfail.d/samba3.base.delaywrite @@ -2,3 +2,4 @@ ^samba3.base.delaywrite.delayed update of write time\(fileserver_smb1\) ^samba3.base.delaywrite.update of write time and SMBwrite truncate\(fileserver_smb1\) ^samba3.base.delaywrite.update of write time and SMBwrite truncate expand\(fileserver_smb1\) +^samba3.base.delaywrite.update of write time using SET_END_OF_FILE\(fileserver_smb1\) diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 5bc311f1d8f..f50fb0b09bd 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -360,15 +360,7 @@ static bool test_delayed_write_update1b(struct torture_context *tctx, struct smb int fnum1 = -1; bool ret = true; ssize_t written; - struct timeval start; - struct timeval end; - double used_delay = torture_setting_int(tctx, "writetimeupdatedelay", 2000000); - int normal_delay = 2000000; - double sec = ((double)used_delay) / ((double)normal_delay); - int msec = 1000 * sec; char buf[2048]; - bool first; - bool updated; torture_comment(tctx, "\nRunning test_delayed_write_update1b\n"); @@ -381,9 +373,8 @@ static bool test_delayed_write_update1b(struct torture_context *tctx, struct smb memset(buf, 'x', 2048); written = smbcli_write(cli->tree, fnum1, 0, buf, 0, 2048); - /* 3 second delay to ensure we get past any 2 second time - granularity (older systems may have that) */ - smb_msleep(3 * msec); + /* Bypass possible filesystem granularity */ + smb_msleep(20); finfo1.all_info.level = RAW_FILEINFO_ALL_INFO; finfo1.all_info.in.file.fnum = fnum1; @@ -402,50 +393,33 @@ static bool test_delayed_write_update1b(struct torture_context *tctx, struct smb torture_comment(tctx, "Initial write time %s\n", nt_time_string(tctx, finfo1.all_info.out.write_time)); + /* Bypass possible filesystem granularity */ + smb_msleep(20); + /* Do a SET_END_OF_FILE_INFO call to truncate. */ status = smbcli_ftruncate(cli->tree, fnum1, (uint64_t)10240); torture_assert_ntstatus_ok(tctx, status, "SET_END_OF_FILE failed"); - start = timeval_current(); - end = timeval_add(&start, (120*sec), 0); - first = true; - updated = false; - while (!timeval_expired(&end)) { - status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); - - torture_assert_ntstatus_ok(tctx, status, "fileinfo failed"); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo2); + torture_assert_ntstatus_ok(tctx, status, "fileinfo failed"); - torture_assert_u64_equal(tctx, finfo2.all_info.out.size, 10240, - "file not truncated to expected size " - "(10240)"); + torture_assert_u64_equal(tctx, finfo2.all_info.out.size, 10240, + "file not truncated to expected size " + "(10240)"); - torture_comment(tctx, "write time %s\n", + torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo2.all_info.out.write_time)); - if (finfo1.all_info.out.write_time != - finfo2.all_info.out.write_time) - { - updated = true; - break; - } - - fflush(stdout); - smb_msleep(1 * msec); - first = false; - } - - torture_assert(tctx, updated, - "Server did not update write time within 120 seconds"); - - torture_assert(tctx, first, talloc_asprintf(tctx, - "Server did not update write time immediately but only " - "after %.2f seconds!", timeval_elapsed(&start))); - - torture_comment(tctx, "Server updated write time immediately. Good!\n"); + torture_assert_u64_not_equal(tctx, + finfo2.all_info.out.write_time, + finfo1.all_info.out.write_time, + "Server did not update write time " + "immediately"); fflush(stdout); - smb_msleep(2 * msec); + /* Bypass possible filesystem granularity */ + smb_msleep(20); /* Do a non-zero length SMBwrite and make sure it doesn't update the write time. */ written = smbcli_smbwrite(cli->tree, fnum1, "x", 0, 1); @@ -453,53 +427,34 @@ static bool test_delayed_write_update1b(struct torture_context *tctx, struct smb torture_assert_int_equal(tctx, written, 1, "unexpected number of bytes written"); - start = timeval_current(); - end = timeval_add(&start, (10*sec), 0); - while (!timeval_expired(&end)) { - status = smb_raw_fileinfo(cli->tree, tctx, &finfo3); - - torture_assert_ntstatus_ok(tctx, status, "fileinfo failed"); + status = smb_raw_fileinfo(cli->tree, tctx, &finfo3); + torture_assert_ntstatus_ok(tctx, status, "fileinfo failed"); - torture_assert_u64_equal(tctx, finfo3.all_info.out.size, 10240, - "file not truncated to expected size " - "(10240)"); + torture_assert_u64_equal(tctx, finfo3.all_info.out.size, 10240, + "file not truncated to expected size " + "(10240)"); - torture_comment(tctx, "write time %s\n", + torture_comment(tctx, "write time %s\n", nt_time_string(tctx, finfo3.all_info.out.write_time)); - torture_assert_u64_equal(tctx, - finfo3.all_info.out.write_time, - finfo2.all_info.out.write_time, - talloc_asprintf(tctx, - "Server updated write time " - "after %.2f seconds (wrong!)", - timeval_elapsed(&start))); - - fflush(stdout); - smb_msleep(1 * msec); - } - - torture_comment(tctx, "Server did not update write time within 10 " - "seconds. Good!\n"); + torture_assert_u64_not_equal(tctx, + finfo3.all_info.out.write_time, + finfo2.all_info.out.write_time, + "Server did not update write time " + "immediately"); - /* the close should trigger an write time update */ + /* the close should not trigger an write time update */ smbcli_close(cli->tree, fnum1); fnum1 = -1; status = smb_raw_pathinfo(cli->tree, tctx, &pinfo4); torture_assert_ntstatus_ok(tctx, status, "pathinfo failed"); - torture_assert_u64_not_equal(tctx, - pinfo4.all_info.out.write_time, - finfo3.all_info.out.write_time, - "Server did not update write time on " - "close (wrong!)"); - torture_assert(tctx, - pinfo4.all_info.out.write_time > finfo3.all_info.out.write_time, - "Server updated write time on close, but to an earlier point " - "in time"); - - torture_comment(tctx, "Server updated write time on close (correct)\n"); + torture_assert_u64_equal(tctx, + pinfo4.all_info.out.write_time, + finfo3.all_info.out.write_time, + "Server updated write time on " + "close (wrong!)"); if (fnum1 != -1) smbcli_close(cli->tree, fnum1);