s3: Return correct error code from SMB2 AIO read failure
[samba.git] / source3 / smbd / smb2_read.c
index 54bd3cdf7c06b60cc85e06ef257412906354057a..6478326ac068dfe10ff0dbdca77dd6c85d6b5ea8 100644 (file)
@@ -31,7 +31,6 @@ static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
                                              struct tevent_context *ev,
                                              struct smbd_smb2_request *smb2req,
                                              struct files_struct *in_fsp,
-                                             uint32_t in_smbpid,
                                              uint32_t in_length,
                                              uint64_t in_offset,
                                              uint32_t in_minimum,
@@ -45,10 +44,7 @@ static void smbd_smb2_request_read_done(struct tevent_req *subreq);
 NTSTATUS smbd_smb2_request_process_read(struct smbd_smb2_request *req)
 {
        NTSTATUS status;
-       const uint8_t *inhdr;
        const uint8_t *inbody;
-       int i = req->current_idx;
-       uint32_t in_smbpid;
        uint32_t in_length;
        uint64_t in_offset;
        uint64_t in_file_id_persistent;
@@ -62,10 +58,7 @@ NTSTATUS smbd_smb2_request_process_read(struct smbd_smb2_request *req)
        if (!NT_STATUS_IS_OK(status)) {
                return smbd_smb2_request_error(req, status);
        }
-       inhdr = (const uint8_t *)req->in.vector[i+0].iov_base;
-       inbody = (const uint8_t *)req->in.vector[i+1].iov_base;
-
-       in_smbpid = IVAL(inhdr, SMB2_HDR_PID);
+       inbody = SMBD_SMB2_IN_BODY_PTR(req);
 
        in_length               = IVAL(inbody, 0x04);
        in_offset               = BVAL(inbody, 0x08);
@@ -94,7 +87,6 @@ NTSTATUS smbd_smb2_request_process_read(struct smbd_smb2_request *req)
 
        subreq = smbd_smb2_read_send(req, req->sconn->ev_ctx,
                                     req, in_fsp,
-                                    in_smbpid,
                                     in_length,
                                     in_offset,
                                     in_minimum_count,
@@ -174,6 +166,7 @@ struct smbd_smb2_read_state {
        uint32_t in_length;
        uint64_t in_offset;
        uint32_t in_minimum;
+       DATA_BLOB out_headers;
        DATA_BLOB out_data;
        uint32_t out_remaining;
 };
@@ -188,10 +181,10 @@ static int smb2_sendfile_send_data(struct smbd_smb2_read_state *state)
        ssize_t nread;
 
        nread = SMB_VFS_SENDFILE(fsp->conn->sconn->sock,
-                                       fsp,
-                                       NULL,
-                                       in_offset,
-                                       in_length);
+                                fsp,
+                                state->smb2req->queue_entry.sendfile_header,
+                                in_offset,
+                                in_length);
        DEBUG(10,("smb2_sendfile_send_data: SMB_VFS_SENDFILE returned %d on file %s\n",
                (int)nread,
                fsp_str_dbg(fsp) ));
@@ -252,7 +245,7 @@ static int smb2_sendfile_send_data(struct smbd_smb2_read_state *state)
        }
 
        init_strict_lock_struct(fsp,
-                               fsp->fnum,
+                               fsp->op->global->open_persistent_id,
                                in_offset,
                                in_length,
                                READ_LOCK,
@@ -283,14 +276,15 @@ static NTSTATUS schedule_smb2_sendfile_read(struct smbd_smb2_request *smb2req,
        */
 
        if (!lp__use_sendfile(SNUM(fsp->conn)) ||
-                       smb2req->do_signing ||
-                       smb2req->in.vector_count != 4 ||
-                       (fsp->base_fsp != NULL) ||
-                       (fsp->wcp != NULL) ||
-                       (!S_ISREG(fsp->fsp_name->st.st_ex_mode)) ||
-                       (state->in_offset >= fsp->fsp_name->st.st_ex_size) ||
-                       (fsp->fsp_name->st.st_ex_size < state->in_offset +
-                               state->in_length)) {
+           smb2req->do_signing ||
+           smb2req->do_encryption ||
+           smb2req->in.vector_count >= (2*SMBD_SMB2_NUM_IOV_PER_REQ) ||
+           (fsp->base_fsp != NULL) ||
+           (fsp->wcp != NULL) ||
+           (!S_ISREG(fsp->fsp_name->st.st_ex_mode)) ||
+           (state->in_offset >= fsp->fsp_name->st.st_ex_size) ||
+           (fsp->fsp_name->st.st_ex_size < state->in_offset + state->in_length))
+       {
                return NT_STATUS_RETRY;
        }
 
@@ -308,6 +302,7 @@ static NTSTATUS schedule_smb2_sendfile_read(struct smbd_smb2_request *smb2req,
        }
        *state_copy = *state;
        talloc_set_destructor(state_copy, smb2_sendfile_send_data);
+       state->smb2req->queue_entry.sendfile_header = &state_copy->out_headers;
        return NT_STATUS_OK;
 }
 
@@ -370,8 +365,6 @@ static bool smbd_smb2_read_cancel(struct tevent_req *req)
                tevent_req_data(req,
                struct smbd_smb2_read_state);
 
-       state->smb2req->cancelled = true;
-
        return cancel_smb2_aio(state->smbreq);
 }
 
@@ -379,7 +372,6 @@ static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
                                              struct tevent_context *ev,
                                              struct smbd_smb2_request *smb2req,
                                              struct files_struct *fsp,
-                                             uint32_t in_smbpid,
                                              uint32_t in_length,
                                              uint64_t in_offset,
                                              uint32_t in_minimum,
@@ -389,7 +381,7 @@ static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
        struct tevent_req *req = NULL;
        struct smbd_smb2_read_state *state = NULL;
        struct smb_request *smbreq = NULL;
-       connection_struct *conn = smb2req->tcon->compat_conn;
+       connection_struct *conn = smb2req->tcon->compat;
        ssize_t nread = -1;
        struct lock_struct lock;
        int saved_errno;
@@ -472,14 +464,14 @@ static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
 
        if (!NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) {
                /* Real error in setting up aio. Fail. */
-               tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
+               tevent_req_nterror(req, status);
                return tevent_req_post(req, ev);
        }
 
        /* Fallback to synchronous. */
 
        init_strict_lock_struct(fsp,
-                               fsp->fnum,
+                               fsp->op->global->open_persistent_id,
                                in_offset,
                                in_length,
                                READ_LOCK,