[Samba] NFS quotas: truncated files without warning

Jeremy Allison jra at samba.org
Fri Jun 15 19:32:27 GMT 2007


On Fri, Jun 15, 2007 at 08:23:49PM +0200, SER.RI-TIC - David Losada wrote:
> mmm... well, it doesn't seem to be working like that in the version that
> ships with RHEL4. I will get around to try it on a fresh build on monday
> and report to you about it.

Apply this patch and let me know if it fixes it (will be in 3.0.25b).

Jeremy.
-------------- next part --------------
Index: smbd/reply.c
===================================================================
--- smbd/reply.c	(revision 23507)
+++ smbd/reply.c	(working copy)
@@ -2743,6 +2743,7 @@
 	BOOL write_through;
 	files_struct *fsp = file_fsp(inbuf,smb_vwv0);
 	int outsize = 0;
+	NTSTATUS status;
 	START_PROFILE(SMBwritebraw);
 
 	if (srv_is_signing_active()) {
@@ -2847,7 +2848,13 @@
  
 	SSVAL(outbuf,smb_vwv0,total_written);
 
-	sync_file(conn, fsp, write_through);
+	status = sync_file(conn, fsp, write_through);
+	if (!NT_STATUS_IS_OK(status)) {
+		DEBUG(5,("reply_writebraw: sync_file for %s returned %s\n",
+			fsp->fsp_name, nt_errstr(status) ));
+		END_PROFILE(SMBwritebraw);
+		return ERROR_NT(status);
+	}
 
 	DEBUG(3,("writebraw2 fnum=%d start=%.0f num=%d wrote=%d\n",
 		fsp->fnum, (double)startpos, (int)numtowrite,(int)total_written));
@@ -2912,7 +2919,13 @@
 		nwritten = write_file(fsp,data,startpos,numtowrite);
 	}
   
-	sync_file(conn, fsp, False /* write through */);
+	status = sync_file(conn, fsp, False /* write through */);
+	if (!NT_STATUS_IS_OK(status)) {
+		END_PROFILE(SMBwriteunlock);
+		DEBUG(5,("reply_writeunlock: sync_file for %s returned %s\n",
+			fsp->fsp_name, nt_errstr(status) ));
+		return ERROR_NT(status);
+	}
 
 	if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0)) {
 		END_PROFILE(SMBwriteunlock);
@@ -2958,6 +2971,7 @@
 	char *data;
 	files_struct *fsp = file_fsp(inbuf,smb_vwv0);
 	int outsize = 0;
+	NTSTATUS status;
 	START_PROFILE(SMBwrite);
 
 	/* If it's an IPC, pass off the pipe handler. */
@@ -2968,6 +2982,7 @@
 
 	CHECK_FSP(fsp,conn);
 	if (!CHECK_WRITE(fsp)) {
+		END_PROFILE(SMBwrite);
 		return(ERROR_DOS(ERRDOS,ERRbadaccess));
 	}
 
@@ -3003,7 +3018,13 @@
 	} else
 		nwritten = write_file(fsp,data,startpos,numtowrite);
   
