main.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* 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 "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(afs_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. #ifdef AFS_CACHING_SUPPORT
  26. static struct cachefs_netfs_operations afs_cache_ops = {
  27. .get_page_cookie = afs_cache_get_page_cookie,
  28. };
  29. struct cachefs_netfs afs_cache_netfs = {
  30. .name = "afs",
  31. .version = 0,
  32. .ops = &afs_cache_ops,
  33. };
  34. #endif
  35. struct afs_uuid afs_uuid;
  36. /*
  37. * get a client UUID
  38. */
  39. static int __init afs_get_client_UUID(void)
  40. {
  41. struct timespec ts;
  42. u64 uuidtime;
  43. u16 clockseq;
  44. int ret;
  45. /* read the MAC address of one of the external interfaces and construct
  46. * a UUID from it */
  47. ret = afs_get_MAC_address(afs_uuid.node, sizeof(afs_uuid.node));
  48. if (ret < 0)
  49. return ret;
  50. getnstimeofday(&ts);
  51. uuidtime = (u64) ts.tv_sec * 1000 * 1000 * 10;
  52. uuidtime += ts.tv_nsec / 100;
  53. uuidtime += AFS_UUID_TO_UNIX_TIME;
  54. afs_uuid.time_low = uuidtime;
  55. afs_uuid.time_mid = uuidtime >> 32;
  56. afs_uuid.time_hi_and_version = (uuidtime >> 48) & AFS_UUID_TIMEHI_MASK;
  57. afs_uuid.time_hi_and_version = AFS_UUID_VERSION_TIME;
  58. get_random_bytes(&clockseq, 2);
  59. afs_uuid.clock_seq_low = clockseq;
  60. afs_uuid.clock_seq_hi_and_reserved =
  61. (clockseq >> 8) & AFS_UUID_CLOCKHI_MASK;
  62. afs_uuid.clock_seq_hi_and_reserved = AFS_UUID_VARIANT_STD;
  63. _debug("AFS UUID: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
  64. afs_uuid.time_low,
  65. afs_uuid.time_mid,
  66. afs_uuid.time_hi_and_version,
  67. afs_uuid.clock_seq_hi_and_reserved,
  68. afs_uuid.clock_seq_low,
  69. afs_uuid.node[0], afs_uuid.node[1], afs_uuid.node[2],
  70. afs_uuid.node[3], afs_uuid.node[4], afs_uuid.node[5]);
  71. return 0;
  72. }
  73. /*
  74. * initialise the AFS client FS module
  75. */
  76. static int __init afs_init(void)
  77. {
  78. int ret;
  79. printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 registering.\n");
  80. ret = afs_get_client_UUID();
  81. if (ret < 0)
  82. return ret;
  83. /* register the /proc stuff */
  84. ret = afs_proc_init();
  85. if (ret < 0)
  86. return ret;
  87. #ifdef AFS_CACHING_SUPPORT
  88. /* we want to be able to cache */
  89. ret = cachefs_register_netfs(&afs_cache_netfs,
  90. &afs_cache_cell_index_def);
  91. if (ret < 0)
  92. goto error_cache;
  93. #endif
  94. /* initialise the cell DB */
  95. ret = afs_cell_init(rootcell);
  96. if (ret < 0)
  97. goto error_cell_init;
  98. /* initialise the VL update process */
  99. ret = afs_vlocation_update_init();
  100. if (ret < 0)
  101. goto error_vl_update_init;
  102. /* initialise the callback update process */
  103. ret = afs_callback_update_init();
  104. /* create the RxRPC transport */
  105. ret = afs_open_socket();
  106. if (ret < 0)
  107. goto error_open_socket;
  108. /* register the filesystems */
  109. ret = afs_fs_init();
  110. if (ret < 0)
  111. goto error_fs;
  112. return ret;
  113. error_fs:
  114. afs_close_socket();
  115. error_open_socket:
  116. error_vl_update_init:
  117. error_cell_init:
  118. #ifdef AFS_CACHING_SUPPORT
  119. cachefs_unregister_netfs(&afs_cache_netfs);
  120. error_cache:
  121. #endif
  122. afs_callback_update_kill();
  123. afs_vlocation_purge();
  124. afs_cell_purge();
  125. afs_proc_cleanup();
  126. rcu_barrier();
  127. printk(KERN_ERR "kAFS: failed to register: %d\n", ret);
  128. return ret;
  129. }
  130. /* XXX late_initcall is kludgy, but the only alternative seems to create
  131. * a transport upon the first mount, which is worse. Or is it?
  132. */
  133. late_initcall(afs_init); /* must be called after net/ to create socket */
  134. /*
  135. * clean up on module removal
  136. */
  137. static void __exit afs_exit(void)
  138. {
  139. printk(KERN_INFO "kAFS: Red Hat AFS client v0.1 unregistering.\n");
  140. afs_fs_exit();
  141. afs_close_socket();
  142. afs_purge_servers();
  143. afs_callback_update_kill();
  144. afs_vlocation_purge();
  145. flush_scheduled_work();
  146. afs_cell_purge();
  147. #ifdef AFS_CACHING_SUPPORT
  148. cachefs_unregister_netfs(&afs_cache_netfs);
  149. #endif
  150. afs_proc_cleanup();
  151. rcu_barrier();
  152. }
  153. module_exit(afs_exit);