Re: [PATCH v2 06/13] io_uring: generalize fixed_file_ref_node functionality

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/12/2020 22:15, Bijan Mottahedeh wrote:
> Split alloc_fixed_file_ref_node into resource generic/specific parts,
> rename destroy_fixed_file_ref_node, and factor out fixed_file_ref_node
> switching, to be be leveraged by fixed buffers.
> 
> Signed-off-by: Bijan Mottahedeh <bijan.mottahedeh@xxxxxxxxxx>
> ---
>  fs/io_uring.c | 34 +++++++++++++++++++++++++---------
>  1 file changed, 25 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 1ed63bc..126237e 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -7672,7 +7672,7 @@ static void io_rsrc_data_ref_zero(struct percpu_ref *ref)
>  		queue_delayed_work(system_wq, &ctx->rsrc_put_work, delay);
>  }
>  
> -static struct fixed_rsrc_ref_node *alloc_fixed_file_ref_node(
> +static struct fixed_rsrc_ref_node *alloc_fixed_rsrc_ref_node(
>  			struct io_ring_ctx *ctx)
>  {
>  	struct fixed_rsrc_ref_node *ref_node;
> @@ -7688,13 +7688,22 @@ static struct fixed_rsrc_ref_node *alloc_fixed_file_ref_node(
>  	}
>  	INIT_LIST_HEAD(&ref_node->node);
>  	INIT_LIST_HEAD(&ref_node->rsrc_list);
> +	ref_node->done = false;
> +	return ref_node;
> +}
> +
> +static struct fixed_rsrc_ref_node *alloc_fixed_file_ref_node(
> +			struct io_ring_ctx *ctx)
> +{
> +	struct fixed_rsrc_ref_node *ref_node;
> +
> +	ref_node = alloc_fixed_rsrc_ref_node(ctx);

if (!ref_node)
	return NULL;

>  	ref_node->rsrc_data = ctx->file_data;
>  	ref_node->rsrc_put = io_ring_file_put;
> -	ref_node->done = false;
>  	return ref_node;
>  }
>  
> -static void destroy_fixed_file_ref_node(struct fixed_rsrc_ref_node *ref_node)
> +static void destroy_fixed_rsrc_ref_node(struct fixed_rsrc_ref_node *ref_node)
>  {
>  	percpu_ref_exit(&ref_node->refs);
>  	kfree(ref_node);
> @@ -7870,6 +7879,17 @@ static inline int io_queue_file_removal(struct fixed_rsrc_data *data,
>  	return io_queue_rsrc_removal(data, (void *)file);
>  }
>  
> +static void switch_fixed_rsrc_ref_node(struct fixed_rsrc_ref_node *ref_node,
> +				       struct fixed_rsrc_data *data,
> +				       struct io_ring_ctx *ctx)
> +{
> +	percpu_ref_kill(&data->node->refs);
> +	spin_lock_bh(&ctx->rsrc_ref_lock);
> +	list_add_tail(&ref_node->node, &ctx->rsrc_ref_list);
> +	data->node = ref_node;
> +	spin_unlock_bh(&ctx->rsrc_ref_lock);
> +}
> +
>  static int __io_sqe_files_update(struct io_ring_ctx *ctx,
>  				 struct io_uring_files_update *up,
>  				 unsigned nr_args)
> @@ -7946,14 +7966,10 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
>  	}
>  
>  	if (needs_switch) {
> -		percpu_ref_kill(&data->node->refs);
> -		spin_lock_bh(&ctx->rsrc_ref_lock);
> -		list_add_tail(&ref_node->node, &ctx->rsrc_ref_list);
> -		data->node = ref_node;
> -		spin_unlock_bh(&ctx->rsrc_ref_lock);
> +		switch_fixed_rsrc_ref_node(ref_node, data, ctx);
>  		percpu_ref_get(&ctx->file_data->refs);
>  	} else
> -		destroy_fixed_file_ref_node(ref_node);
> +		destroy_fixed_rsrc_ref_node(ref_node);
>  
>  	return done ? done : err;
>  }
> 

-- 
Pavel Begunkov



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux