aoemain.c 2.1 KB

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