aoemain.c 1.8 KB

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