aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMing Lin <ming.l@ssi.samsung.com>2016-04-04 17:48:07 -0400
committerMartin K. Petersen <martin.petersen@oracle.com>2016-04-15 16:53:12 -0400
commit91dbc08d64fba7c1426a32be4c57ebb63c4be124 (patch)
tree0a7620d82e7891644b32674c4c4f12a95832991d
parent98be565f1c19747bfc463f668310ff89beb28696 (diff)
scsi: replace "scsi_data_buffer" with "sg_table" in SG functions
Replace parameter "struct scsi_data_buffer" with "struct sg_table" in SG alloc/free functions to make them generic. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Ming Lin <ming.l@ssi.samsung.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
-rw-r--r--drivers/scsi/scsi_lib.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 8106515d1df8..4229c183648b 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -583,14 +583,14 @@ static struct scatterlist *scsi_sg_alloc(unsigned int nents, gfp_t gfp_mask)
583 return mempool_alloc(sgp->pool, gfp_mask); 583 return mempool_alloc(sgp->pool, gfp_mask);
584} 584}
585 585
586static void scsi_free_sgtable(struct scsi_data_buffer *sdb, bool mq) 586static void scsi_free_sgtable(struct sg_table *table, bool mq)
587{ 587{
588 if (mq && sdb->table.orig_nents <= SCSI_MAX_SG_SEGMENTS) 588 if (mq && table->orig_nents <= SCSI_MAX_SG_SEGMENTS)
589 return; 589 return;
590 __sg_free_table(&sdb->table, SCSI_MAX_SG_SEGMENTS, mq, scsi_sg_free); 590 __sg_free_table(table, SCSI_MAX_SG_SEGMENTS, mq, scsi_sg_free);
591} 591}
592 592
593static int scsi_alloc_sgtable(struct scsi_data_buffer *sdb, int nents, bool mq) 593static int scsi_alloc_sgtable(struct sg_table *table, int nents, bool mq)
594{ 594{
595 struct scatterlist *first_chunk = NULL; 595 struct scatterlist *first_chunk = NULL;
596 int ret; 596 int ret;
@@ -599,17 +599,17 @@ static int scsi_alloc_sgtable(struct scsi_data_buffer *sdb, int nents, bool mq)
599 599
600 if (mq) { 600 if (mq) {
601 if (nents <= SCSI_MAX_SG_SEGMENTS) { 601 if (nents <= SCSI_MAX_SG_SEGMENTS) {
602 sdb->table.nents = sdb->table.orig_nents = nents; 602 table->nents = table->orig_nents = nents;
603 sg_init_table(sdb->table.sgl, nents); 603 sg_init_table(table->sgl, nents);
604 return 0; 604 return 0;
605 } 605 }
606 first_chunk = sdb->table.sgl; 606 first_chunk = table->sgl;
607 } 607 }
608 608
609 ret = __sg_alloc_table(&sdb->table, nents, SCSI_MAX_SG_SEGMENTS, 609 ret = __sg_alloc_table(table, nents, SCSI_MAX_SG_SEGMENTS,
610 first_chunk, GFP_ATOMIC, scsi_sg_alloc); 610 first_chunk, GFP_ATOMIC, scsi_sg_alloc);
611 if (unlikely(ret)) 611 if (unlikely(ret))
612 scsi_free_sgtable(sdb, mq); 612 scsi_free_sgtable(table, mq);
613 return ret; 613 return ret;
614} 614}
615 615
@@ -625,12 +625,17 @@ static void scsi_uninit_cmd(struct scsi_cmnd *cmd)
625 625
626static void scsi_mq_free_sgtables(struct scsi_cmnd *cmd) 626static void scsi_mq_free_sgtables(struct scsi_cmnd *cmd)
627{ 627{
628 struct scsi_data_buffer *sdb;
629
628 if (cmd->sdb.table.nents) 630 if (cmd->sdb.table.nents)
629 scsi_free_sgtable(&cmd->sdb, true); 631 scsi_free_sgtable(&cmd->sdb.table, true);
630 if (cmd->request->next_rq && cmd->request->next_rq->special) 632 if (cmd->request->next_rq) {
631 scsi_free_sgtable(cmd->request->next_rq->special, true); 633 sdb = cmd->request->next_rq->special;
634 if (sdb)
635 scsi_free_sgtable(&sdb->table, true);
636 }
632 if (scsi_prot_sg_count(cmd)) 637 if (scsi_prot_sg_count(cmd))
633 scsi_free_sgtable(cmd->prot_sdb, true); 638 scsi_free_sgtable(&cmd->prot_sdb->table, true);
634} 639}
635 640
636static void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd) 641static void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd)
@@ -669,19 +674,19 @@ static void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd)
669static void scsi_release_buffers(struct scsi_cmnd *cmd) 674static void scsi_release_buffers(struct scsi_cmnd *cmd)
670{ 675{
671 if (cmd->sdb.table.nents) 676 if (cmd->sdb.table.nents)
672 scsi_free_sgtable(&cmd->sdb, false); 677 scsi_free_sgtable(&cmd->sdb.table, false);
673 678
674 memset(&cmd->sdb, 0, sizeof(cmd->sdb)); 679 memset(&cmd->sdb, 0, sizeof(cmd->sdb));
675 680
676 if (scsi_prot_sg_count(cmd)) 681 if (scsi_prot_sg_count(cmd))
677 scsi_free_sgtable(cmd->prot_sdb, false); 682 scsi_free_sgtable(&cmd->prot_sdb->table, false);
678} 683}
679 684
680static void scsi_release_bidi_buffers(struct scsi_cmnd *cmd) 685static void scsi_release_bidi_buffers(struct scsi_cmnd *cmd)
681{ 686{
682 struct scsi_data_buffer *bidi_sdb = cmd->request->next_rq->special; 687 struct scsi_data_buffer *bidi_sdb = cmd->request->next_rq->special;
683 688
684 scsi_free_sgtable(bidi_sdb, false); 689 scsi_free_sgtable(&bidi_sdb->table, false);
685 kmem_cache_free(scsi_sdb_cache, bidi_sdb); 690 kmem_cache_free(scsi_sdb_cache, bidi_sdb);
686 cmd->request->next_rq->special = NULL; 691 cmd->request->next_rq->special = NULL;
687} 692}
@@ -1085,7 +1090,7 @@ static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb)
1085 /* 1090 /*
1086 * If sg table allocation fails, requeue request later. 1091 * If sg table allocation fails, requeue request later.
1087 */ 1092 */
1088 if (unlikely(scsi_alloc_sgtable(sdb, req->nr_phys_segments, 1093 if (unlikely(scsi_alloc_sgtable(&sdb->table, req->nr_phys_segments,
1089 req->mq_ctx != NULL))) 1094 req->mq_ctx != NULL)))
1090 return BLKPREP_DEFER; 1095 return BLKPREP_DEFER;
1091 1096
@@ -1158,7 +1163,7 @@ int scsi_init_io(struct scsi_cmnd *cmd)
1158 1163
1159 ivecs = blk_rq_count_integrity_sg(rq->q, rq->bio); 1164 ivecs = blk_rq_count_integrity_sg(rq->q, rq->bio);
1160 1165
1161 if (scsi_alloc_sgtable(prot_sdb, ivecs, is_mq)) { 1166 if (scsi_alloc_sgtable(&prot_sdb->table, ivecs, is_mq)) {
1162 error = BLKPREP_DEFER; 1167 error = BLKPREP_DEFER;
1163 goto err_exit; 1168 goto err_exit;
1164 } 1169 }