aoemain.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 <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. aoechr_exit();
  56. aoedev_exit();
  57. aoeblk_exit(); /* free cache after de-allocating bufs */
  58. }
  59. static int __init
  60. aoe_init(void)
  61. {
  62. int ret;
  63. ret = aoedev_init();
  64. if (ret)
  65. return ret;
  66. ret = aoechr_init();
  67. if (ret)
  68. goto chr_fail;
  69. ret = aoeblk_init();
  70. if (ret)
  71. goto blk_fail;
  72. ret = aoenet_init();
  73. if (ret)
  74. goto net_fail;
  75. ret = register_blkdev(AOE_MAJOR, DEVICE_NAME);
  76. if (ret < 0) {
  77. printk(KERN_ERR "aoe: can't register major\n");
  78. goto blkreg_fail;
  79. }
  80. printk(KERN_INFO "aoe: AoE v%s initialised.\n", VERSION);
  81. discover_timer(TINIT);
  82. return 0;
  83. blkreg_fail:
  84. aoenet_exit();
  85. net_fail:
  86. aoeblk_exit();
  87. blk_fail:
  88. aoechr_exit();
  89. chr_fail:
  90. aoedev_exit();
  91. printk(KERN_INFO "aoe: initialisation failure.\n");
  92. return ret;
  93. }
  94. module_init(aoe_init);
  95. module_exit(aoe_exit);