summaryrefslogtreecommitdiff
path: root/source4/ntvfs/posix/pvfs_aio.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2007-01-09 04:04:26 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:37:16 -0500
commite0e96ae80d21c6b94e05fbf3af457001a005ce09 (patch)
treef5c50ceb4dd0cb464cab8ab848e46ba19ff0a976 /source4/ntvfs/posix/pvfs_aio.c
parent2ed11961292c928be5166b1774e05676bbfabce8 (diff)
downloadsamba-e0e96ae80d21c6b94e05fbf3af457001a005ce09.tar.gz
samba-e0e96ae80d21c6b94e05fbf3af457001a005ce09.tar.bz2
samba-e0e96ae80d21c6b94e05fbf3af457001a005ce09.zip
r20624: added AIO read to pvfs backend
(This used to be commit d6e20d6d8c5c207e7f04b0d0523224437b209917)
Diffstat (limited to 'source4/ntvfs/posix/pvfs_aio.c')
-rw-r--r--source4/ntvfs/posix/pvfs_aio.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/source4/ntvfs/posix/pvfs_aio.c b/source4/ntvfs/posix/pvfs_aio.c
new file mode 100644
index 0000000000..262b856aa9
--- /dev/null
+++ b/source4/ntvfs/posix/pvfs_aio.c
@@ -0,0 +1,96 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ POSIX NTVFS backend - Linux AIO calls
+
+ Copyright (C) Andrew Tridgell 2006
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "vfs_posix.h"
+#include "lib/events/events.h"
+#include "system/aio.h"
+
+struct pvfs_aio_read_state {
+ struct ntvfs_request *req;
+ union smb_read *rd;
+ struct pvfs_file *f;
+ struct aio_event *ae;
+};
+
+/*
+ called when an aio read has finished
+*/
+static void pvfs_aio_handler(struct event_context *ev, struct aio_event *ae,
+ int ret, void *private)
+{
+ struct pvfs_aio_read_state *state = talloc_get_type(private,
+ struct pvfs_aio_read_state);
+ struct pvfs_file *f = state->f;
+ union smb_read *rd = state->rd;
+
+ if (ret < 0) {
+ /* errno is -ret on error */
+ state->req->async_states->status = pvfs_map_errno(f->pvfs, -ret);
+ state->req->async_states->send_fn(state->req);
+ return;
+ }
+
+ f->handle->position = f->handle->seek_offset = rd->readx.in.offset + ret;
+
+ rd->readx.out.nread = ret;
+ rd->readx.out.remaining = 0xFFFF;
+ rd->readx.out.compaction_mode = 0;
+
+ talloc_steal(ev, state->ae);
+
+ state->req->async_states->status = NT_STATUS_OK;
+ state->req->async_states->send_fn(state->req);
+}
+
+
+/*
+ read from a file
+*/
+NTSTATUS pvfs_aio_pread(struct ntvfs_request *req, union smb_read *rd,
+ struct pvfs_file *f, uint32_t maxcnt)
+{
+ struct iocb iocb;
+ struct pvfs_aio_read_state *state;
+
+ state = talloc(req, struct pvfs_aio_read_state);
+ NT_STATUS_HAVE_NO_MEMORY(state);
+
+ io_prep_pread(&iocb, f->handle->fd, rd->readx.out.data,
+ maxcnt, rd->readx.in.offset);
+ state->ae = event_add_aio(req->ctx->event_ctx, req->ctx->event_ctx, &iocb,
+ pvfs_aio_handler, state);
+ if (state->ae == NULL) {
+ DEBUG(0,("Failed event_add_aio\n"));
+ talloc_free(state);
+ return NT_STATUS_NOT_IMPLEMENTED;
+ }
+
+ state->req = req;
+ state->rd = rd;
+ state->f = f;
+
+ req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC;
+
+ return NT_STATUS_OK;
+}
+