Skip to content

Commit afd53a3

Browse files
Christoph Hellwigmartinkpetersen
authored andcommitted
scsi: core: Initialize scsi midlayer limits before allocating the queue
Turn __scsi_init_queue() into scsi_init_limits() which initializes queue_limits structure that can be passed to blk_mq_alloc_queue(). Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Bart Van Assche <[email protected]> Reviewed-by: John Garry <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 9042fb6 commit afd53a3

File tree

5 files changed

+28
-27
lines changed

5 files changed

+28
-27
lines changed

drivers/scsi/scsi_lib.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <scsi/scsi_driver.h>
3333
#include <scsi/scsi_eh.h>
3434
#include <scsi/scsi_host.h>
35-
#include <scsi/scsi_transport.h> /* __scsi_init_queue() */
35+
#include <scsi/scsi_transport.h> /* scsi_init_limits() */
3636
#include <scsi/scsi_dh.h>
3737

3838
#include <trace/events/scsi.h>
@@ -1965,31 +1965,26 @@ static void scsi_map_queues(struct blk_mq_tag_set *set)
19651965
blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]);
19661966
}
19671967

1968-
void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q)
1968+
void scsi_init_limits(struct Scsi_Host *shost, struct queue_limits *lim)
19691969
{
19701970
struct device *dev = shost->dma_dev;
19711971

1972-
/*
1973-
* this limit is imposed by hardware restrictions
1974-
*/
1975-
blk_queue_max_segments(q, min_t(unsigned short, shost->sg_tablesize,
1976-
SG_MAX_SEGMENTS));
1972+
memset(lim, 0, sizeof(*lim));
1973+
lim->max_segments =
1974+
min_t(unsigned short, shost->sg_tablesize, SG_MAX_SEGMENTS);
19771975

19781976
if (scsi_host_prot_dma(shost)) {
19791977
shost->sg_prot_tablesize =
19801978
min_not_zero(shost->sg_prot_tablesize,
19811979
(unsigned short)SCSI_MAX_PROT_SG_SEGMENTS);
19821980
BUG_ON(shost->sg_prot_tablesize < shost->sg_tablesize);
1983-
blk_queue_max_integrity_segments(q, shost->sg_prot_tablesize);
1981+
lim->max_integrity_segments = shost->sg_prot_tablesize;
19841982
}
19851983

1986-
blk_queue_max_hw_sectors(q, shost->max_sectors);
1987-
blk_queue_segment_boundary(q, shost->dma_boundary);
1988-
dma_set_seg_boundary(dev, shost->dma_boundary);
1989-
1990-
blk_queue_max_segment_size(q, shost->max_segment_size);
1991-
blk_queue_virt_boundary(q, shost->virt_boundary_mask);
1992-
dma_set_max_seg_size(dev, queue_max_segment_size(q));
1984+
lim->max_hw_sectors = shost->max_sectors;
1985+
lim->seg_boundary_mask = shost->dma_boundary;
1986+
lim->max_segment_size = shost->max_segment_size;
1987+
lim->virt_boundary_mask = shost->virt_boundary_mask;
19931988

19941989
/*
19951990
* Set a reasonable default alignment: The larger of 32-byte (dword),
@@ -1998,9 +1993,12 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q)
19981993
*
19991994
* Devices that require a bigger alignment can increase it later.
20001995
*/
2001-
blk_queue_dma_alignment(q, max(4, dma_get_cache_alignment()) - 1);
1996+
lim->dma_alignment = max(4, dma_get_cache_alignment()) - 1;
1997+
1998+
dma_set_seg_boundary(dev, shost->dma_boundary);
1999+
dma_set_max_seg_size(dev, shost->max_segment_size);
20022000
}
2003-
EXPORT_SYMBOL_GPL(__scsi_init_queue);
2001+
EXPORT_SYMBOL_GPL(scsi_init_limits);
20042002

