s3-talloc Change TALLOC_ZERO_P() to talloc_zero()
[nivanova/samba-autobuild/.git] / source3 / smbd / aio.c
index 7a23d379181b3a90972aad1a6f40cef957718be1..db2926b4a4f3a41ff579d2152820d276a2f7aaff 100644 (file)
@@ -19,7 +19,9 @@
 */
 
 #include "includes.h"
+#include "smbd/smbd.h"
 #include "smbd/globals.h"
+#include "../lib/util/tevent_ntstatus.h"
 
 #if defined(WITH_AIO)
 
@@ -79,8 +81,8 @@ static bool initialize_async_io_handler(void)
        }
        tried_signal_setup = true;
 
-       aio_signal_event = tevent_add_signal(smbd_event_context(),
-                                            smbd_event_context(),
+       aio_signal_event = tevent_add_signal(server_event_context(),
+                                            server_event_context(),
                                             RT_SIGNAL_AIO, SA_SIGINFO,
                                             smbd_aio_signal_handler,
                                             NULL);
@@ -114,7 +116,7 @@ static struct aio_extra *create_aio_extra(TALLOC_CTX *mem_ctx,
                                        files_struct *fsp,
                                        size_t buflen)
 {
-       struct aio_extra *aio_ex = TALLOC_ZERO_P(mem_ctx, struct aio_extra);
+       struct aio_extra *aio_ex = talloc_zero(mem_ctx, struct aio_extra);
 
        if (!aio_ex) {
                return NULL;
@@ -249,7 +251,7 @@ NTSTATUS schedule_aio_read_and_X(connection_struct *conn,
 
 NTSTATUS schedule_aio_write_and_X(connection_struct *conn,
                              struct smb_request *smbreq,
-                             files_struct *fsp, char *data,
+                             files_struct *fsp, const char *data,
                              SMB_OFF_T startpos,
                              size_t numtowrite)
 {
@@ -327,7 +329,7 @@ NTSTATUS schedule_aio_write_and_X(connection_struct *conn,
        /* Now set up the aio record for the write call. */
 
        a->aio_fildes = fsp->fh->fd;
-       a->aio_buf = data;
+       a->aio_buf = discard_const_p(char, data);
        a->aio_nbytes = numtowrite;
        a->aio_offset = startpos;
        a->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
@@ -385,7 +387,8 @@ NTSTATUS schedule_aio_write_and_X(connection_struct *conn,
 NTSTATUS schedule_smb2_aio_read(connection_struct *conn,
                                struct smb_request *smbreq,
                                files_struct *fsp,
-                               char *inbuf,
+                               TALLOC_CTX *ctx,
+                               DATA_BLOB *preadbuf,
                                SMB_OFF_T startpos,
                                size_t smb_maxcnt)
 {
@@ -427,6 +430,12 @@ NTSTATUS schedule_smb2_aio_read(connection_struct *conn,
                return NT_STATUS_RETRY;
        }
 
+       /* Create the out buffer. */
+       *preadbuf = data_blob_talloc(ctx, NULL, smb_maxcnt);
+       if (preadbuf->data == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
        if (!(aio_ex = create_aio_extra(smbreq->smb2req, fsp, 0))) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -447,7 +456,7 @@ NTSTATUS schedule_smb2_aio_read(connection_struct *conn,
        /* Now set up the aio record for the read call. */
 
        a->aio_fildes = fsp->fh->fd;
-       a->aio_buf = inbuf;
+       a->aio_buf = preadbuf->data;
        a->aio_nbytes = smb_maxcnt;
        a->aio_offset = startpos;
        a->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
@@ -1021,7 +1030,7 @@ NTSTATUS schedule_aio_read_and_X(connection_struct *conn,
 
 NTSTATUS schedule_aio_write_and_X(connection_struct *conn,
                              struct smb_request *smbreq,
-                             files_struct *fsp, char *data,
+                             files_struct *fsp, const char *data,
                              SMB_OFF_T startpos,
                              size_t numtowrite)
 {
@@ -1031,7 +1040,8 @@ NTSTATUS schedule_aio_write_and_X(connection_struct *conn,
 NTSTATUS schedule_smb2_aio_read(connection_struct *conn,
                                 struct smb_request *smbreq,
                                 files_struct *fsp,
-                                char *inbuf,
+                               TALLOC_CTX *ctx,
+                               DATA_BLOB *preadbuf,
                                 SMB_OFF_T startpos,
                                 size_t smb_maxcnt)
 {