r9985: Move the all the strict sync logic into file_sync().
authorJames Peach <jpeach@samba.org>
Sat, 3 Sep 2005 07:19:28 +0000 (07:19 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:03:30 +0000 (11:03 -0500)
source/smbd/aio.c
source/smbd/fileio.c
source/smbd/files.c
source/smbd/reply.c

index d19706ff61ad316f0b066e127cb16464745c0e06..af1f172b9244d76788051c0c147aa0ae3c0508a3 100644 (file)
@@ -475,9 +475,7 @@ Wanted %u bytes but only wrote %d\n", fsp->fsp_name, (unsigned int)numtowrite, (
                }
                                                                                                                                   
                DEBUG(3,("handle_aio_write: fnum=%d num=%d wrote=%d\n", fsp->fnum, (int)numtowrite, (int)nwritten));
-               if (lp_syncalways(SNUM(fsp->conn)) || write_through) {
-                       sync_file(fsp->conn,fsp);
-               }
+               sync_file(fsp->conn,fsp, write_through);
        }
 
        show_msg(outbuf);
index 76189d114bb0dd85f7e58f6925c34693c010da81..375bfbe7cf3a381a14acdcbaf261e81694f5b6d3 100644 (file)
@@ -834,15 +834,18 @@ ssize_t flush_write_cache(files_struct *fsp, enum flush_reason_enum reason)
 sync a file
 ********************************************************************/
 
-void sync_file(connection_struct *conn, files_struct *fsp)
+void sync_file(connection_struct *conn, files_struct *fsp, BOOL write_through)
 {
-       if(lp_strict_sync(SNUM(conn)) && fsp->fh->fd != -1) {
+               if (fsp->fh->fd == -1)
+               return;
+
+       if (lp_strict_sync(SNUM(conn)) &&
+           (lp_syncalways(SNUM(conn)) || write_through)) {
                flush_write_cache(fsp, SYNC_FLUSH);
                SMB_VFS_FSYNC(fsp,fsp->fh->fd);
        }
 }
 
-
 /************************************************************
  Perform a stat whether a valid fd or not.
 ************************************************************/
index c90c2b627cae47177bce2f5fd6b10c7f77278a88..65986e96127bc90be36ecd6b0e8270b9ef37ab11 100644 (file)
@@ -427,7 +427,7 @@ void file_sync_all(connection_struct *conn)
        for (fsp=Files;fsp;fsp=next) {
                next=fsp->next;
                if ((conn == fsp->conn) && (fsp->fh->fd != -1)) {
-                       sync_file(conn,fsp);
+                       sync_file(conn, fsp, True /* write through */);
                }
        }
 }
index e96c3dc01ff896fe0aae39269150386cf6e597fd..90500066531bd8e03603dc0c77e05a7189866c6d 100644 (file)
@@ -2786,8 +2786,7 @@ int reply_writebraw(connection_struct *conn, char *inbuf,char *outbuf, int size,
  
        SSVAL(outbuf,smb_vwv0,total_written);
 
-       if ((lp_syncalways(SNUM(conn)) || write_through) && lp_strict_sync(SNUM(conn)))
-               sync_file(conn,fsp);
+       sync_file(conn, fsp, write_through);
 
        DEBUG(3,("writebraw2 fnum=%d start=%.0f num=%d wrote=%d\n",
                fsp->fnum, (double)startpos, (int)numtowrite,(int)total_written));
@@ -2852,8 +2851,7 @@ int reply_writeunlock(connection_struct *conn, char *inbuf,char *outbuf,
                nwritten = write_file(fsp,data,startpos,numtowrite);
        }
   
-       if (lp_syncalways(SNUM(conn)))
-               sync_file(conn,fsp);
+       sync_file(conn, fsp, False /* write through */);
 
        if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0)) {
                END_PROFILE(SMBwriteunlock);
@@ -2940,8 +2938,7 @@ int reply_write(connection_struct *conn, char *inbuf,char *outbuf,int size,int d
        } else
                nwritten = write_file(fsp,data,startpos,numtowrite);
   
-       if (lp_syncalways(SNUM(conn)))
-               sync_file(conn,fsp);
+       sync_file(conn, fsp, False);
 
        if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0)) {
                END_PROFILE(SMBwrite);
@@ -3068,8 +3065,7 @@ int reply_write_and_X(connection_struct *conn, char *inbuf,char *outbuf,int leng
        DEBUG(3,("writeX fnum=%d num=%d wrote=%d\n",
                fsp->fnum, (int)numtowrite, (int)nwritten));
 
-       if (lp_syncalways(SNUM(conn)) || write_through)
-               sync_file(conn,fsp);
+       sync_file(conn, fsp, write_through);
 
        END_PROFILE(SMBwriteX);
        return chain_reply(inbuf,outbuf,length,bufsize);
@@ -3166,7 +3162,7 @@ int reply_flush(connection_struct *conn, char *inbuf,char *outbuf, int size, int
        if (!fsp) {
                file_sync_all(conn);
        } else {
-               sync_file(conn,fsp);
+               sync_file(conn,fsp, True);
        }
        
        DEBUG(3,("flush\n"));
@@ -5433,8 +5429,7 @@ int reply_writebmpx(connection_struct *conn, char *inbuf,char *outbuf, int size,
 
        nwritten = write_file(fsp,data,startpos,numtowrite);
 
-       if(lp_syncalways(SNUM(conn)) || write_through)
-               sync_file(conn,fsp);
+       sync_file(conn, fsp, write_through);
   
        if(nwritten < (ssize_t)numtowrite) {
                END_PROFILE(SMBwriteBmpx);
@@ -5546,8 +5541,7 @@ int reply_writebs(connection_struct *conn, char *inbuf,char *outbuf, int dum_siz
 
        nwritten = write_file(fsp,data,startpos,numtowrite);
 
-       if(lp_syncalways(SNUM(conn)) || write_through)
-               sync_file(conn,fsp);
+       sync_file(conn, fsp, write_through);
   
        if (nwritten < (ssize_t)numtowrite) {
                if(write_through) {