Ensure we don't use delayed writes on POSIX opened files.
[ira/wip.git] / source3 / smbd / fileio.c
index 30253d44664af9a9ed65382bfb67c87e2dcba75a..5cc3d4b88b0ae187d7dddd82c1528e088e869229 100644 (file)
@@ -20,6 +20,7 @@
 */
 
 #include "includes.h"
+#include "smbd/globals.h"
 
 static bool setup_write_cache(files_struct *, SMB_OFF_T);
 
@@ -109,9 +110,6 @@ tryagain:
        return(ret);
 }
 
-/* how many write cache buffers have been allocated */
-static unsigned int allocated_write_caches;
-
 /****************************************************************************
  *Really* write to a file.
 ****************************************************************************/
@@ -195,6 +193,11 @@ void trigger_write_time_update(struct files_struct *fsp)
 {
        int delay;
 
+       if (fsp->posix_open) {
+               /* Don't use delayed writes on POSIX files. */
+               return;
+       }
+
        if (fsp->write_time_forced) {
                /* No point - "sticky" write times
                 * in effect.
@@ -226,6 +229,11 @@ void trigger_write_time_update(struct files_struct *fsp)
 
 void trigger_write_time_update_immediate(struct files_struct *fsp)
 {
+       if (fsp->posix_open) {
+               /* Don't use delayed writes on POSIX files. */
+               return;
+       }
+
         if (fsp->write_time_forced) {
                /*
                 * No point - "sticky" write times
@@ -258,10 +266,9 @@ ssize_t write_file(struct smb_request *req,
        int write_path = -1;
 
        if (fsp->print_file) {
-               fstring sharename;
                uint32 jobid;
 
-               if (!rap_to_pjobid(fsp->rap_print_jobid, sharename, &jobid)) {
+               if (!rap_to_pjobid(fsp->rap_print_jobid, NULL, &jobid)) {
                        DEBUG(3,("write_file: Unable to map RAP jobid %u to jobid.\n",
                                                (unsigned int)fsp->rap_print_jobid ));
                        errno = EBADF;
@@ -299,7 +306,7 @@ ssize_t write_file(struct smb_request *req,
                         */
 
                        if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && !wcp) {
-                               setup_write_cache(fsp, st.st_size);
+                               setup_write_cache(fsp, st.st_ex_size);
                                wcp = fsp->wcp;
                        }
                }
@@ -320,7 +327,9 @@ ssize_t write_file(struct smb_request *req,
         * the shared memory area whilst doing this.
         */
 
-       release_level_2_oplocks_on_change(fsp);
+       /* This should actually be improved to span the write. */
+       contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_WRITE);
+       contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_WRITE);
 
 #ifdef WITH_PROFILE
        if (profile_p && profile_p->writecache_total_writes % 500 == 0) {
@@ -950,7 +959,7 @@ NTSTATUS sync_file(connection_struct *conn, files_struct *fsp, bool write_throug
 int fsp_stat(files_struct *fsp, SMB_STRUCT_STAT *pst)
 {
        if (fsp->fh->fd == -1) {
-               return SMB_VFS_STAT(fsp->conn, fsp->fsp_name, pst);
+               return vfs_stat_smb_fname(fsp->conn, fsp->fsp_name, pst);
        } else {
                return SMB_VFS_FSTAT(fsp, pst);
        }