aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2018-04-13 14:45:09 -0400
committerChristoph Hellwig <hch@lst.de>2018-05-16 01:24:30 -0400
commit353861cf05945002c3ddeb2519b0dc5f7bb765d5 (patch)
tree433bc1a1445b6c1fef9aa62896df14d336350c3a
parentb8b1483d79550343a687cd4a2c7ff9c82889586f (diff)
afs: simplify procfs code
Use remove_proc_subtree to remove the whole subtree on cleanup, and unwind the registration loop into individual calls. Switch to use proc_create_seq where applicable. Signed-off-by: Christoph Hellwig <hch@lst.de>
-rw-r--r--fs/afs/proc.c134
1 files changed, 15 insertions, 119 deletions
diff --git a/fs/afs/proc.c b/fs/afs/proc.c
index 839a22280606..3aad32762989 100644
--- a/fs/afs/proc.c
+++ b/fs/afs/proc.c
@@ -62,7 +62,6 @@ static const struct file_operations afs_proc_rootcell_fops = {
62 .llseek = no_llseek, 62 .llseek = no_llseek,
63}; 63};
64 64
65static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file);
66static void *afs_proc_cell_volumes_start(struct seq_file *p, loff_t *pos); 65static void *afs_proc_cell_volumes_start(struct seq_file *p, loff_t *pos);
67static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v, 66static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
68 loff_t *pos); 67 loff_t *pos);
@@ -76,15 +75,6 @@ static const struct seq_operations afs_proc_cell_volumes_ops = {
76 .show = afs_proc_cell_volumes_show, 75 .show = afs_proc_cell_volumes_show,
77}; 76};
78 77
79static const struct file_operations afs_proc_cell_volumes_fops = {
80 .open = afs_proc_cell_volumes_open,
81 .read = seq_read,
82 .llseek = seq_lseek,
83 .release = seq_release,
84};
85
86static int afs_proc_cell_vlservers_open(struct inode *inode,
87 struct file *file);
88static void *afs_proc_cell_vlservers_start(struct seq_file *p, loff_t *pos); 78static void *afs_proc_cell_vlservers_start(struct seq_file *p, loff_t *pos);
89static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v, 79static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v,
90 loff_t *pos); 80 loff_t *pos);
@@ -98,14 +88,6 @@ static const struct seq_operations afs_proc_cell_vlservers_ops = {
98 .show = afs_proc_cell_vlservers_show, 88 .show = afs_proc_cell_vlservers_show,
99}; 89};
100 90
101static const struct file_operations afs_proc_cell_vlservers_fops = {
102 .open = afs_proc_cell_vlservers_open,
103 .read = seq_read,
104 .llseek = seq_lseek,
105 .release = seq_release,
106};
107
108static int afs_proc_servers_open(struct inode *inode, struct file *file);
109static void *afs_proc_servers_start(struct seq_file *p, loff_t *pos); 91static void *afs_proc_servers_start(struct seq_file *p, loff_t *pos);
110static void *afs_proc_servers_next(struct seq_file *p, void *v, 92static void *afs_proc_servers_next(struct seq_file *p, void *v,
111 loff_t *pos); 93 loff_t *pos);
@@ -119,13 +101,6 @@ static const struct seq_operations afs_proc_servers_ops = {
119 .show = afs_proc_servers_show, 101 .show = afs_proc_servers_show,
120}; 102};
121 103
122static const struct file_operations afs_proc_servers_fops = {
123 .open = afs_proc_servers_open,
124 .read = seq_read,
125 .llseek = seq_lseek,
126 .release = seq_release,
127};
128
129static int afs_proc_sysname_open(struct inode *inode, struct file *file); 104static int afs_proc_sysname_open(struct inode *inode, struct file *file);
130static int afs_proc_sysname_release(struct inode *inode, struct file *file); 105static int afs_proc_sysname_release(struct inode *inode, struct file *file);
131static void *afs_proc_sysname_start(struct seq_file *p, loff_t *pos); 106static void *afs_proc_sysname_start(struct seq_file *p, loff_t *pos);
@@ -152,7 +127,7 @@ static const struct file_operations afs_proc_sysname_fops = {
152 .write = afs_proc_sysname_write, 127 .write = afs_proc_sysname_write,
153}; 128};
154 129
155static const struct file_operations afs_proc_stats_fops; 130static int afs_proc_stats_show(struct seq_file *m, void *v);
156 131
157/* 132/*
158 * initialise the /proc/fs/afs/ directory 133 * initialise the /proc/fs/afs/ directory
@@ -167,8 +142,8 @@ int afs_proc_init(struct afs_net *net)
167 142
168 if (!proc_create("cells", 0644, net->proc_afs, &afs_proc_cells_fops) || 143 if (!proc_create("cells", 0644, net->proc_afs, &afs_proc_cells_fops) ||
169 !proc_create("rootcell", 0644, net->proc_afs, &afs_proc_rootcell_fops) || 144 !proc_create("rootcell", 0644, net->proc_afs, &afs_proc_rootcell_fops) ||
170 !proc_create("servers", 0644, net->proc_afs, &afs_proc_servers_fops) || 145 !proc_create_seq("servers", 0644, net->proc_afs, &afs_proc_servers_ops) ||
171 !proc_create("stats", 0644, net->proc_afs, &afs_proc_stats_fops) || 146 !proc_create_single("stats", 0644, net->proc_afs, afs_proc_stats_show) ||
172 !proc_create("sysname", 0644, net->proc_afs, &afs_proc_sysname_fops)) 147 !proc_create("sysname", 0644, net->proc_afs, &afs_proc_sysname_fops))
173 goto error_tree; 148 goto error_tree;
174 149
@@ -196,16 +171,7 @@ void afs_proc_cleanup(struct afs_net *net)
196 */ 171 */
197static int afs_proc_cells_open(struct inode *inode, struct file *file) 172static int afs_proc_cells_open(struct inode *inode, struct file *file)
198{ 173{
199 struct seq_file *m; 174 return seq_open(file, &afs_proc_cells_ops);
200 int ret;
201
202 ret = seq_open(file, &afs_proc_cells_ops);
203 if (ret < 0)
204 return ret;
205
206 m = file->private_data;
207 m->private = PDE_DATA(inode);
208 return 0;
209} 175}
210 176
211/* 177/*
@@ -430,10 +396,11 @@ int afs_proc_cell_setup(struct afs_net *net, struct afs_cell *cell)
430 if (!dir) 396 if (!dir)
431 goto error_dir; 397 goto error_dir;
432 398
433 if (!proc_create_data("vlservers", 0, dir, 399 if (!proc_create_seq_data("vlservers", 0, dir,
434 &afs_proc_cell_vlservers_fops, cell) || 400 &afs_proc_cell_vlservers_ops, cell))
435 !proc_create_data("volumes", 0, dir, 401 goto error_tree;
436 &afs_proc_cell_volumes_fops, cell)) 402 if (!proc_create_seq_data("volumes", 0, dir, &afs_proc_cell_volumes_ops,
403 cell))
437 goto error_tree; 404 goto error_tree;
438 405
439 _leave(" = 0"); 406 _leave(" = 0");
@@ -459,36 +426,13 @@ void afs_proc_cell_remove(struct afs_net *net, struct afs_cell *cell)
459} 426}
460 427
461/* 428/*
462 * open "/proc/fs/afs/<cell>/volumes" which provides a summary of extant cells
463 */
464static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file)
465{
466 struct afs_cell *cell;
467 struct seq_file *m;
468 int ret;
469
470 cell = PDE_DATA(inode);
471 if (!cell)
472 return -ENOENT;
473
474 ret = seq_open(file, &afs_proc_cell_volumes_ops);
475 if (ret < 0)
476 return ret;
477
478 m = file->private_data;
479 m->private = cell;
480
481 return 0;
482}
483
484/*
485 * set up the iterator to start reading from the cells list and return the 429 * set up the iterator to start reading from the cells list and return the
486 * first item 430 * first item
487 */ 431 */
488static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos) 432static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos)
489 __acquires(cell->proc_lock) 433 __acquires(cell->proc_lock)
490{ 434{
491 struct afs_cell *cell = m->private; 435 struct afs_cell *cell = PDE_DATA(file_inode(m->file));
492 436
493 _enter("cell=%p pos=%Ld", cell, *_pos); 437 _enter("cell=%p pos=%Ld", cell, *_pos);
494 438
@@ -502,7 +446,7 @@ static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos)
502static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v, 446static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
503 loff_t *_pos) 447 loff_t *_pos)
504{ 448{
505 struct afs_cell *cell = p->private; 449 struct afs_cell *cell = PDE_DATA(file_inode(p->file));
506 450
507 _enter("cell=%p pos=%Ld", cell, *_pos); 451 _enter("cell=%p pos=%Ld", cell, *_pos);
508 return seq_list_next(v, &cell->proc_volumes, _pos); 452 return seq_list_next(v, &cell->proc_volumes, _pos);
@@ -514,7 +458,7 @@ static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
514static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v) 458static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v)
515 __releases(cell->proc_lock) 459 __releases(cell->proc_lock)
516{ 460{
517 struct afs_cell *cell = p->private; 461 struct afs_cell *cell = PDE_DATA(file_inode(p->file));
518 462
519 read_unlock(&cell->proc_lock); 463 read_unlock(&cell->proc_lock);
520} 464}
@@ -530,7 +474,7 @@ static const char afs_vol_types[3][3] = {
530 */ 474 */
531static int afs_proc_cell_volumes_show(struct seq_file *m, void *v) 475static int afs_proc_cell_volumes_show(struct seq_file *m, void *v)
532{ 476{
533 struct afs_cell *cell = m->private; 477 struct afs_cell *cell = PDE_DATA(file_inode(m->file));
534 struct afs_volume *vol = list_entry(v, struct afs_volume, proc_link); 478 struct afs_volume *vol = list_entry(v, struct afs_volume, proc_link);
535 479
536 /* Display header on line 1 */ 480 /* Display header on line 1 */
@@ -547,30 +491,6 @@ static int afs_proc_cell_volumes_show(struct seq_file *m, void *v)
547} 491}
548 492
549/* 493/*
550 * open "/proc/fs/afs/<cell>/vlservers" which provides a list of volume
551 * location server
552 */
553static int afs_proc_cell_vlservers_open(struct inode *inode, struct file *file)
554{
555 struct afs_cell *cell;
556 struct seq_file *m;
557 int ret;
558
559 cell = PDE_DATA(inode);
560 if (!cell)
561 return -ENOENT;
562
563 ret = seq_open(file, &afs_proc_cell_vlservers_ops);
564 if (ret<0)
565 return ret;
566
567 m = file->private_data;
568 m->private = cell;
569
570 return 0;
571}
572
573/*
574 * set up the iterator to start reading from the cells list and return the 494 * set up the iterator to start reading from the cells list and return the
575 * first item 495 * first item
576 */ 496 */
@@ -578,7 +498,7 @@ static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos)
578 __acquires(rcu) 498 __acquires(rcu)
579{ 499{
580 struct afs_addr_list *alist; 500 struct afs_addr_list *alist;
581 struct afs_cell *cell = m->private; 501 struct afs_cell *cell = PDE_DATA(file_inode(m->file));
582 loff_t pos = *_pos; 502 loff_t pos = *_pos;
583 503
584 rcu_read_lock(); 504 rcu_read_lock();
@@ -603,7 +523,7 @@ static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v,
603 loff_t *_pos) 523 loff_t *_pos)
604{ 524{
605 struct afs_addr_list *alist; 525 struct afs_addr_list *alist;
606 struct afs_cell *cell = p->private; 526 struct afs_cell *cell = PDE_DATA(file_inode(p->file));
607 loff_t pos; 527 loff_t pos;
608 528
609 alist = rcu_dereference(cell->vl_addrs); 529 alist = rcu_dereference(cell->vl_addrs);
@@ -644,15 +564,6 @@ static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v)
644} 564}
645 565
646/* 566/*
647 * open "/proc/fs/afs/servers" which provides a summary of active
648 * servers
649 */
650static int afs_proc_servers_open(struct inode *inode, struct file *file)
651{
652 return seq_open(file, &afs_proc_servers_ops);
653}
654
655/*
656 * Set up the iterator to start reading from the server list and return the 567 * Set up the iterator to start reading from the server list and return the
657 * first item. 568 * first item.
658 */ 569 */
@@ -931,18 +842,3 @@ static int afs_proc_stats_show(struct seq_file *m, void *v)
931 atomic_long_read(&net->n_store_bytes)); 842 atomic_long_read(&net->n_store_bytes));
932 return 0; 843 return 0;
933} 844}
934
935/*
936 * Open "/proc/fs/afs/stats" to allow reading of the stat counters.
937 */
938static int afs_proc_stats_open(struct inode *inode, struct file *file)
939{
940 return single_open(file, afs_proc_stats_show, NULL);
941}
942
943static const struct file_operations afs_proc_stats_fops = {
944 .open = afs_proc_stats_open,
945 .read = seq_read,
946 .llseek = seq_lseek,
947 .release = single_release,
948};