main.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #define CREATE_TRACE_POINTS
  18. #include "internal.h"
  19. MODULE_DESCRIPTION("AFS Client File System");
  20. MODULE_AUTHOR("Red Hat, Inc.");
  21. MODULE_LICENSE("GPL");
  22. unsigned afs_debug;
  23. module_param_named(debug, afs_debug, uint, S_IWUSR | S_IRUGO);
  24. MODULE_PARM_DESC(debug, "AFS debugging mask");
  25. static char *rootcell;
  26. module_param(rootcell, charp, 0);
  27. MODULE_PARM_DESC(rootcell, "root AFS cell name and VL server IP addr list");
  28. struct afs_uuid afs_uuid;
  29. struct workqueue_struct *afs_wq;
  30. /*
  31. * initialise the AFS client FS module
  32. */
  33. static int __init afs_init(void)
  34. {
  35. int ret;
  36. printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
  37. generate_random_uuid((unsigned char *)&afs_uuid);
  38. /* create workqueue */
  39. ret = -ENOMEM;
  40. afs_wq = alloc_workqueue("afs", 0, 0);
  41. if (!afs_wq)
  42. return ret;
  43. /* register the /proc stuff */
  44. ret = afs_proc_init();
  45. if (ret < 0)
  46. goto error_proc;
  47. #ifdef CONFIG_AFS_FSCACHE
  48. /* we want to be able to cache */
  49. ret = fscache_register_netfs(&afs_cache_netfs);
  50. if (ret < 0)
  51. goto error_cache;
  52. #endif
  53. /* initialise the cell DB */
  54. ret = afs_cell_init(rootcell);
  55. if (ret < 0)
  56. goto error_cell_init;
  57. /* initialise the VL update process */
  58. ret = afs_vlocation_update_init();
  59. if (ret < 0)
  60. goto error_vl_update_init;
  61. /* initialise the callback update process */
  62. ret = afs_callback_update_init();
  63. if (ret < 0)
  64. goto error_callback_update_init;
  65. /* create the RxRPC transport */
  66. ret = afs_open_socket();
  67. if (ret < 0)
  68. goto error_open_socket;
  69. /* register the filesystems */
  70. ret = afs_fs_init();
  71. if (ret < 0)
  72. goto error_fs;
  73. return ret;
  74. error_fs:
  75. afs_close_socket();
  76. error_open_socket:
  77. afs_callback_update_kill();
  78. error_callback_update_init:
  79. afs_vlocation_purge();
  80. error_vl_update_init:
  81. afs_cell_purge();
  82. error_cell_init:
  83. #ifdef CONFIG_AFS_FSCACHE
  84. fscache_unregister_netfs(&afs_cache_netfs);
  85. error_cache:
  86. #endif
  87. afs_proc_cleanup();
  88. error_proc:
  89. destroy_workqueue(afs_wq);
  90. rcu_barrier();
  91. printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
  92. return ret;
  93. }
  94. /* XXX late_initcall is kludgy, but the only alternative seems to create
  95. * a transport upon the first mount, which is worse. Or is it?
  96. */
  97. late_initcall(afs_init); /* must be called after net/ to create socket */
  98. /*
  99. * clean up on module removal
  100. */
  101. static void __exit afs_exit(void)
  102. {
  103. printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
  104. afs_fs_exit();
  105. afs_kill_lock_manager();
  106. afs_close_socket();
  107. afs_purge_servers();
  108. afs_callback_update_kill();
  109. afs_vlocation_purge();
  110. destroy_workqueue(afs_wq);
  111. afs_cell_purge();
  112. #ifdef CONFIG_AFS_FSCACHE
  113. fscache_unregister_netfs(&afs_cache_netfs);
  114. #endif
  115. afs_proc_cleanup();
  116. rcu_barrier();
  117. }
  118. module_exit(afs_exit);