From: Jacek Caban Subject: [PATCH 02/10] server: Store iosb in async object. Message-Id: <3551974d-11d3-18dc-9735-9972b5f115f8@codeweavers.com> Date: Wed, 19 Oct 2016 19:05:09 +0200 Signed-off-by: Jacek Caban --- server/async.c | 15 ++++++++++++++- server/change.c | 2 +- server/device.c | 2 +- server/fd.c | 6 +++--- server/file.h | 5 +++-- server/mailslot.c | 2 +- server/named_pipe.c | 6 +++--- server/serial.c | 2 +- server/sock.c | 4 ++-- 9 files changed, 29 insertions(+), 15 deletions(-) diff --git a/server/async.c b/server/async.c index 57499c8..733558d 100644 --- a/server/async.c +++ b/server/async.c @@ -44,6 +44,7 @@ struct async int signaled; struct event *event; async_data_t data; /* data for async I/O call */ + struct iosb *iosb; /* I/O status block */ }; static void async_dump( struct object *obj, int verbose ); @@ -137,6 +138,7 @@ static void async_destroy( struct object *obj ) if (async->timeout) remove_timeout_user( async->timeout ); if (async->event) release_object( async->event ); + if (async->iosb) release_iosb( async->iosb ); release_object( async->queue ); release_object( async->thread ); } @@ -221,7 +223,8 @@ void free_async_queue( struct async_queue *queue ) } /* create an async on a given queue of a fd */ -struct async *create_async( struct thread *thread, struct async_queue *queue, const async_data_t *data ) +struct async *create_async( struct thread *thread, struct async_queue *queue, const async_data_t *data, + struct iosb *iosb ) { struct event *event = NULL; struct async *async; @@ -243,6 +246,9 @@ struct async *create_async( struct thread *thread, struct async_queue *queue, co async->queue = (struct async_queue *)grab_object( queue ); async->signaled = 0; + if (iosb) async->iosb = grab_iosb( iosb ); + else async->iosb = NULL; + list_add_tail( &queue->queue, &async->queue_entry ); grab_object( async ); @@ -404,6 +410,13 @@ struct iosb *alloc_iosb( const void *in_data, data_size_t in_size, data_size_t o return iosb; } +/* grab iosb reference */ +struct iosb *grab_iosb(struct iosb *iosb) +{ + iosb->refcount++; + return iosb; +} + /* release iosb reference */ void release_iosb( struct iosb *iosb ) { diff --git a/server/change.c b/server/change.c index 7c0ca99..23d4ac8 100644 --- a/server/change.c +++ b/server/change.c @@ -1248,7 +1248,7 @@ DECL_HANDLER(read_directory_changes) return; /* requests don't timeout */ - if (!(async = fd_queue_async( dir->fd, &req->async, ASYNC_TYPE_WAIT ))) goto end; + if (!(async = fd_queue_async( dir->fd, &req->async, NULL, ASYNC_TYPE_WAIT ))) goto end; /* assign it once */ if (!dir->filter) diff --git a/server/device.c b/server/device.c index 8cc116b..6a05c06 100644 --- a/server/device.c +++ b/server/device.c @@ -487,7 +487,7 @@ static obj_handle_t queue_irp( struct device_file *file, struct irp_call *irp, if (blocking && !(handle = alloc_handle( current->process, irp, SYNCHRONIZE, 0 ))) return 0; - if (!(irp->async = fd_queue_async( file->fd, async_data, ASYNC_TYPE_WAIT ))) + if (!(irp->async = fd_queue_async( file->fd, async_data, irp->iosb, ASYNC_TYPE_WAIT ))) { if (handle) close_handle( current->process, handle ); return 0; diff --git a/server/fd.c b/server/fd.c index 17b1b66..0e54206 100644 --- a/server/fd.c +++ b/server/fd.c @@ -2030,7 +2030,7 @@ void default_poll_event( struct fd *fd, int event ) else if (!fd->inode) set_fd_events( fd, fd->fd_ops->get_poll_events( fd ) ); } -struct async *fd_queue_async( struct fd *fd, const async_data_t *data, int type ) +struct async *fd_queue_async( struct fd *fd, const async_data_t *data, struct iosb *iosb, int type ) { struct async_queue *queue; struct async *async; @@ -2054,7 +2054,7 @@ struct async *fd_queue_async( struct fd *fd, const async_data_t *data, int type assert(0); } - if ((async = create_async( current, queue, data )) && type != ASYNC_TYPE_WAIT) + if ((async = create_async( current, queue, data, iosb )) && type != ASYNC_TYPE_WAIT) { if (!fd->inode) set_fd_events( fd, fd->fd_ops->get_poll_events( fd ) ); @@ -2096,7 +2096,7 @@ void default_fd_queue_async( struct fd *fd, const async_data_t *data, int type, { struct async *async; - if ((async = fd_queue_async( fd, data, type ))) + if ((async = fd_queue_async( fd, data, NULL, type ))) { release_object( async ); set_error( STATUS_PENDING ); diff --git a/server/file.h b/server/file.h index 6b1a6aa..c0a53a2 100644 --- a/server/file.h +++ b/server/file.h @@ -99,7 +99,7 @@ extern int default_fd_signaled( struct object *obj, struct wait_queue_entry *ent extern unsigned int default_fd_map_access( struct object *obj, unsigned int access ); extern int default_fd_get_poll_events( struct fd *fd ); extern void default_poll_event( struct fd *fd, int event ); -extern struct async *fd_queue_async( struct fd *fd, const async_data_t *data, int type ); +extern struct async *fd_queue_async( struct fd *fd, 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 ); @@ -180,7 +180,7 @@ extern struct object *create_serial( struct fd *fd ); extern struct async_queue *create_async_queue( struct fd *fd ); 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 ); + const async_data_t *data, struct iosb *iosb ); 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 ); @@ -193,6 +193,7 @@ extern void async_wake_up( struct async_queue *queue, unsigned int status ); extern struct completion *fd_get_completion( struct fd *fd, apc_param_t *p_key ); extern void fd_copy_completion( struct fd *src, struct fd *dst ); extern struct iosb *alloc_iosb( const void *in_data, data_size_t in_size, data_size_t out_size ); +extern struct iosb *grab_iosb( struct iosb *iosb ); extern void release_iosb( struct iosb *iosb ); /* access rights that require Unix read permission */ diff --git a/server/mailslot.c b/server/mailslot.c index 13e6703..2757028 100644 --- a/server/mailslot.c +++ b/server/mailslot.c @@ -335,7 +335,7 @@ static void mailslot_queue_async( struct fd *fd, const async_data_t *data, int t assert(mailslot->obj.ops == &mailslot_ops); - if ((async = fd_queue_async( fd, data, type ))) + if ((async = fd_queue_async( fd, data, NULL, type ))) { async_set_timeout( async, mailslot->read_timeout ? mailslot->read_timeout : -1, STATUS_IO_TIMEOUT ); diff --git a/server/named_pipe.c b/server/named_pipe.c index cfee4d5..d7f6f3a 100644 --- a/server/named_pipe.c +++ b/server/named_pipe.c @@ -563,7 +563,7 @@ static obj_handle_t pipe_server_flush( struct fd *fd, const async_data_t *async_ if (!pipe_data_remaining( server )) return 0; - if ((async = fd_queue_async( server->fd, async_data, ASYNC_TYPE_WAIT ))) + if ((async = fd_queue_async( server->fd, async_data, NULL, ASYNC_TYPE_WAIT ))) { /* there's no unix way to be alerted when a pipe becomes empty, so resort to polling */ if (!server->flush_poll) @@ -610,7 +610,7 @@ static obj_handle_t pipe_server_ioctl( struct fd *fd, ioctl_code_t code, const a { case ps_idle_server: case ps_wait_connect: - if ((async = fd_queue_async( server->ioctl_fd, async_data, ASYNC_TYPE_WAIT ))) + if ((async = fd_queue_async( server->ioctl_fd, async_data, NULL, ASYNC_TYPE_WAIT ))) { if (blocking) wait_handle = alloc_handle( current->process, async, SYNCHRONIZE, 0 ); set_server_state( server, ps_wait_open ); @@ -865,7 +865,7 @@ static obj_handle_t named_pipe_device_ioctl( struct fd *fd, ioctl_code_t code, if (!pipe->waiters && !(pipe->waiters = create_async_queue( NULL ))) goto done; - if ((async = create_async( current, pipe->waiters, async_data ))) + if ((async = create_async( current, pipe->waiters, async_data, NULL ))) { timeout_t when = buffer->TimeoutSpecified ? buffer->Timeout.QuadPart : pipe->timeout; async_set_timeout( async, when, STATUS_IO_TIMEOUT ); diff --git a/server/serial.c b/server/serial.c index 03d726a..c3cd43d 100644 --- a/server/serial.c +++ b/server/serial.c @@ -202,7 +202,7 @@ static void serial_queue_async( struct fd *fd, const async_data_t *data, int typ break; } - if ((async = fd_queue_async( fd, data, type ))) + if ((async = fd_queue_async( fd, data, NULL, type ))) { if (timeout) async_set_timeout( async, timeout * -10000, STATUS_TIMEOUT ); release_object( async ); diff --git a/server/sock.c b/server/sock.c index 0de6f68..eb84cc5 100644 --- a/server/sock.c +++ b/server/sock.c @@ -554,7 +554,7 @@ obj_handle_t sock_ioctl( struct fd *fd, ioctl_code_t code, const async_data_t *a return 0; } if (!(ifchange_q = sock_get_ifchange_q( sock ))) return 0; - if (!(async = create_async( current, ifchange_q, async_data ))) return 0; + if (!(async = create_async( current, ifchange_q, async_data, NULL ))) return 0; if (blocking) wait_handle = alloc_handle( current->process, async, SYNCHRONIZE, 0 ); release_object( async ); set_error( STATUS_PENDING ); @@ -595,7 +595,7 @@ static void sock_queue_async( struct fd *fd, const async_data_t *data, int type, return; } - if (!(async = create_async( current, queue, data ))) return; + if (!(async = create_async( current, queue, data, NULL ))) return; release_object( async ); sock_reselect( sock );