Add an optimization to pthread aio writes to also do fsync if requested.
authorJeremy Allison <jra@samba.org>
Thu, 12 Jul 2012 17:57:47 +0000 (10:57 -0700)
committerJeremy Allison <jra@samba.org>
Thu, 12 Jul 2012 20:46:07 +0000 (22:46 +0200)
Should help by ensuring complete writes done in sub-thread, not in
the main thread.

source3/modules/vfs_aio_pthread.c
source3/smbd/aio.c
source3/smbd/proto.h

index d62af572561afbb9a3281dc7c8f390d44e1e0599..4525beb818121dfeb8458ed146754c0f9dfe759d 100644 (file)
@@ -40,6 +40,7 @@ struct aio_private_data {
        int ret_errno;
        bool cancelled;
        bool write_command;
+       bool flush_write;
 };
 
 /* List of outstanding requests we have. */
@@ -115,6 +116,14 @@ static void aio_worker(void *private_data)
                                        (const void *)pd->aiocb->aio_buf,
                                        pd->aiocb->aio_nbytes);
                }
+               if (pd->ret_size != -1 && pd->flush_write) {
+                       /*
+                        * Optimization - flush if requested.
+                        * Ignore error as upper layer will
+                        * also do this.
+                        */
+                       (void)fsync(pd->aiocb->aio_fildes);
+               }
        } else {
                pd->ret_size = sys_pread(pd->aiocb->aio_fildes,
                                (void *)pd->aiocb->aio_buf,
@@ -229,6 +238,12 @@ static int aio_pthread_write(struct vfs_handle_struct *handle,
        }
 
        pd->write_command = true;
+       if (lp_strict_sync(SNUM(fsp->conn)) &&
+                       (lp_syncalways(SNUM(fsp->conn)) ||
+                               aio_write_through_requested(aio_ex))) {
+               pd->flush_write = true;
+       }
+
 
        ret = pthreadpool_add_job(pool, pd->jobid, aio_worker, (void *)pd);
        if (ret) {
index 0ea5274420aa2e6d8f169e47e8b3f2be163f6f56..569741c747dc0fc067566ada43b8802008eba247 100644 (file)
@@ -52,6 +52,15 @@ struct aio_extra {
        int (*handle_completion)(struct aio_extra *ex, int errcode);
 };
 
+/****************************************************************************
+ Accessor function to return write_through state.
+*****************************************************************************/
+
+bool aio_write_through_requested(struct aio_extra *aio_ex)
+{
+       return aio_ex->write_through;
+}
+
 /****************************************************************************
  Initialize the signal handler for aio read/write.
 *****************************************************************************/
index 9aaa00a1ce707b2036339d1f96397a55bd3259c2..26d6432c15223cb7aa62e11e8d6c624c3b2edfa3 100644 (file)
@@ -64,6 +64,7 @@ void srv_set_signing(struct smbd_server_connection *conn,
 
 /* The following definitions come from smbd/aio.c  */
 
+bool aio_write_through_requested(struct aio_extra *aio_ex);
 bool initialize_async_io_handler(void);
 NTSTATUS schedule_aio_read_and_X(connection_struct *conn,
                             struct smb_request *req,