main.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /* main.c: AFS client file system
  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/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/init.h>
  14. #include <linux/completion.h>
  15. #include <rxrpc/rxrpc.h>
  16. #include <rxrpc/transport.h>
  17. #include <rxrpc/call.h>
  18. #include <rxrpc/peer.h>
  19. #include "cache.h"
  20. #include "cell.h"
  21. #include "server.h"
  22. #include "fsclient.h"
  23. #include "cmservice.h"
  24. #include "kafstimod.h"
  25. #include "kafsasyncd.h"
  26. #include "internal.h"
  27. struct rxrpc_transport *afs_transport;
  28. static int afs_adding_peer(struct rxrpc_peer *peer);
  29. static void afs_discarding_peer(struct rxrpc_peer *peer);
  30. MODULE_DESCRIPTION("AFS Client File System");
  31. MODULE_AUTHOR("Red Hat, Inc.");
  32. MODULE_LICENSE("GPL");
  33. static char *rootcell;
  34. module_param(rootcell, charp, 0);
  35. MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
  36. static struct rxrpc_peer_ops afs_peer_ops = {
  37. .adding = afs_adding_peer,
  38. .discarding = afs_discarding_peer,
  39. };
  40. struct list_head afs_cb_hash_tbl[AFS_CB_HASH_COUNT];
  41. DEFINE_SPINLOCK(afs_cb_hash_lock);
  42. #ifdef AFS_CACHING_SUPPORT
  43. static struct cachefs_netfs_operations afs_cache_ops = {
  44. .get_page_cookie = afs_cache_get_page_cookie,
  45. };
  46. struct cachefs_netfs afs_cache_netfs = {
  47. .name = "afs",
  48. .version = 0,
  49. .ops = &afs_cache_ops,
  50. };
  51. #endif
  52. /*****************************************************************************/
  53. /*
  54. * initialise the AFS client FS module
  55. */
  56. static int __init afs_init(void)
  57. {
  58. int loop, ret;
  59. printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
  60. /* initialise the callback hash table */
  61. spin_lock_init(&afs_cb_hash_lock);
  62. for (loop = AFS_CB_HASH_COUNT - 1; loop >= 0; loop--)
  63. INIT_LIST_HEAD(&afs_cb_hash_tbl[loop]);
  64. /* register the /proc stuff */
  65. ret = afs_proc_init();
  66. if (ret < 0)
  67. return ret;
  68. #ifdef AFS_CACHING_SUPPORT
  69. /* we want to be able to cache */
  70. ret = cachefs_register_netfs(&afs_cache_netfs,
  71. &afs_cache_cell_index_def);
  72. if (ret < 0)
  73. goto error;
  74. #endif
  75. #ifdef CONFIG_KEYS_TURNED_OFF
  76. ret = afs_key_register();
  77. if (ret < 0)
  78. goto error_cache;
  79. #endif
  80. /* initialise the cell DB */
  81. ret = afs_cell_init(rootcell);
  82. if (ret < 0)
  83. goto error_keys;
  84. /* start the timeout daemon */
  85. ret = afs_kafstimod_start();
  86. if (ret < 0)
  87. goto error_keys;
  88. /* start the async operation daemon */
  89. ret = afs_kafsasyncd_start();
  90. if (ret < 0)
  91. goto error_kafstimod;
  92. /* create the RxRPC transport */
  93. ret = rxrpc_create_transport(7001, &afs_transport);
  94. if (ret < 0)
  95. goto error_kafsasyncd;
  96. afs_transport->peer_ops = &afs_peer_ops;
  97. /* register the filesystems */
  98. ret = afs_fs_init();
  99. if (ret < 0)
  100. goto error_transport;
  101. return ret;
  102. error_transport:
  103. rxrpc_put_transport(afs_transport);
  104. error_kafsasyncd:
  105. afs_kafsasyncd_stop();
  106. error_kafstimod:
  107. afs_kafstimod_stop();
  108. error_keys:
  109. #ifdef CONFIG_KEYS_TURNED_OFF
  110. afs_key_unregister();
  111. error_cache:
  112. #endif
  113. #ifdef AFS_CACHING_SUPPORT
  114. cachefs_unregister_netfs(&afs_cache_netfs);
  115. error:
  116. #endif
  117. afs_cell_purge();
  118. afs_proc_cleanup();
  119. printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
  120. return ret;
  121. } /* end afs_init() */
  122. /* XXX late_initcall is kludgy, but the only alternative seems to create
  123. * a transport upon the first mount, which is worse. Or is it?
  124. */
  125. late_initcall(afs_init); /* must be called after net/ to create socket */
  126. /*****************************************************************************/
  127. /*
  128. * clean up on module removal
  129. */
  130. static void __exit afs_exit(void)
  131. {
  132. printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
  133. afs_fs_exit();
  134. rxrpc_put_transport(afs_transport);
  135. afs_kafstimod_stop();
  136. afs_kafsasyncd_stop();
  137. afs_cell_purge();
  138. #ifdef CONFIG_KEYS_TURNED_OFF
  139. afs_key_unregister();
  140. #endif
  141. #ifdef AFS_CACHING_SUPPORT
  142. cachefs_unregister_netfs(&afs_cache_netfs);
  143. #endif
  144. afs_proc_cleanup();
  145. } /* end afs_exit() */
  146. module_exit(afs_exit);
  147. /*****************************************************************************/
  148. /*
  149. * notification that new peer record is being added
  150. * - called from krxsecd
  151. * - return an error to induce an abort
  152. * - mustn't sleep (caller holds an rwlock)
  153. */
  154. static int afs_adding_peer(struct rxrpc_peer *peer)
  155. {
  156. struct afs_server *server;
  157. int ret;
  158. _debug("kAFS: Adding new peer %08x\n", ntohl(peer->addr.s_addr));
  159. /* determine which server the peer resides in (if any) */
  160. ret = afs_server_find_by_peer(peer, &server);
  161. if (ret < 0)
  162. return ret; /* none that we recognise, so abort */
  163. _debug("Server %p{u=%d}\n", server, atomic_read(&server->usage));
  164. _debug("Cell %p{u=%d}\n",
  165. server->cell, atomic_read(&server->cell->usage));
  166. /* cross-point the structs under a global lock */
  167. spin_lock(&afs_server_peer_lock);
  168. peer->user = server;
  169. server->peer = peer;
  170. spin_unlock(&afs_server_peer_lock);
  171. afs_put_server(server);
  172. return 0;
  173. } /* end afs_adding_peer() */
  174. /*****************************************************************************/
  175. /*
  176. * notification that a peer record is being discarded
  177. * - called from krxiod or krxsecd
  178. */
  179. static void afs_discarding_peer(struct rxrpc_peer *peer)
  180. {
  181. struct afs_server *server;
  182. _enter("%p",peer);
  183. _debug("Discarding peer %08x (rtt=%lu.%lumS)\n",
  184. ntohl(peer->addr.s_addr),
  185. (long) (peer->rtt / 1000),
  186. (long) (peer->rtt % 1000));
  187. /* uncross-point the structs under a global lock */
  188. spin_lock(&afs_server_peer_lock);
  189. server = peer->user;
  190. if (server) {
  191. peer->user = NULL;
  192. server->peer = NULL;
  193. }
  194. spin_unlock(&afs_server_peer_lock);
  195. _leave("");
  196. } /* end afs_discarding_peer() */
  197. /*****************************************************************************/
  198. /*
  199. * clear the dead space between task_struct and kernel stack
  200. * - called by supplying -finstrument-functions to gcc
  201. */
  202. #if 0
  203. void __cyg_profile_func_enter (void *this_fn, void *call_site)
  204. __attribute__((no_instrument_function));
  205. void __cyg_profile_func_enter (void *this_fn, void *call_site)
  206. {
  207. asm volatile(" movl %%esp,%%edi \n"
  208. " andl %0,%%edi \n"
  209. " addl %1,%%edi \n"
  210. " movl %%esp,%%ecx \n"
  211. " subl %%edi,%%ecx \n"
  212. " shrl $2,%%ecx \n"
  213. " movl $0xedededed,%%eax \n"
  214. " rep stosl \n"
  215. :
  216. : "i"(~(THREAD_SIZE - 1)), "i"(sizeof(struct thread_info))
  217. : "eax", "ecx", "edi", "memory", "cc"
  218. );
  219. }
  220. void __cyg_profile_func_exit(void *this_fn, void *call_site)
  221. __attribute__((no_instrument_function));
  222. void __cyg_profile_func_exit(void *this_fn, void *call_site)
  223. {
  224. asm volatile(" movl %%esp,%%edi \n"
  225. " andl %0,%%edi \n"
  226. " addl %1,%%edi \n"
  227. " movl %%esp,%%ecx \n"
  228. " subl %%edi,%%ecx \n"
  229. " shrl $2,%%ecx \n"
  230. " movl $0xdadadada,%%eax \n"
  231. " rep stosl \n"
  232. :
  233. : "i"(~(THREAD_SIZE - 1)), "i"(sizeof(struct thread_info))
  234. : "eax", "ecx", "edi", "memory", "cc"
  235. );
  236. }
  237. #endif