Store sendfile capability per-fsp.
authorJames Peach <jpeach@apple.com>
Mon, 15 Oct 2007 21:38:33 +0000 (14:38 -0700)
committerJames Peach <jpeach@apple.com>
Mon, 15 Oct 2007 21:38:33 +0000 (14:38 -0700)
This patch adds a bit to the fsp structure to tell the network send
path whether this file data can safely be sent using the sendfile(2)
system call.

This is a useful facility for VFS authors, since sometimes a VFS
may need to present a non-file object as a file. In this case,
sendfile should not be used.

source/include/smb.h
source/modules/vfs_default.c
source/smbd/reply.c

index 2b20cfa34fb163dc201165a06404bb0e2fefddf6..d0df005f5443388239e1b6b9f26946005dc0e4ec 100644 (file)
@@ -520,6 +520,7 @@ typedef struct files_struct {
        BOOL modified;
        BOOL is_directory;
        BOOL is_stat;
+       BOOL is_sendfile_capable;
        BOOL aio_write_behind;
        BOOL lockdb_clean;
        BOOL initial_delete_on_close; /* Only set at NTCreateX if file was created. */
index 286ea1a897f3f571bf0adbd16d3cbdd9756a8e14..503577e9ba78f347c35e1804531b512344e6face 100644 (file)
@@ -195,6 +195,11 @@ static int vfswrap_open(vfs_handle_struct *handle,  const char *fname,
        START_PROFILE(syscall_open);
        result = sys_open(fname, flags, mode);
        END_PROFILE(syscall_open);
+
+       if (result != -1) {
+               fsp->is_sendfile_capable = lp_use_sendfile(SNUM(handle->conn));
+       }
+
        return result;
 }
 
index fc85cece8db09482f932424aa793d247276daf83..cee8d771ffd302cfeed661ff11543f062c039f92 100644 (file)
@@ -2218,7 +2218,7 @@ void send_file_readbraw(connection_struct *conn, files_struct *fsp, SMB_OFF_T st
         */
 
        if ( (chain_size == 0) && (nread > 0) &&
-           (fsp->wcp == NULL) && lp_use_sendfile(SNUM(conn)) ) {
+           (fsp->wcp == NULL) && (fsp->is_sendfile_capable) ) {
                DATA_BLOB header;
 
                _smb_setlen(outbuf,nread);
@@ -2561,7 +2561,7 @@ int send_file_readX(connection_struct *conn, char *inbuf,char *outbuf,int length
         */
 
        if ((chain_size == 0) && (CVAL(inbuf,smb_vwv0) == 0xFF) &&
-           lp_use_sendfile(SNUM(conn)) && (fsp->wcp == NULL) ) {
+           (fsp->is_sendfile_capable) && (fsp->wcp == NULL) ) {
                SMB_STRUCT_STAT sbuf;
                DATA_BLOB header;