From ef16f2bc86abc87ddee562f5fa51d9435082e9e8 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 5 Dec 2013 13:07:18 +0100 Subject: [PATCH] hack avoid tevent_req_create on write --- source3/smbd/smb2_write.c | 177 ++++++++++++++++++++------------------ 1 file changed, 92 insertions(+), 85 deletions(-) diff --git a/source3/smbd/smb2_write.c b/source3/smbd/smb2_write.c index 69b713e94b28..4201822ded04 100644 --- a/source3/smbd/smb2_write.c +++ b/source3/smbd/smb2_write.c @@ -113,15 +113,18 @@ NTSTATUS smbd_smb2_request_process_write(struct smbd_smb2_request *req) if (subreq == NULL) { return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY); } - tevent_req_set_callback(subreq, smbd_smb2_request_write_done, req); + //tevent_req_set_callback(subreq, smbd_smb2_request_write_done, req); + smbd_smb2_request_write_done(req); + return NT_STATUS_OK; return smbd_smb2_request_pending_queue(req, subreq, 500); } static void smbd_smb2_request_write_done(struct tevent_req *subreq) { - struct smbd_smb2_request *req = tevent_req_callback_data(subreq, - struct smbd_smb2_request); + struct smbd_smb2_request *req = subreq;//tevent_req_callback_data(subreq, + //struct smbd_smb2_request); + subreq = NULL; DATA_BLOB outbody; DATA_BLOB outdyn; uint32_t out_count = 0; @@ -176,6 +179,7 @@ struct smbd_smb2_write_state { uint64_t in_offset; uint32_t out_count; }; +static struct smbd_smb2_write_state _state; static void smbd_smb2_write_pipe_done(struct tevent_req *subreq); @@ -184,8 +188,8 @@ static NTSTATUS smb2_write_complete_internal(struct tevent_req *req, bool do_sync) { NTSTATUS status; - struct smbd_smb2_write_state *state = tevent_req_data(req, - struct smbd_smb2_write_state); + struct smbd_smb2_write_state *state = &_state;//tevent_req_data(req, + //struct smbd_smb2_write_state); files_struct *fsp = state->fsp; if (nwritten == -1) { @@ -245,9 +249,9 @@ NTSTATUS smb2_write_complete_nosync(struct tevent_req *req, ssize_t nwritten, static bool smbd_smb2_write_cancel(struct tevent_req *req) { - struct smbd_smb2_write_state *state = - tevent_req_data(req, - struct smbd_smb2_write_state); + struct smbd_smb2_write_state *state = &_state; + //tevent_req_data(req, + //struct smbd_smb2_write_state); return cancel_smb2_aio(state->smbreq); } @@ -261,18 +265,20 @@ static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx, uint32_t in_flags) { NTSTATUS status; - struct tevent_req *req = NULL; + //struct tevent_req *req = NULL; struct smbd_smb2_write_state *state = NULL; struct smb_request *smbreq = NULL; connection_struct *conn = smb2req->tcon->compat; ssize_t nwritten; struct lock_struct lock; - req = tevent_req_create(mem_ctx, &state, - struct smbd_smb2_write_state); - if (req == NULL) { - return NULL; - } +// req = tevent_req_create(mem_ctx, &state, +// struct smbd_smb2_write_state); +// if (req == NULL) { +// return NULL; +// } + ZERO_STRUCT(_state); + state = &_state; state->smb2req = smb2req; if (in_flags & SMB2_WRITEFLAG_WRITE_THROUGH) { state->write_through = true; @@ -284,46 +290,46 @@ static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx, fsp_str_dbg(fsp), fsp_fnum_dbg(fsp))); smbreq = smbd_smb2_fake_smb_request(smb2req); - if (tevent_req_nomem(smbreq, req)) { - return tevent_req_post(req, ev); - } +// if (tevent_req_nomem(smbreq, req)) { +// return tevent_req_post(req, ev); +// } state->smbreq = smbreq; state->fsp = fsp; - if (IS_IPC(smbreq->conn)) { - struct tevent_req *subreq = NULL; - - if (!fsp_is_np(fsp)) { - tevent_req_nterror(req, NT_STATUS_FILE_CLOSED); - return tevent_req_post(req, ev); - } - - if (smbreq->unread_bytes > 0) { - /* - * Note: in_data.data is NULL in this case. - */ - tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER); - return tevent_req_post(req, ev); - } - - subreq = np_write_send(state, ev, - fsp->fake_file_handle, - in_data.data, - in_data.length); - if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); - } - tevent_req_set_callback(subreq, - smbd_smb2_write_pipe_done, - req); - return req; - } - - if (!CHECK_WRITE(fsp)) { - tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED); - return tevent_req_post(req, ev); - } +// if (IS_IPC(smbreq->conn)) { +// struct tevent_req *subreq = NULL; +// +// if (!fsp_is_np(fsp)) { +// tevent_req_nterror(req, NT_STATUS_FILE_CLOSED); +// return tevent_req_post(req, ev); +// } +// +// if (smbreq->unread_bytes > 0) { +// /* +// * Note: in_data.data is NULL in this case. +// */ +// tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER); +// return tevent_req_post(req, ev); +// } +// +// subreq = np_write_send(state, ev, +// fsp->fake_file_handle, +// in_data.data, +// in_data.length); +// if (tevent_req_nomem(subreq, req)) { +// return tevent_req_post(req, ev); +// } +// tevent_req_set_callback(subreq, +// smbd_smb2_write_pipe_done, +// req); +// return req; +// } +// +// if (!CHECK_WRITE(fsp)) { +// tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED); +// return tevent_req_post(req, ev); +// } /* Try and do an asynchronous write. */ status = schedule_aio_smb2_write(conn, @@ -332,21 +338,21 @@ static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx, in_offset, in_data, state->write_through); - - if (NT_STATUS_IS_OK(status)) { - /* - * Doing an async write, allow this - * request to be canceled - */ - tevent_req_set_cancel_fn(req, smbd_smb2_write_cancel); - return req; - } - - if (!NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) { - /* Real error in setting up aio. Fail. */ - tevent_req_nterror(req, status); - return tevent_req_post(req, ev); - } +// +// if (NT_STATUS_IS_OK(status)) { +// /* +// * Doing an async write, allow this +// * request to be canceled +// */ +// tevent_req_set_cancel_fn(req, smbd_smb2_write_cancel); +// return req; +// } +// +// if (!NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) { +// /* Real error in setting up aio. Fail. */ +// tevent_req_nterror(req, status); +// return tevent_req_post(req, ev); +// } /* Fallback to synchronous. */ init_strict_lock_struct(fsp, @@ -357,8 +363,8 @@ static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx, &lock); if (!SMB_VFS_STRICT_LOCK(conn, fsp, &lock)) { - tevent_req_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT); - return tevent_req_post(req, ev); +// tevent_req_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT); +// return tevent_req_post(req, ev); } /* @@ -369,7 +375,7 @@ static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx, in_offset, in_data.length); - status = smb2_write_complete(req, nwritten, errno); + status = smb2_write_complete(NULL, nwritten, errno); SMB_VFS_STRICT_UNLOCK(conn, fsp, &lock); @@ -380,14 +386,14 @@ static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx, (unsigned int)in_data.length, (unsigned int)nwritten )); - if (!NT_STATUS_IS_OK(status)) { - tevent_req_nterror(req, status); - } else { - /* Success. */ - tevent_req_done(req); - } - - return req;//tevent_req_post(req, ev); +// if (!NT_STATUS_IS_OK(status)) { +// tevent_req_nterror(req, status); +// } else { +// /* Success. */ +// tevent_req_done(req); +// } +return state; + //return req;//tevent_req_post(req, ev); } static void smbd_smb2_write_pipe_done(struct tevent_req *subreq) @@ -422,16 +428,17 @@ static NTSTATUS smbd_smb2_write_recv(struct tevent_req *req, uint32_t *out_count) { NTSTATUS status; - struct smbd_smb2_write_state *state = tevent_req_data(req, - struct smbd_smb2_write_state); - - if (tevent_req_is_nterror(req, &status)) { - tevent_req_received(req); - return status; - } - + struct smbd_smb2_write_state *state = &_state;//tevent_req_data(req, + // struct smbd_smb2_write_state); +// +// if (tevent_req_is_nterror(req, &status)) { +// tevent_req_received(req); +// return status; +// } +// *out_count = state->out_count; - tevent_req_received(req); +// tevent_req_received(req); + ZERO_STRUCTP(state); return NT_STATUS_OK; } -- 2.34.1