Linux-specific optimization in aio_open code.
authorJeremy Allison <jra@samba.org>
Thu, 12 Jul 2012 17:10:32 +0000 (10:10 -0700)
committerJeremy Allison <jra@samba.org>
Thu, 12 Jul 2012 22:35:47 +0000 (00:35 +0200)
Use initial_allocation_size to allocate on disk if sent. Ignore
failures (upper level will cope).

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Fri Jul 13 00:35:48 CEST 2012 on sn-devel-104

source3/modules/vfs_aio_pthread.c

index 4525beb818121dfeb8458ed146754c0f9dfe759d..2c6121dbe51349a28e1a76d19ca708e973a5581b 100644 (file)
@@ -27,6 +27,9 @@
 #include "smbd/smbd.h"
 #include "smbd/globals.h"
 #include "lib/pthreadpool/pthreadpool.h"
+#ifdef HAVE_LINUX_FALLOC_H
+#include <linux/falloc.h>
+#endif
 
 struct aio_extra;
 static struct pthreadpool *pool;
@@ -635,6 +638,7 @@ struct aio_open_private_data {
        char *dname;
        struct smbd_server_connection *sconn;
        const struct security_unix_token *ux_tok;
+       uint64_t initial_allocation_size;
        /* Returns. */
        int ret_fd;
        int ret_errno;
@@ -769,6 +773,23 @@ static void aio_open_worker(void *private_data)
        } else {
                /* Create was successful. */
                opd->ret_errno = 0;
+
+#if defined(HAVE_LINUX_FALLOCATE)
+               /*
+                * See if we can set the initial
+                * allocation size. We don't record
+                * the return for this as it's an
+                * optimization - the upper layer
+                * will also do this for us once
+                * the open returns.
+                */
+               if (opd->initial_allocation_size) {
+                       (void)fallocate(opd->ret_fd,
+                                       FALLOC_FL_KEEP_SIZE,
+                                       0,
+                                       (off_t)opd->initial_allocation_size);
+               }
+#endif
        }
 }
 
@@ -810,6 +831,7 @@ static struct aio_open_private_data *create_private_open_data(const files_struct
        opd->mid = fsp->mid;
        opd->in_progress = true;
        opd->sconn = fsp->conn->sconn;
+       opd->initial_allocation_size = fsp->initial_allocation_size;
 
        /* Copy our current credentials. */
        opd->ux_tok = copy_unix_token(opd, get_current_utok(fsp->conn));