20052003
static const struct blk_mq_ops scsi_mq_ops_no_commit = {
20062004
.get_budget = scsi_mq_get_budget,

drivers/scsi/scsi_scan.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
283283
struct request_queue *q;
284284
int display_failure_msg = 1, ret;
285285
struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
286+
struct queue_limits lim;
286287

287288
sdev = kzalloc(sizeof(*sdev) + shost->transportt->device_size,
288289
GFP_KERNEL);
@@ -332,7 +333,8 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
332333

333334
sdev->sg_reserved_size = INT_MAX;
334335

335-
q = blk_mq_alloc_queue(&sdev->host->tag_set, NULL, NULL);
336+
scsi_init_limits(shost, &lim);
337+
q = blk_mq_alloc_queue(&sdev->host->tag_set, &lim, NULL);
336338
if (IS_ERR(q)) {
337339
/* release fn is set up in scsi_sysfs_device_initialise, so
338340
* have to free and put manually here */
@@ -343,7 +345,6 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
343345
kref_get(&sdev->host->tagset_refcnt);
344346
sdev->request_queue = q;
345347
q->queuedata = sdev;
346-
__scsi_init_queue(sdev->host, q);
347348

348349
depth = sdev->host->cmd_per_lun ?: 1;
349350

drivers/scsi/scsi_transport_fc.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4276,6 +4276,7 @@ fc_bsg_hostadd(struct Scsi_Host *shost, struct fc_host_attrs *fc_host)
42764276
{
42774277
struct device *dev = &shost->shost_gendev;
42784278
struct fc_internal *i = to_fc_internal(shost->transportt);
4279+
struct queue_limits lim;
42794280
struct request_queue *q;
42804281
char bsg_name[20];
42814282

@@ -4286,16 +4287,15 @@ fc_bsg_hostadd(struct Scsi_Host *shost, struct fc_host_attrs *fc_host)
42864287

42874288
snprintf(bsg_name, sizeof(bsg_name),
42884289
"fc_host%d", shost->host_no);
4289-
4290-
q = bsg_setup_queue(dev, bsg_name, NULL, fc_bsg_dispatch,
4290+
scsi_init_limits(shost, &lim);
4291+
q = bsg_setup_queue(dev, bsg_name, &lim, fc_bsg_dispatch,
42914292
fc_bsg_job_timeout, i->f->dd_bsg_size);
42924293
if (IS_ERR(q)) {
42934294
dev_err(dev,
42944295
"fc_host%d: bsg interface failed to initialize - setup queue\n",
42954296
shost->host_no);
42964297
return PTR_ERR(q);
42974298
}
4298-
__scsi_init_queue(shost, q);
42994299
blk_queue_rq_timeout(q, FC_DEFAULT_BSG_TIMEOUT);
43004300
fc_host->rqst_q = q;
43014301
return 0;
@@ -4311,20 +4311,21 @@ fc_bsg_rportadd(struct Scsi_Host *shost, struct fc_rport *rport)
43114311
{
43124312
struct device *dev = &rport->dev;
43134313
struct fc_internal *i = to_fc_internal(shost->transportt);
4314+
struct queue_limits lim;
43144315
struct request_queue *q;
43154316

43164317
rport->rqst_q = NULL;
43174318

43184319
if (!i->f->bsg_request)
43194320
return -ENOTSUPP;
43204321

4321-
q = bsg_setup_queue(dev, dev_name(dev), NULL, fc_bsg_dispatch_prep,
4322+
scsi_init_limits(shost, &lim);
4323+
q = bsg_setup_queue(dev, dev_name(dev), &lim, fc_bsg_dispatch_prep,
43224324
fc_bsg_job_timeout, i->f->dd_bsg_size);
43234325
if (IS_ERR(q)) {
43244326
dev_err(dev, "failed to setup bsg queue\n");
43254327
return PTR_ERR(q);
43264328
}
4327-
__scsi_init_queue(shost, q);
43284329
blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT);
43294330
rport->rqst_q = q;
43304331
return 0;

drivers/scsi/scsi_transport_iscsi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,21 +1535,22 @@ iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost)
15351535
{
15361536
struct device *dev = &shost->shost_gendev;
15371537
struct iscsi_internal *i = to_iscsi_internal(shost->transportt);
1538+
struct queue_limits lim;
15381539
struct request_queue *q;
15391540
char bsg_name[20];
15401541

15411542
if (!i->iscsi_transport->bsg_request)
15421543
return -ENOTSUPP;
15431544

15441545
snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no);
1545-
q = bsg_setup_queue(dev, bsg_name, NULL, iscsi_bsg_host_dispatch, NULL,
1546+
scsi_init_limits(shost, &lim);
1547+
q = bsg_setup_queue(dev, bsg_name, &lim, iscsi_bsg_host_dispatch, NULL,
15461548
0);
15471549
if (IS_ERR(q)) {
15481550
shost_printk(KERN_ERR, shost, "bsg interface failed to "
15491551
"initialize - no request queue\n");
15501552
return PTR_ERR(q);
15511553
}
1552-
__scsi_init_queue(shost, q);
15531554

15541555
ihost->bsg_q = q;
15551556
return 0;

include/scsi/scsi_transport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ scsi_transport_device_data(struct scsi_device *sdev)
8383
+ shost->transportt->device_private_offset;
8484
}
8585

86-
void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q);
86+
void scsi_init_limits(struct Scsi_Host *shost, struct queue_limits *lim);
8787

8888
#endif /* SCSI_TRANSPORT_H */

0 commit comments

Comments
 (0)