@@ -23,6 +23,8 @@ struct io_rsrc_update {
23
23
u32 offset ;
24
24
};
25
25
26
+ static void io_rsrc_buf_put (struct io_ring_ctx * ctx , struct io_rsrc_put * prsrc );
27
+ static void io_rsrc_file_put (struct io_ring_ctx * ctx , struct io_rsrc_put * prsrc );
26
28
static int io_sqe_buffer_register (struct io_ring_ctx * ctx , struct iovec * iov ,
27
29
struct io_mapped_ubuf * * pimu ,
28
30
struct page * * last_hpage );
@@ -147,7 +149,18 @@ static void io_rsrc_put_work(struct io_rsrc_node *node)
147
149
148
150
if (prsrc -> tag )
149
151
io_post_aux_cqe (data -> ctx , prsrc -> tag , 0 , 0 );
150
- data -> do_put (data -> ctx , prsrc );
152
+
153
+ switch (data -> rsrc_type ) {
154
+ case IORING_RSRC_FILE :
155
+ io_rsrc_file_put (data -> ctx , prsrc );
156
+ break ;
157
+ case IORING_RSRC_BUFFER :
158
+ io_rsrc_buf_put (data -> ctx , prsrc );
159
+ break ;
160
+ default :
161
+ WARN_ON_ONCE (1 );
162
+ break ;
163
+ }
151
164
}
152
165
153
166
void io_rsrc_node_destroy (struct io_ring_ctx * ctx , struct io_rsrc_node * node )
@@ -297,8 +310,8 @@ static __cold void **io_alloc_page_table(size_t size)
297
310
return table ;
298
311
}
299
312
300
- __cold static int io_rsrc_data_alloc (struct io_ring_ctx * ctx ,
301
- rsrc_put_fn * do_put , u64 __user * utags ,
313
+ __cold static int io_rsrc_data_alloc (struct io_ring_ctx * ctx , int type ,
314
+ u64 __user * utags ,
302
315
unsigned nr , struct io_rsrc_data * * pdata )
303
316
{
304
317
struct io_rsrc_data * data ;
@@ -316,7 +329,7 @@ __cold static int io_rsrc_data_alloc(struct io_ring_ctx *ctx,
316
329
317
330
data -> nr = nr ;
318
331
data -> ctx = ctx ;
319
- data -> do_put = do_put ;
332
+ data -> rsrc_type = type ;
320
333
if (utags ) {
321
334
ret = - EFAULT ;
322
335
for (i = 0 ; i < nr ; i ++ ) {
@@ -849,7 +862,7 @@ int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
849
862
return - EMFILE ;
850
863
if (nr_args > rlimit (RLIMIT_NOFILE ))
851
864
return - EMFILE ;
852
- ret = io_rsrc_data_alloc (ctx , io_rsrc_file_put , tags , nr_args ,
865
+ ret = io_rsrc_data_alloc (ctx , IORING_RSRC_FILE , tags , nr_args ,
853
866
& ctx -> file_data );
854
867
if (ret )
855
868
return ret ;
@@ -1184,7 +1197,7 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
1184
1197
return - EBUSY ;
1185
1198
if (!nr_args || nr_args > IORING_MAX_REG_BUFFERS )
1186
1199
return - EINVAL ;
1187
- ret = io_rsrc_data_alloc (ctx , io_rsrc_buf_put , tags , nr_args , & data );
1200
+ ret = io_rsrc_data_alloc (ctx , IORING_RSRC_BUFFER , tags , nr_args , & data );
1188
1201
if (ret )
1189
1202
return ret ;
1190
1203
ret = io_buffers_map_alloc (ctx , nr_args );
0 commit comments