main.c 7.5 KB

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