main.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /* AFS client file system
  2. *
  3. * Copyright (C) 2002,5 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 <linux/sched.h>
  16. #include <linux/random.h>
  17. #include <linux/proc_fs.h>
  18. #define CREATE_TRACE_POINTS
  19. #include "internal.h"
  20. MODULE_DESCRIPTION("AFS Client File System");
  21. MODULE_AUTHOR("Red Hat, Inc.");
  22. MODULE_LICENSE("GPL");
  23. unsigned afs_debug;
  24. module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO);
  25. MODULE_PARM_DESC(debug, "AFS debugging mask");
  26. static char *rootcell;
  27. module_param(rootcell, charp, 0);
  28. MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
  29. struct workqueue_struct *afs_wq;
  30. static struct proc_dir_entry *afs_proc_symlink;
  31. #if defined(CONFIG_ALPHA)
  32. const char afs_init_sysname[] = "alpha_linux26";
  33. #elif defined(CONFIG_X86_64)
  34. const char afs_init_sysname[] = "amd64_linux26";
  35. #elif defined(CONFIG_ARM)
  36. const char afs_init_sysname[] = "arm_linux26";
  37. #elif defined(CONFIG_ARM64)
  38. const char afs_init_sysname[] = "aarch64_linux26";
  39. #elif defined(CONFIG_X86_32)
  40. const char afs_init_sysname[] = "i386_linux26";
  41. #elif defined(CONFIG_IA64)
  42. const char afs_init_sysname[] = "ia64_linux26";
  43. #elif defined(CONFIG_PPC64)
  44. const char afs_init_sysname[] = "ppc64_linux26";
  45. #elif defined(CONFIG_PPC32)
  46. const char afs_init_sysname[] = "ppc_linux26";
  47. #elif defined(CONFIG_S390)
  48. #ifdef CONFIG_64BIT
  49. const char afs_init_sysname[] = "s390x_linux26";
  50. #else
  51. const char afs_init_sysname[] = "s390_linux26";
  52. #endif
  53. #elif defined(CONFIG_SPARC64)
  54. const char afs_init_sysname[] = "sparc64_linux26";
  55. #elif defined(CONFIG_SPARC32)
  56. const char afs_init_sysname[] = "sparc_linux26";
  57. #else
  58. const char afs_init_sysname[] = "unknown_linux26";
  59. #endif
  60. /*
  61. * Initialise an AFS network namespace record.
  62. */
  63. static int __net_init afs_net_init(struct net *net_ns)
  64. {
  65. struct afs_sysnames *sysnames;
  66. struct afs_net *net = afs_net(net_ns);
  67. int ret;
  68. net->net = net_ns;
  69. net->live = true;
  70. generate_random_uuid((unsigned char *)&net->uuid);
  71. INIT_WORK(&net->charge_preallocation_work, afs_charge_preallocation);
  72. mutex_init(&net->socket_mutex);
  73. net->cells = RB_ROOT;
  74. seqlock_init(&net->cells_lock);
  75. INIT_WORK(&net->cells_manager, afs_manage_cells);
  76. timer_setup(&net->cells_timer, afs_cells_timer, 0);
  77. mutex_init(&net->proc_cells_lock);
  78. INIT_HLIST_HEAD(&net->proc_cells);
  79. seqlock_init(&net->fs_lock);
  80. net->fs_servers = RB_ROOT;
  81. INIT_LIST_HEAD(&net->fs_updates);
  82. INIT_HLIST_HEAD(&net->fs_proc);
  83. INIT_HLIST_HEAD(&net->fs_addresses4);
  84. INIT_HLIST_HEAD(&net->fs_addresses6);
  85. seqlock_init(&net->fs_addr_lock);
  86. INIT_WORK(&net->fs_manager, afs_manage_servers);
  87. timer_setup(&net->fs_timer, afs_servers_timer, 0);
  88. ret = -ENOMEM;
  89. sysnames = kzalloc(sizeof(*sysnames), GFP_KERNEL);
  90. if (!sysnames)
  91. goto error_sysnames;
  92. sysnames->subs[0] = (char *)&afs_init_sysname;
  93. sysnames->nr = 1;
  94. refcount_set(&sysnames->usage, 1);
  95. net->sysnames = sysnames;
  96. rwlock_init(&net->sysnames_lock);
  97. /* Register the /proc stuff */
  98. ret = afs_proc_init(net);
  99. if (ret < 0)
  100. goto error_proc;
  101. /* Initialise the cell DB */
  102. ret = afs_cell_init(net, rootcell);
  103. if (ret < 0)
  104. goto error_cell_init;
  105. /* Create the RxRPC transport */
  106. ret = afs_open_socket(net);
  107. if (ret < 0)
  108. goto error_open_socket;
  109. return 0;
  110. error_open_socket:
  111. net->live = false;
  112. afs_cell_purge(net);
  113. afs_purge_servers(net);
  114. error_cell_init:
  115. net->live = false;
  116. afs_proc_cleanup(net);
  117. error_proc:
  118. afs_put_sysnames(net->sysnames);
  119. error_sysnames:
  120. net->live = false;
  121. return ret;
  122. }
  123. /*
  124. * Clean up and destroy an AFS network namespace record.
  125. */
  126. static void __net_exit afs_net_exit(struct net *net_ns)
  127. {
  128. struct afs_net *net = afs_net(net_ns);
  129. net->live = false;
  130. afs_cell_purge(net);
  131. afs_purge_servers(net);
  132. afs_close_socket(net);
  133. afs_proc_cleanup(net);
  134. afs_put_sysnames(net->sysnames);
  135. }
  136. static struct pernet_operations afs_net_ops = {
  137. .init = afs_net_init,
  138. .exit = afs_net_exit,
  139. .id = &afs_net_id,
  140. .size = sizeof(struct afs_net),
  141. };
  142. /*
  143. * initialise the AFS client FS module
  144. */
  145. static int __init afs_init(void)
  146. {
  147. int ret = -ENOMEM;
  148. printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
  149. afs_wq = alloc_workqueue("afs", 0, 0);
  150. if (!afs_wq)
  151. goto error_afs_wq;
  152. afs_async_calls = alloc_workqueue("kafsd", WQ_MEM_RECLAIM, 0);
  153. if (!afs_async_calls)
  154. goto error_async;
  155. afs_lock_manager = alloc_workqueue("kafs_lockd", WQ_MEM_RECLAIM, 0);
  156. if (!afs_lock_manager)
  157. goto error_lockmgr;
  158. #ifdef CONFIG_AFS_FSCACHE
  159. /* we want to be able to cache */
  160. ret = fscache_register_netfs(&afs_cache_netfs);
  161. if (ret < 0)
  162. goto error_cache;
  163. #endif
  164. ret = register_pernet_subsys(&afs_net_ops);
  165. if (ret < 0)
  166. goto error_net;
  167. /* register the filesystems */
  168. ret = afs_fs_init();
  169. if (ret < 0)
  170. goto error_fs;
  171. afs_proc_symlink = proc_symlink("fs/afs", NULL, "../self/net/afs");
  172. if (IS_ERR(afs_proc_symlink)) {
  173. ret = PTR_ERR(afs_proc_symlink);
  174. goto error_proc;
  175. }
  176. return ret;
  177. error_proc:
  178. afs_fs_exit();
  179. error_fs:
  180. unregister_pernet_subsys(&afs_net_ops);
  181. error_net:
  182. #ifdef CONFIG_AFS_FSCACHE
  183. fscache_unregister_netfs(&afs_cache_netfs);
  184. error_cache:
  185. #endif
  186. destroy_workqueue(afs_lock_manager);
  187. error_lockmgr:
  188. destroy_workqueue(afs_async_calls);
  189. error_async:
  190. destroy_workqueue(afs_wq);
  191. error_afs_wq:
  192. rcu_barrier();
  193. printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
  194. return ret;
  195. }
  196. /* XXX late_initcall is kludgy, but the only alternative seems to create
  197. * a transport upon the first mount, which is worse. Or is it?
  198. */
  199. late_initcall(afs_init); /* must be called after net/ to create socket */
  200. /*
  201. * clean up on module removal
  202. */
  203. static void __exit afs_exit(void)
  204. {
  205. printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
  206. proc_remove(afs_proc_symlink);
  207. afs_fs_exit();
  208. unregister_pernet_subsys(&afs_net_ops);
  209. #ifdef CONFIG_AFS_FSCACHE
  210. fscache_unregister_netfs(&afs_cache_netfs);
  211. #endif
  212. destroy_workqueue(afs_lock_manager);
  213. destroy_workqueue(afs_async_calls);
  214. destroy_workqueue(afs_wq);
  215. afs_clean_up_permit_cache();
  216. rcu_barrier();
  217. }
  218. module_exit(afs_exit);