-	sync_file(conn, fsp, False);
+	status = sync_file(conn, fsp, False);
+	if (!NT_STATUS_IS_OK(status)) {
+		END_PROFILE(SMBwrite);
+		DEBUG(5,("reply_write: sync_file for %s returned %s\n",
+			fsp->fsp_name, nt_errstr(status) ));
+		return ERROR_NT(status);
+	}
 
 	if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0)) {
 		END_PROFILE(SMBwrite);
@@ -3040,6 +3061,7 @@
 	unsigned int smblen = smb_len(inbuf);
 	char *data;
 	BOOL large_writeX = ((CVAL(inbuf,smb_wct) == 14) && (smblen > 0xFFFF));
+	NTSTATUS status;
 	START_PROFILE(SMBwriteX);
 
 	/* If it's an IPC, pass off the pipe handler. */
@@ -3130,7 +3152,13 @@
 	DEBUG(3,("writeX fnum=%d num=%d wrote=%d\n",
 		fsp->fnum, (int)numtowrite, (int)nwritten));
 
-	sync_file(conn, fsp, write_through);
+	status = sync_file(conn, fsp, write_through);
+	if (!NT_STATUS_IS_OK(status)) {
+		END_PROFILE(SMBwriteX);
+		DEBUG(5,("reply_write_and_X: sync_file for %s returned %s\n",
+			fsp->fsp_name, nt_errstr(status) ));
+		return ERROR_NT(status);
+	}
 
 	END_PROFILE(SMBwriteX);
 	return chain_reply(inbuf,outbuf,length,bufsize);
@@ -3227,7 +3255,13 @@
 	if (!fsp) {
 		file_sync_all(conn);
 	} else {
-		sync_file(conn,fsp, True);
+		NTSTATUS status = sync_file(conn, fsp, True);
+		if (!NT_STATUS_IS_OK(status)) {
+			END_PROFILE(SMBflush);
+			DEBUG(5,("reply_flush: sync_file for %s returned %s\n",
+				fsp->fsp_name, nt_errstr(status) ));
+			return ERROR_NT(status);
+		}
 	}
 	
 	DEBUG(3,("flush\n"));
@@ -5831,6 +5865,7 @@
 	int smb_doff;
 	char *data;
 	files_struct *fsp = file_fsp(inbuf,smb_vwv0);
+	NTSTATUS status;
 	START_PROFILE(SMBwriteBmpx);
 
 	CHECK_FSP(fsp,conn);
@@ -5860,7 +5895,13 @@
 
 	nwritten = write_file(fsp,data,startpos,numtowrite);
 
-	sync_file(conn, fsp, write_through);
+	status = sync_file(conn, fsp, write_through);
+	if (!NT_STATUS_IS_OK(status)) {
+		END_PROFILE(SMBwriteBmpx);
+		DEBUG(5,("reply_writebmpx: sync_file for %s returned %s\n",
+			fsp->fsp_name, nt_errstr(status) ));
+		return ERROR_NT(status);
+	}
   
 	if(nwritten < (ssize_t)numtowrite) {
 		END_PROFILE(SMBwriteBmpx);
@@ -5936,6 +5977,7 @@
 	write_bmpx_struct *wbms;
 	BOOL send_response = False; 
 	files_struct *fsp = file_fsp(inbuf,smb_vwv0);
+	NTSTATUS status;
 	START_PROFILE(SMBwriteBs);
 
 	CHECK_FSP(fsp,conn);
@@ -5972,9 +6014,9 @@
 
 	nwritten = write_file(fsp,data,startpos,numtowrite);
 
-	sync_file(conn, fsp, write_through);
+	status = sync_file(conn, fsp, write_through);
   
-	if (nwritten < (ssize_t)numtowrite) {
+	if (nwritten < (ssize_t)numtowrite || !NT_STATUS_IS_OK(status)) {
 		if(write_through) {
 			/* We are returning an error - we can delete the aux struct */
 			if (wbms)
Index: smbd/fileio.c
===================================================================
--- smbd/fileio.c	(revision 23507)
+++ smbd/fileio.c	(working copy)
@@ -834,16 +834,23 @@
 sync a file
 ********************************************************************/
 
-void sync_file(connection_struct *conn, files_struct *fsp, BOOL write_through)
+NTSTATUS sync_file(connection_struct *conn, files_struct *fsp, BOOL write_through)
 {
        	if (fsp->fh->fd == -1)
-		return;
+		return NT_STATUS_INVALID_HANDLE;
 
 	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);
+		int ret = flush_write_cache(fsp, SYNC_FLUSH);
+		if (ret == -1) {
+			return map_nt_error_from_unix(errno);
+		}
+		ret = SMB_VFS_FSYNC(fsp,fsp->fh->fd);
+		if (ret == -1) {
+			return map_nt_error_from_unix(errno);
+		}
 	}
+	return NT_STATUS_OK;
 }
 
 /************************************************************
Index: smbd/aio.c
===================================================================
--- smbd/aio.c	(revision 23507)
+++ smbd/aio.c	(working copy)
@@ -497,6 +497,7 @@
 		ret = errno;
         } else {
 		BOOL write_through = BITSETW(aio_ex->inbuf+smb_vwv7,0);
+		NTSTATUS status;
 
         	SSVAL(outbuf,smb_vwv2,nwritten);
 		SSVAL(outbuf,smb_vwv4,(nwritten>>16)&1);
@@ -507,7 +508,13 @@
 
 		DEBUG(3,("handle_aio_write: fnum=%d num=%d wrote=%d\n",
 			 fsp->fnum, (int)numtowrite, (int)nwritten));
-		sync_file(fsp->conn,fsp, write_through);
+		status = sync_file(fsp->conn,fsp, write_through);
+		if (!NT_STATUS_IS_OK(status)) {
+			UNIXERROR(ERRHRD,ERRdiskfull);
+			ret = errno;
+                	DEBUG(5,("handle_aio_write: sync_file for %s returned %s\n",
+				fsp->fsp_name, nt_errstr(status) ));
+		}
 	}
 
 	show_msg(outbuf);


More information about the samba mailing list