From: Jacek Caban Subject: [PATCH 7/7] server: Pass existing async object to fd_queue_async. Message-Id: <06ac6932-e516-4228-6dd4-5535e3aac155@codeweavers.com> Date: Wed, 15 Feb 2017 22:13:34 +0100 Signed-off-by: Jacek Caban --- server/async.c | 5 ----- server/change.c | 6 ++++-- server/device.c | 30 ++++++++++-------------------- server/fd.c | 33 +++++++++++++-------------------- server/file.h | 3 +-- server/mailslot.c | 4 ++-- server/named_pipe.c | 8 ++++---- server/serial.c | 4 ++-- 8 files changed, 36 insertions(+), 57 deletions(-) diff --git a/server/async.c b/server/async.c index aa50333..4e30c2e 100644 --- a/server/async.c +++ b/server/async.c @@ -474,11 +474,6 @@ struct iosb *async_get_iosb( struct async *async ) return async->iosb ? (struct iosb *)grab_object( async->iosb ) : NULL; } -const async_data_t *async_get_data( struct async *async ) -{ - return &async->data; -} - /* cancels all async I/O */ DECL_HANDLER(cancel_async) { diff --git a/server/change.c b/server/change.c index d7ebf3b..e112b8d 100644 --- a/server/change.c +++ b/server/change.c @@ -1246,7 +1246,10 @@ DECL_HANDLER(read_directory_changes) return; /* requests don't timeout */ - if (!(async = fd_queue_async( dir->fd, &req->async, NULL, ASYNC_TYPE_WAIT ))) goto end; + if (!(async = create_async( current, &req->async, NULL ))) goto end; + fd_queue_async( dir->fd, async, ASYNC_TYPE_WAIT ); + release_object( async ); + if (get_error()) goto end; /* assign it once */ if (!dir->filter) @@ -1266,7 +1269,6 @@ DECL_HANDLER(read_directory_changes) if (!inotify_adjust_changes( dir )) dnotify_adjust_changes( dir ); - release_object( async ); set_error(STATUS_PENDING); end: diff --git a/server/device.c b/server/device.c index d5574ae..7e291cc 100644 --- a/server/device.c +++ b/server/device.c @@ -242,7 +242,7 @@ static void irp_call_destroy( struct object *obj ) if (irp->thread) release_object( irp->thread ); } -static struct irp_call *create_irp( struct device_file *file, const irp_params_t *params, struct iosb *iosb ) +static struct irp_call *create_irp( struct device_file *file, const irp_params_t *params, struct async *async ) { struct irp_call *irp; @@ -258,12 +258,10 @@ static struct irp_call *create_irp( struct device_file *file, const irp_params_t irp->thread = NULL; irp->async = NULL; irp->params = *params; + irp->iosb = NULL; - if (iosb) - { - irp->iosb = (struct iosb *)grab_object( iosb ); - } - else if (!(irp->iosb = create_iosb( NULL, 0, 0 ))) + if (async) irp->iosb = async_get_iosb( async ); + if (!irp->iosb && !(irp->iosb = create_iosb( NULL, 0, 0 ))) { release_object( irp ); irp = NULL; @@ -471,11 +469,13 @@ 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_get_data( async ), irp->iosb, ASYNC_TYPE_WAIT ))) + fd_queue_async( file->fd, async, ASYNC_TYPE_WAIT ); + if (get_error()) { if (handle) close_handle( current->process, handle ); return 0; } + irp->async = (struct async *)grab_object( async ); add_irp_to_queue( file, irp, current ); set_error( STATUS_PENDING ); return handle; @@ -492,7 +492,6 @@ static obj_handle_t device_file_read( struct fd *fd, struct async *async, int bl struct irp_call *irp; obj_handle_t handle; irp_params_t params; - struct iosb *iosb; memset( ¶ms, 0, sizeof(params) ); params.read.major = IRP_MJ_READ; @@ -500,9 +499,7 @@ static obj_handle_t device_file_read( struct fd *fd, struct async *async, int bl params.read.pos = pos; params.read.file = file->user_ptr; - iosb = async_get_iosb( async ); - irp = create_irp( file, ¶ms, iosb ); - release_object( iosb ); + irp = create_irp( file, ¶ms, async ); if (!irp) return 0; handle = queue_irp( file, irp, async, blocking ); @@ -516,7 +513,6 @@ static obj_handle_t device_file_write( struct fd *fd, struct async *async, int b struct irp_call *irp; obj_handle_t handle; irp_params_t params; - struct iosb *iosb; memset( ¶ms, 0, sizeof(params) ); params.write.major = IRP_MJ_WRITE; @@ -524,9 +520,7 @@ static obj_handle_t device_file_write( struct fd *fd, struct async *async, int b params.write.pos = pos; params.write.file = file->user_ptr; - iosb = async_get_iosb( async ); - irp = create_irp( file, ¶ms, iosb ); - release_object( iosb ); + irp = create_irp( file, ¶ms, async ); if (!irp) return 0; handle = queue_irp( file, irp, async, blocking ); @@ -560,17 +554,13 @@ static obj_handle_t device_file_ioctl( struct fd *fd, ioctl_code_t code, struct struct irp_call *irp; obj_handle_t handle; irp_params_t params; - struct iosb *iosb; memset( ¶ms, 0, sizeof(params) ); params.ioctl.major = IRP_MJ_DEVICE_CONTROL; params.ioctl.code = code; params.ioctl.file = file->user_ptr; - iosb = create_iosb( get_req_data(), get_req_data_size(), get_reply_max_size() ); - if (!iosb) return 0; - irp = create_irp( file, ¶ms, iosb ); - release_object(iosb); + irp = create_irp( file, ¶ms, async ); if (!irp) return 0; handle = queue_irp( file, irp, async, blocking ); diff --git a/server/fd.c b/server/fd.c index 2ed639f..e279311 100644 --- a/server/fd.c +++ b/server/fd.c @@ -2030,23 +2030,22 @@ 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, struct iosb *iosb, int type ) +void fd_queue_async( struct fd *fd, struct async *async, int type ) { struct async_queue *queue; - struct async *async; switch (type) { case ASYNC_TYPE_READ: - if (!fd->read_q && !(fd->read_q = create_async_queue( fd ))) return NULL; + if (!fd->read_q && !(fd->read_q = create_async_queue( fd ))) return; queue = fd->read_q; break; case ASYNC_TYPE_WRITE: - if (!fd->write_q && !(fd->write_q = create_async_queue( fd ))) return NULL; + if (!fd->write_q && !(fd->write_q = create_async_queue( fd ))) return; queue = fd->write_q; break; case ASYNC_TYPE_WAIT: - if (!fd->wait_q && !(fd->wait_q = create_async_queue( fd ))) return NULL; + if (!fd->wait_q && !(fd->wait_q = create_async_queue( fd ))) return; queue = fd->wait_q; break; default: @@ -2054,18 +2053,15 @@ struct async *fd_queue_async( struct fd *fd, const async_data_t *data, struct io assert(0); } - if ((async = create_async( current, data, iosb ))) + queue_async( queue, async ); + + if (type != ASYNC_TYPE_WAIT) { - queue_async( queue, async ); - if (type != ASYNC_TYPE_WAIT) - { - if (!fd->inode) - set_fd_events( fd, fd->fd_ops->get_poll_events( fd ) ); - else /* regular files are always ready for read and write */ - async_wake_up( queue, STATUS_ALERTED ); - } + if (!fd->inode) + set_fd_events( fd, fd->fd_ops->get_poll_events( fd ) ); + else /* regular files are always ready for read and write */ + async_wake_up( queue, STATUS_ALERTED ); } - return async; } void fd_async_wake_up( struct fd *fd, int type, unsigned int status ) @@ -2098,11 +2094,8 @@ void no_fd_queue_async( struct fd *fd, struct async *async, int type, int count void default_fd_queue_async( struct fd *fd, struct async *async, int type, int count ) { - if ((async = fd_queue_async( fd, async_get_data( async ), NULL, type ))) - { - release_object( async ); - set_error( STATUS_PENDING ); - } + fd_queue_async( fd, async, type ); + if (!get_error()) set_error( STATUS_PENDING ); } /* default reselect_async() fd routine */ diff --git a/server/file.h b/server/file.h index 0a0e72f..ab25c14 100644 --- a/server/file.h +++ b/server/file.h @@ -97,7 +97,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, struct iosb *iosb, int type ); +extern void fd_queue_async( struct fd *fd, struct async *async, 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, struct async *async, int blocking, file_pos_t pos ); @@ -188,7 +188,6 @@ 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 *create_iosb( const void *in_data, data_size_t in_size, data_size_t out_size ); extern struct iosb *async_get_iosb( struct async *async ); -extern const async_data_t *async_get_data( struct async *async ); extern void cancel_process_asyncs( struct process *process ); /* access rights that require Unix read permission */ diff --git a/server/mailslot.c b/server/mailslot.c index 20bf99c..3de73d5 100644 --- a/server/mailslot.c +++ b/server/mailslot.c @@ -331,11 +331,11 @@ static void mailslot_queue_async( struct fd *fd, struct async *async, int type, assert(mailslot->obj.ops == &mailslot_ops); - if ((async = fd_queue_async( fd, async_get_data( async ), NULL, type ))) + fd_queue_async( fd, async, type ); + if (!get_error()) { async_set_timeout( async, mailslot->read_timeout ? mailslot->read_timeout : -1, STATUS_IO_TIMEOUT ); - release_object( async ); set_error( STATUS_PENDING ); } } diff --git a/server/named_pipe.c b/server/named_pipe.c index 1426023..fa18a72 100644 --- a/server/named_pipe.c +++ b/server/named_pipe.c @@ -554,13 +554,13 @@ static obj_handle_t pipe_server_flush( struct fd *fd, struct async *async, int b if (!pipe_data_remaining( server )) return 0; - if ((async = fd_queue_async( server->fd, async_get_data( async ), NULL, ASYNC_TYPE_WAIT ))) + fd_queue_async( server->fd, async, ASYNC_TYPE_WAIT ); + if (!get_error()) { /* there's no unix way to be alerted when a pipe becomes empty, so resort to polling */ if (!server->flush_poll) server->flush_poll = add_timeout_user( -TICKS_PER_SEC / 10, check_flushed, server ); if (blocking) handle = alloc_handle( current->process, async, SYNCHRONIZE, 0 ); - release_object( async ); set_error( STATUS_PENDING ); } return handle; @@ -600,12 +600,12 @@ static obj_handle_t pipe_server_ioctl( struct fd *fd, ioctl_code_t code, struct { case ps_idle_server: case ps_wait_connect: - if ((async = fd_queue_async( server->ioctl_fd, async_get_data( async ), NULL, ASYNC_TYPE_WAIT ))) + fd_queue_async( server->ioctl_fd, async, ASYNC_TYPE_WAIT ); + if (!get_error()) { if (blocking) wait_handle = alloc_handle( current->process, async, SYNCHRONIZE, 0 ); set_server_state( server, ps_wait_open ); if (server->pipe->waiters) async_wake_up( server->pipe->waiters, STATUS_SUCCESS ); - release_object( async ); set_error( STATUS_PENDING ); return wait_handle; } diff --git a/server/serial.c b/server/serial.c index 58170cd..fede7d9 100644 --- a/server/serial.c +++ b/server/serial.c @@ -200,10 +200,10 @@ static void serial_queue_async( struct fd *fd, struct async *async, int type, in break; } - if ((async = fd_queue_async( fd, async_get_data( async ), NULL, type ))) + fd_queue_async( fd, async, type ); + if (!get_error()) { if (timeout) async_set_timeout( async, timeout * -10000, STATUS_TIMEOUT ); - release_object( async ); set_error( STATUS_PENDING ); } }