diff options
author | Jeremy Allison <jra@samba.org> | 2002-01-20 00:04:15 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2002-01-20 00:04:15 +0000 |
commit | ccda82b457b11ec683f404c9059b02c1214a0fd1 (patch) | |
tree | 4e316b14bc2fa4e4753cb47bad56584615e04169 /source/smbd | |
parent | 997d6687fc67e98fe561775b522edfaa00f5ee5f (diff) | |
download | samba-ccda82b457b11ec683f404c9059b02c1214a0fd1.tar.gz samba-ccda82b457b11ec683f404c9059b02c1214a0fd1.tar.xz samba-ccda82b457b11ec683f404c9059b02c1214a0fd1.zip |
Attempt to fix bugs in write cache code (yes I know it's going away :-).
Jeremy.
Diffstat (limited to 'source/smbd')
-rw-r--r-- | source/smbd/fileio.c | 22 | ||||
-rw-r--r-- | source/smbd/vfs.c | 2 |
2 files changed, 21 insertions, 3 deletions
diff --git a/source/smbd/fileio.c b/source/smbd/fileio.c index 38da96b7410..84b8e35bf05 100644 --- a/source/smbd/fileio.c +++ b/source/smbd/fileio.c @@ -419,7 +419,7 @@ len = %u\n",fsp->fd, (double)pos, (unsigned int)n, (double)wcp->offset, (unsigne if ( n <= wcp->alloc_size && n > wcp->data_size) { cache_flush_needed = True; } else { - DO_PROFILE_INC(writecache_direct_writes); + DO_PROFILE_INC(writecache_direct_writes); return real_write_file(fsp, data, pos, n); } @@ -552,7 +552,13 @@ static BOOL setup_write_cache(files_struct *fsp, SMB_OFF_T file_size) void set_filelen_write_cache(files_struct *fsp, SMB_OFF_T file_size) { if(fsp->wcp) { - flush_write_cache(fsp, SIZECHANGE_FLUSH); + /* The cache *must* have been flushed before we do this. */ + if (fsp->wcp->data_size != 0) { + pstring msg; + slprintf(msg, sizeof(msg)-1, "set_filelen_write_cache: size change \ +on file %s with write cache size = %u\n", fsp->fsp_name, fsp->wcp->data_size ); + smb_panic(msg); + } fsp->wcp->file_size = file_size; } } @@ -565,6 +571,7 @@ ssize_t flush_write_cache(files_struct *fsp, enum flush_reason_enum reason) { write_cache *wcp = fsp->wcp; size_t data_size; + ssize_t ret; if(!wcp || !wcp->data_size) return 0; @@ -582,7 +589,16 @@ ssize_t flush_write_cache(files_struct *fsp, enum flush_reason_enum reason) DO_PROFILE_INC(writecache_num_perfect_writes); #endif - return real_write_file(fsp, wcp->data, wcp->offset, data_size); + ret = real_write_file(fsp, wcp->data, wcp->offset, data_size); + + /* + * Ensure file size if kept up to date if write extends file. + */ + + if ((ret != -1) && (wcp->offset + ret >= wcp->file_size)) + wcp->file_size = wcp->offset + ret; + + return ret; } /******************************************************************* diff --git a/source/smbd/vfs.c b/source/smbd/vfs.c index 2396a43d48b..e05b217a141 100644 --- a/source/smbd/vfs.c +++ b/source/smbd/vfs.c @@ -351,6 +351,7 @@ int vfs_allocate_file_space(files_struct *fsp, SMB_OFF_T len) DEBUG(10,("vfs_allocate_file_space: file %s, shrink. Current size %.0f\n", fsp->fsp_name, (double)st.st_size )); + flush_write_cache(fsp, SIZECHANGE_FLUSH); if ((ret = vfs_ops->ftruncate(fsp, fsp->fd, len)) != -1) { set_filelen_write_cache(fsp, len); } @@ -389,6 +390,7 @@ int vfs_set_filelen(files_struct *fsp, SMB_OFF_T len) release_level_2_oplocks_on_change(fsp); DEBUG(10,("vfs_set_filelen: ftruncate %s to len %.0f\n", fsp->fsp_name, (double)len)); + flush_write_cache(fsp, SIZECHANGE_FLUSH); if ((ret = fsp->conn->vfs_ops.ftruncate(fsp, fsp->fd, len)) != -1) set_filelen_write_cache(fsp, len); |