2 Unix SMB/CIFS implementation.
4 POSIX NTVFS backend - Linux AIO calls
6 Copyright (C) Andrew Tridgell 2006
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "vfs_posix.h"
25 #include "lib/events/events.h"
26 #include "system/aio.h"
28 struct pvfs_aio_read_state {
29 struct ntvfs_request *req;
36 called when an aio read has finished
38 static void pvfs_aio_handler(struct event_context *ev, struct aio_event *ae,
39 int ret, void *private)
41 struct pvfs_aio_read_state *state = talloc_get_type(private,
42 struct pvfs_aio_read_state);
43 struct pvfs_file *f = state->f;
44 union smb_read *rd = state->rd;
47 /* errno is -ret on error */
48 state->req->async_states->status = pvfs_map_errno(f->pvfs, -ret);
49 state->req->async_states->send_fn(state->req);
53 f->handle->position = f->handle->seek_offset = rd->readx.in.offset + ret;
55 rd->readx.out.nread = ret;
56 rd->readx.out.remaining = 0xFFFF;
57 rd->readx.out.compaction_mode = 0;
59 talloc_steal(ev, state->ae);
61 state->req->async_states->status = NT_STATUS_OK;
62 state->req->async_states->send_fn(state->req);
69 NTSTATUS pvfs_aio_pread(struct ntvfs_request *req, union smb_read *rd,
70 struct pvfs_file *f, uint32_t maxcnt)
73 struct pvfs_aio_read_state *state;
75 state = talloc(req, struct pvfs_aio_read_state);
76 NT_STATUS_HAVE_NO_MEMORY(state);
78 io_prep_pread(&iocb, f->handle->fd, rd->readx.out.data,
79 maxcnt, rd->readx.in.offset);
80 state->ae = event_add_aio(req->ctx->event_ctx, req->ctx->event_ctx, &iocb,
81 pvfs_aio_handler, state);
82 if (state->ae == NULL) {
83 DEBUG(0,("Failed event_add_aio\n"));
85 return NT_STATUS_NOT_IMPLEMENTED;
92 req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC;