summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2005-06-27 22:53:56 +0000
committerJeremy Allison <jra@samba.org>2005-06-27 22:53:56 +0000
commitcc59dd72a6f06ce58d2ab455277cf76d3b084776 (patch)
treeaf5d1b5b4d854bdbdedbdbebe0489889be76ef6b
parentae5191db2af44e280d8f3f2171c644812b057e65 (diff)
downloadsamba-cc59dd72a6f06ce58d2ab455277cf76d3b084776.tar.gz
samba-cc59dd72a6f06ce58d2ab455277cf76d3b084776.tar.xz
samba-cc59dd72a6f06ce58d2ab455277cf76d3b084776.zip
r7963: Add aio support to 3.0.
Jeremy.
-rw-r--r--examples/VFS/skel_opaque.c44
-rw-r--r--examples/VFS/skel_transparent.c44
-rw-r--r--source/Makefile.in2
-rw-r--r--source/include/ntlmssp.h1
-rw-r--r--source/include/smb.h2
-rw-r--r--source/include/vfs.h33
-rw-r--r--source/include/vfs_macros.h27
-rw-r--r--source/lib/system.c158
-rw-r--r--source/modules/vfs_full_audit.c108
-rw-r--r--source/param/loadparm.c12
-rw-r--r--source/smbd/aio.c748
-rw-r--r--source/smbd/blocking.c10
-rw-r--r--source/smbd/close.c14
-rw-r--r--source/smbd/conn.c1
-rw-r--r--source/smbd/notify.c1
-rw-r--r--source/smbd/open.c4
-rw-r--r--source/smbd/oplock.c26
-rw-r--r--source/smbd/process.c111
-rw-r--r--source/smbd/reply.c7
-rw-r--r--source/smbd/server.c5
-rw-r--r--source/smbd/service.c1
-rw-r--r--source/smbd/sesssetup.c1
-rw-r--r--source/smbd/trans2.c3
-rw-r--r--source/smbd/vfs-wrap.c35
-rw-r--r--source/smbd/vfs.c39
25 files changed, 1385 insertions, 52 deletions
diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c
index a3a42912f87..a3aab55c3ea 100644
--- a/examples/VFS/skel_opaque.c
+++ b/examples/VFS/skel_opaque.c
@@ -487,6 +487,41 @@ static int skel_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp,in
return -1;
}
+static int skel_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ return vfswrap_aio_read(NULL, fsp, aiocb);
+}
+
+static int skel_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ return vfswrap_aio_write(NULL, fsp, aiocb);
+}
+
+static ssize_t skel_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ return vfswrap_aio_return(NULL, fsp, aiocb);
+}
+
+static int skel_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, int fd, SMB_STRUCT_AIOCB *aiocb)
+{
+ return vfswrap_aio_cancel(NULL, fsp, fd, aiocb);
+}
+
+static int skel_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ return vfswrap_aio_error(NULL, fsp, aiocb);
+}
+
+static int skel_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb)
+{
+ return vfswrap_aio_fsync(NULL, fsp, op, aiocb);
+}
+
+static int skel_aio_suspend(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_AIOCB * const aiocb[], int n, const struct timespec *ts)
+{
+ return vfswrap_aioi_suspend(NULL, fsp, aiocb, n, ts);
+}
+
/* VFS operations structure */
static vfs_op_tuple skel_op_tuples[] = {
@@ -590,6 +625,15 @@ static vfs_op_tuple skel_op_tuples[] = {
{SMB_VFS_OP(skel_lsetxattr), SMB_VFS_OP_LSETXATTR, SMB_VFS_LAYER_OPAQUE},
{SMB_VFS_OP(skel_fsetxattr), SMB_VFS_OP_FSETXATTR, SMB_VFS_LAYER_OPAQUE},
+ /* AIO operations. */
+ {SMB_VFS_OP(skel_aio_read), SMB_VFS_OP_AIO_READ, SMB_VFS_LAYER_OPAQUE},
+ {SMB_VFS_OP(skel_aio_write), SMB_VFS_OP_AIO_WRITE, SMB_VFS_LAYER_OPAQUE},
+ {SMB_VFS_OP(skel_aio_return), SMB_VFS_OP_AIO_RETURN, SMB_VFS_LAYER_OPAQUE},
+ {SMB_VFS_OP(skel_aio_cancel), SMB_VFS_OP_AIO_CANCEL, SMB_VFS_LAYER_OPAQUE},
+ {SMB_VFS_OP(skel_aio_error), SMB_VFS_OP_AIO_ERROR, SMB_VFS_LAYER_OPAQUE},
+ {SMB_VFS_OP(skel_aio_fsync), SMB_VFS_OP_AIO_FSYNC, SMB_VFS_LAYER_OPAQUE},
+ {SMB_VFS_OP(skel_aio_suspend), SMB_VFS_OP_AIO_SUSPEND, SMB_VFS_LAYER_OPAQUE},
+
{NULL, SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
};
diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c
index 8be1a7fb449..81069765d0e 100644
--- a/examples/VFS/skel_transparent.c
+++ b/examples/VFS/skel_transparent.c
@@ -456,6 +456,41 @@ static int skel_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp,in
return SMB_VFS_NEXT_FSETXATTR(handle, fsp, fd, name, value, size, flags);
}
+static int skel_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ return SMB_VFS_NEXT_AIO_READ(handle, fsp, aiocb);
+}
+
+static int skel_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ return SMB_VFS_NEXT_AIO_WRITE(handle, fsp, aiocb);
+}
+
+static ssize_t skel_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ return SMB_VFS_NEXT_AIO_RETURN(handle, fsp, aiocb);
+}
+
+static int skel_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, int fd, SMB_STRUCT_AIOCB *aiocb)
+{
+ return SMB_VFS_NEXT_AIO_CANCEL(handle, fsp, fd, aiocb);
+}
+
+static int skel_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ return SMB_VFS_NEXT_AIO_ERROR(handle, fsp, aiocb);
+}
+
+static int skel_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb)
+{
+ return SMB_VFS_NEXT_AIO_FSYNC(handle, fsp, op, aiocb);
+}
+
+static int skel_aio_suspend(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_AIOCB * const aiocb[], int n, const struct timespec *ts)
+{
+ return SMB_VFS_NEXT_AIO_SUSPEND(handle, fsp, aiocb, n, ts);
+}
+
/* VFS operations structure */
static vfs_op_tuple skel_op_tuples[] = {
@@ -557,6 +592,15 @@ static vfs_op_tuple skel_op_tuples[] = {
{SMB_VFS_OP(skel_lsetxattr), SMB_VFS_OP_LSETXATTR, SMB_VFS_LAYER_TRANSPARENT},
{SMB_VFS_OP(skel_fsetxattr), SMB_VFS_OP_FSETXATTR, SMB_VFS_LAYER_TRANSPARENT},
+ /* AIO operations. */
+ {SMB_VFS_OP(skel_aio_read), SMB_VFS_OP_AIO_READ, SMB_VFS_LAYER_TRANSPARENT},
+ {SMB_VFS_OP(skel_aio_write), SMB_VFS_OP_AIO_WRITE, SMB_VFS_LAYER_TRANSPARENT},
+ {SMB_VFS_OP(skel_aio_return), SMB_VFS_OP_AIO_RETURN, SMB_VFS_LAYER_TRANSPARENT},
+ {SMB_VFS_OP(skel_aio_cancel), SMB_VFS_OP_AIO_CANCEL, SMB_VFS_LAYER_TRANSPARENT},
+ {SMB_VFS_OP(skel_aio_error), SMB_VFS_OP_AIO_ERROR, SMB_VFS_LAYER_TRANSPARENT},
+ {SMB_VFS_OP(skel_aio_fsync), SMB_VFS_OP_AIO_FSYNC, SMB_VFS_LAYER_TRANSPARENT},
+ {SMB_VFS_OP(skel_aio_suspend), SMB_VFS_OP_AIO_SUSPEND, SMB_VFS_LAYER_TRANSPARENT},
+
{NULL, SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
};
diff --git a/source/Makefile.in b/source/Makefile.in
index 499f51b77ed..0fbd0464f6a 100644
--- a/source/Makefile.in
+++ b/source/Makefile.in
@@ -387,7 +387,7 @@ SMBD_OBJ_SRV = smbd/files.o smbd/chgpasswd.o smbd/connection.o \
lib/sysquotas_xfs.o lib/sysquotas_4A.o \
smbd/change_trust_pw.o smbd/fake_file.o \
smbd/quotas.o smbd/ntquotas.o $(AFS_OBJ) smbd/msdfs.o \
- $(AFS_SETTOKEN_OBJ) \
+ $(AFS_SETTOKEN_OBJ) smbd/aio.o \
$(MANGLE_OBJ) @VFS_STATIC@
SMBD_OBJ_BASE = $(PARAM_OBJ) $(SMBD_OBJ_SRV) $(LIBSMB_OBJ) \
diff --git a/source/include/ntlmssp.h b/source/include/ntlmssp.h
index 24ac7967615..8ab6265673c 100644
--- a/source/include/ntlmssp.h
+++ b/source/include/ntlmssp.h
@@ -123,6 +123,7 @@ typedef struct ntlmssp_state
* from the DATA_BLOB chal on this structure.
*
* @param ntlmssp_state This structure
+ * @param challenge 8 bytes of data, agreed by the client and server to be the effective challenge for NTLM2 authentication
* @param challange 8 bytes of data, agreed by the client and server to be the effective challenge for NTLM2 authentication
*
*/
diff --git a/source/include/smb.h b/source/include/smb.h
index 658b52a2ffa..50bd233da76 100644
--- a/source/include/smb.h
+++ b/source/include/smb.h
@@ -442,6 +442,7 @@ typedef struct files_struct {
BOOL is_directory;
BOOL is_stat;
BOOL directory_delete_on_close;
+ BOOL aio_write_behind;
char *fsp_name;
FAKE_FILE_HANDLE *fake_file_handle;
} files_struct;
@@ -541,6 +542,7 @@ typedef struct connection_struct
name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */
name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */
name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */
+ name_compare_entry *aio_write_behind_list; /* Per-share list of files to use aio write behind on. */
} connection_struct;
diff --git a/source/include/vfs.h b/source/include/vfs.h
index 4a06fe853a5..c1bab368c95 100644
--- a/source/include/vfs.h
+++ b/source/include/vfs.h
@@ -1,7 +1,7 @@
/*
Unix SMB/CIFS implementation.
VFS structures and parameters
- Copyright (C) Jeremy Allison 1999-2004
+ Copyright (C) Jeremy Allison 1999-2005
Copyright (C) Tim Potter 1999
Copyright (C) Alexander Bokovoy 2002
Copyright (C) Stefan (metze) Metzmacher 2003
@@ -56,11 +56,12 @@
/* Changed to version 9 to include the get_shadow_data call. --metze */
/* Changed to version 10 to include pread/pwrite calls. */
/* Changed to version 11 to include seekdir/telldir/rewinddir calls. JRA */
-/* Changed to version 12 to add mask and attributes to opendir(). JRA */
+/* Changed to version 12 to add mask and attributes to opendir(). JRA
+ Also include aio calls. JRA. */
#define SMB_VFS_INTERFACE_VERSION 12
-/* to bug old modules witch are trying to compile with the old functions */
+/* to bug old modules which are trying to compile with the old functions */
#define vfs_init __ERROR_please_port_this_module_to_SMB_VFS_INTERFACE_VERSION_8_donot_use_vfs_init_anymore(void) { __ERROR_please_port_this_module_to_SMB_VFS_INTERFACE_VERSION_8_donot_use_vfs_init_anymore };
#define lp_parm_string __ERROR_please_port_lp_parm_string_to_lp_parm_const_string_or_lp_parm_talloc_string { \
__ERROR_please_port_lp_parm_string_to_lp_parm_const_string_or_lp_parm_talloc_string };
@@ -191,6 +192,15 @@ typedef enum _vfs_op_type {
SMB_VFS_OP_LSETXATTR,
SMB_VFS_OP_FSETXATTR,
+ /* aio operations */
+ SMB_VFS_OP_AIO_READ,
+ SMB_VFS_OP_AIO_WRITE,
+ SMB_VFS_OP_AIO_RETURN,
+ SMB_VFS_OP_AIO_CANCEL,
+ SMB_VFS_OP_AIO_ERROR,
+ SMB_VFS_OP_AIO_FSYNC,
+ SMB_VFS_OP_AIO_SUSPEND,
+
/* This should always be last enum value */
SMB_VFS_OP_LAST
@@ -302,6 +312,15 @@ struct vfs_ops {
int (*lsetxattr)(struct vfs_handle_struct *handle, struct connection_struct *conn,const char *path, const char *name, const void *value, size_t size, int flags);
int (*fsetxattr)(struct vfs_handle_struct *handle, struct files_struct *fsp,int filedes, const char *name, const void *value, size_t size, int flags);
+ /* aio operations */
+ int (*aio_read)(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
+ int (*aio_write)(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
+ ssize_t (*aio_return)(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
+ int (*aio_cancel)(struct vfs_handle_struct *handle, struct files_struct *fsp, int fd, SMB_STRUCT_AIOCB *aiocb);
+ int (*aio_error)(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
+ int (*aio_fsync)(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb);
+ int (*aio_suspend)(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_AIOCB * const aiocb[], int n, const struct timespec *timeout);
+
} ops;
struct vfs_handles_pointers {
@@ -405,6 +424,14 @@ struct vfs_ops {
struct vfs_handle_struct *lsetxattr;
struct vfs_handle_struct *fsetxattr;
+ /* aio operations */
+ struct vfs_handle_struct *aio_read;
+ struct vfs_handle_struct *aio_write;
+ struct vfs_handle_struct *aio_return;
+ struct vfs_handle_struct *aio_cancel;
+ struct vfs_handle_struct *aio_error;
+ struct vfs_handle_struct *aio_fsync;
+ struct vfs_handle_struct *aio_suspend;
} handles;
};
diff --git a/source/include/vfs_macros.h b/source/include/vfs_macros.h
index dbe7c04d744..40ecd75fc9c 100644
--- a/source/include/vfs_macros.h
+++ b/source/include/vfs_macros.h
@@ -122,6 +122,15 @@
#define SMB_VFS_LSETXATTR(conn,path,name,value,size,flags) ((conn)->vfs.ops.lsetxattr((conn)->vfs.handles.lsetxattr,(conn),(path),(name),(value),(size),(flags)))
#define SMB_VFS_FSETXATTR(fsp,fd,name,value,size,flags) ((fsp)->conn->vfs.ops.fsetxattr((fsp)->conn->vfs.handles.fsetxattr,(fsp),(fd),(name),(value),(size),(flags)))
+/* AIO operations. */
+#define SMB_VFS_AIO_READ(fsp,aiocb) ((fsp)->conn->vfs.ops.aio_read((fsp)->conn->vfs.handles.aio_read,(fsp),(aiocb)))
+#define SMB_VFS_AIO_WRITE(fsp,aiocb) ((fsp)->conn->vfs.ops.aio_write((fsp)->conn->vfs.handles.aio_write,(fsp),(aiocb)))
+#define SMB_VFS_AIO_RETURN(fsp,aiocb) ((fsp)->conn->vfs.ops.aio_return((fsp)->conn->vfs.handles.aio_return,(fsp),(aiocb)))
+#define SMB_VFS_AIO_CANCEL(fsp,fd,aiocb) ((fsp)->conn->vfs.ops.aio_cancel((fsp)->conn->vfs.handles.aio_cancel,(fsp),(fd),(aiocb)))
+#define SMB_VFS_AIO_ERROR(fsp,aiocb) ((fsp)->conn->vfs.ops.aio_error((fsp)->conn->vfs.handles.aio_error,(fsp),(aiocb)))
+#define SMB_VFS_AIO_FSYNC(fsp,op,aiocb) ((fsp)->conn->vfs.ops.aio_fsync((fsp)->conn->vfs.handles.aio_fsync,(fsp),(op),(aiocb)))
+#define SMB_VFS_AIO_SUSPEND(fsp,aiocb,n,ts) ((fsp)->conn->vfs.ops.aio_suspend((fsp)->conn->vfs.handles.aio_suspend,(fsp),(aiocb),(n),(ts)))
+
/*******************************************************************
Don't access conn->vfs_opaque.ops directly!!!
Use this macros!
@@ -223,6 +232,15 @@
#define SMB_VFS_OPAQUE_LSETXATTR(conn,path,name,value,size,flags) ((conn)->vfs_opaque.ops.lsetxattr((conn)->vfs_opaque.handles.lsetxattr,(conn),(path),(name),(value),(size),(flags)))
#define SMB_VFS_OPAQUE_FSETXATTR(fsp,fd,name,value,size,flags) ((fsp)->conn->vfs_opaque.ops.fsetxattr((fsp)->conn->vfs_opaque.handles.fsetxattr,(fsp),(fd),(name),(value),(size),(flags)))
+/* AIO operations. */
+#define SMB_VFS_OPAQUE_AIO_READ(fsp,aiocb) ((fsp)->conn->vfs_opaque.ops.aio_read((fsp)->conn->vfs_opaque.handles.aio_read,(fsp),(aiocb)))
+#define SMB_VFS_OPAQUE_AIO_WRITE(fsp,aiocb) ((fsp)->conn->vfs_opaque.ops.aio_write((fsp)->conn->vfs_opaque.handles.aio_read,(fsp),(aiocb)))
+#define SMB_VFS_OPAQUE_AIO_RETURN(fsp,aiocb) ((fsp)->conn->vfs_opaque.ops.aio_return((fsp)->conn->vfs_opaque.handles.aio_read,(fsp),(aiocb)))
+#define SMB_VFS_OPAQUE_AIO_CANCEL(fsp,fd,aiocb) ((fsp)->conn->vfs_opaque.ops.aio_cancel((fsp)->conn->vfs_opaque.handles.aio_read,(fsp),(fd),(aiocb)))
+#define SMB_VFS_OPAQUE_AIO_ERROR(fsp,aiocb) ((fsp)->conn->vfs_opaque.ops.aio_error((fsp)->conn->vfs_opaque.handles.aio_read,(fsp),(aiocb)))
+#define SMB_VFS_OPAQUE_AIO_FSYNC(fsp,op,aiocb) ((fsp)->conn->vfs_opaque.ops.aio_fsync((fsp)->conn->vfs_opaque.handles.aio_read,(fsp),(op),(aiocb)))
+#define SMB_VFS_OPAQUE_AIO_SUSPEND(fsp,aiocb,n,ts) ((fsp)->conn->vfs_opaque.ops.aio_suspend((fsp)->conn->vfs_opaque.handles.aio_suspend,(fsp),(aiocb),(n),(ts)))
+
/*******************************************************************
Don't access handle->vfs_next.ops.* directly!!!
Use this macros!
@@ -325,4 +343,13 @@
#define SMB_VFS_NEXT_LSETXATTR(handle,conn,path,name,value,size,flags) ((handle)->vfs_next.ops.lsetxattr((handle)->vfs_next.handles.lsetxattr,(conn),(path),(name),(value),(size),(flags)))
#define SMB_VFS_NEXT_FSETXATTR(handle,fsp,fd,name,value,size,flags) ((handle)->vfs_next.ops.fsetxattr((handle)->vfs_next.handles.fsetxattr,(fsp),(fd),(name),(value),(size),(flags)))
+/* AIO operations. */
+#define SMB_VFS_NEXT_AIO_READ(handle,fsp,aiocb) ((handle)->vfs_next.ops.aio_read((handle)->vfs_next.handles.aio_read,(fsp),(aiocb)))
+#define SMB_VFS_NEXT_AIO_WRITE(handle,fsp,aiocb) ((handle)->vfs_next.ops.aio_write((handle)->vfs_next.handles.aio_read,(fsp),(aiocb)))
+#define SMB_VFS_NEXT_AIO_RETURN(handle,fsp,aiocb) ((handle)->vfs_next.ops.aio_return((handle)->vfs_next.handles.aio_read,(fsp),(aiocb)))
+#define SMB_VFS_NEXT_AIO_CANCEL(handle,fsp,fd,aiocb) ((handle)->vfs_next.ops.aio_cancel((handle)->vfs_next.handles.aio_read,(fsp),(fd),(aiocb)))
+#define SMB_VFS_NEXT_AIO_ERROR(handle,fsp,aiocb) ((handle)->vfs_next.ops.aio_error((handle)->vfs_next.handles.aio_read,(fsp),(aiocb)))
+#define SMB_VFS_NEXT_AIO_FSYNC(handle,fsp,op,aiocb) ((handle)->vfs_next.ops.aio_fsync((handle)->vfs_next.handles.aio_read,(fsp),(op),(aiocb)))
+#define SMB_VFS_NEXT_AIO_SUSPEND(handle,fsp,aiocb,n,ts) ((handle)->vfs_next.ops.aio_suspend((handle)->vfs_next.handles.aio_suspend,(fsp),(aiocb),(n),(ts)))
+
#endif /* _VFS_MACROS_H */
diff --git a/source/lib/system.c b/source/lib/system.c
index 6c36544b775..6ac2cdf2433 100644
--- a/source/lib/system.c
+++ b/source/lib/system.c
@@ -1846,3 +1846,161 @@ uint32 unix_dev_minor(SMB_DEV_T dev)
return (uint32)(dev & 0xff);
#endif
}
+
+#if defined(WITH_AIO)
+
+/*******************************************************************
+ An aio_read wrapper that will deal with 64-bit sizes.
+********************************************************************/
+
+int sys_aio_read(SMB_STRUCT_AIOCB *aiocb)
+{
+#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_READ64)
+ return aio_read64(aiocb);
+#elif defined(HAVE_AIO_READ)
+ return aio_read(aiocb);
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
+/*******************************************************************
+ An aio_write wrapper that will deal with 64-bit sizes.
+********************************************************************/
+
+int sys_aio_write(SMB_STRUCT_AIOCB *aiocb)
+{
+#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_WRITE64)
+ return aio_write64(aiocb);
+#elif defined(HAVE_AIO_WRITE)
+ return aio_write(aiocb);
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
+/*******************************************************************
+ An aio_return wrapper that will deal with 64-bit sizes.
+********************************************************************/
+
+ssize_t sys_aio_return(SMB_STRUCT_AIOCB *aiocb)
+{
+#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_RETURN64)
+ return aio_return64(aiocb);
+#elif defined(HAVE_AIO_RETURN)
+ return aio_return(aiocb);
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
+/*******************************************************************
+ An aio_cancel wrapper that will deal with 64-bit sizes.
+********************************************************************/
+
+int sys_aio_cancel(int fd, SMB_STRUCT_AIOCB *aiocb)
+{
+#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_CANCEL64)
+ return aio_cancel64(fd, aiocb);
+#elif defined(HAVE_AIO_CANCEL)
+ return aio_cancel(fd, aiocb);
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
+/*******************************************************************
+ An aio_error wrapper that will deal with 64-bit sizes.
+********************************************************************/
+
+int sys_aio_error(const SMB_STRUCT_AIOCB *aiocb)
+{
+#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_ERROR64)
+ return aio_error64(aiocb);
+#elif defined(HAVE_AIO_ERROR)
+ return aio_error(aiocb);
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
+/*******************************************************************
+ An aio_fsync wrapper that will deal with 64-bit sizes.
+********************************************************************/
+
+int sys_aio_fsync(int op, SMB_STRUCT_AIOCB *aiocb)
+{
+#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_FSYNC64)
+ return aio_fsync64(op, aiocb);
+#elif defined(HAVE_AIO_FSYNC)
+ return aio_fsync64(op, aiocb);
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
+/*******************************************************************
+ An aio_fsync wrapper that will deal with 64-bit sizes.
+********************************************************************/
+
+int sys_aio_suspend(const SMB_STRUCT_AIOCB * const cblist[], int n, const struct timespec *timeout)
+{
+#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_SUSPEND64)
+ return aio_suspend64(cblist, n, timeout);
+#elif defined(HAVE_AIO_FSYNC)
+ return aio_suspend(cblist, n, timeout);
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+#else /* !WITH_AIO */
+
+int sys_aio_read(SMB_STRUCT_AIOCB *aiocb)
+{
+ errno = ENOSYS;
+ return -1;
+}
+
+int sys_aio_write(SMB_STRUCT_AIOCB *aiocb)
+{
+ errno = ENOSYS;
+ return -1;
+}
+
+ssize_t sys_aio_return(SMB_STRUCT_AIOCB *aiocb)
+{
+ errno = ENOSYS;
+ return -1;
+}
+
+int sys_aio_cancel(int fd, SMB_STRUCT_AIOCB *aiocb)
+{
+ errno = ENOSYS;
+ return -1;
+}
+
+int sys_aio_error(const SMB_STRUCT_AIOCB *aiocb)
+{
+ errno = ENOSYS;
+ return -1;
+}
+
+int sys_aio_fsync(int op, SMB_STRUCT_AIOCB *aiocb)
+{
+ errno = ENOSYS;
+ return -1;
+}
+
+int sys_aio_suspend(const SMB_STRUCT_AIOCB * const cblist[], int n, const struct timespec *timeout)
+{
+ errno = ENOSYS;
+ return -1;
+}
+#endif /* WITH_AIO */
diff --git a/source/modules/vfs_full_audit.c b/source/modules/vfs_full_audit.c
index abb77bcbf47..aa9e047f0ae 100644
--- a/source/modules/vfs_full_audit.c
+++ b/source/modules/vfs_full_audit.c
@@ -291,6 +291,14 @@ static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
struct files_struct *fsp, int fd, const char *name,
const void *value, size_t size, int flags);
+static int smb_full_audit_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
+static int smb_full_audit_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
+static ssize_t smb_full_audit_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
+static int smb_full_audit_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, int fd, SMB_STRUCT_AIOCB *aiocb);
+static int smb_full_audit_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
+static int smb_full_audit_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb);
+static int smb_full_audit_aio_suspend(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_AIOCB * const aiocb[], int n, const struct timespec *ts);
+
/* VFS operations */
static vfs_op_tuple audit_op_tuples[] = {
@@ -477,6 +485,21 @@ static vfs_op_tuple audit_op_tuples[] = {
{SMB_VFS_OP(smb_full_audit_fsetxattr), SMB_VFS_OP_FSETXATTR,
SMB_VFS_LAYER_LOGGER},
+ {SMB_VFS_OP(smb_full_audit_aio_read), SMB_VFS_OP_AIO_READ,
+ SMB_VFS_LAYER_LOGGER},
+ {SMB_VFS_OP(smb_full_audit_aio_write), SMB_VFS_OP_AIO_WRITE,
+ SMB_VFS_LAYER_LOGGER},
+ {SMB_VFS_OP(smb_full_audit_aio_return), SMB_VFS_OP_AIO_RETURN,
+ SMB_VFS_LAYER_LOGGER},
+ {SMB_VFS_OP(smb_full_audit_aio_cancel), SMB_VFS_OP_AIO_CANCEL,
+ SMB_VFS_LAYER_LOGGER},
+ {SMB_VFS_OP(smb_full_audit_aio_error), SMB_VFS_OP_AIO_ERROR,
+ SMB_VFS_LAYER_LOGGER},
+ {SMB_VFS_OP(smb_full_audit_aio_fsync), SMB_VFS_OP_AIO_FSYNC,
+ SMB_VFS_LAYER_LOGGER},
+ {SMB_VFS_OP(smb_full_audit_aio_suspend),SMB_VFS_OP_AIO_SUSPEND,
+ SMB_VFS_LAYER_LOGGER},
+
/* Finish VFS operations definition */
{SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP,
@@ -571,6 +594,13 @@ static struct {
{ SMB_VFS_OP_SETXATTR, "setxattr" },
{ SMB_VFS_OP_LSETXATTR, "lsetxattr" },
{ SMB_VFS_OP_FSETXATTR, "fsetxattr" },
+ { SMB_VFS_OP_AIO_READ, "aio_read" },
+ { SMB_VFS_OP_AIO_WRITE, "aio_write" },
+ { SMB_VFS_OP_AIO_RETURN,"aio_return" },
+ { SMB_VFS_OP_AIO_CANCEL,"aio_cancel" },
+ { SMB_VFS_OP_AIO_ERROR, "aio_error" },
+ { SMB_VFS_OP_AIO_FSYNC, "aio_fsync" },
+ { SMB_VFS_OP_AIO_SUSPEND,"aio_suspend" },
{ SMB_VFS_OP_LAST, NULL }
};
@@ -1835,6 +1865,84 @@ static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
return result;
}
+static int smb_full_audit_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ int result;
+
+ result = SMB_VFS_NEXT_AIO_READ(handle, fsp, aiocb);
+ do_log(SMB_VFS_OP_AIO_READ, (result >= 0), handle,
+ "%s", fsp->fsp_name);
+
+ return result;
+}
+
+static int smb_full_audit_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ int result;
+
+ result = SMB_VFS_NEXT_AIO_WRITE(handle, fsp, aiocb);
+ do_log(SMB_VFS_OP_AIO_WRITE, (result >= 0), handle,
+ "%s", fsp->fsp_name);
+
+ return result;
+}
+
+static ssize_t smb_full_audit_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ int result;
+
+ result = SMB_VFS_NEXT_AIO_RETURN(handle, fsp, aiocb);
+ do_log(SMB_VFS_OP_AIO_RETURN, (result >= 0), handle,
+ "%s", fsp->fsp_name);
+
+ return result;
+}
+
+static int smb_full_audit_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, int fd, SMB_STRUCT_AIOCB *aiocb)
+{
+ int result;
+
+ result = SMB_VFS_NEXT_AIO_CANCEL(handle, fsp, fd, aiocb);
+ do_log(SMB_VFS_OP_AIO_CANCEL, (result >= 0), handle,
+ "%s", fsp->fsp_name);
+
+ return result;
+}
+
+static int smb_full_audit_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ int result;
+
+ result = SMB_VFS_NEXT_AIO_ERROR(handle, fsp, aiocb);
+ do_log(SMB_VFS_OP_AIO_ERROR, (result >= 0), handle,
+ "%s", fsp->fsp_name);
+
+ return result;
+}
+
+static int smb_full_audit_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb)
+{
+ int result;
+
+ result = SMB_VFS_NEXT_AIO_FSYNC(handle, fsp, op, aiocb);
+ do_log(SMB_VFS_OP_AIO_FSYNC, (result >= 0), handle,
+ "%s", fsp->fsp_name);
+
+ return result;
+}
+
+static int smb_full_audit_aio_suspend(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_AIOCB * const aiocb[], int n, const struct timespec *ts)
+{
+ int result;
+
+ result = SMB_VFS_NEXT_AIO_SUSPEND(handle, fsp, aiocb, n, ts);
+ do_log(SMB_VFS_OP_AIO_SUSPEND, (result >= 0), handle,
+ "%s", fsp->fsp_name);
+
+ return result;
+}
+
+
NTSTATUS vfs_full_audit_init(void)
{
NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
diff --git a/source/param/loadparm.c b/source/param/loadparm.c
index 24563042615..ff410a01db6 100644
--- a/source/param/loadparm.c
+++ b/source/param/loadparm.c
@@ -360,6 +360,7 @@ typedef struct
char *fstype;
char **szVfsObjects;
char *szMSDfsProxy;
+ char *szAioWriteBehind;
int iMinPrintSpace;
int iMaxPrintJobs;
int iMaxReportedPrintJobs;
@@ -437,6 +438,8 @@ typedef struct
BOOL bEASupport;
BOOL bAclCheckPermissions;
int iallocation_roundup_size;
+ int iAioReadSize;
+ int iAioWriteSize;
param_opt_struct *param_opt;
char dummy[3]; /* for alignment */
@@ -488,6 +491,7 @@ static service sDefault = {
NULL, /* fstype */
NULL, /* vfs objects */
NULL, /* szMSDfsProxy */
+ NULL, /* szAioWriteBehind */
0, /* iMinPrintSpace */
1000, /* iMaxPrintJobs */
0, /* iMaxReportedPrintJobs */
@@ -565,6 +569,8 @@ static service sDefault = {
False, /* bEASupport */
True, /* bAclCheckPermissions */
SMB_ROUNDUP_ALLOCATION_SIZE, /* iallocation_roundup_size */
+ 0, /* iAioReadSize */
+ 0, /* iAioWriteSize */
NULL, /* Parametric options */
@@ -914,6 +920,9 @@ static struct parm_struct parm_table[] = {
{N_("Protocol Options"), P_SEP, P_SEPARATOR},
{"allocation roundup size", P_INTEGER, P_LOCAL, &sDefault.iallocation_roundup_size, NULL, NULL, FLAG_ADVANCED},
+ {"aio read size", P_INTEGER, P_LOCAL, &sDefault.iAioReadSize, NULL, NULL, FLAG_ADVANCED},
+ {"aio write size", P_INTEGER, P_LOCAL, &sDefault.iAioWriteSize, NULL, NULL, FLAG_ADVANCED},
+ {"aio write behind", P_STRING, P_LOCAL, &sDefault.szAioWriteBehind, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL },
{"smb ports", P_STRING, P_GLOBAL, &Globals.smb_ports, NULL, NULL, FLAG_ADVANCED},
{"large readwrite", P_BOOL, P_GLOBAL, &Globals.bLargeReadwrite, NULL, NULL, FLAG_ADVANCED},
{"max protocol", P_ENUM, P_GLOBAL, &Globals.maxprotocol, NULL, enum_protocol, FLAG_ADVANCED},
@@ -1914,6 +1923,7 @@ FN_LOCAL_STRING(lp_veto_files, szVetoFiles)
FN_LOCAL_STRING(lp_hide_files, szHideFiles)
FN_LOCAL_STRING(lp_veto_oplocks, szVetoOplockFiles)
FN_LOCAL_BOOL(lp_msdfs_root, bMSDfsRoot)
+FN_LOCAL_STRING(lp_aio_write_behind, szAioWriteBehind)
FN_LOCAL_BOOL(lp_autoloaded, autoloaded)
FN_LOCAL_BOOL(lp_preexec_close, bPreexecClose)
FN_LOCAL_BOOL(lp_rootpreexec_close, bRootpreexecClose)
@@ -1987,6 +1997,8 @@ FN_LOCAL_INTEGER(lp_csc_policy, iCSCPolicy)
FN_LOCAL_INTEGER(lp_write_cache_size, iWriteCacheSize)
FN_LOCAL_INTEGER(lp_block_size, iBlock_size)
FN_LOCAL_INTEGER(lp_allocation_roundup_size, iallocation_roundup_size);
+FN_LOCAL_INTEGER(lp_aio_read_size, iAioReadSize);
+FN_LOCAL_INTEGER(lp_aio_write_size, iAioWriteSize);
FN_LOCAL_CHAR(lp_magicchar, magic_char)
FN_GLOBAL_INTEGER(lp_winbind_cache_time, &Globals.winbind_cache_time)
FN_GLOBAL_INTEGER(lp_winbind_max_idle_children, &Globals.winbind_max_idle_children)
diff --git a/source/smbd/aio.c b/source/smbd/aio.c
new file mode 100644
index 00000000000..7910ee5a7aa
--- /dev/null
+++ b/source/smbd/aio.c
@@ -0,0 +1,748 @@
+/*
+ Unix SMB/Netbios implementation.
+ Version 3.0
+ async_io read handling using POSIX async io.
+ Copyright (C) Jeremy Allison 2005.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+
+#if defined(WITH_AIO)
+
+/* The signal we'll use to signify aio done. */
+#ifndef RT_SIGNAL_AIO
+#define RT_SIGNAL_AIO (SIGRTMIN+3)
+#endif
+
+/****************************************************************************
+ The buffer we keep around whilst an aio request is in process.
+*****************************************************************************/
+
+struct aio_extra {
+ struct aio_extra *next, *prev;
+ SMB_STRUCT_AIOCB acb;
+ files_struct *fsp;
+ BOOL read_req;
+ uint16 mid;
+ char *inbuf;
+ char *outbuf;
+};
+
+static struct aio_extra *aio_list_head;
+
+/****************************************************************************
+ Create the extended aio struct we must keep around for the lifetime
+ of the aio_read call.
+*****************************************************************************/
+
+static struct aio_extra *create_aio_ex_read(files_struct *fsp, size_t buflen, uint16 mid)
+{
+ struct aio_extra *aio_ex = SMB_MALLOC_P(struct aio_extra);
+
+ if (!aio_ex) {
+ return NULL;
+ }
+ ZERO_STRUCTP(aio_ex);
+ /* The output buffer stored in the aio_ex is the start of
+ the smb return buffer. The buffer used in the acb
+ is the start of the reply data portion of that buffer. */
+ aio_ex->outbuf = SMB_MALLOC_ARRAY(char, buflen);
+ if (!aio_ex->outbuf) {
+ SAFE_FREE(aio_ex);
+ return NULL;
+ }
+ DLIST_ADD(aio_list_head, aio_ex);
+ aio_ex->fsp = fsp;
+ aio_ex->read_req = True;
+ aio_ex->mid = mid;
+ return aio_ex;
+}
+
+/****************************************************************************
+ Create the extended aio struct we must keep around for the lifetime
+ of the aio_write call.
+*****************************************************************************/
+
+static struct aio_extra *create_aio_ex_write(files_struct *fsp, size_t outbuflen, uint16 mid)
+{
+ struct aio_extra *aio_ex = SMB_MALLOC_P(struct aio_extra);
+
+ if (!aio_ex) {
+ return NULL;
+ }
+ ZERO_STRUCTP(aio_ex);
+
+ /* We need space for an output reply of outbuflen bytes. */
+ aio_ex->outbuf = SMB_MALLOC_ARRAY(char, outbuflen);
+ if (!aio_ex->outbuf) {
+ SAFE_FREE(aio_ex);
+ return NULL;
+ }
+ /* Steal the input buffer containing the write data from the main SMB call. */
+ /* We must re-allocate a new one here. */
+ if (NewInBuffer(&aio_ex->inbuf) == NULL) {
+ SAFE_FREE(aio_ex->outbuf);
+ SAFE_FREE(aio_ex);
+ return NULL;
+ }
+
+ /* aio_ex->inbuf now contains the stolen old InBuf containing the data to write. */
+
+ DLIST_ADD(aio_list_head, aio_ex);
+ aio_ex->fsp = fsp;
+ aio_ex->read_req = False;
+ aio_ex->mid = mid;
+ return aio_ex;
+}
+
+/****************************************************************************
+ Delete the extended aio struct.
+*****************************************************************************/
+
+static void delete_aio_ex(struct aio_extra *aio_ex)
+{
+ DLIST_REMOVE(aio_list_head, aio_ex);
+ /* Safe to do as we've removed ourselves from the in use list first. */
+ free_InBuffer(aio_ex->inbuf);
+
+ SAFE_FREE(aio_ex->outbuf);
+ SAFE_FREE(aio_ex);
+}
+
+/****************************************************************************
+ Given the aiocb struct find the extended aio struct containing it.
+*****************************************************************************/
+
+static struct aio_extra *find_aio_ex(uint16 mid)
+{
+ struct aio_extra *p;
+
+ for( p = aio_list_head; p; p = p->next) {
+ if (mid == p->mid) {
+ return p;
+ }
+ }
+ return NULL;
+}
+
+/****************************************************************************
+ We can have these many aio buffers in flight.
+*****************************************************************************/
+
+#define AIO_PENDING_SIZE 10
+static sig_atomic_t signals_received;
+static int outstanding_aio_calls;
+static uint16 aio_pending_array[AIO_PENDING_SIZE];
+
+/****************************************************************************
+ Signal handler when an aio request completes.
+*****************************************************************************/
+
+static void signal_handler(int sig, siginfo_t *info, void *unused)
+{
+ if (signals_received < AIO_PENDING_SIZE - 1) {
+ aio_pending_array[signals_received] = *(uint16 *)(info->si_value.sival_ptr);
+ signals_received++;
+ } /* Else signal is lost. */
+ sys_select_signal(RT_SIGNAL_AIO);
+}
+
+/****************************************************************************
+ Is there a signal waiting ?
+*****************************************************************************/
+
+BOOL aio_finished(void)
+{
+ return (signals_received != 0);
+}
+
+/****************************************************************************
+ Initialize the signal handler for aio read/write.
+*****************************************************************************/
+
+void initialize_async_io_handler(void)
+{
+ struct sigaction act;
+
+ ZERO_STRUCT(act);
+ act.sa_sigaction = signal_handler;
+ act.sa_flags = SA_SIGINFO;
+ sigemptyset( &act.sa_mask );
+ if (sigaction(RT_SIGNAL_AIO, &act, NULL) != 0) {
+ DEBUG(0,("Failed to setup RT_SIGNAL_AIO handler\n"));
+ }
+
+ /* the signal can start off blocked due to a bug in bash */
+ BlockSignals(False, RT_SIGNAL_AIO);
+}
+
+/****************************************************************************
+ Set up an aio request from a SMBreadX call.
+*****************************************************************************/
+
+BOOL schedule_aio_read_and_X(connection_struct *conn,
+ char *inbuf, char *outbuf,
+ int length, int len_outbuf,
+ files_struct *fsp, SMB_OFF_T startpos,
+ size_t smb_maxcnt)
+{
+ struct aio_extra *aio_ex;
+ SMB_STRUCT_AIOCB *a;
+ size_t bufsize;
+ size_t min_aio_read_size = lp_aio_read_size(SNUM(conn));
+
+ if (!min_aio_read_size || (smb_maxcnt < min_aio_read_size)) {
+ /* Too small a read for aio request. */
+ DEBUG(10,("schedule_aio_read_and_X: read size (%u) too small "
+ "for minimum aio_read of %u\n",
+ (unsigned int)smb_maxcnt,
+ (unsigned int)min_aio_read_size ));
+ return False;
+ }
+
+ /* Only do this on non-chained and non-chaining reads not using the write cache. */
+ if (chain_size !=0 || (CVAL(inbuf,smb_vwv0) != 0xFF) || (lp_write_cache_size(SNUM(conn)) != 0) ) {
+ return False;
+ }
+
+ if (outstanding_aio_calls >= AIO_PENDING_SIZE) {
+ DEBUG(10,("schedule_aio_read_and_X: Already have %d aio activities outstanding.\n",
+ outstanding_aio_calls ));
+ return False;
+ }
+
+ /* The following is safe from integer wrap as we've already
+ checked smb_maxcnt is 128k or less. */
+ bufsize = PTR_DIFF(smb_buf(outbuf),outbuf) + smb_maxcnt;
+
+ if ((aio_ex = create_aio_ex_read(fsp, bufsize, SVAL(inbuf,smb_mid))) == NULL) {
+ DEBUG(10,("schedule_aio_read_and_X: malloc fail.\n"));
+ return False;
+ }
+
+ /* Copy the SMB header already setup in outbuf. */
+ memcpy(aio_ex->outbuf, outbuf, smb_buf(outbuf) - outbuf);
+ SCVAL(aio_ex->outbuf,smb_vwv0,0xFF); /* Never a chained reply. */
+
+ a = &aio_ex->acb;
+
+ /* Now set up the aio record for the read call. */
+
+ a->aio_fildes = fsp->fd;
+ a->aio_buf = smb_buf(aio_ex->outbuf);
+ a->aio_nbytes = smb_maxcnt;
+ a->aio_offset = startpos;
+ a->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
+ a->aio_sigevent.sigev_signo = RT_SIGNAL_AIO;
+ a->aio_sigevent.sigev_value.sival_ptr = (void *)&aio_ex->mid;
+
+ if (SMB_VFS_AIO_READ(fsp,a) == -1) {
+ DEBUG(0,("schedule_aio_read_and_X: aio_read failed. Error %s\n",
+ strerror(errno) ));
+ delete_aio_ex(aio_ex);
+ return False;
+ }
+
+ DEBUG(10,("schedule_aio_read_and_X: scheduled aio_read for file %s, offset %.0f, len = %u (mid = %u)\n",
+ fsp->fsp_name, (double)startpos, (unsigned int)smb_maxcnt, (unsigned int)aio_ex->mid ));
+
+ srv_defer_sign_response(aio_ex->mid);
+ outstanding_aio_calls++;
+ return True;
+}
+
+/****************************************************************************
+ Set up an aio request from a SMBwriteX call.
+*****************************************************************************/
+
+BOOL schedule_aio_write_and_X(connection_struct *conn,
+ char *inbuf, char *outbuf,
+ int length, int len_outbuf,
+ files_struct *fsp, char *data,
+ SMB_OFF_T startpos,
+ size_t numtowrite)
+{
+ struct aio_extra *aio_ex;
+ SMB_STRUCT_AIOCB *a;
+ size_t outbufsize;
+ BOOL write_through = BITSETW(inbuf+smb_vwv7,0);
+ size_t min_aio_write_size = lp_aio_write_size(SNUM(conn));
+
+ if (!min_aio_write_size || (numtowrite < min_aio_write_size)) {
+ /* Too small a write for aio request. */
+ DEBUG(10,("schedule_aio_write_and_X: write size (%u) too small "
+ "for minimum aio_write of %u\n",
+ (unsigned int)numtowrite,
+ (unsigned int)min_aio_write_size ));
+ return False;
+ }
+
+ /* Only do this on non-chained and non-chaining reads not using the write cache. */
+ if (chain_size !=0 || (CVAL(inbuf,smb_vwv0) != 0xFF) || (lp_write_cache_size(SNUM(conn)) != 0) ) {
+ return False;
+ }
+
+ if (outstanding_aio_calls >= AIO_PENDING_SIZE) {
+ DEBUG(3,("schedule_aio_write_and_X: Already have %d aio activities outstanding.\n",
+ outstanding_aio_calls ));
+ DEBUG(10,("schedule_aio_write_and_X: failed to schedule aio_write for file %s, offset %.0f, len = %u (mid = %u)\n",
+ fsp->fsp_name, (double)startpos, (unsigned int)numtowrite, (unsigned int)SVAL(inbuf,smb_mid) ));
+ return False;
+ }
+
+ outbufsize = smb_len(outbuf) + 4;
+ if ((aio_ex = create_aio_ex_write(fsp, outbufsize, SVAL(inbuf,smb_mid))) == NULL) {
+ DEBUG(0,("schedule_aio_write_and_X: malloc fail.\n"));
+ return False;
+ }
+
+ /* Paranioa.... */
+ SMB_ASSERT(aio_ex->inbuf == inbuf);
+
+ /* Copy the SMB header already setup in outbuf. */
+ memcpy(aio_ex->outbuf, outbuf, outbufsize);
+ SCVAL(aio_ex->outbuf,smb_vwv0,0xFF); /* Never a chained reply. */
+
+ a = &aio_ex->acb;
+
+ /* Now set up the aio record for the write call. */
+
+ a->aio_fildes = fsp->fd;
+ a->aio_buf = data; /* As we've stolen inbuf this points within inbuf. */
+ a->aio_nbytes = numtowrite;
+ a->aio_offset = startpos;
+ a->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
+ a->aio_sigevent.sigev_signo = RT_SIGNAL_AIO;
+ a->aio_sigevent.sigev_value.sival_ptr = (void *)&aio_ex->mid;
+
+ if (SMB_VFS_AIO_WRITE(fsp,a) == -1) {
+ DEBUG(3,("schedule_aio_wrote_and_X: aio_write failed. Error %s\n",
+ strerror(errno) ));
+ /* Replace global InBuf as we're going to do a normal write. */
+ set_InBuffer(aio_ex->inbuf);
+ aio_ex->inbuf = NULL;
+ delete_aio_ex(aio_ex);
+ return False;
+ }
+
+ if (!write_through && !lp_syncalways(SNUM(fsp->conn)) && fsp->aio_write_behind) {
+ /* Lie to the client and immediately claim we finished the write. */
+ SSVAL(aio_ex->outbuf,smb_vwv2,numtowrite);
+ SSVAL(aio_ex->outbuf,smb_vwv4,(numtowrite>>16)&1);
+ show_msg(aio_ex->outbuf);
+ if (!send_smb(smbd_server_fd(),aio_ex->outbuf)) {
+ exit_server("handle_aio_write: send_smb failed.");
+ }
+ DEBUG(10,("schedule_aio_write_and_X: scheduled aio_write behind for file %s\n",
+ fsp->fsp_name ));
+ } else {
+ srv_defer_sign_response(aio_ex->mid);
+ }
+ outstanding_aio_calls++;
+
+ DEBUG(10,("schedule_aio_write_and_X: scheduled aio_write for file %s, \
+offset %.0f, len = %u (mid = %u) outstanding_aio_calls = %d\n",
+ fsp->fsp_name, (double)startpos, (unsigned int)numtowrite, (unsigned int)aio_ex->mid, outstanding_aio_calls ));
+
+ return True;
+}
+
+
+/****************************************************************************
+ Complete the read and return the data or error back to the client.
+ Returns errno or zero if all ok.
+*****************************************************************************/
+
+static int handle_aio_read_complete(struct aio_extra *aio_ex)
+{
+ int ret = 0;
+ int outsize;
+ char *outbuf = aio_ex->outbuf;
+ char *data = smb_buf(outbuf);
+ ssize_t nread = SMB_VFS_AIO_RETURN(aio_ex->fsp,&aio_ex->acb);
+
+ if (nread < 0) {
+ /* We're relying here on the fact that if the fd is
+ closed then the aio will complete and aio_return
+ will return an error. Hopefully this is
+ true.... JRA. */
+
+ /* If errno is ECANCELED then don't return anything to the client. */
+ if (errno == ECANCELED) {
+ srv_cancel_sign_response(aio_ex->mid);
+ return 0;
+ }
+
+ DEBUG( 3,( "handle_aio_read_complete: file %s nread == -1. Error = %s\n",
+ aio_ex->fsp->fsp_name, strerror(errno) ));
+
+ outsize = (UNIXERROR(ERRDOS,ERRnoaccess));
+ ret = errno;
+ } else {
+ outsize = set_message(outbuf,12,nread,False);
+ SSVAL(outbuf,smb_vwv2,0xFFFF); /* Remaining - must be * -1. */
+ SSVAL(outbuf,smb_vwv5,nread);
+ SSVAL(outbuf,smb_vwv6,smb_offset(data,outbuf));
+ SSVAL(outbuf,smb_vwv7,((nread >> 16) & 1));
+ SSVAL(smb_buf(outbuf),-2,nread);
+
+ DEBUG( 3, ( "handle_aio_read_complete file %s max=%d nread=%d\n",
+ aio_ex->fsp->fsp_name,
+ aio_ex->acb.aio_nbytes, (int)nread ) );
+
+ }
+ smb_setlen(outbuf,outsize - 4);
+ show_msg(outbuf);
+ if (!send_smb(smbd_server_fd(),outbuf)) {
+ exit_server("handle_aio_read_complete: send_smb failed.");
+ }
+
+ DEBUG(10,("handle_aio_read_complete: scheduled aio_read completed for file %s, offset %.0f, len = %u\n",
+ aio_ex->fsp->fsp_name, (double)aio_ex->acb.aio_offset, (unsigned int)nread ));
+
+ return ret;
+}
+
+/****************************************************************************
+ Complete the write and return the data or error back to the client.
+ Returns errno or zero if all ok.
+*****************************************************************************/
+
+static int handle_aio_write_complete(struct aio_extra *aio_ex)
+{
+ int ret = 0;
+ files_struct *fsp = aio_ex->fsp;
+ char *outbuf = aio_ex->outbuf;
+ ssize_t numtowrite = aio_ex->acb.aio_nbytes;
+ ssize_t nwritten = SMB_VFS_AIO_RETURN(fsp,&aio_ex->acb);
+
+ if (fsp->aio_write_behind) {
+ if (nwritten != numtowrite) {
+ if (nwritten == -1) {
+ DEBUG(5,("handle_aio_write_complete: aio_write_behind failed ! File %s is corrupt ! Error %s\n",
+ fsp->fsp_name, strerror(errno) ));
+ ret = errno;
+ } else {
+ DEBUG(0,("handle_aio_write_complete: aio_write_behind failed ! File %s is corrupt ! \
+Wanted %u bytes but only wrote %d\n", fsp->fsp_name, (unsigned int)numtowrite, (int)nwritten ));
+ ret = EIO;
+ }
+ } else {
+ DEBUG(10,("handle_aio_write_complete: aio_write_behind completed for file %s\n",
+ fsp->fsp_name ));
+ }
+ return 0;
+ }
+
+ /* We don't need outsize or set_message here as we've already set the
+ fixed size length when we set up the aio call. */
+
+ if(nwritten == -1) {
+ DEBUG( 3,( "handle_aio_write: file %s wanted %u bytes. nwritten == %d. Error = %s\n",
+ fsp->fsp_name, (unsigned int)numtowrite,
+ (int)nwritten, strerror(errno) ));
+
+ /* If errno is ECANCELED then don't return anything to the client. */
+ if (errno == ECANCELED) {
+ srv_cancel_sign_response(aio_ex->mid);
+ return 0;
+ }
+
+ UNIXERROR(ERRHRD,ERRdiskfull);
+ ret = errno;
+ } else {
+ BOOL write_through = BITSETW(aio_ex->inbuf+smb_vwv7,0);
+
+ SSVAL(outbuf,smb_vwv2,nwritten);
+ SSVAL(outbuf,smb_vwv4,(nwritten>>16)&1);
+ if (nwritten < (ssize_t)numtowrite) {
+ SCVAL(outbuf,smb_rcls,ERRHRD);
+ SSVAL(outbuf,smb_err,ERRdiskfull);
+ }
+
+ 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);
+ }
+ }
+
+ show_msg(outbuf);
+ if (!send_smb(smbd_server_fd(),outbuf)) {
+ exit_server("handle_aio_write: send_smb failed.");
+ }
+
+ DEBUG(10,("handle_aio_write_complete: scheduled aio_write completed for file %s, offset %.0f, requested %u, written = %u\n",
+ fsp->fsp_name, (double)aio_ex->acb.aio_offset, (unsigned int)numtowrite, (unsigned int)nwritten ));
+
+ return ret;
+}
+
+/****************************************************************************
+ Handle any aio completion. Returns True if finished (and sets *perr if err was non-zero),
+ False if not.
+*****************************************************************************/
+
+static BOOL handle_aio_completed(struct aio_extra *aio_ex, int *perr)
+{
+ int err;
+
+ /* Ensure the operation has really completed. */
+ if (SMB_VFS_AIO_ERROR(aio_ex->fsp, &aio_ex->acb) == EINPROGRESS) {
+ DEBUG(10,( "handle_aio_completed: operation mid %u still in process for file %s\n",
+ aio_ex->mid, aio_ex->fsp->fsp_name ));
+ return False;
+ }
+
+ if (aio_ex->read_req) {
+ err = handle_aio_read_complete(aio_ex);
+ } else {
+ err = handle_aio_write_complete(aio_ex);
+ }
+
+ if (err) {
+ *perr = err; /* Only save non-zero errors. */
+ }
+
+ return True;
+}
+
+/****************************************************************************
+ Handle any aio completion inline.
+ Returns non-zero errno if fail or zero if all ok.
+*****************************************************************************/
+
+int process_aio_queue(void)
+{
+ int i;
+ int ret = 0;
+
+ BlockSignals(True, RT_SIGNAL_AIO);
+
+ DEBUG(10,("process_aio_queue: signals_received = %d\n", (int)signals_received));
+ DEBUG(10,("process_aio_queue: outstanding_aio_calls = %d\n", outstanding_aio_calls));
+
+ if (!signals_received) {
+ BlockSignals(False, RT_SIGNAL_AIO);
+ return 0;
+ }
+
+ /* Drain all the complete aio_reads. */
+ for (i = 0; i < signals_received; i++) {
+ uint16 mid = aio_pending_array[i];
+ files_struct *fsp = NULL;
+ struct aio_extra *aio_ex = find_aio_ex(mid);
+
+ if (!aio_ex) {
+ DEBUG(3,("process_aio_queue: Can't find record to match mid %u.\n",
+ (unsigned int)mid));
+ srv_cancel_sign_response(mid);
+ continue;
+ }
+
+ fsp = aio_ex->fsp;
+ if (fsp == NULL) {
+ /* file was closed whilst I/O was outstanding. Just ignore. */
+ DEBUG( 3,( "process_aio_queue: file closed whilst aio outstanding.\n"));
+ srv_cancel_sign_response(mid);
+ continue;
+ }
+
+ if (!handle_aio_completed(aio_ex, &ret)) {
+ continue;
+ }
+
+ delete_aio_ex(aio_ex);
+ }
+
+ outstanding_aio_calls -= signals_received;
+ signals_received = 0;
+ BlockSignals(False, RT_SIGNAL_AIO);
+ return ret;
+}
+
+/****************************************************************************
+ We're doing write behind and the client closed the file. Wait up to 30 seconds
+ (my arbitrary choice) for the aio to complete. Return 0 if all writes completed,
+ errno to return if not.
+*****************************************************************************/
+
+#define SMB_TIME_FOR_AIO_COMPLETE_WAIT 29
+
+BOOL wait_for_aio_completion(files_struct *fsp)
+{
+ struct aio_extra *aio_ex;
+ const SMB_STRUCT_AIOCB **aiocb_list;
+ int aio_completion_count = 0;
+ time_t start_time = time(NULL);
+ int seconds_left;
+ int ret = 0;
+
+ for (seconds_left = SMB_TIME_FOR_AIO_COMPLETE_WAIT; seconds_left >= 0;) {
+ int err = 0;
+ int i;
+ struct timespec ts;
+
+ aio_completion_count = 0;
+ for( aio_ex = aio_list_head; aio_ex; aio_ex = aio_ex->next) {
+ if (aio_ex->fsp == fsp) {
+ aio_completion_count++;
+ }
+ }
+
+ if (!aio_completion_count) {
+ return ret;
+ }
+
+ DEBUG(3,("wait_for_aio_completion: waiting for %d aio events to complete.\n",
+ aio_completion_count ));
+
+ aiocb_list = SMB_MALLOC_ARRAY(const SMB_STRUCT_AIOCB *, aio_completion_count);
+ if (!aiocb_list) {
+ return False;
+ }
+
+ for( i = 0, aio_ex = aio_list_head; aio_ex; aio_ex = aio_ex->next) {
+ if (aio_ex->fsp == fsp) {
+ aiocb_list[i++] = &aio_ex->acb;
+ }
+ }
+
+ /* Now wait up to seconds_left for completion. */
+ ts.tv_sec = seconds_left;
+ ts.tv_nsec = 0;
+
+ DEBUG(10,("wait_for_aio_completion: %d events, doing a wait of %d seconds.\n",
+ aio_completion_count, seconds_left ));
+
+ err = SMB_VFS_AIO_SUSPEND(fsp, aiocb_list, aio_completion_count, &ts);
+
+ DEBUG(10,("wait_for_aio_completion: returned err = %d, errno = %s\n",
+ err, strerror(errno) ));
+
+ if (err == -1 && errno == EAGAIN) {
+ DEBUG(0,("wait_for_aio_completion: aio_suspend timed out waiting for %d events after a wait of %d seconds\n",
+ aio_completion_count, seconds_left));
+ /* Timeout. */
+ cancel_aio_by_fsp(fsp);
+ SAFE_FREE(aiocb_list);
+ return ret ? ret : EIO;
+ }
+
+ /* One or more events might have completed - process them if so. */
+ for( i = 0; i < aio_completion_count; i++) {
+ uint16 mid = *(uint16 *)aiocb_list[i]->aio_sigevent.sigev_value.sival_ptr;
+
+ aio_ex = find_aio_ex(mid);
+
+ if (!handle_aio_completed(aio_ex, &err)) {
+ continue;
+ }
+ delete_aio_ex(aio_ex);
+ }
+
+ SAFE_FREE(aiocb_list);
+ seconds_left = SMB_TIME_FOR_AIO_COMPLETE_WAIT - (time(NULL) - start_time);
+ }
+
+ /* We timed out - we don't know why. Return ret if already an error, else EIO. */
+ DEBUG(10,("wait_for_aio_completion: aio_suspend timed out waiting for %d events\n",
+ aio_completion_count));
+
+ return ret ? ret : EIO;
+}
+
+/****************************************************************************
+ Cancel any outstanding aio requests. The client doesn't care about the reply.
+*****************************************************************************/
+
+void cancel_aio_by_fsp(files_struct *fsp)
+{
+ struct aio_extra *aio_ex;
+
+ for( aio_ex = aio_list_head; aio_ex; aio_ex = aio_ex->next) {
+ if (aio_ex->fsp == fsp) {
+ /* Don't delete the aio_extra record as we may have completed
+ and don't yet know it. Just do the aio_cancel call and return. */
+ SMB_VFS_AIO_CANCEL(fsp,fsp->fd, &aio_ex->acb);
+ aio_ex->fsp = NULL; /* fsp will be closed when we return. */
+ }
+ }
+}
+
+/****************************************************************************
+ Check if a buffer was stolen for aio use.
+*****************************************************************************/
+
+BOOL aio_inbuffer_in_use(char *inbuf)
+{
+ struct aio_extra *aio_ex;
+
+ for( aio_ex = aio_list_head; aio_ex; aio_ex = aio_ex->next) {
+ if (aio_ex->inbuf == inbuf) {
+ return True;
+ }
+ }
+ return False;
+}
+#else
+BOOL aio_finished(void)
+{
+ return False;
+}
+
+void initialize_async_io_handler(void)
+{
+}
+
+int process_aio_queue(void)
+{
+ return False;
+}
+
+BOOL schedule_aio_read_and_X(connection_struct *conn,
+ char *inbuf, char *outbuf,
+ int length, int len_outbuf,
+ files_struct *fsp, SMB_OFF_T startpos,
+ size_t smb_maxcnt)
+{
+ return False;
+}
+
+BOOL schedule_aio_write_and_X(connection_struct *conn,
+ char *inbuf, char *outbuf,
+ int length, int len_outbuf,
+ files_struct *fsp, char *data,
+ SMB_OFF_T startpos,
+ size_t numtowrite)
+{
+ return False;
+}
+
+void cancel_aio_by_fsp(files_struct *fsp)
+{
+}
+
+BOOL wait_for_aio_completion(files_struct *fsp)
+{
+ return True;
+}
+
+BOOL aio_inbuffer_in_use(char *ptr)
+{
+ return False;
+}
+#endif
diff --git a/source/smbd/blocking.c b/source/smbd/blocking.c
index 0e71174a2ee..72d021d4e64 100644
--- a/source/smbd/blocking.c
+++ b/source/smbd/blocking.c
@@ -20,8 +20,6 @@
#include "includes.h"
-extern char *OutBuffer;
-
/****************************************************************************
This is the structure to queue to implement blocking locks.
notify. It consists of the requesting SMB and the expiry time.
@@ -175,7 +173,7 @@ static void send_blocking_reply(char *outbuf, int outsize)
static void reply_lockingX_success(blocking_lock_record *blr)
{
- char *outbuf = OutBuffer;
+ char *outbuf = get_OutBuffer();
int bufsize = BUFFER_SIZE;
char *inbuf = blr->inbuf;
int outsize = 0;
@@ -204,7 +202,7 @@ static void reply_lockingX_success(blocking_lock_record *blr)
static void generic_blocking_lock_error(blocking_lock_record *blr, NTSTATUS status)
{
- char *outbuf = OutBuffer;
+ char *outbuf = get_OutBuffer();
char *inbuf = blr->inbuf;
construct_reply_common(inbuf, outbuf);
@@ -295,7 +293,7 @@ static void blocking_lock_reply_error(blocking_lock_record *blr, NTSTATUS status
static BOOL process_lockread(blocking_lock_record *blr)
{
- char *outbuf = OutBuffer;
+ char *outbuf = get_OutBuffer();
char *inbuf = blr->inbuf;
ssize_t nread = -1;
char *data, *p;
@@ -367,7 +365,7 @@ static BOOL process_lockread(blocking_lock_record *blr)
static BOOL process_lock(blocking_lock_record *blr)
{
- char *outbuf = OutBuffer;
+ char *outbuf = get_OutBuffer();
char *inbuf = blr->inbuf;
int outsize;
SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT)0;
diff --git a/source/smbd/close.c b/source/smbd/close.c
index b3244432ff5..b7649bcce4f 100644
--- a/source/smbd/close.c
+++ b/source/smbd/close.c
@@ -156,6 +156,20 @@ static int close_normal_file(files_struct *fsp, BOOL normal_close)
remove_pending_lock_requests_by_fid(fsp);
+ if (fsp->aio_write_behind) {
+ /*
+ * If we're finishing write behind on a close we can get a write
+ * error here, we must remember this.
+ */
+ int ret = wait_for_aio_completion(fsp);
+ if (ret) {
+ saved_errno = ret;
+ err1 = -1;
+ }
+ } else {
+ cancel_aio_by_fsp(fsp);
+ }
+
/*
* If we're flushing on a close we can get a write
* error here, we must remember this.
diff --git a/source/smbd/conn.c b/source/smbd/conn.c
index dc7dec4e970..534a3367d48 100644
--- a/source/smbd/conn.c
+++ b/source/smbd/conn.c
@@ -257,6 +257,7 @@ void conn_free(connection_struct *conn)
free_namearray(conn->veto_list);
free_namearray(conn->hide_list);
free_namearray(conn->veto_oplock_list);
+ free_namearray(conn->aio_write_behind_list);
string_free(&conn->user);
string_free(&conn->dirpath);
diff --git a/source/smbd/notify.c b/source/smbd/notify.c
index 92b86f350c7..ad49dc0a211 100644
--- a/source/smbd/notify.c
+++ b/source/smbd/notify.c
@@ -60,6 +60,7 @@ static void change_notify_reply_packet(char *inbuf, NTSTATUS error_code)
*/
set_message(outbuf,18,0,False);
+ show_msg(outbuf);
if (!send_smb(smbd_server_fd(),outbuf))
exit_server("change_notify_reply_packet: send_smb failed.");
}
diff --git a/source/smbd/open.c b/source/smbd/open.c
index 8b30776fdd6..9da53a5057a 100644
--- a/source/smbd/open.c
+++ b/source/smbd/open.c
@@ -316,6 +316,10 @@ static BOOL open_file(files_struct *fsp,connection_struct *conn,
fsp->is_directory = False;
fsp->is_stat = False;
fsp->directory_delete_on_close = False;
+ if (conn->aio_write_behind_list && is_in_path(fname, conn->aio_write_behind_list, conn->case_sensitive)) {
+ fsp->aio_write_behind = True;
+ }
+
string_set(&fsp->fsp_name,fname);
fsp->wcp = NULL; /* Write cache pointer. */
diff --git a/source/smbd/oplock.c b/source/smbd/oplock.c
index 9b8df98fd56..8208fbebe34 100644
--- a/source/smbd/oplock.c
+++ b/source/smbd/oplock.c
@@ -634,6 +634,7 @@ static BOOL oplock_break_level2(files_struct *fsp, BOOL local_request)
/* Save the server smb signing state. */
sign_state = srv_oplock_set_signing(False);
+ show_msg(outbuf);
if (!send_smb(smbd_server_fd(), outbuf))
exit_server("oplock_break_level2: send_smb failed.");
@@ -677,7 +678,9 @@ static BOOL oplock_break_level2(files_struct *fsp, BOOL local_request)
static BOOL oplock_break(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id, BOOL local_request)
{
char *inbuf = NULL;
+ char *saved_inbuf = NULL;
char *outbuf = NULL;
+ char *saved_outbuf = NULL;
files_struct *fsp = NULL;
time_t start_time;
BOOL shutdown_server = False;
@@ -740,14 +743,15 @@ static BOOL oplock_break(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id,
* messages crossing on the wire.
*/
- if((inbuf = (char *)SMB_MALLOC(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
+ if((inbuf = NewInBuffer(&saved_inbuf))==NULL) {
DEBUG(0,("oplock_break: malloc fail for input buffer.\n"));
return False;
}
- if((outbuf = (char *)SMB_MALLOC(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
+ if((outbuf = NewOutBuffer(&saved_outbuf))==NULL) {
DEBUG(0,("oplock_break: malloc fail for output buffer.\n"));
- SAFE_FREE(inbuf);
+ set_InBuffer(saved_inbuf);
+ free_InBuffer(inbuf);
return False;
}
@@ -778,6 +782,7 @@ static BOOL oplock_break(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id,
/* Save the server smb signing state. */
sign_state = srv_oplock_set_signing(False);
+ show_msg(outbuf);
if (!send_smb(smbd_server_fd(), outbuf)) {
srv_oplock_set_signing(sign_state);
exit_server("oplock_break: send_smb failed.");
@@ -823,11 +828,16 @@ static BOOL oplock_break(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id,
* From Charles Hoch <hoch@exemplary.com>. If the break processing
* code closes the file (as it often does), then the fsp pointer here
* points to free()'d memory. We *must* revalidate fsp each time
- * around the loop.
+ * around the loop. With async I/O, write calls may steal the global InBuffer,
+ * so ensure we're using the correct one each time around the loop.
*/
while((fsp = initial_break_processing(dev, inode, file_id)) &&
OPEN_FSP(fsp) && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
+
+ inbuf = get_InBuffer();
+ outbuf = get_OutBuffer();
+
if(receive_smb(smbd_server_fd(),inbuf, timeout) == False) {
/*
* Die if we got an error.
@@ -899,9 +909,13 @@ static BOOL oplock_break(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id,
/* Restore the chain fnum. */
file_chain_restore();
+ /* Restore the global In/Out buffers. */
+ set_InBuffer(saved_inbuf);
+ set_OutBuffer(saved_outbuf);
+
/* Free the buffers we've been using to recurse. */
- SAFE_FREE(inbuf);
- SAFE_FREE(outbuf);
+ free_InBuffer(inbuf);
+ free_OutBuffer(outbuf);
/* We need this in case a readraw crossed on the wire. */
if(global_oplock_break)
diff --git a/source/smbd/process.c b/source/smbd/process.c
index c4c1debbf38..94d4b8d9032 100644
--- a/source/smbd/process.c
+++ b/source/smbd/process.c
@@ -28,8 +28,7 @@ extern int smb_echo_count;
struct timeval smb_last_time;
static char *InBuffer = NULL;
-char *OutBuffer = NULL;
-char *last_inbuf = NULL;
+static char *OutBuffer = NULL;
/*
* Size of data we can send to client. Set
@@ -287,11 +286,17 @@ static void async_processing(char *buffer, int buffer_len)
{
DEBUG(10,("async_processing: Doing async processing.\n"));
+ process_aio_queue();
+
/* check for oplock messages (both UDP and kernel) */
if (receive_local_message(buffer, buffer_len, 1)) {
process_local_message(buffer, buffer_len);
}
+ /* Do the aio check again after receive_local_message as it does a select
+ and may have eaten our signal. */
+ process_aio_queue();
+
if (got_sig_term) {
exit_server("Caught TERM signal");
}
@@ -981,8 +986,6 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize
!check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1))))
return(ERROR_DOS(ERRSRV,ERRaccess));
- last_inbuf = inbuf;
-
outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize);
}
@@ -1511,24 +1514,106 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup()));
}
/****************************************************************************
- process commands from the client
+ Accessor functions for InBuffer, OutBuffer.
****************************************************************************/
-void smbd_process(void)
+char *get_InBuffer(void)
{
- time_t last_timeout_processing_time = time(NULL);
- unsigned int num_smbs = 0;
- const size_t total_buffer_size = BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN;
+ return InBuffer;
+}
- InBuffer = (char *)SMB_MALLOC(total_buffer_size);
- OutBuffer = (char *)SMB_MALLOC(total_buffer_size);
- if ((InBuffer == NULL) || (OutBuffer == NULL))
- return;
+void set_InBuffer(char *new_inbuf)
+{
+ InBuffer = new_inbuf;
+}
+
+char *get_OutBuffer(void)
+{
+ return OutBuffer;
+}
+
+void set_OutBuffer(char *new_outbuf)
+{
+ OutBuffer = new_outbuf;
+}
+
+/****************************************************************************
+ Free an InBuffer. Checks if not in use by aio system.
+ Must have been allocated by NewInBuffer.
+****************************************************************************/
+
+void free_InBuffer(char *inbuf)
+{
+ if (!aio_inbuffer_in_use(inbuf)) {
+ SAFE_FREE(inbuf);
+ }
+}
+
+/****************************************************************************
+ Free an OutBuffer. No outbuffers currently stolen by aio system.
+ Must have been allocated by NewInBuffer.
+****************************************************************************/
+
+void free_OutBuffer(char *outbuf)
+{
+ SAFE_FREE(outbuf);
+}
+
+const int total_buffer_size = (BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN);
+/****************************************************************************
+ Allocate a new InBuffer. Returns the new and old ones.
+****************************************************************************/
+
+char *NewInBuffer(char **old_inbuf)
+{
+ char *new_inbuf = (char *)SMB_MALLOC(total_buffer_size);
+ if (!new_inbuf) {
+ return NULL;
+ }
+ if (old_inbuf) {
+ *old_inbuf = InBuffer;
+ }
+ InBuffer = new_inbuf;
#if defined(DEVELOPER)
clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size);
+#endif
+ return InBuffer;
+}
+
+/****************************************************************************
+ Allocate a new OutBuffer. Returns the new and old ones.
+****************************************************************************/
+
+char *NewOutBuffer(char **old_outbuf)
+{
+ char *new_outbuf = (char *)SMB_MALLOC(total_buffer_size);
+ if (!new_outbuf) {
+ return NULL;
+ }
+ if (old_outbuf) {
+ *old_outbuf = OutBuffer;
+ }
+ OutBuffer = new_outbuf;
+#if defined(DEVELOPER)
clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, OutBuffer, total_buffer_size);
#endif
+ return OutBuffer;
+}
+
+/****************************************************************************
+ Process commands from the client
+****************************************************************************/
+
+void smbd_process(void)
+{
+ time_t last_timeout_processing_time = time(NULL);
+ unsigned int num_smbs = 0;
+
+ /* Allocate the primary Inbut/Output buffers. */
+
+ if ((NewInBuffer(NULL) == NULL) || (NewOutBuffer(NULL) == NULL))
+ return;
max_recv = MIN(lp_maxxmit(),BUFFER_SIZE);
diff --git a/source/smbd/reply.c b/source/smbd/reply.c
index 9a7c22320c9..312a3ace23c 100644
--- a/source/smbd/reply.c
+++ b/source/smbd/reply.c
@@ -2575,13 +2575,10 @@ int reply_read_and_X(connection_struct *conn, char *inbuf,char *outbuf,int lengt
return ERROR_DOS(ERRDOS,ERRlock);
}
-#if 0
- /* Enable when the AIO code is moved over. JRA. */
if (schedule_aio_read_and_X(conn, inbuf, outbuf, length, bufsize, fsp, startpos, smb_maxcnt)) {
END_PROFILE(SMBreadX);
return -1;
}
-#endif
nread = send_file_readX(conn, inbuf, outbuf, length, bufsize, fsp, startpos, smb_maxcnt);
if (nread != -1)
@@ -2952,15 +2949,11 @@ int reply_write_and_X(connection_struct *conn, char *inbuf,char *outbuf,int leng
nwritten = 0;
} else {
-#if 0
- /* Enable when AIO code is moved over. JRA. */
-
if (schedule_aio_write_and_X(conn, inbuf, outbuf, length, bufsize,
fsp,data,startpos,numtowrite)) {
END_PROFILE(SMBwriteX);
return -1;
}
-#endif
nwritten = write_file(fsp,data,startpos,numtowrite);
}
diff --git a/source/smbd/server.c b/source/smbd/server.c
index b40a8267cc9..4217d821f4c 100644
--- a/source/smbd/server.c
+++ b/source/smbd/server.c
@@ -30,7 +30,6 @@ int last_message = -1;
/* a useful macro to debug the last message processed */
#define LAST_MESSAGE() smb_fn_name(last_message)
-extern char *last_inbuf;
extern struct auth_context *negprot_global_auth_context;
extern pstring user_socket_options;
extern SIG_ATOMIC_T got_sig_term;
@@ -635,6 +634,7 @@ void exit_server(const char *reason)
if (!reason) {
int oldlevel = DEBUGLEVEL;
+ char *last_inbuf = get_InBuffer();
DEBUGLEVEL = 10;
DEBUG(0,("Last message was %s\n",smb_fn_name(last_message)));
if (last_inbuf)
@@ -951,6 +951,9 @@ void build_options(BOOL screen);
if (!init_change_notify())
exit(1);
+ /* Setup aio signal handler. */
+ initialize_async_io_handler();
+
/* re-initialise the timezone */
TimeInit();
diff --git a/source/smbd/service.c b/source/smbd/service.c
index b53d6e3ad95..d330e847e2e 100644
--- a/source/smbd/service.c
+++ b/source/smbd/service.c
@@ -379,6 +379,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
conn->veto_list = NULL;
conn->hide_list = NULL;
conn->veto_oplock_list = NULL;
+ conn->aio_write_behind_list = NULL;
string_set(&conn->dirpath,"");
string_set(&conn->user,user);
conn->nt_user_token = NULL;
diff --git a/source/smbd/sesssetup.c b/source/smbd/sesssetup.c
index 95fe571cff1..1ddd6256b31 100644
--- a/source/smbd/sesssetup.c
+++ b/source/smbd/sesssetup.c
@@ -96,6 +96,7 @@ static BOOL reply_sesssetup_blob(connection_struct *conn, char *outbuf,
set_message_end(outbuf,p);
+ show_msg(outbuf);
return send_smb(smbd_server_fd(),outbuf);
}
diff --git a/source/smbd/trans2.c b/source/smbd/trans2.c
index 5bf53fca8aa..d4daf1fd690 100644
--- a/source/smbd/trans2.c
+++ b/source/smbd/trans2.c
@@ -591,6 +591,7 @@ static int send_trans2_replies(char *outbuf,
/* If there genuinely are no parameters or data to send just send the empty packet */
if(params_to_send == 0 && data_to_send == 0) {
+ show_msg(outbuf);
if (!send_smb(smbd_server_fd(),outbuf))
exit_server("send_trans2_replies: send_smb failed.");
return 0;
@@ -685,6 +686,7 @@ static int send_trans2_replies(char *outbuf,
params_to_send, data_to_send, paramsize, datasize));
/* Send the packet */
+ show_msg(outbuf);
if (!send_smb(smbd_server_fd(),outbuf))
exit_server("send_trans2_replies: send_smb failed.");
@@ -4912,6 +4914,7 @@ int reply_trans2(connection_struct *conn,
of the parameter/data bytes */
outsize = set_message(outbuf,0,0,True);
srv_signing_trans_stop();
+ show_msg(outbuf);
if (!send_smb(smbd_server_fd(),outbuf))
exit_server("reply_trans2: send_smb failed.");
diff --git a/source/smbd/vfs-wrap.c b/source/smbd/vfs-wrap.c
index 3260cce9aa2..1d205e59779 100644
--- a/source/smbd/vfs-wrap.c
+++ b/source/smbd/vfs-wrap.c
@@ -1052,3 +1052,38 @@ int vfswrap_fsetxattr(struct vfs_handle_struct *handle, struct files_struct *fsp
{
return sys_fsetxattr(fd, name, value, size, flags);
}
+
+int vfswrap_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ return sys_aio_read(aiocb);
+}
+
+int vfswrap_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ return sys_aio_write(aiocb);
+}
+
+int vfswrap_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ return sys_aio_return(aiocb);
+}
+
+int vfswrap_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, int fd, SMB_STRUCT_AIOCB *aiocb)
+{
+ return sys_aio_cancel(fd, aiocb);
+}
+
+int vfswrap_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
+{
+ return sys_aio_error(aiocb);
+}
+
+int vfswrap_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb)
+{
+ return sys_aio_fsync(op, aiocb);
+}
+
+int vfswrap_aio_suspend(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_AIOCB * const aiocb[], int n, const struct timespec *timeout)
+{
+ return sys_aio_suspend(aiocb, n, timeout);
+}
diff --git a/source/smbd/vfs.c b/source/smbd/vfs.c
index b09935eaa99..11adfed6946 100644
--- a/source/smbd/vfs.c
+++ b/source/smbd/vfs.c
@@ -145,7 +145,16 @@ static struct vfs_ops default_vfs = {
vfswrap_fremovexattr,
vfswrap_setxattr,
vfswrap_lsetxattr,
- vfswrap_fsetxattr
+ vfswrap_fsetxattr,
+
+ /* AIO operations. */
+ vfswrap_aio_read,
+ vfswrap_aio_write,
+ vfswrap_aio_return,
+ vfswrap_aio_cancel,
+ vfswrap_aio_error,
+ vfswrap_aio_fsync,
+ vfswrap_aio_suspend
}
};
@@ -277,20 +286,20 @@ BOOL vfs_init_custom(connection_struct *conn, const char *vfs_object)
DLIST_ADD(conn->vfs_handles, handle);
for(i=0; ops[i].op != NULL; i++) {
- DEBUG(5, ("Checking operation #%d (type %d, layer %d)\n", i, ops[i].type, ops[i].layer));
- if(ops[i].layer == SMB_VFS_LAYER_OPAQUE) {
- /* Check whether this operation was already made opaque by different module */
- if(((void**)&conn->vfs_opaque.ops)[ops[i].type] == ((void**)&default_vfs.ops)[ops[i].type]) {
- /* No, it isn't overloaded yet. Overload. */
- DEBUGADD(5, ("Making operation type %d opaque [module %s]\n", ops[i].type, vfs_object));
- ((void**)&conn->vfs_opaque.ops)[ops[i].type] = ops[i].op;
- ((vfs_handle_struct **)&conn->vfs_opaque.handles)[ops[i].type] = handle;
- }
- }
- /* Change current VFS disposition*/
- DEBUGADD(5, ("Accepting operation type %d from module %s\n", ops[i].type, vfs_object));
- ((void**)&conn->vfs.ops)[ops[i].type] = ops[i].op;
- ((vfs_handle_struct **)&conn->vfs.handles)[ops[i].type] = handle;
+ DEBUG(5, ("Checking operation #%d (type %d, layer %d)\n", i, ops[i].type, ops[i].layer));
+ if(ops[i].layer == SMB_VFS_LAYER_OPAQUE) {
+ /* Check whether this operation was already made opaque by different module */
+ if(((void**)&conn->vfs_opaque.ops)[ops[i].type] == ((void**)&default_vfs.ops)[ops[i].type]) {
+ /* No, it isn't overloaded yet. Overload. */
+ DEBUGADD(5, ("Making operation type %d opaque [module %s]\n", ops[i].type, vfs_object));
+ ((void**)&conn->vfs_opaque.ops)[ops[i].type] = ops[i].op;
+ ((vfs_handle_struct **)&conn->vfs_opaque.handles)[ops[i].type] = handle;
+ }
+ }
+ /* Change current VFS disposition*/
+ DEBUGADD(5, ("Accepting operation type %d from module %s\n", ops[i].type, vfs_object));
+ ((void**)&conn->vfs.ops)[ops[i].type] = ops[i].op;
+ ((vfs_handle_struct **)&conn->vfs.handles)[ops[i].type] = handle;
}
SAFE_FREE(module_name);