Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec
[linux-2.6-block.git] / fs / afs / proc.c
CommitLineData
ec26815a 1/* /proc interface for AFS
1da177e4
LT
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
1da177e4
LT
12#include <linux/slab.h>
13#include <linux/module.h>
14#include <linux/proc_fs.h>
15#include <linux/seq_file.h>
e8edc6e0 16#include <linux/sched.h>
7c0f6ba6 17#include <linux/uaccess.h>
1da177e4
LT
18#include "internal.h"
19
0a5143f2
DH
20struct afs_vl_seq_net_private {
21 struct seq_net_private seq; /* Must be first */
22 struct afs_vlserver_list *vllist;
23};
24
5b86d4ff 25static inline struct afs_net *afs_seq2net(struct seq_file *m)
f044c884 26{
5b86d4ff 27 return afs_net(seq_file_net(m));
f044c884 28}
1da177e4 29
5b86d4ff 30static inline struct afs_net *afs_seq2net_single(struct seq_file *m)
f044c884 31{
5b86d4ff 32 return afs_net(seq_file_single_net(m));
f044c884 33}
1da177e4 34
f0691689 35/*
5d9de25d 36 * Display the list of cells known to the namespace.
f0691689
DH
37 */
38static int afs_proc_cells_show(struct seq_file *m, void *v)
39{
ded2f4c5
DH
40 struct afs_vlserver_list *vllist;
41 struct afs_cell *cell;
f0691689 42
6b3944e4 43 if (v == SEQ_START_TOKEN) {
f0691689 44 /* display header on line 1 */
ded2f4c5 45 seq_puts(m, "USE TTL SV NAME\n");
f0691689
DH
46 return 0;
47 }
48
ded2f4c5
DH
49 cell = list_entry(v, struct afs_cell, proc_link);
50 vllist = rcu_dereference(cell->vl_servers);
51
f0691689 52 /* display one cell per line on subsequent lines */
ded2f4c5
DH
53 seq_printf(m, "%3u %6lld %2u %s\n",
54 atomic_read(&cell->usage),
55 cell->dns_expiry - ktime_get_real_seconds(),
56 vllist ? vllist->nr_servers : 0,
57 cell->name);
f0691689
DH
58 return 0;
59}
60
1da177e4 61static void *afs_proc_cells_start(struct seq_file *m, loff_t *_pos)
fe342cf7 62 __acquires(rcu)
1da177e4 63{
989782dc 64 rcu_read_lock();
6b3944e4 65 return seq_hlist_start_head_rcu(&afs_seq2net(m)->proc_cells, *_pos);
ec26815a 66}
1da177e4 67
f044c884 68static void *afs_proc_cells_next(struct seq_file *m, void *v, loff_t *pos)
1da177e4 69{
6b3944e4 70 return seq_hlist_next_rcu(v, &afs_seq2net(m)->proc_cells, pos);
ec26815a 71}
1da177e4 72
f044c884 73static void afs_proc_cells_stop(struct seq_file *m, void *v)
fe342cf7 74 __releases(rcu)
1da177e4 75{
989782dc 76 rcu_read_unlock();
ec26815a 77}
1da177e4 78
5d9de25d
DH
79static const struct seq_operations afs_proc_cells_ops = {
80 .start = afs_proc_cells_start,
81 .next = afs_proc_cells_next,
82 .stop = afs_proc_cells_stop,
83 .show = afs_proc_cells_show,
84};
85
1da177e4
LT
86/*
87 * handle writes to /proc/fs/afs/cells
88 * - to add cells: echo "add <cellname> <IP>[:<IP>][:<IP>]"
89 */
5b86d4ff 90static int afs_proc_cells_write(struct file *file, char *buf, size_t size)
1da177e4 91{
5b86d4ff
DH
92 struct seq_file *m = file->private_data;
93 struct afs_net *net = afs_seq2net(m);
94 char *name, *args;
1da177e4
LT
95 int ret;
96
1da177e4 97 /* trim to first NL */
5b86d4ff 98 name = memchr(buf, '\n', size);
1da177e4
LT
99 if (name)
100 *name = 0;
101
102 /* split into command, name and argslist */
5b86d4ff 103 name = strchr(buf, ' ');
1da177e4
LT
104 if (!name)
105 goto inval;
106 do {
107 *name++ = 0;
108 } while(*name == ' ');
109 if (!*name)
110 goto inval;
111
112 args = strchr(name, ' ');
ecfe951f
DH
113 if (args) {
114 do {
115 *args++ = 0;
116 } while(*args == ' ');
117 if (!*args)
118 goto inval;
119 }
1da177e4
LT
120
121 /* determine command to perform */
5b86d4ff 122 _debug("cmd=%s name=%s args=%s", buf, name, args);
1da177e4 123
5b86d4ff 124 if (strcmp(buf, "add") == 0) {
1da177e4 125 struct afs_cell *cell;
08e0e7c8 126
989782dc 127 cell = afs_lookup_cell(net, name, strlen(name), args, true);
08e0e7c8
DH
128 if (IS_ERR(cell)) {
129 ret = PTR_ERR(cell);
1da177e4 130 goto done;
08e0e7c8 131 }
1da177e4 132
17814aef
DH
133 if (test_and_set_bit(AFS_CELL_FL_NO_GC, &cell->flags))
134 afs_put_cell(net, cell);
ec26815a 135 } else {
1da177e4
LT
136 goto inval;
137 }
138
5b86d4ff 139 ret = 0;
1da177e4 140
ec26815a 141done:
1da177e4
LT
142 _leave(" = %d", ret);
143 return ret;
144
ec26815a 145inval:
1da177e4
LT
146 ret = -EINVAL;
147 printk("kAFS: Invalid Command on /proc/fs/afs/cells file\n");
148 goto done;
ec26815a 149}
1da177e4 150
5d9de25d 151/*
5b86d4ff 152 * Display the name of the current workstation cell.
5d9de25d 153 */
5b86d4ff 154static int afs_proc_rootcell_show(struct seq_file *m, void *v)
1da177e4 155{
37ab6368 156 struct afs_cell *cell;
5b86d4ff
DH
157 struct afs_net *net;
158
159 net = afs_seq2net_single(m);
160 if (rcu_access_pointer(net->ws_cell)) {
161 rcu_read_lock();
162 cell = rcu_dereference(net->ws_cell);
163 if (cell)
164 seq_printf(m, "%s\n", cell->name);
165 rcu_read_unlock();
166 }
167 return 0;
1da177e4
LT
168}
169
1da177e4 170/*
5d9de25d
DH
171 * Set the current workstation cell and optionally supply its list of volume
172 * location servers.
173 *
174 * echo "cell.name:192.168.231.14" >/proc/fs/afs/rootcell
1da177e4 175 */
5b86d4ff 176static int afs_proc_rootcell_write(struct file *file, char *buf, size_t size)
1da177e4 177{
5b86d4ff
DH
178 struct seq_file *m = file->private_data;
179 struct afs_net *net = afs_seq2net_single(m);
180 char *s;
1da177e4
LT
181 int ret;
182
6f8880d8 183 ret = -EINVAL;
5b86d4ff 184 if (buf[0] == '.')
6f8880d8 185 goto out;
5b86d4ff 186 if (memchr(buf, '/', size))
6f8880d8
DH
187 goto out;
188
1da177e4 189 /* trim to first NL */
5b86d4ff 190 s = memchr(buf, '\n', size);
1da177e4
LT
191 if (s)
192 *s = 0;
193
194 /* determine command to perform */
5b86d4ff 195 _debug("rootcell=%s", buf);
1da177e4 196
5b86d4ff 197 ret = afs_cell_init(net, buf);
1da177e4 198
6f8880d8 199out:
1da177e4
LT
200 _leave(" = %d", ret);
201 return ret;
ec26815a 202}
1da177e4 203
f0691689
DH
204static const char afs_vol_types[3][3] = {
205 [AFSVL_RWVOL] = "RW",
206 [AFSVL_ROVOL] = "RO",
207 [AFSVL_BACKVOL] = "BK",
208};
209
210/*
5d9de25d 211 * Display the list of volumes known to a cell.
f0691689
DH
212 */
213static int afs_proc_cell_volumes_show(struct seq_file *m, void *v)
214{
215 struct afs_cell *cell = PDE_DATA(file_inode(m->file));
216 struct afs_volume *vol = list_entry(v, struct afs_volume, proc_link);
217
218 /* Display header on line 1 */
219 if (v == &cell->proc_volumes) {
220 seq_puts(m, "USE VID TY\n");
221 return 0;
222 }
223
3b6492df 224 seq_printf(m, "%3d %08llx %s\n",
f0691689
DH
225 atomic_read(&vol->usage), vol->vid,
226 afs_vol_types[vol->type]);
227
228 return 0;
229}
230
1da177e4 231static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos)
fe342cf7 232 __acquires(cell->proc_lock)
1da177e4 233{
353861cf 234 struct afs_cell *cell = PDE_DATA(file_inode(m->file));
1da177e4 235
d2ddc776
DH
236 read_lock(&cell->proc_lock);
237 return seq_list_start_head(&cell->proc_volumes, *_pos);
ec26815a 238}
1da177e4 239
5b86d4ff 240static void *afs_proc_cell_volumes_next(struct seq_file *m, void *v,
1da177e4
LT
241 loff_t *_pos)
242{
5b86d4ff 243 struct afs_cell *cell = PDE_DATA(file_inode(m->file));
1da177e4 244
d2ddc776 245 return seq_list_next(v, &cell->proc_volumes, _pos);
ec26815a 246}
1da177e4 247
5b86d4ff 248static void afs_proc_cell_volumes_stop(struct seq_file *m, void *v)
fe342cf7 249 __releases(cell->proc_lock)
1da177e4 250{
5b86d4ff 251 struct afs_cell *cell = PDE_DATA(file_inode(m->file));
1da177e4 252
d2ddc776 253 read_unlock(&cell->proc_lock);
ec26815a 254}
1da177e4 255
5d9de25d
DH
256static const struct seq_operations afs_proc_cell_volumes_ops = {
257 .start = afs_proc_cell_volumes_start,
258 .next = afs_proc_cell_volumes_next,
259 .stop = afs_proc_cell_volumes_stop,
260 .show = afs_proc_cell_volumes_show,
261};
262
0a5143f2
DH
263static const char *const dns_record_sources[NR__dns_record_source + 1] = {
264 [DNS_RECORD_UNAVAILABLE] = "unav",
265 [DNS_RECORD_FROM_CONFIG] = "cfg",
266 [DNS_RECORD_FROM_DNS_A] = "A",
267 [DNS_RECORD_FROM_DNS_AFSDB] = "AFSDB",
268 [DNS_RECORD_FROM_DNS_SRV] = "SRV",
269 [DNS_RECORD_FROM_NSS] = "nss",
270 [NR__dns_record_source] = "[weird]"
271};
272
273static const char *const dns_lookup_statuses[NR__dns_lookup_status + 1] = {
274 [DNS_LOOKUP_NOT_DONE] = "no-lookup",
275 [DNS_LOOKUP_GOOD] = "good",
276 [DNS_LOOKUP_GOOD_WITH_BAD] = "good/bad",
277 [DNS_LOOKUP_BAD] = "bad",
278 [DNS_LOOKUP_GOT_NOT_FOUND] = "not-found",
279 [DNS_LOOKUP_GOT_LOCAL_FAILURE] = "local-failure",
280 [DNS_LOOKUP_GOT_TEMP_FAILURE] = "temp-failure",
281 [DNS_LOOKUP_GOT_NS_FAILURE] = "ns-failure",
282 [NR__dns_lookup_status] = "[weird]"
283};
284
1da177e4 285/*
5d9de25d 286 * Display the list of Volume Location servers we're using for a cell.
1da177e4 287 */
f0691689 288static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v)
1da177e4 289{
0a5143f2
DH
290 const struct afs_vl_seq_net_private *priv = m->private;
291 const struct afs_vlserver_list *vllist = priv->vllist;
292 const struct afs_vlserver_entry *entry;
293 const struct afs_vlserver *vlserver;
294 const struct afs_addr_list *alist;
295 int i;
1da177e4 296
0a5143f2
DH
297 if (v == SEQ_START_TOKEN) {
298 seq_printf(m, "# source %s, status %s\n",
299 dns_record_sources[vllist->source],
300 dns_lookup_statuses[vllist->status]);
1da177e4
LT
301 return 0;
302 }
303
0a5143f2
DH
304 entry = v;
305 vlserver = entry->server;
306 alist = rcu_dereference(vlserver->addresses);
307
308 seq_printf(m, "%s [p=%hu w=%hu s=%s,%s]:\n",
309 vlserver->name, entry->priority, entry->weight,
310 dns_record_sources[alist ? alist->source : entry->source],
311 dns_lookup_statuses[alist ? alist->status : entry->status]);
312 if (alist) {
313 for (i = 0; i < alist->nr_addrs; i++)
314 seq_printf(m, " %c %pISpc\n",
3bf0fb6f 315 alist->preferred == i ? '>' : '-',
0a5143f2
DH
316 &alist->addrs[i].transport);
317 }
1da177e4 318 return 0;
ec26815a 319}
1da177e4 320
1da177e4 321static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos)
fe342cf7 322 __acquires(rcu)
1da177e4 323{
0a5143f2
DH
324 struct afs_vl_seq_net_private *priv = m->private;
325 struct afs_vlserver_list *vllist;
353861cf 326 struct afs_cell *cell = PDE_DATA(file_inode(m->file));
1da177e4
LT
327 loff_t pos = *_pos;
328
8b2a464c 329 rcu_read_lock();
1da177e4 330
0a5143f2
DH
331 vllist = rcu_dereference(cell->vl_servers);
332 priv->vllist = vllist;
1da177e4 333
0a5143f2
DH
334 if (pos < 0)
335 *_pos = pos = 0;
336 if (pos == 0)
337 return SEQ_START_TOKEN;
1da177e4 338
0a5143f2 339 if (!vllist || pos - 1 >= vllist->nr_servers)
1da177e4
LT
340 return NULL;
341
0a5143f2 342 return &vllist->servers[pos - 1];
ec26815a 343}
1da177e4 344
5b86d4ff 345static void *afs_proc_cell_vlservers_next(struct seq_file *m, void *v,
1da177e4
LT
346 loff_t *_pos)
347{
0a5143f2
DH
348 struct afs_vl_seq_net_private *priv = m->private;
349 struct afs_vlserver_list *vllist = priv->vllist;
1da177e4
LT
350 loff_t pos;
351
1da177e4 352 pos = *_pos;
0a5143f2
DH
353 pos++;
354 *_pos = pos;
355 if (!vllist || pos - 1 >= vllist->nr_servers)
1da177e4
LT
356 return NULL;
357
0a5143f2 358 return &vllist->servers[pos - 1];
ec26815a 359}
1da177e4 360
5b86d4ff 361static void afs_proc_cell_vlservers_stop(struct seq_file *m, void *v)
fe342cf7 362 __releases(rcu)
1da177e4 363{
8b2a464c 364 rcu_read_unlock();
ec26815a 365}
1da177e4 366
5d9de25d
DH
367static const struct seq_operations afs_proc_cell_vlservers_ops = {
368 .start = afs_proc_cell_vlservers_start,
369 .next = afs_proc_cell_vlservers_next,
370 .stop = afs_proc_cell_vlservers_stop,
371 .show = afs_proc_cell_vlservers_show,
372};
373
1da177e4 374/*
5d9de25d 375 * Display the list of fileservers we're using within a namespace.
1da177e4 376 */
f0691689 377static int afs_proc_servers_show(struct seq_file *m, void *v)
1da177e4 378{
f0691689
DH
379 struct afs_server *server;
380 struct afs_addr_list *alist;
0aac4bce 381 int i;
1da177e4 382
f0691689
DH
383 if (v == SEQ_START_TOKEN) {
384 seq_puts(m, "UUID USE ADDR\n");
1da177e4
LT
385 return 0;
386 }
387
f0691689
DH
388 server = list_entry(v, struct afs_server, proc_link);
389 alist = rcu_dereference(server->addresses);
0aac4bce 390 seq_printf(m, "%pU %3d %pISpc%s\n",
f0691689
DH
391 &server->uuid,
392 atomic_read(&server->usage),
0aac4bce 393 &alist->addrs[0].transport,
3bf0fb6f 394 alist->preferred == 0 ? "*" : "");
0aac4bce
DH
395 for (i = 1; i < alist->nr_addrs; i++)
396 seq_printf(m, " %pISpc%s\n",
397 &alist->addrs[i].transport,
3bf0fb6f 398 alist->preferred == i ? "*" : "");
1da177e4 399 return 0;
ec26815a 400}
1da177e4 401
d2ddc776 402static void *afs_proc_servers_start(struct seq_file *m, loff_t *_pos)
fe342cf7 403 __acquires(rcu)
1da177e4 404{
d2ddc776 405 rcu_read_lock();
5d9de25d 406 return seq_hlist_start_head_rcu(&afs_seq2net(m)->fs_proc, *_pos);
ec26815a 407}
1da177e4 408
d2ddc776 409static void *afs_proc_servers_next(struct seq_file *m, void *v, loff_t *_pos)
1da177e4 410{
5d9de25d 411 return seq_hlist_next_rcu(v, &afs_seq2net(m)->fs_proc, _pos);
ec26815a 412}
1da177e4 413
5b86d4ff 414static void afs_proc_servers_stop(struct seq_file *m, void *v)
fe342cf7 415 __releases(rcu)
1da177e4 416{
d2ddc776 417 rcu_read_unlock();
ec26815a 418}
1da177e4 419
5d9de25d
DH
420static const struct seq_operations afs_proc_servers_ops = {
421 .start = afs_proc_servers_start,
422 .next = afs_proc_servers_next,
423 .stop = afs_proc_servers_stop,
424 .show = afs_proc_servers_show,
425};
6f8880d8 426
6f8880d8 427/*
5d9de25d
DH
428 * Display the list of strings that may be substituted for the @sys pathname
429 * macro.
6f8880d8 430 */
5d9de25d 431static int afs_proc_sysname_show(struct seq_file *m, void *v)
6f8880d8 432{
5d9de25d
DH
433 struct afs_net *net = afs_seq2net(m);
434 struct afs_sysnames *sysnames = net->sysnames;
435 unsigned int i = (unsigned long)v - 1;
6f8880d8 436
5d9de25d
DH
437 if (i < sysnames->nr)
438 seq_printf(m, "%s\n", sysnames->subs[i]);
439 return 0;
440}
6f8880d8 441
5d9de25d
DH
442static void *afs_proc_sysname_start(struct seq_file *m, loff_t *pos)
443 __acquires(&net->sysnames_lock)
444{
445 struct afs_net *net = afs_seq2net(m);
5b86d4ff 446 struct afs_sysnames *names;
6f8880d8 447
5d9de25d 448 read_lock(&net->sysnames_lock);
6f8880d8 449
5b86d4ff 450 names = net->sysnames;
5d9de25d
DH
451 if (*pos >= names->nr)
452 return NULL;
453 return (void *)(unsigned long)(*pos + 1);
454}
455
456static void *afs_proc_sysname_next(struct seq_file *m, void *v, loff_t *pos)
457{
458 struct afs_net *net = afs_seq2net(m);
459 struct afs_sysnames *names = net->sysnames;
460
461 *pos += 1;
462 if (*pos >= names->nr)
463 return NULL;
464 return (void *)(unsigned long)(*pos + 1);
465}
466
467static void afs_proc_sysname_stop(struct seq_file *m, void *v)
468 __releases(&net->sysnames_lock)
469{
470 struct afs_net *net = afs_seq2net(m);
471
472 read_unlock(&net->sysnames_lock);
6f8880d8
DH
473}
474
5d9de25d
DH
475static const struct seq_operations afs_proc_sysname_ops = {
476 .start = afs_proc_sysname_start,
477 .next = afs_proc_sysname_next,
478 .stop = afs_proc_sysname_stop,
479 .show = afs_proc_sysname_show,
480};
481
6f8880d8 482/*
5d9de25d 483 * Allow the @sys substitution to be configured.
6f8880d8 484 */
5b86d4ff 485static int afs_proc_sysname_write(struct file *file, char *buf, size_t size)
6f8880d8 486{
5b86d4ff 487 struct afs_sysnames *sysnames, *kill;
6f8880d8 488 struct seq_file *m = file->private_data;
5b86d4ff
DH
489 struct afs_net *net = afs_seq2net(m);
490 char *s, *p, *sub;
6f8880d8
DH
491 int ret, len;
492
5b86d4ff 493 sysnames = kzalloc(sizeof(*sysnames), GFP_KERNEL);
6f8880d8 494 if (!sysnames)
5b86d4ff
DH
495 return -ENOMEM;
496 refcount_set(&sysnames->usage, 1);
497 kill = sysnames;
6f8880d8 498
5b86d4ff 499 p = buf;
6f8880d8
DH
500 while ((s = strsep(&p, " \t\n"))) {
501 len = strlen(s);
502 if (len == 0)
503 continue;
504 ret = -ENAMETOOLONG;
505 if (len >= AFSNAMEMAX)
506 goto error;
507
508 if (len >= 4 &&
509 s[len - 4] == '@' &&
510 s[len - 3] == 's' &&
511 s[len - 2] == 'y' &&
512 s[len - 1] == 's')
513 /* Protect against recursion */
514 goto invalid;
515
516 if (s[0] == '.' &&
517 (len < 2 || (len == 2 && s[1] == '.')))
518 goto invalid;
519
520 if (memchr(s, '/', len))
521 goto invalid;
522
523 ret = -EFBIG;
524 if (sysnames->nr >= AFS_NR_SYSNAME)
525 goto out;
526
527 if (strcmp(s, afs_init_sysname) == 0) {
528 sub = (char *)afs_init_sysname;
529 } else {
530 ret = -ENOMEM;
531 sub = kmemdup(s, len + 1, GFP_KERNEL);
532 if (!sub)
533 goto out;
534 }
535
536 sysnames->subs[sysnames->nr] = sub;
537 sysnames->nr++;
538 }
539
5b86d4ff
DH
540 if (sysnames->nr == 0) {
541 sysnames->subs[0] = sysnames->blank;
542 sysnames->nr++;
543 }
544
545 write_lock(&net->sysnames_lock);
546 kill = net->sysnames;
547 net->sysnames = sysnames;
548 write_unlock(&net->sysnames_lock);
549 ret = 0;
6f8880d8 550out:
5b86d4ff 551 afs_put_sysnames(kill);
6f8880d8
DH
552 return ret;
553
554invalid:
555 ret = -EINVAL;
556error:
6f8880d8
DH
557 goto out;
558}
559
5d9de25d
DH
560void afs_put_sysnames(struct afs_sysnames *sysnames)
561{
562 int i;
563
564 if (sysnames && refcount_dec_and_test(&sysnames->usage)) {
565 for (i = 0; i < sysnames->nr; i++)
566 if (sysnames->subs[i] != afs_init_sysname &&
567 sysnames->subs[i] != sysnames->blank)
568 kfree(sysnames->subs[i]);
569 }
570}
571
d55b4da4
DH
572/*
573 * Display general per-net namespace statistics
574 */
575static int afs_proc_stats_show(struct seq_file *m, void *v)
576{
5b86d4ff 577 struct afs_net *net = afs_seq2net_single(m);
d55b4da4
DH
578
579 seq_puts(m, "kAFS statistics\n");
580
f3ddee8d 581 seq_printf(m, "dir-mgmt: look=%u reval=%u inval=%u relpg=%u\n",
d55b4da4
DH
582 atomic_read(&net->n_lookup),
583 atomic_read(&net->n_reval),
f3ddee8d
DH
584 atomic_read(&net->n_inval),
585 atomic_read(&net->n_relpg));
d55b4da4
DH
586
587 seq_printf(m, "dir-data: rdpg=%u\n",
588 atomic_read(&net->n_read_dir));
63a4681f
DH
589
590 seq_printf(m, "dir-edit: cr=%u rm=%u\n",
591 atomic_read(&net->n_dir_cr),
592 atomic_read(&net->n_dir_rm));
76a5cb6f
DH
593
594 seq_printf(m, "file-rd : n=%u nb=%lu\n",
595 atomic_read(&net->n_fetches),
596 atomic_long_read(&net->n_fetch_bytes));
597 seq_printf(m, "file-wr : n=%u nb=%lu\n",
598 atomic_read(&net->n_stores),
599 atomic_long_read(&net->n_store_bytes));
d55b4da4
DH
600 return 0;
601}
10495a00
DH
602
603/*
604 * initialise /proc/fs/afs/<cell>/
605 */
5b86d4ff 606int afs_proc_cell_setup(struct afs_cell *cell)
10495a00
DH
607{
608 struct proc_dir_entry *dir;
5b86d4ff 609 struct afs_net *net = cell->net;
10495a00
DH
610
611 _enter("%p{%s},%p", cell, cell->name, net->proc_afs);
612
5b86d4ff 613 dir = proc_net_mkdir(net->net, cell->name, net->proc_afs);
10495a00
DH
614 if (!dir)
615 goto error_dir;
616
5b86d4ff
DH
617 if (!proc_create_net_data("vlservers", 0444, dir,
618 &afs_proc_cell_vlservers_ops,
0a5143f2 619 sizeof(struct afs_vl_seq_net_private),
5b86d4ff
DH
620 cell) ||
621 !proc_create_net_data("volumes", 0444, dir,
622 &afs_proc_cell_volumes_ops,
623 sizeof(struct seq_net_private),
624 cell))
10495a00
DH
625 goto error_tree;
626
627 _leave(" = 0");
628 return 0;
629
630error_tree:
631 remove_proc_subtree(cell->name, net->proc_afs);
632error_dir:
633 _leave(" = -ENOMEM");
634 return -ENOMEM;
635}
636
637/*
638 * remove /proc/fs/afs/<cell>/
639 */
5b86d4ff 640void afs_proc_cell_remove(struct afs_cell *cell)
10495a00 641{
5b86d4ff 642 struct afs_net *net = cell->net;
10495a00 643
5b86d4ff 644 _enter("");
10495a00 645 remove_proc_subtree(cell->name, net->proc_afs);
10495a00
DH
646 _leave("");
647}
648
649/*
650 * initialise the /proc/fs/afs/ directory
651 */
652int afs_proc_init(struct afs_net *net)
653{
5b86d4ff
DH
654 struct proc_dir_entry *p;
655
10495a00
DH
656 _enter("");
657
5b86d4ff
DH
658 p = proc_net_mkdir(net->net, "afs", net->net->proc_net);
659 if (!p)
10495a00
DH
660 goto error_dir;
661
5b86d4ff
DH
662 if (!proc_create_net_data_write("cells", 0644, p,
663 &afs_proc_cells_ops,
664 afs_proc_cells_write,
665 sizeof(struct seq_net_private),
666 NULL) ||
667 !proc_create_net_single_write("rootcell", 0644, p,
668 afs_proc_rootcell_show,
669 afs_proc_rootcell_write,
670 NULL) ||
671 !proc_create_net("servers", 0444, p, &afs_proc_servers_ops,
672 sizeof(struct seq_net_private)) ||
673 !proc_create_net_single("stats", 0444, p, afs_proc_stats_show, NULL) ||
674 !proc_create_net_data_write("sysname", 0644, p,
675 &afs_proc_sysname_ops,
676 afs_proc_sysname_write,
677 sizeof(struct seq_net_private),
678 NULL))
10495a00
DH
679 goto error_tree;
680
5b86d4ff 681 net->proc_afs = p;
10495a00
DH
682 _leave(" = 0");
683 return 0;
684
685error_tree:
5b86d4ff 686 proc_remove(p);
10495a00
DH
687error_dir:
688 _leave(" = -ENOMEM");
689 return -ENOMEM;
690}
691
692/*
693 * clean up the /proc/fs/afs/ directory
694 */
695void afs_proc_cleanup(struct afs_net *net)
696{
697 proc_remove(net->proc_afs);
698 net->proc_afs = NULL;
699}