1 /* proc.c: /proc interface for AFS
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/sched.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <linux/proc_fs.h>
16 #include <linux/seq_file.h>
19 #include <asm/uaccess.h>
22 static struct proc_dir_entry
*proc_afs
;
25 static int afs_proc_cells_open(struct inode
*inode
, struct file
*file
);
26 static void *afs_proc_cells_start(struct seq_file
*p
, loff_t
*pos
);
27 static void *afs_proc_cells_next(struct seq_file
*p
, void *v
, loff_t
*pos
);
28 static void afs_proc_cells_stop(struct seq_file
*p
, void *v
);
29 static int afs_proc_cells_show(struct seq_file
*m
, void *v
);
30 static ssize_t
afs_proc_cells_write(struct file
*file
, const char __user
*buf
,
31 size_t size
, loff_t
*_pos
);
33 static struct seq_operations afs_proc_cells_ops
= {
34 .start
= afs_proc_cells_start
,
35 .next
= afs_proc_cells_next
,
36 .stop
= afs_proc_cells_stop
,
37 .show
= afs_proc_cells_show
,
40 static const struct file_operations afs_proc_cells_fops
= {
41 .open
= afs_proc_cells_open
,
43 .write
= afs_proc_cells_write
,
45 .release
= seq_release
,
48 static int afs_proc_rootcell_open(struct inode
*inode
, struct file
*file
);
49 static int afs_proc_rootcell_release(struct inode
*inode
, struct file
*file
);
50 static ssize_t
afs_proc_rootcell_read(struct file
*file
, char __user
*buf
,
51 size_t size
, loff_t
*_pos
);
52 static ssize_t
afs_proc_rootcell_write(struct file
*file
,
53 const char __user
*buf
,
54 size_t size
, loff_t
*_pos
);
56 static const struct file_operations afs_proc_rootcell_fops
= {
57 .open
= afs_proc_rootcell_open
,
58 .read
= afs_proc_rootcell_read
,
59 .write
= afs_proc_rootcell_write
,
61 .release
= afs_proc_rootcell_release
64 static int afs_proc_cell_volumes_open(struct inode
*inode
, struct file
*file
);
65 static int afs_proc_cell_volumes_release(struct inode
*inode
,
67 static void *afs_proc_cell_volumes_start(struct seq_file
*p
, loff_t
*pos
);
68 static void *afs_proc_cell_volumes_next(struct seq_file
*p
, void *v
,
70 static void afs_proc_cell_volumes_stop(struct seq_file
*p
, void *v
);
71 static int afs_proc_cell_volumes_show(struct seq_file
*m
, void *v
);
73 static struct seq_operations afs_proc_cell_volumes_ops
= {
74 .start
= afs_proc_cell_volumes_start
,
75 .next
= afs_proc_cell_volumes_next
,
76 .stop
= afs_proc_cell_volumes_stop
,
77 .show
= afs_proc_cell_volumes_show
,
80 static const struct file_operations afs_proc_cell_volumes_fops
= {
81 .open
= afs_proc_cell_volumes_open
,
84 .release
= afs_proc_cell_volumes_release
,
87 static int afs_proc_cell_vlservers_open(struct inode
*inode
,
89 static int afs_proc_cell_vlservers_release(struct inode
*inode
,
91 static void *afs_proc_cell_vlservers_start(struct seq_file
*p
, loff_t
*pos
);
92 static void *afs_proc_cell_vlservers_next(struct seq_file
*p
, void *v
,
94 static void afs_proc_cell_vlservers_stop(struct seq_file
*p
, void *v
);
95 static int afs_proc_cell_vlservers_show(struct seq_file
*m
, void *v
);
97 static struct seq_operations afs_proc_cell_vlservers_ops
= {
98 .start
= afs_proc_cell_vlservers_start
,
99 .next
= afs_proc_cell_vlservers_next
,
100 .stop
= afs_proc_cell_vlservers_stop
,
101 .show
= afs_proc_cell_vlservers_show
,
104 static const struct file_operations afs_proc_cell_vlservers_fops
= {
105 .open
= afs_proc_cell_vlservers_open
,
108 .release
= afs_proc_cell_vlservers_release
,
111 static int afs_proc_cell_servers_open(struct inode
*inode
, struct file
*file
);
112 static int afs_proc_cell_servers_release(struct inode
*inode
,
114 static void *afs_proc_cell_servers_start(struct seq_file
*p
, loff_t
*pos
);
115 static void *afs_proc_cell_servers_next(struct seq_file
*p
, void *v
,
117 static void afs_proc_cell_servers_stop(struct seq_file
*p
, void *v
);
118 static int afs_proc_cell_servers_show(struct seq_file
*m
, void *v
);
120 static struct seq_operations afs_proc_cell_servers_ops
= {
121 .start
= afs_proc_cell_servers_start
,
122 .next
= afs_proc_cell_servers_next
,
123 .stop
= afs_proc_cell_servers_stop
,
124 .show
= afs_proc_cell_servers_show
,
127 static const struct file_operations afs_proc_cell_servers_fops
= {
128 .open
= afs_proc_cell_servers_open
,
131 .release
= afs_proc_cell_servers_release
,
134 /*****************************************************************************/
136 * initialise the /proc/fs/afs/ directory
138 int afs_proc_init(void)
140 struct proc_dir_entry
*p
;
144 proc_afs
= proc_mkdir("fs/afs", NULL
);
147 proc_afs
->owner
= THIS_MODULE
;
149 p
= create_proc_entry("cells", 0, proc_afs
);
152 p
->proc_fops
= &afs_proc_cells_fops
;
153 p
->owner
= THIS_MODULE
;
155 p
= create_proc_entry("rootcell", 0, proc_afs
);
158 p
->proc_fops
= &afs_proc_rootcell_fops
;
159 p
->owner
= THIS_MODULE
;
165 remove_proc_entry("cells", proc_afs
);
167 remove_proc_entry("fs/afs", NULL
);
169 _leave(" = -ENOMEM");
172 } /* end afs_proc_init() */
174 /*****************************************************************************/
176 * clean up the /proc/fs/afs/ directory
178 void afs_proc_cleanup(void)
180 remove_proc_entry("cells", proc_afs
);
182 remove_proc_entry("fs/afs", NULL
);
184 } /* end afs_proc_cleanup() */
186 /*****************************************************************************/
188 * open "/proc/fs/afs/cells" which provides a summary of extant cells
190 static int afs_proc_cells_open(struct inode
*inode
, struct file
*file
)
195 ret
= seq_open(file
, &afs_proc_cells_ops
);
199 m
= file
->private_data
;
200 m
->private = PDE(inode
)->data
;
203 } /* end afs_proc_cells_open() */
205 /*****************************************************************************/
207 * set up the iterator to start reading from the cells list and return the
210 static void *afs_proc_cells_start(struct seq_file
*m
, loff_t
*_pos
)
212 struct list_head
*_p
;
215 /* lock the list against modification */
216 down_read(&afs_proc_cells_sem
);
218 /* allow for the header line */
223 /* find the n'th element in the list */
224 list_for_each(_p
, &afs_proc_cells
)
228 return _p
!= &afs_proc_cells
? _p
: NULL
;
229 } /* end afs_proc_cells_start() */
231 /*****************************************************************************/
233 * move to next cell in cells list
235 static void *afs_proc_cells_next(struct seq_file
*p
, void *v
, loff_t
*pos
)
237 struct list_head
*_p
;
242 _p
= v
== (void *) 1 ? afs_proc_cells
.next
: _p
->next
;
244 return _p
!= &afs_proc_cells
? _p
: NULL
;
245 } /* end afs_proc_cells_next() */
247 /*****************************************************************************/
249 * clean up after reading from the cells list
251 static void afs_proc_cells_stop(struct seq_file
*p
, void *v
)
253 up_read(&afs_proc_cells_sem
);
255 } /* end afs_proc_cells_stop() */
257 /*****************************************************************************/
259 * display a header line followed by a load of cell lines
261 static int afs_proc_cells_show(struct seq_file
*m
, void *v
)
263 struct afs_cell
*cell
= list_entry(v
, struct afs_cell
, proc_link
);
265 /* display header on line 1 */
266 if (v
== (void *) 1) {
267 seq_puts(m
, "USE NAME\n");
271 /* display one cell per line on subsequent lines */
272 seq_printf(m
, "%3d %s\n", atomic_read(&cell
->usage
), cell
->name
);
275 } /* end afs_proc_cells_show() */
277 /*****************************************************************************/
279 * handle writes to /proc/fs/afs/cells
280 * - to add cells: echo "add <cellname> <IP>[:<IP>][:<IP>]"
282 static ssize_t
afs_proc_cells_write(struct file
*file
, const char __user
*buf
,
283 size_t size
, loff_t
*_pos
)
285 char *kbuf
, *name
, *args
;
288 /* start by dragging the command into memory */
289 if (size
<= 1 || size
>= PAGE_SIZE
)
292 kbuf
= kmalloc(size
+ 1, GFP_KERNEL
);
297 if (copy_from_user(kbuf
, buf
, size
) != 0)
301 /* trim to first NL */
302 name
= memchr(kbuf
, '\n', size
);
306 /* split into command, name and argslist */
307 name
= strchr(kbuf
, ' ');
312 } while(*name
== ' ');
316 args
= strchr(name
, ' ');
321 } while(*args
== ' ');
325 /* determine command to perform */
326 _debug("cmd=%s name=%s args=%s", kbuf
, name
, args
);
328 if (strcmp(kbuf
, "add") == 0) {
329 struct afs_cell
*cell
;
330 ret
= afs_cell_create(name
, args
, &cell
);
334 printk("kAFS: Added new cell '%s'\n", name
);
344 _leave(" = %d", ret
);
349 printk("kAFS: Invalid Command on /proc/fs/afs/cells file\n");
351 } /* end afs_proc_cells_write() */
353 /*****************************************************************************/
355 * Stubs for /proc/fs/afs/rootcell
357 static int afs_proc_rootcell_open(struct inode
*inode
, struct file
*file
)
362 static int afs_proc_rootcell_release(struct inode
*inode
, struct file
*file
)
367 static ssize_t
afs_proc_rootcell_read(struct file
*file
, char __user
*buf
,
368 size_t size
, loff_t
*_pos
)
373 /*****************************************************************************/
375 * handle writes to /proc/fs/afs/rootcell
376 * - to initialize rootcell: echo "cell.name:192.168.231.14"
378 static ssize_t
afs_proc_rootcell_write(struct file
*file
,
379 const char __user
*buf
,
380 size_t size
, loff_t
*_pos
)
385 /* start by dragging the command into memory */
386 if (size
<= 1 || size
>= PAGE_SIZE
)
390 kbuf
= kmalloc(size
+ 1, GFP_KERNEL
);
395 if (copy_from_user(kbuf
, buf
, size
) != 0)
399 /* trim to first NL */
400 s
= memchr(kbuf
, '\n', size
);
404 /* determine command to perform */
405 _debug("rootcell=%s", kbuf
);
407 ret
= afs_cell_init(kbuf
);
409 ret
= size
; /* consume everything, always */
414 _leave(" = %d", ret
);
416 } /* end afs_proc_rootcell_write() */
418 /*****************************************************************************/
420 * initialise /proc/fs/afs/<cell>/
422 int afs_proc_cell_setup(struct afs_cell
*cell
)
424 struct proc_dir_entry
*p
;
426 _enter("%p{%s}", cell
, cell
->name
);
428 cell
->proc_dir
= proc_mkdir(cell
->name
, proc_afs
);
432 p
= create_proc_entry("servers", 0, cell
->proc_dir
);
435 p
->proc_fops
= &afs_proc_cell_servers_fops
;
436 p
->owner
= THIS_MODULE
;
439 p
= create_proc_entry("vlservers", 0, cell
->proc_dir
);
442 p
->proc_fops
= &afs_proc_cell_vlservers_fops
;
443 p
->owner
= THIS_MODULE
;
446 p
= create_proc_entry("volumes", 0, cell
->proc_dir
);
448 goto error_vlservers
;
449 p
->proc_fops
= &afs_proc_cell_volumes_fops
;
450 p
->owner
= THIS_MODULE
;
457 remove_proc_entry("vlservers", cell
->proc_dir
);
459 remove_proc_entry("servers", cell
->proc_dir
);
461 remove_proc_entry(cell
->name
, proc_afs
);
462 _leave(" = -ENOMEM");
464 } /* end afs_proc_cell_setup() */
466 /*****************************************************************************/
468 * remove /proc/fs/afs/<cell>/
470 void afs_proc_cell_remove(struct afs_cell
*cell
)
474 remove_proc_entry("volumes", cell
->proc_dir
);
475 remove_proc_entry("vlservers", cell
->proc_dir
);
476 remove_proc_entry("servers", cell
->proc_dir
);
477 remove_proc_entry(cell
->name
, proc_afs
);
480 } /* end afs_proc_cell_remove() */
482 /*****************************************************************************/
484 * open "/proc/fs/afs/<cell>/volumes" which provides a summary of extant cells
486 static int afs_proc_cell_volumes_open(struct inode
*inode
, struct file
*file
)
488 struct afs_cell
*cell
;
492 cell
= afs_get_cell_maybe((struct afs_cell
**) &PDE(inode
)->data
);
496 ret
= seq_open(file
, &afs_proc_cell_volumes_ops
);
500 m
= file
->private_data
;
504 } /* end afs_proc_cell_volumes_open() */
506 /*****************************************************************************/
508 * close the file and release the ref to the cell
510 static int afs_proc_cell_volumes_release(struct inode
*inode
, struct file
*file
)
512 struct afs_cell
*cell
= PDE(inode
)->data
;
515 ret
= seq_release(inode
,file
);
520 } /* end afs_proc_cell_volumes_release() */
522 /*****************************************************************************/
524 * set up the iterator to start reading from the cells list and return the
527 static void *afs_proc_cell_volumes_start(struct seq_file
*m
, loff_t
*_pos
)
529 struct list_head
*_p
;
530 struct afs_cell
*cell
= m
->private;
533 _enter("cell=%p pos=%Ld", cell
, *_pos
);
535 /* lock the list against modification */
536 down_read(&cell
->vl_sem
);
538 /* allow for the header line */
543 /* find the n'th element in the list */
544 list_for_each(_p
, &cell
->vl_list
)
548 return _p
!= &cell
->vl_list
? _p
: NULL
;
549 } /* end afs_proc_cell_volumes_start() */
551 /*****************************************************************************/
553 * move to next cell in cells list
555 static void *afs_proc_cell_volumes_next(struct seq_file
*p
, void *v
,
558 struct list_head
*_p
;
559 struct afs_cell
*cell
= p
->private;
561 _enter("cell=%p pos=%Ld", cell
, *_pos
);
566 _p
= v
== (void *) 1 ? cell
->vl_list
.next
: _p
->next
;
568 return _p
!= &cell
->vl_list
? _p
: NULL
;
569 } /* end afs_proc_cell_volumes_next() */
571 /*****************************************************************************/
573 * clean up after reading from the cells list
575 static void afs_proc_cell_volumes_stop(struct seq_file
*p
, void *v
)
577 struct afs_cell
*cell
= p
->private;
579 up_read(&cell
->vl_sem
);
581 } /* end afs_proc_cell_volumes_stop() */
583 /*****************************************************************************/
585 * display a header line followed by a load of volume lines
587 static int afs_proc_cell_volumes_show(struct seq_file
*m
, void *v
)
589 struct afs_vlocation
*vlocation
=
590 list_entry(v
, struct afs_vlocation
, link
);
592 /* display header on line 1 */
593 if (v
== (void *) 1) {
594 seq_puts(m
, "USE VLID[0] VLID[1] VLID[2] NAME\n");
598 /* display one cell per line on subsequent lines */
599 seq_printf(m
, "%3d %08x %08x %08x %s\n",
600 atomic_read(&vlocation
->usage
),
601 vlocation
->vldb
.vid
[0],
602 vlocation
->vldb
.vid
[1],
603 vlocation
->vldb
.vid
[2],
608 } /* end afs_proc_cell_volumes_show() */
610 /*****************************************************************************/
612 * open "/proc/fs/afs/<cell>/vlservers" which provides a list of volume
615 static int afs_proc_cell_vlservers_open(struct inode
*inode
, struct file
*file
)
617 struct afs_cell
*cell
;
621 cell
= afs_get_cell_maybe((struct afs_cell
**)&PDE(inode
)->data
);
625 ret
= seq_open(file
,&afs_proc_cell_vlservers_ops
);
629 m
= file
->private_data
;
633 } /* end afs_proc_cell_vlservers_open() */
635 /*****************************************************************************/
637 * close the file and release the ref to the cell
639 static int afs_proc_cell_vlservers_release(struct inode
*inode
,
642 struct afs_cell
*cell
= PDE(inode
)->data
;
645 ret
= seq_release(inode
,file
);
650 } /* end afs_proc_cell_vlservers_release() */
652 /*****************************************************************************/
654 * set up the iterator to start reading from the cells list and return the
657 static void *afs_proc_cell_vlservers_start(struct seq_file
*m
, loff_t
*_pos
)
659 struct afs_cell
*cell
= m
->private;
662 _enter("cell=%p pos=%Ld", cell
, *_pos
);
664 /* lock the list against modification */
665 down_read(&cell
->vl_sem
);
667 /* allow for the header line */
672 if (pos
>= cell
->vl_naddrs
)
675 return &cell
->vl_addrs
[pos
];
676 } /* end afs_proc_cell_vlservers_start() */
678 /*****************************************************************************/
680 * move to next cell in cells list
682 static void *afs_proc_cell_vlservers_next(struct seq_file
*p
, void *v
,
685 struct afs_cell
*cell
= p
->private;
688 _enter("cell=%p{nad=%u} pos=%Ld", cell
, cell
->vl_naddrs
, *_pos
);
692 if (pos
>= cell
->vl_naddrs
)
695 return &cell
->vl_addrs
[pos
];
696 } /* end afs_proc_cell_vlservers_next() */
698 /*****************************************************************************/
700 * clean up after reading from the cells list
702 static void afs_proc_cell_vlservers_stop(struct seq_file
*p
, void *v
)
704 struct afs_cell
*cell
= p
->private;
706 up_read(&cell
->vl_sem
);
708 } /* end afs_proc_cell_vlservers_stop() */
710 /*****************************************************************************/
712 * display a header line followed by a load of volume lines
714 static int afs_proc_cell_vlservers_show(struct seq_file
*m
, void *v
)
716 struct in_addr
*addr
= v
;
718 /* display header on line 1 */
719 if (v
== (struct in_addr
*) 1) {
720 seq_puts(m
, "ADDRESS\n");
724 /* display one cell per line on subsequent lines */
725 seq_printf(m
, "%u.%u.%u.%u\n", NIPQUAD(addr
->s_addr
));
728 } /* end afs_proc_cell_vlservers_show() */
730 /*****************************************************************************/
732 * open "/proc/fs/afs/<cell>/servers" which provides a summary of active
735 static int afs_proc_cell_servers_open(struct inode
*inode
, struct file
*file
)
737 struct afs_cell
*cell
;
741 cell
= afs_get_cell_maybe((struct afs_cell
**) &PDE(inode
)->data
);
745 ret
= seq_open(file
, &afs_proc_cell_servers_ops
);
749 m
= file
->private_data
;
753 } /* end afs_proc_cell_servers_open() */
755 /*****************************************************************************/
757 * close the file and release the ref to the cell
759 static int afs_proc_cell_servers_release(struct inode
*inode
,
762 struct afs_cell
*cell
= PDE(inode
)->data
;
765 ret
= seq_release(inode
, file
);
770 } /* end afs_proc_cell_servers_release() */
772 /*****************************************************************************/
774 * set up the iterator to start reading from the cells list and return the
777 static void *afs_proc_cell_servers_start(struct seq_file
*m
, loff_t
*_pos
)
778 __acquires(m
->private->sv_lock
)
780 struct list_head
*_p
;
781 struct afs_cell
*cell
= m
->private;
784 _enter("cell=%p pos=%Ld", cell
, *_pos
);
786 /* lock the list against modification */
787 read_lock(&cell
->sv_lock
);
789 /* allow for the header line */
794 /* find the n'th element in the list */
795 list_for_each(_p
, &cell
->sv_list
)
799 return _p
!= &cell
->sv_list
? _p
: NULL
;
800 } /* end afs_proc_cell_servers_start() */
802 /*****************************************************************************/
804 * move to next cell in cells list
806 static void *afs_proc_cell_servers_next(struct seq_file
*p
, void *v
,
809 struct list_head
*_p
;
810 struct afs_cell
*cell
= p
->private;
812 _enter("cell=%p pos=%Ld", cell
, *_pos
);
817 _p
= v
== (void *) 1 ? cell
->sv_list
.next
: _p
->next
;
819 return _p
!= &cell
->sv_list
? _p
: NULL
;
820 } /* end afs_proc_cell_servers_next() */
822 /*****************************************************************************/
824 * clean up after reading from the cells list
826 static void afs_proc_cell_servers_stop(struct seq_file
*p
, void *v
)
827 __releases(p
->private->sv_lock
)
829 struct afs_cell
*cell
= p
->private;
831 read_unlock(&cell
->sv_lock
);
833 } /* end afs_proc_cell_servers_stop() */
835 /*****************************************************************************/
837 * display a header line followed by a load of volume lines
839 static int afs_proc_cell_servers_show(struct seq_file
*m
, void *v
)
841 struct afs_server
*server
= list_entry(v
, struct afs_server
, link
);
844 /* display header on line 1 */
845 if (v
== (void *) 1) {
846 seq_puts(m
, "USE ADDR STATE\n");
850 /* display one cell per line on subsequent lines */
851 sprintf(ipaddr
, "%u.%u.%u.%u", NIPQUAD(server
->addr
));
852 seq_printf(m
, "%3d %-15.15s %5d\n",
853 atomic_read(&server
->usage
),
859 } /* end afs_proc_cell_servers_show() */