Skip to content

Commit b3ad8c0

Browse files
josefbacikSomasundaram Krishnasamy
authored andcommitted
block: init flush rq ref count to 1
We discovered a problem in newer kernels where a disconnect of a NBD device while the flush request was pending would result in a hang. This is because the blk mq timeout handler does if (!refcount_inc_not_zero(&rq->ref)) return true; to determine if it's ok to run the timeout handler for the request. Flush_rq's don't have a ref count set, so we'd skip running the timeout handler for this request and it would just sit there in limbo forever. Fix this by always setting the refcount of any request going through blk_init_rq() to 1. I tested this with a nbd-server that dropped flush requests to verify that it hung, and then tested with this patch to verify I got the timeout as expected and the error handling kicked in. Thanks, Orabug: 30671963 Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: Jens Axboe <[email protected]> (cherry picked from commit b554db1) Signed-off-by: Ritika Srivastava <[email protected]> Reviewed-by: John Sobecki <[email protected]> Reviewed-by: Junxiao Bi <[email protected]> Signed-off-by: Somasundaram Krishnasamy <[email protected]>
1 parent dc7559a commit b3ad8c0

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

block/blk-core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ void blk_rq_init(struct request_queue *q, struct request *rq)
198198
rq->start_time = jiffies;
199199
set_start_time_ns(rq);
200200
rq->part = NULL;
201+
refcount_set(&rq->ref, 1);
201202
}
202203
EXPORT_SYMBOL(blk_rq_init);
203204

0 commit comments

Comments
 (0)