proc.c 21 KB

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