Release 4.7 drivers/isdn/hysdn/hysdn_proclog.c
/* $Id: hysdn_proclog.c,v 1.9.6.3 2001/09/23 22:24:54 kai Exp $
*
* Linux driver for HYSDN cards, /proc/net filesystem log functions.
*
* Author Werner Cornelius (werner@titro.de) for Hypercope GmbH
* Copyright 1999 by Werner Cornelius (werner@titro.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 <linux/proc_fs.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/mutex.h>
#include <linux/kernel.h>
#include "hysdn_defs.h"
/* the proc subdir for the interface is defined in the procconf module */
extern struct proc_dir_entry *hysdn_proc_entry;
static DEFINE_MUTEX(hysdn_log_mutex);
static void put_log_buffer(hysdn_card *card, char *cp);
/*************************************************/
/* structure keeping ascii log for device output */
/*************************************************/
struct log_data {
struct log_data *next;
unsigned long usage_cnt;/* number of files still to work */
void *proc_ctrl; /* pointer to own control procdata structure */
char log_start[2]; /* log string start (final len aligned by size) */
};
/**********************************************/
/* structure holding proc entrys for one card */
/**********************************************/
struct procdata {
struct proc_dir_entry *log; /* log entry */
char log_name[15]; /* log filename */
struct log_data *log_head, *log_tail; /* head and tail for queue */
int if_used; /* open count for interface */
int volatile del_lock; /* lock for delete operations */
unsigned char logtmp[LOG_MAX_LINELEN];
wait_queue_head_t rd_queue;
};
/**********************************************/
/* log function for cards error log interface */
/**********************************************/
void
hysdn_card_errlog(hysdn_card *card, tErrLogEntry *logp, int maxsize)
{
char buf[ERRLOG_TEXT_SIZE + 40];
sprintf(buf, "LOG 0x%08lX 0x%08lX : %s\n", logp->ulErrType, logp->ulErrSubtype, logp->ucText);
put_log_buffer(card, buf); /* output the string */
} Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 51 | 100.00% | 1 | 100.00% |
| Total | 51 | 100.00% | 1 | 100.00% |
/* hysdn_card_errlog */
/***************************************************/
/* Log function using format specifiers for output */
/***************************************************/
void
hysdn_addlog(hysdn_card *card, char *fmt, ...)
{
struct procdata *pd = card->proclog;
char *cp;
va_list args;
if (!pd)
return; /* log structure non existent */
cp = pd->logtmp;
cp += sprintf(cp, "HYSDN: card %d ", card->myid);
va_start(args, fmt);
cp += vsprintf(cp, fmt, args);
va_end(args);
*cp++ = '\n';
*cp = 0;
if (card->debug_flags & DEB_OUT_SYSLOG)
printk(KERN_INFO "%s", pd->logtmp);
else
put_log_buffer(card, pd->logtmp);
} Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 119 | 100.00% | 1 | 100.00% |
| Total | 119 | 100.00% | 1 | 100.00% |
/* hysdn_addlog */
/********************************************/
/* put an log buffer into the log queue. */
/* This buffer will be kept until all files */
/* opened for read got the contents. */
/* Flushes buffers not longer in use. */
/********************************************/
static void
put_log_buffer(hysdn_card *card, char *cp)
{
struct log_data *ib;
struct procdata *pd = card->proclog;
int i;
unsigned long flags;
if (!pd)
return;
if (!cp)
return;
if (!*cp)
return;
if (pd->if_used <= 0)
return; /* no open file for read */
if (!(ib = kmalloc(sizeof(struct log_data) + strlen(cp), GFP_ATOMIC)))
return; /* no memory */
strcpy(ib->log_start, cp); /* set output string */
ib->next = NULL;
ib->proc_ctrl = pd; /* point to own control structure */
spin_lock_irqsave(&card->hysdn_lock, flags);
ib->usage_cnt = pd->if_used;
if (!pd->log_head)
pd->log_head = ib; /* new head */
else
pd->log_tail->next = ib; /* follows existing messages */
pd->log_tail = ib; /* new tail */
i = pd->del_lock++; /* get lock state */
spin_unlock_irqrestore(&card->hysdn_lock, flags);
/* delete old entrys */
if (!i)
while (pd->log_head->next) {
if ((pd->log_head->usage_cnt <= 0) &&
(pd->log_head->next->usage_cnt <= 0)) {
ib = pd->log_head;
pd->log_head = pd->log_head->next;
kfree(ib);
} else
break;
} /* pd->log_head->next */
pd->del_lock--; /* release lock level */
wake_up_interruptible(&(pd->rd_queue)); /* announce new entry */
} Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 246 | 93.89% | 1 | 25.00% |
amol lad | amol lad | 12 | 4.58% | 1 | 25.00% |
kai germaschewski | kai germaschewski | 3 | 1.15% | 1 | 25.00% |
adrian bunk | adrian bunk | 1 | 0.38% | 1 | 25.00% |
| Total | 262 | 100.00% | 4 | 100.00% |
/* put_log_buffer */
/******************************/
/* file operations and tables */
/******************************/
/****************************************/
/* write log file -> set log level bits */
/****************************************/
static ssize_t
hysdn_log_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
{
int rc;
hysdn_card *card = file->private_data;
rc = kstrtoul_from_user(buf, count, 0, &card->debug_flags);
if (rc < 0)
return rc;
hysdn_addlog(card, "debug set to 0x%lx", card->debug_flags);
return (count);
} Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 59 | 77.63% | 1 | 20.00% |
andy shevchenko | andy shevchenko | 7 | 9.21% | 1 | 20.00% |
alexey dobriyan | alexey dobriyan | 7 | 9.21% | 1 | 20.00% |
peter huewe | peter huewe | 2 | 2.63% | 1 | 20.00% |
al viro | al viro | 1 | 1.32% | 1 | 20.00% |
| Total | 76 | 100.00% | 5 | 100.00% |
/* hysdn_log_write */
/******************/
/* read log file */
/******************/
static ssize_t
hysdn_log_read(struct file *file, char __user *buf, size_t count, loff_t *off)
{
struct log_data *inf;
int len;
hysdn_card *card = PDE_DATA(file_inode(file));
if (!(inf = *((struct log_data **) file->private_data))) {
struct procdata *pd = card->proclog;
if (file->f_flags & O_NONBLOCK)
return (-EAGAIN);
wait_event_interruptible(pd->rd_queue, (inf =
*((struct log_data **) file->private_data)));
}
if (!inf)
return (0);
inf->usage_cnt--; /* new usage count */
file->private_data = &inf->next; /* next structure */
if ((len = strlen(inf->log_start)) <= count) {
if (copy_to_user(buf, inf->log_start, len))
return -EFAULT;
*off += len;
return (len);
}
return (0);
} Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 151 | 80.75% | 1 | 12.50% |
al viro | al viro | 21 | 11.23% | 5 | 62.50% |
arnd bergmann | arnd bergmann | 13 | 6.95% | 1 | 12.50% |
linus torvalds | linus torvalds | 2 | 1.07% | 1 | 12.50% |
| Total | 187 | 100.00% | 8 | 100.00% |
/* hysdn_log_read */
/******************/
/* open log file */
/******************/
static int
hysdn_log_open(struct inode *ino, struct file *filep)
{
hysdn_card *card = PDE_DATA(ino);
mutex_lock(&hysdn_log_mutex);
if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) {
/* write only access -> write log level only */
filep->private_data = card; /* remember our own card */
} else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) {
struct procdata *pd = card->proclog;
unsigned long flags;
/* read access -> log/debug read */
spin_lock_irqsave(&card->hysdn_lock, flags);
pd->if_used++;
if (pd->log_head)
filep->private_data = &pd->log_tail->next;
else
filep->private_data = &pd->log_head;
spin_unlock_irqrestore(&card->hysdn_lock, flags);
} else { /* simultaneous read/write access forbidden ! */
mutex_unlock(&hysdn_log_mutex);
return (-EPERM); /* no permission this time */
}
mutex_unlock(&hysdn_log_mutex);
return nonseekable_open(ino, filep);
} Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 115 | 66.47% | 2 | 22.22% |
al viro | al viro | 25 | 14.45% | 3 | 33.33% |
arnd bergmann | arnd bergmann | 14 | 8.09% | 1 | 11.11% |
amol lad | amol lad | 12 | 6.94% | 1 | 11.11% |
linus torvalds | linus torvalds | 7 | 4.05% | 2 | 22.22% |
| Total | 173 | 100.00% | 9 | 100.00% |
/* hysdn_log_open */
/*******************************************************************************/
/* close a cardlog file. If the file has been opened for exclusive write it is */
/* assumed as pof data input and the pof loader is noticed about. */
/* Otherwise file is handled as log output. In this case the interface usage */
/* count is decremented and all buffers are noticed of closing. If this file */
/* was the last one to be closed, all buffers are freed. */
/*******************************************************************************/
static int
hysdn_log_close(struct inode *ino, struct file *filep)
{
struct log_data *inf;
struct procdata *pd;
hysdn_card *card;
int retval = 0;
mutex_lock(&hysdn_log_mutex);
if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) {
/* write only access -> write debug level written */
retval = 0; /* success */
} else {
/* read access -> log/debug read, mark one further file as closed */
inf = *((struct log_data **) filep->private_data); /* get first log entry */
if (inf)
pd = (struct procdata *) inf->proc_ctrl; /* still entries there */
else {
/* no info available -> search card */
card = PDE_DATA(file_inode(filep));
pd = card->proclog; /* pointer to procfs log */
}
if (pd)
pd->if_used--; /* decrement interface usage count by one */
while (inf) {
inf->usage_cnt--; /* decrement usage count for buffers */
inf = inf->next;
}
if (pd)
if (pd->if_used <= 0) /* delete buffers if last file closed */
while (pd->log_head) {
inf = pd->log_head;
pd->log_head = pd->log_head->next;
kfree(inf);
}
} /* read access */
mutex_unlock(&hysdn_log_mutex);
return (retval);
} Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 187 | 91.67% | 2 | 33.33% |
arnd bergmann | arnd bergmann | 10 | 4.90% | 1 | 16.67% |
al viro | al viro | 7 | 3.43% | 3 | 50.00% |
| Total | 204 | 100.00% | 6 | 100.00% |
/* hysdn_log_close */
/*************************************************/
/* select/poll routine to be able using select() */
/*************************************************/
static unsigned int
hysdn_log_poll(struct file *file, poll_table *wait)
{
unsigned int mask = 0;
hysdn_card *card = PDE_DATA(file_inode(file));
struct procdata *pd = card->proclog;
if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE)
return (mask); /* no polling for write supported */
poll_wait(file, &(pd->rd_queue), wait);
if (*((struct log_data **) file->private_data))
mask |= POLLIN | POLLRDNORM;
return mask;
} Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 88 | 85.44% | 1 | 16.67% |
al viro | al viro | 14 | 13.59% | 4 | 66.67% |
linus torvalds | linus torvalds | 1 | 0.97% | 1 | 16.67% |
| Total | 103 | 100.00% | 6 | 100.00% |
/* hysdn_log_poll */
/**************************************************/
/* table for log filesystem functions defined above. */
/**************************************************/
static const struct file_operations log_fops =
{
.owner = THIS_MODULE,
.llseek = no_llseek,
.read = hysdn_log_read,
.write = hysdn_log_write,
.poll = hysdn_log_poll,
.open = hysdn_log_open,
.release = hysdn_log_close,
};
/***********************************************************************************/
/* hysdn_proclog_init is called when the module is loaded after creating the cards */
/* conf files. */
/***********************************************************************************/
int
hysdn_proclog_init(hysdn_card *card)
{
struct procdata *pd;
/* create a cardlog proc entry */
if ((pd = kzalloc(sizeof(struct procdata), GFP_KERNEL)) != NULL) {
sprintf(pd->log_name, "%s%d", PROC_LOG_BASENAME, card->myid);
pd->log = proc_create_data(pd->log_name,
S_IFREG | S_IRUGO | S_IWUSR, hysdn_proc_entry,
&log_fops, card);
init_waitqueue_head(&(pd->rd_queue));
card->proclog = (void *) pd; /* remember procfs structure */
}
return (0);
} Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 95 | 94.06% | 2 | 40.00% |
al viro | al viro | 3 | 2.97% | 1 | 20.00% |
denis v. lunev | denis v. lunev | 2 | 1.98% | 1 | 20.00% |
burman yan | burman yan | 1 | 0.99% | 1 | 20.00% |
| Total | 101 | 100.00% | 5 | 100.00% |
/* hysdn_proclog_init */
/************************************************************************************/
/* hysdn_proclog_release is called when the module is unloaded and before the cards */
/* conf file is released */
/* The module counter is assumed to be 0 ! */
/************************************************************************************/
void
hysdn_proclog_release(hysdn_card *card)
{
struct procdata *pd;
if ((pd = (struct procdata *) card->proclog) != NULL) {
if (pd->log)
remove_proc_entry(pd->log_name, hysdn_proc_entry);
kfree(pd); /* release memory */
card->proclog = NULL;
}
} Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 60 | 100.00% | 1 | 100.00% |
| Total | 60 | 100.00% | 1 | 100.00% |
/* hysdn_proclog_release */
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 1346 | 86.01% | 5 | 16.13% |
al viro | al viro | 71 | 4.54% | 5 | 16.13% |
arnd bergmann | arnd bergmann | 44 | 2.81% | 2 | 6.45% |
amol lad | amol lad | 24 | 1.53% | 1 | 3.23% |
kai germaschewski | kai germaschewski | 15 | 0.96% | 2 | 6.45% |
adrian bunk | adrian bunk | 14 | 0.89% | 1 | 3.23% |
linus torvalds | linus torvalds | 12 | 0.77% | 5 | 16.13% |
alexey dobriyan | alexey dobriyan | 10 | 0.64% | 2 | 6.45% |
andy shevchenko | andy shevchenko | 10 | 0.64% | 1 | 3.23% |
denis v. lunev | denis v. lunev | 7 | 0.45% | 1 | 3.23% |
andrew morton | andrew morton | 4 | 0.26% | 1 | 3.23% |
tejun heo | tejun heo | 3 | 0.19% | 1 | 3.23% |
peter huewe | peter huewe | 2 | 0.13% | 1 | 3.23% |
joe perches | joe perches | 1 | 0.06% | 1 | 3.23% |
arjan van de ven | arjan van de ven | 1 | 0.06% | 1 | 3.23% |
burman yan | burman yan | 1 | 0.06% | 1 | 3.23% |
| Total | 1565 | 100.00% | 31 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.