main.c 4.4 KB

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