Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 89683
b: refs/heads/master
c: e507e30
h: refs/heads/master
i:
  89681: c6d4c89
  89679: 853edad
v: v3
  • Loading branch information
James Bottomley authored and James Bottomley committed Apr 7, 2008
1 parent b4c6c64 commit 0efc485
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 33 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 035f5e06515a66827015202685e457a5534441b7
refs/heads/master: e507e30b803fb56d768ed9a597e7609b74d2db21
82 changes: 50 additions & 32 deletions trunk/drivers/scsi/scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,51 @@ static struct scsi_host_cmd_pool scsi_cmd_dma_pool = {

static DEFINE_MUTEX(host_cmd_pool_mutex);

/**
* scsi_pool_alloc_command - internal function to get a fully allocated command
* @pool: slab pool to allocate the command from
* @gfp_mask: mask for the allocation
*
* Returns a fully allocated command (with the allied sense buffer) or
* NULL on failure
*/
static struct scsi_cmnd *
scsi_pool_alloc_command(struct scsi_host_cmd_pool *pool, gfp_t gfp_mask)
{
struct scsi_cmnd *cmd;

cmd = kmem_cache_alloc(pool->cmd_slab, gfp_mask | pool->gfp_mask);
if (!cmd)
return NULL;

memset(cmd, 0, sizeof(*cmd));

cmd->sense_buffer = kmem_cache_alloc(pool->sense_slab,
gfp_mask | pool->gfp_mask);
if (!cmd->sense_buffer) {
kmem_cache_free(pool->cmd_slab, cmd);
return NULL;
}

return cmd;
}

/**
* scsi_pool_free_command - internal function to release a command
* @pool: slab pool to allocate the command from
* @cmd: command to release
*
* the command must previously have been allocated by
* scsi_pool_alloc_command.
*/
static void
scsi_pool_free_command(struct scsi_host_cmd_pool *pool,
struct scsi_cmnd *cmd)
{
kmem_cache_free(pool->sense_slab, cmd->sense_buffer);
kmem_cache_free(pool->cmd_slab, cmd);
}

/**
* __scsi_get_command - Allocate a struct scsi_cmnd
* @shost: host to transmit command
Expand All @@ -178,20 +223,7 @@ struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *shost, gfp_t gfp_mask)
struct scsi_cmnd *cmd;
unsigned char *buf;

cmd = kmem_cache_alloc(shost->cmd_pool->cmd_slab,
gfp_mask | shost->cmd_pool->gfp_mask);

if (likely(cmd)) {
buf = kmem_cache_alloc(shost->cmd_pool->sense_slab,
gfp_mask | shost->cmd_pool->gfp_mask);
if (likely(buf)) {
memset(cmd, 0, sizeof(*cmd));
cmd->sense_buffer = buf;
} else {
kmem_cache_free(shost->cmd_pool->cmd_slab, cmd);
cmd = NULL;
}
}
cmd = scsi_pool_alloc_command(shost->cmd_pool, gfp_mask);

if (unlikely(!cmd)) {
unsigned long flags;
Expand Down Expand Up @@ -268,11 +300,8 @@ void __scsi_put_command(struct Scsi_Host *shost, struct scsi_cmnd *cmd,
}
spin_unlock_irqrestore(&shost->free_list_lock, flags);

if (likely(cmd != NULL)) {
kmem_cache_free(shost->cmd_pool->sense_slab,
cmd->sense_buffer);
kmem_cache_free(shost->cmd_pool->cmd_slab, cmd);
}
if (likely(cmd != NULL))
scsi_pool_free_command(shost->cmd_pool, cmd);

put_device(dev);
}
Expand Down Expand Up @@ -348,23 +377,14 @@ int scsi_setup_command_freelist(struct Scsi_Host *shost)
/*
* Get one backup command for this host.
*/
cmd = kmem_cache_alloc(shost->cmd_pool->cmd_slab,
GFP_KERNEL | shost->cmd_pool->gfp_mask);
cmd = scsi_pool_alloc_command(shost->cmd_pool, GFP_KERNEL);
if (!cmd)
goto fail2;

cmd->sense_buffer = kmem_cache_alloc(shost->cmd_pool->sense_slab,
GFP_KERNEL |
shost->cmd_pool->gfp_mask);
if (!cmd->sense_buffer)
goto fail2;

list_add(&cmd->list, &shost->free_list);
return 0;

fail2:
if (cmd)
kmem_cache_free(shost->cmd_pool->cmd_slab, cmd);
mutex_lock(&host_cmd_pool_mutex);
if (!--pool->users) {
kmem_cache_destroy(pool->cmd_slab);
Expand All @@ -386,9 +406,7 @@ void scsi_destroy_command_freelist(struct Scsi_Host *shost)

cmd = list_entry(shost->free_list.next, struct scsi_cmnd, list);
list_del_init(&cmd->list);
kmem_cache_free(shost->cmd_pool->sense_slab,
cmd->sense_buffer);
kmem_cache_free(shost->cmd_pool->cmd_slab, cmd);
scsi_pool_free_command(shost->cmd_pool, cmd);
}

mutex_lock(&host_cmd_pool_mutex);
Expand Down

0 comments on commit 0efc485

Please sign in to comment.