ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / fs / afs / proc.c
1 /* proc.c: /proc interface for AFS
2  *
3  * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
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.
10  */
11
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>
17 #include "cell.h"
18 #include "volume.h"
19 #include <asm/uaccess.h>
20 #include "internal.h"
21
22 static struct proc_dir_entry *proc_afs;
23
24
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 *buf,
31                                     size_t size, loff_t *_pos);
32
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,
38 };
39
40 static struct file_operations afs_proc_cells_fops = {
41         .open           = afs_proc_cells_open,
42         .read           = seq_read,
43         .write          = afs_proc_cells_write,
44         .llseek         = seq_lseek,
45         .release        = seq_release,
46 };
47
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 *buf,
51                                       size_t size, loff_t *_pos);
52 static ssize_t afs_proc_rootcell_write(struct file *file, const char *buf,
53                                        size_t size, loff_t *_pos);
54
55 static struct file_operations afs_proc_rootcell_fops = {
56         .open           = afs_proc_rootcell_open,
57         .read           = afs_proc_rootcell_read,
58         .write          = afs_proc_rootcell_write,
59         .llseek         = no_llseek,
60         .release        = afs_proc_rootcell_release
61 };
62
63 static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file);
64 static int afs_proc_cell_volumes_release(struct inode *inode,
65                                          struct file *file);
66 static void *afs_proc_cell_volumes_start(struct seq_file *p, loff_t *pos);
67 static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
68                                         loff_t *pos);
69 static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v);
70 static int afs_proc_cell_volumes_show(struct seq_file *m, void *v);
71
72 static struct seq_operations afs_proc_cell_volumes_ops = {
73         .start  = afs_proc_cell_volumes_start,
74         .next   = afs_proc_cell_volumes_next,
75         .stop   = afs_proc_cell_volumes_stop,
76         .show   = afs_proc_cell_volumes_show,
77 };
78
79 static 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        = afs_proc_cell_volumes_release,
84 };
85
86 static int afs_proc_cell_vlservers_open(struct inode *inode,
87                                         struct file *file);
88 static int afs_proc_cell_vlservers_release(struct inode *inode,
89                                            struct file *file);
90 static void *afs_proc_cell_vlservers_start(struct seq_file *p, loff_t *pos);
91 static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v,
92                                           loff_t *pos);
93 static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v);
94 static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v);
95
96 static struct seq_operations afs_proc_cell_vlservers_ops = {
97         .start  = afs_proc_cell_vlservers_start,
98         .next   = afs_proc_cell_vlservers_next,
99         .stop   = afs_proc_cell_vlservers_stop,
100         .show   = afs_proc_cell_vlservers_show,
101 };
102
103 static struct file_operations afs_proc_cell_vlservers_fops = {
104         .open           = afs_proc_cell_vlservers_open,
105         .read           = seq_read,
106         .llseek         = seq_lseek,
107         .release        = afs_proc_cell_vlservers_release,
108 };
109
110 static int afs_proc_cell_servers_open(struct inode *inode, struct file *file);
111 static int afs_proc_cell_servers_release(struct inode *inode,
112                                          struct file *file);
113 static void *afs_proc_cell_servers_start(struct seq_file *p, loff_t *pos);
114 static void *afs_proc_cell_servers_next(struct seq_file *p, void *v,
115                                         loff_t *pos);
116 static void afs_proc_cell_servers_stop(struct seq_file *p, void *v);
117 static int afs_proc_cell_servers_show(struct seq_file *m, void *v);
118
119 static struct seq_operations afs_proc_cell_servers_ops = {
120         .start  = afs_proc_cell_servers_start,
121         .next   = afs_proc_cell_servers_next,
122         .stop   = afs_proc_cell_servers_stop,
123         .show   = afs_proc_cell_servers_show,
124 };
125
126 static struct file_operations afs_proc_cell_servers_fops = {
127         .open           = afs_proc_cell_servers_open,
128         .read           = seq_read,
129         .llseek         = seq_lseek,
130         .release        = afs_proc_cell_servers_release,
131 };
132
133 /*****************************************************************************/
134 /*
135  * initialise the /proc/fs/afs/ directory
136  */
137 int afs_proc_init(void)
138 {
139         struct proc_dir_entry *p;
140
141         _enter("");
142
143         proc_afs = proc_mkdir("fs/afs", NULL);
144         if (!proc_afs)
145                 goto error;
146         proc_afs->owner = THIS_MODULE;
147
148         p = create_proc_entry("cells", 0, proc_afs);
149         if (!p)
150                 goto error_proc;
151         p->proc_fops = &afs_proc_cells_fops;
152         p->owner = THIS_MODULE;
153
154         p = create_proc_entry("rootcell", 0, proc_afs);
155         if (!p)
156                 goto error_cells;
157         p->proc_fops = &afs_proc_rootcell_fops;
158         p->owner = THIS_MODULE;
159
160         _leave(" = 0");
161         return 0;
162
163  error_cells:
164         remove_proc_entry("cells", proc_afs);
165  error_proc:
166         remove_proc_entry("fs/afs", NULL);
167  error:
168         _leave(" = -ENOMEM");
169         return -ENOMEM;
170
171 } /* end afs_proc_init() */
172
173 /*****************************************************************************/
174 /*
175  * clean up the /proc/fs/afs/ directory
176  */
177 void afs_proc_cleanup(void)
178 {
179         remove_proc_entry("cells", proc_afs);
180
181         remove_proc_entry("fs/afs", NULL);
182
183 } /* end afs_proc_cleanup() */
184
185 /*****************************************************************************/
186 /*
187  * open "/proc/fs/afs/cells" which provides a summary of extant cells
188  */
189 static int afs_proc_cells_open(struct inode *inode, struct file *file)
190 {
191         struct seq_file *m;
192         int ret;
193
194         ret = seq_open(file, &afs_proc_cells_ops);
195         if (ret < 0)
196                 return ret;
197
198         m = file->private_data;
199         m->private = PDE(inode)->data;
200
201         return 0;
202 } /* end afs_proc_cells_open() */
203
204 /*****************************************************************************/
205 /*
206  * set up the iterator to start reading from the cells list and return the
207  * first item
208  */
209 static void *afs_proc_cells_start(struct seq_file *m, loff_t *_pos)
210 {
211         struct list_head *_p;
212         loff_t pos = *_pos;
213
214         /* lock the list against modification */
215         down_read(&afs_proc_cells_sem);
216
217         /* allow for the header line */
218         if (!pos)
219                 return (void *) 1;
220         pos--;
221
222         /* find the n'th element in the list */
223         list_for_each(_p, &afs_proc_cells)
224                 if (!pos--)
225                         break;
226
227         return _p != &afs_proc_cells ? _p : NULL;
228 } /* end afs_proc_cells_start() */
229
230 /*****************************************************************************/
231 /*
232  * move to next cell in cells list
233  */
234 static void *afs_proc_cells_next(struct seq_file *p, void *v, loff_t *pos)
235 {
236         struct list_head *_p;
237
238         (*pos)++;
239
240         _p = v;
241         _p = v == (void *) 1 ? afs_proc_cells.next : _p->next;
242
243         return _p != &afs_proc_cells ? _p : NULL;
244 } /* end afs_proc_cells_next() */
245
246 /*****************************************************************************/
247 /*
248  * clean up after reading from the cells list
249  */
250 static void afs_proc_cells_stop(struct seq_file *p, void *v)
251 {
252         up_read(&afs_proc_cells_sem);
253
254 } /* end afs_proc_cells_stop() */
255
256 /*****************************************************************************/
257 /*
258  * display a header line followed by a load of cell lines
259  */
260 static int afs_proc_cells_show(struct seq_file *m, void *v)
261 {
262         struct afs_cell *cell = list_entry(v, struct afs_cell, proc_link);
263
264         /* display header on line 1 */
265         if (v == (void *) 1) {
266                 seq_puts(m, "USE NAME\n");
267                 return 0;
268         }
269
270         /* display one cell per line on subsequent lines */
271         seq_printf(m, "%3d %s\n", atomic_read(&cell->usage), cell->name);
272
273         return 0;
274 } /* end afs_proc_cells_show() */
275
276 /*****************************************************************************/
277 /*
278  * handle writes to /proc/fs/afs/cells
279  * - to add cells: echo "add <cellname> <IP>[:<IP>][:<IP>]"
280  */
281 static ssize_t afs_proc_cells_write(struct file *file, const char *buf,
282                                     size_t size, loff_t *_pos)
283 {
284         char *kbuf, *name, *args;
285         int ret;
286
287         /* start by dragging the command into memory */
288         if (size <= 1 || size >= PAGE_SIZE)
289                 return -EINVAL;
290
291         kbuf = kmalloc(size + 1, GFP_KERNEL);
292         if (!kbuf)
293                 return -ENOMEM;
294
295         ret = -EFAULT;
296         if (copy_from_user(kbuf, buf, size) != 0)
297                 goto done;
298         kbuf[size] = 0;
299
300         /* trim to first NL */
301         name = memchr(kbuf, '\n', size);
302         if (name)
303                 *name = 0;
304
305         /* split into command, name and argslist */
306         name = strchr(kbuf, ' ');
307         if (!name)
308                 goto inval;
309         do {
310                 *name++ = 0;
311         } while(*name == ' ');
312         if (!*name)
313                 goto inval;
314
315         args = strchr(name, ' ');
316         if (!args)
317                 goto inval;
318         do {
319                 *args++ = 0;
320         } while(*args == ' ');
321         if (!*args)
322                 goto inval;
323
324         /* determine command to perform */
325         _debug("cmd=%s name=%s args=%s", kbuf, name, args);
326
327         if (strcmp(kbuf, "add") == 0) {
328                 struct afs_cell *cell;
329                 ret = afs_cell_create(name, args, &cell);
330                 if (ret < 0)
331                         goto done;
332
333                 printk("kAFS: Added new cell '%s'\n", name);
334         }
335         else {
336                 goto inval;
337         }
338
339         ret = size;
340
341  done:
342         kfree(kbuf);
343         _leave(" = %d", ret);
344         return ret;
345
346  inval:
347         ret = -EINVAL;
348         printk("kAFS: Invalid Command on /proc/fs/afs/cells file\n");
349         goto done;
350 } /* end afs_proc_cells_write() */
351
352 /*****************************************************************************/
353 /*
354  * Stubs for /proc/fs/afs/rootcell
355  */
356 static int afs_proc_rootcell_open(struct inode *inode, struct file *file)
357 {
358         return 0;
359 }
360
361 static int afs_proc_rootcell_release(struct inode *inode, struct file *file)
362 {
363         return 0;
364 }
365
366 static ssize_t afs_proc_rootcell_read(struct file *file, char *buf,
367                                       size_t size, loff_t *_pos)
368 {
369         return 0;
370 }
371
372 /*****************************************************************************/
373 /*
374  * handle writes to /proc/fs/afs/rootcell
375  * - to initialize rootcell: echo "cell.name:192.168.231.14"
376  */
377 static ssize_t afs_proc_rootcell_write(struct file *file, const char *buf,
378                                        size_t size, loff_t *_pos)
379 {
380         char *kbuf, *s;
381         int ret;
382
383         /* start by dragging the command into memory */
384         if (size <= 1 || size >= PAGE_SIZE)
385                 return -EINVAL;
386
387         ret = -ENOMEM;
388         kbuf = kmalloc(size + 1, GFP_KERNEL);
389         if (!kbuf)
390                 goto nomem;
391
392         ret = -EFAULT;
393         if (copy_from_user(kbuf, buf, size) != 0)
394                 goto infault;
395         kbuf[size] = 0;
396
397         /* trim to first NL */
398         s = memchr(kbuf, '\n', size);
399         if (s)
400                 *s = 0;
401
402         /* determine command to perform */
403         _debug("rootcell=%s", kbuf);
404
405         ret = afs_cell_init(kbuf);
406         if (ret >= 0)
407                 ret = size;     /* consume everything, always */
408
409  infault:
410         kfree(kbuf);
411  nomem:
412         _leave(" = %d", ret);
413         return ret;
414 } /* end afs_proc_rootcell_write() */
415
416 /*****************************************************************************/
417 /*
418  * initialise /proc/fs/afs/<cell>/
419  */
420 int afs_proc_cell_setup(struct afs_cell *cell)
421 {
422         struct proc_dir_entry *p;
423
424         _enter("%p{%s}", cell, cell->name);
425
426         cell->proc_dir = proc_mkdir(cell->name, proc_afs);
427         if (!cell->proc_dir)
428                 return -ENOMEM;
429
430         p = create_proc_entry("servers", 0, cell->proc_dir);
431         if (!p)
432                 goto error_proc;
433         p->proc_fops = &afs_proc_cell_servers_fops;
434         p->owner = THIS_MODULE;
435         p->data = cell;
436
437         p = create_proc_entry("vlservers", 0, cell->proc_dir);
438         if (!p)
439                 goto error_servers;
440         p->proc_fops = &afs_proc_cell_vlservers_fops;
441         p->owner = THIS_MODULE;
442         p->data = cell;
443
444         p = create_proc_entry("volumes", 0, cell->proc_dir);
445         if (!p)
446                 goto error_vlservers;
447         p->proc_fops = &afs_proc_cell_volumes_fops;
448         p->owner = THIS_MODULE;
449         p->data = cell;
450
451         _leave(" = 0");
452         return 0;
453
454  error_vlservers:
455         remove_proc_entry("vlservers", cell->proc_dir);
456  error_servers:
457         remove_proc_entry("servers", cell->proc_dir);
458  error_proc:
459         remove_proc_entry(cell->name, proc_afs);
460         _leave(" = -ENOMEM");
461         return -ENOMEM;
462 } /* end afs_proc_cell_setup() */
463
464 /*****************************************************************************/
465 /*
466  * remove /proc/fs/afs/<cell>/
467  */
468 void afs_proc_cell_remove(struct afs_cell *cell)
469 {
470         _enter("");
471
472         remove_proc_entry("volumes", cell->proc_dir);
473         remove_proc_entry("vlservers", cell->proc_dir);
474         remove_proc_entry("servers", cell->proc_dir);
475         remove_proc_entry(cell->name, proc_afs);
476
477         _leave("");
478 } /* end afs_proc_cell_remove() */
479
480 /*****************************************************************************/
481 /*
482  * open "/proc/fs/afs/<cell>/volumes" which provides a summary of extant cells
483  */
484 static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file)
485 {
486         struct afs_cell *cell;
487         struct seq_file *m;
488         int ret;
489
490         cell = afs_get_cell_maybe((struct afs_cell **) &PDE(inode)->data);
491         if (!cell)
492                 return -ENOENT;
493
494         ret = seq_open(file, &afs_proc_cell_volumes_ops);
495         if (ret < 0)
496                 return ret;
497
498         m = file->private_data;
499         m->private = cell;
500
501         return 0;
502 } /* end afs_proc_cell_volumes_open() */
503
504 /*****************************************************************************/
505 /*
506  * close the file and release the ref to the cell
507  */
508 static int afs_proc_cell_volumes_release(struct inode *inode, struct file *file)
509 {
510         struct afs_cell *cell = PDE(inode)->data;
511         int ret;
512
513         ret = seq_release(inode,file);
514
515         afs_put_cell(cell);
516
517         return ret;
518 } /* end afs_proc_cell_volumes_release() */
519
520 /*****************************************************************************/
521 /*
522  * set up the iterator to start reading from the cells list and return the
523  * first item
524  */
525 static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos)
526 {
527         struct list_head *_p;
528         struct afs_cell *cell = m->private;
529         loff_t pos = *_pos;
530
531         _enter("cell=%p pos=%Ld", cell, *_pos);
532
533         /* lock the list against modification */
534         down_read(&cell->vl_sem);
535
536         /* allow for the header line */
537         if (!pos)
538                 return (void *) 1;
539         pos--;
540
541         /* find the n'th element in the list */
542         list_for_each(_p, &cell->vl_list)
543                 if (!pos--)
544                         break;
545
546         return _p != &cell->vl_list ? _p : NULL;
547 } /* end afs_proc_cell_volumes_start() */
548
549 /*****************************************************************************/
550 /*
551  * move to next cell in cells list
552  */
553 static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
554                                         loff_t *_pos)
555 {
556         struct list_head *_p;
557         struct afs_cell *cell = p->private;
558
559         _enter("cell=%p pos=%Ld", cell, *_pos);
560
561         (*_pos)++;
562
563         _p = v;
564         _p = v == (void *) 1 ? cell->vl_list.next : _p->next;
565
566         return _p != &cell->vl_list ? _p : NULL;
567 } /* end afs_proc_cell_volumes_next() */
568
569 /*****************************************************************************/
570 /*
571  * clean up after reading from the cells list
572  */
573 static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v)
574 {
575         struct afs_cell *cell = p->private;
576
577         up_read(&cell->vl_sem);
578
579 } /* end afs_proc_cell_volumes_stop() */
580
581 /*****************************************************************************/
582 /*
583  * display a header line followed by a load of volume lines
584  */
585 static int afs_proc_cell_volumes_show(struct seq_file *m, void *v)
586 {
587         struct afs_vlocation *vlocation =
588                 list_entry(v, struct afs_vlocation, link);
589
590         /* display header on line 1 */
591         if (v == (void *) 1) {
592                 seq_puts(m, "USE VLID[0]  VLID[1]  VLID[2]  NAME\n");
593                 return 0;
594         }
595
596         /* display one cell per line on subsequent lines */
597         seq_printf(m, "%3d %08x %08x %08x %s\n",
598                    atomic_read(&vlocation->usage),
599                    vlocation->vldb.vid[0],
600                    vlocation->vldb.vid[1],
601                    vlocation->vldb.vid[2],
602                    vlocation->vldb.name
603                    );
604
605         return 0;
606 } /* end afs_proc_cell_volumes_show() */
607
608 /*****************************************************************************/
609 /*
610  * open "/proc/fs/afs/<cell>/vlservers" which provides a list of volume
611  * location server
612  */
613 static int afs_proc_cell_vlservers_open(struct inode *inode, struct file *file)
614 {
615         struct afs_cell *cell;
616         struct seq_file *m;
617         int ret;
618
619         cell = afs_get_cell_maybe((struct afs_cell**)&PDE(inode)->data);
620         if (!cell)
621                 return -ENOENT;
622
623         ret = seq_open(file,&afs_proc_cell_vlservers_ops);
624         if (ret<0)
625                 return ret;
626
627         m = file->private_data;
628         m->private = cell;
629
630         return 0;
631 } /* end afs_proc_cell_vlservers_open() */
632
633 /*****************************************************************************/
634 /*
635  * close the file and release the ref to the cell
636  */
637 static int afs_proc_cell_vlservers_release(struct inode *inode,
638                                            struct file *file)
639 {
640         struct afs_cell *cell = PDE(inode)->data;
641         int ret;
642
643         ret = seq_release(inode,file);
644
645         afs_put_cell(cell);
646
647         return ret;
648 } /* end afs_proc_cell_vlservers_release() */
649
650 /*****************************************************************************/
651 /*
652  * set up the iterator to start reading from the cells list and return the
653  * first item
654  */
655 static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos)
656 {
657         struct afs_cell *cell = m->private;
658         loff_t pos = *_pos;
659
660         _enter("cell=%p pos=%Ld", cell, *_pos);
661
662         /* lock the list against modification */
663         down_read(&cell->vl_sem);
664
665         /* allow for the header line */
666         if (!pos)
667                 return (void *) 1;
668         pos--;
669
670         if (pos >= cell->vl_naddrs)
671                 return NULL;
672
673         return &cell->vl_addrs[pos];
674 } /* end afs_proc_cell_vlservers_start() */
675
676 /*****************************************************************************/
677 /*
678  * move to next cell in cells list
679  */
680 static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v,
681                                           loff_t *_pos)
682 {
683         struct afs_cell *cell = p->private;
684         loff_t pos;
685
686         _enter("cell=%p{nad=%u} pos=%Ld", cell, cell->vl_naddrs, *_pos);
687
688         pos = *_pos;
689         (*_pos)++;
690         if (pos >= cell->vl_naddrs)
691                 return NULL;
692
693         return &cell->vl_addrs[pos];
694 } /* end afs_proc_cell_vlservers_next() */
695
696 /*****************************************************************************/
697 /*
698  * clean up after reading from the cells list
699  */
700 static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v)
701 {
702         struct afs_cell *cell = p->private;
703
704         up_read(&cell->vl_sem);
705
706 } /* end afs_proc_cell_vlservers_stop() */
707
708 /*****************************************************************************/
709 /*
710  * display a header line followed by a load of volume lines
711  */
712 static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v)
713 {
714         struct in_addr *addr = v;
715
716         /* display header on line 1 */
717         if (v == (struct in_addr *) 1) {
718                 seq_puts(m, "ADDRESS\n");
719                 return 0;
720         }
721
722         /* display one cell per line on subsequent lines */
723         seq_printf(m, "%u.%u.%u.%u\n", NIPQUAD(addr->s_addr));
724
725         return 0;
726 } /* end afs_proc_cell_vlservers_show() */
727
728 /*****************************************************************************/
729 /*
730  * open "/proc/fs/afs/<cell>/servers" which provides a summary of active
731  * servers
732  */
733 static int afs_proc_cell_servers_open(struct inode *inode, struct file *file)
734 {
735         struct afs_cell *cell;
736         struct seq_file *m;
737         int ret;
738
739         cell = afs_get_cell_maybe((struct afs_cell **) &PDE(inode)->data);
740         if (!cell)
741                 return -ENOENT;
742
743         ret = seq_open(file, &afs_proc_cell_servers_ops);
744         if (ret < 0)
745                 return ret;
746
747         m = file->private_data;
748         m->private = cell;
749
750         return 0;
751 } /* end afs_proc_cell_servers_open() */
752
753 /*****************************************************************************/
754 /*
755  * close the file and release the ref to the cell
756  */
757 static int afs_proc_cell_servers_release(struct inode *inode,
758                                          struct file *file)
759 {
760         struct afs_cell *cell = PDE(inode)->data;
761         int ret;
762
763         ret = seq_release(inode, file);
764
765         afs_put_cell(cell);
766
767         return ret;
768 } /* end afs_proc_cell_servers_release() */
769
770 /*****************************************************************************/
771 /*
772  * set up the iterator to start reading from the cells list and return the
773  * first item
774  */
775 static void *afs_proc_cell_servers_start(struct seq_file *m, loff_t *_pos)
776 {
777         struct list_head *_p;
778         struct afs_cell *cell = m->private;
779         loff_t pos = *_pos;
780
781         _enter("cell=%p pos=%Ld", cell, *_pos);
782
783         /* lock the list against modification */
784         read_lock(&cell->sv_lock);
785
786         /* allow for the header line */
787         if (!pos)
788                 return (void *) 1;
789         pos--;
790
791         /* find the n'th element in the list */
792         list_for_each(_p, &cell->sv_list)
793                 if (!pos--)
794                         break;
795
796         return _p != &cell->sv_list ? _p : NULL;
797 } /* end afs_proc_cell_servers_start() */
798
799 /*****************************************************************************/
800 /*
801  * move to next cell in cells list
802  */
803 static void *afs_proc_cell_servers_next(struct seq_file *p, void *v,
804                                         loff_t *_pos)
805 {
806         struct list_head *_p;
807         struct afs_cell *cell = p->private;
808
809         _enter("cell=%p pos=%Ld", cell, *_pos);
810
811         (*_pos)++;
812
813         _p = v;
814         _p = v == (void *) 1 ? cell->sv_list.next : _p->next;
815
816         return _p != &cell->sv_list ? _p : NULL;
817 } /* end afs_proc_cell_servers_next() */
818
819 /*****************************************************************************/
820 /*
821  * clean up after reading from the cells list
822  */
823 static void afs_proc_cell_servers_stop(struct seq_file *p, void *v)
824 {
825         struct afs_cell *cell = p->private;
826
827         read_unlock(&cell->sv_lock);
828
829 } /* end afs_proc_cell_servers_stop() */
830
831 /*****************************************************************************/
832 /*
833  * display a header line followed by a load of volume lines
834  */
835 static int afs_proc_cell_servers_show(struct seq_file *m, void *v)
836 {
837         struct afs_server *server = list_entry(v, struct afs_server, link);
838         char ipaddr[20];
839
840         /* display header on line 1 */
841         if (v == (void *) 1) {
842                 seq_puts(m, "USE ADDR            STATE\n");
843                 return 0;
844         }
845
846         /* display one cell per line on subsequent lines */
847         sprintf(ipaddr, "%u.%u.%u.%u", NIPQUAD(server->addr));
848         seq_printf(m, "%3d %-15.15s %5d\n",
849                    atomic_read(&server->usage),
850                    ipaddr,
851                    server->fs_state
852                    );
853
854         return 0;
855 } /* end afs_proc_cell_servers_show() */