Remove ctl_mem_pool.{c,h}.

Sponsored by:	The FreeBSD Foundation
This commit is contained in:
trasz 2014-03-27 11:10:13 +00:00
parent b46b2184f0
commit 427a2d21c4
7 changed files with 19 additions and 432 deletions

View File

@ -394,14 +394,6 @@ ctl_ioctl.h:
This defines all ioctls available through the CTL character device, and
the data structures needed for those ioctls.
ctl_mem_pool.c
ctl_mem_pool.h:
--------------
Generic memory pool implementation. This is currently only used by the
internal frontend. The internal frontend can probably be rewritten to use
UMA zones and this can be removed.
ctl_private.h:
-------------

View File

@ -65,7 +65,6 @@ __FBSDID("$FreeBSD$");
#include <cam/ctl/ctl.h>
#include <cam/ctl/ctl_frontend.h>
#include <cam/ctl/ctl_frontend_internal.h>
#include <cam/ctl/ctl_mem_pool.h>
#include <cam/ctl/ctl_debug.h>
#define io_ptr spriv_ptr1

View File

@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$");
#include <sys/queue.h>
#include <sys/sbuf.h>
#include <sys/sysctl.h>
#include <vm/uma.h>
#include <cam/scsi/scsi_all.h>
#include <cam/scsi/scsi_da.h>
#include <cam/ctl/ctl_io.h>
@ -73,7 +74,6 @@ __FBSDID("$FreeBSD$");
#include <cam/ctl/ctl_util.h>
#include <cam/ctl/ctl_ha.h>
#include <cam/ctl/ctl_private.h>
#include <cam/ctl/ctl_mem_pool.h>
#include <cam/ctl/ctl_debug.h>
#include <cam/ctl/ctl_scsi_all.h>
#include <cam/ctl/ctl_error.h>
@ -118,7 +118,6 @@ struct cfi_metatask {
cfi_tasktype tasktype;
cfi_mt_status status;
union cfi_taskinfo taskinfo;
struct ctl_mem_element *element;
void *cfi_context;
STAILQ_ENTRY(cfi_metatask) links;
};
@ -153,7 +152,6 @@ struct cfi_lun {
int blocksize_powerof2;
uint32_t cur_tag_num;
cfi_lun_state state;
struct ctl_mem_element *element;
struct cfi_softc *softc;
STAILQ_HEAD(, cfi_lun_io) io_list;
STAILQ_ENTRY(cfi_lun) links;
@ -181,12 +179,13 @@ struct cfi_softc {
cfi_flags flags;
STAILQ_HEAD(, cfi_lun) lun_list;
STAILQ_HEAD(, cfi_metatask) metatask_list;
struct ctl_mem_pool lun_pool;
struct ctl_mem_pool metatask_pool;
};
MALLOC_DEFINE(M_CTL_CFI, "ctlcfi", "CTL CFI");
static uma_zone_t cfi_lun_zone;
static uma_zone_t cfi_metatask_zone;
static struct cfi_softc fetd_internal_softc;
int cfi_init(void);
@ -275,48 +274,15 @@ cfi_init(void)
if (ctl_frontend_register(fe, (softc->flags & CTL_FLAG_MASTER_SHELF)) != 0)
{
printf("%s: internal frontend registration failed\n", __func__);
retval = 1;
goto bailout;
return (0);
}
if (ctl_init_mem_pool(&softc->lun_pool,
sizeof(struct cfi_lun),
CTL_MEM_POOL_PERM_GROW, /*grow_inc*/ 3,
/* initial_pool_size */ CTL_MAX_LUNS) != 0) {
printf("%s: can't initialize LUN memory pool\n", __func__);
retval = 1;
goto bailout_error;
}
if (ctl_init_mem_pool(&softc->metatask_pool,
sizeof(struct cfi_metatask),
CTL_MEM_POOL_PERM_GROW, /*grow_inc*/ 3,
/*initial_pool_size*/ 10) != 0) {
printf("%s: can't initialize metatask memory pool\n", __func__);
retval = 2;
goto bailout_error;
}
bailout:
cfi_lun_zone = uma_zcreate("cfi_lun", sizeof(struct cfi_lun),
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
cfi_metatask_zone = uma_zcreate("cfi_metatask", sizeof(struct cfi_metatask),
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
return (0);
bailout_error:
switch (retval) {
case 3:
ctl_shrink_mem_pool(&softc->metatask_pool);
/* FALLTHROUGH */
case 2:
ctl_shrink_mem_pool(&softc->lun_pool);
/* FALLTHROUGH */
case 1:
ctl_frontend_deregister(fe);
break;
default:
break;
}
return (ENOMEM);
}
void
@ -332,11 +298,8 @@ cfi_shutdown(void)
if (ctl_frontend_deregister(&softc->fe) != 0)
printf("%s: ctl_frontend_deregister() failed\n", __func__);
if (ctl_shrink_mem_pool(&softc->lun_pool) != 0)
printf("%s: error shrinking LUN pool\n", __func__);
if (ctl_shrink_mem_pool(&softc->metatask_pool) != 0)
printf("%s: error shrinking LUN pool\n", __func__);
uma_zdestroy(cfi_lun_zone);
uma_zdestroy(cfi_metatask_zone);
}
static int
@ -398,7 +361,6 @@ cfi_targ_disable(void *arg, struct ctl_id targ_id)
static int
cfi_lun_enable(void *arg, struct ctl_id target_id, int lun_id)
{
struct ctl_mem_element *element;
struct cfi_softc *softc;
struct cfi_lun *lun;
int found;
@ -423,16 +385,12 @@ cfi_lun_enable(void *arg, struct ctl_id target_id, int lun_id)
if (found != 0)
return (0);
element = ctl_alloc_mem_element(&softc->lun_pool, /*can_wait*/ 0);
if (element == NULL) {
lun = uma_zalloc(cfi_lun_zone, M_NOWAIT | M_ZERO);
if (lun == NULL) {
printf("%s: unable to allocate LUN structure\n", __func__);
return (1);
}
lun = (struct cfi_lun *)element->bytes;
lun->element = element;
lun->target_id = target_id;
lun->lun_id = lun_id;
lun->cur_tag_num = 0;
@ -485,7 +443,7 @@ cfi_lun_disable(void *arg, struct ctl_id target_id, int lun_id)
return (1);
}
ctl_free_mem_element(lun->element);
uma_zfree(cfi_lun_zone, lun);
return (0);
}
@ -1682,106 +1640,20 @@ cfi_action(struct cfi_metatask *metatask)
}
}
#ifdef oldapi
void
cfi_shutdown_shelf(cfi_cb_t callback, void *callback_arg)
{
struct ctl_mem_element *element;
struct cfi_softc *softc;
struct cfi_metatask *metatask;
softc = &fetd_internal_softc;
element = ctl_alloc_mem_element(&softc->metatask_pool, /*can_wait*/ 0);
if (element == NULL) {
callback(callback_arg,
/*status*/ CFI_MT_ERROR,
/*sluns_found*/ 0,
/*sluns_complete*/ 0,
/*sluns_failed*/ 0);
return;
}
metatask = (struct cfi_metatask *)element->bytes;
memset(metatask, 0, sizeof(*metatask));
metatask->tasktype = CFI_TASK_SHUTDOWN;
metatask->status = CFI_MT_NONE;
metatask->taskinfo.startstop.callback = callback;
metatask->taskinfo.startstop.callback_arg = callback_arg;
metatask->element = element;
cfi_action(softc, metatask);
/*
* - send a report luns to lun 0, get LUN list.
* - send an inquiry to each lun
* - send a stop/offline to each direct access LUN
* - if we get a reservation conflict, reset the LUN and then
* retry sending the stop/offline
* - return status back to the caller
*/
}
void
cfi_start_shelf(cfi_cb_t callback, void *callback_arg)
{
struct ctl_mem_element *element;
struct cfi_softc *softc;
struct cfi_metatask *metatask;
softc = &fetd_internal_softc;
element = ctl_alloc_mem_element(&softc->metatask_pool, /*can_wait*/ 0);
if (element == NULL) {
callback(callback_arg,
/*status*/ CFI_MT_ERROR,
/*sluns_found*/ 0,
/*sluns_complete*/ 0,
/*sluns_failed*/ 0);
return;
}
metatask = (struct cfi_metatask *)element->bytes;
memset(metatask, 0, sizeof(*metatask));
metatask->tasktype = CFI_TASK_STARTUP;
metatask->status = CFI_MT_NONE;
metatask->taskinfo.startstop.callback = callback;
metatask->taskinfo.startstop.callback_arg = callback_arg;
metatask->element = element;
cfi_action(softc, metatask);
/*
* - send a report luns to lun 0, get LUN list.
* - send an inquiry to each lun
* - send a stop/offline to each direct access LUN
* - if we get a reservation conflict, reset the LUN and then
* retry sending the stop/offline
* - return status back to the caller
*/
}
#endif
struct cfi_metatask *
cfi_alloc_metatask(int can_wait)
{
struct ctl_mem_element *element;
struct cfi_metatask *metatask;
struct cfi_softc *softc;
softc = &fetd_internal_softc;
element = ctl_alloc_mem_element(&softc->metatask_pool, can_wait);
if (element == NULL)
metatask = uma_zalloc(cfi_metatask_zone,
(can_wait ? M_WAITOK : M_NOWAIT) | M_ZERO);
if (metatask == NULL)
return (NULL);
metatask = (struct cfi_metatask *)element->bytes;
memset(metatask, 0, sizeof(*metatask));
metatask->status = CFI_MT_NONE;
metatask->element = element;
return (metatask);
}
@ -1789,7 +1661,8 @@ cfi_alloc_metatask(int can_wait)
void
cfi_free_metatask(struct cfi_metatask *metatask)
{
ctl_free_mem_element(metatask->element);
uma_zfree(cfi_metatask_zone, metatask);
}
/*

View File

@ -1,192 +0,0 @@
/*-
* Copyright (c) 2003, 2004 Silicon Graphics International Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_mem_pool.c#1 $
*/
/*
* CAM Target Layer memory pool code.
*
* Author: Ken Merry <ken@FreeBSD.org>
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/types.h>
#include <sys/malloc.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/queue.h>
#include <cam/ctl/ctl_mem_pool.h>
MALLOC_DEFINE(M_CTL_POOL, "ctlpool", "CTL memory pool");
int
ctl_init_mem_pool(struct ctl_mem_pool *pool, int chunk_size,
ctl_mem_pool_flags flags, int grow_inc,
int initial_pool_size)
{
pool->flags = flags;
pool->chunk_size = chunk_size;
pool->grow_inc = grow_inc;
mtx_init(&pool->lock, "Pool mutex", NULL, MTX_DEF);
STAILQ_INIT(&pool->free_mem_list);
cv_init(&pool->wait_mem, "CTL mem pool");
if (ctl_grow_mem_pool(pool, initial_pool_size, /*can_wait*/ 1) !=
initial_pool_size)
return (1);
else
return (0);
}
struct ctl_mem_element *
ctl_alloc_mem_element(struct ctl_mem_pool *pool, int can_wait)
{
struct ctl_mem_element *mem;
for (;;) {
mtx_lock(&pool->lock);
mem = STAILQ_FIRST(&pool->free_mem_list);
if (mem != NULL) {
STAILQ_REMOVE(&pool->free_mem_list, mem,
ctl_mem_element, links);
mem->flags = CTL_MEM_ELEMENT_PREALLOC;
}
mtx_unlock(&pool->lock);
if (mem != NULL)
return (mem);
/*
* Grow the pool permanantly by the requested increment
* instead of temporarily. This has the effect that
* whatever the high water mark of transactions is for
* this pool, we'll keep that much memory around.
*/
if (pool->flags & CTL_MEM_POOL_PERM_GROW) {
if (ctl_grow_mem_pool(pool, pool->grow_inc,
can_wait) != 0)
continue;
}
mem = (struct ctl_mem_element *)malloc(sizeof(*mem),
M_CTL_POOL, can_wait ? M_WAITOK : M_NOWAIT);
if (mem != NULL) {
mem->flags = CTL_MEM_ELEMENT_NONE;
mem->pool = pool;
mem->bytes = malloc(pool->chunk_size, M_CTL_POOL,
can_wait ? M_WAITOK : M_NOWAIT);
if (mem->bytes == NULL) {
free(mem, M_CTL_POOL);
mem = NULL;
} else {
return (mem);
}
}
if (can_wait == 0)
return (NULL);
cv_wait_unlock(&pool->wait_mem, &pool->lock);
}
}
void
ctl_free_mem_element(struct ctl_mem_element *mem)
{
struct ctl_mem_pool *pool;
pool = mem->pool;
if (mem->flags & CTL_MEM_ELEMENT_PREALLOC) {
mtx_lock(&pool->lock);
STAILQ_INSERT_TAIL(&pool->free_mem_list, mem, links);
mtx_unlock(&pool->lock);
cv_broadcast(&pool->wait_mem);
} else
free(mem, M_CTL_POOL);
}
int
ctl_grow_mem_pool(struct ctl_mem_pool *pool, int count, int can_wait)
{
int i;
for (i = 0; i < count; i++) {
struct ctl_mem_element *mem;
mem = (struct ctl_mem_element *)malloc(sizeof(*mem),
M_CTL_POOL, can_wait ? M_WAITOK : M_NOWAIT);
if (mem == NULL)
break;
mem->bytes = malloc(pool->chunk_size, M_CTL_POOL, can_wait ?
M_WAITOK : M_NOWAIT);
if (mem->bytes == NULL) {
free(mem, M_CTL_POOL);
break;
}
mem->flags = CTL_MEM_ELEMENT_PREALLOC;
mem->pool = pool;
mtx_lock(&pool->lock);
STAILQ_INSERT_TAIL(&pool->free_mem_list, mem, links);
mtx_unlock(&pool->lock);
}
return (i);
}
int
ctl_shrink_mem_pool(struct ctl_mem_pool *pool)
{
struct ctl_mem_element *mem, *mem_next;
mtx_lock(&pool->lock);
for (mem = STAILQ_FIRST(&pool->free_mem_list); mem != NULL;
mem = mem_next) {
mem_next = STAILQ_NEXT(mem, links);
STAILQ_REMOVE(&pool->free_mem_list, mem, ctl_mem_element,
links);
free(mem->bytes, M_CTL_POOL);
free(mem, M_CTL_POOL);
}
mtx_unlock(&pool->lock);
return (0);
}

