Change interface of schedule_smb2_aio_read() to allocate the return DATA_BLOB.
authorJeremy Allison <jra@samba.org>
Wed, 15 Dec 2010 00:32:10 +0000 (16:32 -0800)
committerJeremy Allison <jra@samba.org>
Wed, 15 Dec 2010 00:38:16 +0000 (01:38 +0100)
Change smb2_read code to allocate return DATA_BLOB just before the read.

Preparing for SMB2 sendfile change which will not need to allocate
return buffer.

Jeremy

source3/include/proto.h
source3/smbd/aio.c
source3/smbd/smb2_read.c

index 084d97f16e2879de0e4ada5e53e5070d1818e1b3..2ba2153258a7aaf6e7be1eb1bfc6c1442566bf80 100644 (file)
@@ -4438,7 +4438,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);
 NTSTATUS schedule_aio_smb2_write(connection_struct *conn,
index 7a23d379181b3a90972aad1a6f40cef957718be1..eb8ed6799f1c3e9179b2888f58cc55f25ba42474 100644 (file)
@@ -385,7 +385,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 +428,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 +454,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;
@@ -1031,7 +1038,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)
 {
index b1866d148110f4426e37d33689a7f0741856fbdd..97f12d582cb128e17571fe8cd10a10d67f0f23da 100644 (file)
@@ -290,16 +290,16 @@ static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
                return tevent_req_post(req, ev);
        }
 
-       state->out_data = data_blob_talloc(state, NULL, in_length);
-       if (in_length > 0 && tevent_req_nomem(state->out_data.data, req)) {
-               return tevent_req_post(req, ev);
-       }
-
        state->fsp = fsp;
 
        if (IS_IPC(smbreq->conn)) {
                struct tevent_req *subreq = NULL;
 
+               state->out_data = data_blob_talloc(state, NULL, in_length);
+               if (in_length > 0 && tevent_req_nomem(state->out_data.data, req)) {
+                       return tevent_req_post(req, ev);
+               }
+
                if (!fsp_is_np(fsp)) {
                        tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                        return tevent_req_post(req, ev);
@@ -326,7 +326,8 @@ static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
        status = schedule_smb2_aio_read(fsp->conn,
                                smbreq,
                                fsp,
-                               (char *)state->out_data.data,
+                               state,
+                               &state->out_data,
                                (SMB_OFF_T)in_offset,
                                (size_t)in_length);
 
@@ -363,6 +364,13 @@ static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
                return tevent_req_post(req, ev);
        }
 
+       /* Ok, read into memory. Allocate the out buffer. */
+       state->out_data = data_blob_talloc(state, NULL, in_length);
+       if (in_length > 0 && tevent_req_nomem(state->out_data.data, req)) {
+               SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock);
+               return tevent_req_post(req, ev);
+       }
+
        nread = read_file(fsp,
                          (char *)state->out_data.data,
                          in_offset,