@@ -1075,8 +1075,11 @@ static bool io_match_task(struct io_kiocb *head,
1075
1075
return true;
1076
1076
1077
1077
io_for_each_link (req , head ) {
1078
- if ((req -> flags & REQ_F_WORK_INITIALIZED ) &&
1079
- (req -> work .flags & IO_WQ_WORK_FILES ) &&
1078
+ if (!(req -> flags & REQ_F_WORK_INITIALIZED ))
1079
+ continue ;
1080
+ if (req -> file && req -> file -> f_op == & io_uring_fops )
1081
+ return true;
1082
+ if ((req -> work .flags & IO_WQ_WORK_FILES ) &&
1080
1083
req -> work .identity -> files == files )
1081
1084
return true;
1082
1085
}
@@ -1505,11 +1508,14 @@ static bool io_grab_identity(struct io_kiocb *req)
1505
1508
return false;
1506
1509
atomic_inc (& id -> files -> count );
1507
1510
get_nsproxy (id -> nsproxy );
1508
- req -> flags |= REQ_F_INFLIGHT ;
1509
1511
1510
- spin_lock_irq (& ctx -> inflight_lock );
1511
- list_add (& req -> inflight_entry , & ctx -> inflight_list );
1512
- spin_unlock_irq (& ctx -> inflight_lock );
1512
+ if (!(req -> flags & REQ_F_INFLIGHT )) {
1513
+ req -> flags |= REQ_F_INFLIGHT ;
1514
+
1515
+ spin_lock_irq (& ctx -> inflight_lock );
1516
+ list_add (& req -> inflight_entry , & ctx -> inflight_list );
1517
+ spin_unlock_irq (& ctx -> inflight_lock );
1518
+ }
1513
1519
req -> work .flags |= IO_WQ_WORK_FILES ;
1514
1520
}
1515
1521
if (!(req -> work .flags & IO_WQ_WORK_MM ) &&
@@ -6164,8 +6170,10 @@ static void io_req_drop_files(struct io_kiocb *req)
6164
6170
struct io_uring_task * tctx = req -> task -> io_uring ;
6165
6171
unsigned long flags ;
6166
6172
6167
- put_files_struct (req -> work .identity -> files );
6168
- put_nsproxy (req -> work .identity -> nsproxy );
6173
+ if (req -> work .flags & IO_WQ_WORK_FILES ) {
6174
+ put_files_struct (req -> work .identity -> files );
6175
+ put_nsproxy (req -> work .identity -> nsproxy );
6176
+ }
6169
6177
spin_lock_irqsave (& ctx -> inflight_lock , flags );
6170
6178
list_del (& req -> inflight_entry );
6171
6179
spin_unlock_irqrestore (& ctx -> inflight_lock , flags );
@@ -6450,6 +6458,15 @@ static struct file *io_file_get(struct io_submit_state *state,
6450
6458
file = __io_file_get (state , fd );
6451
6459
}
6452
6460
6461
+ if (file && file -> f_op == & io_uring_fops ) {
6462
+ io_req_init_async (req );
6463
+ req -> flags |= REQ_F_INFLIGHT ;
6464
+
6465
+ spin_lock_irq (& ctx -> inflight_lock );
6466
+ list_add (& req -> inflight_entry , & ctx -> inflight_list );
6467
+ spin_unlock_irq (& ctx -> inflight_lock );
6468
+ }
6469
+
6453
6470
return file ;
6454
6471
}
6455
6472
@@ -8860,8 +8877,7 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx,
8860
8877
8861
8878
spin_lock_irq (& ctx -> inflight_lock );
8862
8879
list_for_each_entry (req , & ctx -> inflight_list , inflight_entry ) {
8863
- if (req -> task != task ||
8864
- req -> work .identity -> files != files )
8880
+ if (!io_match_task (req , task , files ))
8865
8881
continue ;
8866
8882
found = true;
8867
8883
break ;
0 commit comments