From: Jacek Caban Subject: [PATCH 5/9] server: Create async objects in read and write request handlers. Message-Id: <88d1775a-b86d-4cc6-639d-66d816bb12f3@codeweavers.com> Date: Fri, 10 Feb 2017 16:10:30 +0100 Signed-off-by: Jacek Caban --- server/async.c | 5 +++++ server/device.c | 22 +++++++++++----------- server/fd.c | 24 ++++++++++++++++++------ server/file.h | 9 +++++---- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/server/async.c b/server/async.c index 8ff0a87..49cf58a 100644 --- a/server/async.c +++ b/server/async.c @@ -275,6 +275,11 @@ struct async *create_async( struct thread *thread, struct async_queue *queue, co return async; } +const async_data_t *async_get_data( struct async *async ) +{ + return &async->data; +} + /* set the timeout of an async operation */ void async_set_timeout( struct async *async, timeout_t timeout, unsigned int status ) { diff --git a/server/device.c b/server/device.c index dbbfb1a..3e8d8ca 100644 --- a/server/device.c +++ b/server/device.c @@ -175,9 +175,9 @@ static struct fd *device_file_get_fd( struct object *obj ); static int device_file_close_handle( struct object *obj, struct process *process, obj_handle_t handle ); static void device_file_destroy( struct object *obj ); static enum server_fd_type device_file_get_fd_type( struct fd *fd ); -static obj_handle_t device_file_read( struct fd *fd, const async_data_t *async_data, int blocking, +static obj_handle_t device_file_read( struct fd *fd, struct async *async, int blocking, file_pos_t pos, struct iosb *iosb ); -static obj_handle_t device_file_write( struct fd *fd, const async_data_t *async_data, int blocking, +static obj_handle_t device_file_write( struct fd *fd, struct async *async, int blocking, file_pos_t pos, struct iosb *iosb ); static obj_handle_t device_file_flush( struct fd *fd, const async_data_t *async_data, int blocking ); static obj_handle_t device_file_ioctl( struct fd *fd, ioctl_code_t code, const async_data_t *async_data, @@ -468,19 +468,19 @@ static void set_file_user_ptr( struct device_file *file, client_ptr_t ptr ) } /* queue an irp to the device */ -static obj_handle_t queue_irp( struct device_file *file, struct irp_call *irp, +static obj_handle_t queue_irp( struct device_file *file, struct irp_call *irp, struct async *async, const async_data_t *async_data, int blocking ) { obj_handle_t handle = 0; if (blocking && !(handle = alloc_handle( current->process, irp, SYNCHRONIZE, 0 ))) return 0; - if (!(irp->async = fd_queue_async( file->fd, NULL, async_data, irp->iosb, ASYNC_TYPE_WAIT ))) + if (!(irp->async = fd_queue_async( file->fd, async, async_data, irp->iosb, ASYNC_TYPE_WAIT ))) { if (handle) close_handle( current->process, handle ); return 0; } - irp->user_arg = async_data->arg; + irp->user_arg = async_get_data(irp->async)->arg; add_irp_to_queue( file, irp, current ); set_error( STATUS_PENDING ); return handle; @@ -491,7 +491,7 @@ static enum server_fd_type device_file_get_fd_type( struct fd *fd ) return FD_TYPE_DEVICE; } -static obj_handle_t device_file_read( struct fd *fd, const async_data_t *async_data, int blocking, +static obj_handle_t device_file_read( struct fd *fd, struct async *async, int blocking, file_pos_t pos, struct iosb *iosb ) { struct device_file *file = get_fd_user( fd ); @@ -508,12 +508,12 @@ static obj_handle_t device_file_read( struct fd *fd, const async_data_t *async_d irp = create_irp( file, ¶ms, iosb ); if (!irp) return 0; - handle = queue_irp( file, irp, async_data, blocking ); + handle = queue_irp( file, irp, async, NULL, blocking ); release_object( irp ); return handle; } -static obj_handle_t device_file_write( struct fd *fd, const async_data_t *async_data, int blocking, +static obj_handle_t device_file_write( struct fd *fd, struct async *async, int blocking, file_pos_t pos, struct iosb *iosb ) { struct device_file *file = get_fd_user( fd ); @@ -530,7 +530,7 @@ static obj_handle_t device_file_write( struct fd *fd, const async_data_t *async_ irp = create_irp( file, ¶ms, iosb ); if (!irp) return 0; - handle = queue_irp( file, irp, async_data, blocking ); + handle = queue_irp( file, irp, async, NULL, blocking ); release_object( irp ); return handle; } @@ -549,7 +549,7 @@ static obj_handle_t device_file_flush( struct fd *fd, const async_data_t *async_ irp = create_irp( file, ¶ms, NULL ); if (!irp) return 0; - handle = queue_irp( file, irp, async_data, blocking ); + handle = queue_irp( file, irp, NULL, async_data, blocking ); release_object( irp ); return handle; } @@ -574,7 +574,7 @@ static obj_handle_t device_file_ioctl( struct fd *fd, ioctl_code_t code, const a release_object(iosb); if (!irp) return 0; - handle = queue_irp( file, irp, async_data, blocking ); + handle = queue_irp( file, irp, NULL, async_data, blocking ); release_object( irp ); return handle; } diff --git a/server/fd.c b/server/fd.c index 086f9ea..32a7bc9 100644 --- a/server/fd.c +++ b/server/fd.c @@ -2166,14 +2166,14 @@ static void unmount_device( struct fd *device_fd ) } /* default read() routine */ -obj_handle_t no_fd_read( struct fd *fd, const async_data_t *async, int blocking, file_pos_t pos, struct iosb *iosb ) +obj_handle_t no_fd_read( struct fd *fd, struct async *async, int blocking, file_pos_t pos, struct iosb *iosb ) { set_error( STATUS_OBJECT_TYPE_MISMATCH ); return 0; } /* default write() routine */ -obj_handle_t no_fd_write( struct fd *fd, const async_data_t *async, int blocking, +obj_handle_t no_fd_write( struct fd *fd, struct async *async, int blocking, file_pos_t pos, struct iosb *iosb ) { set_error( STATUS_OBJECT_TYPE_MISMATCH ); @@ -2449,14 +2449,20 @@ DECL_HANDLER(get_handle_fd) DECL_HANDLER(read) { struct fd *fd = get_handle_fd_obj( current->process, req->async.handle, FILE_READ_DATA ); + struct async *async; struct iosb *iosb; if (!fd) return; if ((iosb = create_iosb( NULL, 0, get_reply_max_size() ))) { - reply->wait = fd->fd_ops->read( fd, &req->async, req->blocking, req->pos, iosb ); - reply->options = fd->options; + async = create_async( current, NULL, &req->async, iosb ); + if (async) + { + reply->wait = fd->fd_ops->read( fd, async, req->blocking, req->pos, iosb ); + reply->options = fd->options; + release_object( async ); + } release_object( iosb ); } release_object( fd ); @@ -2466,14 +2472,20 @@ DECL_HANDLER(read) DECL_HANDLER(write) { struct fd *fd = get_handle_fd_obj( current->process, req->async.handle, FILE_WRITE_DATA ); + struct async *async; struct iosb *iosb; if (!fd) return; if ((iosb = create_iosb( get_req_data(), get_req_data_size(), 0 ))) { - reply->wait = fd->fd_ops->write( fd, &req->async, req->blocking, req->pos, iosb ); - reply->options = fd->options; + async = create_async( current, NULL, &req->async, iosb ); + if (async) + { + reply->wait = fd->fd_ops->write( fd, async, req->blocking, req->pos, iosb ); + reply->options = fd->options; + release_object( async ); + } release_object( iosb ); } release_object( fd ); diff --git a/server/file.h b/server/file.h index 30baef4..879dbd9 100644 --- a/server/file.h +++ b/server/file.h @@ -52,9 +52,9 @@ struct fd_ops /* get file information */ enum server_fd_type (*get_fd_type)(struct fd *fd); /* perform a read on the file */ - obj_handle_t (*read)(struct fd *, const async_data_t *, int, file_pos_t, struct iosb * ); + obj_handle_t (*read)(struct fd *, struct async *, int, file_pos_t, struct iosb * ); /* perform a write on the file */ - obj_handle_t (*write)(struct fd *, const async_data_t *, int, file_pos_t, struct iosb * ); + obj_handle_t (*write)(struct fd *, struct async *, int, file_pos_t, struct iosb * ); /* flush the object buffers */ obj_handle_t (*flush)(struct fd *, const async_data_t *, int); /* perform an ioctl on the file */ @@ -100,9 +100,9 @@ extern void default_poll_event( struct fd *fd, int event ); extern struct async *fd_queue_async( struct fd *fd, struct async *async, const async_data_t *data, struct iosb *iosb, int type ); extern void fd_async_wake_up( struct fd *fd, int type, unsigned int status ); extern void fd_reselect_async( struct fd *fd, struct async_queue *queue ); -extern obj_handle_t no_fd_read( struct fd *fd, const async_data_t *async, int blocking, file_pos_t pos, +extern obj_handle_t no_fd_read( struct fd *fd, struct async *async, int blocking, file_pos_t pos, struct iosb *iosb ); -extern obj_handle_t no_fd_write( struct fd *fd, const async_data_t *async, int blocking, +extern obj_handle_t no_fd_write( struct fd *fd, struct async *async, int blocking, file_pos_t pos, struct iosb *iosb ); extern obj_handle_t no_fd_flush( struct fd *fd, const async_data_t *async, int blocking ); extern obj_handle_t no_fd_ioctl( struct fd *fd, ioctl_code_t code, const async_data_t *async, int blocking ); @@ -180,6 +180,7 @@ extern void free_async_queue( struct async_queue *queue ); extern struct async *create_async( struct thread *thread, struct async_queue *queue, const async_data_t *data, struct iosb *iosb ); extern void queue_async( struct async_queue *queue, struct async *async ); +extern const async_data_t *async_get_data( struct async *async ); extern void async_set_timeout( struct async *async, timeout_t timeout, unsigned int status ); extern void async_set_result( struct object *obj, unsigned int status, apc_param_t total, client_ptr_t apc, client_ptr_t apc_arg );