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