aoemain.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. static struct timer_list timer;
  16. static void discover_timer(struct timer_list *t)
  17. {
  18. mod_timer(t, jiffies + HZ * 60); /* one minute */
  19. aoecmd_cfg(0xffff, 0xff);
  20. }
  21. static void
  22. aoe_exit(void)
  23. {
  24. del_timer_sync(&timer);
  25. aoenet_exit();
  26. unregister_blkdev(AOE_MAJOR, DEVICE_NAME);
  27. aoecmd_exit();
  28. aoechr_exit();
  29. aoedev_exit();
  30. aoeblk_exit(); /* free cache after de-allocating bufs */
  31. }
  32. static int __init
  33. aoe_init(void)
  34. {
  35. int ret;
  36. ret = aoedev_init();
  37. if (ret)
  38. return ret;
  39. ret = aoechr_init();
  40. if (ret)
  41. goto chr_fail;
  42. ret = aoeblk_init();
  43. if (ret)
  44. goto blk_fail;
  45. ret = aoenet_init();
  46. if (ret)
  47. goto net_fail;
  48. ret = aoecmd_init();
  49. if (ret)
  50. goto cmd_fail;
  51. ret = register_blkdev(AOE_MAJOR, DEVICE_NAME);
  52. if (ret < 0) {
  53. printk(KERN_ERR "aoe: can't register major\n");
  54. goto blkreg_fail;
  55. }
  56. printk(KERN_INFO "aoe: AoE v%s initialised.\n", VERSION);
  57. timer_setup(&timer, discover_timer, 0);
  58. discover_timer(&timer);
  59. return 0;
  60. blkreg_fail:
  61. aoecmd_exit();
  62. cmd_fail:
  63. aoenet_exit();
  64. net_fail:
  65. aoeblk_exit();
  66. blk_fail:
  67. aoechr_exit();
  68. chr_fail:
  69. aoedev_exit();
  70. printk(KERN_INFO "aoe: initialisation failure.\n");
  71. return ret;
  72. }
  73. module_init(aoe_init);
  74. module_exit(aoe_exit);