diff options
author | Jeremy Allison <jra@samba.org> | 2004-11-20 01:09:25 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:06:02 -0500 |
commit | 96ecdf3a334f7b473ad590dbc41474d2173474c6 (patch) | |
tree | 8ac8875684caafaad0089b01e198e468b4c1043b /source4/torture/basic | |
parent | 5d35fe6f711985ac337da812bdbde006172bf256 (diff) | |
download | samba-96ecdf3a334f7b473ad590dbc41474d2173474c6.tar.gz samba-96ecdf3a334f7b473ad590dbc41474d2173474c6.tar.bz2 samba-96ecdf3a334f7b473ad590dbc41474d2173474c6.zip |
r3886: Trying to understand delayed file write update times. Added another
test that uses 2 connections and queries the time via pathinfo, not fileinfo.
MSDN states : "When writing to a file, the last write time is not fully updated
until all handles used for writing have been closed." - but this is obviously
untrue. W2K3 seems to use a 2 second granularity for this. Next I'll try using
SetFileTime equivalent to see if this takes the same time to take effect.
Jeremy.
(This used to be commit 2e47e241f98c3dba8be346cea726def38399eb97)
Diffstat (limited to 'source4/torture/basic')
-rw-r--r-- | source4/torture/basic/delaywrite.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/source4/torture/basic/delaywrite.c b/source4/torture/basic/delaywrite.c index 3a632c49ea..4ffd398c17 100644 --- a/source4/torture/basic/delaywrite.c +++ b/source4/torture/basic/delaywrite.c @@ -109,6 +109,102 @@ static BOOL test_delayed_write_update(struct smbcli_state *cli, TALLOC_CTX *mem_ return ret; } +/* + * Do as above, but using 2 connections. + */ + +static BOOL test_delayed_write_update2(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +{ + struct smbcli_state *cli2=NULL; + union smb_fileinfo finfo1, finfo2; + const char *fname = BASEDIR "\\torture_file.txt"; + NTSTATUS status; + int fnum1 = -1; + BOOL ret = True; + ssize_t written; + time_t t; + + printf("Testing delayed update of write time using 2 connections\n"); + + if (!torture_open_connection(&cli2)) { + return False; + } + + if (!torture_setup_dir(cli, BASEDIR)) { + return False; + } + + fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + printf("Failed to open %s\n", fname); + return False; + } + + finfo1.basic_info.level = RAW_FILEINFO_BASIC_INFO; + finfo1.basic_info.in.fnum = fnum1; + finfo2 = finfo1; + + status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + return False; + } + + printf("Initial write time %s\n", + nt_time_string(mem_ctx, finfo1.basic_info.out.write_time)); + + /* 3 second delay to ensure we get past any 2 second time + granularity (older systems may have that) */ + sleep(3); + + written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1); + + if (written != 1) { + printf("write failed - wrote %d bytes (%s)\n", written, __location__); + return False; + } + + t = time(NULL); + + while (time(NULL) < t+120) { + finfo2.basic_info.in.fname = fname; + + status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status))); + ret = False; + break; + } + printf("write time %s\n", + nt_time_string(mem_ctx, finfo2.basic_info.out.write_time)); + if (finfo1.basic_info.out.write_time != finfo2.basic_info.out.write_time) { + printf("Server updated write_time after %d seconds\n", + (int)(time(NULL) - t)); + break; + } + sleep(1); + fflush(stdout); + } + + if (finfo1.basic_info.out.write_time == finfo2.basic_info.out.write_time) { + printf("Server did not update write time?!\n"); + ret = False; + } + + + if (cli2 != NULL) { + torture_close_connection(cli2); + } + if (fnum1 != -1) + smbcli_close(cli->tree, fnum1); + smbcli_unlink(cli->tree, fname); + smbcli_deltree(cli->tree, BASEDIR); + + return ret; +} + /* Windows does obviously not update the stat info during a write call. I * *think* this is the problem causing a spurious Excel 2003 on XP error @@ -277,6 +373,7 @@ BOOL torture_delay_write(void) ret &= test_finfo_after_write(cli, mem_ctx); ret &= test_delayed_write_update(cli, mem_ctx); + ret &= test_delayed_write_update2(cli, mem_ctx); torture_close_connection(cli); talloc_destroy(mem_ctx); |