proc.c 18 KB

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