Skip to content

Commit e9193da

Browse files
committed
Merge branch 'stable/for-jens-4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen into for-linus
Pull xen-blkfront fixes from Konrad for 4.13.
2 parents 7a362ea + bd912ef commit e9193da

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

drivers/block/xen-blkfront.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
708708
* existing persistent grants, or if we have to get new grants,
709709
* as there are not sufficiently many free.
710710
*/
711+
bool new_persistent_gnts = false;
711712
struct scatterlist *sg;
712713
int num_sg, max_grefs, num_grant;
713714

@@ -719,19 +720,21 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
719720
*/
720721
max_grefs += INDIRECT_GREFS(max_grefs);
721722

722-
/*
723-
* We have to reserve 'max_grefs' grants because persistent
724-
* grants are shared by all rings.
725-
*/
726-
if (max_grefs > 0)
727-
if (gnttab_alloc_grant_references(max_grefs, &setup.gref_head) < 0) {
723+
/* Check if we have enough persistent grants to allocate a requests */
724+
if (rinfo->persistent_gnts_c < max_grefs) {
725+
new_persistent_gnts = true;
726+
727+
if (gnttab_alloc_grant_references(
728+
max_grefs - rinfo->persistent_gnts_c,
729+
&setup.gref_head) < 0) {
728730
gnttab_request_free_callback(
729731
&rinfo->callback,
730732
blkif_restart_queue_callback,
731733
rinfo,
732-
max_grefs);
734+
max_grefs - rinfo->persistent_gnts_c);
733735
return 1;
734736
}
737+
}
735738

736739
/* Fill out a communications ring structure. */
737740
id = blkif_ring_get_request(rinfo, req, &ring_req);
@@ -832,7 +835,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
832835
if (unlikely(require_extra_req))
833836
rinfo->shadow[extra_id].req = *extra_ring_req;
834837

835-
if (max_grefs > 0)
838+
if (new_persistent_gnts)
836839
gnttab_free_grant_references(setup.gref_head);
837840

838841
return 0;
@@ -906,8 +909,8 @@ static blk_status_t blkif_queue_rq(struct blk_mq_hw_ctx *hctx,
906909
return BLK_STS_IOERR;
907910

908911
out_busy:
909-
spin_unlock_irqrestore(&rinfo->ring_lock, flags);
910912
blk_mq_stop_hw_queue(hctx);
913+
spin_unlock_irqrestore(&rinfo->ring_lock, flags);
911914
return BLK_STS_RESOURCE;
912915
}
913916

0 commit comments

Comments
 (0)