proc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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. struct list_head *_p;
  175. loff_t pos = *_pos;
  176. /* lock the list against modification */
  177. down_read(&afs_proc_cells_sem);
  178. /* allow for the header line */
  179. if (!pos)
  180. return (void *) 1;
  181. pos--;
  182. /* find the n'th element in the list */
  183. list_for_each(_p, &afs_proc_cells)
  184. if (!pos--)
  185. break;
  186. return _p != &afs_proc_cells ? _p : NULL;
  187. }
  188. /*
  189. * move to next cell in cells list
  190. */
  191. static void *afs_proc_cells_next(struct seq_file *p, void *v, loff_t *pos)
  192. {
  193. struct list_head *_p;
  194. (*pos)++;
  195. _p = v;
  196. _p = v == (void *) 1 ? afs_proc_cells.next : _p->next;
  197. return _p != &afs_proc_cells ? _p : NULL;
  198. }
  199. /*
  200. * clean up after reading from the cells list
  201. */
  202. static void afs_proc_cells_stop(struct seq_file *p, void *v)
  203. {
  204. up_read(&afs_proc_cells_sem);
  205. }
  206. /*
  207. * display a header line followed by a load of cell lines
  208. */
  209. static int afs_proc_cells_show(struct seq_file *m, void *v)
  210. {
  211. struct afs_cell *cell = list_entry(v, struct afs_cell, proc_link);
  212. if (v == (void *) 1) {
  213. /* display header on line 1 */
  214. seq_puts(m, "USE NAME\n");
  215. return 0;
  216. }
  217. /* display one cell per line on subsequent lines */
  218. seq_printf(m, "%3d %s\n",
  219. atomic_read(&cell->usage), cell->name);
  220. return 0;
  221. }
  222. /*
  223. * handle writes to /proc/fs/afs/cells
  224. * - to add cells: echo "add <cellname> <IP>[:<IP>][:<IP>]"
  225. */
  226. static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf,
  227. size_t size, loff_t *_pos)
  228. {
  229. char *kbuf, *name, *args;
  230. int ret;
  231. /* start by dragging the command into memory */
  232. if (size <= 1 || size >= PAGE_SIZE)
  233. return -EINVAL;
  234. kbuf = kmalloc(size + 1, GFP_KERNEL);
  235. if (!kbuf)
  236. return -ENOMEM;
  237. ret = -EFAULT;
  238. if (copy_from_user(kbuf, buf, size) != 0)
  239. goto done;
  240. kbuf[size] = 0;
  241. /* trim to first NL */
  242. name = memchr(kbuf, '\n', size);
  243. if (name)
  244. *name = 0;
  245. /* split into command, name and argslist */
  246. name = strchr(kbuf, ' ');
  247. if (!name)
  248. goto inval;
  249. do {
  250. *name++ = 0;
  251. } while(*name == ' ');
  252. if (!*name)
  253. goto inval;
  254. args = strchr(name, ' ');
  255. if (!args)
  256. goto inval;
  257. do {
  258. *args++ = 0;
  259. } while(*args == ' ');
  260. if (!*args)
  261. goto inval;
  262. /* determine command to perform */
  263. _debug("cmd=%s name=%s args=%s", kbuf, name, args);
  264. if (strcmp(kbuf, "add") == 0) {
  265. struct afs_cell *cell;
  266. cell = afs_cell_create(name, args);
  267. if (IS_ERR(cell)) {
  268. ret = PTR_ERR(cell);
  269. goto done;
  270. }
  271. afs_put_cell(cell);
  272. printk("kAFS: Added new cell '%s'\n", name);
  273. } else {
  274. goto inval;
  275. }
  276. ret = size;
  277. done:
  278. kfree(kbuf);
  279. _leave(" = %d", ret);
  280. return ret;
  281. inval:
  282. ret = -EINVAL;
  283. printk("kAFS: Invalid Command on /proc/fs/afs/cells file\n");
  284. goto done;
  285. }
  286. /*
  287. * Stubs for /proc/fs/afs/rootcell
  288. */
  289. static int afs_proc_rootcell_open(struct inode *inode, struct file *file)
  290. {
  291. return 0;
  292. }
  293. static int afs_proc_rootcell_release(struct inode *inode, struct file *file)
  294. {
  295. return 0;
  296. }
  297. static ssize_t afs_proc_rootcell_read(struct file *file, char __user *buf,
  298. size_t size, loff_t *_pos)
  299. {
  300. return 0;
  301. }
  302. /*
  303. * handle writes to /proc/fs/afs/rootcell
  304. * - to initialize rootcell: echo "cell.name:192.168.231.14"
  305. */
  306. static ssize_t afs_proc_rootcell_write(struct file *file,
  307. const char __user *buf,
  308. size_t size, loff_t *_pos)
  309. {
  310. char *kbuf, *s;
  311. int ret;
  312. /* start by dragging the command into memory */
  313. if (size <= 1 || size >= PAGE_SIZE)
  314. return -EINVAL;
  315. ret = -ENOMEM;
  316. kbuf = kmalloc(size + 1, GFP_KERNEL);
  317. if (!kbuf)
  318. goto nomem;
  319. ret = -EFAULT;
  320. if (copy_from_user(kbuf, buf, size) != 0)
  321. goto infault;
  322. kbuf[size] = 0;
  323. /* trim to first NL */
  324. s = memchr(kbuf, '\n', size);
  325. if (s)
  326. *s = 0;
  327. /* determine command to perform */
  328. _debug("rootcell=%s", kbuf);
  329. ret = afs_cell_init(kbuf);
  330. if (ret >= 0)
  331. ret = size; /* consume everything, always */
  332. infault:
  333. kfree(kbuf);
  334. nomem:
  335. _leave(" = %d", ret);
  336. return ret;
  337. }
  338. /*
  339. * initialise /proc/fs/afs/<cell>/
  340. */
  341. int afs_proc_cell_setup(struct afs_cell *cell)
  342. {
  343. struct proc_dir_entry *p;
  344. _enter("%p{%s}", cell, cell->name);
  345. cell->proc_dir = proc_mkdir(cell->name, proc_afs);
  346. if (!cell->proc_dir)
  347. goto error_dir;
  348. p = create_proc_entry("servers", 0, cell->proc_dir);
  349. if (!p)
  350. goto error_servers;
  351. p->proc_fops = &afs_proc_cell_servers_fops;
  352. p->owner = THIS_MODULE;
  353. p->data = cell;
  354. p = create_proc_entry("vlservers", 0, cell->proc_dir);
  355. if (!p)
  356. goto error_vlservers;
  357. p->proc_fops = &afs_proc_cell_vlservers_fops;
  358. p->owner = THIS_MODULE;
  359. p->data = cell;
  360. p = create_proc_entry("volumes", 0, cell->proc_dir);
  361. if (!p)
  362. goto error_volumes;
  363. p->proc_fops = &afs_proc_cell_volumes_fops;
  364. p->owner = THIS_MODULE;
  365. p->data = cell;
  366. _leave(" = 0");
  367. return 0;
  368. error_volumes:
  369. remove_proc_entry("vlservers", cell->proc_dir);
  370. error_vlservers:
  371. remove_proc_entry("servers", cell->proc_dir);
  372. error_servers:
  373. remove_proc_entry(cell->name, proc_afs);
  374. error_dir:
  375. _leave(" = -ENOMEM");
  376. return -ENOMEM;
  377. }
  378. /*
  379. * remove /proc/fs/afs/<cell>/
  380. */
  381. void afs_proc_cell_remove(struct afs_cell *cell)
  382. {
  383. _enter("");
  384. remove_proc_entry("volumes", cell->proc_dir);
  385. remove_proc_entry("vlservers", cell->proc_dir);
  386. remove_proc_entry("servers", cell->proc_dir);
  387. remove_proc_entry(cell->name, proc_afs);
  388. _leave("");
  389. }
  390. /*
  391. * open "/proc/fs/afs/<cell>/volumes" which provides a summary of extant cells
  392. */
  393. static int afs_proc_cell_volumes_open(struct inode *inode, struct file *file)
  394. {
  395. struct afs_cell *cell;
  396. struct seq_file *m;
  397. int ret;
  398. cell = PDE(inode)->data;
  399. if (!cell)
  400. return -ENOENT;
  401. ret = seq_open(file, &afs_proc_cell_volumes_ops);
  402. if (ret < 0)
  403. return ret;
  404. m = file->private_data;
  405. m->private = cell;
  406. return 0;
  407. }
  408. /*
  409. * close the file and release the ref to the cell
  410. */
  411. static int afs_proc_cell_volumes_release(struct inode *inode, struct file *file)
  412. {
  413. return seq_release(inode, file);
  414. }
  415. /*
  416. * set up the iterator to start reading from the cells list and return the
  417. * first item
  418. */
  419. static void *afs_proc_cell_volumes_start(struct seq_file *m, loff_t *_pos)
  420. {
  421. struct list_head *_p;
  422. struct afs_cell *cell = m->private;
  423. loff_t pos = *_pos;
  424. _enter("cell=%p pos=%Ld", cell, *_pos);
  425. /* lock the list against modification */
  426. down_read(&cell->vl_sem);
  427. /* allow for the header line */
  428. if (!pos)
  429. return (void *) 1;
  430. pos--;
  431. /* find the n'th element in the list */
  432. list_for_each(_p, &cell->vl_list)
  433. if (!pos--)
  434. break;
  435. return _p != &cell->vl_list ? _p : NULL;
  436. }
  437. /*
  438. * move to next cell in cells list
  439. */
  440. static void *afs_proc_cell_volumes_next(struct seq_file *p, void *v,
  441. loff_t *_pos)
  442. {
  443. struct list_head *_p;
  444. struct afs_cell *cell = p->private;
  445. _enter("cell=%p pos=%Ld", cell, *_pos);
  446. (*_pos)++;
  447. _p = v;
  448. _p = (v == (void *) 1) ? cell->vl_list.next : _p->next;
  449. return (_p != &cell->vl_list) ? _p : NULL;
  450. }
  451. /*
  452. * clean up after reading from the cells list
  453. */
  454. static void afs_proc_cell_volumes_stop(struct seq_file *p, void *v)
  455. {
  456. struct afs_cell *cell = p->private;
  457. up_read(&cell->vl_sem);
  458. }
  459. const char afs_vlocation_states[][4] = {
  460. [AFS_VL_NEW] = "New",
  461. [AFS_VL_CREATING] = "Crt",
  462. [AFS_VL_VALID] = "Val",
  463. [AFS_VL_NO_VOLUME] = "NoV",
  464. [AFS_VL_UPDATING] = "Upd",
  465. [AFS_VL_VOLUME_DELETED] = "Del",
  466. [AFS_VL_UNCERTAIN] = "Unc",
  467. };
  468. /*
  469. * display a header line followed by a load of volume lines
  470. */
  471. static int afs_proc_cell_volumes_show(struct seq_file *m, void *v)
  472. {
  473. struct afs_vlocation *vlocation =
  474. list_entry(v, struct afs_vlocation, link);
  475. /* display header on line 1 */
  476. if (v == (void *) 1) {
  477. seq_puts(m, "USE STT VLID[0] VLID[1] VLID[2] NAME\n");
  478. return 0;
  479. }
  480. /* display one cell per line on subsequent lines */
  481. seq_printf(m, "%3d %s %08x %08x %08x %s\n",
  482. atomic_read(&vlocation->usage),
  483. afs_vlocation_states[vlocation->state],
  484. vlocation->vldb.vid[0],
  485. vlocation->vldb.vid[1],
  486. vlocation->vldb.vid[2],
  487. vlocation->vldb.name);
  488. return 0;
  489. }
  490. /*
  491. * open "/proc/fs/afs/<cell>/vlservers" which provides a list of volume
  492. * location server
  493. */
  494. static int afs_proc_cell_vlservers_open(struct inode *inode, struct file *file)
  495. {
  496. struct afs_cell *cell;
  497. struct seq_file *m;
  498. int ret;
  499. cell = PDE(inode)->data;
  500. if (!cell)
  501. return -ENOENT;
  502. ret = seq_open(file, &afs_proc_cell_vlservers_ops);
  503. if (ret<0)
  504. return ret;
  505. m = file->private_data;
  506. m->private = cell;
  507. return 0;
  508. }
  509. /*
  510. * close the file and release the ref to the cell
  511. */
  512. static int afs_proc_cell_vlservers_release(struct inode *inode,
  513. struct file *file)
  514. {
  515. return seq_release(inode, file);
  516. }
  517. /*
  518. * set up the iterator to start reading from the cells list and return the
  519. * first item
  520. */
  521. static void *afs_proc_cell_vlservers_start(struct seq_file *m, loff_t *_pos)
  522. {
  523. struct afs_cell *cell = m->private;
  524. loff_t pos = *_pos;
  525. _enter("cell=%p pos=%Ld", cell, *_pos);
  526. /* lock the list against modification */
  527. down_read(&cell->vl_sem);
  528. /* allow for the header line */
  529. if (!pos)
  530. return (void *) 1;
  531. pos--;
  532. if (pos >= cell->vl_naddrs)
  533. return NULL;
  534. return &cell->vl_addrs[pos];
  535. }
  536. /*
  537. * move to next cell in cells list
  538. */
  539. static void *afs_proc_cell_vlservers_next(struct seq_file *p, void *v,
  540. loff_t *_pos)
  541. {
  542. struct afs_cell *cell = p->private;
  543. loff_t pos;
  544. _enter("cell=%p{nad=%u} pos=%Ld", cell, cell->vl_naddrs, *_pos);
  545. pos = *_pos;
  546. (*_pos)++;
  547. if (pos >= cell->vl_naddrs)
  548. return NULL;
  549. return &cell->vl_addrs[pos];
  550. }
  551. /*
  552. * clean up after reading from the cells list
  553. */
  554. static void afs_proc_cell_vlservers_stop(struct seq_file *p, void *v)
  555. {
  556. struct afs_cell *cell = p->private;
  557. up_read(&cell->vl_sem);
  558. }
  559. /*
  560. * display a header line followed by a load of volume lines
  561. */
  562. static int afs_proc_cell_vlservers_show(struct seq_file *m, void *v)
  563. {
  564. struct in_addr *addr = v;
  565. /* display header on line 1 */
  566. if (v == (struct in_addr *) 1) {
  567. seq_puts(m, "ADDRESS\n");
  568. return 0;
  569. }
  570. /* display one cell per line on subsequent lines */
  571. seq_printf(m, "%u.%u.%u.%u\n", NIPQUAD(addr->s_addr));
  572. return 0;
  573. }
  574. /*
  575. * open "/proc/fs/afs/<cell>/servers" which provides a summary of active
  576. * servers
  577. */
  578. static int afs_proc_cell_servers_open(struct inode *inode, struct file *file)
  579. {
  580. struct afs_cell *cell;
  581. struct seq_file *m;
  582. int ret;
  583. cell = PDE(inode)->data;
  584. if (!cell)
  585. return -ENOENT;
  586. ret = seq_open(file, &afs_proc_cell_servers_ops);
  587. if (ret < 0)
  588. return ret;
  589. m = file->private_data;
  590. m->private = cell;
  591. return 0;
  592. }
  593. /*
  594. * close the file and release the ref to the cell
  595. */
  596. static int afs_proc_cell_servers_release(struct inode *inode,
  597. struct file *file)
  598. {
  599. return seq_release(inode, file);
  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->servers_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->servers_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->servers)
  620. if (!pos--)
  621. break;
  622. return _p != &cell->servers ? _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->servers.next : _p->next;
  636. return _p != &cell->servers ? _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->servers_lock)
  643. {
  644. struct afs_cell *cell = p->private;
  645. read_unlock(&cell->servers_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. }