dahdi: Add module parameter to limit number of pseudo channels.
Since there isn't a fixed array to hold all the channels, and also limit the total number of channels that can be created, we'll add a module parameter to allow the system administrator to specify the maximum number of pseudo channels. This is to prevent a potentially non-privledged process from consuming too much CPU (since all pseudos are checked each "tick" for conferencing) and kernel memory. By default the number of pseudo channels is limited to 512. Change the default limit with: ]# modprobe dahdi max_pseudo_channels=<new limit> or at runtime with: ]# echo <new limit> > /sys/module/dahdi/parameters/max_psuedo_channels Signed-off-by: Shaun Ruffell <sruffell@digium.com> Acked-by: Kinsey Moore <kmoore@digium.com> git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@9610 a0bf4364-ded3-4de4-8d8a-66a801d63aff
This commit is contained in:
parent
579ea560ef
commit
e5cbedbf37
5
README
5
README
@ -437,6 +437,11 @@ deftaps (dahdi)::
|
|||||||
different default size. So normally setting this doesn't change
|
different default size. So normally setting this doesn't change
|
||||||
anything.
|
anything.
|
||||||
|
|
||||||
|
max_pseudo_channels (dahdi)::
|
||||||
|
The maximum number of pseudo channels that dahdi will allow userspace to
|
||||||
|
create. Pseudo channels are used when conferencing channels together.
|
||||||
|
The default is 512.
|
||||||
|
|
||||||
To get a list of parameters supported by a module, use
|
To get a list of parameters supported by a module, use
|
||||||
|
|
||||||
modinfo module_name
|
modinfo module_name
|
||||||
|
@ -3003,7 +3003,10 @@ static int can_open_timer(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct dahdi_chan *dahdi_alloc_pseudo(void)
|
static unsigned int max_pseudo_channels = 512;
|
||||||
|
static unsigned int num_pseudo_channels;
|
||||||
|
|
||||||
|
static struct dahdi_chan *dahdi_alloc_pseudo(struct file *file)
|
||||||
{
|
{
|
||||||
struct pseudo_chan *pseudo;
|
struct pseudo_chan *pseudo;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
@ -3016,6 +3019,9 @@ static struct dahdi_chan *dahdi_alloc_pseudo(void)
|
|||||||
if (!can_open_timer())
|
if (!can_open_timer())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (unlikely(num_pseudo_channels >= max_pseudo_channels))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
pseudo = kzalloc(sizeof(*pseudo), GFP_KERNEL);
|
pseudo = kzalloc(sizeof(*pseudo), GFP_KERNEL);
|
||||||
if (NULL == pseudo)
|
if (NULL == pseudo)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -3059,9 +3065,12 @@ static struct dahdi_chan *dahdi_alloc_pseudo(void)
|
|||||||
snprintf(pseudo->chan.name, sizeof(pseudo->chan.name)-1,
|
snprintf(pseudo->chan.name, sizeof(pseudo->chan.name)-1,
|
||||||
"Pseudo/%d", pseudo->chan.channo);
|
"Pseudo/%d", pseudo->chan.channo);
|
||||||
|
|
||||||
|
file->private_data = &pseudo->chan;
|
||||||
|
|
||||||
/* Once we place the pseudo chan on the list...it's registered and
|
/* Once we place the pseudo chan on the list...it's registered and
|
||||||
* live. */
|
* live. */
|
||||||
spin_lock_irqsave(&chan_lock, flags);
|
spin_lock_irqsave(&chan_lock, flags);
|
||||||
|
++num_pseudo_channels;
|
||||||
list_add(&pseudo->node, pos);
|
list_add(&pseudo->node, pos);
|
||||||
spin_unlock_irqrestore(&chan_lock, flags);
|
spin_unlock_irqrestore(&chan_lock, flags);
|
||||||
|
|
||||||
@ -3082,6 +3091,7 @@ static void dahdi_free_pseudo(struct dahdi_chan *chan)
|
|||||||
|
|
||||||
spin_lock_irqsave(&chan_lock, flags);
|
spin_lock_irqsave(&chan_lock, flags);
|
||||||
list_del(&pseudo->node);
|
list_del(&pseudo->node);
|
||||||
|
--num_pseudo_channels;
|
||||||
spin_unlock_irqrestore(&chan_lock, flags);
|
spin_unlock_irqrestore(&chan_lock, flags);
|
||||||
|
|
||||||
dahdi_chan_unreg(chan);
|
dahdi_chan_unreg(chan);
|
||||||
@ -3127,13 +3137,10 @@ static int dahdi_open(struct inode *inode, struct file *file)
|
|||||||
if (unit == DAHDI_CHANNEL)
|
if (unit == DAHDI_CHANNEL)
|
||||||
return dahdi_chan_open(file);
|
return dahdi_chan_open(file);
|
||||||
if (unit == DAHDI_PSEUDO) {
|
if (unit == DAHDI_PSEUDO) {
|
||||||
chan = dahdi_alloc_pseudo();
|
chan = dahdi_alloc_pseudo(file);
|
||||||
if (chan) {
|
if (unlikely(!chan))
|
||||||
file->private_data = chan;
|
return -ENOMEM;
|
||||||
return dahdi_specchan_open(file);
|
return dahdi_specchan_open(file);
|
||||||
} else {
|
|
||||||
return -ENXIO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return dahdi_specchan_open(file);
|
return dahdi_specchan_open(file);
|
||||||
}
|
}
|
||||||
@ -9050,6 +9057,9 @@ MODULE_PARM_DESC(debug, "Sets debugging verbosity as a bitfield, to see"\
|
|||||||
" this to 32");
|
" this to 32");
|
||||||
module_param(deftaps, int, 0644);
|
module_param(deftaps, int, 0644);
|
||||||
|
|
||||||
|
module_param(max_pseudo_channels, int, 0644);
|
||||||
|
MODULE_PARM_DESC(max_pseudo_channels, "Maximum number of pseudo channels.");
|
||||||
|
|
||||||
static const struct file_operations dahdi_fops = {
|
static const struct file_operations dahdi_fops = {
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.open = dahdi_open,
|
.open = dahdi_open,
|
||||||
|
Loading…
Reference in New Issue
Block a user