/* This function should also be useful for request stacking drivers in some cases below, so export this fuction. Request stacking drivers like request-based dm may change the queue limits while requests are in the queue (e.g. dm's table swapping). Such request stacking drivers should check those requests agaist the new queue limits again when they dispatch those requests, although such checkings are also done against the old queue limits when submitting requests.  */
int blk_rq_check_limits(struct request_queue *q, struct request *rq)
/* This function should also be useful for request stacking drivers in some cases below, so export this fuction. Request stacking drivers like request-based dm may change the queue limits while requests are in the queue (e.g. dm's table swapping). Such request stacking drivers should check those requests agaist the new queue limits again when they dispatch those requests, although such checkings are also done against the old queue limits when submitting requests.  */
int blk_rq_check_limits(struct request_queue *q, struct request *rq)
{
	if (blk_rq_sectors(rq) > queue_max_sectors(q) ||
	    blk_rq_bytes(rq) > queue_max_hw_sectors(q) << 9) {
		printk(KERN_ERR "%s: over max size limit.\n", __func__);
		return -EIO;
	}
	blk_recalc_rq_segments(rq);
	if (rq->nr_phys_segments > queue_max_phys_segments(q) ||
	    rq->nr_phys_segments > queue_max_hw_segments(q)) {
		printk(KERN_ERR "%s: over max segments limit.\n", __func__);
		return -EIO;
	}
	return 0;
}