aoemain.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Copyright (c) 2007 Coraid, Inc. See COPYING for GPL terms. */
  2. /*
  3. * aoemain.c
  4. * Module initialization routines, discover timer
  5. */
  6. #include <linux/hdreg.h>
  7. #include <linux/blkdev.h>
  8. #include <linux/module.h>
  9. #include "aoe.h"
  10. MODULE_LICENSE("GPL");
  11. MODULE_AUTHOR("Sam Hopkins <sah@coraid.com>");
  12. MODULE_DESCRIPTION("AoE block/char driver for 2.6.2 and newer 2.6 kernels");
  13. MODULE_VERSION(VERSION);
  14. enum { TINIT, TRUN, TKILL };
  15. static void
  16. discover_timer(ulong vp)
  17. {
  18. static struct timer_list t;
  19. static volatile ulong die;
  20. static spinlock_t lock;
  21. ulong flags;
  22. enum { DTIMERTICK = HZ * 60 }; /* one minute */
  23. switch (vp) {
  24. case TINIT:
  25. init_timer(&t);
  26. spin_lock_init(&lock);
  27. t.data = TRUN;
  28. t.function = discover_timer;
  29. die = 0;
  30. case TRUN:
  31. spin_lock_irqsave(&lock, flags);
  32. if (!die) {
  33. t.expires = jiffies + DTIMERTICK;
  34. add_timer(&t);
  35. }
  36. spin_unlock_irqrestore(&lock, flags);
  37. aoecmd_cfg(0xffff, 0xff);
  38. return;
  39. case TKILL:
  40. spin_lock_irqsave(&lock, flags);
  41. die = 1;
  42. spin_unlock_irqrestore(&lock, flags);
  43. del_timer_sync(&t);
  44. default:
  45. return;
  46. }
  47. }
  48. static void
  49. aoe_exit(void)
  50. {
  51. discover_timer(TKILL);
  52. aoenet_exit();
  53. unregister_blkdev(AOE_MAJOR, DEVICE_NAME);
  54. aoechr_exit();
  55. aoedev_exit();
  56. aoeblk_exit(); /* free cache after de-allocating bufs */
  57. }
  58. static int __init
  59. aoe_init(void)
  60. {
  61. int ret;
  62. ret = aoedev_init();
  63. if (ret)
  64. return ret;
  65. ret = aoechr_init();
  66. if (ret)
  67. goto chr_fail;
  68. ret = aoeblk_init();
  69. if (ret)
  70. goto blk_fail;
  71. ret = aoenet_init();
  72. if (ret)
  73. goto net_fail;
  74. ret = register_blkdev(AOE_MAJOR, DEVICE_NAME);
  75. if (ret < 0) {
  76. printk(KERN_ERR "aoe: can't register major\n");
  77. goto blkreg_fail;
  78. }
  79. printk(KERN_INFO "aoe: AoE v%s initialised.\n", VERSION);
  80. discover_timer(TINIT);
  81. return 0;
  82. blkreg_fail:
  83. aoenet_exit();
  84. net_fail:
  85. aoeblk_exit();
  86. blk_fail:
  87. aoechr_exit();
  88. chr_fail:
  89. aoedev_exit();
  90. printk(KERN_INFO "aoe: initialisation failure.\n");
  91. return ret;
  92. }
  93. module_init(aoe_init);
  94. module_exit(aoe_exit);