@@ -1394,12 +1394,31 @@ static struct fuse_ring_queue *fuse_uring_task_to_queue(struct fuse_ring *ring)
13941394 return queue ;
13951395}
13961396
1397- static void fuse_uring_dispatch_ent (struct fuse_ring_ent * ent )
1397+ static void fuse_uring_dispatch_ent (struct fuse_ring_ent * ent , bool bg )
13981398{
13991399 struct io_uring_cmd * cmd = ent -> cmd ;
14001400
1401- uring_cmd_set_ring_ent (cmd , ent );
1402- io_uring_cmd_complete_in_task (cmd , fuse_uring_send_in_task );
1401+ /*
1402+ * Task needed when pages are not pinned as the application doing IO
1403+ * is not allowed to write into fuse-server pages.
1404+ * Additionally for IO through io-uring as issue flags are unknown then.
1405+ * backgrounds requests might hold spin-locks, that conflict with
1406+ * io_uring_cmd_done() mutex lock.
1407+ */
1408+ if (!ent -> header_pages || current -> io_uring || bg ) {
1409+ uring_cmd_set_ring_ent (cmd , ent );
1410+ io_uring_cmd_complete_in_task (cmd , fuse_uring_send_in_task );
1411+ } else {
1412+ int err = fuse_uring_prepare_send (ent , ent -> fuse_req );
1413+ struct fuse_ring_queue * queue = ent -> queue ;
1414+
1415+ if (err ) {
1416+ fuse_uring_next_fuse_req (ent , queue ,
1417+ IO_URING_F_UNLOCKED );
1418+ return ;
1419+ }
1420+ fuse_uring_send (ent , cmd , 0 , IO_URING_F_UNLOCKED );
1421+ }
14031422}
14041423
14051424/* queue a fuse request and send it if a ring entry is available */
@@ -1432,7 +1451,7 @@ void fuse_uring_queue_fuse_req(struct fuse_iqueue *fiq, struct fuse_req *req)
14321451 spin_unlock (& queue -> lock );
14331452
14341453 if (ent )
1435- fuse_uring_dispatch_ent (ent );
1454+ fuse_uring_dispatch_ent (ent , false );
14361455
14371456 return ;
14381457
@@ -1485,7 +1504,7 @@ bool fuse_uring_queue_bq_req(struct fuse_req *req)
14851504 fuse_uring_add_req_to_ring_ent (ent , req );
14861505 spin_unlock (& queue -> lock );
14871506
1488- fuse_uring_dispatch_ent (ent );
1507+ fuse_uring_dispatch_ent (ent , true );
14891508 } else {
14901509 spin_unlock (& queue -> lock );
14911510 }
0 commit comments