#include "../lib/util/tevent_unix.h"
#include "lib/tevent_wait.h"
+/****************************************************************************
+ Statics plus accessor functions.
+*****************************************************************************/
+
+static int outstanding_aio_calls;
+
+int get_outstanding_aio_calls(void)
+{
+ return outstanding_aio_calls;
+}
+
+void increment_outstanding_aio_calls(void)
+{
+ outstanding_aio_calls++;
+}
+
+void decrement_outstanding_aio_calls(void)
+{
+ outstanding_aio_calls--;
+}
+
/****************************************************************************
The buffer we keep around whilst an aio request is in process.
*****************************************************************************/
static int aio_extra_destructor(struct aio_extra *aio_ex)
{
- outstanding_aio_calls--;
+ decrement_outstanding_aio_calls();
return 0;
}
}
talloc_set_destructor(aio_ex, aio_extra_destructor);
aio_ex->fsp = fsp;
- outstanding_aio_calls++;
+ increment_outstanding_aio_calls();
return aio_ex;
}
return 0;
}
-static bool aio_add_req_to_fsp(files_struct *fsp, struct tevent_req *req)
+bool aio_add_req_to_fsp(files_struct *fsp, struct tevent_req *req)
{
size_t array_len;
struct aio_req_fsp_link *lnk;
return NT_STATUS_RETRY;
}
- if (outstanding_aio_calls >= aio_pending_size) {
- DEBUG(10,("schedule_aio_read_and_X: Already have %d aio "
- "activities outstanding.\n",
- outstanding_aio_calls ));
- return NT_STATUS_RETRY;
- }
-
/* The following is safe from integer wrap as we've already checked
smb_maxcnt is 128k or less. Wct is 12 for read replies */
- bufsize = smb_size + 12 * 2 + smb_maxcnt;
+ bufsize = smb_size + 12 * 2 + smb_maxcnt + 1 /* padding byte */;
if ((aio_ex = create_aio_extra(NULL, fsp, bufsize)) == NULL) {
DEBUG(10,("schedule_aio_read_and_X: malloc fail.\n"));
construct_reply_common_req(smbreq, (char *)aio_ex->outbuf.data);
srv_set_message((char *)aio_ex->outbuf.data, 12, 0, True);
SCVAL(aio_ex->outbuf.data,smb_vwv0,0xFF); /* Never a chained reply. */
+ SCVAL(smb_buf(aio_ex->outbuf.data), 0, 0); /* padding byte */
init_strict_lock_struct(fsp, (uint64_t)smbreq->smbpid,
(uint64_t)startpos, (uint64_t)smb_maxcnt, READ_LOCK,
aio_ex->offset = startpos;
req = SMB_VFS_PREAD_SEND(aio_ex, fsp->conn->sconn->ev_ctx,
- fsp, smb_buf(aio_ex->outbuf.data),
+ fsp,
+ smb_buf(aio_ex->outbuf.data) + 1 /* pad */,
smb_maxcnt, startpos);
if (req == NULL) {
DEBUG(0,("schedule_aio_read_and_X: aio_read failed. "
"Error %s\n", strerror(errno) ));
- SMB_VFS_STRICT_UNLOCK(conn, fsp, &aio_ex->lock);
TALLOC_FREE(aio_ex);
return NT_STATUS_RETRY;
}
if (!aio_add_req_to_fsp(fsp, req)) {
DEBUG(1, ("Could not add req to fsp\n"));
- SMB_VFS_STRICT_UNLOCK(conn, fsp, &aio_ex->lock);
TALLOC_FREE(aio_ex);
return NT_STATUS_RETRY;
}
files_struct *fsp = aio_ex->fsp;
int outsize;
char *outbuf = (char *)aio_ex->outbuf.data;
- char *data = smb_buf(outbuf);
ssize_t nread;
- int err;
+ struct vfs_aio_state vfs_aio_state;
- nread = SMB_VFS_PREAD_RECV(req, &err);
+ nread = SMB_VFS_PREAD_RECV(req, &vfs_aio_state);
TALLOC_FREE(req);
DEBUG(10, ("pread_recv returned %d, err = %s\n", (int)nread,
- (nread == -1) ? strerror(err) : "no error"));
+ (nread == -1) ? strerror(vfs_aio_state.error) : "no error"));
if (fsp == NULL) {
DEBUG( 3, ("aio_pread_smb1_done: file closed whilst "
return;
}
- /* Unlock now we're done. */
- SMB_VFS_STRICT_UNLOCK(fsp->conn, fsp, &aio_ex->lock);
-
if (nread < 0) {
DEBUG( 3, ("handle_aio_read_complete: file %s nread == %d. "
"Error = %s\n", fsp_str_dbg(fsp), (int)nread,
- strerror(err)));
+ strerror(vfs_aio_state.error)));
- ERROR_NT(map_nt_error_from_unix(err));
+ ERROR_NT(map_nt_error_from_unix(vfs_aio_state.error));
outsize = srv_set_message(outbuf,0,0,true);
} else {
- outsize = srv_set_message(outbuf, 12, nread, False);
- SSVAL(outbuf,smb_vwv2, 0xFFFF); /* Remaining - must be * -1. */
- SSVAL(outbuf,smb_vwv5, nread);
- SSVAL(outbuf,smb_vwv6, smb_offset(data,outbuf));
- SSVAL(outbuf,smb_vwv7, ((nread >> 16) & 1));
- SSVAL(smb_buf(outbuf), -2, nread);
+ outsize = setup_readX_header(outbuf, nread);
aio_ex->fsp->fh->pos = aio_ex->offset + nread;
aio_ex->fsp->fh->position_information = aio_ex->fsp->fh->pos;
}
smb_setlen(outbuf, outsize - 4);
show_msg(outbuf);
- if (!srv_send_smb(aio_ex->smbreq->sconn, outbuf,
+ if (!srv_send_smb(aio_ex->smbreq->xconn, outbuf,
true, aio_ex->smbreq->seqnum+1,
IS_CONN_ENCRYPTED(fsp->conn), NULL)) {
exit_server_cleanly("handle_aio_read_complete: srv_send_smb "
struct pwrite_fsync_state *state = tevent_req_data(
req, struct pwrite_fsync_state);
connection_struct *conn = state->fsp->conn;
- int err;
bool do_sync;
+ struct vfs_aio_state vfs_aio_state;
- state->nwritten = SMB_VFS_PWRITE_RECV(subreq, &err);
+ state->nwritten = SMB_VFS_PWRITE_RECV(subreq, &vfs_aio_state);
TALLOC_FREE(subreq);
if (state->nwritten == -1) {
- tevent_req_error(req, err);
+ tevent_req_error(req, vfs_aio_state.error);
return;
}
do_sync = (lp_strict_sync(SNUM(conn)) &&
- (lp_syncalways(SNUM(conn)) || state->write_through));
+ (lp_sync_always(SNUM(conn)) || state->write_through));
if (!do_sync) {
tevent_req_done(req);
return;
{
struct tevent_req *req = tevent_req_callback_data(
subreq, struct tevent_req);
- int ret, err;
+ int ret;
+ struct vfs_aio_state vfs_aio_state;
- ret = SMB_VFS_FSYNC_RECV(subreq, &err);
+ ret = SMB_VFS_FSYNC_RECV(subreq, &vfs_aio_state);
TALLOC_FREE(subreq);
if (ret == -1) {
- tevent_req_error(req, err);
+ tevent_req_error(req, vfs_aio_state.error);
return;
}
tevent_req_done(req);
return NT_STATUS_RETRY;
}
- if (outstanding_aio_calls >= aio_pending_size) {
- DEBUG(3,("schedule_aio_write_and_X: Already have %d aio "
- "activities outstanding.\n",
- outstanding_aio_calls ));
- DEBUG(10,("schedule_aio_write_and_X: failed to schedule "
- "aio_write for file %s, offset %.0f, len = %u "
- "(mid = %u)\n",
- fsp_str_dbg(fsp), (double)startpos,
- (unsigned int)numtowrite,
- (unsigned int)smbreq->mid ));
- return NT_STATUS_RETRY;
- }
-
bufsize = smb_size + 6*2;
if (!(aio_ex = create_aio_extra(NULL, fsp, bufsize))) {
if (req == NULL) {
DEBUG(3,("schedule_aio_wrote_and_X: aio_write failed. "
"Error %s\n", strerror(errno) ));
- SMB_VFS_STRICT_UNLOCK(conn, fsp, &aio_ex->lock);
TALLOC_FREE(aio_ex);
return NT_STATUS_RETRY;
}
if (!aio_add_req_to_fsp(fsp, req)) {
DEBUG(1, ("Could not add req to fsp\n"));
- SMB_VFS_STRICT_UNLOCK(conn, fsp, &aio_ex->lock);
TALLOC_FREE(aio_ex);
return NT_STATUS_RETRY;
}
contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_WRITE);
contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_WRITE);
- if (!aio_ex->write_through && !lp_syncalways(SNUM(fsp->conn))
+ if (!aio_ex->write_through && !lp_sync_always(SNUM(fsp->conn))
&& fsp->aio_write_behind) {
/* Lie to the client and immediately claim we finished the
* write. */
SSVAL(aio_ex->outbuf.data,smb_vwv2,numtowrite);
SSVAL(aio_ex->outbuf.data,smb_vwv4,(numtowrite>>16)&1);
show_msg((char *)aio_ex->outbuf.data);
- if (!srv_send_smb(aio_ex->smbreq->sconn,
+ if (!srv_send_smb(aio_ex->smbreq->xconn,
(char *)aio_ex->outbuf.data,
true, aio_ex->smbreq->seqnum+1,
IS_CONN_ENCRYPTED(fsp->conn),
"%s, offset %.0f, len = %u (mid = %u) "
"outstanding_aio_calls = %d\n",
fsp_str_dbg(fsp), (double)startpos, (unsigned int)numtowrite,
- (unsigned int)aio_ex->smbreq->mid, outstanding_aio_calls ));
+ (unsigned int)aio_ex->smbreq->mid,
+ get_outstanding_aio_calls() ));
return NT_STATUS_OK;
}
return;
}
- /* Unlock now we're done. */
- SMB_VFS_STRICT_UNLOCK(fsp->conn, fsp, &aio_ex->lock);
-
mark_file_modified(fsp);
if (fsp->aio_write_behind) {
}
show_msg(outbuf);
- if (!srv_send_smb(aio_ex->smbreq->sconn, outbuf,
+ if (!srv_send_smb(aio_ex->smbreq->xconn, outbuf,
true, aio_ex->smbreq->seqnum+1,
IS_CONN_ENCRYPTED(fsp->conn),
NULL)) {
return NT_STATUS_RETRY;
}
+ if (fsp->op == NULL) {
+ /* No AIO on internal opens. */
+ return NT_STATUS_RETRY;
+ }
+
if ((!min_aio_read_size || (smb_maxcnt < min_aio_read_size))
&& !SMB_VFS_AIO_FORCE(fsp)) {
/* Too small a read for aio request. */
return NT_STATUS_RETRY;
}
- if (outstanding_aio_calls >= aio_pending_size) {
- DEBUG(10,("smb2: Already have %d aio "
- "activities outstanding.\n",
- outstanding_aio_calls ));
- 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;
}
- init_strict_lock_struct(fsp, (uint64_t)smbreq->smbpid,
+ init_strict_lock_struct(fsp, fsp->op->global->open_persistent_id,
(uint64_t)startpos, (uint64_t)smb_maxcnt, READ_LOCK,
&aio_ex->lock);
if (req == NULL) {
DEBUG(0, ("smb2: SMB_VFS_PREAD_SEND failed. "
"Error %s\n", strerror(errno)));
- SMB_VFS_STRICT_UNLOCK(conn, fsp, &aio_ex->lock);
TALLOC_FREE(aio_ex);
return NT_STATUS_RETRY;
}
if (!aio_add_req_to_fsp(fsp, req)) {
DEBUG(1, ("Could not add req to fsp\n"));
- SMB_VFS_STRICT_UNLOCK(conn, fsp, &aio_ex->lock);
TALLOC_FREE(aio_ex);
return NT_STATUS_RETRY;
}
files_struct *fsp = aio_ex->fsp;
NTSTATUS status;
ssize_t nread;
- int err = 0;
+ struct vfs_aio_state vfs_aio_state = { 0 };
- nread = SMB_VFS_PREAD_RECV(req, &err);
+ nread = SMB_VFS_PREAD_RECV(req, &vfs_aio_state);
TALLOC_FREE(req);
DEBUG(10, ("pread_recv returned %d, err = %s\n", (int)nread,
- (nread == -1) ? strerror(err) : "no error"));
+ (nread == -1) ? strerror(vfs_aio_state.error) : "no error"));
if (fsp == NULL) {
- DEBUG( 3, ("aio_pread_smb2_done: file closed whilst "
- "aio outstanding (mid[%llu]).\n",
- (unsigned long long)aio_ex->smbreq->mid));
+ DEBUG(3, ("%s: request cancelled (mid[%ju])\n",
+ __func__, (uintmax_t)aio_ex->smbreq->mid));
TALLOC_FREE(aio_ex);
+ tevent_req_nterror(subreq, NT_STATUS_INTERNAL_ERROR);
return;
}
- /* Unlock now we're done. */
- SMB_VFS_STRICT_UNLOCK(fsp->conn, fsp, &aio_ex->lock);
-
/* Common error or success code processing for async or sync
read returns. */
- status = smb2_read_complete(subreq, nread, err);
+ status = smb2_read_complete(subreq, nread, vfs_aio_state.error);
if (nread > 0) {
fsp->fh->pos = aio_ex->offset + nread;
fsp_str_dbg(aio_ex->fsp),
(double)aio_ex->offset,
(unsigned int)nread,
- err, nt_errstr(status)));
+ vfs_aio_state.error, nt_errstr(status)));
if (!NT_STATUS_IS_OK(status)) {
tevent_req_nterror(subreq, status);
return NT_STATUS_RETRY;
}
+ if (fsp->op == NULL) {
+ /* No AIO on internal opens. */
+ return NT_STATUS_RETRY;
+ }
+
if ((!min_aio_write_size || (in_data.length < min_aio_write_size))
&& !SMB_VFS_AIO_FORCE(fsp)) {
/* Too small a write for aio request. */
return NT_STATUS_RETRY;
}
- if (outstanding_aio_calls >= aio_pending_size) {
- DEBUG(3,("smb2: Already have %d aio "
- "activities outstanding.\n",
- outstanding_aio_calls ));
- return NT_STATUS_RETRY;
- }
-
if (smbreq->unread_bytes) {
/* Can't do async with recvfile. */
return NT_STATUS_RETRY;
aio_ex->write_through = write_through;
- init_strict_lock_struct(fsp, (uint64_t)smbreq->smbpid,
+ init_strict_lock_struct(fsp, fsp->op->global->open_persistent_id,
in_offset, (uint64_t)in_data.length, WRITE_LOCK,
&aio_ex->lock);
if (req == NULL) {
DEBUG(3, ("smb2: SMB_VFS_PWRITE_SEND failed. "
"Error %s\n", strerror(errno)));
- SMB_VFS_STRICT_UNLOCK(conn, fsp, &aio_ex->lock);
TALLOC_FREE(aio_ex);
return NT_STATUS_RETRY;
}
if (!aio_add_req_to_fsp(fsp, req)) {
DEBUG(1, ("Could not add req to fsp\n"));
- SMB_VFS_STRICT_UNLOCK(conn, fsp, &aio_ex->lock);
TALLOC_FREE(aio_ex);
return NT_STATUS_RETRY;
}
(double)in_offset,
(unsigned int)in_data.length,
(unsigned int)aio_ex->smbreq->mid,
- outstanding_aio_calls ));
+ get_outstanding_aio_calls() ));
return NT_STATUS_OK;
}
(nwritten == -1) ? strerror(err) : "no error"));
if (fsp == NULL) {
- DEBUG( 3, ("aio_pwrite_smb2_done: file closed whilst "
- "aio outstanding (mid[%llu]).\n",
- (unsigned long long)aio_ex->smbreq->mid));
+ DEBUG(3, ("%s: request cancelled (mid[%ju])\n",
+ __func__, (uintmax_t)aio_ex->smbreq->mid));
TALLOC_FREE(aio_ex);
+ tevent_req_nterror(subreq, NT_STATUS_INTERNAL_ERROR);
return;
}
- /* Unlock now we're done. */
- SMB_VFS_STRICT_UNLOCK(fsp->conn, fsp, &aio_ex->lock);
+ mark_file_modified(fsp);
status = smb2_write_complete_nosync(subreq, nwritten, err);