Blame view

fs/afs/proc.c 14.9 KB
ec26815ad   David Howells   [AFS]: Clean up t...
1
  /* /proc interface for AFS
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
   *
   * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
   * Written by David Howells (dhowells@redhat.com)
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License
   * as published by the Free Software Foundation; either version
   * 2 of the License, or (at your option) any later version.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
12
13
14
  #include <linux/slab.h>
  #include <linux/module.h>
  #include <linux/proc_fs.h>
  #include <linux/seq_file.h>
e8edc6e03   Alexey Dobriyan   Detach sched.h fr...
15
  #include <linux/sched.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
17
18
19
20
21
22
23
24
25
26
27
28
  #include <asm/uaccess.h>
  #include "internal.h"
  
  static struct proc_dir_entry *proc_afs;
  
  
  static int afs_proc_cells_open(struct inode *inode, struct file *file);
  static void *afs_proc_cells_start(struct seq_file *p, loff_t *pos);
  static void *afs_proc_cells_next(struct seq_file *p, void *v, loff_t *pos);
  static void afs_proc_cells_stop(struct seq_file *p, void *v);
  static int afs_proc_cells_show(struct seq_file *m, void *v);
  static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf,
  				    size_t size, loff_t *_pos);
88e9d34c7   James Morris   seq_file: constif...
29
  static const struct seq_operations afs_proc_cells_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
31
32
33
34
  	.start	= afs_proc_cells_start,
  	.next	= afs_proc_cells_next,
  	.stop	= afs_proc_cells_stop,
  	.show	= afs_proc_cells_show,
  };
4b6f5d20b   Arjan van de Ven   [PATCH] Make most...
35
  static const struct file_operations afs_proc_cells_fops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
38
39
40
41
  	.open		= afs_proc_cells_open,
  	.read		= seq_read,
  	.write		= afs_proc_cells_write,
  	.llseek		= seq_lseek,
  	.release	= seq_release,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
44
45
46
  static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf,
  				      size_t size, loff_t *_pos);
  static ssize_t afs_proc_rootcell_write(struct file *file,
  				       const char __user *buf,
  				       size_t size, loff_t *_pos);
4b6f5d20b   Arjan van de Ven   [PATCH] Make most...
47
  static const struct file_operations afs_proc_rootcell_fops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48
49
50
  	.read		= afs_proc_rootcell_read,
  	.write		= afs_proc_rootcell_write,
  	.llseek		= no_llseek,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
51
52
53
  };
  
  static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
54
55
56
57
58
  static void *afs_proc_cell_volumes_start(struct seq_file *p, loff_t *pos);
  static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
  					loff_t *pos);
  static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v);
  static int afs_proc_cell_volumes_show(struct seq_file *m, void *v);
88e9d34c7   James Morris   seq_file: constif...
59
  static const struct seq_operations afs_proc_cell_volumes_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60
61
62
63
64
  	.start	= afs_proc_cell_volumes_start,
  	.next	= afs_proc_cell_volumes_next,
  	.stop	= afs_proc_cell_volumes_stop,
  	.show	= afs_proc_cell_volumes_show,
  };
4b6f5d20b   Arjan van de Ven   [PATCH] Make most...
65
  static const struct file_operations afs_proc_cell_volumes_fops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
67
68
  	.open		= afs_proc_cell_volumes_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
b42d570c9   Al Viro   afs: get rid of j...
69
  	.release	= seq_release,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
70
71
72
73
  };
  
  static int afs_proc_cell_vlservers_open(struct inode *inode,
  					struct file *file);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
74
75
76
77
78
  static void *afs_proc_cell_vlservers_start(struct seq_file *p, loff_t *pos);
  static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v,
  					  loff_t *pos);
  static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v);
  static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v);
88e9d34c7   James Morris   seq_file: constif...
79
  static const struct seq_operations afs_proc_cell_vlservers_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
80
81
82
83
84
  	.start	= afs_proc_cell_vlservers_start,
  	.next	= afs_proc_cell_vlservers_next,
  	.stop	= afs_proc_cell_vlservers_stop,
  	.show	= afs_proc_cell_vlservers_show,
  };
4b6f5d20b   Arjan van de Ven   [PATCH] Make most...
85
  static const struct file_operations afs_proc_cell_vlservers_fops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86
87
88
  	.open		= afs_proc_cell_vlservers_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
b42d570c9   Al Viro   afs: get rid of j...
89
  	.release	= seq_release,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
91
92
  };
  
  static int afs_proc_cell_servers_open(struct inode *inode, struct file *file);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
93
94
95
96
97
  static void *afs_proc_cell_servers_start(struct seq_file *p, loff_t *pos);
  static void *afs_proc_cell_servers_next(struct seq_file *p, void *v,
  					loff_t *pos);
  static void afs_proc_cell_servers_stop(struct seq_file *p, void *v);
  static int afs_proc_cell_servers_show(struct seq_file *m, void *v);
88e9d34c7   James Morris   seq_file: constif...
98
  static const struct seq_operations afs_proc_cell_servers_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99
100
101
102
103
  	.start	= afs_proc_cell_servers_start,
  	.next	= afs_proc_cell_servers_next,
  	.stop	= afs_proc_cell_servers_stop,
  	.show	= afs_proc_cell_servers_show,
  };
4b6f5d20b   Arjan van de Ven   [PATCH] Make most...
104
  static const struct file_operations afs_proc_cell_servers_fops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105
106
107
  	.open		= afs_proc_cell_servers_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
b42d570c9   Al Viro   afs: get rid of j...
108
  	.release	= seq_release,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
111
112
113
114
  /*
   * initialise the /proc/fs/afs/ directory
   */
  int afs_proc_init(void)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115
