linux/block/blk-timeout.c
/**
 * blk_add_timer - Start timeout timer for a single request
 * @req:	request that is about to start running.
 *
 * Notes:
 *    Each request has its own timer, and as it is added to the queue, we
 *    set up the timer. When the request completes, we cancel the timer.
 */
Start timeout timer for a single request
@req:        request that is about to start running.

Each request has its own timer, and as it is added to the queue, we
set up the timer. When the request completes, we cancel the timer.
Start timeout timer for a single request @req : request that is about to start running . Each request has its own timer and as it is added to the queue we set up the timer . When the request completes we cancel the timer .
void blk_add_timer(struct request *req)
{
	struct request_queue *q = req->q;
	unsigned long expiry;
	if (!q->mq_ops)
		lockdep_assert_held(q->queue_lock);
	if (!q->mq_ops && !q->rq_timed_out_fn)
		return;
	BUG_ON(!list_empty(&req->timeout_list));
	if (!req->timeout)
		req->timeout = q->rq_timeout;
	req->rq_flags &= ~RQF_TIMED_OUT;
	blk_rq_set_deadline(req, jiffies + req->timeout);
	if (!q->mq_ops)
		list_add_tail(&req->timeout_list, &req->q->timeout_list);
	expiry = blk_rq_timeout(round_jiffies_up(blk_rq_deadline(req)));
	if (!timer_pending(&q->timeout) ||
	    time_before(expiry, q->timeout.expires)) {
		unsigned long diff = q->timeout.expires - expiry;
		if (!timer_pending(&q->timeout) || (diff >= HZ / 2))
			mod_timer(&q->timeout, expiry);
	}
}
void blk_add_timer ( struct request * req ) { struct request_queue * q = req -> q ; unsigned long expiry ; if ( ! q -> mq_ops ) lockdep_assert_held ( q -> queue_lock ) ; if ( ! q -> mq_ops && ! q -> rq_timed_out_fn ) return ; BUG_ON ( ! list_empty ( & req -> timeout_list ) ) ; if ( ! req -> timeout ) req -> timeout = q -> rq_timeout ; req -> rq_flags &= ~ RQF_TIMED_OUT ; blk_rq_set_deadline ( req , jiffies + req -> timeout ) ; if ( ! q -> mq_ops ) list_add_tail ( & req -> timeout_list , & req -> q -> timeout_list ) ; expiry = blk_rq_timeout ( round_jiffies_up ( blk_rq_deadline ( req ) ) ) ; if ( ! timer_pending ( & q -> timeout ) || time_before ( expiry , q -> timeout . expires ) ) { unsigned long diff = q -> timeout . expires - expiry ; if ( ! timer_pending ( & q -> timeout ) || ( diff >= HZ / 2 ) ) mod_timer ( & q -> timeout , expiry ) ; } }
blk_add_timer - Start timeout timer for a single request
 @req:        request that is about to start running.
blk_add_timer - Start timeout timer for a single request @req : request that is about to start running .
/* blk-mq has its own handler, so we don't need ->rq_timed_out_fn */ /*
	 * Some LLDs, like scsi, peek at the timeout to prevent a
	 * command from being retried forever.
	 */ /*
	 * Only the non-mq case needs to add the request to a protected list.
	 * For the mq case we simply scan the tag map.
	 */ /*
	 * If the timer isn't already pending or this timeout is earlier
	 * than an existing one, modify the timer. Round up to next nearest
	 * second.
	 */ /*
		 * Due to added timer slack to group timers, the timer
		 * will often be a little in front of what we asked for.
		 * So apply some tolerance here too, otherwise we keep
		 * modifying the timer because expires for value X
		 * will be X + something.
		 */