aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2014-12-29 23:05:09 -0500
committerChristoph Hellwig <hch@lst.de>2015-01-09 09:44:24 -0500
commitead3700d893654d440edcb66fb3767a0c0db54cf (patch)
tree617c6093b91dfb01a7da543cab5864d71f9c820a
parentd454c91f74fcefce5cd545cf98c565ed882bf81a (diff)
storvsc: use cmd_size to allocate per-command data
STORVSC uses its own momory pool to manage device request data. However, the SCSI layer already has a mechanisim for allocating additional memory for each command issued to device driver. This patch removes the memory pool in STORVSC and makes it use SCSI layer to allocate memory for device request data. Reviewed-by: Long Li <longli@microsoft.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
-rw-r--r--drivers/scsi/storvsc_drv.c119
1 files changed, 8 insertions, 111 deletions
diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 4cff0ddc2c25..14ee98edeed1 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -32,7 +32,6 @@
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/device.h> 33#include <linux/device.h>
34#include <linux/hyperv.h> 34#include <linux/hyperv.h>
35#include <linux/mempool.h>
36#include <linux/blkdev.h> 35#include <linux/blkdev.h>
37#include <scsi/scsi.h> 36#include <scsi/scsi.h>
38#include <scsi/scsi_cmnd.h> 37#include <scsi/scsi_cmnd.h>
@@ -309,14 +308,6 @@ enum storvsc_request_type {
309 * This is the end of Protocol specific defines. 308 * This is the end of Protocol specific defines.
310 */ 309 */
311 310
312
313/*
314 * We setup a mempool to allocate request structures for this driver
315 * on a per-lun basis. The following define specifies the number of
316 * elements in the pool.
317 */
318
319#define STORVSC_MIN_BUF_NR 64
320static int storvsc_ringbuffer_size = (20 * PAGE_SIZE); 311static int storvsc_ringbuffer_size = (20 * PAGE_SIZE);
321 312
322module_param(storvsc_ringbuffer_size, int, S_IRUGO); 313module_param(storvsc_ringbuffer_size, int, S_IRUGO);
@@ -346,7 +337,6 @@ static void storvsc_on_channel_callback(void *context);
346#define STORVSC_IDE_MAX_CHANNELS 1 337#define STORVSC_IDE_MAX_CHANNELS 1
347 338
348struct storvsc_cmd_request { 339struct storvsc_cmd_request {
349 struct list_head entry;
350 struct scsi_cmnd *cmd; 340 struct scsi_cmnd *cmd;
351 341
352 unsigned int bounce_sgl_count; 342 unsigned int bounce_sgl_count;
@@ -357,7 +347,6 @@ struct storvsc_cmd_request {
357 /* Synchronize the request/response if needed */ 347 /* Synchronize the request/response if needed */
358 struct completion wait_event; 348 struct completion wait_event;
359 349
360 unsigned char *sense_buffer;
361 struct hv_multipage_buffer data_buffer; 350 struct hv_multipage_buffer data_buffer;
362 struct vstor_packet vstor_packet; 351 struct vstor_packet vstor_packet;
363}; 352};
@@ -389,11 +378,6 @@ struct storvsc_device {
389 struct storvsc_cmd_request reset_request; 378 struct storvsc_cmd_request reset_request;
390}; 379};
391 380
392struct stor_mem_pools {
393 struct kmem_cache *request_pool;
394 mempool_t *request_mempool;
395};
396
397struct hv_host_device { 381struct hv_host_device {
398 struct hv_device *dev; 382 struct hv_device *dev;
399 unsigned int port; 383 unsigned int port;
@@ -1070,10 +1054,8 @@ static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request)
1070{ 1054{
1071 struct scsi_cmnd *scmnd = cmd_request->cmd; 1055 struct scsi_cmnd *scmnd = cmd_request->cmd;
1072 struct hv_host_device *host_dev = shost_priv(scmnd->device->host); 1056 struct hv_host_device *host_dev = shost_priv(scmnd->device->host);
1073 void (*scsi_done_fn)(struct scsi_cmnd *);
1074 struct scsi_sense_hdr sense_hdr; 1057 struct scsi_sense_hdr sense_hdr;
1075 struct vmscsi_request *vm_srb; 1058 struct vmscsi_request *vm_srb;
1076 struct stor_mem_pools *memp = scmnd->device->hostdata;
1077 struct Scsi_Host *host; 1059 struct Scsi_Host *host;
1078 struct storvsc_device *stor_dev; 1060 struct storvsc_device *stor_dev;
1079 struct hv_device *dev = host_dev->dev; 1061 struct hv_device *dev = host_dev->dev;
@@ -1109,14 +1091,7 @@ static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request)
1109 cmd_request->data_buffer.len - 1091 cmd_request->data_buffer.len -
1110 vm_srb->data_transfer_length); 1092 vm_srb->data_transfer_length);
1111 1093
1112 scsi_done_fn = scmnd->scsi_done; 1094 scmnd->scsi_done(scmnd);
1113
1114 scmnd->host_scribble = NULL;
1115 scmnd->scsi_done = NULL;
1116
1117 scsi_done_fn(scmnd);
1118
1119 mempool_free(cmd_request, memp->request_mempool);
1120} 1095}
1121 1096
1122static void storvsc_on_io_completion(struct hv_device *device, 1097static void storvsc_on_io_completion(struct hv_device *device,
@@ -1160,7 +1135,7 @@ static void storvsc_on_io_completion(struct hv_device *device,
1160 SRB_STATUS_AUTOSENSE_VALID) { 1135 SRB_STATUS_AUTOSENSE_VALID) {
1161 /* autosense data available */ 1136 /* autosense data available */
1162 1137
1163 memcpy(request->sense_buffer, 1138 memcpy(request->cmd->sense_buffer,
1164 vstor_packet->vm_srb.sense_data, 1139 vstor_packet->vm_srb.sense_data,
1165 vstor_packet->vm_srb.sense_info_length); 1140 vstor_packet->vm_srb.sense_info_length);
1166 1141
@@ -1378,55 +1353,6 @@ static int storvsc_do_io(struct hv_device *device,
1378 return ret; 1353 return ret;
1379} 1354}
1380 1355
1381static int storvsc_device_alloc(struct scsi_device *sdevice)
1382{
1383 struct stor_mem_pools *memp;
1384 int number = STORVSC_MIN_BUF_NR;
1385
1386 memp = kzalloc(sizeof(struct stor_mem_pools), GFP_KERNEL);
1387 if (!memp)
1388 return -ENOMEM;
1389
1390 memp->request_pool =
1391 kmem_cache_create(dev_name(&sdevice->sdev_dev),
1392 sizeof(struct storvsc_cmd_request), 0,
1393 SLAB_HWCACHE_ALIGN, NULL);
1394
1395 if (!memp->request_pool)
1396 goto err0;
1397
1398 memp->request_mempool = mempool_create(number, mempool_alloc_slab,
1399 mempool_free_slab,
1400 memp->request_pool);
1401
1402 if (!memp->request_mempool)
1403 goto err1;
1404
1405 sdevice->hostdata = memp;
1406
1407 return 0;
1408
1409err1:
1410 kmem_cache_destroy(memp->request_pool);
1411
1412err0:
1413 kfree(memp);
1414 return -ENOMEM;
1415}
1416
1417static void storvsc_device_destroy(struct scsi_device *sdevice)
1418{
1419 struct stor_mem_pools *memp = sdevice->hostdata;
1420
1421 if (!memp)
1422 return;
1423
1424 mempool_destroy(memp->request_mempool);
1425 kmem_cache_destroy(memp->request_pool);
1426 kfree(memp);
1427 sdevice->hostdata = NULL;
1428}
1429
1430static int storvsc_device_configure(struct scsi_device *sdevice) 1356static int storvsc_device_configure(struct scsi_device *sdevice)
1431{ 1357{
1432 scsi_change_queue_depth(sdevice, STORVSC_MAX_IO_REQUESTS); 1358 scsi_change_queue_depth(sdevice, STORVSC_MAX_IO_REQUESTS);
@@ -1561,13 +1487,11 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
1561 int ret; 1487 int ret;
1562 struct hv_host_device *host_dev = shost_priv(host); 1488 struct hv_host_device *host_dev = shost_priv(host);
1563 struct hv_device *dev = host_dev->dev; 1489 struct hv_device *dev = host_dev->dev;
1564 struct storvsc_cmd_request *cmd_request; 1490 struct storvsc_cmd_request *cmd_request = scsi_cmd_priv(scmnd);
1565 unsigned int request_size = 0;
1566 int i; 1491 int i;
1567 struct scatterlist *sgl; 1492 struct scatterlist *sgl;
1568 unsigned int sg_count = 0; 1493 unsigned int sg_count = 0;
1569 struct vmscsi_request *vm_srb; 1494 struct vmscsi_request *vm_srb;
1570 struct stor_mem_pools *memp = scmnd->device->hostdata;
1571 1495
1572 if (vmstor_current_major <= VMSTOR_WIN8_MAJOR) { 1496 if (vmstor_current_major <= VMSTOR_WIN8_MAJOR) {
1573 /* 1497 /*
@@ -1584,25 +1508,9 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
1584 } 1508 }
1585 } 1509 }
1586 1510
1587 request_size = sizeof(struct storvsc_cmd_request);
1588
1589 cmd_request = mempool_alloc(memp->request_mempool,
1590 GFP_ATOMIC);
1591
1592 /*
1593 * We might be invoked in an interrupt context; hence
1594 * mempool_alloc() can fail.
1595 */
1596 if (!cmd_request)
1597 return SCSI_MLQUEUE_DEVICE_BUSY;
1598
1599 memset(cmd_request, 0, sizeof(struct storvsc_cmd_request));
1600
1601 /* Setup the cmd request */ 1511 /* Setup the cmd request */
1602 cmd_request->cmd = scmnd; 1512 cmd_request->cmd = scmnd;
1603 1513
1604 scmnd->host_scribble = (unsigned char *)cmd_request;
1605
1606 vm_srb = &cmd_request->vstor_packet.vm_srb; 1514 vm_srb = &cmd_request->vstor_packet.vm_srb;
1607 vm_srb->win8_extension.time_out_value = 60; 1515 vm_srb->win8_extension.time_out_value = 60;
1608 1516
@@ -1637,9 +1545,6 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
1637 1545
1638 memcpy(vm_srb->cdb, scmnd->cmnd, vm_srb->cdb_length); 1546 memcpy(vm_srb->cdb, scmnd->cmnd, vm_srb->cdb_length);
1639 1547
1640 cmd_request->sense_buffer = scmnd->sense_buffer;
1641
1642
1643 cmd_request->data_buffer.len = scsi_bufflen(scmnd); 1548 cmd_request->data_buffer.len = scsi_bufflen(scmnd);
1644 if (scsi_sg_count(scmnd)) { 1549 if (scsi_sg_count(scmnd)) {
1645 sgl = (struct scatterlist *)scsi_sglist(scmnd); 1550 sgl = (struct scatterlist *)scsi_sglist(scmnd);
@@ -1651,10 +1556,8 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
1651 create_bounce_buffer(sgl, scsi_sg_count(scmnd), 1556 create_bounce_buffer(sgl, scsi_sg_count(scmnd),
1652 scsi_bufflen(scmnd), 1557 scsi_bufflen(scmnd),
1653 vm_srb->data_in); 1558 vm_srb->data_in);
1654 if (!cmd_request->bounce_sgl) { 1559 if (!cmd_request->bounce_sgl)
1655 ret = SCSI_MLQUEUE_HOST_BUSY; 1560 return SCSI_MLQUEUE_HOST_BUSY;
1656 goto queue_error;
1657 }
1658 1561
1659 cmd_request->bounce_sgl_count = 1562 cmd_request->bounce_sgl_count =
1660 ALIGN(scsi_bufflen(scmnd), PAGE_SIZE) >> 1563 ALIGN(scsi_bufflen(scmnd), PAGE_SIZE) >>
@@ -1692,27 +1595,21 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
1692 destroy_bounce_buffer(cmd_request->bounce_sgl, 1595 destroy_bounce_buffer(cmd_request->bounce_sgl,
1693 cmd_request->bounce_sgl_count); 1596 cmd_request->bounce_sgl_count);
1694 1597
1695 ret = SCSI_MLQUEUE_DEVICE_BUSY; 1598 return SCSI_MLQUEUE_DEVICE_BUSY;
1696 goto queue_error;
1697 } 1599 }
1698 1600
1699 return 0; 1601 return 0;
1700
1701queue_error:
1702 mempool_free(cmd_request, memp->request_mempool);
1703 scmnd->host_scribble = NULL;
1704 return ret;
1705} 1602}
1706 1603
1707static struct scsi_host_template scsi_driver = { 1604static struct scsi_host_template scsi_driver = {
1708 .module = THIS_MODULE, 1605 .module = THIS_MODULE,
1709 .name = "storvsc_host_t", 1606 .name = "storvsc_host_t",
1607 .cmd_size = sizeof(struct storvsc_cmd_request),
1710 .bios_param = storvsc_get_chs, 1608 .bios_param = storvsc_get_chs,
1711 .queuecommand = storvsc_queuecommand, 1609 .queuecommand = storvsc_queuecommand,
1712 .eh_host_reset_handler = storvsc_host_reset_handler, 1610 .eh_host_reset_handler = storvsc_host_reset_handler,
1611 .proc_name = "storvsc_host",
1713 .eh_timed_out = storvsc_eh_timed_out, 1612 .eh_timed_out = storvsc_eh_timed_out,
1714 .slave_alloc = storvsc_device_alloc,
1715 .slave_destroy = storvsc_device_destroy,
1716 .slave_configure = storvsc_device_configure, 1613 .slave_configure = storvsc_device_configure,
1717 .cmd_per_lun = 255, 1614 .cmd_per_lun = 255,
1718 .can_queue = STORVSC_MAX_IO_REQUESTS*STORVSC_MAX_TARGETS, 1615 .can_queue = STORVSC_MAX_IO_REQUESTS*STORVSC_MAX_TARGETS,