2005-04-17 06:20:36 +08:00
|
|
|
/* $Id: divert_procfs.c,v 1.11.6.2 2001/09/23 22:24:36 kai Exp $
|
|
|
|
*
|
|
|
|
* Filesystem handling for the diversion supplementary services.
|
|
|
|
*
|
|
|
|
* Copyright 1998 by Werner Cornelius (werner@isdn4linux.de)
|
|
|
|
*
|
|
|
|
* This software may be used and distributed according to the terms
|
|
|
|
* of the GNU General Public License, incorporated herein by reference.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/poll.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#else
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#endif
|
2009-10-04 20:11:37 +08:00
|
|
|
#include <linux/sched.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/isdnif.h>
|
2007-09-12 18:01:34 +08:00
|
|
|
#include <net/net_namespace.h>
|
2010-07-11 19:18:53 +08:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "isdn_divert.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************/
|
|
|
|
/* Variables for interface queue */
|
|
|
|
/*********************************/
|
|
|
|
ulong if_used = 0; /* number of interface users */
|
2010-07-11 19:18:53 +08:00
|
|
|
static DEFINE_MUTEX(isdn_divert_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct divert_info *divert_info_head = NULL; /* head of queue */
|
|
|
|
static struct divert_info *divert_info_tail = NULL; /* pointer to last entry */
|
|
|
|
static DEFINE_SPINLOCK(divert_info_lock);/* lock for queue */
|
|
|
|
static wait_queue_head_t rd_queue;
|
|
|
|
|
|
|
|
/*********************************/
|
|
|
|
/* put an info buffer into queue */
|
|
|
|
/*********************************/
|
|
|
|
void
|
|
|
|
put_info_buffer(char *cp)
|
|
|
|
{
|
|
|
|
struct divert_info *ib;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (if_used <= 0)
|
|
|
|
return;
|
|
|
|
if (!cp)
|
|
|
|
return;
|
|
|
|
if (!*cp)
|
|
|
|
return;
|
2006-12-13 16:35:56 +08:00
|
|
|
if (!(ib = kmalloc(sizeof(struct divert_info) + strlen(cp), GFP_ATOMIC)))
|
2012-02-20 11:52:38 +08:00
|
|
|
return; /* no memory */
|
2005-04-17 06:20:36 +08:00
|
|
|
strcpy(ib->info_start, cp); /* set output string */
|
|
|
|
ib->next = NULL;
|
2012-02-20 11:52:38 +08:00
|
|
|
spin_lock_irqsave(&divert_info_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
ib->usage_cnt = if_used;
|
|
|
|
if (!divert_info_head)
|
|
|
|
divert_info_head = ib; /* new head */
|
|
|
|
else
|
|
|
|
divert_info_tail->next = ib; /* follows existing messages */
|
|
|
|
divert_info_tail = ib; /* new tail */
|
|
|
|
|
|
|
|
/* delete old entrys */
|
|
|
|
while (divert_info_head->next) {
|
|
|
|
if ((divert_info_head->usage_cnt <= 0) &&
|
|
|
|
(divert_info_head->next->usage_cnt <= 0)) {
|
|
|
|
ib = divert_info_head;
|
|
|
|
divert_info_head = divert_info_head->next;
|
|
|
|
kfree(ib);
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
} /* divert_info_head->next */
|
2012-02-20 11:52:38 +08:00
|
|
|
spin_unlock_irqrestore(&divert_info_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
wake_up_interruptible(&(rd_queue));
|
|
|
|
} /* put_info_buffer */
|
|
|
|
|
2007-07-31 15:39:45 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**********************************/
|
|
|
|
/* deflection device read routine */
|
|
|
|
/**********************************/
|
|
|
|
static ssize_t
|
2012-02-20 11:52:38 +08:00
|
|
|
isdn_divert_read(struct file *file, char __user *buf, size_t count, loff_t *off)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct divert_info *inf;
|
|
|
|
int len;
|
|
|
|
|
2014-02-26 19:01:54 +08:00
|
|
|
if (!(inf = *((struct divert_info **) file->private_data))) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (file->f_flags & O_NONBLOCK)
|
|
|
|
return -EAGAIN;
|
2014-02-26 19:01:54 +08:00
|
|
|
wait_event_interruptible(rd_queue, (inf =
|
|
|
|
*((struct divert_info **) file->private_data)));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2014-02-26 19:01:54 +08:00
|
|
|
if (!inf)
|
2005-04-17 06:20:36 +08:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
inf->usage_cnt--; /* new usage count */
|
|
|
|
file->private_data = &inf->next; /* next structure */
|
|
|
|
if ((len = strlen(inf->info_start)) <= count) {
|
|
|
|
if (copy_to_user(buf, inf->info_start, len))
|
|
|
|
return -EFAULT;
|
|
|
|
*off += len;
|
|
|
|
return (len);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
} /* isdn_divert_read */
|
|
|
|
|
|
|
|
/**********************************/
|
|
|
|
/* deflection device write routine */
|
|
|
|
/**********************************/
|
|
|
|
static ssize_t
|
2012-02-20 11:52:38 +08:00
|
|
|
isdn_divert_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
return (-ENODEV);
|
|
|
|
} /* isdn_divert_write */
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************/
|
|
|
|
/* select routines for various kernels */
|
|
|
|
/***************************************/
|
2017-07-03 18:39:46 +08:00
|
|
|
static __poll_t
|
2012-02-20 11:52:38 +08:00
|
|
|
isdn_divert_poll(struct file *file, poll_table *wait)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-07-03 18:39:46 +08:00
|
|
|
__poll_t mask = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
poll_wait(file, &(rd_queue), wait);
|
2018-02-12 06:34:03 +08:00
|
|
|
/* mask = EPOLLOUT | EPOLLWRNORM; */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (*((struct divert_info **) file->private_data)) {
|
2018-02-12 06:34:03 +08:00
|
|
|
mask |= EPOLLIN | EPOLLRDNORM;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return mask;
|
|
|
|
} /* isdn_divert_poll */
|
|
|
|
|
|
|
|
/****************/
|
|
|
|
/* Open routine */
|
|
|
|
/****************/
|
|
|
|
static int
|
|
|
|
isdn_divert_open(struct inode *ino, struct file *filep)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2012-02-20 11:52:38 +08:00
|
|
|
spin_lock_irqsave(&divert_info_lock, flags);
|
|
|
|
if_used++;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (divert_info_head)
|
|
|
|
filep->private_data = &(divert_info_tail->next);
|
|
|
|
else
|
|
|
|
filep->private_data = &divert_info_head;
|
2012-02-20 11:52:38 +08:00
|
|
|
spin_unlock_irqrestore(&divert_info_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* start_divert(); */
|
|
|
|
return nonseekable_open(ino, filep);
|
|
|
|
} /* isdn_divert_open */
|
|
|
|
|
|
|
|
/*******************/
|
|
|
|
/* close routine */
|
|
|
|
/*******************/
|
|
|
|
static int
|
|
|
|
isdn_divert_close(struct inode *ino, struct file *filep)
|
|
|
|
{
|
|
|
|
struct divert_info *inf;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2012-02-20 11:52:38 +08:00
|
|
|
spin_lock_irqsave(&divert_info_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
if_used--;
|
|
|
|
inf = *((struct divert_info **) filep->private_data);
|
|
|
|
while (inf) {
|
|
|
|
inf->usage_cnt--;
|
|
|
|
inf = inf->next;
|
|
|
|
}
|
|
|
|
if (if_used <= 0)
|
|
|
|
while (divert_info_head) {
|
|
|
|
inf = divert_info_head;
|
|
|
|
divert_info_head = divert_info_head->next;
|
|
|
|
kfree(inf);
|
|
|
|
}
|
2012-02-20 11:52:38 +08:00
|
|
|
spin_unlock_irqrestore(&divert_info_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
return (0);
|
|
|
|
} /* isdn_divert_close */
|
|
|
|
|
|
|
|
/*********/
|
|
|
|
/* IOCTL */
|
|
|
|
/*********/
|
2010-03-30 13:27:50 +08:00
|
|
|
static int isdn_divert_ioctl_unlocked(struct file *file, uint cmd, ulong arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
divert_ioctl dioctl;
|
|
|
|
int i;
|
|
|
|
unsigned long flags;
|
|
|
|
divert_rule *rulep;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (copy_from_user(&dioctl, (void __user *) arg, sizeof(dioctl)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
switch (cmd) {
|
2012-02-20 11:52:38 +08:00
|
|
|
case IIOCGETVER:
|
|
|
|
dioctl.drv_version = DIVERT_IIOC_VERSION; /* set version */
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-02-20 11:52:38 +08:00
|
|
|
case IIOCGETDRV:
|
|
|
|
if ((dioctl.getid.drvid = divert_if.name_to_drv(dioctl.getid.drvnam)) < 0)
|
|
|
|
return (-EINVAL);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-02-20 11:52:38 +08:00
|
|
|
case IIOCGETNAM:
|
|
|
|
cp = divert_if.drv_to_name(dioctl.getid.drvid);
|
|
|
|
if (!cp)
|
|
|
|
return (-EINVAL);
|
|
|
|
if (!*cp)
|
|
|
|
return (-EINVAL);
|
|
|
|
strcpy(dioctl.getid.drvnam, cp);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-02-20 11:52:38 +08:00
|
|
|
case IIOCGETRULE:
|
|
|
|
if (!(rulep = getruleptr(dioctl.getsetrule.ruleidx)))
|
|
|
|
return (-EINVAL);
|
|
|
|
dioctl.getsetrule.rule = *rulep; /* copy data */
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-02-20 11:52:38 +08:00
|
|
|
case IIOCMODRULE:
|
|
|
|
if (!(rulep = getruleptr(dioctl.getsetrule.ruleidx)))
|
2005-04-17 06:20:36 +08:00
|
|
|
return (-EINVAL);
|
2012-02-20 11:52:38 +08:00
|
|
|
spin_lock_irqsave(&divert_lock, flags);
|
|
|
|
*rulep = dioctl.getsetrule.rule; /* copy data */
|
|
|
|
spin_unlock_irqrestore(&divert_lock, flags);
|
|
|
|
return (0); /* no copy required */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IIOCINSRULE:
|
|
|
|
return (insertrule(dioctl.getsetrule.ruleidx, &dioctl.getsetrule.rule));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IIOCDELRULE:
|
|
|
|
return (deleterule(dioctl.getsetrule.ruleidx));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IIOCDODFACT:
|
|
|
|
return (deflect_extern_action(dioctl.fwd_ctrl.subcmd,
|
|
|
|
dioctl.fwd_ctrl.callid,
|
|
|
|
dioctl.fwd_ctrl.to_nr));
|
|
|
|
|
|
|
|
case IIOCDOCFACT:
|
|
|
|
case IIOCDOCFDIS:
|
|
|
|
case IIOCDOCFINT:
|
|
|
|
if (!divert_if.drv_to_name(dioctl.cf_ctrl.drvid))
|
|
|
|
return (-EINVAL); /* invalid driver */
|
|
|
|
if (strnlen(dioctl.cf_ctrl.msn, sizeof(dioctl.cf_ctrl.msn)) ==
|
|
|
|
sizeof(dioctl.cf_ctrl.msn))
|
|
|
|
return -EINVAL;
|
|
|
|
if (strnlen(dioctl.cf_ctrl.fwd_nr, sizeof(dioctl.cf_ctrl.fwd_nr)) ==
|
|
|
|
sizeof(dioctl.cf_ctrl.fwd_nr))
|
|
|
|
return -EINVAL;
|
|
|
|
if ((i = cf_command(dioctl.cf_ctrl.drvid,
|
|
|
|
(cmd == IIOCDOCFACT) ? 1 : (cmd == IIOCDOCFDIS) ? 0 : 2,
|
|
|
|
dioctl.cf_ctrl.cfproc,
|
|
|
|
dioctl.cf_ctrl.msn,
|
|
|
|
dioctl.cf_ctrl.service,
|
|
|
|
dioctl.cf_ctrl.fwd_nr,
|
|
|
|
&dioctl.cf_ctrl.procid)))
|
|
|
|
return (i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (-EINVAL);
|
2005-04-17 06:20:36 +08:00
|
|
|
} /* switch cmd */
|
|
|
|
return copy_to_user((void __user *)arg, &dioctl, sizeof(dioctl)) ? -EFAULT : 0;
|
|
|
|
} /* isdn_divert_ioctl */
|
|
|
|
|
2010-03-30 13:27:50 +08:00
|
|
|
static long isdn_divert_ioctl(struct file *file, uint cmd, ulong arg)
|
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
|
2010-07-11 19:18:53 +08:00
|
|
|
mutex_lock(&isdn_divert_mutex);
|
2010-03-30 13:27:50 +08:00
|
|
|
ret = isdn_divert_ioctl_unlocked(file, cmd, arg);
|
2010-07-11 19:18:53 +08:00
|
|
|
mutex_unlock(&isdn_divert_mutex);
|
2010-03-30 13:27:50 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-02-12 16:55:32 +08:00
|
|
|
static const struct file_operations isdn_fops =
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.read = isdn_divert_read,
|
|
|
|
.write = isdn_divert_write,
|
|
|
|
.poll = isdn_divert_poll,
|
2010-03-30 13:27:50 +08:00
|
|
|
.unlocked_ioctl = isdn_divert_ioctl,
|
2005-04-17 06:20:36 +08:00
|
|
|
.open = isdn_divert_open,
|
2012-02-20 11:52:38 +08:00
|
|
|
.release = isdn_divert_close,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************/
|
|
|
|
/* isdn subdir in /proc/net */
|
|
|
|
/****************************/
|
|
|
|
static struct proc_dir_entry *isdn_proc_entry = NULL;
|
|
|
|
static struct proc_dir_entry *isdn_divert_entry = NULL;
|
|
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/* divert_dev_init must be called before the proc filesystem may be used */
|
|
|
|
/***************************************************************************/
|
|
|
|
int
|
|
|
|
divert_dev_init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
init_waitqueue_head(&rd_queue);
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2007-09-12 18:01:34 +08:00
|
|
|
isdn_proc_entry = proc_mkdir("isdn", init_net.proc_net);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!isdn_proc_entry)
|
|
|
|
return (-1);
|
2008-04-29 16:02:30 +08:00
|
|
|
isdn_divert_entry = proc_create("divert", S_IFREG | S_IRUGO,
|
|
|
|
isdn_proc_entry, &isdn_fops);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!isdn_divert_entry) {
|
2007-09-12 18:01:34 +08:00
|
|
|
remove_proc_entry("isdn", init_net.proc_net);
|
2005-04-17 06:20:36 +08:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
} /* divert_dev_init */
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/* divert_dev_deinit must be called before leaving isdn when included as */
|
|
|
|
/* a module. */
|
|
|
|
/***************************************************************************/
|
|
|
|
int
|
|
|
|
divert_dev_deinit(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
remove_proc_entry("divert", isdn_proc_entry);
|
2007-09-12 18:01:34 +08:00
|
|
|
remove_proc_entry("isdn", init_net.proc_net);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
} /* divert_dev_deinit */
|