116
117
118
  	_enter("");
  
  	proc_afs = proc_mkdir("fs/afs", NULL);
  	if (!proc_afs)
ec26815ad   David Howells   [AFS]: Clean up t...
119
  		goto error_dir;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
120

1bda2ac07   Pali Rohár   afs: proc cells a...
121
122
  	if (!proc_create("cells", 0644, proc_afs, &afs_proc_cells_fops) ||
  	    !proc_create("rootcell", 0644, proc_afs, &afs_proc_rootcell_fops))
b42d570c9   Al Viro   afs: get rid of j...
123
  		goto error_tree;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
124
125
126
  
  	_leave(" = 0");
  	return 0;
b42d570c9   Al Viro   afs: get rid of j...
127
128
  error_tree:
  	remove_proc_subtree("fs/afs", NULL);
ec26815ad   David Howells   [AFS]: Clean up t...
129
  error_dir:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
130
131
  	_leave(" = -ENOMEM");
  	return -ENOMEM;
ec26815ad   David Howells   [AFS]: Clean up t...
132
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
133

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
134
135
136
137
138
  /*
   * clean up the /proc/fs/afs/ directory
   */
  void afs_proc_cleanup(void)
  {
b42d570c9   Al Viro   afs: get rid of j...
139
  	remove_proc_subtree("fs/afs", NULL);
ec26815ad   David Howells   [AFS]: Clean up t...
140
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
142
143
144
145
146
147
148
149
150
151
152
153
154
  /*
   * open "/proc/fs/afs/cells" which provides a summary of extant cells
   */
  static int afs_proc_cells_open(struct inode *inode, struct file *file)
  {
  	struct seq_file *m;
  	int ret;
  
  	ret = seq_open(file, &afs_proc_cells_ops);
  	if (ret < 0)
  		return ret;
  
  	m = file->private_data;
d9dda78ba   Al Viro   procfs: new helpe...
155
  	m->private = PDE_DATA(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
156
157
  
  	return 0;
ec26815ad   David Howells   [AFS]: Clean up t...
158
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
159

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
160
161
162
163
164
165
  /*
   * set up the iterator to start reading from the cells list and return the
   * first item
   */
  static void *afs_proc_cells_start(struct seq_file *m, loff_t *_pos)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
166
167
  	/* lock the list against modification */
  	down_read(&afs_proc_cells_sem);
a6a8bd6d2   Pavel Emelianov   Make AFS use seq_...
168
  	return seq_list_start_head(&afs_proc_cells, *_pos);
ec26815ad   David Howells   [AFS]: Clean up t...
169
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
170

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
171
172
173
174
175
  /*
   * move to next cell in cells list
   */
  static void *afs_proc_cells_next(struct seq_file *p, void *v, loff_t *pos)
  {
a6a8bd6d2   Pavel Emelianov   Make AFS use seq_...
176
  	return seq_list_next(v, &afs_proc_cells, pos);
ec26815ad   David Howells   [AFS]: Clean up t...
177
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
179
180
181
182
183
184
  /*
   * clean up after reading from the cells list
   */
  static void afs_proc_cells_stop(struct seq_file *p, void *v)
  {
  	up_read(&afs_proc_cells_sem);
ec26815ad   David Howells   [AFS]: Clean up t...
185
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
186

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
187
188
189
190
191
192
  /*
   * display a header line followed by a load of cell lines
   */
  static int afs_proc_cells_show(struct seq_file *m, void *v)
  {
  	struct afs_cell *cell = list_entry(v, struct afs_cell, proc_link);
a6a8bd6d2   Pavel Emelianov   Make AFS use seq_...
193
  	if (v == &afs_proc_cells) {
ec26815ad   David Howells   [AFS]: Clean up t...
194
  		/* display header on line 1 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
195
196
197
198
199
200
  		seq_puts(m, "USE NAME
  ");
  		return 0;
  	}
  
  	/* display one cell per line on subsequent lines */
ec26815ad   David Howells   [AFS]: Clean up t...
201
202
203
  	seq_printf(m, "%3d %s
  ",
  		   atomic_read(&cell->usage), cell->name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
204
  	return 0;
ec26815ad   David Howells   [AFS]: Clean up t...
205
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
206

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207
208
209
210
211
212
213
214
215
216
217
218
219
  /*
   * handle writes to /proc/fs/afs/cells
   * - to add cells: echo "add <cellname> <IP>[:<IP>][:<IP>]"
   */
  static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf,
  				    size_t size, loff_t *_pos)
  {
  	char *kbuf, *name, *args;
  	int ret;
  
  	/* start by dragging the command into memory */
  	if (size <= 1 || size >= PAGE_SIZE)
  		return -EINVAL;
16e5c1fc3   Al Viro   convert a bunch o...
220
221
222
  	kbuf = memdup_user_nul(buf, size);
  	if (IS_ERR(kbuf))
  		return PTR_ERR(kbuf);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
  
  	/* trim to first NL */
  	name = memchr(kbuf, '
  ', size);
  	if (name)
  		*name = 0;
  
  	/* split into command, name and argslist */
  	name = strchr(kbuf, ' ');
  	if (!name)
  		goto inval;
  	do {
  		*name++ = 0;
  	} while(*name == ' ');
  	if (!*name)
  		goto inval;
  
  	args = strchr(name, ' ');
  	if (!args)
  		goto inval;
  	do {
  		*args++ = 0;
  	} while(*args == ' ');
  	if (!*args)
  		goto inval;
  
  	/* determine command to perform */
  	_debug("cmd=%s name=%s args=%s", kbuf, name, args);
  
  	if (strcmp(kbuf, "add") == 0) {
  		struct afs_cell *cell;
08e0e7c82   David Howells   [AF_RXRPC]: Make ...
254

bec5eb614   wanglei   AFS: Implement an...
255
  		cell = afs_cell_create(name, strlen(name), args, false);
08e0e7c82   David Howells   [AF_RXRPC]: Make ...
256
257
  		if (IS_ERR(cell)) {
  			ret = PTR_ERR(cell);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
258
  			goto done;
08e0e7c82   David Howells   [AF_RXRPC]: Make ...
259
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
260

08e0e7c82   David Howells   [AF_RXRPC]: Make ...
261
  		afs_put_cell(cell);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
262
263
  		printk("kAFS: Added new cell '%s'
  ", name);
ec26815ad   David Howells   [AFS]: Clean up t...
264
  	} else {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
265
266
267
268
  		goto inval;
  	}
  
  	ret = size;
ec26815ad   David Howells   [AFS]: Clean up t...
269
  done:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
270
271
272
  	kfree(kbuf);
  	_leave(" = %d", ret);
  	return ret;
ec26815ad   David Howells   [AFS]: Clean up t...
273
  inval:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
274
275
276
277
  	ret = -EINVAL;
  	printk("kAFS: Invalid Command on /proc/fs/afs/cells file
  ");
  	goto done;
ec26815ad   David Howells   [AFS]: Clean up t...
278
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
279

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
280
281
282
283
284
  static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf,
  				      size_t size, loff_t *_pos)
  {
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
285
286
287
288
289
290
291
292
293
294
295
296
297
298
  /*
   * handle writes to /proc/fs/afs/rootcell
   * - to initialize rootcell: echo "cell.name:192.168.231.14"
   */
  static ssize_t afs_proc_rootcell_write(struct file *file,
  				       const char __user *buf,
  				       size_t size, loff_t *_pos)
  {
  	char *kbuf, *s;
  	int ret;
  
  	/* start by dragging the command into memory */
  	if (size <= 1 || size >= PAGE_SIZE)
  		return -EINVAL;
16e5c1fc3   Al Viro   convert a bunch o...
299
300
301
  	kbuf = memdup_user_nul(buf, size);
  	if (IS_ERR(kbuf))
  		return PTR_ERR(kbuf);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
302
303
304
305
306
307
308
309
310
311
312
313
314
  
  	/* trim to first NL */
  	s = memchr(kbuf, '
  ', size);
  	if (s)
  		*s = 0;
  
  	/* determine command to perform */
  	_debug("rootcell=%s", kbuf);
  
  	ret = afs_cell_init(kbuf);
  	if (ret >= 0)
  		ret = size;	/* consume everything, always */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
315
  	kfree(kbuf);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
316
317
  	_leave(" = %d", ret);
  	return ret;
ec26815ad   David Howells   [AFS]: Clean up t...
318
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
319

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
320
321
322
323
324
  /*
   * initialise /proc/fs/afs/<cell>/
   */
  int afs_proc_cell_setup(struct afs_cell *cell)
  {
b42d570c9   Al Viro   afs: get rid of j...
325
  	struct proc_dir_entry *dir;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
326
327
  
  	_enter("%p{%s}", cell, cell->name);
b42d570c9   Al Viro   afs: get rid of j...
328
329
  	dir = proc_mkdir(cell->name, proc_afs);
  	if (!dir)
ec26815ad   David Howells   [AFS]: Clean up t...
330
  		goto error_dir;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
331

b42d570c9   Al Viro   afs: get rid of j...
332
333
334
335
336
337
338
  	if (!proc_create_data("servers", 0, dir,
  			     &afs_proc_cell_servers_fops, cell) ||
  	    !proc_create_data("vlservers", 0, dir,
  			     &afs_proc_cell_vlservers_fops, cell) ||
  	    !proc_create_data("volumes", 0, dir,
  			     &afs_proc_cell_volumes_fops, cell))
  		goto error_tree;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
339
340
341
  
  	_leave(" = 0");
  	return 0;
b42d570c9   Al Viro   afs: get rid of j...
342
343
  error_tree:
  	remove_proc_subtree(cell->name, proc_afs);
ec26815ad   David Howells   [AFS]: Clean up t...
344
  error_dir:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
345
346
  	_leave(" = -ENOMEM");
  	return -ENOMEM;
ec26815ad   David Howells   [AFS]: Clean up t...
347
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
349
350
351
352
353
354
  /*
   * remove /proc/fs/afs/<cell>/
   */
  void afs_proc_cell_remove(struct afs_cell *cell)
  {
  	_enter("");
b42d570c9   Al Viro   afs: get rid of j...
355
  	remove_proc_subtree(cell->name, proc_afs);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
356
357
  
  	_leave("");
ec26815ad   David Howells   [AFS]: Clean up t...
358
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
359

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
360
361
362
363
364
365
366
367
  /*
   * open "/proc/fs/afs/<cell>/volumes" which provides a summary of extant cells
   */
  static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file)
  {
  	struct afs_cell *cell;
  	struct seq_file *m;
  	int ret;
d9dda78ba   Al Viro   procfs: new helpe...
368
  	cell = PDE_DATA(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
369
370
371
372
373
374
375
376
377
378
379
  	if (!cell)
  		return -ENOENT;
  
  	ret = seq_open(file, &afs_proc_cell_volumes_ops);
  	if (ret < 0)
  		return ret;
  
  	m = file->private_data;
  	m->private = cell;
  
  	return 0;
ec26815ad   David Howells   [AFS]: Clean up t...
380
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
381

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
382
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
383
384
385
386
387
   * set up the iterator to start reading from the cells list and return the
   * first item
   */
  static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
388
  	struct afs_cell *cell = m->private;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
389
390
391
392
393
  
  	_enter("cell=%p pos=%Ld", cell, *_pos);
  
  	/* lock the list against modification */
  	down_read(&cell->vl_sem);
a6a8bd6d2   Pavel Emelianov   Make AFS use seq_...
394
  	return seq_list_start_head(&cell->vl_list, *_pos);
ec26815ad   David Howells   [AFS]: Clean up t...
395
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
396

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
397
398
399
400
401
402
  /*
   * move to next cell in cells list
   */
  static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
  					loff_t *_pos)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
403
404
405
  	struct afs_cell *cell = p->private;
  
  	_enter("cell=%p pos=%Ld", cell, *_pos);
a6a8bd6d2   Pavel Emelianov   Make AFS use seq_...
406
  	return seq_list_next(v, &cell->vl_list, _pos);
ec26815ad   David Howells   [AFS]: Clean up t...
407
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
408

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
409
410
411
412
413
414
415
416
  /*
   * clean up after reading from the cells list
   */
  static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v)
  {
  	struct afs_cell *cell = p->private;
  
  	up_read(&cell->vl_sem);
ec26815ad   David Howells   [AFS]: Clean up t...
417
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
418

c1206a2c6   Adrian Bunk   fs/afs/: possible...
419
  static const char afs_vlocation_states[][4] = {
08e0e7c82   David Howells   [AF_RXRPC]: Make ...
420
421
422
423
424
425
426
427
  	[AFS_VL_NEW]			= "New",
  	[AFS_VL_CREATING]		= "Crt",
  	[AFS_VL_VALID]			= "Val",
  	[AFS_VL_NO_VOLUME]		= "NoV",
  	[AFS_VL_UPDATING]		= "Upd",
  	[AFS_VL_VOLUME_DELETED]		= "Del",
  	[AFS_VL_UNCERTAIN]		= "Unc",
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
428
429
430
431
432
  /*
   * display a header line followed by a load of volume lines
   */
  static int afs_proc_cell_volumes_show(struct seq_file *m, void *v)
  {
a6a8bd6d2   Pavel Emelianov   Make AFS use seq_...
433
  	struct afs_cell *cell = m->private;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
434
435
436
437
  	struct afs_vlocation *vlocation =
  		list_entry(v, struct afs_vlocation, link);
  
  	/* display header on line 1 */
a6a8bd6d2   Pavel Emelianov   Make AFS use seq_...
438
  	if (v == &cell->vl_list) {
08e0e7c82   David Howells   [AF_RXRPC]: Make ...
439
440
  		seq_puts(m, "USE STT VLID[0]  VLID[1]  VLID[2]  NAME
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
441
442
443
444
  		return 0;
  	}
  
  	/* display one cell per line on subsequent lines */
08e0e7c82   David Howells   [AF_RXRPC]: Make ...
445
446
  	seq_printf(m, "%3d %s %08x %08x %08x %s
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
447
  		   atomic_read(&vlocation->usage),
08e0e7c82   David Howells   [AF_RXRPC]: Make ...
448
  		   afs_vlocation_states[vlocation->state],
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
449
450
451
  		   vlocation->vldb.vid[0],
  		   vlocation->vldb.vid[1],
  		   vlocation->vldb.vid[2],
ec26815ad   David Howells   [AFS]: Clean up t...
452
  		   vlocation->vldb.name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
453
454
  
  	return 0;
ec26815ad   David Howells   [AFS]: Clean up t...
455
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
456

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
457
458
459
460
461
462
463
464
465
  /*
   * open "/proc/fs/afs/<cell>/vlservers" which provides a list of volume
   * location server
   */
  static int afs_proc_cell_vlservers_open(struct inode *inode, struct file *file)
  {
  	struct afs_cell *cell;
  	struct seq_file *m;
  	int ret;
d9dda78ba   Al Viro   procfs: new helpe...
466
  	cell = PDE_DATA(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
467
468
  	if (!cell)
  		return -ENOENT;
08e0e7c82   David Howells   [AF_RXRPC]: Make ...
469
  	ret = seq_open(file, &afs_proc_cell_vlservers_ops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
470
471
472
473
474
475
476
  	if (ret<0)
  		return ret;
  
  	m = file->private_data;
  	m->private = cell;
  
  	return 0;
ec26815ad   David Howells   [AFS]: Clean up t...
477
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
478

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
479
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
   * set up the iterator to start reading from the cells list and return the
   * first item
   */
  static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos)
  {
  	struct afs_cell *cell = m->private;
  	loff_t pos = *_pos;
  
  	_enter("cell=%p pos=%Ld", cell, *_pos);
  
  	/* lock the list against modification */
  	down_read(&cell->vl_sem);
  
  	/* allow for the header line */
  	if (!pos)
  		return (void *) 1;
  	pos--;
  
  	if (pos >= cell->vl_naddrs)
  		return NULL;
  
  	return &cell->vl_addrs[pos];
ec26815ad   David Howells   [AFS]: Clean up t...
502
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
503

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
  /*
   * move to next cell in cells list
   */
  static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v,
  					  loff_t *_pos)
  {
  	struct afs_cell *cell = p->private;
  	loff_t pos;
  
  	_enter("cell=%p{nad=%u} pos=%Ld", cell, cell->vl_naddrs, *_pos);
  
  	pos = *_pos;
  	(*_pos)++;
  	if (pos >= cell->vl_naddrs)
  		return NULL;
  
  	return &cell->vl_addrs[pos];
ec26815ad   David Howells   [AFS]: Clean up t...
521
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
522

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
523
524
525
526
527
528
529
530
  /*
   * clean up after reading from the cells list
   */
  static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v)
  {
  	struct afs_cell *cell = p->private;
  
  	up_read(&cell->vl_sem);
ec26815ad   David Howells   [AFS]: Clean up t...
531
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
532

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
  /*
   * display a header line followed by a load of volume lines
   */
  static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v)
  {
  	struct in_addr *addr = v;
  
  	/* display header on line 1 */
  	if (v == (struct in_addr *) 1) {
  		seq_puts(m, "ADDRESS
  ");
  		return 0;
  	}
  
  	/* display one cell per line on subsequent lines */
be8594054   Harvey Harrison   fs: replace NIPQU...
548
549
  	seq_printf(m, "%pI4
  ", &addr->s_addr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
550
  	return 0;
ec26815ad   David Howells   [AFS]: Clean up t...
551
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
552

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
553
554
555
556
557
558
559
560
561
  /*
   * open "/proc/fs/afs/<cell>/servers" which provides a summary of active
   * servers
   */
  static int afs_proc_cell_servers_open(struct inode *inode, struct file *file)
  {
  	struct afs_cell *cell;
  	struct seq_file *m;
  	int ret;
d9dda78ba   Al Viro   procfs: new helpe...
562
  	cell = PDE_DATA(inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
563
564
565
566
567
568
569
570
571
  	if (!cell)
  		return -ENOENT;
  
  	ret = seq_open(file, &afs_proc_cell_servers_ops);
  	if (ret < 0)
  		return ret;
  
  	m = file->private_data;
  	m->private = cell;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
572
  	return 0;
ec26815ad   David Howells   [AFS]: Clean up t...
573
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
574

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
575
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
576
577
578
579
   * set up the iterator to start reading from the cells list and return the
   * first item
   */
  static void *afs_proc_cell_servers_start(struct seq_file *m, loff_t *_pos)
08e0e7c82   David Howells   [AF_RXRPC]: Make ...
580
  	__acquires(m->private->servers_lock)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
581
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
582
  	struct afs_cell *cell = m->private;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
583
584
585
586
  
  	_enter("cell=%p pos=%Ld", cell, *_pos);
  
  	/* lock the list against modification */
08e0e7c82   David Howells   [AF_RXRPC]: Make ...
587
  	read_lock(&cell->servers_lock);
a6a8bd6d2   Pavel Emelianov   Make AFS use seq_...
588
  	return seq_list_start_head(&cell->servers, *_pos);
ec26815ad   David Howells   [AFS]: Clean up t...
589
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
590

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
591
592
593
594
595
596
  /*
   * move to next cell in cells list
   */
  static void *afs_proc_cell_servers_next(struct seq_file *p, void *v,
  					loff_t *_pos)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
597
598
599
  	struct afs_cell *cell = p->private;
  
  	_enter("cell=%p pos=%Ld", cell, *_pos);
a6a8bd6d2   Pavel Emelianov   Make AFS use seq_...
600
  	return seq_list_next(v, &cell->servers, _pos);
ec26815ad   David Howells   [AFS]: Clean up t...
601
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
602

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
603
604
605
606
  /*
   * clean up after reading from the cells list
   */
  static void afs_proc_cell_servers_stop(struct seq_file *p, void *v)
08e0e7c82   David Howells   [AF_RXRPC]: Make ...
607
  	__releases(p->private->servers_lock)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
608
609
  {
  	struct afs_cell *cell = p->private;
08e0e7c82   David Howells   [AF_RXRPC]: Make ...
610
  	read_unlock(&cell->servers_lock);
ec26815ad   David Howells   [AFS]: Clean up t...
611
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
612

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
613
614
615
616
617
  /*
   * display a header line followed by a load of volume lines
   */
  static int afs_proc_cell_servers_show(struct seq_file *m, void *v)
  {
a6a8bd6d2   Pavel Emelianov   Make AFS use seq_...
618
  	struct afs_cell *cell = m->private;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
619
620
621
622
  	struct afs_server *server = list_entry(v, struct afs_server, link);
  	char ipaddr[20];
  
  	/* display header on line 1 */
a6a8bd6d2   Pavel Emelianov   Make AFS use seq_...
623
  	if (v == &cell->servers) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
624
625
626
627
628
629
  		seq_puts(m, "USE ADDR            STATE
  ");
  		return 0;
  	}
  
  	/* display one cell per line on subsequent lines */
be8594054   Harvey Harrison   fs: replace NIPQU...
630
  	sprintf(ipaddr, "%pI4", &server->addr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
631
632
  	seq_printf(m, "%3d %-15.15s %5d
  ",
ec26815ad   David Howells   [AFS]: Clean up t...
633
  		   atomic_read(&server->usage), ipaddr, server->fs_state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
634
635
  
  	return 0;
ec26815ad   David Howells   [AFS]: Clean up t...
636
  }