From: "K. Y. Srinivasan" <kys@microsoft.com>
To: gregkh@suse.de, linux-kernel@vger.kernel.org,
devel@linuxdriverproject.org, virtualization@lists.osdl.org,
ohering@suse.com, James.Bottomley@HansenPartnership.com,
hch@infradead.org
Cc: "K. Y. Srinivasan" <kys@microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>
Subject: [PATCH 01/11] Staging: hv: storvsc: Use mempools to allocate struct storvsc_cmd_request
Date: Tue, 8 Nov 2011 09:01:40 -0800 [thread overview]
Message-ID: <1320771710-29139-1-git-send-email-kys@microsoft.com> (raw)
In-Reply-To: <1320771677-29095-1-git-send-email-kys@microsoft.com>
We intend to use the storage driver to manage the root device.
To avoid deadlocks, use mempools to allocate struct storvsc_cmd_request.
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
---
drivers/staging/hv/storvsc_drv.c | 30 +++++++++++++++++++++++++-----
1 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c
index ae8c33e..6a255e9 100644
--- a/drivers/staging/hv/storvsc_drv.c
+++ b/drivers/staging/hv/storvsc_drv.c
@@ -32,6 +32,7 @@
#include <linux/module.h>
#include <linux/device.h>
#include <linux/hyperv.h>
+#include <linux/mempool.h>
#include <scsi/scsi.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_host.h>
@@ -42,6 +43,7 @@
#include <scsi/scsi_dbg.h>
+#define STORVSC_MIN_BUF_NR 64
#define STORVSC_RING_BUFFER_SIZE (20*PAGE_SIZE)
static int storvsc_ringbuffer_size = STORVSC_RING_BUFFER_SIZE;
@@ -287,6 +289,7 @@ struct storvsc_device {
struct hv_host_device {
struct hv_device *dev;
struct kmem_cache *request_pool;
+ mempool_t *request_mempool;
unsigned int port;
unsigned char path;
unsigned char target;
@@ -974,8 +977,10 @@ static int storvsc_remove(struct hv_device *dev)
storvsc_dev_remove(dev);
if (host_dev->request_pool) {
+ mempool_destroy(host_dev->request_mempool);
kmem_cache_destroy(host_dev->request_pool);
host_dev->request_pool = NULL;
+ host_dev->request_mempool = NULL;
}
return 0;
}
@@ -1120,7 +1125,7 @@ static void storvsc_command_completion(struct hv_storvsc_request *request)
scsi_done_fn(scmnd);
- kmem_cache_free(host_dev->request_pool, cmd_request);
+ mempool_free(cmd_request, host_dev->request_mempool);
}
static bool storvsc_check_scsi_cmd(struct scsi_cmnd *scmnd)
@@ -1176,12 +1181,13 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd,
request_size = sizeof(struct storvsc_cmd_request);
- cmd_request = kmem_cache_zalloc(host_dev->request_pool,
+ cmd_request = mempool_alloc(host_dev->request_mempool,
GFP_ATOMIC);
if (!cmd_request) {
scmnd->scsi_done = NULL;
return SCSI_MLQUEUE_DEVICE_BUSY;
}
+ memset(cmd_request, 0, sizeof(struct storvsc_cmd_request));
/* Setup the cmd request */
cmd_request->bounce_sgl_count = 0;
@@ -1235,8 +1241,8 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd,
if (!cmd_request->bounce_sgl) {
scmnd->scsi_done = NULL;
scmnd->host_scribble = NULL;
- kmem_cache_free(host_dev->request_pool,
- cmd_request);
+ mempool_free(cmd_request,
+ host_dev->request_mempool);
return SCSI_MLQUEUE_HOST_BUSY;
}
@@ -1278,7 +1284,7 @@ retry_request:
destroy_bounce_buffer(cmd_request->bounce_sgl,
cmd_request->bounce_sgl_count);
- kmem_cache_free(host_dev->request_pool, cmd_request);
+ mempool_free(cmd_request, host_dev->request_mempool);
scmnd->scsi_done = NULL;
scmnd->host_scribble = NULL;
@@ -1348,6 +1354,7 @@ static int storvsc_probe(struct hv_device *device,
const struct hv_vmbus_device_id *dev_id)
{
int ret;
+ int number = STORVSC_MIN_BUF_NR;
struct Scsi_Host *host;
struct hv_host_device *host_dev;
bool dev_is_ide = ((dev_id->driver_data == IDE_GUID) ? true : false);
@@ -1376,8 +1383,19 @@ static int storvsc_probe(struct hv_device *device,
return -ENOMEM;
}
+ host_dev->request_mempool = mempool_create(number, mempool_alloc_slab,
+ mempool_free_slab,
+ host_dev->request_pool);
+
+ if (!host_dev->request_mempool) {
+ kmem_cache_destroy(host_dev->request_pool);
+ scsi_host_put(host);
+ return -ENOMEM;
+ }
+
stor_device = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);
if (!stor_device) {
+ mempool_destroy(host_dev->request_mempool);
kmem_cache_destroy(host_dev->request_pool);
scsi_host_put(host);
return -ENOMEM;
@@ -1392,6 +1410,7 @@ static int storvsc_probe(struct hv_device *device,
stor_device->port_number = host->host_no;
ret = storvsc_connect_to_vsp(device, storvsc_ringbuffer_size);
if (ret) {
+ mempool_destroy(host_dev->request_mempool);
kmem_cache_destroy(host_dev->request_pool);
scsi_host_put(host);
kfree(stor_device);
@@ -1431,6 +1450,7 @@ static int storvsc_probe(struct hv_device *device,
err_out:
storvsc_dev_remove(device);
+ mempool_destroy(host_dev->request_mempool);
kmem_cache_destroy(host_dev->request_pool);
scsi_host_put(host);
return -ENODEV;
--
1.7.4.1
next prev parent reply other threads:[~2011-11-08 16:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-08 17:01 [PATCH 0000/0011] Staging: hv: storvsc cleanup/new features K. Y. Srinivasan
2011-11-08 16:39 ` James Bottomley
2011-11-08 16:46 ` KY Srinivasan
2011-11-08 17:01 ` K. Y. Srinivasan [this message]
2011-11-08 17:01 ` [PATCH 02/11] Staging: hv: storvsc: Cleanup error handling in the probe function K. Y. Srinivasan
2011-11-08 17:01 ` [PATCH 03/11] Staging: hv: storvsc: Fixup the error when processing SET_WINDOW command K. Y. Srinivasan
2011-11-08 17:01 ` [PATCH 04/11] Staging: hv: storvsc: Fix error handling storvsc_host_reset() K. Y. Srinivasan
2011-11-08 17:01 ` [PATCH 05/11] Staging: hv: storvsc: Use the accessor function shost_priv() K. Y. Srinivasan
2011-11-08 17:01 ` [PATCH 06/11] Staging: hv: storvsc: Use the unlocked version queuecommand K. Y. Srinivasan
2011-11-08 17:01 ` [PATCH 07/11] Staging: hv: storvsc: use the macro KBUILD_MODNAME K. Y. Srinivasan
2011-11-08 17:01 ` [PATCH 08/11] Staging: hv: storvsc: Get rid of an unnecessary forward declaration K. Y. Srinivasan
2011-11-08 17:01 ` [PATCH 09/11] Staging: hv: storvsc: Upgrade the vmstor protocol version K. Y. Srinivasan
2011-11-08 17:01 ` [PATCH 10/11] Staging: hv: storvsc: Support hot add of scsi disks K. Y. Srinivasan
2011-11-08 17:01 ` [PATCH 11/11] Staging: hv: storvsc: Support hot-removing of scsi devices K. Y. Srinivasan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1320771710-29139-1-git-send-email-kys@microsoft.com \
--to=kys@microsoft.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=devel@linuxdriverproject.org \
--cc=gregkh@suse.de \
--cc=haiyangz@microsoft.com \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ohering@suse.com \
--cc=virtualization@lists.osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®