Commit af064cdd authored by Al Viro's avatar Al Viro

dgrp procfs fixes, part 5: per-node files

this "hooks" scheme is pointless - just make file_operations non-static
and consolidate initialiazation bits.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 08f3d07d
......@@ -49,20 +49,20 @@ extern struct dgrp_poll_data dgrp_poll_data;
extern void dgrp_poll_handler(unsigned long arg);
/* from dgrp_mon_ops.c */
extern void dgrp_register_mon_hook(struct proc_dir_entry *de);
extern const struct file_operations dgrp_mon_ops;
/* from dgrp_tty.c */
extern int dgrp_tty_init(struct nd_struct *nd);
extern void dgrp_tty_uninit(struct nd_struct *nd);
/* from dgrp_ports_ops.c */
extern void dgrp_register_ports_hook(struct proc_dir_entry *de);
extern const struct file_operations dgrp_ports_ops;
/* from dgrp_net_ops.c */
extern void dgrp_register_net_hook(struct proc_dir_entry *de);
extern const struct file_operations dgrp_net_ops;
/* from dgrp_dpa_ops.c */
extern void dgrp_register_dpa_hook(struct proc_dir_entry *de);
extern const struct file_operations dgrp_dpa_ops;
extern void dgrp_dpa_data(struct nd_struct *, int, u8 *, int);
/* from dgrp_sysfs.c */
......
......@@ -52,7 +52,7 @@ static long dgrp_dpa_ioctl(struct file *file, unsigned int cmd,
unsigned long arg);
static unsigned int dgrp_dpa_select(struct file *, struct poll_table_struct *);
static const struct file_operations dpa_ops = {
const struct file_operations dgrp_dpa_ops = {
.owner = THIS_MODULE,
.read = dgrp_dpa_read,
.poll = dgrp_dpa_select,
......@@ -61,12 +61,6 @@ static const struct file_operations dpa_ops = {
.release = dgrp_dpa_release,
};
static struct inode_operations dpa_inode_ops = {
.permission = dgrp_inode_permission
};
struct digi_node {
uint nd_state; /* Node state: 1 = up, 0 = down. */
uint nd_chan_count; /* Number of channels found */
......@@ -111,17 +105,6 @@ struct digi_debug {
#define DIGI_SETDEBUG (('d'<<8) | 247) /* set debug info */
void dgrp_register_dpa_hook(struct proc_dir_entry *de)
{
struct nd_struct *node = de->data;
de->proc_iops = &dpa_inode_ops;
de->proc_fops = &dpa_ops;
node->nd_dpa_de = de;
spin_lock_init(&node->nd_dpa_lock);
}
/*
* dgrp_dpa_open -- open the DPA device for a particular PortServer
*/
......
......@@ -49,7 +49,7 @@ static ssize_t dgrp_mon_read(struct file *, char __user *, size_t, loff_t *);
static long dgrp_mon_ioctl(struct file *file, unsigned int cmd,
unsigned long arg);
static const struct file_operations mon_ops = {
const struct file_operations dgrp_mon_ops = {
.owner = THIS_MODULE,
.read = dgrp_mon_read,
.unlocked_ioctl = dgrp_mon_ioctl,
......@@ -57,20 +57,6 @@ static const struct file_operations mon_ops = {
.release = dgrp_mon_release,
};
static struct inode_operations mon_inode_ops = {
.permission = dgrp_inode_permission
};
void dgrp_register_mon_hook(struct proc_dir_entry *de)
{
struct nd_struct *node = de->data;
de->proc_iops = &mon_inode_ops;
de->proc_fops = &mon_ops;
node->nd_mon_de = de;
sema_init(&node->nd_mon_semaphore, 1);
}
/**
* dgrp_mon_open() -- open /proc/dgrp/ports device for a PortServer
* @inode: struct inode *
......
......@@ -72,7 +72,7 @@ static long dgrp_net_ioctl(struct file *file, unsigned int cmd,
static unsigned int dgrp_net_select(struct file *file,
struct poll_table_struct *table);
static const struct file_operations net_ops = {
const struct file_operations dgrp_net_ops = {
.owner = THIS_MODULE,
.read = dgrp_net_read,
.write = dgrp_net_write,
......@@ -82,23 +82,6 @@ static const struct file_operations net_ops = {
.release = dgrp_net_release,
};
static struct inode_operations net_inode_ops = {
.permission = dgrp_inode_permission
};
void dgrp_register_net_hook(struct proc_dir_entry *de)
{
struct nd_struct *node = de->data;
de->proc_iops = &net_inode_ops;
de->proc_fops = &net_ops;
node->nd_net_de = de;
sema_init(&node->nd_net_semaphore, 1);
node->nd_state = NS_CLOSED;
dgrp_create_node_class_sysfs_files(node);
}
/**
* dgrp_dump() -- prints memory for debugging purposes.
* @mem: Memory location which should be printed to the console
......
......@@ -47,7 +47,7 @@
/* File operation declarations */
static int dgrp_ports_open(struct inode *, struct file *);
static const struct file_operations ports_ops = {
const struct file_operations dgrp_ports_ops = {
.owner = THIS_MODULE,
.open = dgrp_ports_open,
.read = seq_read,
......@@ -55,20 +55,6 @@ static const struct file_operations ports_ops = {
.release = seq_release
};
static struct inode_operations ports_inode_ops = {
.permission = dgrp_inode_permission
};
void dgrp_register_ports_hook(struct proc_dir_entry *de)
{
struct nd_struct *node = de->data;
de->proc_iops = &ports_inode_ops;
de->proc_fops = &ports_ops;
node->nd_ports_de = de;
}
static void *dgrp_ports_seq_start(struct seq_file *seq, loff_t *pos)
{
if (*pos == 0)
......
......@@ -48,10 +48,9 @@ static struct proc_dir_entry *dgrp_proc_dir_entry;
static int dgrp_add_id(long id);
static int dgrp_remove_nd(struct nd_struct *nd);
static void unregister_dgrp_device(struct proc_dir_entry *de);
static void register_dgrp_device(struct nd_struct *node,
static struct proc_dir_entry *add_proc_file(struct nd_struct *node,
struct proc_dir_entry *root,
void (*register_hook)(struct proc_dir_entry *de));
const struct file_operations *fops);
/* File operation declarations */
static int parse_write_config(char *);
......@@ -100,6 +99,21 @@ static struct proc_dir_entry *mon_entry_pointer;
static struct proc_dir_entry *dpa_entry_pointer;
static struct proc_dir_entry *ports_entry_pointer;
static void remove_files(struct nd_struct *nd)
{
char buf[3];
ID_TO_CHAR(nd->nd_ID, buf);
dgrp_remove_node_class_sysfs_files(nd);
if (nd->nd_net_de)
remove_proc_entry(buf, net_entry_pointer);
if (nd->nd_mon_de)
remove_proc_entry(buf, mon_entry_pointer);
if (nd->nd_dpa_de)
remove_proc_entry(buf, dpa_entry_pointer);
if (nd->nd_ports_de)
remove_proc_entry(buf, ports_entry_pointer);
}
void dgrp_unregister_proc(void)
{
net_entry_pointer = NULL;
......@@ -109,21 +123,8 @@ void dgrp_unregister_proc(void)
if (dgrp_proc_dir_entry) {
struct nd_struct *nd;
list_for_each_entry(nd, &nd_struct_list, list) {
if (nd->nd_net_de) {
unregister_dgrp_device(nd->nd_net_de);
dgrp_remove_node_class_sysfs_files(nd);
}
if (nd->nd_mon_de)
unregister_dgrp_device(nd->nd_mon_de);
if (nd->nd_dpa_de)
unregister_dgrp_device(nd->nd_dpa_de);
if (nd->nd_ports_de)
unregister_dgrp_device(nd->nd_ports_de);
}
list_for_each_entry(nd, &nd_struct_list, list)
remove_files(nd);
remove_proc_entry("dgrp/config", NULL);
remove_proc_entry("dgrp/info", NULL);
remove_proc_entry("dgrp/nodeinfo", NULL);
......@@ -494,6 +495,10 @@ static int dgrp_add_id(long id)
init_waitqueue_head(&nd->nd_tx_waitq);
init_waitqueue_head(&nd->nd_mon_wqueue);
init_waitqueue_head(&nd->nd_dpa_wqueue);
sema_init(&nd->nd_mon_semaphore, 1);
sema_init(&nd->nd_net_semaphore, 1);
spin_lock_init(&nd->nd_dpa_lock);
nd->nd_state = NS_CLOSED;
for (i = 0; i < SEQ_MAX; i++)
init_waitqueue_head(&nd->nd_seq_wque[i]);
......@@ -508,12 +513,12 @@ static int dgrp_add_id(long id)
if (ret)
goto error_out;
register_dgrp_device(nd, net_entry_pointer, dgrp_register_net_hook);
register_dgrp_device(nd, mon_entry_pointer, dgrp_register_mon_hook);
register_dgrp_device(nd, dpa_entry_pointer, dgrp_register_dpa_hook);
register_dgrp_device(nd, ports_entry_pointer,
dgrp_register_ports_hook);
dgrp_create_node_class_sysfs_files(nd);
nd->nd_net_de = add_proc_file(nd, net_entry_pointer, &dgrp_net_ops);
nd->nd_mon_de = add_proc_file(nd, mon_entry_pointer, &dgrp_mon_ops);
nd->nd_dpa_de = add_proc_file(nd, dpa_entry_pointer, &dgrp_dpa_ops);
nd->nd_ports_de = add_proc_file(nd, ports_entry_pointer,
&dgrp_ports_ops);
return 0;
/* FIXME this guy should free the tty driver stored in nd and destroy
......@@ -532,16 +537,7 @@ static int dgrp_remove_nd(struct nd_struct *nd)
if (nd->nd_tty_ref_cnt)
return -EBUSY;
if (nd->nd_net_de) {
unregister_dgrp_device(nd->nd_net_de);
dgrp_remove_node_class_sysfs_files(nd);
}
unregister_dgrp_device(nd->nd_mon_de);
unregister_dgrp_device(nd->nd_ports_de);
unregister_dgrp_device(nd->nd_dpa_de);
remove_files(nd);
dgrp_tty_uninit(nd);
......@@ -553,9 +549,9 @@ static int dgrp_remove_nd(struct nd_struct *nd)
return 0;
}
static void register_dgrp_device(struct nd_struct *node,
static struct proc_dir_entry *add_proc_file(struct nd_struct *node,
struct proc_dir_entry *root,
void (*register_hook)(struct proc_dir_entry *de))
const struct file_operations *fops)
{
char buf[3];
struct proc_dir_entry *de;
......@@ -563,28 +559,10 @@ static void register_dgrp_device(struct nd_struct *node,
ID_TO_CHAR(node->nd_ID, buf);
de = create_proc_entry(buf, 0600 | S_IFREG, root);
if (!de)
return;
de->data = (void *) node;
if (register_hook)
register_hook(de);
}
static void unregister_dgrp_device(struct proc_dir_entry *de)
{
if (!de)
return;
/* Don't unregister proc entries that are still being used.. */
if ((atomic_read(&de->count)) != 1) {
pr_alert("%s - proc entry %s in use. Not removing.\n",
__func__, de->name);
return;
if (de) {
de->data = (void *) node;
de->proc_fops = fops;
de->proc_iops = &proc_inode_ops;
}
remove_proc_entry(de->name, de->parent);
de = NULL;
return de;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment