blob: 4508dd54f78968dab3d9e85cc0a7deb6a1b31a7d [file] [log] [blame]
David Howellsec268152007-04-26 15:49:28 -07001/* /proc interface for AFS
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/slab.h>
13#include <linux/module.h>
14#include <linux/proc_fs.h>
15#include <linux/seq_file.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040016#include <linux/sched.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080017#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "internal.h"
19
David Howellsf044c882017-11-02 15:27:45 +000020static inline struct afs_net *afs_proc2net(struct file *f)
21{
22 return &__afs_net;
23}
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
David Howellsf044c882017-11-02 15:27:45 +000025static inline struct afs_net *afs_seq2net(struct seq_file *m)
26{
27 return &__afs_net; // TODO: use seq_file_net(m)
28}
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30static int afs_proc_cells_open(struct inode *inode, struct file *file);
31static void *afs_proc_cells_start(struct seq_file *p, loff_t *pos);
32static void *afs_proc_cells_next(struct seq_file *p, void *v, loff_t *pos);
33static void afs_proc_cells_stop(struct seq_file *p, void *v);
34static int afs_proc_cells_show(struct seq_file *m, void *v);
35static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf,
36 size_t size, loff_t *_pos);
37
James Morris88e9d342009-09-22 16:43:43 -070038static const struct seq_operations afs_proc_cells_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 .start = afs_proc_cells_start,
40 .next = afs_proc_cells_next,
41 .stop = afs_proc_cells_stop,
42 .show = afs_proc_cells_show,
43};
44
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080045static const struct file_operations afs_proc_cells_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 .open = afs_proc_cells_open,
47 .read = seq_read,
48 .write = afs_proc_cells_write,
49 .llseek = seq_lseek,
50 .release = seq_release,
51};
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf,
54 size_t size, loff_t *_pos);
55static ssize_t afs_proc_rootcell_write(struct file *file,
56 const char __user *buf,
57 size_t size, loff_t *_pos);
58
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080059static const struct file_operations afs_proc_rootcell_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 .read = afs_proc_rootcell_read,
61 .write = afs_proc_rootcell_write,
62 .llseek = no_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -070063};
64
65static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static 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,
68 loff_t *pos);
69static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v);
70static int afs_proc_cell_volumes_show(struct seq_file *m, void *v);
71
James Morris88e9d342009-09-22 16:43:43 -070072static const struct seq_operations afs_proc_cell_volumes_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 .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
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080079static const struct file_operations afs_proc_cell_volumes_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 .open = afs_proc_cell_volumes_open,
81 .read = seq_read,
82 .llseek = seq_lseek,
Al Virob42d5702013-11-22 01:53:47 -050083 .release = seq_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -070084};
85
86static int afs_proc_cell_vlservers_open(struct inode *inode,
87 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static 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,
90 loff_t *pos);
91static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v);
92static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v);
93
James Morris88e9d342009-09-22 16:43:43 -070094static const struct seq_operations afs_proc_cell_vlservers_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 .start = afs_proc_cell_vlservers_start,
96 .next = afs_proc_cell_vlservers_next,
97 .stop = afs_proc_cell_vlservers_stop,
98 .show = afs_proc_cell_vlservers_show,
99};
100
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800101static const struct file_operations afs_proc_cell_vlservers_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 .open = afs_proc_cell_vlservers_open,
103 .read = seq_read,
104 .llseek = seq_lseek,
Al Virob42d5702013-11-22 01:53:47 -0500105 .release = seq_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106};
107
David Howellsd2ddc772017-11-02 15:27:50 +0000108static int afs_proc_servers_open(struct inode *inode, struct file *file);
109static void *afs_proc_servers_start(struct seq_file *p, loff_t *pos);
110static void *afs_proc_servers_next(struct seq_file *p, void *v,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 loff_t *pos);
David Howellsd2ddc772017-11-02 15:27:50 +0000112static void afs_proc_servers_stop(struct seq_file *p, void *v);
113static int afs_proc_servers_show(struct seq_file *m, void *v);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
David Howellsd2ddc772017-11-02 15:27:50 +0000115static const struct seq_operations afs_proc_servers_ops = {
116 .start = afs_proc_servers_start,
117 .next = afs_proc_servers_next,
118 .stop = afs_proc_servers_stop,
119 .show = afs_proc_servers_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120};
121
David Howellsd2ddc772017-11-02 15:27:50 +0000122static const struct file_operations afs_proc_servers_fops = {
123 .open = afs_proc_servers_open,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 .read = seq_read,
125 .llseek = seq_lseek,
Al Virob42d5702013-11-22 01:53:47 -0500126 .release = seq_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127};
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129/*
130 * initialise the /proc/fs/afs/ directory
131 */
David Howellsf044c882017-11-02 15:27:45 +0000132int afs_proc_init(struct afs_net *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 _enter("");
135
David Howellsf044c882017-11-02 15:27:45 +0000136 net->proc_afs = proc_mkdir("fs/afs", NULL);
137 if (!net->proc_afs)
David Howellsec268152007-04-26 15:49:28 -0700138 goto error_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
David Howellsf044c882017-11-02 15:27:45 +0000140 if (!proc_create("cells", 0644, net->proc_afs, &afs_proc_cells_fops) ||
David Howellsd2ddc772017-11-02 15:27:50 +0000141 !proc_create("rootcell", 0644, net->proc_afs, &afs_proc_rootcell_fops) ||
142 !proc_create("servers", 0644, net->proc_afs, &afs_proc_servers_fops))
Al Virob42d5702013-11-22 01:53:47 -0500143 goto error_tree;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 _leave(" = 0");
146 return 0;
147
Al Virob42d5702013-11-22 01:53:47 -0500148error_tree:
David Howellsf044c882017-11-02 15:27:45 +0000149 proc_remove(net->proc_afs);
David Howellsec268152007-04-26 15:49:28 -0700150error_dir:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 _leave(" = -ENOMEM");
152 return -ENOMEM;
David Howellsec268152007-04-26 15:49:28 -0700153}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155/*
156 * clean up the /proc/fs/afs/ directory
157 */
David Howellsf044c882017-11-02 15:27:45 +0000158void afs_proc_cleanup(struct afs_net *net)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
David Howellsf044c882017-11-02 15:27:45 +0000160 proc_remove(net->proc_afs);
161 net->proc_afs = NULL;
David Howellsec268152007-04-26 15:49:28 -0700162}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164/*
165 * open "/proc/fs/afs/cells" which provides a summary of extant cells
166 */
167static int afs_proc_cells_open(struct inode *inode, struct file *file)
168{
169 struct seq_file *m;
170 int ret;
171
172 ret = seq_open(file, &afs_proc_cells_ops);
173 if (ret < 0)
174 return ret;
175
176 m = file->private_data;
Al Virod9dda782013-03-31 18:16:14 -0400177 m->private = PDE_DATA(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return 0;
David Howellsec268152007-04-26 15:49:28 -0700179}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181/*
182 * set up the iterator to start reading from the cells list and return the
183 * first item
184 */
185static void *afs_proc_cells_start(struct seq_file *m, loff_t *_pos)
186{
David Howellsf044c882017-11-02 15:27:45 +0000187 struct afs_net *net = afs_seq2net(m);
188
David Howells989782d2017-11-02 15:27:50 +0000189 rcu_read_lock();
David Howellsf044c882017-11-02 15:27:45 +0000190 return seq_list_start_head(&net->proc_cells, *_pos);
David Howellsec268152007-04-26 15:49:28 -0700191}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193/*
194 * move to next cell in cells list
195 */
David Howellsf044c882017-11-02 15:27:45 +0000196static void *afs_proc_cells_next(struct seq_file *m, void *v, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
David Howellsf044c882017-11-02 15:27:45 +0000198 struct afs_net *net = afs_seq2net(m);
199
200 return seq_list_next(v, &net->proc_cells, pos);
David Howellsec268152007-04-26 15:49:28 -0700201}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203/*
204 * clean up after reading from the cells list
205 */
David Howellsf044c882017-11-02 15:27:45 +0000206static void afs_proc_cells_stop(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
David Howells989782d2017-11-02 15:27:50 +0000208 rcu_read_unlock();
David Howellsec268152007-04-26 15:49:28 -0700209}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211/*
212 * display a header line followed by a load of cell lines
213 */
214static int afs_proc_cells_show(struct seq_file *m, void *v)
215{
216 struct afs_cell *cell = list_entry(v, struct afs_cell, proc_link);
David Howellsf044c882017-11-02 15:27:45 +0000217 struct afs_net *net = afs_seq2net(m);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
David Howellsf044c882017-11-02 15:27:45 +0000219 if (v == &net->proc_cells) {
David Howellsec268152007-04-26 15:49:28 -0700220 /* display header on line 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 seq_puts(m, "USE NAME\n");
222 return 0;
223 }
224
225 /* display one cell per line on subsequent lines */
David Howells989782d2017-11-02 15:27:50 +0000226 seq_printf(m, "%3u %s\n", atomic_read(&cell->usage), cell->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 return 0;
David Howellsec268152007-04-26 15:49:28 -0700228}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230/*
231 * handle writes to /proc/fs/afs/cells
232 * - to add cells: echo "add <cellname> <IP>[:<IP>][:<IP>]"
233 */
234static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf,
235 size_t size, loff_t *_pos)
236{
David Howellsf044c882017-11-02 15:27:45 +0000237 struct afs_net *net = afs_proc2net(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 char *kbuf, *name, *args;
239 int ret;
240
241 /* start by dragging the command into memory */
242 if (size <= 1 || size >= PAGE_SIZE)
243 return -EINVAL;
244
Al Viro16e5c1f2015-12-24 00:06:05 -0500245 kbuf = memdup_user_nul(buf, size);
246 if (IS_ERR(kbuf))
247 return PTR_ERR(kbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 /* trim to first NL */
250 name = memchr(kbuf, '\n', size);
251 if (name)
252 *name = 0;
253
254 /* split into command, name and argslist */
255 name = strchr(kbuf, ' ');
256 if (!name)
257 goto inval;
258 do {
259 *name++ = 0;
260 } while(*name == ' ');
261 if (!*name)
262 goto inval;
263
264 args = strchr(name, ' ');
265 if (!args)
266 goto inval;
267 do {
268 *args++ = 0;
269 } while(*args == ' ');
270 if (!*args)
271 goto inval;
272
273 /* determine command to perform */
274 _debug("cmd=%s name=%s args=%s", kbuf, name, args);
275
276 if (strcmp(kbuf, "add") == 0) {
277 struct afs_cell *cell;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
David Howells989782d2017-11-02 15:27:50 +0000279 cell = afs_lookup_cell(net, name, strlen(name), args, true);
David Howells08e0e7c2007-04-26 15:55:03 -0700280 if (IS_ERR(cell)) {
281 ret = PTR_ERR(cell);
282 goto done;
283 }
284
David Howells989782d2017-11-02 15:27:50 +0000285 set_bit(AFS_CELL_FL_NO_GC, &cell->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 printk("kAFS: Added new cell '%s'\n", name);
David Howellsec268152007-04-26 15:49:28 -0700287 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 goto inval;
289 }
290
291 ret = size;
292
David Howellsec268152007-04-26 15:49:28 -0700293done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 kfree(kbuf);
295 _leave(" = %d", ret);
296 return ret;
297
David Howellsec268152007-04-26 15:49:28 -0700298inval:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 ret = -EINVAL;
300 printk("kAFS: Invalid Command on /proc/fs/afs/cells file\n");
301 goto done;
David Howellsec268152007-04-26 15:49:28 -0700302}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf,
305 size_t size, loff_t *_pos)
306{
307 return 0;
308}
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310/*
311 * handle writes to /proc/fs/afs/rootcell
312 * - to initialize rootcell: echo "cell.name:192.168.231.14"
313 */
314static ssize_t afs_proc_rootcell_write(struct file *file,
315 const char __user *buf,
316 size_t size, loff_t *_pos)
317{
David Howellsf044c882017-11-02 15:27:45 +0000318 struct afs_net *net = afs_proc2net(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 char *kbuf, *s;
320 int ret;
321
322 /* start by dragging the command into memory */
323 if (size <= 1 || size >= PAGE_SIZE)
324 return -EINVAL;
325
Al Viro16e5c1f2015-12-24 00:06:05 -0500326 kbuf = memdup_user_nul(buf, size);
327 if (IS_ERR(kbuf))
328 return PTR_ERR(kbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 /* trim to first NL */
331 s = memchr(kbuf, '\n', size);
332 if (s)
333 *s = 0;
334
335 /* determine command to perform */
336 _debug("rootcell=%s", kbuf);
337
David Howellsf044c882017-11-02 15:27:45 +0000338 ret = afs_cell_init(net, kbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 if (ret >= 0)
340 ret = size; /* consume everything, always */
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 kfree(kbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 _leave(" = %d", ret);
344 return ret;
David Howellsec268152007-04-26 15:49:28 -0700345}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347/*
348 * initialise /proc/fs/afs/<cell>/
349 */
David Howellsf044c882017-11-02 15:27:45 +0000350int afs_proc_cell_setup(struct afs_net *net, struct afs_cell *cell)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Al Virob42d5702013-11-22 01:53:47 -0500352 struct proc_dir_entry *dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
David Howells989782d2017-11-02 15:27:50 +0000354 _enter("%p{%s},%p", cell, cell->name, net->proc_afs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
David Howellsf044c882017-11-02 15:27:45 +0000356 dir = proc_mkdir(cell->name, net->proc_afs);
Al Virob42d5702013-11-22 01:53:47 -0500357 if (!dir)
David Howellsec268152007-04-26 15:49:28 -0700358 goto error_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
David Howellsd2ddc772017-11-02 15:27:50 +0000360 if (!proc_create_data("vlservers", 0, dir,
361 &afs_proc_cell_vlservers_fops, cell) ||
Al Virob42d5702013-11-22 01:53:47 -0500362 !proc_create_data("volumes", 0, dir,
David Howellsd2ddc772017-11-02 15:27:50 +0000363 &afs_proc_cell_volumes_fops, cell))
Al Virob42d5702013-11-22 01:53:47 -0500364 goto error_tree;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 _leave(" = 0");
367 return 0;
368
Al Virob42d5702013-11-22 01:53:47 -0500369error_tree:
David Howellsf044c882017-11-02 15:27:45 +0000370 remove_proc_subtree(cell->name, net->proc_afs);
David Howellsec268152007-04-26 15:49:28 -0700371error_dir:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 _leave(" = -ENOMEM");
373 return -ENOMEM;
David Howellsec268152007-04-26 15:49:28 -0700374}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376/*
377 * remove /proc/fs/afs/<cell>/
378 */
David Howellsf044c882017-11-02 15:27:45 +0000379void afs_proc_cell_remove(struct afs_net *net, struct afs_cell *cell)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
381 _enter("");
382
David Howellsf044c882017-11-02 15:27:45 +0000383 remove_proc_subtree(cell->name, net->proc_afs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700386}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388/*
389 * open "/proc/fs/afs/<cell>/volumes" which provides a summary of extant cells
390 */
391static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file)
392{
393 struct afs_cell *cell;
394 struct seq_file *m;
395 int ret;
396
Al Virod9dda782013-03-31 18:16:14 -0400397 cell = PDE_DATA(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 if (!cell)
399 return -ENOENT;
400
401 ret = seq_open(file, &afs_proc_cell_volumes_ops);
402 if (ret < 0)
403 return ret;
404
405 m = file->private_data;
406 m->private = cell;
407
408 return 0;
David Howellsec268152007-04-26 15:49:28 -0700409}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 * set up the iterator to start reading from the cells list and return the
413 * first item
414 */
415static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos)
416{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 struct afs_cell *cell = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419 _enter("cell=%p pos=%Ld", cell, *_pos);
420
David Howellsd2ddc772017-11-02 15:27:50 +0000421 read_lock(&cell->proc_lock);
422 return seq_list_start_head(&cell->proc_volumes, *_pos);
David Howellsec268152007-04-26 15:49:28 -0700423}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425/*
426 * move to next cell in cells list
427 */
428static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
429 loff_t *_pos)
430{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 struct afs_cell *cell = p->private;
432
433 _enter("cell=%p pos=%Ld", cell, *_pos);
David Howellsd2ddc772017-11-02 15:27:50 +0000434 return seq_list_next(v, &cell->proc_volumes, _pos);
David Howellsec268152007-04-26 15:49:28 -0700435}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437/*
438 * clean up after reading from the cells list
439 */
440static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v)
441{
442 struct afs_cell *cell = p->private;
443
David Howellsd2ddc772017-11-02 15:27:50 +0000444 read_unlock(&cell->proc_lock);
David Howellsec268152007-04-26 15:49:28 -0700445}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
David Howellsd2ddc772017-11-02 15:27:50 +0000447static const char afs_vol_types[3][3] = {
448 [AFSVL_RWVOL] = "RW",
449 [AFSVL_ROVOL] = "RO",
450 [AFSVL_BACKVOL] = "BK",
David Howells08e0e7c2007-04-26 15:55:03 -0700451};
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453/*
454 * display a header line followed by a load of volume lines
455 */
456static int afs_proc_cell_volumes_show(struct seq_file *m, void *v)
457{
Pavel Emelianova6a8bd62007-07-15 23:39:52 -0700458 struct afs_cell *cell = m->private;
David Howellsd2ddc772017-11-02 15:27:50 +0000459 struct afs_volume *vol = list_entry(v, struct afs_volume, proc_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
David Howellsd2ddc772017-11-02 15:27:50 +0000461 /* Display header on line 1 */
462 if (v == &cell->proc_volumes) {
463 seq_puts(m, "USE VID TY\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 return 0;
465 }
466
David Howellsd2ddc772017-11-02 15:27:50 +0000467 seq_printf(m, "%3d %08x %s\n",
468 atomic_read(&vol->usage), vol->vid,
469 afs_vol_types[vol->type]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 return 0;
David Howellsec268152007-04-26 15:49:28 -0700472}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474/*
475 * open "/proc/fs/afs/<cell>/vlservers" which provides a list of volume
476 * location server
477 */
478static int afs_proc_cell_vlservers_open(struct inode *inode, struct file *file)
479{
480 struct afs_cell *cell;
481 struct seq_file *m;
482 int ret;
483
Al Virod9dda782013-03-31 18:16:14 -0400484 cell = PDE_DATA(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 if (!cell)
486 return -ENOENT;
487
David Howells08e0e7c2007-04-26 15:55:03 -0700488 ret = seq_open(file, &afs_proc_cell_vlservers_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 if (ret<0)
490 return ret;
491
492 m = file->private_data;
493 m->private = cell;
494
495 return 0;
David Howellsec268152007-04-26 15:49:28 -0700496}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 * set up the iterator to start reading from the cells list and return the
500 * first item
501 */
502static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos)
503{
David Howells8b2a4642017-11-02 15:27:50 +0000504 struct afs_addr_list *alist;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 struct afs_cell *cell = m->private;
506 loff_t pos = *_pos;
507
David Howells8b2a4642017-11-02 15:27:50 +0000508 rcu_read_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
David Howells8b2a4642017-11-02 15:27:50 +0000510 alist = rcu_dereference(cell->vl_addrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 /* allow for the header line */
513 if (!pos)
514 return (void *) 1;
515 pos--;
516
David Howells8b2a4642017-11-02 15:27:50 +0000517 if (!alist || pos >= alist->nr_addrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 return NULL;
519
David Howells8b2a4642017-11-02 15:27:50 +0000520 return alist->addrs + pos;
David Howellsec268152007-04-26 15:49:28 -0700521}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523/*
524 * move to next cell in cells list
525 */
526static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v,
527 loff_t *_pos)
528{
David Howells8b2a4642017-11-02 15:27:50 +0000529 struct afs_addr_list *alist;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 struct afs_cell *cell = p->private;
531 loff_t pos;
532
David Howells8b2a4642017-11-02 15:27:50 +0000533 alist = rcu_dereference(cell->vl_addrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 pos = *_pos;
536 (*_pos)++;
David Howells8b2a4642017-11-02 15:27:50 +0000537 if (!alist || pos >= alist->nr_addrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 return NULL;
539
David Howells8b2a4642017-11-02 15:27:50 +0000540 return alist->addrs + pos;
David Howellsec268152007-04-26 15:49:28 -0700541}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543/*
544 * clean up after reading from the cells list
545 */
546static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v)
547{
David Howells8b2a4642017-11-02 15:27:50 +0000548 rcu_read_unlock();
David Howellsec268152007-04-26 15:49:28 -0700549}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551/*
552 * display a header line followed by a load of volume lines
553 */
554static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v)
555{
David Howells4d9df982017-11-02 15:27:47 +0000556 struct sockaddr_rxrpc *addr = v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
558 /* display header on line 1 */
David Howells4d9df982017-11-02 15:27:47 +0000559 if (v == (void *)1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 seq_puts(m, "ADDRESS\n");
561 return 0;
562 }
563
564 /* display one cell per line on subsequent lines */
David Howells4d9df982017-11-02 15:27:47 +0000565 seq_printf(m, "%pISp\n", &addr->transport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 return 0;
David Howellsec268152007-04-26 15:49:28 -0700567}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569/*
David Howellsd2ddc772017-11-02 15:27:50 +0000570 * open "/proc/fs/afs/servers" which provides a summary of active
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 * servers
572 */
David Howellsd2ddc772017-11-02 15:27:50 +0000573static int afs_proc_servers_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574{
David Howellsd2ddc772017-11-02 15:27:50 +0000575 return seq_open(file, &afs_proc_servers_ops);
David Howellsec268152007-04-26 15:49:28 -0700576}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578/*
David Howellsd2ddc772017-11-02 15:27:50 +0000579 * Set up the iterator to start reading from the server list and return the
580 * first item.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 */
David Howellsd2ddc772017-11-02 15:27:50 +0000582static void *afs_proc_servers_start(struct seq_file *m, loff_t *_pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583{
David Howellsd2ddc772017-11-02 15:27:50 +0000584 struct afs_net *net = afs_seq2net(m);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
David Howellsd2ddc772017-11-02 15:27:50 +0000586 rcu_read_lock();
587 return seq_hlist_start_head_rcu(&net->fs_proc, *_pos);
David Howellsec268152007-04-26 15:49:28 -0700588}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590/*
591 * move to next cell in cells list
592 */
David Howellsd2ddc772017-11-02 15:27:50 +0000593static void *afs_proc_servers_next(struct seq_file *m, void *v, loff_t *_pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
David Howellsd2ddc772017-11-02 15:27:50 +0000595 struct afs_net *net = afs_seq2net(m);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
David Howellsd2ddc772017-11-02 15:27:50 +0000597 return seq_hlist_next_rcu(v, &net->fs_proc, _pos);
David Howellsec268152007-04-26 15:49:28 -0700598}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600/*
601 * clean up after reading from the cells list
602 */
David Howellsd2ddc772017-11-02 15:27:50 +0000603static void afs_proc_servers_stop(struct seq_file *p, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
David Howellsd2ddc772017-11-02 15:27:50 +0000605 rcu_read_unlock();
David Howellsec268152007-04-26 15:49:28 -0700606}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608/*
609 * display a header line followed by a load of volume lines
610 */
David Howellsd2ddc772017-11-02 15:27:50 +0000611static int afs_proc_servers_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612{
David Howellsd2ddc772017-11-02 15:27:50 +0000613 struct afs_server *server;
614 struct afs_addr_list *alist;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
David Howellsd2ddc772017-11-02 15:27:50 +0000616 if (v == SEQ_START_TOKEN) {
617 seq_puts(m, "UUID USE ADDR\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 return 0;
619 }
620
David Howellsd2ddc772017-11-02 15:27:50 +0000621 server = list_entry(v, struct afs_server, proc_link);
622 alist = rcu_dereference(server->addresses);
623 seq_printf(m, "%pU %3d %pISp\n",
624 &server->uuid,
625 atomic_read(&server->usage),
626 &alist->addrs[alist->index].transport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 return 0;
David Howellsec268152007-04-26 15:49:28 -0700628}