blob: 526e4bbbde59e4936f91367101adac8c7373053e [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 Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/uaccess.h>
18#include "internal.h"
19
20static struct proc_dir_entry *proc_afs;
21
22
23static int afs_proc_cells_open(struct inode *inode, struct file *file);
24static void *afs_proc_cells_start(struct seq_file *p, loff_t *pos);
25static void *afs_proc_cells_next(struct seq_file *p, void *v, loff_t *pos);
26static void afs_proc_cells_stop(struct seq_file *p, void *v);
27static int afs_proc_cells_show(struct seq_file *m, void *v);
28static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf,
29 size_t size, loff_t *_pos);
30
James Morris88e9d342009-09-22 16:43:43 -070031static const struct seq_operations afs_proc_cells_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 .start = afs_proc_cells_start,
33 .next = afs_proc_cells_next,
34 .stop = afs_proc_cells_stop,
35 .show = afs_proc_cells_show,
36};
37
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080038static const struct file_operations afs_proc_cells_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 .open = afs_proc_cells_open,
40 .read = seq_read,
41 .write = afs_proc_cells_write,
42 .llseek = seq_lseek,
43 .release = seq_release,
Denis V. Lunev21ac2952008-04-29 01:02:07 -070044 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070045};
46
47static int afs_proc_rootcell_open(struct inode *inode, struct file *file);
48static int afs_proc_rootcell_release(struct inode *inode, struct file *file);
49static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf,
50 size_t size, loff_t *_pos);
51static ssize_t afs_proc_rootcell_write(struct file *file,
52 const char __user *buf,
53 size_t size, loff_t *_pos);
54
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080055static const struct file_operations afs_proc_rootcell_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 .open = afs_proc_rootcell_open,
57 .read = afs_proc_rootcell_read,
58 .write = afs_proc_rootcell_write,
59 .llseek = no_llseek,
Denis V. Lunev21ac2952008-04-29 01:02:07 -070060 .release = afs_proc_rootcell_release,
61 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070062};
63
64static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file);
65static int afs_proc_cell_volumes_release(struct inode *inode,
66 struct file *file);
67static void *afs_proc_cell_volumes_start(struct seq_file *p, loff_t *pos);
68static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
69 loff_t *pos);
70static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v);
71static int afs_proc_cell_volumes_show(struct seq_file *m, void *v);
72
James Morris88e9d342009-09-22 16:43:43 -070073static const struct seq_operations afs_proc_cell_volumes_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 .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,
78};
79
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080080static const struct file_operations afs_proc_cell_volumes_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 .open = afs_proc_cell_volumes_open,
82 .read = seq_read,
83 .llseek = seq_lseek,
84 .release = afs_proc_cell_volumes_release,
Denis V. Lunev21ac2952008-04-29 01:02:07 -070085 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086};
87
88static int afs_proc_cell_vlservers_open(struct inode *inode,
89 struct file *file);
90static int afs_proc_cell_vlservers_release(struct inode *inode,
91 struct file *file);
92static void *afs_proc_cell_vlservers_start(struct seq_file *p, loff_t *pos);
93static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v,
94 loff_t *pos);
95static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v);
96static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v);
97
James Morris88e9d342009-09-22 16:43:43 -070098static const struct seq_operations afs_proc_cell_vlservers_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 .start = afs_proc_cell_vlservers_start,
100 .next = afs_proc_cell_vlservers_next,
101 .stop = afs_proc_cell_vlservers_stop,
102 .show = afs_proc_cell_vlservers_show,
103};
104
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800105static const struct file_operations afs_proc_cell_vlservers_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 .open = afs_proc_cell_vlservers_open,
107 .read = seq_read,
108 .llseek = seq_lseek,
109 .release = afs_proc_cell_vlservers_release,
Denis V. Lunev21ac2952008-04-29 01:02:07 -0700110 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111};
112
113static int afs_proc_cell_servers_open(struct inode *inode, struct file *file);
114static int afs_proc_cell_servers_release(struct inode *inode,
115 struct file *file);
116static void *afs_proc_cell_servers_start(struct seq_file *p, loff_t *pos);
117static void *afs_proc_cell_servers_next(struct seq_file *p, void *v,
118 loff_t *pos);
119static void afs_proc_cell_servers_stop(struct seq_file *p, void *v);
120static int afs_proc_cell_servers_show(struct seq_file *m, void *v);
121
James Morris88e9d342009-09-22 16:43:43 -0700122static const struct seq_operations afs_proc_cell_servers_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 .start = afs_proc_cell_servers_start,
124 .next = afs_proc_cell_servers_next,
125 .stop = afs_proc_cell_servers_stop,
126 .show = afs_proc_cell_servers_show,
127};
128
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800129static const struct file_operations afs_proc_cell_servers_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .open = afs_proc_cell_servers_open,
131 .read = seq_read,
132 .llseek = seq_lseek,
133 .release = afs_proc_cell_servers_release,
Denis V. Lunev21ac2952008-04-29 01:02:07 -0700134 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135};
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137/*
138 * initialise the /proc/fs/afs/ directory
139 */
140int afs_proc_init(void)
141{
142 struct proc_dir_entry *p;
143
144 _enter("");
145
146 proc_afs = proc_mkdir("fs/afs", NULL);
147 if (!proc_afs)
David Howellsec268152007-04-26 15:49:28 -0700148 goto error_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Denis V. Lunev21ac2952008-04-29 01:02:07 -0700150 p = proc_create("cells", 0, proc_afs, &afs_proc_cells_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 if (!p)
David Howellsec268152007-04-26 15:49:28 -0700152 goto error_cells;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Denis V. Lunev21ac2952008-04-29 01:02:07 -0700154 p = proc_create("rootcell", 0, proc_afs, &afs_proc_rootcell_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 if (!p)
David Howellsec268152007-04-26 15:49:28 -0700156 goto error_rootcell;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158 _leave(" = 0");
159 return 0;
160
David Howellsec268152007-04-26 15:49:28 -0700161error_rootcell:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 remove_proc_entry("cells", proc_afs);
David Howellsec268152007-04-26 15:49:28 -0700163error_cells:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 remove_proc_entry("fs/afs", NULL);
David Howellsec268152007-04-26 15:49:28 -0700165error_dir:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 _leave(" = -ENOMEM");
167 return -ENOMEM;
David Howellsec268152007-04-26 15:49:28 -0700168}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170/*
171 * clean up the /proc/fs/afs/ directory
172 */
173void afs_proc_cleanup(void)
174{
David Howellsec268152007-04-26 15:49:28 -0700175 remove_proc_entry("rootcell", proc_afs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 remove_proc_entry("cells", proc_afs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 remove_proc_entry("fs/afs", NULL);
David Howellsec268152007-04-26 15:49:28 -0700178}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180/*
181 * open "/proc/fs/afs/cells" which provides a summary of extant cells
182 */
183static int afs_proc_cells_open(struct inode *inode, struct file *file)
184{
185 struct seq_file *m;
186 int ret;
187
188 ret = seq_open(file, &afs_proc_cells_ops);
189 if (ret < 0)
190 return ret;
191
192 m = file->private_data;
Al Virod9dda782013-03-31 18:16:14 -0400193 m->private = PDE_DATA(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195 return 0;
David Howellsec268152007-04-26 15:49:28 -0700196}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198/*
199 * set up the iterator to start reading from the cells list and return the
200 * first item
201 */
202static void *afs_proc_cells_start(struct seq_file *m, loff_t *_pos)
203{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 /* lock the list against modification */
205 down_read(&afs_proc_cells_sem);
Pavel Emelianova6a8bd62007-07-15 23:39:52 -0700206 return seq_list_start_head(&afs_proc_cells, *_pos);
David Howellsec268152007-04-26 15:49:28 -0700207}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209/*
210 * move to next cell in cells list
211 */
212static void *afs_proc_cells_next(struct seq_file *p, void *v, loff_t *pos)
213{
Pavel Emelianova6a8bd62007-07-15 23:39:52 -0700214 return seq_list_next(v, &afs_proc_cells, pos);
David Howellsec268152007-04-26 15:49:28 -0700215}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217/*
218 * clean up after reading from the cells list
219 */
220static void afs_proc_cells_stop(struct seq_file *p, void *v)
221{
222 up_read(&afs_proc_cells_sem);
David Howellsec268152007-04-26 15:49:28 -0700223}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225/*
226 * display a header line followed by a load of cell lines
227 */
228static int afs_proc_cells_show(struct seq_file *m, void *v)
229{
230 struct afs_cell *cell = list_entry(v, struct afs_cell, proc_link);
231
Pavel Emelianova6a8bd62007-07-15 23:39:52 -0700232 if (v == &afs_proc_cells) {
David Howellsec268152007-04-26 15:49:28 -0700233 /* display header on line 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 seq_puts(m, "USE NAME\n");
235 return 0;
236 }
237
238 /* display one cell per line on subsequent lines */
David Howellsec268152007-04-26 15:49:28 -0700239 seq_printf(m, "%3d %s\n",
240 atomic_read(&cell->usage), cell->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return 0;
David Howellsec268152007-04-26 15:49:28 -0700242}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244/*
245 * handle writes to /proc/fs/afs/cells
246 * - to add cells: echo "add <cellname> <IP>[:<IP>][:<IP>]"
247 */
248static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf,
249 size_t size, loff_t *_pos)
250{
251 char *kbuf, *name, *args;
252 int ret;
253
254 /* start by dragging the command into memory */
255 if (size <= 1 || size >= PAGE_SIZE)
256 return -EINVAL;
257
258 kbuf = kmalloc(size + 1, GFP_KERNEL);
259 if (!kbuf)
260 return -ENOMEM;
261
262 ret = -EFAULT;
263 if (copy_from_user(kbuf, buf, size) != 0)
264 goto done;
265 kbuf[size] = 0;
266
267 /* trim to first NL */
268 name = memchr(kbuf, '\n', size);
269 if (name)
270 *name = 0;
271
272 /* split into command, name and argslist */
273 name = strchr(kbuf, ' ');
274 if (!name)
275 goto inval;
276 do {
277 *name++ = 0;
278 } while(*name == ' ');
279 if (!*name)
280 goto inval;
281
282 args = strchr(name, ' ');
283 if (!args)
284 goto inval;
285 do {
286 *args++ = 0;
287 } while(*args == ' ');
288 if (!*args)
289 goto inval;
290
291 /* determine command to perform */
292 _debug("cmd=%s name=%s args=%s", kbuf, name, args);
293
294 if (strcmp(kbuf, "add") == 0) {
295 struct afs_cell *cell;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
wangleibec5eb62010-08-11 09:38:04 +0100297 cell = afs_cell_create(name, strlen(name), args, false);
David Howells08e0e7c2007-04-26 15:55:03 -0700298 if (IS_ERR(cell)) {
299 ret = PTR_ERR(cell);
300 goto done;
301 }
302
303 afs_put_cell(cell);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 printk("kAFS: Added new cell '%s'\n", name);
David Howellsec268152007-04-26 15:49:28 -0700305 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 goto inval;
307 }
308
309 ret = size;
310
David Howellsec268152007-04-26 15:49:28 -0700311done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 kfree(kbuf);
313 _leave(" = %d", ret);
314 return ret;
315
David Howellsec268152007-04-26 15:49:28 -0700316inval:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 ret = -EINVAL;
318 printk("kAFS: Invalid Command on /proc/fs/afs/cells file\n");
319 goto done;
David Howellsec268152007-04-26 15:49:28 -0700320}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322/*
323 * Stubs for /proc/fs/afs/rootcell
324 */
325static int afs_proc_rootcell_open(struct inode *inode, struct file *file)
326{
327 return 0;
328}
329
330static int afs_proc_rootcell_release(struct inode *inode, struct file *file)
331{
332 return 0;
333}
334
335static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf,
336 size_t size, loff_t *_pos)
337{
338 return 0;
339}
340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341/*
342 * handle writes to /proc/fs/afs/rootcell
343 * - to initialize rootcell: echo "cell.name:192.168.231.14"
344 */
345static ssize_t afs_proc_rootcell_write(struct file *file,
346 const char __user *buf,
347 size_t size, loff_t *_pos)
348{
349 char *kbuf, *s;
350 int ret;
351
352 /* start by dragging the command into memory */
353 if (size <= 1 || size >= PAGE_SIZE)
354 return -EINVAL;
355
356 ret = -ENOMEM;
357 kbuf = kmalloc(size + 1, GFP_KERNEL);
358 if (!kbuf)
359 goto nomem;
360
361 ret = -EFAULT;
362 if (copy_from_user(kbuf, buf, size) != 0)
363 goto infault;
364 kbuf[size] = 0;
365
366 /* trim to first NL */
367 s = memchr(kbuf, '\n', size);
368 if (s)
369 *s = 0;
370
371 /* determine command to perform */
372 _debug("rootcell=%s", kbuf);
373
374 ret = afs_cell_init(kbuf);
375 if (ret >= 0)
376 ret = size; /* consume everything, always */
377
David Howellsec268152007-04-26 15:49:28 -0700378infault:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 kfree(kbuf);
David Howellsec268152007-04-26 15:49:28 -0700380nomem:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 _leave(" = %d", ret);
382 return ret;
David Howellsec268152007-04-26 15:49:28 -0700383}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385/*
386 * initialise /proc/fs/afs/<cell>/
387 */
388int afs_proc_cell_setup(struct afs_cell *cell)
389{
390 struct proc_dir_entry *p;
391
392 _enter("%p{%s}", cell, cell->name);
393
394 cell->proc_dir = proc_mkdir(cell->name, proc_afs);
395 if (!cell->proc_dir)
David Howellsec268152007-04-26 15:49:28 -0700396 goto error_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Denis V. Lunev21ac2952008-04-29 01:02:07 -0700398 p = proc_create_data("servers", 0, cell->proc_dir,
399 &afs_proc_cell_servers_fops, cell);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 if (!p)
David Howellsec268152007-04-26 15:49:28 -0700401 goto error_servers;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Denis V. Lunev21ac2952008-04-29 01:02:07 -0700403 p = proc_create_data("vlservers", 0, cell->proc_dir,
404 &afs_proc_cell_vlservers_fops, cell);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 if (!p)
David Howellsec268152007-04-26 15:49:28 -0700406 goto error_vlservers;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Denis V. Lunev21ac2952008-04-29 01:02:07 -0700408 p = proc_create_data("volumes", 0, cell->proc_dir,
409 &afs_proc_cell_volumes_fops, cell);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 if (!p)
David Howellsec268152007-04-26 15:49:28 -0700411 goto error_volumes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 _leave(" = 0");
414 return 0;
415
David Howellsec268152007-04-26 15:49:28 -0700416error_volumes:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 remove_proc_entry("vlservers", cell->proc_dir);
David Howellsec268152007-04-26 15:49:28 -0700418error_vlservers:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 remove_proc_entry("servers", cell->proc_dir);
David Howellsec268152007-04-26 15:49:28 -0700420error_servers:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 remove_proc_entry(cell->name, proc_afs);
David Howellsec268152007-04-26 15:49:28 -0700422error_dir:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 _leave(" = -ENOMEM");
424 return -ENOMEM;
David Howellsec268152007-04-26 15:49:28 -0700425}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427/*
428 * remove /proc/fs/afs/<cell>/
429 */
430void afs_proc_cell_remove(struct afs_cell *cell)
431{
432 _enter("");
433
434 remove_proc_entry("volumes", cell->proc_dir);
435 remove_proc_entry("vlservers", cell->proc_dir);
436 remove_proc_entry("servers", cell->proc_dir);
437 remove_proc_entry(cell->name, proc_afs);
438
439 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700440}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442/*
443 * open "/proc/fs/afs/<cell>/volumes" which provides a summary of extant cells
444 */
445static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file)
446{
447 struct afs_cell *cell;
448 struct seq_file *m;
449 int ret;
450
Al Virod9dda782013-03-31 18:16:14 -0400451 cell = PDE_DATA(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 if (!cell)
453 return -ENOENT;
454
455 ret = seq_open(file, &afs_proc_cell_volumes_ops);
456 if (ret < 0)
457 return ret;
458
459 m = file->private_data;
460 m->private = cell;
461
462 return 0;
David Howellsec268152007-04-26 15:49:28 -0700463}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465/*
466 * close the file and release the ref to the cell
467 */
468static int afs_proc_cell_volumes_release(struct inode *inode, struct file *file)
469{
David Howells08e0e7c2007-04-26 15:55:03 -0700470 return seq_release(inode, file);
David Howellsec268152007-04-26 15:49:28 -0700471}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473/*
474 * set up the iterator to start reading from the cells list and return the
475 * first item
476 */
477static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos)
478{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 struct afs_cell *cell = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
481 _enter("cell=%p pos=%Ld", cell, *_pos);
482
483 /* lock the list against modification */
484 down_read(&cell->vl_sem);
Pavel Emelianova6a8bd62007-07-15 23:39:52 -0700485 return seq_list_start_head(&cell->vl_list, *_pos);
David Howellsec268152007-04-26 15:49:28 -0700486}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488/*
489 * move to next cell in cells list
490 */
491static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
492 loff_t *_pos)
493{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 struct afs_cell *cell = p->private;
495
496 _enter("cell=%p pos=%Ld", cell, *_pos);
Pavel Emelianova6a8bd62007-07-15 23:39:52 -0700497 return seq_list_next(v, &cell->vl_list, _pos);
David Howellsec268152007-04-26 15:49:28 -0700498}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500/*
501 * clean up after reading from the cells list
502 */
503static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v)
504{
505 struct afs_cell *cell = p->private;
506
507 up_read(&cell->vl_sem);
David Howellsec268152007-04-26 15:49:28 -0700508}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Adrian Bunkc1206a22007-10-16 23:26:41 -0700510static const char afs_vlocation_states[][4] = {
David Howells08e0e7c2007-04-26 15:55:03 -0700511 [AFS_VL_NEW] = "New",
512 [AFS_VL_CREATING] = "Crt",
513 [AFS_VL_VALID] = "Val",
514 [AFS_VL_NO_VOLUME] = "NoV",
515 [AFS_VL_UPDATING] = "Upd",
516 [AFS_VL_VOLUME_DELETED] = "Del",
517 [AFS_VL_UNCERTAIN] = "Unc",
518};
519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520/*
521 * display a header line followed by a load of volume lines
522 */
523static int afs_proc_cell_volumes_show(struct seq_file *m, void *v)
524{
Pavel Emelianova6a8bd62007-07-15 23:39:52 -0700525 struct afs_cell *cell = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 struct afs_vlocation *vlocation =
527 list_entry(v, struct afs_vlocation, link);
528
529 /* display header on line 1 */
Pavel Emelianova6a8bd62007-07-15 23:39:52 -0700530 if (v == &cell->vl_list) {
David Howells08e0e7c2007-04-26 15:55:03 -0700531 seq_puts(m, "USE STT VLID[0] VLID[1] VLID[2] NAME\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 return 0;
533 }
534
535 /* display one cell per line on subsequent lines */
David Howells08e0e7c2007-04-26 15:55:03 -0700536 seq_printf(m, "%3d %s %08x %08x %08x %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 atomic_read(&vlocation->usage),
David Howells08e0e7c2007-04-26 15:55:03 -0700538 afs_vlocation_states[vlocation->state],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 vlocation->vldb.vid[0],
540 vlocation->vldb.vid[1],
541 vlocation->vldb.vid[2],
David Howellsec268152007-04-26 15:49:28 -0700542 vlocation->vldb.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 return 0;
David Howellsec268152007-04-26 15:49:28 -0700545}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547/*
548 * open "/proc/fs/afs/<cell>/vlservers" which provides a list of volume
549 * location server
550 */
551static int afs_proc_cell_vlservers_open(struct inode *inode, struct file *file)
552{
553 struct afs_cell *cell;
554 struct seq_file *m;
555 int ret;
556
Al Virod9dda782013-03-31 18:16:14 -0400557 cell = PDE_DATA(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 if (!cell)
559 return -ENOENT;
560
David Howells08e0e7c2007-04-26 15:55:03 -0700561 ret = seq_open(file, &afs_proc_cell_vlservers_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 if (ret<0)
563 return ret;
564
565 m = file->private_data;
566 m->private = cell;
567
568 return 0;
David Howellsec268152007-04-26 15:49:28 -0700569}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571/*
572 * close the file and release the ref to the cell
573 */
574static int afs_proc_cell_vlservers_release(struct inode *inode,
575 struct file *file)
576{
David Howells08e0e7c2007-04-26 15:55:03 -0700577 return seq_release(inode, file);
David Howellsec268152007-04-26 15:49:28 -0700578}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580/*
581 * set up the iterator to start reading from the cells list and return the
582 * first item
583 */
584static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos)
585{
586 struct afs_cell *cell = m->private;
587 loff_t pos = *_pos;
588
589 _enter("cell=%p pos=%Ld", cell, *_pos);
590
591 /* lock the list against modification */
592 down_read(&cell->vl_sem);
593
594 /* allow for the header line */
595 if (!pos)
596 return (void *) 1;
597 pos--;
598
599 if (pos >= cell->vl_naddrs)
600 return NULL;
601
602 return &cell->vl_addrs[pos];
David Howellsec268152007-04-26 15:49:28 -0700603}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605/*
606 * move to next cell in cells list
607 */
608static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v,
609 loff_t *_pos)
610{
611 struct afs_cell *cell = p->private;
612 loff_t pos;
613
614 _enter("cell=%p{nad=%u} pos=%Ld", cell, cell->vl_naddrs, *_pos);
615
616 pos = *_pos;
617 (*_pos)++;
618 if (pos >= cell->vl_naddrs)
619 return NULL;
620
621 return &cell->vl_addrs[pos];
David Howellsec268152007-04-26 15:49:28 -0700622}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624/*
625 * clean up after reading from the cells list
626 */
627static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v)
628{
629 struct afs_cell *cell = p->private;
630
631 up_read(&cell->vl_sem);
David Howellsec268152007-04-26 15:49:28 -0700632}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634/*
635 * display a header line followed by a load of volume lines
636 */
637static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v)
638{
639 struct in_addr *addr = v;
640
641 /* display header on line 1 */
642 if (v == (struct in_addr *) 1) {
643 seq_puts(m, "ADDRESS\n");
644 return 0;
645 }
646
647 /* display one cell per line on subsequent lines */
Harvey Harrisonbe859402008-10-31 00:56:28 -0700648 seq_printf(m, "%pI4\n", &addr->s_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 return 0;
David Howellsec268152007-04-26 15:49:28 -0700650}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652/*
653 * open "/proc/fs/afs/<cell>/servers" which provides a summary of active
654 * servers
655 */
656static int afs_proc_cell_servers_open(struct inode *inode, struct file *file)
657{
658 struct afs_cell *cell;
659 struct seq_file *m;
660 int ret;
661
Al Virod9dda782013-03-31 18:16:14 -0400662 cell = PDE_DATA(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 if (!cell)
664 return -ENOENT;
665
666 ret = seq_open(file, &afs_proc_cell_servers_ops);
667 if (ret < 0)
668 return ret;
669
670 m = file->private_data;
671 m->private = cell;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 return 0;
David Howellsec268152007-04-26 15:49:28 -0700673}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675/*
676 * close the file and release the ref to the cell
677 */
678static int afs_proc_cell_servers_release(struct inode *inode,
679 struct file *file)
680{
David Howells08e0e7c2007-04-26 15:55:03 -0700681 return seq_release(inode, file);
David Howellsec268152007-04-26 15:49:28 -0700682}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684/*
685 * set up the iterator to start reading from the cells list and return the
686 * first item
687 */
688static void *afs_proc_cell_servers_start(struct seq_file *m, loff_t *_pos)
David Howells08e0e7c2007-04-26 15:55:03 -0700689 __acquires(m->private->servers_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 struct afs_cell *cell = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
693 _enter("cell=%p pos=%Ld", cell, *_pos);
694
695 /* lock the list against modification */
David Howells08e0e7c2007-04-26 15:55:03 -0700696 read_lock(&cell->servers_lock);
Pavel Emelianova6a8bd62007-07-15 23:39:52 -0700697 return seq_list_start_head(&cell->servers, *_pos);
David Howellsec268152007-04-26 15:49:28 -0700698}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700/*
701 * move to next cell in cells list
702 */
703static void *afs_proc_cell_servers_next(struct seq_file *p, void *v,
704 loff_t *_pos)
705{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 struct afs_cell *cell = p->private;
707
708 _enter("cell=%p pos=%Ld", cell, *_pos);
Pavel Emelianova6a8bd62007-07-15 23:39:52 -0700709 return seq_list_next(v, &cell->servers, _pos);
David Howellsec268152007-04-26 15:49:28 -0700710}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712/*
713 * clean up after reading from the cells list
714 */
715static void afs_proc_cell_servers_stop(struct seq_file *p, void *v)
David Howells08e0e7c2007-04-26 15:55:03 -0700716 __releases(p->private->servers_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717{
718 struct afs_cell *cell = p->private;
719
David Howells08e0e7c2007-04-26 15:55:03 -0700720 read_unlock(&cell->servers_lock);
David Howellsec268152007-04-26 15:49:28 -0700721}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723/*
724 * display a header line followed by a load of volume lines
725 */
726static int afs_proc_cell_servers_show(struct seq_file *m, void *v)
727{
Pavel Emelianova6a8bd62007-07-15 23:39:52 -0700728 struct afs_cell *cell = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 struct afs_server *server = list_entry(v, struct afs_server, link);
730 char ipaddr[20];
731
732 /* display header on line 1 */
Pavel Emelianova6a8bd62007-07-15 23:39:52 -0700733 if (v == &cell->servers) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 seq_puts(m, "USE ADDR STATE\n");
735 return 0;
736 }
737
738 /* display one cell per line on subsequent lines */
Harvey Harrisonbe859402008-10-31 00:56:28 -0700739 sprintf(ipaddr, "%pI4", &server->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 seq_printf(m, "%3d %-15.15s %5d\n",
David Howellsec268152007-04-26 15:49:28 -0700741 atomic_read(&server->usage), ipaddr, server->fs_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
743 return 0;
David Howellsec268152007-04-26 15:49:28 -0700744}