View File

@ -1,83 +0,0 @@
/*-
* Copyright (c) 2003, 2004 Silicon Graphics International Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_mem_pool.h#1 $
* $FreeBSD$
*/
/*
* CAM Target Layer memory pool code.
*
* Author: Ken Merry <ken@FreeBSD.org>
*/
#ifndef _CTL_MEMPOOL_H_
#define _CTL_MEMPOOL_H_
typedef enum {
CTL_MEM_POOL_NONE,
CTL_MEM_POOL_PERM_GROW
} ctl_mem_pool_flags;
struct ctl_mem_pool {
ctl_mem_pool_flags flags;
int chunk_size;
int grow_inc;
struct mtx lock;
struct cv wait_mem;
STAILQ_HEAD(, ctl_mem_element) free_mem_list;
};
typedef enum {
CTL_MEM_ELEMENT_NONE,
CTL_MEM_ELEMENT_PREALLOC
} ctl_mem_element_flags;
struct ctl_mem_element {
ctl_mem_element_flags flags;
struct ctl_mem_pool *pool;
uint8_t *bytes;
STAILQ_ENTRY(ctl_mem_element) links;
};
#ifdef _KERNEL
MALLOC_DECLARE(M_CTL_POOL);
int ctl_init_mem_pool(struct ctl_mem_pool *pool, int chunk_size,
ctl_mem_pool_flags flags, int grow_inc,
int initial_pool_size);
struct ctl_mem_element *ctl_alloc_mem_element(struct ctl_mem_pool *pool,
int can_wait);
void ctl_free_mem_element(struct ctl_mem_element *mem);
int ctl_grow_mem_pool(struct ctl_mem_pool *pool, int count,
int can_wait);
int ctl_shrink_mem_pool(struct ctl_mem_pool *pool);
#endif /* _KERNEL */
#endif /* _CTL_MEMPOOL_H_ */

View File

@ -85,7 +85,6 @@ cam/ctl/ctl_frontend.c optional ctl
cam/ctl/ctl_frontend_cam_sim.c optional ctl
cam/ctl/ctl_frontend_internal.c optional ctl
cam/ctl/ctl_frontend_iscsi.c optional ctl
cam/ctl/ctl_mem_pool.c optional ctl
cam/ctl/ctl_scsi_all.c optional ctl
cam/ctl/ctl_error.c optional ctl
cam/ctl/ctl_util.c optional ctl

View File

@ -13,7 +13,6 @@ SRCS+= ctl_frontend.c
SRCS+= ctl_frontend_cam_sim.c
SRCS+= ctl_frontend_internal.c
SRCS+= ctl_frontend_iscsi.c
SRCS+= ctl_mem_pool.c
SRCS+= ctl_scsi_all.c
SRCS+= ctl_error.c
SRCS+= ctl_util.c