aoemain.c (1825B)
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 13MODULE_LICENSE("GPL"); 14MODULE_AUTHOR("Sam Hopkins <sah@coraid.com>"); 15MODULE_DESCRIPTION("AoE block/char driver for 2.6.2 and newer 2.6 kernels"); 16MODULE_VERSION(VERSION); 17 18static struct timer_list timer; 19struct workqueue_struct *aoe_wq; 20 21static void discover_timer(struct timer_list *t) 22{ 23 mod_timer(t, jiffies + HZ * 60); /* one minute */ 24 25 aoecmd_cfg(0xffff, 0xff); 26} 27 28static void __exit 29aoe_exit(void) 30{ 31 del_timer_sync(&timer); 32 33 aoenet_exit(); 34 unregister_blkdev(AOE_MAJOR, DEVICE_NAME); 35 aoecmd_exit(); 36 aoechr_exit(); 37 aoedev_exit(); 38 aoeblk_exit(); /* free cache after de-allocating bufs */ 39 destroy_workqueue(aoe_wq); 40} 41 42static int __init 43aoe_init(void) 44{ 45 int ret; 46 47 aoe_wq = alloc_workqueue("aoe_wq", 0, 0); 48 if (!aoe_wq) 49 return -ENOMEM; 50 51 ret = aoedev_init(); 52 if (ret) 53 goto dev_fail; 54 ret = aoechr_init(); 55 if (ret) 56 goto chr_fail; 57 ret = aoeblk_init(); 58 if (ret) 59 goto blk_fail; 60 ret = aoenet_init(); 61 if (ret) 62 goto net_fail; 63 ret = aoecmd_init(); 64 if (ret) 65 goto cmd_fail; 66 ret = register_blkdev(AOE_MAJOR, DEVICE_NAME); 67 if (ret < 0) { 68 printk(KERN_ERR "aoe: can't register major\n"); 69 goto blkreg_fail; 70 } 71 printk(KERN_INFO "aoe: AoE v%s initialised.\n", VERSION); 72 73 timer_setup(&timer, discover_timer, 0); 74 discover_timer(&timer); 75 return 0; 76 blkreg_fail: 77 aoecmd_exit(); 78 cmd_fail: 79 aoenet_exit(); 80 net_fail: 81 aoeblk_exit(); 82 blk_fail: 83 aoechr_exit(); 84 chr_fail: 85 aoedev_exit(); 86 dev_fail: 87 destroy_workqueue(aoe_wq); 88 89 printk(KERN_INFO "aoe: initialisation failure.\n"); 90 return ret; 91} 92 93module_init(aoe_init); 94module_exit(aoe_exit); 95