1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

s3-vfs: async pread

Signed-off-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke 2012-06-26 14:30:59 +02:00 committed by Jeremy Allison
parent c6e456d9c0
commit e24aed15fa
4 changed files with 131 additions and 0 deletions

View File

@ -515,6 +515,13 @@ struct vfs_fn_pointers {
int (*close_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp);
ssize_t (*read_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, void *data, size_t n);
ssize_t (*pread_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, void *data, size_t n, off_t offset);
struct tevent_req *(*pread_send_fn)(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct files_struct *fsp,
void *data,
size_t n, off_t offset);
ssize_t (*pread_recv_fn)(struct tevent_req *req, int *err);
ssize_t (*write_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const void *data, size_t n);
ssize_t (*pwrite_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const void *data, size_t n, off_t offset);
struct tevent_req *(*pwrite_send_fn)(struct vfs_handle_struct *handle,
@ -885,6 +892,14 @@ ssize_t smb_vfs_call_read(struct vfs_handle_struct *handle,
ssize_t smb_vfs_call_pread(struct vfs_handle_struct *handle,
struct files_struct *fsp, void *data, size_t n,
off_t offset);
struct tevent_req *smb_vfs_call_pread_send(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct files_struct *fsp,
void *data,
size_t n, off_t offset);
ssize_t SMB_VFS_PREAD_RECV(struct tevent_req *req, int *perrno);
ssize_t smb_vfs_call_write(struct vfs_handle_struct *handle,
struct files_struct *fsp, const void *data,
size_t n);

View File

@ -158,6 +158,13 @@
#define SMB_VFS_NEXT_PREAD(handle, fsp, data, n, off) \
smb_vfs_call_pread((handle)->next, (fsp), (data), (n), (off))
#define SMB_VFS_PREAD_SEND(mem_ctx, ev, fsp, data, n, off) \
smb_vfs_call_pread_send((fsp)->conn->vfs_handles, (mem_ctx), (ev), \
(fsp), (data), (n), (off))
#define SMB_VFS_NEXT_PREAD_SEND(mem_ctx, ev, handle, fsp, data, n, off) \
smb_vfs_call_pread_send((handle)->next, (mem_ctx), (ev), (fsp), \
(data), (n), (off))
#define SMB_VFS_WRITE(fsp, data, n) \
smb_vfs_call_write((fsp)->conn->vfs_handles, (fsp), (data), (n))
#define SMB_VFS_NEXT_WRITE(handle, fsp, data, n) \

View File

@ -580,6 +580,49 @@ static ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, void
return result;
}
struct vfswrap_pread_state {
ssize_t ret;
};
static struct tevent_req *vfswrap_pread_send(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct files_struct *fsp,
void *data,
size_t n, off_t offset)
{
struct tevent_req *req;
struct vfswrap_pread_state *state;
int saved_errno;
req = tevent_req_create(req, &state, struct vfswrap_pread_state);
if (req == NULL) {
return NULL;
}
START_PROFILE_BYTES(syscall_pread, n);
state->ret = sys_pread(fsp->fh->fd, data, n, offset);
saved_errno = errno;
END_PROFILE(syscall_pread);
if (state->ret == -1) {
tevent_req_error(req, saved_errno);
return tevent_req_post(req, ev);
}
tevent_req_done(req);
return tevent_req_post(req, ev);
}
static ssize_t vfswrap_pread_recv(struct tevent_req *req, int *err)
{
struct vfswrap_pread_state *state = tevent_req_data(
req, struct vfswrap_pread_state);
if (tevent_req_is_unix_error(req, err)) {
return -1;
}
return state->ret;
}
static ssize_t vfswrap_write(vfs_handle_struct *handle, files_struct *fsp, const void *data, size_t n)
{
ssize_t result;
@ -2255,6 +2298,8 @@ static struct vfs_fn_pointers vfs_default_fns = {
.close_fn = vfswrap_close,
.read_fn = vfswrap_read,
.pread_fn = vfswrap_pread,
.pread_send_fn = vfswrap_pread_send,
.pread_recv_fn = vfswrap_pread_recv,
.write_fn = vfswrap_write,
.pwrite_fn = vfswrap_pwrite,
.pwrite_send_fn = vfswrap_pwrite_send,

View File

@ -1541,6 +1541,70 @@ ssize_t smb_vfs_call_pread(struct vfs_handle_struct *handle,
return handle->fns->pread_fn(handle, fsp, data, n, offset);
}
struct smb_vfs_call_pread_state {
ssize_t (*recv_fn)(struct tevent_req *req, int *err);
ssize_t retval;
};
static void smb_vfs_call_pread_done(struct tevent_req *subreq);
struct tevent_req *smb_vfs_call_pread_send(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct files_struct *fsp,
void *data,
size_t n, off_t offset)
{
struct tevent_req *req, *subreq;
struct smb_vfs_call_pread_state *state;
req = tevent_req_create(mem_ctx, &state,
struct smb_vfs_call_pread_state);
if (req == NULL) {
return NULL;
}
VFS_FIND(pread_send);
state->recv_fn = handle->fns->pread_recv_fn;
subreq = handle->fns->pread_send_fn(handle, state, ev, fsp, data, n,
offset);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
tevent_req_set_callback(subreq, smb_vfs_call_pread_done, req);
return req;
}
static void smb_vfs_call_pread_done(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(
subreq, struct tevent_req);
struct smb_vfs_call_pread_state *state = tevent_req_data(
req, struct smb_vfs_call_pread_state);
int err;
state->retval = state->recv_fn(subreq, &err);
TALLOC_FREE(subreq);
if (state->retval == -1) {
tevent_req_error(req, err);
return;
}
tevent_req_done(req);
}
ssize_t SMB_VFS_PREAD_RECV(struct tevent_req *req, int *perrno)
{
struct smb_vfs_call_pread_state *state = tevent_req_data(
req, struct smb_vfs_call_pread_state);
int err;
if (tevent_req_is_unix_error(req, &err)) {
*perrno = err;
return -1;
}
return state->retval;
}
ssize_t smb_vfs_call_write(struct vfs_handle_struct *handle,
struct files_struct *fsp, const void *data,
size_t n)