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;
35 struct pvfs_aio_write_state {
36 struct ntvfs_request *req;
43 called when an aio read has finished
45 static void pvfs_aio_read_handler(struct event_context *ev, struct aio_event *ae,
46 int ret, void *private)
48 struct pvfs_aio_read_state *state = talloc_get_type(private,
49 struct pvfs_aio_read_state);
50 struct pvfs_file *f = state->f;
51 union smb_read *rd = state->rd;
54 /* errno is -ret on error */
55 state->req->async_states->status = pvfs_map_errno(f->pvfs, -ret);
56 state->req->async_states->send_fn(state->req);
60 f->handle->position = f->handle->seek_offset = rd->readx.in.offset + ret;
62 rd->readx.out.nread = ret;
63 rd->readx.out.remaining = 0xFFFF;
64 rd->readx.out.compaction_mode = 0;
66 talloc_steal(ev, state->ae);
68 state->req->async_states->status = NT_STATUS_OK;
69 state->req->async_states->send_fn(state->req);
76 NTSTATUS pvfs_aio_pread(struct ntvfs_request *req, union smb_read *rd,
77 struct pvfs_file *f, uint32_t maxcnt)
80 struct pvfs_aio_read_state *state;
82 state = talloc(req, struct pvfs_aio_read_state);
83 NT_STATUS_HAVE_NO_MEMORY(state);
85 io_prep_pread(&iocb, f->handle->fd, rd->readx.out.data,
86 maxcnt, rd->readx.in.offset);
87 state->ae = event_add_aio(req->ctx->event_ctx, req->ctx->event_ctx, &iocb,
88 pvfs_aio_read_handler, state);
89 if (state->ae == NULL) {
90 DEBUG(0,("Failed event_add_aio\n"));
92 return NT_STATUS_NOT_IMPLEMENTED;
99 req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC;
108 called when an aio write has finished
110 static void pvfs_aio_write_handler(struct event_context *ev, struct aio_event *ae,
111 int ret, void *private)
113 struct pvfs_aio_write_state *state = talloc_get_type(private,
114 struct pvfs_aio_write_state);
115 struct pvfs_file *f = state->f;
116 union smb_write *wr = state->wr;
119 /* errno is -ret on error */
120 state->req->async_states->status = pvfs_map_errno(f->pvfs, -ret);
121 state->req->async_states->send_fn(state->req);
125 f->handle->seek_offset = wr->writex.in.offset + ret;
127 wr->writex.out.nwritten = ret;
128 wr->writex.out.remaining = 0;
130 talloc_steal(ev, state->ae);
132 state->req->async_states->status = NT_STATUS_OK;
133 state->req->async_states->send_fn(state->req);
140 NTSTATUS pvfs_aio_pwrite(struct ntvfs_request *req, union smb_write *wr,
144 struct pvfs_aio_write_state *state;
146 state = talloc(req, struct pvfs_aio_write_state);
147 NT_STATUS_HAVE_NO_MEMORY(state);
149 io_prep_pwrite(&iocb, f->handle->fd, wr->writex.in.data,
150 wr->writex.in.count, wr->writex.in.offset);
151 state->ae = event_add_aio(req->ctx->event_ctx, req->ctx->event_ctx, &iocb,
152 pvfs_aio_write_handler, state);
153 if (state->ae == NULL) {
154 DEBUG(0,("Failed event_add_aio\n"));
156 return NT_STATUS_NOT_IMPLEMENTED;
163 req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC;