Commit 44414d82 authored by Christoph Hellwig's avatar Christoph Hellwig

proc: introduce proc_create_seq_private

Variant of proc_create_data that directly take a struct seq_operations
argument + a private state size and drastically reduces the boilerplate
code in the callers.

All trivial callers converted over.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent fddda2b7
...@@ -2788,22 +2788,10 @@ static const struct seq_operations locks_seq_operations = { ...@@ -2788,22 +2788,10 @@ static const struct seq_operations locks_seq_operations = {
.show = locks_show, .show = locks_show,
}; };
static int locks_open(struct inode *inode, struct file *filp)
{
return seq_open_private(filp, &locks_seq_operations,
sizeof(struct locks_iterator));
}
static const struct file_operations proc_locks_operations = {
.open = locks_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_private,
};
static int __init proc_locks_init(void) static int __init proc_locks_init(void)
{ {
proc_create("locks", 0, NULL, &proc_locks_operations); proc_create_seq_private("locks", 0, NULL, &locks_seq_operations,
sizeof(struct locks_iterator), NULL);
return 0; return 0;
} }
fs_initcall(proc_locks_init); fs_initcall(proc_locks_init);
......
...@@ -560,6 +560,8 @@ static int proc_seq_open(struct inode *inode, struct file *file) ...@@ -560,6 +560,8 @@ static int proc_seq_open(struct inode *inode, struct file *file)
{ {
struct proc_dir_entry *de = PDE(inode); struct proc_dir_entry *de = PDE(inode);
if (de->state_size)
return seq_open_private(file, de->seq_ops, de->state_size);
return seq_open(file, de->seq_ops); return seq_open(file, de->seq_ops);
} }
...@@ -570,9 +572,9 @@ static const struct file_operations proc_seq_fops = { ...@@ -570,9 +572,9 @@ static const struct file_operations proc_seq_fops = {
.release = seq_release, .release = seq_release,
}; };
struct proc_dir_entry *proc_create_seq_data(const char *name, umode_t mode, struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
struct proc_dir_entry *parent, const struct seq_operations *ops, struct proc_dir_entry *parent, const struct seq_operations *ops,
void *data) unsigned int state_size, void *data)
{ {
struct proc_dir_entry *p; struct proc_dir_entry *p;
...@@ -581,9 +583,10 @@ struct proc_dir_entry *proc_create_seq_data(const char *name, umode_t mode, ...@@ -581,9 +583,10 @@ struct proc_dir_entry *proc_create_seq_data(const char *name, umode_t mode,
return NULL; return NULL;
p->proc_fops = &proc_seq_fops; p->proc_fops = &proc_seq_fops;
p->seq_ops = ops; p->seq_ops = ops;
p->state_size = state_size;
return proc_register(parent, p); return proc_register(parent, p);
} }
EXPORT_SYMBOL(proc_create_seq_data); EXPORT_SYMBOL(proc_create_seq_private);
void proc_set_size(struct proc_dir_entry *de, loff_t size) void proc_set_size(struct proc_dir_entry *de, loff_t size)
{ {
......
...@@ -46,6 +46,7 @@ struct proc_dir_entry { ...@@ -46,6 +46,7 @@ struct proc_dir_entry {
const struct file_operations *proc_fops; const struct file_operations *proc_fops;
const struct seq_operations *seq_ops; const struct seq_operations *seq_ops;
void *data; void *data;
unsigned int state_size;
unsigned int low_ino; unsigned int low_ino;
nlink_t nlink; nlink_t nlink;
kuid_t uid; kuid_t uid;
......
...@@ -145,7 +145,12 @@ extern rwlock_t atalk_interfaces_lock; ...@@ -145,7 +145,12 @@ extern rwlock_t atalk_interfaces_lock;
extern struct atalk_route atrtr_default; extern struct atalk_route atrtr_default;
extern const struct file_operations atalk_seq_arp_fops; struct aarp_iter_state {
int bucket;
struct aarp_entry **table;
};
extern const struct seq_operations aarp_seq_ops;
extern int sysctl_aarp_expiry_time; extern int sysctl_aarp_expiry_time;
extern int sysctl_aarp_tick_time; extern int sysctl_aarp_tick_time;
......
...@@ -25,11 +25,13 @@ extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t, ...@@ -25,11 +25,13 @@ extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
struct proc_dir_entry *); struct proc_dir_entry *);
struct proc_dir_entry *proc_create_mount_point(const char *name); struct proc_dir_entry *proc_create_mount_point(const char *name);
struct proc_dir_entry *proc_create_seq_data(const char *name, umode_t mode, struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
struct proc_dir_entry *parent, const struct seq_operations *ops, struct proc_dir_entry *parent, const struct seq_operations *ops,
void *data); unsigned int state_size, void *data);
#define proc_create_seq_data(name, mode, parent, ops, data) \
proc_create_seq_private(name, mode, parent, ops, 0, data)
#define proc_create_seq(name, mode, parent, ops) \ #define proc_create_seq(name, mode, parent, ops) \
proc_create_seq_data(name, mode, parent, ops, NULL) proc_create_seq_private(name, mode, parent, ops, 0, NULL)
extern struct proc_dir_entry *proc_create_data(const char *, umode_t, extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
struct proc_dir_entry *, struct proc_dir_entry *,
...@@ -64,6 +66,7 @@ static inline struct proc_dir_entry *proc_mkdir_data(const char *name, ...@@ -64,6 +66,7 @@ static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; } umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
static inline struct proc_dir_entry *proc_mkdir_mode(const char *name, static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
umode_t mode, struct proc_dir_entry *parent) { return NULL; } umode_t mode, struct proc_dir_entry *parent) { return NULL; }
#define proc_create_seq_private(name, mode, parent, ops, 0, data) ({NULL;})
#define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;}) #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
#define proc_create_seq(name, mode, parent, ops) ({NULL;}) #define proc_create_seq(name, mode, parent, ops) ({NULL;})
#define proc_create(name, mode, parent, proc_fops) ({NULL;}) #define proc_create(name, mode, parent, proc_fops) ({NULL;})
......
...@@ -372,24 +372,12 @@ static const struct seq_operations timer_list_sops = { ...@@ -372,24 +372,12 @@ static const struct seq_operations timer_list_sops = {
.show = timer_list_show, .show = timer_list_show,
}; };
static int timer_list_open(struct inode *inode, struct file *filp)
{
return seq_open_private(filp, &timer_list_sops,
sizeof(struct timer_list_iter));
}
static const struct file_operations timer_list_fops = {
.open = timer_list_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_private,
};
static int __init init_timer_list_procfs(void) static int __init init_timer_list_procfs(void)
{ {
struct proc_dir_entry *pe; struct proc_dir_entry *pe;
pe = proc_create("timer_list", 0400, NULL, &timer_list_fops); pe = proc_create_seq_private("timer_list", 0400, NULL, &timer_list_sops,
sizeof(struct timer_list_iter), NULL);
if (!pe) if (!pe)
return -ENOMEM; return -ENOMEM;
return 0; return 0;
......
...@@ -2751,24 +2751,12 @@ static const struct seq_operations vmalloc_op = { ...@@ -2751,24 +2751,12 @@ static const struct seq_operations vmalloc_op = {
.show = s_show, .show = s_show,
}; };
static int vmalloc_open(struct inode *inode, struct file *file)
{
return seq_open_private(file, &vmalloc_op,
nr_node_ids * sizeof(unsigned int));
}
static const struct file_operations proc_vmalloc_operations = {
.open = vmalloc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_private,
};
static int __init proc_vmalloc_init(void) static int __init proc_vmalloc_init(void)
{ {
if (IS_ENABLED(CONFIG_NUMA)) if (IS_ENABLED(CONFIG_NUMA))
proc_create("vmallocinfo", S_IRUSR, NULL, proc_create_seq_private("vmallocinfo", S_IRUSR, NULL,
&proc_vmalloc_operations); &vmalloc_op,
nr_node_ids * sizeof(unsigned int), NULL);
else else
proc_create_seq("vmallocinfo", S_IRUSR, NULL, &vmalloc_op); proc_create_seq("vmallocinfo", S_IRUSR, NULL, &vmalloc_op);
return 0; return 0;
......
...@@ -907,11 +907,6 @@ void aarp_device_down(struct net_device *dev) ...@@ -907,11 +907,6 @@ void aarp_device_down(struct net_device *dev)
} }
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
struct aarp_iter_state {
int bucket;
struct aarp_entry **table;
};
/* /*
* Get the aarp entry that is in the chain described * Get the aarp entry that is in the chain described
* by the iterator. * by the iterator.
...@@ -1033,25 +1028,12 @@ static int aarp_seq_show(struct seq_file *seq, void *v) ...@@ -1033,25 +1028,12 @@ static int aarp_seq_show(struct seq_file *seq, void *v)
return 0; return 0;
} }
static const struct seq_operations aarp_seq_ops = { const struct seq_operations aarp_seq_ops = {
.start = aarp_seq_start, .start = aarp_seq_start,
.next = aarp_seq_next, .next = aarp_seq_next,
.stop = aarp_seq_stop, .stop = aarp_seq_stop,
.show = aarp_seq_show, .show = aarp_seq_show,
}; };
static int aarp_seq_open(struct inode *inode, struct file *file)
{
return seq_open_private(file, &aarp_seq_ops,
sizeof(struct aarp_iter_state));
}
const struct file_operations atalk_seq_arp_fops = {
.open = aarp_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_private,
};
#endif #endif
/* General module cleanup. Called from cleanup_module() in ddp.c. */ /* General module cleanup. Called from cleanup_module() in ddp.c. */
......
...@@ -236,7 +236,8 @@ int __init atalk_proc_init(void) ...@@ -236,7 +236,8 @@ int __init atalk_proc_init(void)
if (!p) if (!p)
goto out_socket; goto out_socket;
p = proc_create("arp", 0444, atalk_proc_dir, &atalk_seq_arp_fops); p = proc_create_seq_private("arp", 0444, atalk_proc_dir, &aarp_seq_ops,
sizeof(struct aarp_iter_state), NULL);
if (!p) if (!p)
goto out_arp; goto out_arp;
......
...@@ -990,18 +990,6 @@ static const struct seq_operations lec_seq_ops = { ...@@ -990,18 +990,6 @@ static const struct seq_operations lec_seq_ops = {
.stop = lec_seq_stop, .stop = lec_seq_stop,
.show = lec_seq_show, .show = lec_seq_show,
}; };
static int lec_seq_open(struct inode *inode, struct file *file)
{
return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
}
static const struct file_operations lec_seq_fops = {
.open = lec_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_private,
};
#endif #endif
static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
...@@ -1047,7 +1035,8 @@ static int __init lane_module_init(void) ...@@ -1047,7 +1035,8 @@ static int __init lane_module_init(void)
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
struct proc_dir_entry *p; struct proc_dir_entry *p;
p = proc_create("lec", 0444, atm_proc_root, &lec_seq_fops); p = proc_create_seq_private("lec", 0444, atm_proc_root, &lec_seq_ops,
sizeof(struct lec_state), NULL);
if (!p) { if (!p) {
pr_err("Unable to initialize /proc/net/atm/lec\n"); pr_err("Unable to initialize /proc/net/atm/lec\n");
return -ENOMEM; return -ENOMEM;
......
...@@ -2314,19 +2314,6 @@ static const struct seq_operations dn_socket_seq_ops = { ...@@ -2314,19 +2314,6 @@ static const struct seq_operations dn_socket_seq_ops = {
.stop = dn_socket_seq_stop, .stop = dn_socket_seq_stop,
.show = dn_socket_seq_show, .show = dn_socket_seq_show,
}; };
static int dn_socket_seq_open(struct inode *inode, struct file *file)
{
return seq_open_private(file, &dn_socket_seq_ops,
sizeof(struct dn_iter_state));
}
static const struct file_operations dn_socket_seq_fops = {
.open = dn_socket_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_private,
};
#endif #endif
static const struct net_proto_family dn_family_ops = { static const struct net_proto_family dn_family_ops = {
...@@ -2383,7 +2370,9 @@ static int __init decnet_init(void) ...@@ -2383,7 +2370,9 @@ static int __init decnet_init(void)
dev_add_pack(&dn_dix_packet_type); dev_add_pack(&dn_dix_packet_type);
register_netdevice_notifier(&dn_dev_notifier); register_netdevice_notifier(&dn_dev_notifier);
proc_create("decnet", 0444, init_net.proc_net, &dn_socket_seq_fops); proc_create_seq_private("decnet", 0444, init_net.proc_net,
&dn_socket_seq_ops, sizeof(struct dn_iter_state),
NULL);
dn_register_sysctl(); dn_register_sysctl();
out: out:
return rc; return rc;
......
...@@ -1852,20 +1852,6 @@ static const struct seq_operations dn_rt_cache_seq_ops = { ...@@ -1852,20 +1852,6 @@ static const struct seq_operations dn_rt_cache_seq_ops = {
.stop = dn_rt_cache_seq_stop, .stop = dn_rt_cache_seq_stop,
.show = dn_rt_cache_seq_show, .show = dn_rt_cache_seq_show,
}; };
static int dn_rt_cache_seq_open(struct inode *inode, struct file *file)
{
return seq_open_private(file, &dn_rt_cache_seq_ops,
sizeof(struct dn_rt_cache_iter_state));
}
static const struct file_operations dn_rt_cache_seq_fops = {
.open = dn_rt_cache_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_private,
};
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
void __init dn_route_init(void) void __init dn_route_init(void)
...@@ -1918,8 +1904,9 @@ void __init dn_route_init(void) ...@@ -1918,8 +1904,9 @@ void __init dn_route_init(void)
dn_dst_ops.gc_thresh = (dn_rt_hash_mask + 1); dn_dst_ops.gc_thresh = (dn_rt_hash_mask + 1);
proc_create("decnet_cache", 0444, init_net.proc_net, proc_create_seq_private("decnet_cache", 0444, init_net.proc_net,
&dn_rt_cache_seq_fops); &dn_rt_cache_seq_ops,
sizeof(struct dn_rt_cache_iter_state), NULL);
#ifdef CONFIG_DECNET_ROUTER #ifdef CONFIG_DECNET_ROUTER
rtnl_register_module(THIS_MODULE, PF_DECnet, RTM_GETROUTE, rtnl_register_module(THIS_MODULE, PF_DECnet, RTM_GETROUTE,
......
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