main.c 6.0 KB

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