proc.c 17 KB

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